| 1 | <?php
|
|---|
| 2 | /**
|
|---|
| 3 | * The engine, powers everything :-)
|
|---|
| 4 | *
|
|---|
| 5 | * PHP version 5
|
|---|
| 6 | *
|
|---|
| 7 | * LICENSE: Hotaru CMS is free software: you can redistribute it and/or
|
|---|
| 8 | * modify it under the terms of the GNU General Public License as
|
|---|
| 9 | * published by the Free Software Foundation, either version 3 of
|
|---|
| 10 | * the License, or (at your option) any later version.
|
|---|
| 11 | *
|
|---|
| 12 | * Hotaru CMS is distributed in the hope that it will be useful, but WITHOUT
|
|---|
| 13 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|---|
| 14 | * FITNESS FOR A PARTICULAR PURPOSE.
|
|---|
| 15 | *
|
|---|
| 16 | * You should have received a copy of the GNU General Public License along
|
|---|
| 17 | * with Hotaru CMS. If not, see http://www.gnu.org/licenses/.
|
|---|
| 18 | *
|
|---|
| 19 | * @category Content Management System
|
|---|
| 20 | * @package HotaruCMS
|
|---|
| 21 | * @author Nick Ramsay <admin@hotarucms.org>
|
|---|
| 22 | * @copyright Copyright (c) 2009, Hotaru CMS
|
|---|
| 23 | * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License
|
|---|
| 24 | * @link http://www.hotarucms.org/
|
|---|
| 25 | */
|
|---|
| 26 | class Hotaru
|
|---|
| 27 | {
|
|---|
| 28 | protected $version = "1.1.3"; // Hotaru CMS version
|
|---|
| 29 | protected $isDebug = false; // show db queries and page loading time
|
|---|
| 30 | protected $isAdmin = false; // flag to tell if we are in Admin or not
|
|---|
| 31 | protected $sidebars = true; // enable or disable the sidebars
|
|---|
| 32 | protected $csrfToken = ''; // token for CSRF
|
|---|
| 33 | protected $lang = array(); // stores language file content
|
|---|
| 34 |
|
|---|
| 35 | // objects
|
|---|
| 36 | protected $db; // database object
|
|---|
| 37 | protected $cage; // Inspekt object
|
|---|
| 38 | protected $currentUser; // UserBase object
|
|---|
| 39 | protected $plugin; // Plugin object
|
|---|
| 40 | protected $post; // Post object
|
|---|
| 41 | protected $avatar; // Avatar object
|
|---|
| 42 | protected $comment; // Comment object
|
|---|
| 43 | protected $includes; // for CSS/JavaScript includes
|
|---|
| 44 | protected $debug; // Debug object
|
|---|
| 45 | protected $email; // Email object
|
|---|
| 46 |
|
|---|
| 47 | // page info
|
|---|
| 48 | protected $pageName = ''; // e.g. index, category
|
|---|
| 49 | protected $pageTitle = ''; // e.g. Top Stories
|
|---|
| 50 | protected $pageType = ''; // e.g. post, list
|
|---|
| 51 | protected $pageTemplate = ''; // e.g. sb_list, tag_cloud
|
|---|
| 52 | protected $subPage = ''; // e.g. category (if pageName is "index")
|
|---|
| 53 |
|
|---|
| 54 | // ALL plugins
|
|---|
| 55 | protected $pluginSettings = array(); // contains all settings for all plugins
|
|---|
| 56 | protected $allPluginDetails = array(); // contains details of all plugins
|
|---|
| 57 |
|
|---|
| 58 | // messages
|
|---|
| 59 | protected $message = ''; // message to display
|
|---|
| 60 | protected $messageType = 'green'; // green or red, color of message box
|
|---|
| 61 | protected $messages = array(); // for multiple messages
|
|---|
| 62 |
|
|---|
| 63 | // miscellaneous
|
|---|
| 64 | protected $vars = array(); // multi-purpose
|
|---|
| 65 |
|
|---|
| 66 | /**
|
|---|
| 67 | * CONSTRUCTOR - Initialize
|
|---|
| 68 | */
|
|---|
| 69 | public function __construct($start = '', $admin = false)
|
|---|
| 70 | {
|
|---|
| 71 | if ($admin) { $this->isAdmin = true; } // we have this here because the checkCssJs function needs it
|
|---|
| 72 |
|
|---|
| 73 | // initialize Hotaru
|
|---|
| 74 | if (!$start) {
|
|---|
| 75 | require_once(LIBS . 'Initialize.php');
|
|---|
| 76 | $init = new Initialize($this);
|
|---|
| 77 | $this->db = $init->db; // database object
|
|---|
| 78 | $this->cage = $init->cage; // Inspekt cage
|
|---|
| 79 | $this->isDebug = $init->isDebug; // set debug
|
|---|
| 80 | $this->currentUser = new UserAuth(); // the current user
|
|---|
| 81 | $this->plugin = new Plugin(); // instantiate Plugin object
|
|---|
| 82 | $this->post = new Post(); // instantiate Post object
|
|---|
| 83 | $this->includes = new IncludeCssJs(); // instantiate Includes object
|
|---|
| 84 |
|
|---|
| 85 | $this->checkCssJs(); // check if we need to merge css/js
|
|---|
| 86 | $this->csrf('set'); // set a csrfToken
|
|---|
| 87 | $this->db->setHotaru($this); // pass $h object to EzSQL for error reporting
|
|---|
| 88 | }
|
|---|
| 89 | }
|
|---|
| 90 |
|
|---|
| 91 |
|
|---|
| 92 | /* *************************************************************
|
|---|
| 93 | *
|
|---|
| 94 | * HOTARU FUNCTIONS
|
|---|
| 95 | *
|
|---|
| 96 | * *********************************************************** */
|
|---|
| 97 |
|
|---|
| 98 |
|
|---|
| 99 | /**
|
|---|
| 100 | * START - the top of "Hotaru", i.e. the page-building process
|
|---|
| 101 | */
|
|---|
| 102 | public function start($entrance = '')
|
|---|
| 103 | {
|
|---|
| 104 | // Set up debugging:
|
|---|
| 105 | if ($this->isDebug) {
|
|---|
| 106 | require_once(LIBS . 'Debug.php');
|
|---|
| 107 | $this->debug = new Debug();
|
|---|
| 108 | }
|
|---|
| 109 |
|
|---|
| 110 | // include "main" language pack
|
|---|
| 111 | $lang = new Language();
|
|---|
| 112 | $this->lang = $lang->includeLanguagePack($this->lang, 'main');
|
|---|
| 113 |
|
|---|
| 114 | $this->getPageName(); // fills $h->pageName
|
|---|
| 115 |
|
|---|
| 116 | switch ($entrance) {
|
|---|
| 117 | case 'admin':
|
|---|
| 118 | $this->isAdmin = true;
|
|---|
| 119 | $this->lang = $lang->includeLanguagePack($this->lang, 'admin');
|
|---|
| 120 | require_once(LIBS . 'AdminAuth.php'); // include Admin class
|
|---|
| 121 | $admin = new AdminAuth(); // new Admin object
|
|---|
| 122 | $this->checkCookie(); // check cookie reads user details
|
|---|
| 123 | $this->checkAccess(); // site closed if no access permitted
|
|---|
| 124 | $page = $admin->adminInit($this); // initialize Admin & get desired page
|
|---|
| 125 | $this->adminPages($page); // Direct to desired Admin page
|
|---|
| 126 | break;
|
|---|
| 127 | default:
|
|---|
| 128 | $this->isAdmin = false;
|
|---|
| 129 | $this->checkCookie(); // log in user if cookie
|
|---|
| 130 | $this->checkAccess(); // site closed if no access permitted
|
|---|
| 131 | if (!$entrance) { return false; } // stop here if entrance not defined
|
|---|
| 132 | $this->displayTemplate('index'); // displays the index page
|
|---|
| 133 | }
|
|---|
| 134 |
|
|---|
| 135 | exit;
|
|---|
| 136 | }
|
|---|
| 137 |
|
|---|
| 138 |
|
|---|
| 139 | /* *************************************************************
|
|---|
| 140 | *
|
|---|
| 141 | * ACCESS MODIFIERS
|
|---|
| 142 | *
|
|---|
| 143 | * *********************************************************** */
|
|---|
| 144 |
|
|---|
| 145 |
|
|---|
| 146 | /**
|
|---|
| 147 | * Access modifier to set protected properties
|
|---|
| 148 | */
|
|---|
| 149 | public function __set($var, $val)
|
|---|
| 150 | {
|
|---|
| 151 | $this->$var = $val;
|
|---|
| 152 | }
|
|---|
| 153 |
|
|---|
| 154 |
|
|---|
| 155 | /**
|
|---|
| 156 | * Access modifier to get protected properties
|
|---|
| 157 | * The & is necessary (http://bugs.php.net/bug.php?id=39449)
|
|---|
| 158 | */
|
|---|
| 159 | public function &__get($var)
|
|---|
| 160 | {
|
|---|
| 161 | return $this->$var;
|
|---|
| 162 | }
|
|---|
| 163 |
|
|---|
| 164 |
|
|---|
| 165 | /* *************************************************************
|
|---|
| 166 | *
|
|---|
| 167 | * DEFAULT PLUGIN HOOK ACTIONS
|
|---|
| 168 | *
|
|---|
| 169 | * *********************************************************** */
|
|---|
| 170 |
|
|---|
| 171 |
|
|---|
| 172 | /**
|
|---|
| 173 | * Include language file if available
|
|---|
| 174 | */
|
|---|
| 175 | public function install_plugin()
|
|---|
| 176 | {
|
|---|
| 177 | $this->includeLanguage($this->plugin->folder);
|
|---|
| 178 | }
|
|---|
| 179 |
|
|---|
| 180 |
|
|---|
| 181 | /**
|
|---|
| 182 | * Include All CSS and JavaScript files for this plugin
|
|---|
| 183 | */
|
|---|
| 184 | public function header_include()
|
|---|
| 185 | {
|
|---|
| 186 | if ($this->isAdmin) { return false; }
|
|---|
| 187 |
|
|---|
| 188 | // include a files that match the name of the plugin folder:
|
|---|
| 189 | $this->includeJs($this->plugin->folder); // folder name, filename
|
|---|
| 190 | $this->includeCss($this->plugin->folder);
|
|---|
| 191 | }
|
|---|
| 192 |
|
|---|
| 193 |
|
|---|
| 194 | /**
|
|---|
| 195 | * Include All CSS and JavaScript files for this plugin in Admin
|
|---|
| 196 | */
|
|---|
| 197 | public function admin_header_include()
|
|---|
| 198 | {
|
|---|
| 199 | if (!$this->isAdmin) { return false; }
|
|---|
| 200 |
|
|---|
| 201 | // include a files that match the name of the plugin folder:
|
|---|
| 202 | $this->includeJs($this->plugin->folder); // folder name, filename
|
|---|
| 203 | $this->includeCss($this->plugin->folder);
|
|---|
| 204 | }
|
|---|
| 205 |
|
|---|
| 206 | /**
|
|---|
| 207 | * Include code as a template before the closing </body> tag
|
|---|
| 208 | */
|
|---|
| 209 | public function pre_close_body()
|
|---|
| 210 | {
|
|---|
| 211 | $this->displayTemplate($this->plugin->folder . '_footer', $this->plugin->folder);
|
|---|
| 212 | }
|
|---|
| 213 |
|
|---|
| 214 |
|
|---|
| 215 | /**
|
|---|
| 216 | * Display Admin sidebar link
|
|---|
| 217 | */
|
|---|
| 218 | public function admin_sidebar_plugin_settings()
|
|---|
| 219 | {
|
|---|
| 220 | $vars['plugin'] = $this->plugin->folder;
|
|---|
| 221 | $vars['name'] = $this->plugin->name;
|
|---|
| 222 | //$vars['name'] = make_name($this->plugin->folder);
|
|---|
| 223 | return $vars;
|
|---|
| 224 | }
|
|---|
| 225 |
|
|---|
| 226 |
|
|---|
| 227 | /**
|
|---|
| 228 | * Display Admin settings page
|
|---|
| 229 | *
|
|---|
| 230 | * @return true
|
|---|
| 231 | */
|
|---|
| 232 | public function admin_plugin_settings()
|
|---|
| 233 | {
|
|---|
| 234 | // This requires there to be a file in the plugin folder called pluginname_settings.php
|
|---|
| 235 | // The file must contain a class titled PluginNameSettings
|
|---|
| 236 | // The class must have a method called "settings".
|
|---|
| 237 | if (($this->cage->get->testAlnumLines('plugin') != $this->plugin->folder)
|
|---|
| 238 | && ($this->cage->post->testAlnumLines('plugin') != $this->plugin->folder))
|
|---|
| 239 | {
|
|---|
| 240 | return false;
|
|---|
| 241 | }
|
|---|
| 242 |
|
|---|
| 243 | if (file_exists(PLUGINS . $this->plugin->folder . '/' . $this->plugin->folder . '_settings.php')) {
|
|---|
| 244 | include_once(PLUGINS . $this->plugin->folder . '/' . $this->plugin->folder . '_settings.php');
|
|---|
| 245 | }
|
|---|
| 246 | $settings_class = make_name($this->plugin->folder, '_') . 'Settings'; // e.g. CategoriesSettings
|
|---|
| 247 | $settings_class = str_replace(' ', '', $settings_class); // strip spaces
|
|---|
| 248 | $settings_object = new $settings_class();
|
|---|
| 249 | $settings_object->settings($this); // call the settings function
|
|---|
| 250 | return true;
|
|---|
| 251 | }
|
|---|
| 252 |
|
|---|
| 253 |
|
|---|
| 254 | /* *************************************************************
|
|---|
| 255 | *
|
|---|
| 256 | * PAGE HANDLING FUNCTIONS
|
|---|
| 257 | *
|
|---|
| 258 | * *********************************************************** */
|
|---|
| 259 |
|
|---|
| 260 | /**
|
|---|
| 261 | * Determine the title tags for the header
|
|---|
| 262 | *
|
|---|
| 263 | * @param bool $raw -return the title only
|
|---|
| 264 | * @return string - the title
|
|---|
| 265 | */
|
|---|
| 266 | public function getTitle($delimiter = ' « ', $raw = false)
|
|---|
| 267 | {
|
|---|
| 268 | $pageHandling = new PageHandling();
|
|---|
| 269 | return $pageHandling->getTitle($this, $delimiter, $raw);
|
|---|
| 270 | }
|
|---|
| 271 |
|
|---|
| 272 |
|
|---|
| 273 | /**
|
|---|
| 274 | * Includes a template to display
|
|---|
| 275 | *
|
|---|
| 276 | * @param string $page page name
|
|---|
| 277 | * @param string $plugin optional plugin name
|
|---|
| 278 | * @param bool $include_once true or false
|
|---|
| 279 | */
|
|---|
| 280 | public function displayTemplate($page = '', $plugin = '', $include_once = true)
|
|---|
| 281 | {
|
|---|
| 282 | $pageHandling = new PageHandling();
|
|---|
| 283 | $pageHandling->displayTemplate($this, $page, $plugin, $include_once);
|
|---|
| 284 | }
|
|---|
| 285 |
|
|---|
| 286 |
|
|---|
| 287 | /**
|
|---|
| 288 | * Checks if current page (in url or form) matches the page parameter
|
|---|
| 289 | *
|
|---|
| 290 | * @param string $page page name
|
|---|
| 291 | */
|
|---|
| 292 | public function isPage($page = '')
|
|---|
| 293 | {
|
|---|
| 294 | $pageHandling = new PageHandling();
|
|---|
| 295 | return $pageHandling->isPage($this, $page);
|
|---|
| 296 | }
|
|---|
| 297 |
|
|---|
| 298 |
|
|---|
| 299 | /**
|
|---|
| 300 | * Check to see if the Admin settings page we are looking at
|
|---|
| 301 | * matches the plugin passed to this function.
|
|---|
| 302 | *
|
|---|
| 303 | * @param string $folder - plugin folder
|
|---|
| 304 | * @return bool
|
|---|
| 305 | *
|
|---|
| 306 | * Notes: This is used in "admin_header_include" so we only include the css,
|
|---|
| 307 | * javascript etc. for the plugin we're trying to change settings for.
|
|---|
| 308 | * Usage: $h->isSettingsPage('submit') returns true if
|
|---|
| 309 | * page=plugin_settings and plugin=submit in the url.
|
|---|
| 310 | */
|
|---|
| 311 | public function isSettingsPage($folder = '')
|
|---|
| 312 | {
|
|---|
| 313 | $pageHandling = new PageHandling();
|
|---|
| 314 | return $pageHandling->isSettingsPage($this, $folder);
|
|---|
| 315 | }
|
|---|
| 316 |
|
|---|
| 317 |
|
|---|
| 318 | /**
|
|---|
| 319 | * Gets the current page name
|
|---|
| 320 | */
|
|---|
| 321 | public function getPageName()
|
|---|
| 322 | {
|
|---|
| 323 | $pageHandling = new PageHandling();
|
|---|
| 324 | $this->pageName = $pageHandling->getPageName($this);
|
|---|
| 325 | return $this->pageName;
|
|---|
| 326 | }
|
|---|
| 327 |
|
|---|
| 328 |
|
|---|
| 329 | /**
|
|---|
| 330 | * Converts a friendly url into a standard one
|
|---|
| 331 | *
|
|---|
| 332 | * @param string $friendly_url
|
|---|
| 333 | * return string $standard_url
|
|---|
| 334 | */
|
|---|
| 335 | public function friendlyToStandardUrl($friendly_url)
|
|---|
| 336 | {
|
|---|
| 337 | $pageHandling = new PageHandling();
|
|---|
| 338 | return $pageHandling->friendlyToStandardUrl($this, $friendly_url);
|
|---|
| 339 | }
|
|---|
| 340 |
|
|---|
| 341 |
|
|---|
| 342 | /**
|
|---|
| 343 | * Generate either default or friendly urls
|
|---|
| 344 | *
|
|---|
| 345 | * @param array $parameters an array of pairs, e.g. 'page' => 'about'
|
|---|
| 346 | * @param string $head either 'index' or 'admin'
|
|---|
| 347 | * @return string
|
|---|
| 348 | */
|
|---|
| 349 | public function url($parameters = array(), $head = 'index')
|
|---|
| 350 | {
|
|---|
| 351 | $pageHandling = new PageHandling();
|
|---|
| 352 | return $pageHandling->url($this, $parameters, $head);
|
|---|
| 353 | }
|
|---|
| 354 |
|
|---|
| 355 |
|
|---|
| 356 | /**
|
|---|
| 357 | * Pagination with query and row count (better for large sets of data)
|
|---|
| 358 | *
|
|---|
| 359 | * @param string $query - SQL query
|
|---|
| 360 | * @param int $total_items - total row count
|
|---|
| 361 | * @param int $items_per_page
|
|---|
| 362 | * @param string $cache_table - must provide a table, e.g. "posts" for caching to be used
|
|---|
| 363 | * @return object|false - object
|
|---|
| 364 | */
|
|---|
| 365 | public function pagination($query, $total_items, $items_per_page = 10, $cache_table = '')
|
|---|
| 366 | {
|
|---|
| 367 | require_once(LIBS . 'Paginator.php');
|
|---|
| 368 | $paginator = new Paginator();
|
|---|
| 369 | return $paginator->pagination($this, $query, $total_items, $items_per_page, $cache_table);
|
|---|
| 370 | }
|
|---|
| 371 |
|
|---|
| 372 |
|
|---|
| 373 | /**
|
|---|
| 374 | * Pagination with full dataset (easier for small sets of data)
|
|---|
| 375 | *
|
|---|
| 376 | * @param array $data - array of results for paginating
|
|---|
| 377 | * @param int $items_per_page
|
|---|
| 378 | * @return object|false - object
|
|---|
| 379 | */
|
|---|
| 380 | public function paginationFull($data, $items_per_page = 10)
|
|---|
| 381 | {
|
|---|
| 382 | require_once(LIBS . 'Paginator.php');
|
|---|
| 383 | $paginator = new Paginator();
|
|---|
| 384 | return $paginator->paginationFull($this, $data, $items_per_page);
|
|---|
| 385 | }
|
|---|
| 386 |
|
|---|
| 387 |
|
|---|
| 388 | /**
|
|---|
| 389 | * Return page numbers bar
|
|---|
| 390 | *
|
|---|
| 391 | * @param object $paginator - current object of type Paginator
|
|---|
| 392 | * @return string - HTML for page number bar
|
|---|
| 393 | */
|
|---|
| 394 | public function pageBar($paginator = NULL)
|
|---|
| 395 | {
|
|---|
| 396 | return $paginator->pageBar($this);
|
|---|
| 397 | }
|
|---|
| 398 |
|
|---|
| 399 |
|
|---|
| 400 | /* *************************************************************
|
|---|
| 401 | *
|
|---|
| 402 | * BREADCRUMB FUNCTIONS
|
|---|
| 403 | *
|
|---|
| 404 | * *********************************************************** */
|
|---|
| 405 |
|
|---|
| 406 |
|
|---|
| 407 | /**
|
|---|
| 408 | * Build breadcrumbs
|
|---|
| 409 | */
|
|---|
| 410 | public function breadcrumbs()
|
|---|
| 411 | {
|
|---|
| 412 | require_once(LIBS . 'Breadcrumbs.php');
|
|---|
| 413 | $breadcrumbs = new Breadcrumbs();
|
|---|
| 414 | return $breadcrumbs->buildBreadcrumbs($this);
|
|---|
| 415 | }
|
|---|
| 416 |
|
|---|
| 417 |
|
|---|
| 418 | /**
|
|---|
| 419 | * prepares the RSS link found in breadcrumbs
|
|---|
| 420 | *
|
|---|
| 421 | * @param string $status - post status, e.g. new, top, etc.
|
|---|
| 422 | * @param array $vars - array of key -> value pairs
|
|---|
| 423 | * @return string
|
|---|
| 424 | */
|
|---|
| 425 | public function rssBreadcrumbsLink($status = '', $vars = array())
|
|---|
| 426 | {
|
|---|
| 427 | require_once(LIBS . 'Breadcrumbs.php');
|
|---|
| 428 | $breadcrumbs = new Breadcrumbs();
|
|---|
| 429 | return $breadcrumbs->rssBreadcrumbsLink($this, $status, $vars);
|
|---|
| 430 | }
|
|---|
| 431 |
|
|---|
| 432 |
|
|---|
| 433 | /* *************************************************************
|
|---|
| 434 | *
|
|---|
| 435 | * USERAUTH FUNCTIONS / USERBASE FUNCTIONS
|
|---|
| 436 | *
|
|---|
| 437 | * *********************************************************** */
|
|---|
| 438 |
|
|---|
| 439 | /* UserBase & UserAuth functions should be called directly if you want to
|
|---|
| 440 | retain the user object being used. E.g.
|
|---|
| 441 |
|
|---|
| 442 | $user = new UserAuth();
|
|---|
| 443 | $user->getUserBasic($h);
|
|---|
| 444 | $user->updateUserBasic($h);
|
|---|
| 445 | */
|
|---|
| 446 |
|
|---|
| 447 |
|
|---|
| 448 | /**
|
|---|
| 449 | * check cookie and log in
|
|---|
| 450 | *
|
|---|
| 451 | * @return bool
|
|---|
| 452 | */
|
|---|
| 453 | public function checkCookie()
|
|---|
| 454 | {
|
|---|
| 455 | $this->currentUser->checkCookie($this);
|
|---|
| 456 | }
|
|---|
| 457 |
|
|---|
| 458 |
|
|---|
| 459 | /**
|
|---|
| 460 | * Get basic user details
|
|---|
| 461 | *
|
|---|
| 462 | * @param int $userid
|
|---|
| 463 | * @param string $username
|
|---|
| 464 | * @param bool $no_cache - set true to disable caching of SQl results
|
|---|
| 465 | * @return array|false
|
|---|
| 466 | *
|
|---|
| 467 | * Note: Needs either userid or username, not both
|
|---|
| 468 | */
|
|---|
| 469 | public function getUserBasic($userid = 0, $username = '', $no_cache = false)
|
|---|
| 470 | {
|
|---|
| 471 | $userbase = new UserBase();
|
|---|
| 472 | return $userbase->getUserBasic($this, $userid, $username, $no_cache);
|
|---|
| 473 | }
|
|---|
| 474 |
|
|---|
| 475 |
|
|---|
| 476 | /**
|
|---|
| 477 | * Default permissions
|
|---|
| 478 | *
|
|---|
| 479 | * @param string $role or 'all'
|
|---|
| 480 | * @param string $field 'site' for site defaults and 'base' for base defaults
|
|---|
| 481 | * @param book $options_only returns just the options if true
|
|---|
| 482 | * @return array $perms
|
|---|
| 483 | */
|
|---|
| 484 | public function getDefaultPermissions($role = '', $defaults = 'site', $options_only = false)
|
|---|
| 485 | {
|
|---|
| 486 | $userbase = new UserBase();
|
|---|
| 487 | return $userbase->getDefaultPermissions($this, $role, $defaults, $options_only);
|
|---|
| 488 | }
|
|---|
| 489 |
|
|---|
| 490 |
|
|---|
| 491 | /**
|
|---|
| 492 | * Update Default permissions
|
|---|
| 493 | *
|
|---|
| 494 | * @param array $new_perms from a plugin's install function
|
|---|
| 495 | * @param string $defaults - either "site", "base" or "both"
|
|---|
| 496 | */
|
|---|
| 497 | public function updateDefaultPermissions($new_perms = array(), $defaults = 'both')
|
|---|
| 498 | {
|
|---|
| 499 | $userbase = new UserBase();
|
|---|
| 500 | return $userbase->updateDefaultPermissions($this, $new_perms, $defaults);
|
|---|
| 501 | }
|
|---|
| 502 |
|
|---|
| 503 |
|
|---|
| 504 | /**
|
|---|
| 505 | * Get the default user settings
|
|---|
| 506 | *
|
|---|
| 507 | * @param string $type either 'site' or 'base' (base for the originals)
|
|---|
| 508 | * @return array
|
|---|
| 509 | */
|
|---|
| 510 | public function getDefaultSettings($type = 'site')
|
|---|
| 511 | {
|
|---|
| 512 | $userbase = new UserBase();
|
|---|
| 513 | return $userbase->getDefaultSettings($this, $type);
|
|---|
| 514 | }
|
|---|
| 515 |
|
|---|
| 516 |
|
|---|
| 517 | /**
|
|---|
| 518 | * Update the default user settings
|
|---|
| 519 | *
|
|---|
| 520 | * @param array $settings
|
|---|
| 521 | * @param string $type either 'site' or 'base' (base for the originals)
|
|---|
| 522 | * @return array
|
|---|
| 523 | */
|
|---|
| 524 | public function updateDefaultSettings($settings, $type = 'site')
|
|---|
| 525 | {
|
|---|
| 526 | $userbase = new UserBase();
|
|---|
| 527 | return $userbase->updateDefaultSettings($this, $settings, $type);
|
|---|
| 528 | }
|
|---|
| 529 |
|
|---|
| 530 |
|
|---|
| 531 | /**
|
|---|
| 532 | * Get a user's profile or settings data
|
|---|
| 533 | *
|
|---|
| 534 | * @return array|false
|
|---|
| 535 | */
|
|---|
| 536 | public function getProfileSettingsData($type = 'user_profile', $userid = 0, $check_exists_only = false)
|
|---|
| 537 | {
|
|---|
| 538 | $userbase = new UserBase();
|
|---|
| 539 | return $userbase->getProfileSettingsData($this, $type, $userid, $check_exists_only);
|
|---|
| 540 | }
|
|---|
| 541 |
|
|---|
| 542 |
|
|---|
| 543 | /**
|
|---|
| 544 | * Physically delete a user
|
|---|
| 545 | * Note: You should delete all their posts, comments, etc. first
|
|---|
| 546 | *
|
|---|
| 547 | * @param array $user_id (optional)
|
|---|
| 548 | */
|
|---|
| 549 | public function deleteUser($user_id = 0)
|
|---|
| 550 | {
|
|---|
| 551 | $userbase = new UserBase();
|
|---|
| 552 | return $userbase->deleteUser($this, $user_id);
|
|---|
| 553 | }
|
|---|
| 554 |
|
|---|
| 555 |
|
|---|
| 556 | /* *************************************************************
|
|---|
| 557 | *
|
|---|
| 558 | * USERINFO FUNCTIONS
|
|---|
| 559 | *
|
|---|
| 560 | * *********************************************************** */
|
|---|
| 561 |
|
|---|
| 562 |
|
|---|
| 563 | /**
|
|---|
| 564 | * Get the username for a given user id
|
|---|
| 565 | *
|
|---|
| 566 | * @param int $id user id
|
|---|
| 567 | * @return string|false
|
|---|
| 568 | */
|
|---|
| 569 | public function getUserNameFromId($id = 0)
|
|---|
| 570 | {
|
|---|
| 571 | require_once(LIBS . 'UserInfo.php');
|
|---|
| 572 | $userInfo = new UserInfo();
|
|---|
| 573 | return $userInfo->getUserNameFromId($this, $id);
|
|---|
| 574 | }
|
|---|
| 575 |
|
|---|
| 576 |
|
|---|
| 577 | /**
|
|---|
| 578 | * Get the user id for a given username
|
|---|
| 579 | *
|
|---|
| 580 | * @param string $username
|
|---|
| 581 | * @return int|false
|
|---|
| 582 | */
|
|---|
| 583 | public function getUserIdFromName($username = '')
|
|---|
| 584 | {
|
|---|
| 585 | require_once(LIBS . 'UserInfo.php');
|
|---|
| 586 | $userInfo = new UserInfo();
|
|---|
| 587 | return $userInfo->getUserIdFromName($this, $username);
|
|---|
| 588 | }
|
|---|
| 589 |
|
|---|
| 590 |
|
|---|
| 591 | /**
|
|---|
| 592 | * Get the email from user id
|
|---|
| 593 | *
|
|---|
| 594 | * @param int $userid
|
|---|
| 595 | * @return string|false
|
|---|
| 596 | */
|
|---|
| 597 | public function getEmailFromId($userid = 0)
|
|---|
| 598 | {
|
|---|
| 599 | require_once(LIBS . 'UserInfo.php');
|
|---|
| 600 | $userInfo = new UserInfo();
|
|---|
| 601 | return $userInfo->getEmailFromId($this, $userid);
|
|---|
| 602 | }
|
|---|
| 603 |
|
|---|
| 604 |
|
|---|
| 605 | /**
|
|---|
| 606 | * Get the user id from email
|
|---|
| 607 | *
|
|---|
| 608 | * @param string $email
|
|---|
| 609 | * @return string|false
|
|---|
| 610 | */
|
|---|
| 611 | public function getUserIdFromEmail($email = '')
|
|---|
| 612 | {
|
|---|
| 613 | require_once(LIBS . 'UserInfo.php');
|
|---|
| 614 | $userInfo = new UserInfo();
|
|---|
| 615 | return $userInfo->getUserIdFromEmail($this, $email);
|
|---|
| 616 | }
|
|---|
| 617 |
|
|---|
| 618 |
|
|---|
| 619 | /**
|
|---|
| 620 | * Checks if the user has an 'admin' role
|
|---|
| 621 | *
|
|---|
| 622 | * @return bool
|
|---|
| 623 | */
|
|---|
| 624 | public function isAdmin($username)
|
|---|
| 625 | {
|
|---|
| 626 | require_once(LIBS . 'UserInfo.php');
|
|---|
| 627 | $userInfo = new UserInfo();
|
|---|
| 628 | return $userInfo->isAdmin($this->db, $username);
|
|---|
| 629 | }
|
|---|
| 630 |
|
|---|
| 631 |
|
|---|
| 632 | /**
|
|---|
| 633 | * Check if a user exists
|
|---|
| 634 | *
|
|---|
| 635 | * @param int $userid
|
|---|
| 636 | * @param string $username
|
|---|
| 637 | * @return int
|
|---|
| 638 | *
|
|---|
| 639 | * Notes: Returns 'no' if a user doesn't exist, else field under which found
|
|---|
| 640 | */
|
|---|
| 641 | public function userExists($id = 0, $username = '', $email = '')
|
|---|
| 642 | {
|
|---|
| 643 | require_once(LIBS . 'UserInfo.php');
|
|---|
| 644 | $userInfo = new UserInfo();
|
|---|
| 645 | return $userInfo->userExists($this->db, $id, $username, $email);
|
|---|
| 646 | }
|
|---|
| 647 |
|
|---|
| 648 |
|
|---|
| 649 | /**
|
|---|
| 650 | * Check if an username exists in the database (used in forgotten password)
|
|---|
| 651 | *
|
|---|
| 652 | * @param string $username user username
|
|---|
| 653 | * @param string $role user role (optional)
|
|---|
| 654 | * @param int $exclude - exclude a user
|
|---|
| 655 | * @return string|false
|
|---|
| 656 | */
|
|---|
| 657 | public function nameExists($username = '', $role = '', $exclude = 0)
|
|---|
| 658 | {
|
|---|
| 659 | require_once(LIBS . 'UserInfo.php');
|
|---|
| 660 | $userInfo = new UserInfo();
|
|---|
| 661 | return $userInfo->nameExists($this, $username, $role, $exclude);
|
|---|
| 662 | }
|
|---|
| 663 |
|
|---|
| 664 |
|
|---|
| 665 | /**
|
|---|
| 666 | * Check if an email exists in the database (used in forgotten password)
|
|---|
| 667 | *
|
|---|
| 668 | * @param string $email user email
|
|---|
| 669 | * @param string $role user role (optional)
|
|---|
| 670 | * @param int $exclude - exclude a user
|
|---|
| 671 | * @return string|false
|
|---|
| 672 | */
|
|---|
| 673 | public function emailExists($email = '', $role = '', $exclude = 0)
|
|---|
| 674 | {
|
|---|
| 675 | require_once(LIBS . 'UserInfo.php');
|
|---|
| 676 | $userInfo = new UserInfo();
|
|---|
| 677 | return $userInfo->emailExists($this, $email, $role, $exclude);
|
|---|
| 678 | }
|
|---|
| 679 |
|
|---|
| 680 |
|
|---|
| 681 | /**
|
|---|
| 682 | * Get all users with permission to (access admin)
|
|---|
| 683 | *
|
|---|
| 684 | * @param string $permission
|
|---|
| 685 | * @param string $value - value for the permission, usually yes, no, own or mod
|
|---|
| 686 | * @return array
|
|---|
| 687 | */
|
|---|
| 688 | public function getMods($permission = 'can_access_admin', $value = 'yes')
|
|---|
| 689 | {
|
|---|
| 690 | require_once(LIBS . 'UserInfo.php');
|
|---|
| 691 | $userInfo = new UserInfo();
|
|---|
| 692 | return $userInfo->getMods($this, $permission, $value);
|
|---|
| 693 | }
|
|---|
| 694 |
|
|---|
| 695 |
|
|---|
| 696 | /**
|
|---|
| 697 | * Get Unique Roles
|
|---|
| 698 | *
|
|---|
| 699 | * @return array|false
|
|---|
| 700 | */
|
|---|
| 701 | public function getUniqueRoles()
|
|---|
| 702 | {
|
|---|
| 703 | require_once(LIBS . 'UserInfo.php');
|
|---|
| 704 | $userInfo = new UserInfo();
|
|---|
| 705 | return $userInfo->getUniqueRoles($this);
|
|---|
| 706 | }
|
|---|
| 707 |
|
|---|
| 708 |
|
|---|
| 709 | /**
|
|---|
| 710 | * Get the ids and names of all users or those with a specified role, sorted alphabetically
|
|---|
| 711 | *
|
|---|
| 712 | * @param string $role - optional user role to filter to
|
|---|
| 713 | * @return array
|
|---|
| 714 | */
|
|---|
| 715 | public function userIdNameList($role = '')
|
|---|
| 716 | {
|
|---|
| 717 | require_once(LIBS . 'UserInfo.php');
|
|---|
| 718 | $userInfo = new UserInfo();
|
|---|
| 719 | return $userInfo->userIdNameList($this, $role);
|
|---|
| 720 | }
|
|---|
| 721 |
|
|---|
| 722 |
|
|---|
| 723 | /**
|
|---|
| 724 | * Get full details of all users or batches of users, sorted alphabetically
|
|---|
| 725 | *
|
|---|
| 726 | * @param array $id_array - optional array of user ids
|
|---|
| 727 | * @param int $start - LIMIT $start $range (optional)
|
|---|
| 728 | * @param int $range - LIMIT $start $range (optional)
|
|---|
| 729 | * @return array
|
|---|
| 730 | */
|
|---|
| 731 | public function userListFull($id_array = array(), $start = 0, $range = 0)
|
|---|
| 732 | {
|
|---|
| 733 | require_once(LIBS . 'UserInfo.php');
|
|---|
| 734 | $userInfo = new UserInfo();
|
|---|
| 735 | return $userInfo->userListFull($this, $id_array, $start, $range);
|
|---|
| 736 | }
|
|---|
| 737 |
|
|---|
| 738 |
|
|---|
| 739 | /**
|
|---|
| 740 | * Get settings for all users
|
|---|
| 741 | *
|
|---|
| 742 | * @param int $userid - optional user id
|
|---|
| 743 | * @return array
|
|---|
| 744 | */
|
|---|
| 745 | public function userSettingsList($userid = 0)
|
|---|
| 746 | {
|
|---|
| 747 | require_once(LIBS . 'UserInfo.php');
|
|---|
| 748 | $userInfo = new UserInfo();
|
|---|
| 749 | return $userInfo->userSettingsList($this, $userid);
|
|---|
| 750 | }
|
|---|
| 751 |
|
|---|
| 752 |
|
|---|
| 753 | /* *************************************************************
|
|---|
| 754 | *
|
|---|
| 755 | * PLUGIN FUNCTIONS
|
|---|
| 756 | *
|
|---|
| 757 | * *********************************************************** */
|
|---|
| 758 |
|
|---|
| 759 |
|
|---|
| 760 | /**
|
|---|
| 761 | * Look for and run actions at a given plugin hook
|
|---|
| 762 | *
|
|---|
| 763 | * @param string $hook name of the plugin hook
|
|---|
| 764 | * @param bool $perform false to check existence, true to actually run
|
|---|
| 765 | * @param string $folder name of plugin folder
|
|---|
| 766 | * @param array $parameters mixed values passed from plugin hook
|
|---|
| 767 | * @return array | bool
|
|---|
| 768 | */
|
|---|
| 769 | public function pluginHook($hook = '', $folder = '', $parameters = array(), $exclude = array())
|
|---|
| 770 | {
|
|---|
| 771 | $pluginFunctions = new PluginFunctions();
|
|---|
| 772 | return $pluginFunctions->pluginHook($this, $hook, $folder, $parameters, $exclude);
|
|---|
| 773 | }
|
|---|
| 774 |
|
|---|
| 775 |
|
|---|
| 776 | /**
|
|---|
| 777 | * Get a single plugin's details for Hotaru
|
|---|
| 778 | *
|
|---|
| 779 | * @param string $folder - plugin folder name, else $h->plugin->folder is used
|
|---|
| 780 | */
|
|---|
| 781 | public function readPlugin($folder = '')
|
|---|
| 782 | {
|
|---|
| 783 | $pluginFunctions = new PluginFunctions();
|
|---|
| 784 | $pluginFunctions->readPlugin($this, $folder);
|
|---|
| 785 | }
|
|---|
| 786 |
|
|---|
| 787 |
|
|---|
| 788 | /**
|
|---|
| 789 | * Get a single property from a specified plugin
|
|---|
| 790 | *
|
|---|
| 791 | * @param string $property - plugin property, e.g. "plugin_version"
|
|---|
| 792 | * @param string $folder - plugin folder name, else $h->plugin->folder is used
|
|---|
| 793 | * @param string $field - an alternative field to use instead of $folder
|
|---|
| 794 | */
|
|---|
| 795 | public function getPluginProperty($property = '', $folder = '', $field = '')
|
|---|
| 796 | {
|
|---|
| 797 | $pluginFunctions = new PluginFunctions();
|
|---|
| 798 | return $pluginFunctions->getPluginProperty($this, $property, $folder, $field);
|
|---|
| 799 | }
|
|---|
| 800 |
|
|---|
| 801 |
|
|---|
| 802 | /**
|
|---|
| 803 | * Get number of active plugins
|
|---|
| 804 | *
|
|---|
| 805 | * @return int|false
|
|---|
| 806 | */
|
|---|
| 807 | public function numActivePlugins()
|
|---|
| 808 | {
|
|---|
| 809 | $pluginFunctions = new PluginFunctions();
|
|---|
| 810 | return $pluginFunctions->numActivePlugins($this->db);
|
|---|
| 811 | }
|
|---|
| 812 |
|
|---|
| 813 |
|
|---|
| 814 | /**
|
|---|
| 815 | * Get version number of plugin if active
|
|---|
| 816 | *
|
|---|
| 817 | * @param string $folder plugin folder name
|
|---|
| 818 | * @return string|false
|
|---|
| 819 | */
|
|---|
| 820 | public function getPluginVersion($folder = '')
|
|---|
| 821 | {
|
|---|
| 822 | return $this->getPluginProperty('plugin_version', $folder);
|
|---|
| 823 | }
|
|---|
| 824 |
|
|---|
| 825 |
|
|---|
| 826 | /**
|
|---|
| 827 | * Get a plugin's actual name from its folder name
|
|---|
| 828 | *
|
|---|
| 829 | * @param string $folder plugin folder name
|
|---|
| 830 | * @return string
|
|---|
| 831 | */
|
|---|
| 832 | public function getPluginName($folder = '')
|
|---|
| 833 | {
|
|---|
| 834 | return $this->getPluginProperty('plugin_name', $folder);
|
|---|
| 835 | }
|
|---|
| 836 |
|
|---|
| 837 |
|
|---|
| 838 | /**
|
|---|
| 839 | * Get a plugin's folder from its class name
|
|---|
| 840 | *
|
|---|
| 841 | * @param string $class plugin class name
|
|---|
| 842 | * @return string|false
|
|---|
| 843 | */
|
|---|
| 844 | public function getPluginFolderFromClass($class = '')
|
|---|
| 845 | {
|
|---|
| 846 | $pluginFunctions = new PluginFunctions();
|
|---|
| 847 | $this->plugin->folder = $pluginFunctions->getPluginFolderFromClass($this, $class);
|
|---|
| 848 | }
|
|---|
| 849 |
|
|---|
| 850 |
|
|---|
| 851 | /**
|
|---|
| 852 | * Get a plugin's class from its folder name
|
|---|
| 853 | *
|
|---|
| 854 | * @param string $folder plugin folder name
|
|---|
| 855 | * @return string|false
|
|---|
| 856 | */
|
|---|
| 857 | public function getPluginClass($folder = '')
|
|---|
| 858 | {
|
|---|
| 859 | return $this->getPluginProperty('plugin_class', $folder);
|
|---|
| 860 | }
|
|---|
| 861 |
|
|---|
| 862 |
|
|---|
| 863 | /**
|
|---|
| 864 | * Determines if a plugin "type" is enabled, if not, plugin "folder"
|
|---|
| 865 | *
|
|---|
| 866 | * @param string $type plugin type or folder name
|
|---|
| 867 | * @return bool
|
|---|
| 868 | */
|
|---|
| 869 | public function isActive($type = '')
|
|---|
| 870 | {
|
|---|
| 871 | $pluginFunctions = new PluginFunctions();
|
|---|
| 872 | //return $pluginFunctions->isActive($this, $type); // dropped in favor of cache:
|
|---|
| 873 | $result = $this->getPluginProperty('plugin_enabled', $type, 'type');
|
|---|
| 874 | if (!$result) { $result = $this->getPluginProperty('plugin_enabled', $type); }
|
|---|
| 875 | return $result;
|
|---|
| 876 | }
|
|---|
| 877 |
|
|---|
| 878 |
|
|---|
| 879 | /**
|
|---|
| 880 | * Determines if a specific plugin is installed
|
|---|
| 881 | *
|
|---|
| 882 | * @param string $folder folder name
|
|---|
| 883 | * @return bool
|
|---|
| 884 | */
|
|---|
| 885 | public function isInstalled($folder = '')
|
|---|
| 886 | {
|
|---|
| 887 | $pluginFunctions = new PluginFunctions();
|
|---|
| 888 | $result = $this->getPluginProperty('plugin_id', $folder);
|
|---|
| 889 | return $result;
|
|---|
| 890 | }
|
|---|
| 891 |
|
|---|
| 892 |
|
|---|
| 893 | /**
|
|---|
| 894 | * Determines if a plugin has a settings page or not
|
|---|
| 895 | *
|
|---|
| 896 | * @param object $h
|
|---|
| 897 | * @param string $folder plugin folder name (optional)
|
|---|
| 898 | * @return bool
|
|---|
| 899 | */
|
|---|
| 900 | public function hasSettings($folder = '')
|
|---|
| 901 | {
|
|---|
| 902 | $pluginFunctions = new PluginFunctions();
|
|---|
| 903 | return $pluginFunctions->hasSettings($this, $folder);
|
|---|
| 904 | }
|
|---|
| 905 |
|
|---|
| 906 |
|
|---|
| 907 | /* *************************************************************
|
|---|
| 908 | *
|
|---|
| 909 | * PLUGIN SETTINGS FUNCTIONS
|
|---|
| 910 | *
|
|---|
| 911 | * *********************************************************** */
|
|---|
| 912 |
|
|---|
| 913 |
|
|---|
| 914 | /**
|
|---|
| 915 | * Get the value for a given plugin and setting
|
|---|
| 916 | *
|
|---|
| 917 | * @param string $folder name of plugin folder
|
|---|
| 918 | * @param string $setting name of the setting to retrieve
|
|---|
| 919 | * @return string|false
|
|---|
| 920 | *
|
|---|
| 921 | * Notes: If there are multiple settings with the same name,
|
|---|
| 922 | * this will only get the first.
|
|---|
| 923 | */
|
|---|
| 924 | public function getSetting($setting = '', $folder = '')
|
|---|
| 925 | {
|
|---|
| 926 | $pluginSettings = new PluginSettings();
|
|---|
| 927 | return $pluginSettings->getSetting($this, $setting, $folder);
|
|---|
| 928 | }
|
|---|
| 929 |
|
|---|
| 930 |
|
|---|
| 931 | /**
|
|---|
| 932 | * Get an array of settings for a given plugin
|
|---|
| 933 | *
|
|---|
| 934 | * @param string $folder name of plugin folder
|
|---|
| 935 | * @return array|false
|
|---|
| 936 | *
|
|---|
| 937 | * Note: Unlike "getSetting", this will get ALL settings with the same name.
|
|---|
| 938 | */
|
|---|
| 939 | public function getSettingsArray($folder = '')
|
|---|
| 940 | {
|
|---|
| 941 | $pluginSettings = new PluginSettings();
|
|---|
| 942 | return $pluginSettings->getSettingsArray($this, $folder);
|
|---|
| 943 | }
|
|---|
| 944 |
|
|---|
| 945 |
|
|---|
| 946 | /**
|
|---|
| 947 | * Get and unserialize serialized settings
|
|---|
| 948 | *
|
|---|
| 949 | * @param string $folder plugin folder name
|
|---|
| 950 | * @param string $settings_name optional settings name if different from folder
|
|---|
| 951 | * @return array - of submit settings
|
|---|
| 952 | */
|
|---|
| 953 | public function getSerializedSettings($folder = '', $settings_name = '')
|
|---|
| 954 | {
|
|---|
| 955 | $pluginSettings = new PluginSettings();
|
|---|
| 956 | return $pluginSettings->getSerializedSettings($this, $folder, $settings_name);
|
|---|
| 957 | }
|
|---|
| 958 |
|
|---|
| 959 |
|
|---|
| 960 | /**
|
|---|
| 961 | * Get and store all plugin settings in $h->pluginSettings
|
|---|
| 962 | *
|
|---|
| 963 | * @return array - all settings
|
|---|
| 964 | */
|
|---|
| 965 | public function getAllPluginSettings()
|
|---|
| 966 | {
|
|---|
| 967 | $pluginSettings = new PluginSettings();
|
|---|
| 968 | $this->pluginSettings = $pluginSettings->getAllPluginSettings($this);
|
|---|
| 969 | return $this->pluginSettings;
|
|---|
| 970 | }
|
|---|
| 971 |
|
|---|
| 972 |
|
|---|
| 973 | /**
|
|---|
| 974 | * Determine if a plugin setting already exists
|
|---|
| 975 | *
|
|---|
| 976 | * @param string $folder name of plugin folder
|
|---|
| 977 | * @param string $setting name of the setting to retrieve
|
|---|
| 978 | * @return string|false
|
|---|
| 979 | */
|
|---|
| 980 | public function isSetting($setting = '', $folder = '')
|
|---|
| 981 | {
|
|---|
| 982 | $pluginSettings = new PluginSettings();
|
|---|
| 983 | return $pluginSettings->isSetting($this, $setting, $folder);
|
|---|
| 984 | }
|
|---|
| 985 |
|
|---|
| 986 |
|
|---|
| 987 | /**
|
|---|
| 988 | * Update a plugin setting
|
|---|
| 989 | *
|
|---|
| 990 | * @param string $folder name of plugin folder
|
|---|
| 991 | * @param string $setting name of the setting
|
|---|
| 992 | * @param string $setting stting value
|
|---|
| 993 | */
|
|---|
| 994 | public function updateSetting($setting = '', $value = '', $folder = '')
|
|---|
| 995 | {
|
|---|
| 996 | $pluginSettings = new PluginSettings();
|
|---|
| 997 | return $pluginSettings->updateSetting($this, $setting, $value, $folder);
|
|---|
| 998 | }
|
|---|
| 999 |
|
|---|
| 1000 |
|
|---|
| 1001 | /* *************************************************************
|
|---|
| 1002 | *
|
|---|
| 1003 | * THEME SETTINGS FUNCTIONS
|
|---|
| 1004 | *
|
|---|
| 1005 | * *********************************************************** */
|
|---|
| 1006 |
|
|---|
| 1007 | /**
|
|---|
| 1008 | * Read and return plugin info from top of a plugin file.
|
|---|
| 1009 | *
|
|---|
| 1010 | * @param string $theme - theme folder
|
|---|
| 1011 | * @return array|false
|
|---|
| 1012 | */
|
|---|
| 1013 | public function readThemeMeta($theme = 'default')
|
|---|
| 1014 | {
|
|---|
| 1015 | require_once(LIBS . 'ThemeSettings.php');
|
|---|
| 1016 | $themeSettings = new ThemeSettings();
|
|---|
| 1017 | return $themeSettings->readThemeMeta($this, $theme);
|
|---|
| 1018 | }
|
|---|
| 1019 |
|
|---|
| 1020 |
|
|---|
| 1021 | /**
|
|---|
| 1022 | * Get and unserialize serialized settings
|
|---|
| 1023 | *
|
|---|
| 1024 | * @param string $theme theme folder name
|
|---|
| 1025 | * @param string $return 'value' or 'default'
|
|---|
| 1026 | * @return array - of theme settings
|
|---|
| 1027 | */
|
|---|
| 1028 | public function getThemeSettings($theme = '', $return = 'value')
|
|---|
| 1029 | {
|
|---|
| 1030 | require_once(LIBS . 'ThemeSettings.php');
|
|---|
| 1031 | $themeSettings = new ThemeSettings();
|
|---|
| 1032 | return $themeSettings->getThemeSettings($this, $theme, $return);
|
|---|
| 1033 | }
|
|---|
| 1034 |
|
|---|
| 1035 |
|
|---|
| 1036 | /**
|
|---|
| 1037 | * Update theme settings
|
|---|
| 1038 | *
|
|---|
| 1039 | * @param array $settings array of settings
|
|---|
| 1040 | * @param string $theme theme folder name
|
|---|
| 1041 | * @param string $column 'value', 'default' or 'both'
|
|---|
| 1042 |
|
|---|
| 1043 | */
|
|---|
| 1044 | public function updateThemeSettings($settings = array(), $theme = '', $column = 'value')
|
|---|
| 1045 | {
|
|---|
| 1046 | require_once(LIBS . 'ThemeSettings.php');
|
|---|
| 1047 | $themeSettings = new ThemeSettings();
|
|---|
| 1048 | return $themeSettings->updateThemeSettings($this, $settings, $theme, $column);
|
|---|
| 1049 | }
|
|---|
| 1050 |
|
|---|
| 1051 |
|
|---|
| 1052 | /* *************************************************************
|
|---|
| 1053 | *
|
|---|
| 1054 | * INCLUDE CSS & JAVASCRIPT FUNCTIONS
|
|---|
| 1055 | *
|
|---|
| 1056 | * *********************************************************** */
|
|---|
| 1057 |
|
|---|
| 1058 |
|
|---|
| 1059 | /**
|
|---|
| 1060 | * Check if we need to combine CSS and JavaScript files (from start function )
|
|---|
| 1061 | */
|
|---|
| 1062 | public function checkCssJs()
|
|---|
| 1063 | {
|
|---|
| 1064 | if (!$this->cage->get->keyExists('combine')) { return false; }
|
|---|
| 1065 |
|
|---|
| 1066 | $type = $this->cage->get->testAlpha('type');
|
|---|
| 1067 | $version = $this->cage->get->testInt('version');
|
|---|
| 1068 | $this->includes->combineIncludes($this, $type, $version);
|
|---|
| 1069 | return true;
|
|---|
| 1070 | }
|
|---|
| 1071 |
|
|---|
| 1072 |
|
|---|
| 1073 | /**
|
|---|
| 1074 | * Do Includes (called from template header.php)
|
|---|
| 1075 | */
|
|---|
| 1076 | public function doIncludes()
|
|---|
| 1077 | {
|
|---|
| 1078 | $version_js = $this->includes->combineIncludes($this, 'js');
|
|---|
| 1079 | $version_css = $this->includes->combineIncludes($this, 'css');
|
|---|
| 1080 | $this->includes->includeCombined($this, $version_js, $version_css, $this->isAdmin);
|
|---|
| 1081 | }
|
|---|
| 1082 |
|
|---|
| 1083 |
|
|---|
| 1084 | /**
|
|---|
| 1085 | * Build an array of css files to combine
|
|---|
| 1086 | *
|
|---|
| 1087 | * @param $folder - the folder name of the plugin
|
|---|
| 1088 | * @param $filename - optional css file without an extension
|
|---|
| 1089 | */
|
|---|
| 1090 | public function includeCss($folder = '', $filename = '')
|
|---|
| 1091 | {
|
|---|
| 1092 | return $this->includes->includeCss($this, $folder, $filename);
|
|---|
| 1093 | }
|
|---|
| 1094 |
|
|---|
| 1095 |
|
|---|
| 1096 | /**
|
|---|
| 1097 | * Build an array of JavaScript files to combine
|
|---|
| 1098 | *
|
|---|
| 1099 | * @param $folder - the folder name of the plugin
|
|---|
| 1100 | * @param $filename - optional js file without an extension
|
|---|
| 1101 | */
|
|---|
| 1102 | public function includeJs($folder = '', $filename = '')
|
|---|
| 1103 | {
|
|---|
| 1104 | return $this->includes->includeJs($this, $folder, $filename);
|
|---|
| 1105 | }
|
|---|
| 1106 |
|
|---|
| 1107 |
|
|---|
| 1108 | /* *************************************************************
|
|---|
| 1109 | *
|
|---|
| 1110 | * MESSAGE FUNCTIONS (success/error messages)
|
|---|
| 1111 | *
|
|---|
| 1112 | * *********************************************************** */
|
|---|
| 1113 |
|
|---|
| 1114 |
|
|---|
| 1115 | /**
|
|---|
| 1116 | * Display a SINGLE success or failure message
|
|---|
| 1117 | *
|
|---|
| 1118 | * @param string $msg
|
|---|
| 1119 | * @param string $msg_type ('green' or 'red')
|
|---|
| 1120 | */
|
|---|
| 1121 | public function showMessage($msg = '', $msg_type = 'green')
|
|---|
| 1122 | {
|
|---|
| 1123 | require_once(LIBS . 'Messages.php');
|
|---|
| 1124 | $messages = new Messages();
|
|---|
| 1125 | $messages->showMessage($this, $msg, $msg_type);
|
|---|
| 1126 | }
|
|---|
| 1127 |
|
|---|
| 1128 |
|
|---|
| 1129 | /**
|
|---|
| 1130 | * Displays ALL success or failure messages
|
|---|
| 1131 | */
|
|---|
| 1132 | public function showMessages()
|
|---|
| 1133 | {
|
|---|
| 1134 | require_once(LIBS . 'Messages.php');
|
|---|
| 1135 | $messages = new Messages();
|
|---|
| 1136 | $messages->showMessages($this);
|
|---|
| 1137 | }
|
|---|
| 1138 |
|
|---|
| 1139 |
|
|---|
| 1140 | /* *************************************************************
|
|---|
| 1141 | *
|
|---|
| 1142 | * ANNOUNCEMENT FUNCTIONS
|
|---|
| 1143 | *
|
|---|
| 1144 | * *********************************************************** */
|
|---|
| 1145 |
|
|---|
| 1146 |
|
|---|
| 1147 | /**
|
|---|
| 1148 | * Displays an announcement at the top of the screen
|
|---|
| 1149 | *
|
|---|
| 1150 | * @param string $announcement - optional for non-admin pages
|
|---|
| 1151 | * @return array
|
|---|
| 1152 | */
|
|---|
| 1153 | public function checkAnnouncements($announcement = '')
|
|---|
| 1154 | {
|
|---|
| 1155 | require_once(LIBS . 'Announcements.php');
|
|---|
| 1156 | $announce = new Announcements();
|
|---|
| 1157 | if ($this->isAdmin) {
|
|---|
| 1158 | return $announce->checkAdminAnnouncements($this);
|
|---|
| 1159 | } else {
|
|---|
| 1160 | return $announce->checkAnnouncements($this, $announcement);
|
|---|
| 1161 | }
|
|---|
| 1162 | }
|
|---|
| 1163 |
|
|---|
| 1164 |
|
|---|
| 1165 | /* *************************************************************
|
|---|
| 1166 | *
|
|---|
| 1167 | * DEBUG FUNCTIONS
|
|---|
| 1168 | *
|
|---|
| 1169 | * *********************************************************** */
|
|---|
| 1170 |
|
|---|
| 1171 |
|
|---|
| 1172 | /**
|
|---|
| 1173 | * Shows number of database queries and the time it takes for a page to load
|
|---|
| 1174 | */
|
|---|
| 1175 | public function showQueriesAndTime()
|
|---|
| 1176 | {
|
|---|
| 1177 | if ($this->isDebug) {
|
|---|
| 1178 | $this->debug->showQueriesAndTime($this);
|
|---|
| 1179 | }
|
|---|
| 1180 | }
|
|---|
| 1181 |
|
|---|
| 1182 | /**
|
|---|
| 1183 | * Open file for logging
|
|---|
| 1184 | *
|
|---|
| 1185 | * @param string $type "speed", "error", etc.
|
|---|
| 1186 | * @param string $mode e.g. 'a' or 'w'.
|
|---|
| 1187 | * @link http://php.net/manual/en/function.fopen.php
|
|---|
| 1188 | */
|
|---|
| 1189 | public function openLog($type = 'debug', $mode = 'a+')
|
|---|
| 1190 | {
|
|---|
| 1191 | $this->debug->openLog($type, $mode);
|
|---|
| 1192 | }
|
|---|
| 1193 |
|
|---|
| 1194 |
|
|---|
| 1195 | /**
|
|---|
| 1196 | * Log performance and errors
|
|---|
| 1197 | *
|
|---|
| 1198 | * @param string $type "speed", "error", etc.
|
|---|
| 1199 | */
|
|---|
| 1200 | public function writeLog($type = 'error', $string = '')
|
|---|
| 1201 | {
|
|---|
| 1202 | $this->debug->writeLog($type, $string);
|
|---|
| 1203 | }
|
|---|
| 1204 |
|
|---|
| 1205 |
|
|---|
| 1206 | /**
|
|---|
| 1207 | * Close log file
|
|---|
| 1208 | *
|
|---|
| 1209 | * @param string $type "speed", "error", etc.
|
|---|
| 1210 | */
|
|---|
| 1211 | public function closeLog($type = 'error')
|
|---|
| 1212 | {
|
|---|
| 1213 | $this->debug->closeLog($type);
|
|---|
| 1214 | }
|
|---|
| 1215 |
|
|---|
| 1216 |
|
|---|
| 1217 | /**
|
|---|
| 1218 | * Generate a system report
|
|---|
| 1219 | *
|
|---|
| 1220 | * @param string $type "log" or "object"
|
|---|
| 1221 | */
|
|---|
| 1222 | public function generateReport($type = 'log')
|
|---|
| 1223 | {
|
|---|
| 1224 | return $this->debug->generateReport($this, $type);
|
|---|
| 1225 | }
|
|---|
| 1226 |
|
|---|
| 1227 |
|
|---|
| 1228 | /* *************************************************************
|
|---|
| 1229 | *
|
|---|
| 1230 | * RSS FEED FUNCTIONS
|
|---|
| 1231 | *
|
|---|
| 1232 | * *********************************************************** */
|
|---|
| 1233 |
|
|---|
| 1234 |
|
|---|
| 1235 | /**
|
|---|
| 1236 | * Includes the SimplePie RSS file and sets the cache
|
|---|
| 1237 | *
|
|---|
| 1238 | * @param string $feed
|
|---|
| 1239 | * @param bool $cache
|
|---|
| 1240 | * @param int $cache_duration
|
|---|
| 1241 | *
|
|---|
| 1242 | * @return object|false $sp
|
|---|
| 1243 | */
|
|---|
| 1244 | public function newSimplePie($feed='', $cache=RSS_CACHE, $cache_duration=RSS_CACHE_DURATION)
|
|---|
| 1245 | {
|
|---|
| 1246 | require_once(LIBS . 'Feeds.php');
|
|---|
| 1247 | $feeds = new Feeds();
|
|---|
| 1248 | return $feeds->newSimplePie($feed, $cache, $cache_duration);
|
|---|
| 1249 | }
|
|---|
| 1250 |
|
|---|
| 1251 |
|
|---|
| 1252 | /**
|
|---|
| 1253 | * Display Hotaru forums feed on Admin front page
|
|---|
| 1254 | *
|
|---|
| 1255 | * @param int $max_items
|
|---|
| 1256 | * @param int $items_with_content
|
|---|
| 1257 | * @param int $max_chars
|
|---|
| 1258 | */
|
|---|
| 1259 | public function adminNews($max_items = 10, $items_with_content = 3, $max_chars = 300)
|
|---|
| 1260 | {
|
|---|
| 1261 | require_once(LIBS . 'Feeds.php');
|
|---|
| 1262 | $feeds = new Feeds();
|
|---|
| 1263 | $feeds->adminNews($this->lang, $max_items, $items_with_content, $max_chars);
|
|---|
| 1264 | }
|
|---|
| 1265 |
|
|---|
| 1266 |
|
|---|
| 1267 | /* *************************************************************
|
|---|
| 1268 | *
|
|---|
| 1269 | * ADMIN FUNCTIONS
|
|---|
| 1270 | *
|
|---|
| 1271 | * *********************************************************** */
|
|---|
| 1272 |
|
|---|
| 1273 |
|
|---|
| 1274 | /**
|
|---|
| 1275 | * Admin Pages
|
|---|
| 1276 | */
|
|---|
| 1277 | public function adminPages($page = 'admin_login')
|
|---|
| 1278 | {
|
|---|
| 1279 | require_once(LIBS . 'AdminPages.php');
|
|---|
| 1280 | $admin = new AdminPages();
|
|---|
| 1281 | $admin->pages($this, $page);
|
|---|
| 1282 | }
|
|---|
| 1283 |
|
|---|
| 1284 |
|
|---|
| 1285 | /**
|
|---|
| 1286 | * Admin login/logout
|
|---|
| 1287 | *
|
|---|
| 1288 | * @param string $action
|
|---|
| 1289 | */
|
|---|
| 1290 | public function adminLoginLogout($action = 'logout')
|
|---|
| 1291 | {
|
|---|
| 1292 | require_once(LIBS . 'AdminAuth.php');
|
|---|
| 1293 | $admin = new AdminAuth();
|
|---|
| 1294 | return ($action == 'login') ? $admin->adminLogin($this) : $admin->adminLogout($this);
|
|---|
| 1295 | }
|
|---|
| 1296 |
|
|---|
| 1297 |
|
|---|
| 1298 | /**
|
|---|
| 1299 | * Admin login form
|
|---|
| 1300 | */
|
|---|
| 1301 | public function adminLoginForm()
|
|---|
| 1302 | {
|
|---|
| 1303 | require_once(LIBS . 'AdminAuth.php');
|
|---|
| 1304 | $admin = new AdminAuth();
|
|---|
| 1305 | $admin->adminLoginForm($this);
|
|---|
| 1306 | }
|
|---|
| 1307 |
|
|---|
| 1308 |
|
|---|
| 1309 | /* *************************************************************
|
|---|
| 1310 | *
|
|---|
| 1311 | * MAINTENANCE FUNCTIONS
|
|---|
| 1312 | *
|
|---|
| 1313 | * *********************************************************** */
|
|---|
| 1314 |
|
|---|
| 1315 |
|
|---|
| 1316 | /**
|
|---|
| 1317 | * Check if site is open or closed. Exit if closed
|
|---|
| 1318 | *
|
|---|
| 1319 | * @param object $h
|
|---|
| 1320 | */
|
|---|
| 1321 | public function checkAccess()
|
|---|
| 1322 | {
|
|---|
| 1323 | if (SITE_OPEN == 'true') { return true; } // site is open, go back and continue
|
|---|
| 1324 |
|
|---|
| 1325 | // site closed, but user has admin access so go back and continue as normal
|
|---|
| 1326 | if ($this->currentUser->getPermission('can_access_admin') == 'yes') { return true; }
|
|---|
| 1327 |
|
|---|
| 1328 | if ($this->pageName == 'admin_login' || $this->pageName == 'api' ) { return true; }
|
|---|
| 1329 |
|
|---|
| 1330 | require_once(LIBS . 'Maintenance.php');
|
|---|
| 1331 | $maintenance = new Maintenance();
|
|---|
| 1332 | return $maintenance->siteClosed($this, $this->lang); // displays "Site Closed for Maintenance"
|
|---|
| 1333 | }
|
|---|
| 1334 |
|
|---|
| 1335 |
|
|---|
| 1336 | /**
|
|---|
| 1337 | * Open or close the site for maintenance
|
|---|
| 1338 | *
|
|---|
| 1339 | * @param string $switch - 'open' or 'close'
|
|---|
| 1340 | */
|
|---|
| 1341 | public function openCloseSite($switch = 'open')
|
|---|
| 1342 | {
|
|---|
| 1343 | require_once(LIBS . 'Maintenance.php');
|
|---|
| 1344 | $maintenance = new Maintenance();
|
|---|
| 1345 | $maintenance->openCloseSite($this, $switch);
|
|---|
| 1346 | }
|
|---|
| 1347 |
|
|---|
| 1348 |
|
|---|
| 1349 | /**
|
|---|
| 1350 | * Optimize all database tables
|
|---|
| 1351 | */
|
|---|
| 1352 | public function optimizeTables()
|
|---|
| 1353 | {
|
|---|
| 1354 | require_once(LIBS . 'Maintenance.php');
|
|---|
| 1355 | $maintenance = new Maintenance();
|
|---|
| 1356 | $maintenance->optimizeTables($this);
|
|---|
| 1357 | }
|
|---|
| 1358 |
|
|---|
| 1359 |
|
|---|
| 1360 | /**
|
|---|
| 1361 | * Empty plugin database table
|
|---|
| 1362 | *
|
|---|
| 1363 | * @param string $table_name - table to empty
|
|---|
| 1364 | * @param string $msg - show "emptied" message or not
|
|---|
| 1365 | */
|
|---|
| 1366 | public function emptyTable($table_name = '', $msg = true)
|
|---|
| 1367 | {
|
|---|
| 1368 | require_once(LIBS . 'Maintenance.php');
|
|---|
| 1369 | $maintenance = new Maintenance();
|
|---|
| 1370 | $maintenance->emptyTable($this, $table_name, $msg);
|
|---|
| 1371 | }
|
|---|
| 1372 |
|
|---|
| 1373 |
|
|---|
| 1374 | /**
|
|---|
| 1375 | * Delete plugin database table
|
|---|
| 1376 | *
|
|---|
| 1377 | * @param string $table_name - table to drop
|
|---|
| 1378 | * @param string $msg - show "dropped" message or not
|
|---|
| 1379 | */
|
|---|
| 1380 | public function dropTable($table_name = '', $msg = true)
|
|---|
| 1381 | {
|
|---|
| 1382 | require_once(LIBS . 'Maintenance.php');
|
|---|
| 1383 | $maintenance = new Maintenance();
|
|---|
| 1384 | $maintenance->dropTable($this, $table_name, $msg);
|
|---|
| 1385 | }
|
|---|
| 1386 |
|
|---|
| 1387 |
|
|---|
| 1388 | /**
|
|---|
| 1389 | * Remove plugin settings
|
|---|
| 1390 | *
|
|---|
| 1391 | * @param string $folder - plugin folder name
|
|---|
| 1392 | * @param bool $msg - show "Removed" message or not
|
|---|
| 1393 | */
|
|---|
| 1394 | public function removeSettings($folder = '', $msg = true)
|
|---|
| 1395 | {
|
|---|
| 1396 | require_once(LIBS . 'Maintenance.php');
|
|---|
| 1397 | $maintenance = new Maintenance();
|
|---|
| 1398 | $maintenance->removeSettings($this, $folder, $msg);
|
|---|
| 1399 | }
|
|---|
| 1400 |
|
|---|
| 1401 |
|
|---|
| 1402 | /**
|
|---|
| 1403 | * Deletes rows from pluginsettings that match a given setting or plugin
|
|---|
| 1404 | *
|
|---|
| 1405 | * @param string $setting name of the setting to remove
|
|---|
| 1406 | * @param string $folder name of plugin folder
|
|---|
| 1407 | */
|
|---|
| 1408 | public function deleteSettings($setting = '', $folder = '')
|
|---|
| 1409 | {
|
|---|
| 1410 | require_once(LIBS . 'Maintenance.php');
|
|---|
| 1411 | $maintenance = new Maintenance();
|
|---|
| 1412 | $maintenance->deleteSettings($this, $setting, $folder);
|
|---|
| 1413 | }
|
|---|
| 1414 |
|
|---|
| 1415 |
|
|---|
| 1416 | /**
|
|---|
| 1417 | * Delete all files in the specified directory except placeholder.txt
|
|---|
| 1418 | *
|
|---|
| 1419 | * @param string $dir - path to the cache folder
|
|---|
| 1420 | * @return bool
|
|---|
| 1421 | */
|
|---|
| 1422 | public function deleteFiles($dir = '')
|
|---|
| 1423 | {
|
|---|
| 1424 | require_once(LIBS . 'Maintenance.php');
|
|---|
| 1425 | $maintenance = new Maintenance();
|
|---|
| 1426 | $maintenance->deleteFiles($dir);
|
|---|
| 1427 | }
|
|---|
| 1428 |
|
|---|
| 1429 |
|
|---|
| 1430 | /**
|
|---|
| 1431 | * Calls the delete_files function, then displays a message.
|
|---|
| 1432 | *
|
|---|
| 1433 | * @param string $folder - path to the cache folder
|
|---|
| 1434 | * @param string $msg - show "cleared" message or not
|
|---|
| 1435 | */
|
|---|
| 1436 | public function clearCache($folder = '', $msg = true)
|
|---|
| 1437 | {
|
|---|
| 1438 | require_once(LIBS . 'Maintenance.php');
|
|---|
| 1439 | $maintenance = new Maintenance();
|
|---|
| 1440 | $maintenance->clearCache($this, $folder, $msg);
|
|---|
| 1441 | }
|
|---|
| 1442 |
|
|---|
| 1443 |
|
|---|
| 1444 | /**
|
|---|
| 1445 | * Get all files in the specified directory except placeholder.txt
|
|---|
| 1446 | *
|
|---|
| 1447 | * @param string $dir - path to the folder
|
|---|
| 1448 | * @param array $exclude - array of file/folder names to exclude
|
|---|
| 1449 | * @return array
|
|---|
| 1450 | */
|
|---|
| 1451 | public function getFiles($dir = '', $exclude = array())
|
|---|
| 1452 | {
|
|---|
| 1453 | require_once(LIBS . 'Maintenance.php');
|
|---|
| 1454 | $maintenance = new Maintenance();
|
|---|
| 1455 | return $maintenance->getFiles($dir, $exclude);
|
|---|
| 1456 | }
|
|---|
| 1457 |
|
|---|
| 1458 |
|
|---|
| 1459 | /**
|
|---|
| 1460 | * System Report is under Debug Functions
|
|---|
| 1461 | */
|
|---|
| 1462 |
|
|---|
| 1463 |
|
|---|
| 1464 | /* *************************************************************
|
|---|
| 1465 | *
|
|---|
| 1466 | * CACHING FUNCTIONS (Note: "clearCache" is in Maintenance above)
|
|---|
| 1467 | *
|
|---|
| 1468 | * *********************************************************** */
|
|---|
| 1469 |
|
|---|
| 1470 |
|
|---|
| 1471 | /**
|
|---|
| 1472 | * Hotaru CMS Smart Caching
|
|---|
| 1473 | *
|
|---|
| 1474 | * This function does one query on the database to get the last updated time for a
|
|---|
| 1475 | * specified table. If that time is more recent than the $timeout length (e.g. 10 minutes),
|
|---|
| 1476 | * the database will be used. If there hasn't been an update, any cached results from the
|
|---|
| 1477 | * last 10 minutes will be used.
|
|---|
| 1478 | *
|
|---|
| 1479 | * @param string $switch either "on", "off" or "html"
|
|---|
| 1480 | * @param string $table DB table name
|
|---|
| 1481 | * @param int $timeout time before DB cache expires
|
|---|
| 1482 | * @param string $html_sql output as HTML, or an SQL query
|
|---|
| 1483 | * @param string $label optional label to append to filename
|
|---|
| 1484 | * @return bool
|
|---|
| 1485 | */
|
|---|
| 1486 | public function smartCache($switch = 'off', $table = '', $timeout = 0, $html_sql = '', $label = '')
|
|---|
| 1487 | {
|
|---|
| 1488 | require_once(LIBS . 'Caching.php');
|
|---|
| 1489 | $caching = new Caching();
|
|---|
| 1490 | return $caching->smartCache($this, $switch, $table, $timeout, $html_sql, $label);
|
|---|
| 1491 | }
|
|---|
| 1492 |
|
|---|
| 1493 |
|
|---|
| 1494 | /**
|
|---|
| 1495 | * Cache HTML without checking for database updates
|
|---|
| 1496 | *
|
|---|
| 1497 | * This function caches blocks of HTML code
|
|---|
| 1498 | *
|
|---|
| 1499 | * @param int $timeout timeout in minutes before cache file is deleted
|
|---|
| 1500 | * @param string $html block of HTML to cache
|
|---|
| 1501 | * @param string $label name to identify the cached file
|
|---|
| 1502 | * @return bool
|
|---|
| 1503 | */
|
|---|
| 1504 | public function cacheHTML($timeout = 0, $html = '', $label = '')
|
|---|
| 1505 | {
|
|---|
| 1506 | require_once(LIBS . 'Caching.php');
|
|---|
| 1507 | $caching = new Caching();
|
|---|
| 1508 | return $caching->cacheHTML($this, $timeout, $html, $label);
|
|---|
| 1509 | }
|
|---|
| 1510 |
|
|---|
| 1511 |
|
|---|
| 1512 | /* *************************************************************
|
|---|
| 1513 | *
|
|---|
| 1514 | * BLOCKED FUNCTIONS (i.e. Admin's Blocked list)
|
|---|
| 1515 | *
|
|---|
| 1516 | * *********************************************************** */
|
|---|
| 1517 |
|
|---|
| 1518 | /**
|
|---|
| 1519 | * Check if a value is blocked from registration and post submission)
|
|---|
| 1520 | *
|
|---|
| 1521 | * @param string $type - i.e. ip, url, email, user
|
|---|
| 1522 | * @param string $value
|
|---|
| 1523 | * @param bool $like - used for LIKE sql if true
|
|---|
| 1524 | * @return bool
|
|---|
| 1525 | */
|
|---|
| 1526 | public function isBlocked($type = '', $value = '', $operator = '=')
|
|---|
| 1527 | {
|
|---|
| 1528 | require_once(LIBS . 'Blocked.php');
|
|---|
| 1529 | $blocked = new Blocked();
|
|---|
| 1530 | return $blocked->isBlocked($this->db, $type, $value, $operator);
|
|---|
| 1531 | }
|
|---|
| 1532 |
|
|---|
| 1533 |
|
|---|
| 1534 | /**
|
|---|
| 1535 | * Add or update blocked items
|
|---|
| 1536 | *
|
|---|
| 1537 | * @param string $type - e.g. url, email, ip
|
|---|
| 1538 | * @param string $value - item to block
|
|---|
| 1539 | * @param bool $msg - show a success/failure message on Maintenance page
|
|---|
| 1540 | * @return bool
|
|---|
| 1541 | */
|
|---|
| 1542 | public function addToBlockedList($type = '', $value = 0, $msg = false)
|
|---|
| 1543 | {
|
|---|
| 1544 | require_once(LIBS . 'Blocked.php');
|
|---|
| 1545 | $blocked = new Blocked();
|
|---|
| 1546 | return $blocked->addToBlockedList($this, $type, $value, $msg);
|
|---|
| 1547 | }
|
|---|
| 1548 |
|
|---|
| 1549 |
|
|---|
| 1550 | /* *************************************************************
|
|---|
| 1551 | *
|
|---|
| 1552 | * LANGUAGE FUNCTIONS
|
|---|
| 1553 | *
|
|---|
| 1554 | * *********************************************************** */
|
|---|
| 1555 |
|
|---|
| 1556 |
|
|---|
| 1557 | /**
|
|---|
| 1558 | * Include a language file in a plugin
|
|---|
| 1559 | *
|
|---|
| 1560 | * @param string $folder name of plugin folder
|
|---|
| 1561 | * @param string $filename optional filename without file extension
|
|---|
| 1562 | *
|
|---|
| 1563 | * Note: the language file should be in a plugin folder named 'languages'.
|
|---|
| 1564 | * '_language.php' is appended automatically to the folder of file name.
|
|---|
| 1565 | */
|
|---|
| 1566 | public function includeLanguage($folder = '', $filename = '')
|
|---|
| 1567 | {
|
|---|
| 1568 | require_once(LIBS . 'Language.php');
|
|---|
| 1569 | $language = new Language();
|
|---|
| 1570 | $language->includeLanguage($this, $folder, $filename);
|
|---|
| 1571 | }
|
|---|
| 1572 |
|
|---|
| 1573 |
|
|---|
| 1574 | /**
|
|---|
| 1575 | * Include a language file for a theme
|
|---|
| 1576 | *
|
|---|
| 1577 | * @param string $filename optional filename without '_language.php' file extension
|
|---|
| 1578 | *
|
|---|
| 1579 | * Note: the language file should be in a plugin folder named 'languages'.
|
|---|
| 1580 | * '_language.php' is appended automatically to the folder of file name.
|
|---|
| 1581 | */
|
|---|
| 1582 | public function includeThemeLanguage($filename = 'main')
|
|---|
| 1583 | {
|
|---|
| 1584 | require_once(LIBS . 'Language.php');
|
|---|
| 1585 | $language = new Language();
|
|---|
| 1586 | $language->includeThemeLanguage($this, $filename);
|
|---|
| 1587 | }
|
|---|
| 1588 |
|
|---|
| 1589 |
|
|---|
| 1590 | /* *************************************************************
|
|---|
| 1591 | *
|
|---|
| 1592 | * CSRF FUNCTIONS
|
|---|
| 1593 | *
|
|---|
| 1594 | * *********************************************************** */
|
|---|
| 1595 |
|
|---|
| 1596 |
|
|---|
| 1597 | /**
|
|---|
| 1598 | * Shortcut for CSRF functions
|
|---|
| 1599 | *
|
|---|
| 1600 | * @param string $type - either "set" or "check" CSRF key
|
|---|
| 1601 | * @param string $script - optional name of page using the key
|
|---|
| 1602 | * @param int $life - minutes before the token expires
|
|---|
| 1603 | * @return string $key (if using $type "fetch")
|
|---|
| 1604 | */
|
|---|
| 1605 | public function csrf($type = 'check', $script = '', $life = 30)
|
|---|
| 1606 | {
|
|---|
| 1607 | $csrf = new csrf();
|
|---|
| 1608 | return $csrf->csrfInit($this, $type, $script, $life);
|
|---|
| 1609 | }
|
|---|
| 1610 |
|
|---|
| 1611 |
|
|---|
| 1612 | /* *************************************************************
|
|---|
| 1613 | *
|
|---|
| 1614 | * POST FUNCTIONS
|
|---|
| 1615 | *
|
|---|
| 1616 | * *********************************************************** */
|
|---|
| 1617 |
|
|---|
| 1618 |
|
|---|
| 1619 | /**
|
|---|
| 1620 | * Get all the parameters for the current post
|
|---|
| 1621 | *
|
|---|
| 1622 | * @param int $post_id - Optional row from the posts table in the database
|
|---|
| 1623 | * @param array $post_row - a post already fetched from the db, just needs reading
|
|---|
| 1624 | * @return bool
|
|---|
| 1625 | */
|
|---|
| 1626 | public function readPost($post_id = 0, $post_row = NULL)
|
|---|
| 1627 | {
|
|---|
| 1628 | return $this->post->readPost($this, $post_id, $post_row);
|
|---|
| 1629 | }
|
|---|
| 1630 |
|
|---|
| 1631 |
|
|---|
| 1632 | /**
|
|---|
| 1633 | * Gets a single post from the database
|
|---|
| 1634 | *
|
|---|
| 1635 | * @param int $post_id - post id of the post to get
|
|---|
| 1636 | * @return array|false
|
|---|
| 1637 | */
|
|---|
| 1638 | public function getPost($post_id = 0)
|
|---|
| 1639 | {
|
|---|
| 1640 | return $this->post->getPost($this, $post_id);
|
|---|
| 1641 | }
|
|---|
| 1642 |
|
|---|
| 1643 |
|
|---|
| 1644 | /**
|
|---|
| 1645 | * Add a post to the database
|
|---|
| 1646 | *
|
|---|
| 1647 | * @return true
|
|---|
| 1648 | */
|
|---|
| 1649 | public function addPost()
|
|---|
| 1650 | {
|
|---|
| 1651 | $this->post->addPost($this);
|
|---|
| 1652 | }
|
|---|
| 1653 |
|
|---|
| 1654 |
|
|---|
| 1655 | /**
|
|---|
| 1656 | * Update a post in the database
|
|---|
| 1657 | *
|
|---|
| 1658 | * @return true
|
|---|
| 1659 | */
|
|---|
| 1660 | public function updatePost()
|
|---|
| 1661 | {
|
|---|
| 1662 | $this->post->updatePost($this);
|
|---|
| 1663 | }
|
|---|
| 1664 |
|
|---|
| 1665 |
|
|---|
| 1666 | /**
|
|---|
| 1667 | * Physically delete a post from the database
|
|---|
| 1668 | *
|
|---|
| 1669 | * There's a plugin hook in here to delete their parts, e.g. votes, coments, tags, etc.
|
|---|
| 1670 | */
|
|---|
| 1671 | public function deletePost()
|
|---|
| 1672 | {
|
|---|
| 1673 | $this->post->deletePost($this);
|
|---|
| 1674 | }
|
|---|
| 1675 |
|
|---|
| 1676 |
|
|---|
| 1677 | /**
|
|---|
| 1678 | * Physically delete all posts by a specified user
|
|---|
| 1679 | *
|
|---|
| 1680 | * @param array $user_id
|
|---|
| 1681 | * @return bool
|
|---|
| 1682 | */
|
|---|
| 1683 | public function deletePosts($user_id = 0)
|
|---|
| 1684 | {
|
|---|
| 1685 | return $this->post->deletePosts($this, $user_id);
|
|---|
| 1686 | }
|
|---|
| 1687 |
|
|---|
| 1688 |
|
|---|
| 1689 | /**
|
|---|
| 1690 | * Delete posts with "processing" status that are older than 30 minutes
|
|---|
| 1691 | * This is called automatically when a new post is submitted
|
|---|
| 1692 | */
|
|---|
| 1693 | public function deleteProcessingPosts()
|
|---|
| 1694 | {
|
|---|
| 1695 | $this->post->deleteProcessingPosts($this);
|
|---|
| 1696 | }
|
|---|
| 1697 |
|
|---|
| 1698 |
|
|---|
| 1699 | /**
|
|---|
| 1700 | * Update a post's status
|
|---|
| 1701 | *
|
|---|
| 1702 | * @param string $status
|
|---|
| 1703 | * @param int $post_id (optional)
|
|---|
| 1704 | * @return true
|
|---|
| 1705 | */
|
|---|
| 1706 | public function changePostStatus($status = "processing", $post_id = 0)
|
|---|
| 1707 | {
|
|---|
| 1708 | return $this->post->changePostStatus($this, $status, $post_id);
|
|---|
| 1709 | }
|
|---|
| 1710 |
|
|---|
| 1711 |
|
|---|
| 1712 | /**
|
|---|
| 1713 | * Count how many approved posts a user has had
|
|---|
| 1714 | *
|
|---|
| 1715 | * @param int $userid (optional)
|
|---|
| 1716 | * @return int
|
|---|
| 1717 | */
|
|---|
| 1718 | public function postsApproved($userid = 0)
|
|---|
| 1719 | {
|
|---|
| 1720 | return $this->post->postsApproved($this, $userid);
|
|---|
| 1721 | }
|
|---|
| 1722 |
|
|---|
| 1723 |
|
|---|
| 1724 | /**
|
|---|
| 1725 | * Count posts in the last X hours/minutes for this user
|
|---|
| 1726 | *
|
|---|
| 1727 | * @param int $hours
|
|---|
| 1728 | * @param int $minutes
|
|---|
| 1729 | * @param int $user_id (optional)
|
|---|
| 1730 | * @return int
|
|---|
| 1731 | */
|
|---|
| 1732 | public function countPosts($hours = 0, $minutes = 0, $user_id = 0)
|
|---|
| 1733 | {
|
|---|
| 1734 | return $this->post->countPosts($this, $hours, $minutes, $user_id);
|
|---|
| 1735 | }
|
|---|
| 1736 |
|
|---|
| 1737 |
|
|---|
| 1738 | /**
|
|---|
| 1739 | * Checks for existence of a url
|
|---|
| 1740 | *
|
|---|
| 1741 | * @return array|false - array of posts
|
|---|
| 1742 | */
|
|---|
| 1743 | public function urlExists($url = '')
|
|---|
| 1744 | {
|
|---|
| 1745 | return $this->post->urlExists($this, $url);
|
|---|
| 1746 | }
|
|---|
| 1747 |
|
|---|
| 1748 |
|
|---|
| 1749 | /**
|
|---|
| 1750 | * Checks for existence of a title
|
|---|
| 1751 | *
|
|---|
| 1752 | * @param str $title
|
|---|
| 1753 | * @return int - id of post with matching title
|
|---|
| 1754 | */
|
|---|
| 1755 | public function titleExists($title = '')
|
|---|
| 1756 | {
|
|---|
| 1757 | return $this->post->titleExists($this, $title);
|
|---|
| 1758 | }
|
|---|
| 1759 |
|
|---|
| 1760 |
|
|---|
| 1761 | /**
|
|---|
| 1762 | * Checks for existence of a post with given post_url
|
|---|
| 1763 | *
|
|---|
| 1764 | * @param str $post_url (slug)
|
|---|
| 1765 | * @return int - id of post with matching url
|
|---|
| 1766 | */
|
|---|
| 1767 | public function isPostUrl($post_url = '')
|
|---|
| 1768 | {
|
|---|
| 1769 | return $this->post->isPostUrl($this, $post_url);
|
|---|
| 1770 | }
|
|---|
| 1771 |
|
|---|
| 1772 |
|
|---|
| 1773 | /**
|
|---|
| 1774 | * Get Unique Post Statuses
|
|---|
| 1775 | *
|
|---|
| 1776 | * @return array|false
|
|---|
| 1777 | */
|
|---|
| 1778 | public function getUniqueStatuses()
|
|---|
| 1779 | {
|
|---|
| 1780 | return $this->post->getUniqueStatuses($this);
|
|---|
| 1781 | }
|
|---|
| 1782 |
|
|---|
| 1783 |
|
|---|
| 1784 | /**
|
|---|
| 1785 | * Prepares and calls functions to send a trackback
|
|---|
| 1786 | * Uses $h->post->id
|
|---|
| 1787 | */
|
|---|
| 1788 | public function sendTrackback()
|
|---|
| 1789 | {
|
|---|
| 1790 | require_once(LIBS . 'Trackback.php');
|
|---|
| 1791 | $trackback = new Trackback();
|
|---|
| 1792 | return $trackback->sendTrackback($this);
|
|---|
| 1793 | }
|
|---|
| 1794 |
|
|---|
| 1795 |
|
|---|
| 1796 | /* *************************************************************
|
|---|
| 1797 | *
|
|---|
| 1798 | * AVATAR FUNCTIONS
|
|---|
| 1799 | *
|
|---|
| 1800 | * *********************************************************** */
|
|---|
| 1801 |
|
|---|
| 1802 |
|
|---|
| 1803 | /**
|
|---|
| 1804 | * setAvatar
|
|---|
| 1805 | *
|
|---|
| 1806 | * @param $user_id
|
|---|
| 1807 | * @param $size avatar size in pixels
|
|---|
| 1808 | * @param $rating avatar rating (g, pg, r or x in Gravatar)
|
|---|
| 1809 | */
|
|---|
| 1810 | public function setAvatar($user_id = 0, $size = 32, $rating = 'g')
|
|---|
| 1811 | {
|
|---|
| 1812 | $this->avatar = new Avatar($this, $user_id, $size, $rating);
|
|---|
| 1813 | }
|
|---|
| 1814 |
|
|---|
| 1815 |
|
|---|
| 1816 | /**
|
|---|
| 1817 | * get the plain avatar with no surrounding HTML div
|
|---|
| 1818 | *
|
|---|
| 1819 | * @return return the avatar
|
|---|
| 1820 | */
|
|---|
| 1821 | public function getAvatar()
|
|---|
| 1822 | {
|
|---|
| 1823 | return $this->avatar->getAvatar($this);
|
|---|
| 1824 | }
|
|---|
| 1825 |
|
|---|
| 1826 |
|
|---|
| 1827 | /**
|
|---|
| 1828 | * option to display the avatar linked to ther user's profile
|
|---|
| 1829 | *
|
|---|
| 1830 | * @return return the avatar
|
|---|
| 1831 | */
|
|---|
| 1832 | public function linkAvatar()
|
|---|
| 1833 | {
|
|---|
| 1834 | return $this->avatar->linkAvatar($this);
|
|---|
| 1835 | }
|
|---|
| 1836 |
|
|---|
| 1837 |
|
|---|
| 1838 | /**
|
|---|
| 1839 | * option to display the profile-linked avatar wrapped in a div
|
|---|
| 1840 | *
|
|---|
| 1841 | * @return return the avatar
|
|---|
| 1842 | */
|
|---|
| 1843 | public function wrapAvatar()
|
|---|
| 1844 | {
|
|---|
| 1845 | return $this->avatar->wrapAvatar($this);
|
|---|
| 1846 | }
|
|---|
| 1847 |
|
|---|
| 1848 |
|
|---|
| 1849 | /* *************************************************************
|
|---|
| 1850 | *
|
|---|
| 1851 | * CATEGORY FUNCTIONS
|
|---|
| 1852 | *
|
|---|
| 1853 | * *********************************************************** */
|
|---|
| 1854 |
|
|---|
| 1855 | /**
|
|---|
| 1856 | * Returns the category id for a given category safe name.
|
|---|
| 1857 | *
|
|---|
| 1858 | * @param string $cat_name
|
|---|
| 1859 | * @return int
|
|---|
| 1860 | */
|
|---|
| 1861 | public function getCatId($cat_safe_name)
|
|---|
| 1862 | {
|
|---|
| 1863 | require_once(LIBS . 'Category.php');
|
|---|
| 1864 | $category = new Category();
|
|---|
| 1865 | return $category->getCatId($this, $cat_safe_name);
|
|---|
| 1866 | }
|
|---|
| 1867 |
|
|---|
| 1868 |
|
|---|
| 1869 | /**
|
|---|
| 1870 | * Returns the category name for a given category id or safe name.
|
|---|
| 1871 | *
|
|---|
| 1872 | * @param int $cat_id
|
|---|
| 1873 | * @param string $cat_safe_name
|
|---|
| 1874 | * @return string
|
|---|
| 1875 | */
|
|---|
| 1876 | public function getCatName($cat_id = 0, $cat_safe_name = '')
|
|---|
| 1877 | {
|
|---|
| 1878 | require_once(LIBS . 'Category.php');
|
|---|
| 1879 | $category = new Category();
|
|---|
| 1880 | return $category->getCatName($this, $cat_id, $cat_safe_name);
|
|---|
| 1881 | }
|
|---|
| 1882 |
|
|---|
| 1883 |
|
|---|
| 1884 | /**
|
|---|
| 1885 | * Returns the category safe name for a given category id
|
|---|
| 1886 | *
|
|---|
| 1887 | * @param int $cat_id
|
|---|
| 1888 | * @return string
|
|---|
| 1889 | */
|
|---|
| 1890 | public function getCatSafeName($cat_id = 0)
|
|---|
| 1891 | {
|
|---|
| 1892 | require_once(LIBS . 'Category.php');
|
|---|
| 1893 | $category = new Category();
|
|---|
| 1894 | return $category->getCatSafeName($this, $cat_id);
|
|---|
| 1895 | }
|
|---|
| 1896 |
|
|---|
| 1897 |
|
|---|
| 1898 | /**
|
|---|
| 1899 | * Returns parent id
|
|---|
| 1900 | *
|
|---|
| 1901 | * @param int $cat_id
|
|---|
| 1902 | * @return int
|
|---|
| 1903 | */
|
|---|
| 1904 | public function getCatParent($cat_id)
|
|---|
| 1905 | {
|
|---|
| 1906 | require_once(LIBS . 'Category.php');
|
|---|
| 1907 | $category = new Category();
|
|---|
| 1908 | return $category->getCatParent($this, $cat_id);
|
|---|
| 1909 | }
|
|---|
| 1910 |
|
|---|
| 1911 |
|
|---|
| 1912 | /**
|
|---|
| 1913 | * Returns child ids
|
|---|
| 1914 | *
|
|---|
| 1915 | * @param int $cat_parent_id
|
|---|
| 1916 | * @return int
|
|---|
| 1917 | */
|
|---|
| 1918 | public function getCatChildren($cat_parent_id)
|
|---|
| 1919 | {
|
|---|
| 1920 | require_once(LIBS . 'Category.php');
|
|---|
| 1921 | $category = new Category();
|
|---|
| 1922 | return $category->getCatChildren($this, $cat_parent_id);
|
|---|
| 1923 | }
|
|---|
| 1924 |
|
|---|
| 1925 | /**
|
|---|
| 1926 | * Returns Category list ids
|
|---|
| 1927 | *
|
|---|
| 1928 | * @param array $args
|
|---|
| 1929 | * @return int
|
|---|
| 1930 | */
|
|---|
| 1931 | public function getCategories($args = array())
|
|---|
| 1932 | {
|
|---|
| 1933 | require_once(LIBS . 'Category.php');
|
|---|
| 1934 | $category = new Category();
|
|---|
| 1935 | return $category->getCategories($this, $args);
|
|---|
| 1936 | }
|
|---|
| 1937 |
|
|---|
| 1938 |
|
|---|
| 1939 | /**
|
|---|
| 1940 | * Returns meta description and keywords for the category (if available)
|
|---|
| 1941 | *
|
|---|
| 1942 | * @param int $cat_id
|
|---|
| 1943 | * @return array|false
|
|---|
| 1944 | */
|
|---|
| 1945 | public function getCatMeta($cat_id)
|
|---|
| 1946 | {
|
|---|
| 1947 | require_once(LIBS . 'Category.php');
|
|---|
| 1948 | $category = new Category();
|
|---|
| 1949 | return $category->getCatMeta($this, $cat_id);
|
|---|
| 1950 | }
|
|---|
| 1951 |
|
|---|
| 1952 |
|
|---|
| 1953 | /* *************************************************************
|
|---|
| 1954 | *
|
|---|
| 1955 | * COMMENT FUNCTIONS
|
|---|
| 1956 | *
|
|---|
| 1957 | * *********************************************************** */
|
|---|
| 1958 |
|
|---|
| 1959 |
|
|---|
| 1960 | /**
|
|---|
| 1961 | * Count comments
|
|---|
| 1962 | *
|
|---|
| 1963 | * @param bool $link - true used for "comments" link, false for top of actual comments
|
|---|
| 1964 | * @return string - text to show in the link, e.g. "3 comments"
|
|---|
| 1965 | */
|
|---|
| 1966 | function countComments($link = true)
|
|---|
| 1967 | {
|
|---|
| 1968 | require_once(LIBS . 'Comment.php');
|
|---|
| 1969 | $comment = new Comment();
|
|---|
| 1970 | return $comment->countComments($this, $link);
|
|---|
| 1971 | }
|
|---|
| 1972 |
|
|---|
| 1973 |
|
|---|
| 1974 | /**
|
|---|
| 1975 | * Physically delete all comments by a specified user (and responses)
|
|---|
| 1976 | *
|
|---|
| 1977 | * @param array $user_id
|
|---|
| 1978 | * @return bool
|
|---|
| 1979 | */
|
|---|
| 1980 | public function deleteComments($user_id)
|
|---|
| 1981 | {
|
|---|
| 1982 | require_once(LIBS . 'Comment.php');
|
|---|
| 1983 | $comment = new Comment();
|
|---|
| 1984 | return $comment->deleteComments($this, $user_id);
|
|---|
| 1985 | }
|
|---|
| 1986 |
|
|---|
| 1987 |
|
|---|
| 1988 | /**
|
|---|
| 1989 | * Get comment from database
|
|---|
| 1990 | *
|
|---|
| 1991 | * @param int $comment_id
|
|---|
| 1992 | * @return array|false
|
|---|
| 1993 | */
|
|---|
| 1994 | function getComment($comment_id = 0)
|
|---|
| 1995 | {
|
|---|
| 1996 | require_once(LIBS . 'Comment.php');
|
|---|
| 1997 | $comment = new Comment();
|
|---|
| 1998 | return $comment->getComment($this, $comment_id);
|
|---|
| 1999 | }
|
|---|
| 2000 |
|
|---|
| 2001 |
|
|---|
| 2002 | /**
|
|---|
| 2003 | * Read comment
|
|---|
| 2004 | *
|
|---|
| 2005 | * @param array $comment_row pulled from database
|
|---|
| 2006 | */
|
|---|
| 2007 | function readComment($comment_row = array())
|
|---|
| 2008 | {
|
|---|
| 2009 | require_once(LIBS . 'Comment.php');
|
|---|
| 2010 | $comment = new Comment();
|
|---|
| 2011 | return $comment->readComment($this, $comment_row);
|
|---|
| 2012 | }
|
|---|
| 2013 |
|
|---|
| 2014 |
|
|---|
| 2015 | /* *************************************************************
|
|---|
| 2016 | *
|
|---|
| 2017 | * WIDGET FUNCTIONS
|
|---|
| 2018 | *
|
|---|
| 2019 | * *********************************************************** */
|
|---|
| 2020 |
|
|---|
| 2021 | /**
|
|---|
| 2022 | * Add widget
|
|---|
| 2023 | *
|
|---|
| 2024 | * @param string $plugin
|
|---|
| 2025 | * @param string $function
|
|---|
| 2026 | * @param string $value
|
|---|
| 2027 | */
|
|---|
| 2028 | public function addWidget($plugin = '', $function = '', $args = '')
|
|---|
| 2029 | {
|
|---|
| 2030 | require_once(LIBS . 'Widget.php');
|
|---|
| 2031 | $widget = new Widget();
|
|---|
| 2032 | $widget->addWidget($this, $plugin, $function, $args);
|
|---|
| 2033 | }
|
|---|
| 2034 |
|
|---|
| 2035 |
|
|---|
| 2036 | /**
|
|---|
| 2037 | * Delete a widget from the widget db table
|
|---|
| 2038 | *
|
|---|
| 2039 | * @param string $function
|
|---|
| 2040 | */
|
|---|
| 2041 | public function deleteWidget($function)
|
|---|
| 2042 | {
|
|---|
| 2043 | require_once(LIBS . 'Widget.php');
|
|---|
| 2044 | $widget = new Widget();
|
|---|
| 2045 | $widget->deleteWidget($this, $function);
|
|---|
| 2046 | }
|
|---|
| 2047 |
|
|---|
| 2048 |
|
|---|
| 2049 | /**
|
|---|
| 2050 | * Get plugin name from widget function name
|
|---|
| 2051 | *
|
|---|
| 2052 | * @return string
|
|---|
| 2053 | */
|
|---|
| 2054 | public function getPluginFromFunction($function)
|
|---|
| 2055 | {
|
|---|
| 2056 | require_once(LIBS . 'Widget.php');
|
|---|
| 2057 | $widget = new Widget();
|
|---|
| 2058 | return $widget->getPluginFromFunction($this, $function);
|
|---|
| 2059 | }
|
|---|
| 2060 |
|
|---|
| 2061 |
|
|---|
| 2062 | /* *************************************************************
|
|---|
| 2063 | *
|
|---|
| 2064 | * EMAIL FUNCTIONS
|
|---|
| 2065 | *
|
|---|
| 2066 | * *********************************************************** */
|
|---|
| 2067 |
|
|---|
| 2068 | /**
|
|---|
| 2069 | * Send emails
|
|---|
| 2070 | *
|
|---|
| 2071 | * @param string $to - defaults to SITE_EMAIL
|
|---|
| 2072 | * @param string $subject - defaults to "No Subject";
|
|---|
| 2073 | * @param string $body - returns false if empty
|
|---|
| 2074 | * @param string $headers default is "From: " . SITE_EMAIL . "\r\nReply-To: " . SITE_EMAIL . "\r\nX-Priority: 3\r\n";
|
|---|
| 2075 | * @param string $type - default is "email", but you can write to a "log" file, print to "screen" or "return" an array of the content
|
|---|
| 2076 | * @return array|false - only if $type = "return"
|
|---|
| 2077 | */
|
|---|
| 2078 | public function email($to = '', $subject = '', $body = '', $headers = '', $type = 'email')
|
|---|
| 2079 | {
|
|---|
| 2080 | if (!is_object($this->email)) {
|
|---|
| 2081 | require_once(LIBS . 'EmailFunctions.php');
|
|---|
| 2082 | $this->email = new EmailFunctions();
|
|---|
| 2083 | }
|
|---|
| 2084 |
|
|---|
| 2085 | $this->email->to = $to;
|
|---|
| 2086 | $this->email->subject = $subject;
|
|---|
| 2087 | $this->email->body = $body;
|
|---|
| 2088 | $this->email->headers = $headers;
|
|---|
| 2089 | $this->email->type = $type;
|
|---|
| 2090 |
|
|---|
| 2091 | return $this->email->doEmail();
|
|---|
| 2092 | }
|
|---|
| 2093 | }
|
|---|
| 2094 | ?>
|
|---|