source: branches/1.3/Hotaru.php @ 1737

Revision 1737, 60.3 KB checked in by nick_ramsay, 3 years ago (diff)

[Branch 1.3] Moved smartLoader into Extensions and made it refresh itself on "clear all cache folders" in Maintenance.

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