root/trunk/Hotaru.php

Revision 2233, 64.2 KB (checked in by nick_ramsay, 18 months ago)

[Trunk] Updating with 1.4.2. files.

Line 
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) 2010, Hotaru CMS
23 * @license   http://www.gnu.org/copyleft/gpl.html GNU General Public License
24 * @link      http://www.hotarucms.org/
25 */
26class Hotaru
27{
28        protected $version              = "1.4.2";  // 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        protected $pageHandling;                    // PageHandling object
47       
48        // page info
49        protected $home                 = '';       // name for front page
50        protected $pageName             = '';       // e.g. index, category
51        protected $pageTitle            = '';       // e.g. Top Stories
52        protected $pageType             = '';       // e.g. post, list
53        protected $pageTemplate         = '';       // e.g. sb_list, tag_cloud
54        protected $subPage              = '';       // e.g. category (if pageName is "index")
55
56        // ALL plugins
57        protected $pluginSettings       = array();  // contains all settings for all plugins
58        protected $allPluginDetails     = array();  // contains details of all plugins
59       
60        // messages
61        protected $message              = '';       // message to display
62        protected $messageType          = 'green';  // green or red, color of message box
63        protected $messages             = array();  // for multiple messages
64       
65        // miscellaneous
66        protected $vars                 = array();  // multi-purpose   
67   
68        /**
69         * CONSTRUCTOR - Initialize
70         */
71        public function __construct($start = '')
72        {
73                // define shorthand paths
74                if (!defined('BASE')) {
75                        define("BASE", dirname(__FILE__). '/');
76                        define("CACHE", dirname(__FILE__).'/cache/');
77                        define("ADMIN", dirname(__FILE__).'/admin/');
78                        define("INSTALL", dirname(__FILE__).'/install/');
79                        define("LIBS", dirname(__FILE__).'/libs/');
80                        define("EXTENSIONS", dirname(__FILE__).'/libs/extensions/');
81                        define("FUNCTIONS", dirname(__FILE__).'/functions/');
82                        define("CONTENT", dirname(__FILE__).'/content/');
83                        define("THEMES", dirname(__FILE__).'/content/themes/');
84                        define("PLUGINS", dirname(__FILE__).'/content/plugins/');
85                        define("ADMIN_THEMES", dirname(__FILE__).'/content/admin_themes/');
86                        define("SITEURL", BASEURL);
87                }
88
89                require_once(EXTENSIONS . 'SmartLoader/smartloader.class.php');
90
91                // initialize Hotaru
92                if (!$start) {
93                       
94                        $init = new Initialize($this);
95
96                        $this->db           = $init->db;            // database object
97                        $this->cage         = $init->cage;          // Inspekt cage
98                        $this->isDebug      = $init->isDebug;       // set debug                       
99                        $this->currentUser  = new UserAuth();       // the current user
100                        $this->plugin       = new Plugin();         // instantiate Plugin object
101                        $this->post         = new Post();           // instantiate Post object
102                        $this->includes     = new IncludeCssJs();   // instantiate Includes object
103                        $this->pageHandling = new PageHandling();   // instantiate PageHandling object
104                        $this->debug        = new Debug();          // instantiate Debug object
105                       
106                        $this->csrf('set');                         // set a csrfToken
107                        $this->db->setHotaru($this);                // pass $h object to EzSQL for error reporting
108                }
109        }
110   
111   
112/* *************************************************************
113 *
114 *  HOTARU FUNCTIONS
115 *
116 * *********************************************************** */
117
118
119        /**
120         * START - the top of "Hotaru", i.e. the page-building process
121         */
122        public function start($entrance = '')
123        {
124                // include "main" language pack
125                $lang = new Language();
126                $this->lang = $lang->includeLanguagePack($this->lang, 'main');
127               
128                $this->getPageName();                   // fills $h->pageName
129               
130                switch ($entrance) {
131                        case 'admin':
132                                $this->isAdmin = true;
133                                $this->lang = $lang->includeLanguagePack($this->lang, 'admin');                         
134                                $admin = new AdminAuth();               // new Admin object
135                                $this->checkCookie();                   // check cookie reads user details
136                                $this->checkAccess();                   // site closed if no access permitted
137                                $page = $admin->adminInit($this);       // initialize Admin & get desired page
138                                $this->adminPages($page);               // Direct to desired Admin page
139                                break;
140                        default:
141                                $this->isAdmin = false;
142                                $this->checkCookie();                   // log in user if cookie
143                                $this->checkAccess();                   // site closed if no access permitted
144                                if (!$entrance) { return false; }       // stop here if entrance not defined
145                                $this->displayTemplate('index');        // displays the index page
146                }
147               
148                $lang->writeLanguageCache($this);
149               
150                exit;
151        }
152   
153   
154/* *************************************************************
155 *
156 *  ACCESS MODIFIERS
157 *
158 * *********************************************************** */
159 
160 
161        /**
162         * Access modifier to set protected properties
163         */
164        public function __set($var, $val)
165        {
166                $this->$var = $val;
167        }
168   
169   
170        /**
171         * Access modifier to get protected properties
172         * The & is necessary (http://bugs.php.net/bug.php?id=39449)
173         */
174        public function &__get($var)
175        {
176                return $this->$var;
177        }
178
179
180/* *************************************************************
181 *
182 *  DEFAULT PLUGIN HOOK ACTIONS
183 *
184 * *********************************************************** */
185 
186     
187        /**
188         * Include language file if available
189         */
190        public function install_plugin()
191        {
192                $this->includeLanguage($this->plugin->folder);
193        }
194     
195     
196        /**
197         * Include All CSS and JavaScript files for this plugin
198         */
199        public function header_include()
200        {
201                if ($this->isAdmin) { return false; }
202               
203                // include a files that match the name of the plugin folder:
204                $this->includeJs($this->plugin->folder); // folder name, filename
205                $this->includeCss($this->plugin->folder);
206        }
207   
208   
209        /**
210         * Include All CSS and JavaScript files for this plugin in Admin
211         */
212        public function admin_header_include()
213        {
214                if (!$this->isAdmin) { return false; }
215               
216                // include a files that match the name of the plugin folder:
217                $this->includeJs($this->plugin->folder); // folder name, filename
218                $this->includeCss($this->plugin->folder);
219        }
220   
221   
222        /**
223         * Include code as a template before the closing </body> tag
224         */
225        public function pre_close_body()
226        {
227                $this->displayTemplate($this->plugin->folder . '_footer', $this->plugin->folder);
228        }
229   
230
231        /**
232         * Display Admin sidebar link
233         */
234        public function admin_sidebar_plugin_settings()
235        {
236                $vars['plugin'] = $this->plugin->folder;
237                $vars['name'] = $this->plugin->name;
238                //$vars['name'] = make_name($this->plugin->folder);
239                return $vars;
240        }
241       
242       
243        /**
244         * Display Admin settings page
245         *
246         * @return true
247         */
248        public function admin_plugin_settings()
249        {
250                // This requires there to be a file in the plugin folder called pluginname_settings.php
251                // The file must contain a class titled PluginNameSettings
252                // The class must have a method called "settings".
253                if (($this->cage->get->testAlnumLines('plugin') != $this->plugin->folder)
254                        && ($this->cage->post->testAlnumLines('plugin') != $this->plugin->folder))
255                {
256                        return false;
257                }
258               
259                if (file_exists(PLUGINS . $this->plugin->folder . '/' . $this->plugin->folder . '_settings.php')) {
260                    include_once(PLUGINS . $this->plugin->folder . '/' . $this->plugin->folder . '_settings.php');
261               
262                    $settings_class = make_name($this->plugin->folder, '_') . 'Settings'; // e.g. CategoriesSettings
263                    $settings_class = str_replace(' ', '', $settings_class); // strip spaces
264                    $settings_object = new $settings_class();
265                    $settings_object->settings($this);   // call the settings function         
266                }
267                else {
268                    echo $this->lang["admin_theme_plugins_filenotfound"] . "<br/><br/>";
269                    echo $this->lang["admin_theme_plugins_checkforfile"] . PLUGINS . $this->plugin->folder . '/' . $this->plugin->folder . '_settings.php';
270                }
271                return true;
272        }
273   
274   
275/* *************************************************************
276 *
277 *  PAGE HANDLING FUNCTIONS
278 *
279 * *********************************************************** */
280
281        /**
282         * Set the homepage (and set page name)
283         *
284         * @param string $home
285         * @param string $pagename
286         */
287        public function setHome($home = '', $pagename = '')
288        {
289                $this->pageHandling->setHome($this, $home, $pagename);
290        }
291
292        /**
293         * Test if the current url is the *true* homepage, i.e. equal to SITEURL
294         *
295         * @return bool
296         */
297        public function isHome()
298        {
299                return $this->pageHandling->isHome($this);
300        }
301       
302       
303        /**
304         * Determine the title tags for the header
305         *
306         * @param bool $raw -return the title only
307         * @return string - the title
308         */
309        public function getTitle($delimiter = ' &laquo; ', $raw = false)
310        {
311                return $this->pageHandling->getTitle($this, $delimiter, $raw);
312        }
313   
314   
315        /**
316         * Includes a template to display
317         *
318         * @param string $page page name
319         * @param string $plugin optional plugin name
320         * @param bool $include_once true or false
321         */
322        public function displayTemplate($page = '', $plugin = '', $include_once = true)
323        {
324                $this->pageHandling->displayTemplate($this, $page, $plugin, $include_once);
325        }
326   
327   
328        /**
329         * Checks if current page (in url or form) matches the page parameter
330         *
331         * @param string $page page name
332         */
333        public function isPage($page = '')
334        {
335                return $this->pageHandling->isPage($this, $page);
336        }
337   
338   
339        /**
340         * Check to see if the Admin settings page we are looking at 
341         * matches the plugin passed to this function.
342         *
343         * @param string $folder - plugin folder
344         * @return bool
345         *
346         *  Notes: This is used in "admin_header_include" so we only include the css,
347         *         javascript etc. for the plugin we're trying to change settings for.
348         *  Usage: $h->isSettingsPage('submit') returns true if
349         *         page=plugin_settings and plugin=submit in the url.
350         */
351        public function isSettingsPage($folder = '')
352        {
353                return $this->pageHandling->isSettingsPage($this, $folder);
354        }
355
356   
357        /**
358         * Gets the current page name
359         */
360        public function getPageName()
361        {
362                $this->pageName = $this->pageHandling->getPageName($this);
363                return $this->pageName;
364        }
365   
366   
367        /**
368         * Converts a friendly url into a standard one
369         *
370         * @param string $friendly_url
371         * return string $standard_url
372         */
373        public function friendlyToStandardUrl($friendly_url)
374        {
375                return $this->pageHandling->friendlyToStandardUrl($this, $friendly_url);
376        }
377   
378   
379        /**
380         * Generate either default or friendly urls
381         *
382         * @param array $parameters an array of pairs, e.g. 'page' => 'about'
383         * @param string $head either 'index' or 'admin'
384         * @return string
385         */
386        public function url($parameters = array(), $head = 'index')
387        {
388                return $this->pageHandling->url($this, $parameters, $head);
389        }
390   
391   
392        /**
393         * Pagination with query and row count (better for large sets of data)
394         *
395         * @param string $query - SQL query
396         * @param int $total_items - total row count
397         * @param int $items_per_page
398         * @param string $cache_table - must provide a table, e.g. "posts" for caching to be used
399         * @return object|false - object
400         */
401        public function pagination($query, $total_items, $items_per_page = 10, $cache_table = '')
402        {
403                $paginator = new Paginator();
404                return $paginator->pagination($this, $query, $total_items, $items_per_page, $cache_table);
405        }
406   
407
408        /**
409         * Pagination with full dataset (easier for small sets of data)
410         *
411         * @param array $data - array of results for paginating
412         * @param int $items_per_page
413         * @return object|false - object
414         */
415        public function paginationFull($data, $items_per_page = 10)
416        {
417                $paginator = new Paginator();
418                return $paginator->paginationFull($this, $data, $items_per_page);
419        }
420   
421 
422        /**
423         * Return page numbers bar
424         *
425         * @param object $paginator - current object of type Paginator
426         * @return string - HTML for page number bar
427         */
428        public function pageBar($paginator = NULL)
429        {
430                return $paginator->pageBar($this);
431        }
432   
433
434/* *************************************************************
435 *
436 *  BREADCRUMB FUNCTIONS
437 *
438 * *********************************************************** */
439 
440 
441        /**
442         * Build breadcrumbs
443         */
444        public function breadcrumbs()
445        {
446                $breadcrumbs = new Breadcrumbs();
447                return $breadcrumbs->buildBreadcrumbs($this);
448        }
449   
450   
451        /**
452         * prepares the RSS link found in breadcrumbs
453         *
454         * @param string $status - post status, e.g. new, top, etc.
455         * @param array $vars - array of key -> value pairs
456         * @return string
457         */   
458        public function rssBreadcrumbsLink($status = '', $vars = array())
459        {
460                $breadcrumbs = new Breadcrumbs();
461                return $breadcrumbs->rssBreadcrumbsLink($this, $status, $vars);
462        }
463   
464 
465 /* *************************************************************
466 *
467 *  USERAUTH FUNCTIONS / USERBASE FUNCTIONS
468 *
469 * *********************************************************** */
470 
471        /* UserBase & UserAuth functions should be called directly if you want to
472           retain the user object being used. E.g.
473               
474                $user = new UserAuth();
475                $user->getUserBasic($h);
476                $user->updateUserBasic($h);
477        */
478       
479       
480        /**
481         * check cookie and log in
482         *
483         * @return bool
484         */
485        public function checkCookie()
486        {
487                $this->currentUser->checkCookie($this);
488        }
489       
490       
491        /**
492         * Get basic user details
493         *
494         * @param int $userid
495         * @param string $username
496         * @param bool $no_cache - set true to disable caching of SQl results
497         * @return array|false
498         *
499         * Note: Needs either userid or username, not both
500         */
501        public function getUserBasic($userid = 0, $username = '', $no_cache = false)
502        {
503                $userbase = new UserBase();
504                return $userbase->getUserBasic($this, $userid, $username, $no_cache);
505        }
506       
507       
508        /**
509         * Get full user details (i.e. permissions and settings, too)
510         *
511         * @param int $userid
512         * @param string $username
513         * @param bool $no_cache - set true to disable caching of SQl results
514         * @return array|false
515         *
516         * Note: Needs either userid or username, not both
517         */
518        public function getUser($userid = 0, $username = '', $no_cache = false)
519        {
520                $userbase = new UserBase();
521                return $userbase->getUser($this, $userid, $username, $no_cache);
522        }
523       
524       
525        /**
526         * Default permissions
527         *
528         * @param string $role or 'all'
529         * @param string $field 'site' for site defaults and 'base' for base defaults
530         * @param book $options_only returns just the options if true
531         * @return array $perms
532         */
533        public function getDefaultPermissions($role = '', $defaults = 'site', $options_only = false)
534        {
535                $userbase = new UserBase();
536                return $userbase->getDefaultPermissions($this, $role, $defaults, $options_only);
537        }
538       
539       
540        /**
541         * Update Default permissions
542         *
543         * @param array $new_perms from a plugin's install function
544         * @param string $defaults - either "site", "base" or "both"
545         * @param bool $remove - false if adding perms, true if deleting them
546         */
547        public function updateDefaultPermissions($new_perms = array(), $defaults = 'both', $remove = false)
548        {
549                $userbase = new UserBase();
550                return $userbase->updateDefaultPermissions($this, $new_perms, $defaults, $remove);
551        }
552       
553       
554        /**
555         * Get the default user settings
556         *
557         * @param string $type either 'site' or 'base' (base for the originals)
558         * @return array
559         */
560        public function getDefaultSettings($type = 'site')
561        {
562                $userbase = new UserBase();
563                return $userbase->getDefaultSettings($this, $type);
564        }
565       
566       
567        /**
568         * Update the default user settings
569         *
570         * @param array $settings
571         * @param string $type either 'site' or 'base' (base for the originals)
572         * @return array
573         */
574        public function updateDefaultSettings($settings, $type = 'site')
575        {
576                $userbase = new UserBase();
577                return $userbase->updateDefaultSettings($this, $settings, $type);
578        }
579       
580       
581        /**
582         * Get a user's profile or settings data
583         *
584         * @return array|false
585         */
586        public function getProfileSettingsData($type = 'user_profile', $userid = 0, $check_exists_only = false)
587        {
588                $userbase = new UserBase();
589                return $userbase->getProfileSettingsData($this, $type, $userid, $check_exists_only);
590        }
591       
592       
593        /**
594         * Physically delete a user
595         * Note: You should delete all their posts, comments, etc. first
596         *
597         * @param int $user_id (optional)
598         */
599        public function deleteUser($user_id = 0)
600        {
601                $userbase = new UserBase();
602                return $userbase->deleteUser($this, $user_id);
603        }
604
605
606        /**
607         * Update user_lastvisit field
608         *
609         * @param int $user_id (optional)
610         */
611        public function updateUserLastVisit($user_id = 0)
612        {
613                return $this->currentUser->updateUserLastVisit($this, $user_id);
614        }
615       
616
617        /**
618         * Get User Roles - returns an array of role names
619         *
620         * @param string $type 'all', 'default', or 'custom'
621         * @return array|false
622         */
623        public function getRoles($type = 'all')
624        {
625                return $this->currentUser->getRoles($this, $type);
626        }
627
628
629        /**
630         * Get Unique User Roles - DEPRECATED Hotaru 1.4.1 - Plugins should be updated to use above getRoles() instead
631         *
632         * @return array|false
633         */
634        public function getUniqueRoles()
635        {
636                return $this->getRoles();
637        }
638
639       
640 /* *************************************************************
641 *
642 *  USERINFO FUNCTIONS
643 *
644 * *********************************************************** */
645       
646       
647        /**
648         * Get the username for a given user id
649         *
650         * @param int $id user id
651         * @return string|false
652         */
653        public function getUserNameFromId($id = 0)
654        {
655                $userInfo = new UserInfo();
656                return $userInfo->getUserNameFromId($this, $id);
657        }
658       
659       
660        /**
661         * Get the user id for a given username
662         *
663         * @param string $username
664         * @return int|false
665         */
666        public function getUserIdFromName($username = '')
667        {
668                $userInfo = new UserInfo();
669                return $userInfo->getUserIdFromName($this, $username);
670        }
671       
672       
673        /**
674         * Get the email from user id
675         *
676         * @param int $userid
677         * @return string|false
678         */
679        public function getEmailFromId($userid = 0)
680        {
681                $userInfo = new UserInfo();
682                return $userInfo->getEmailFromId($this, $userid);
683        }
684       
685       
686        /**
687         * Get the user id from email
688         *
689         * @param string $email
690         * @return string|false
691         */
692        public function getUserIdFromEmail($email = '')
693        {
694                $userInfo = new UserInfo();
695                return $userInfo->getUserIdFromEmail($this, $email);
696        }
697       
698       
699         /**
700         * Checks if the user has an 'admin' role
701         *
702         * @return bool
703         */
704        public function isAdmin($username)
705        {
706                $userInfo = new UserInfo();
707                return $userInfo->isAdmin($this->db, $username);
708        }
709       
710       
711        /**
712         * Check if a user exists
713         *
714         * @param int $userid
715         * @param string $username
716         * @return int
717         *
718         * Notes: Returns 'no' if a user doesn't exist, else field under which found
719         */
720        public function userExists($id = 0, $username = '', $email = '')
721        {
722                $userInfo = new UserInfo();
723                return $userInfo->userExists($this->db, $id, $username, $email);
724        }
725       
726       
727        /**
728         * Check if an username exists in the database (used in forgotten password)
729         *
730         * @param string $username user username
731         * @param string $role user role (optional)
732         * @param int $exclude - exclude a user
733         * @return string|false
734         */
735        public function nameExists($username = '', $role = '', $exclude = 0)
736        {
737                $userInfo = new UserInfo();
738                return $userInfo->nameExists($this, $username, $role, $exclude);
739        }
740       
741       
742        /**
743         * Check if an email exists in the database (used in forgotten password)
744         *
745         * @param string $email user email
746         * @param string $role user role (optional)
747         * @param int $exclude - exclude a user
748         * @return string|false
749         */
750        public function emailExists($email = '', $role = '', $exclude = 0)
751        {
752                $userInfo = new UserInfo();
753                return $userInfo->emailExists($this, $email, $role, $exclude);
754        }
755       
756       
757        /**
758         * Get all users with permission to (access admin)
759         *
760         * @param string $permission
761         * @param string $value - value for the permission, usually yes, no, own or mod
762         * @return array
763         */
764        public function getMods($permission = 'can_access_admin', $value = 'yes')
765        {
766                $userInfo = new UserInfo();
767                return $userInfo->getMods($this, $permission, $value);
768        }
769       
770       
771        /**
772         * Get the ids and names of all users or those with a specified role, sorted alphabetically
773         *
774         * @param string $role - optional user role to filter to
775         * @return array
776         */
777        public function userIdNameList($role = '')
778        {
779                $userInfo = new UserInfo();
780                return $userInfo->userIdNameList($this, $role);
781        }
782       
783       
784        /**
785         * Get full details of all users or batches of users, sorted alphabetically
786         *
787         * @param array $id_array - optional array of user ids
788         * @param int $start - LIMIT $start $range (optional)
789         * @param int $range - LIMIT $start $range (optional)
790         * @return array
791         */
792        public function userListFull($id_array = array(), $start = 0, $range = 0)
793        {
794                $userInfo = new UserInfo();
795                return $userInfo->userListFull($this, $id_array, $start, $range);
796        }
797       
798       
799        /**
800         * Get settings for all users
801         *
802         * @param int $userid - optional user id
803         * @return array
804         */
805        public function userSettingsList($userid = 0)
806        {
807                $userInfo = new UserInfo();
808                return $userInfo->userSettingsList($this, $userid);
809        }
810
811   
812 /* *************************************************************
813 *
814 *  PLUGIN FUNCTIONS
815 *
816 * *********************************************************** */
817 
818 
819        /**
820         * Look for and run actions at a given plugin hook
821         *
822         * @param string $hook name of the plugin hook
823         * @param bool $perform false to check existence, true to actually run
824         * @param string $folder name of plugin folder
825         * @param array $parameters mixed values passed from plugin hook
826         * @return array | bool
827         */
828        public function pluginHook($hook = '', $folder = '', $parameters = array(), $exclude = array())
829        {
830                $pluginFunctions = new PluginFunctions();
831                return $pluginFunctions->pluginHook($this, $hook, $folder, $parameters, $exclude);
832        }
833       
834       
835        /**
836         * Get a single plugin's details for Hotaru
837         *
838         * @param string $folder - plugin folder name, else $h->plugin->folder is used
839         * @return array - $key array object, e.g. $key->plugin_id
840         */
841        public function readPlugin($folder = '')
842        {
843                $pluginFunctions = new PluginFunctions();
844                return $pluginFunctions->readPlugin($this, $folder);
845        }
846       
847       
848        /**
849         * Get a single property from a specified plugin
850         *
851         * @param string $property - plugin property, e.g. "plugin_version"
852         * @param string $folder - plugin folder name, else $h->plugin->folder is used
853         * @param string $field - an alternative field to use instead of $folder
854         */
855        public function getPluginProperty($property = '', $folder = '', $field = '')
856        {
857                $pluginFunctions = new PluginFunctions();
858                return $pluginFunctions->getPluginProperty($this, $property, $folder, $field);
859        }
860       
861       
862        /**
863         * Get number of active plugins
864         *
865         * @return int|false
866         */
867        public function numActivePlugins()
868        {
869                $pluginFunctions = new PluginFunctions();
870                return $pluginFunctions->numActivePlugins($this->db);
871        }
872       
873       
874        /**
875         * Get version number of plugin if active
876         *
877         * @param string $folder plugin folder name
878         * @return string|false
879         */
880        public function getPluginVersion($folder = '')
881        {
882                return $this->getPluginProperty('plugin_version', $folder);
883        }
884       
885       
886        /**
887         * Get a plugin's actual name from its folder name
888         *
889         * @param string $folder plugin folder name
890         * @return string
891         */
892        public function getPluginName($folder = '')
893        {
894                return $this->getPluginProperty('plugin_name', $folder);
895        }
896       
897       
898        /**
899         * Get a plugin's folder from its class name
900         *
901         * @param string $class plugin class name
902         * @return string|false
903         */
904        public function getPluginFolderFromClass($class = '')
905        {
906                $pluginFunctions = new PluginFunctions();
907                $this->plugin->folder = $pluginFunctions->getPluginFolderFromClass($this, $class);
908        }
909       
910       
911        /**
912         * Get a plugin's class from its folder name
913         *
914         * @param string $folder plugin folder name
915         * @return string|false
916         */
917        public function getPluginClass($folder = '')
918        {
919                return $this->getPluginProperty('plugin_class', $folder);
920        }
921       
922       
923        /**
924         * Determines if a plugin "type" is enabled, if not, plugin "folder"
925         *
926         * @param string $type plugin type or folder name
927         * @return bool
928         */
929        public function isActive($type = '')
930        {
931                $pluginFunctions = new PluginFunctions();
932                //return $pluginFunctions->isActive($this, $type); // dropped in favor of cache:
933                $result = $this->getPluginProperty('plugin_enabled', $type, 'type');
934                if (!$result) { $result = $this->getPluginProperty('plugin_enabled', $type); }
935                return $result;
936        }
937       
938       
939        /**
940         * Determines if a specific plugin is installed
941         *
942         * @param string $folder folder name
943         * @return bool
944         */
945        public function isInstalled($folder = '')
946        {
947                $pluginFunctions = new PluginFunctions();
948                $result = $this->getPluginProperty('plugin_id', $folder);
949                return $result;
950        }
951       
952       
953        /**
954         * Determines if a plugin has a settings page or not
955         *
956         * @param object $h
957         * @param string $folder plugin folder name (optional)
958         * @return bool
959         */
960        public function hasSettings($folder = '')
961        {
962                $pluginFunctions = new PluginFunctions();
963                return $pluginFunctions->hasSettings($this, $folder);
964        }
965
966
967 /* *************************************************************
968 *
969 *  PLUGIN SETTINGS FUNCTIONS
970 *
971 * *********************************************************** */
972 
973 
974        /**
975         * Get the value for a given plugin and setting
976         *
977         * @param string $folder name of plugin folder
978         * @param string $setting name of the setting to retrieve
979         * @return string|false
980         *
981         * Notes: If there are multiple settings with the same name,
982         * this will only get the first.
983         */
984        public function getSetting($setting = '', $folder = '')
985        {
986                $pluginSettings = new PluginSettings();
987                return $pluginSettings->getSetting($this, $setting, $folder);
988        }
989       
990       
991        /**
992         * Get an array of settings for a given plugin
993         *
994         * @param string $folder name of plugin folder
995         * @return array|false
996         *
997         * Note: Unlike "getSetting", this will get ALL settings with the same name.
998         */
999        public function getSettingsArray($folder = '')
1000        {
1001                $pluginSettings = new PluginSettings();
1002                return $pluginSettings->getSettingsArray($this, $folder);
1003        }
1004       
1005       
1006        /**
1007         * Get and unserialize serialized settings
1008         *
1009         * @param string $folder plugin folder name
1010         * @param string $settings_name optional settings name if different from folder
1011         * @return array - of submit settings
1012         */
1013        public function getSerializedSettings($folder = '', $settings_name = '')
1014        {
1015                $pluginSettings = new PluginSettings();
1016                return $pluginSettings->getSerializedSettings($this, $folder, $settings_name);
1017        }
1018       
1019       
1020        /**
1021         * Get and store all plugin settings in $h->pluginSettings
1022         *
1023         * @return array - all settings
1024         */
1025        public function getAllPluginSettings()
1026        {
1027                $pluginSettings = new PluginSettings();
1028                $this->pluginSettings = $pluginSettings->getAllPluginSettings($this);
1029                return $this->pluginSettings;
1030        }
1031       
1032       
1033        /**
1034         * Determine if a plugin setting already exists
1035         *
1036         * @param string $folder name of plugin folder
1037         * @param string $setting name of the setting to retrieve
1038         * @return string|false
1039         */
1040        public function isSetting($setting = '', $folder = '')
1041        {
1042                $pluginSettings = new PluginSettings();
1043                return $pluginSettings->isSetting($this, $setting, $folder);
1044        }
1045       
1046       
1047        /**
1048         * Update a plugin setting
1049         *
1050         * @param string $folder name of plugin folder
1051         * @param string $setting name of the setting
1052         * @param string $setting stting value
1053         */
1054        public function updateSetting($setting = '', $value = '', $folder = '')
1055        {
1056                $pluginSettings = new PluginSettings();
1057                return $pluginSettings->updateSetting($this, $setting, $value, $folder);
1058        }
1059
1060
1061 /* *************************************************************
1062 *
1063 *  THEME SETTINGS FUNCTIONS
1064 *
1065 * *********************************************************** */
1066
1067        /**
1068         * Read and return plugin info from top of a plugin file.
1069         *
1070         * @param string $theme - theme folder
1071         * @return array|false
1072         */
1073        public function readThemeMeta($theme = 'default')
1074        {
1075                $themeSettings = new ThemeSettings();
1076                return $themeSettings->readThemeMeta($this, $theme);
1077        }
1078       
1079       
1080        /**
1081         * Get and unserialize serialized settings
1082         *
1083         * @param string $theme theme folder name
1084         * @param string $return 'value' or 'default'
1085         * @return array - of theme settings
1086         */
1087        public function getThemeSettings($theme = '', $return = 'value')
1088        {
1089                $themeSettings = new ThemeSettings();
1090                return $themeSettings->getThemeSettings($this, $theme, $return);
1091        }
1092       
1093       
1094        /**
1095         * Update theme settings
1096         *
1097         * @param array $settings array of settings
1098         * @param string $theme theme folder name
1099         * @param string $column 'value', 'default' or 'both'
1100       
1101         */
1102        public function updateThemeSettings($settings = array(), $theme = '', $column = 'value')
1103        {
1104                $themeSettings = new ThemeSettings();
1105                return $themeSettings->updateThemeSettings($this, $settings, $theme, $column);
1106        }
1107
1108
1109 /* *************************************************************
1110 *
1111 *  INCLUDE CSS & JAVASCRIPT FUNCTIONS
1112 *
1113 * *********************************************************** */
1114 
1115
1116        /**
1117         * Do Includes (called from template header.php)
1118         */
1119         public function doIncludes()
1120         {
1121                $version_js = $this->includes->combineIncludes($this, 'js');
1122                $version_css = $this->includes->combineIncludes($this, 'css');
1123                $this->includes->includeCombined($this, $version_js, $version_css, $this->isAdmin);
1124         }
1125         
1126         
1127        /**
1128         * Build an array of css files to combine
1129         *
1130         * @param $folder - the folder name of the plugin
1131         * @param $filename - optional css file without an extension
1132         */
1133         public function includeCss($folder = '', $filename = '')
1134         {
1135                return $this->includes->includeCss($this, $folder, $filename);
1136         }
1137       
1138       
1139        /**
1140         * Build an array of JavaScript files to combine
1141         *
1142         * @param $folder - the folder name of the plugin
1143         * @param $filename - optional js file without an extension
1144         */
1145         public function includeJs($folder = '', $filename = '')
1146         {
1147                return $this->includes->includeJs($this, $folder, $filename);
1148         }
1149         
1150         
1151        /**
1152         * Include individual CSS files, not merged into the CSS archive
1153         *
1154         * @param $files- array of files to include (no extensions)
1155         * @param $folder - optional pluin folder
1156         */
1157         public function includeOnceCss($files = array(), $folder = '')
1158         {
1159                return $this->includes->includeOnceCss($this, $files, $folder);
1160         }
1161         
1162         
1163        /**
1164         * Include individual JavaScript files, not merged into the JavaScript archive
1165         *
1166         * @param $files- array of files to include (no extensions)
1167         * @param $folder - optional pluin folder
1168         */
1169         public function includeOnceJs($files = array(), $folder = '')
1170         {
1171                return $this->includes->includeOnceJs($this, $files, $folder);
1172         }
1173     
1174     
1175 /* *************************************************************
1176 *
1177 *  MESSAGE FUNCTIONS (success/error messages)
1178 *
1179 * *********************************************************** */
1180 
1181 
1182        /**
1183         * Display a SINGLE success or failure message
1184         *
1185         * @param string $msg
1186         * @param string $msg_type ('green' or 'red')
1187         */
1188        public function showMessage($msg = '', $msg_type = 'green')
1189        {
1190                $messages = new Messages();
1191                $messages->showMessage($this, $msg, $msg_type);
1192        }
1193       
1194       
1195        /**
1196         * Displays ALL success or failure messages
1197         */
1198        public function showMessages()
1199        {
1200                $messages = new Messages();
1201                $messages->showMessages($this);
1202        }
1203   
1204   
1205 /* *************************************************************
1206 *
1207 *  ANNOUNCEMENT FUNCTIONS
1208 *
1209 * *********************************************************** */
1210 
1211 
1212        /**
1213         * Displays an announcement at the top of the screen
1214         *
1215         * @param string $announcement - optional for non-admin pages
1216         * @return array
1217         */
1218        public function checkAnnouncements($announcement = '')
1219        {
1220                $announce = new Announcements();
1221                if ($this->isAdmin) {
1222                        return $announce->checkAdminAnnouncements($this);
1223                } else {
1224                        return $announce->checkAnnouncements($this, $announcement);
1225                }
1226        }
1227   
1228   
1229 /* *************************************************************
1230 *
1231 *  DEBUG FUNCTIONS
1232 *
1233 * *********************************************************** */
1234 
1235 
1236        /**
1237         * Shows number of database queries and the time it takes for a page to load
1238         */
1239        public function showQueriesAndTime()
1240        {
1241                $this->debug->showQueriesAndTime($this);
1242        }
1243       
1244        /**
1245         * Open file for logging
1246         *
1247         * @param string $type "speed", "error", etc.
1248         * @param string $mode e.g. 'a' or 'w'.
1249         * @link http://php.net/manual/en/function.fopen.php
1250         */
1251        public function openLog($type = 'debug', $mode = 'a+')
1252        {
1253                $this->debug->openLog($type, $mode);
1254        }
1255       
1256       
1257        /**
1258         * Log performance and errors
1259         *
1260         * @param string $type "speed", "error", etc.
1261         */
1262        public function writeLog($type = 'error', $string = '')
1263        {
1264                $this->debug->writeLog($type, $string);
1265        }
1266       
1267       
1268        /**
1269         * Close log file
1270         *
1271         * @param string $type "speed", "error", etc.
1272         */
1273        public function closeLog($type = 'error')
1274        {
1275                $this->debug->closeLog($type);
1276        }
1277       
1278       
1279        /**
1280         * Generate a system report
1281         *
1282         * @param string $type "log" or "object"
1283         */
1284        public function generateReport($type = 'log')
1285        {
1286                if (!is_object($this->debug)) {
1287                        $this->debug = new Debug();
1288                }
1289                return $this->debug->generateReport($this, $type);
1290        }
1291
1292   
1293 /* *************************************************************
1294 *
1295 *  RSS FEED FUNCTIONS
1296 *
1297 * *********************************************************** */
1298 
1299 
1300        /**
1301         * Includes the SimplePie RSS file and sets the cache
1302         *
1303         * @param string $feed
1304         * @param bool $cache
1305         * @param int $cache_duration
1306         *
1307         * @return object|false $sp
1308         */
1309        public function newSimplePie($feed='', $cache=RSS_CACHE, $cache_duration=RSS_CACHE_DURATION)
1310        {
1311                $feeds = new Feeds();
1312                return $feeds->newSimplePie($feed, $cache, $cache_duration);
1313        }
1314       
1315       
1316         /**
1317         * Display Hotaru forums feed on Admin front page
1318         *
1319         * @param int $max_items
1320         * @param int $items_with_content
1321         * @param int $max_chars
1322         */
1323        public function adminNews($max_items = 10, $items_with_content = 3, $max_chars = 300)
1324        {
1325                $feeds = new Feeds();
1326                $feeds->adminNews($this->lang, $max_items, $items_with_content, $max_chars);
1327        }
1328
1329
1330         /**
1331         * Create an RSS Feed
1332         *
1333         * @param string $title - feed title
1334         * @param string $link - url feed title should point to
1335         * @param string $description - feed description
1336         * @param array $items - $items[0] = array('title'=>TITLE, 'link'=>URL, 'date'=>TIMESTAMP, 'description'=>DESCRIPTION)
1337         */
1338        public function rss($title = '', $link = '', $description = '', $items = array())
1339        {
1340                $feeds = new Feeds();
1341                $feeds->rss($this, $title, $link, $description, $items);
1342        }
1343       
1344       
1345 /* *************************************************************
1346 *
1347 *  ADMIN FUNCTIONS
1348 *
1349 * *********************************************************** */
1350 
1351 
1352         /**
1353         * Admin Pages
1354         */
1355        public function adminPages($page = 'admin_login')
1356        {
1357                $admin = new AdminPages();
1358                $admin->pages($this, $page);
1359        }
1360       
1361       
1362         /**
1363         * Admin login/logout
1364         *
1365         * @param string $action
1366         */
1367        public function adminLoginLogout($action = 'logout')
1368        {
1369                $admin = new AdminAuth();
1370                return ($action == 'login') ? $admin->adminLogin($this) : $admin->adminLogout($this);
1371        }
1372       
1373       
1374         /**
1375         * Admin login form
1376         */
1377        public function adminLoginForm()
1378        {
1379                $admin = new AdminAuth();
1380                $admin->adminLoginForm($this);
1381        }
1382   
1383   
1384 /* *************************************************************
1385 *
1386 *  MAINTENANCE FUNCTIONS
1387 *
1388 * *********************************************************** */
1389 
1390 
1391        /**
1392         * Check if site is open or closed. Exit if closed
1393         *
1394         * @param object $h
1395         */
1396        public function checkAccess()
1397        {
1398                if (SITE_OPEN == 'true') { return true; }   // site is open, go back and continue
1399               
1400                // site closed, but user has admin access so go back and continue as normal
1401                if ($this->currentUser->getPermission('can_access_admin') == 'yes') { return true; }
1402               
1403                if ($this->pageName == 'admin_login') { return true; }
1404               
1405                $maintenance = new Maintenance();
1406                return $maintenance->siteClosed($this, $this->lang); // displays "Site Closed for Maintenance"
1407        }
1408       
1409       
1410        /**
1411         * Open or close the site for maintenance
1412         *
1413         * @param string $switch - 'open' or 'close'
1414         */
1415        public function openCloseSite($switch = 'open')
1416        {
1417                $maintenance = new Maintenance();
1418                $maintenance->openCloseSite($this, $switch);
1419        }
1420       
1421       
1422        /**
1423         * Optimize all database tables
1424         */
1425        public function optimizeTables()
1426        {
1427                $maintenance = new Maintenance();
1428                $maintenance->optimizeTables($this);
1429        }
1430       
1431       
1432        /**
1433         * Empty plugin database table
1434         *
1435         * @param string $table_name - table to empty
1436         * @param string $msg - show "emptied" message or not
1437         */
1438        public function emptyTable($table_name = '', $msg = true)
1439        {
1440                $maintenance = new Maintenance();
1441                $maintenance->emptyTable($this, $table_name, $msg);
1442        }
1443       
1444       
1445        /**
1446         * Delete plugin database table
1447         *
1448         * @param string $table_name - table to drop
1449         * @param string $msg - show "dropped" message or not
1450         */
1451        public function dropTable($table_name = '', $msg = true)
1452        {
1453                $maintenance = new Maintenance();
1454                $maintenance->dropTable($this, $table_name, $msg);
1455        }
1456       
1457       
1458        /**
1459         * Remove plugin settings
1460         *
1461         * @param string $folder - plugin folder name
1462         * @param bool $msg - show "Removed" message or not
1463         */
1464        public function removeSettings($folder = '', $msg = true)
1465        {
1466                $maintenance = new Maintenance();
1467                $maintenance->removeSettings($this, $folder, $msg);
1468        }
1469       
1470       
1471        /**
1472         * Deletes rows from pluginsettings that match a given setting or plugin
1473         *
1474         * @param string $setting name of the setting to remove
1475         * @param string $folder name of plugin folder
1476         */
1477        public function deleteSettings($setting = '', $folder = '')
1478        {
1479                $maintenance = new Maintenance();
1480                $maintenance->deleteSettings($this, $setting, $folder);
1481        }
1482       
1483       
1484        /**
1485         * Delete all files in the specified directory except placeholder.txt
1486         *
1487         * @param string $dir - path to the cache folder
1488         * @return bool
1489         */   
1490        public function deleteFiles($dir = '')
1491        {
1492                $maintenance = new Maintenance();
1493                return $maintenance->deleteFiles($dir);
1494        }
1495       
1496       
1497        /**
1498         * Calls the delete_files function, then displays a message.
1499         *
1500         * @param string $folder - path to the cache folder
1501         * @param string $msg - show "cleared" message or not
1502         */
1503        public function clearCache($folder = '', $msg = true)
1504        {
1505                $maintenance = new Maintenance();
1506                return $maintenance->clearCache($this, $folder, $msg);
1507        }
1508       
1509       
1510        /**
1511         * Get all files in the specified directory except placeholder.txt
1512         *
1513         * @param string $dir - path to the folder
1514         * @param array $exclude - array of file/folder names to exclude
1515         * @return array
1516         */   
1517        public function getFiles($dir = '', $exclude = array())
1518        {
1519                $maintenance = new Maintenance();
1520                return $maintenance->getFiles($dir, $exclude);
1521        }
1522       
1523       
1524        /**
1525         * System Report is under Debug Functions
1526         */
1527   
1528   
1529 /* *************************************************************
1530 *
1531 *  CACHING FUNCTIONS (Note: "clearCache" is in Maintenance above)
1532 *
1533 * *********************************************************** */
1534       
1535       
1536        /**
1537         * Hotaru CMS Smart Caching
1538         *
1539         * This function does one query on the database to get the last updated time for a
1540         * specified table. If that time is more recent than the $timeout length (e.g. 10 minutes),
1541         * the database will be used. If there hasn't been an update, any cached results from the
1542         * last 10 minutes will be used.
1543         *
1544         * @param string $switch either "on", "off" or "html"
1545         * @param string $table DB table name
1546         * @param int $timeout time before DB cache expires
1547         * @param string $html_sql output as HTML, or an SQL query
1548         * @param string $label optional label to append to filename
1549         * @return bool
1550         */
1551        public function smartCache($switch = 'off', $table = '', $timeout = 0, $html_sql = '', $label = '')
1552        {
1553                $caching = new Caching();
1554                return $caching->smartCache($this, $switch, $table, $timeout, $html_sql, $label);
1555        }
1556       
1557       
1558        /**
1559         * Cache HTML without checking for database updates
1560         *
1561         * This function caches blocks of HTML code
1562         *
1563         * @param int $timeout timeout in minutes before cache file is deleted
1564         * @param string $html block of HTML to cache
1565         * @param string $label name to identify the cached file
1566         * @return bool
1567         */
1568        public function cacheHTML($timeout = 0, $html = '', $label = '')
1569        {
1570                $caching = new Caching();
1571                return $caching->cacheHTML($this, $timeout, $html, $label);
1572        }
1573   
1574   
1575 /* *************************************************************
1576 *
1577 *  BLOCKED FUNCTIONS (i.e. Admin's Blocked list)
1578 *
1579 * *********************************************************** */
1580 
1581         /**
1582         * Check if a value is blocked from registration and post submission)
1583         *
1584         * @param string $type - i.e. ip, url, email, user
1585         * @param string $value
1586         * @param bool $like - used for LIKE sql if true
1587         * @return bool
1588         */
1589        public function isBlocked($type = '', $value = '', $operator = '=')
1590        {
1591                $blocked = new Blocked();
1592                return $blocked->isBlocked($this->db, $type, $value, $operator);
1593        }
1594       
1595       
1596         /**
1597         * Add or update blocked items
1598         *
1599         * @param string $type - e.g. url, email, ip
1600         * @param string $value - item to block
1601         * @param bool $msg - show a success/failure message on Maintenance page
1602         * @return bool
1603         */
1604        public function addToBlockedList($type = '', $value = 0, $msg = false)
1605        {
1606                $blocked = new Blocked();
1607                return $blocked->addToBlockedList($this, $type, $value, $msg);
1608        }
1609
1610
1611 /* *************************************************************
1612 *
1613 *  LANGUAGE FUNCTIONS
1614 *
1615 * *********************************************************** */
1616
1617
1618        /**
1619         * Include a language file in a plugin
1620         *
1621         * @param string $folder name of plugin folder
1622         * @param string $filename optional filename without file extension
1623         *
1624         * Note: the language file should be in a plugin folder named 'languages'.
1625         * '_language.php' is appended automatically to the folder of file name.
1626         */
1627        public function includeLanguage($folder = '', $filename = '')
1628        {
1629                $language = new Language();
1630                $language->includeLanguage($this, $folder, $filename);
1631        }
1632   
1633   
1634        /**
1635         * Include a language file for a theme
1636         *
1637         * @param string $filename optional filename without '_language.php' file extension
1638         *
1639         * Note: the language file should be in a plugin folder named 'languages'.
1640         * '_language.php' is appended automatically to the folder of file name.
1641         */   
1642        public function includeThemeLanguage($filename = 'main')
1643        {
1644                $language = new Language();
1645                $language->includeThemeLanguage($this, $filename);
1646        }
1647   
1648   
1649/* *************************************************************
1650 *
1651 *  CSRF FUNCTIONS
1652 *
1653 * *********************************************************** */
1654
1655
1656        /**
1657         * Shortcut for CSRF functions
1658         *
1659         * @param string $type - either "set" or "check" CSRF key
1660         * @param string $script - optional name of page using the key
1661         * @param int $life - minutes before the token expires
1662         * @return string $key (if using $type "fetch")
1663         */
1664        public function csrf($type = 'check', $script = '', $life = 60)
1665        {
1666                $csrf = new csrf();
1667                return $csrf->csrfInit($this, $type, $script, $life);
1668        }
1669   
1670   
1671/* *************************************************************
1672 *
1673 *  POST FUNCTIONS
1674 *
1675 * *********************************************************** */
1676
1677
1678        /**
1679         * Get all the parameters for the current post
1680         *
1681         * @param int $post_id - Optional row from the posts table in the database
1682         * @param array $post_row - a post already fetched from the db, just needs reading
1683         * @return bool
1684         */   
1685        public function readPost($post_id = 0, $post_row = NULL)
1686        {
1687                return $this->post->readPost($this, $post_id, $post_row);
1688        }
1689       
1690       
1691        /**
1692         * Gets a single post from the database
1693         *
1694         * @param int $post_id - post id of the post to get
1695         * @return array|false
1696         */   
1697        public function getPost($post_id = 0)
1698        {
1699                return $this->post->getPost($this, $post_id);
1700        }
1701       
1702       
1703        /**
1704         * Add a post to the database
1705         *
1706         * @return int $last_insert_id
1707         */
1708        public function addPost()
1709        {
1710                return $this->post->addPost($this);
1711        }
1712       
1713       
1714        /**
1715         * Update a post in the database
1716         *
1717         * @return true
1718         */   
1719        public function updatePost()
1720        {
1721                $this->post->updatePost($this);
1722        }
1723       
1724       
1725        /**
1726         * Physically delete a post from the database
1727         *
1728         * There's a plugin hook in here to delete their parts, e.g. votes, coments, tags, etc.
1729         */   
1730        public function deletePost()
1731        {
1732                $this->post->deletePost($this);
1733        }
1734       
1735       
1736        /**
1737         * Physically delete all posts by a specified user
1738         *
1739         * @param array $user_id
1740         * @return bool
1741         */
1742        public function deletePosts($user_id = 0)
1743        {
1744                return $this->post->deletePosts($this, $user_id);
1745        }
1746       
1747       
1748        /**
1749         * Delete posts with "processing" status that are older than 30 minutes
1750         * This is called automatically when a new post is submitted
1751         */
1752        public function deleteProcessingPosts()
1753        {
1754                $this->post->deleteProcessingPosts($this);
1755        }
1756       
1757       
1758        /**
1759         * Update a post's status
1760         *
1761         * @param string $status
1762         * @param int $post_id (optional)
1763         * @return true
1764         */   
1765        public function changePostStatus($status = "processing", $post_id = 0)
1766        {
1767                return $this->post->changePostStatus($this, $status, $post_id);
1768        }
1769       
1770       
1771        /**
1772         * Count how many approved posts a user has had
1773         *
1774         * @param int $userid (optional)
1775         * @param int $post_type (optional)
1776         * @return int
1777         */
1778        public function postsApproved($userid = 0, $post_type = 'news')
1779        {
1780                return $this->post->postsApproved($this, $userid, $post_type);
1781        }
1782       
1783       
1784        /**
1785         * Count posts in the last X hours/minutes for this user
1786         *
1787         * @param int $hours
1788         * @param int $minutes
1789         * @param int $user_id (optional)
1790         * @param int $post_type (optional)
1791         * @return int
1792         */
1793        public function countPosts($hours = 0, $minutes = 0, $user_id = 0, $post_type = 'news')
1794        {
1795                return $this->post->countPosts($this, $hours, $minutes, $user_id, $post_type);
1796        }
1797       
1798       
1799        /**
1800         * Checks for existence of a url
1801         *
1802         * @return array|false - array containing existing post
1803         */   
1804        public function urlExists($url = '')
1805        {
1806                return $this->post->urlExists($this, $url);
1807        }
1808       
1809       
1810        /**
1811         * Checks for existence of a title
1812         *
1813         * @param str $title
1814         * @return int - id of post with matching title
1815         */
1816        public function titleExists($title = '')
1817        {
1818                return $this->post->titleExists($this, $title);
1819        }
1820       
1821       
1822        /**
1823         * Checks for existence of a post with given post_url
1824         *
1825         * @param str $post_url (slug)
1826         * @return int - id of post with matching url
1827         */
1828        public function isPostUrl($post_url = '')
1829        {
1830                return $this->post->isPostUrl($this, $post_url);
1831        }
1832       
1833       
1834        /**
1835         * Get Unique Post Statuses
1836         *
1837         * @return array|false
1838         */
1839        public function getUniqueStatuses()
1840        {
1841                return $this->post->getUniqueStatuses($this);
1842        }
1843       
1844       
1845        /**
1846         * Prepares and calls functions to send a trackback
1847         * Uses $h->post->id
1848         */
1849        public function sendTrackback()
1850        {
1851                $trackback = new Trackback();
1852                return $trackback->sendTrackback($this);
1853        }
1854   
1855   
1856/* *************************************************************
1857 *
1858 *  AVATAR FUNCTIONS
1859 *
1860 * *********************************************************** */
1861 
1862
1863        /**
1864         * setAvatar
1865         *
1866         * @param $user_id
1867         * @param $size avatar size in pixels
1868         * @param $rating avatar rating (g, pg, r or x in Gravatar)
1869         * @return bool
1870         */
1871        public function setAvatar($user_id = 0, $size = 32, $rating = 'g')
1872        {
1873                return $this->avatar = new Avatar($this, $user_id, $size, $rating);
1874        }
1875       
1876       
1877        /**
1878         * get the plain avatar with no surrounding HTML div
1879         *
1880         * @return return the avatar
1881         */
1882        public function getAvatar()
1883        {
1884                return $this->avatar->getAvatar($this);
1885        }
1886       
1887       
1888        /**
1889         * option to display the avatar linked to ther user's profile
1890         *
1891         * @return return the avatar
1892         */
1893        public function linkAvatar()
1894        {
1895                return $this->avatar->linkAvatar($this);
1896        }
1897       
1898       
1899        /**
1900         * option to display the profile-linked avatar wrapped in a div
1901         *
1902         * @return return the avatar
1903         */
1904        public function wrapAvatar()
1905        {
1906                return $this->avatar->wrapAvatar($this);
1907        }
1908   
1909   
1910/* *************************************************************
1911 *
1912 *  CATEGORY FUNCTIONS
1913 *
1914 * *********************************************************** */
1915
1916        /**
1917         * Returns the category id for a given category safe name.
1918         *
1919         * @param string $cat_name
1920         * @return int
1921         */
1922        public function getCatId($cat_safe_name = '')
1923        {
1924                $category = new Category();
1925                return $category->getCatId($this, $cat_safe_name);
1926        }
1927       
1928       
1929        /**
1930         * Returns the category name for a given category id or safe name.
1931         *
1932         * @param int $cat_id
1933         * @param string $cat_safe_name
1934         * @return string
1935         */
1936        public function getCatName($cat_id = 0, $cat_safe_name = '')
1937        {
1938                $category = new Category();
1939                return $category->getCatName($this, $cat_id, $cat_safe_name);
1940        }
1941       
1942       
1943        /**
1944         * Returns the category safe name for a given category id
1945         *
1946         * @param int $cat_id
1947         * @return string
1948         */
1949        public function getCatSafeName($cat_id = 0)
1950        {
1951                $category = new Category();
1952                return $category->getCatSafeName($this, $cat_id);
1953        }
1954       
1955       
1956        /**
1957         * Returns parent id
1958         *
1959         * @param int $cat_id
1960         * @return int
1961         */
1962        public function getCatParent($cat_id = 0)
1963        {
1964                $category = new Category();
1965                return $category->getCatParent($this, $cat_id);
1966        }
1967       
1968       
1969        /**
1970         * Returns child ids
1971         *
1972         * @param int $cat_parent_id
1973         * @return int
1974         */
1975        public function getCatChildren($cat_parent_id = 0)
1976        {
1977                $category = new Category();
1978                return $category->getCatChildren($this, $cat_parent_id);
1979        }
1980       
1981         /**
1982         * Returns Category list ids
1983         *
1984         * @param array $args
1985         * @return int
1986         */
1987        public function getCategories($args = array())
1988        {
1989                $category = new Category();
1990                return $category->getCategories($this, $args);
1991        }
1992       
1993       
1994        /**
1995         * Returns meta description and keywords for the category (if available)
1996         *
1997         * @param int $cat_id
1998         * @return array|false
1999         */
2000        public function getCatMeta($cat_id = 0)
2001        {
2002                $category = new Category();
2003                return $category->getCatMeta($this, $cat_id);
2004        }
2005
2006
2007        /**
2008         * Add a new category
2009         *
2010         * @param int $parent
2011         * @param string $new_cat_name
2012         * @return bool
2013         */
2014        public function addCategory($parent = 0, $new_cat_name = '')
2015        {
2016                $category = new Category();
2017                return $category->addCategory($this, $parent, $new_cat_name);
2018        }
2019
2020
2021        /**
2022         * rebuild the category tree
2023         *
2024         * @param int $parent_id
2025         * @param int $left
2026         * @return int
2027         */
2028        public function rebuildTree($parent_id = 0, $left = 0)
2029        {
2030                $category = new Category();
2031                return $category->rebuildTree($this, $parent_id, $left);
2032        }
2033
2034
2035        /**
2036         * Delete a category
2037         *
2038         * @param int $delete_category
2039         * @return bool
2040         */
2041        function deleteCategory($delete_category = 0)
2042        {
2043                $category = new Category();
2044                return $category->deleteCategory($this, $delete_category);
2045        }
2046
2047
2048/* *************************************************************
2049 *
2050 *  COMMENT FUNCTIONS
2051 *
2052 * *********************************************************** */
2053
2054        /**
2055         * Count comments
2056         *
2057         * @param bool $digits_only - return just the count (if false, returns "3 comments", etc.)
2058         * @param string $no_comments_text - e.g. "Leave a comment" or "No comments"
2059         * @return string - text to show, e.g. "3 comments"
2060         */
2061        function countComments($digits_only = true, $no_comments_text = '')
2062        {
2063                $comment = new Comment();
2064                return $comment->countComments($this, $digits_only, $no_comments_text);
2065        }
2066       
2067       
2068        /**
2069         * Count all user comments
2070         *
2071         * @param int $user_id
2072         * @return int
2073         */
2074        function countUserComments($user_id = 0)
2075        {
2076                $comment = new Comment();
2077                return $comment->countUserComments($this, $user_id);
2078        }
2079       
2080       
2081        /**
2082         * Physically delete all comments by a specified user (and responses)
2083         *
2084         * @param array $user_id
2085         * @return bool
2086         */
2087        public function deleteComments($user_id)
2088        {
2089                $comment = new Comment();
2090                return $comment->deleteComments($this, $user_id);
2091        }
2092       
2093       
2094        /**
2095         * Get comment from database
2096         *
2097         * @param int $comment_id
2098         * @return array|false
2099         */
2100        function getComment($comment_id = 0)
2101        {
2102                $comment = new Comment();
2103                return $comment->getComment($this, $comment_id);
2104        }
2105       
2106       
2107        /**
2108         * Read comment
2109         *
2110         * @param array $comment_row pulled from database
2111         */
2112        function readComment($comment_row = array())
2113        {
2114                $comment = new Comment();
2115                return $comment->readComment($this, $comment_row);
2116        }
2117   
2118   
2119/* *************************************************************
2120 *
2121 *  WIDGET FUNCTIONS
2122 *
2123 * *********************************************************** */
2124
2125        /**
2126         * Add widget
2127         *
2128         * @param string $plugin
2129         * @param string $function
2130         * @param string $value
2131         */
2132        public function addWidget($plugin = '', $function = '', $args = '')
2133        {
2134                $widget = new Widget();
2135                $widget->addWidget($this, $plugin, $function, $args);
2136        }
2137       
2138
2139        /**
2140         * Get widgets from widgets_settings array
2141         *
2142         * USAGE: foreach ($widgets as $widget=>$details)
2143         * { echo "Name: " . $widget; echo $details['order']; echo $details['args']; }
2144         *
2145         * @param $widget_name - optional for a single widget
2146         * @return array - of widgets
2147         */
2148        public function getArrayWidgets($widget_name = '')
2149        {
2150                $widget = new Widget();
2151                return $widget->getArrayWidgets($this, $widget_name);
2152        }
2153       
2154       
2155        /**
2156         * Delete a widget from the widget db table
2157         *
2158         * @param string $function
2159         * @param string $plugin - plugin folder (optional: used for double checking the plugin is uninstalled)
2160         */
2161        public function deleteWidget($function = '', $plugin = '')
2162        {
2163                $widget = new Widget();
2164                $widget->deleteWidget($this, $function, $plugin);
2165        }
2166       
2167       
2168        /**
2169         * Get plugin name from widget function name
2170         *
2171         * @return string
2172         */
2173        public function getPluginFromFunction($function)
2174        {
2175                $widget = new Widget();
2176                return $widget->getPluginFromFunction($this, $function);
2177        }
2178   
2179   
2180/* *************************************************************
2181 *
2182 *  EMAIL FUNCTIONS
2183 *
2184 * *********************************************************** */
2185 
2186        /**
2187         * Send emails
2188         *
2189         * @param string $to - defaults to SITE_EMAIL
2190         * @param string $subject - defaults to "No Subject";
2191         * @param string $body - returns false if empty
2192         * @param string $headers default is "From: " . SITE_EMAIL . "\r\nReply-To: " . SITE_EMAIL . "\r\nX-Priority: 3\r\n";
2193         * @param string $type - default is "email", but you can write to a "log" file, print to "screen" or "return" an array of the content
2194         * @return array|false - only if $type = "return"
2195         */
2196        public function email($to = '', $subject = '', $body = '', $headers = '', $type = 'email')
2197        {
2198                if (!is_object($this->email)) {
2199                        $this->email = new EmailFunctions();
2200                }
2201               
2202                $this->email->to = $to;
2203                $this->email->subject = $subject;
2204                $this->email->body = $body;
2205                $this->email->headers = $headers;
2206                $this->email->type = $type;
2207               
2208                return $this->email->doEmail();
2209        }
2210       
2211       
2212/* *************************************************************
2213 *
2214 *  FRIEND FUNCTIONS
2215 *
2216 * *********************************************************** */
2217
2218        /**
2219         * count followers
2220         *
2221         * @param int $user_id - get people following this user
2222         * @return int
2223         */
2224        public function countFollowers($user_id = 0)
2225        {
2226                $friends = new Friends();
2227                return $friends->countFriends($this, $user_id, 'follower');
2228        }
2229       
2230       
2231        /**
2232         * count following
2233         *
2234         * @param int $user_id - get people following this user
2235         * @return int
2236         */
2237        public function countFollowing($user_id = 0)
2238        {
2239                $friends = new Friends();
2240                return $friends->countFriends($this, $user_id, 'following');
2241        }
2242       
2243       
2244        /**
2245         * get followers
2246         *
2247         * @param int $user_id - get this user's followers
2248         * @param string $return - return 'array' of users of prepared 'query'
2249         * @return array|string
2250         */
2251        public function getFollowers($user_id = 0, $return = 'array')
2252        {
2253                $friends = new Friends();
2254                return $friends->getFriends($this, $user_id, 'follower', $return);
2255        }
2256       
2257       
2258        /**
2259         * get people this user is following
2260         *
2261         * @param int $user_id
2262         * @param string $return - return 'array' of users of prepared 'query'
2263         * @return array|string
2264         */
2265        public function getFollowing($user_id = 0, $return = 'array')
2266        {
2267                $friends = new Friends();
2268                return $friends->getFriends($this, $user_id, 'following', $return);
2269        }
2270       
2271       
2272        /**
2273         * Is current user being followed by user X?
2274         *
2275         * @param int $user_id - user X
2276         * @return bool
2277         */
2278        public function isFollower($user_id = 0)
2279        {
2280                $friends = new Friends();
2281                return $friends->checkFriends($this, $user_id, 'follower');
2282        }
2283       
2284       
2285        /**
2286         * Is current user following user X?
2287         *
2288         * @param int $user_id - user X
2289         * @return bool
2290         */
2291        public function isFollowing($user_id = 0)
2292        {
2293                $friends = new Friends();
2294                return $friends->checkFriends($this, $user_id, 'following');
2295        }
2296       
2297       
2298        /**
2299         * Follow / become a fan of user X
2300         *
2301         * @param int $follow - user to follow
2302         * @return bool
2303         */
2304        public function follow($user_id = 0)
2305        {
2306                $friends = new Friends();
2307                return $friends->updateFriends($this, $user_id, 'follow');
2308        }
2309       
2310       
2311        /**
2312         * Unfollow / stop being a fan of user X
2313         *
2314         * @param int $unfollow - user to stop following
2315         * @return bool
2316         */
2317        public function unfollow($user_id = 0)
2318        {
2319                $friends = new Friends();
2320                return $friends->updateFriends($this, $user_id, 'unfollow');
2321        }
2322       
2323       
2324 /* *************************************************************
2325 *
2326 *  SITE ACTIVITY FUNCTIONS
2327 *
2328 * *********************************************************** */
2329 
2330 
2331        /**
2332         * Get the latest site activity
2333         *
2334         * @param int $limit
2335         * @param int $userid
2336         * @param string $type blank or "count" or "query"
2337         * @return array|false
2338         */
2339        public function getLatestActivity($limit = 0, $userid = 0, $type = '')
2340        {
2341                $activity = new UserActivity();
2342                return $activity->getLatestActivity($this, $limit, $userid, $type);
2343        }
2344       
2345       
2346        /**
2347         * Check if an action already exists
2348         *
2349         * @param array $args e.g. array('userid'=>4, 'key'=>'post', 'value'=>'6408')
2350         * @return bool
2351         */
2352        public function activityExists($args = array())
2353        {
2354                $activity = new UserActivity();
2355                return $activity->activityExists($this, $args);
2356        }
2357       
2358       
2359        /**
2360         * Insert new activity
2361         *
2362         * @param array $args e.g. array('userid'=>4, 'key'=>'post', 'value'=>'6408')
2363         */
2364        public function insertActivity($args = array())
2365        {
2366                $activity = new UserActivity();
2367                return $activity->insertActivity($this, $args);
2368        }
2369       
2370       
2371        /**
2372         * Update activity
2373         *
2374         * @param array $args e.g. array('userid'=>4, 'key'=>'post', 'value'=>'6408')
2375         */
2376        public function updateActivity($args = array())
2377        {
2378                $activity = new UserActivity();
2379                return $activity->updateActivity($this, $args);
2380        }
2381       
2382       
2383        /**
2384         * Remove activity
2385         *
2386         * @param array $args e.g. array('userid'=>4, 'key'=>'post', 'value'=>'6408')
2387         */
2388        public function removeActivity($args = array())
2389        {
2390                $activity = new UserActivity();
2391                return $activity->removeActivity($this, $args);
2392        }
2393       
2394       
2395 /* *************************************************************
2396 *
2397 *  MESSAGING FUNCTIONS
2398 *
2399 * *********************************************************** */
2400 
2401
2402        /**
2403         * Get Messages
2404         *
2405         * @param string $box "inbox" or "outbox"
2406         * @param string $type blank or "count" or "query"
2407         * @return int | array | false
2408         */
2409        public function getMessages($box = 'inbox', $type = '')
2410        {
2411                $pm = new PrivateMessaging();
2412                return $pm->getMessages($this, $box, $type);
2413        }
2414       
2415       
2416        /**
2417         * Get Message
2418         *
2419         * @param int $message_id
2420         * @return array
2421         */
2422        public function getMessage($message_id = 0)
2423        {
2424                $pm = new PrivateMessaging();
2425                return $pm->getMessage($this, $message_id);
2426        }
2427         
2428         
2429        /**
2430         * Mark message as read
2431         *
2432         * @param int $message_id
2433         */
2434        public function markRead($message_id = 0)
2435        {
2436                $pm = new PrivateMessaging();
2437                $pm->markRead($this, $message_id);
2438        }
2439       
2440       
2441        /**
2442         * Delete Message
2443         *
2444         * @param int $message_id
2445         * @param string $box "inbox" or "outbox"
2446         * @return bool
2447         */
2448        public function deleteMessage($message_id = 0, $box = 'inbox')
2449        {
2450                $pm = new PrivateMessaging();
2451                $pm->deleteMessage($this, $message_id, $box);
2452        }
2453       
2454       
2455        /**
2456         * Send Message
2457         *
2458         * @param string $to
2459         * @param string $from
2460         * @param string $subject
2461         * @param string $body
2462         * @return int | array (int on success, array on failure)
2463         */
2464        public function sendMessage($to = '', $from = '', $subject = '', $body = '')
2465        {
2466                $pm = new PrivateMessaging();
2467                return $pm->sendMessage($this, $to, $from, $subject, $body);
2468        }
2469
2470
2471 /* *************************************************************
2472 *
2473 *  VOTE FUNCTIONS
2474 *
2475 * *********************************************************** */
2476 
2477
2478        /**
2479         * Get Individual Vote Rating
2480         *
2481         * @param int $post_id
2482         * @param int $user_id
2483         * @param string $ip
2484         * @param bool $anon
2485         * @return int - vote rating e.g. 10, -10
2486         */
2487        public function getVoteRating($post_id = 0, $user_id = 0, $ip = '', $anon = false)
2488        {
2489                return VoteFunctions::getVoteRating($this, $post_id, $user_id, $ip, $anon);
2490        }
2491
2492
2493        /**
2494         * Get Post Vote Info
2495         *
2496         * @param int $post_id
2497         * @return array|false
2498         */
2499        public function getPostVoteInfo($post_id = 0)
2500        {
2501                return VoteFunctions::getPostVoteInfo($this, $post_id);
2502        }
2503
2504
2505        /**
2506         * Add Vote to PostVotes table
2507         *
2508         * @param int $post_id
2509         * @param int $user_id
2510         * @param string $ip
2511         * @param int $rating
2512         * @param string $type - usually the plugin name
2513         */
2514        public function addVote($post_id = 0, $user_id = 0, $ip = '', $rating = 0, $type = 'vote')
2515        {
2516                VoteFunctions::addVote($this, $post_id, $user_id, $ip, $rating, $type);
2517        }
2518
2519
2520        /**
2521         * Update Post Vote Info
2522         *
2523         * @param int $post_id
2524         * @param int $post_votes_up - either -1, 0 or 1
2525         * @param int $post_votes_down - either -1, 0 or 1
2526         * @param string $post_status
2527         * @param bool $pub_date - set to TRUE to update to current time
2528         */
2529        public function updatePostVoteInfo($post_id = 0, $post_votes_up = 0, $post_votes_down = 0, $post_status = '', $pub_date = FALSE)
2530        {
2531                VoteFunctions::updatePostVoteInfo($this, $post_id, $post_votes_up, $post_votes_down, $post_status, $pub_date);
2532        }
2533
2534
2535        /**
2536         * Delete Vote from PostVotes table
2537         *
2538         * @param int $post_id
2539         * @param int $user_id
2540         * @param int $rating
2541         * @param string $ip
2542         * @param bool $anon
2543         */
2544        public function deleteVote($post_id = 0, $user_id = 0, $rating = 0, $ip = '', $anon = FALSE)
2545        {
2546                VoteFunctions::deleteVote($this, $post_id, $user_id, $rating, $ip, $anon);
2547        }
2548
2549
2550        /**
2551         * Count votes by a user
2552         *
2553         * @param string $type - 'all', 'pos', 'neg', 'flags' (flags not included in 'all')
2554         * @param int $user_id
2555         * return int|false
2556         */
2557        public function countUserVotes($type = 'all', $user_id = 0)
2558        {
2559                return VoteFunctions::countUserVotes($this, $type, $user_id);
2560        }
2561}
2562?>
Note: See TracBrowser for help on using the browser.