source: branches/1.0/content/plugins/sb_base/sb_base.php @ 1170

Revision 1170, 28.7 KB checked in by nick_ramsay, 3 years ago (diff)

[Branch 1.0] Replaced 3rd party Paginated class with my own. Updated all files that use pagination to use the new class. This change means that instead of retrieving ALL comments, posts etc and dividing them into pages, it now only gets the data for the page you're looking at. Therefore saving large sites from crashing on shared servers! :-P

Line 
1<?php
2/**
3 * name: SB Base
4 * description: Social Bookmarking base - provides "list" and "post" templates.
5 * version: 0.1
6 * folder: sb_base
7 * class: SbBase
8 * type: base
9 * hooks: install_plugin, theme_index_top, header_meta, header_include, navigation, breadcrumbs, theme_index_main, admin_plugin_settings, admin_sidebar_plugin_settings, admin_maintenance_database, admin_maintenance_top, admin_theme_main_stats, user_settings_pre_save, user_settings_fill_form, user_settings_extra_settings, theme_index_pre_main
10 * author: Nick Ramsay
11 * authorurl: http://hotarucms.org/member.php?1-Nick
12 *
13 * PHP version 5
14 *
15 * LICENSE: Hotaru CMS is free software: you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License as
17 * published by the Free Software Foundation, either version 3 of
18 * the License, or (at your option) any later version.
19 *
20 * Hotaru CMS is distributed in the hope that it will be useful, but WITHOUT
21 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
22 * FITNESS FOR A PARTICULAR PURPOSE.
23 *
24 * You should have received a copy of the GNU General Public License along
25 * with Hotaru CMS. If not, see http://www.gnu.org/licenses/.
26 *
27 * @category  Content Management System
28 * @package   HotaruCMS
29 * @author    Nick Ramsay <admin@hotarucms.org>
30 * @copyright Copyright (c) 2009, Hotaru CMS
31 * @license   http://www.gnu.org/copyleft/gpl.html GNU General Public License
32 * @link      http://www.hotarucms.org/
33 */
34
35class SbBase
36{
37    /**
38     * Install Submit settings if they don't already exist
39     */
40    public function install_plugin($h)
41    {
42        // Default settings
43        $sb_base_settings = $h->getSerializedSettings();
44        if (!isset($sb_base_settings['posts_per_page'])) { $sb_base_settings['posts_per_page'] = 10; }
45        if (!isset($sb_base_settings['archive'])) { $sb_base_settings['archive'] = "no_archive"; }
46        $h->updateSetting('sb_base_settings', serialize($sb_base_settings));
47       
48        // Add "open in new tab" option to the default user settings
49        $base_settings = $h->getDefaultSettings('base'); // originals from plugins
50        $site_settings = $h->getDefaultSettings('site'); // site defaults updated by admin
51        if (!isset($base_settings['new_tab'])) {
52            $base_settings['new_tab'] = ""; $site_settings['new_tab'] = "";
53            $h->updateDefaultSettings($base_settings, 'base');
54            $h->updateDefaultSettings($site_settings, 'site');
55        }
56        if (!isset($base_settings['link_action'])) {
57            $base_settings['link_action'] = ""; $site_settings['link_action'] = "";
58            $h->updateDefaultSettings($base_settings, 'base');
59            $h->updateDefaultSettings($site_settings, 'site');
60        }
61    }
62   
63   
64    /**
65     * Determine the pageType
66     */
67    public function theme_index_top($h)
68    {
69        // check if we're using the sort/filter links
70        if ($h->cage->get->keyExists('sort')) {
71            $h->pageName = 'sort';
72        }
73       
74        // include sb_base_functions class:
75        require_once(PLUGINS . 'sb_base/libs/SbBaseFunctions.php');
76        $sb_funcs = new SbBaseFunctions();
77       
78        switch ($h->pageName)
79        {
80            case 'rss':
81                $sb_funcs->rssFeed($h);
82                exit;
83                break;
84            case 'index':
85                $h->pageType = 'list';
86                $h->pageTitle = $h->lang["sb_base_site_name"];
87                break;
88            case 'latest':
89                $h->pageType = 'list';
90                $h->pageTitle = $h->lang["sb_base_latest"];
91                break;
92            case 'upcoming':
93                $h->pageType = 'list';
94                $h->pageTitle = $h->lang["sb_base_upcoming"];
95                break;
96            case 'all':
97                $h->pageType = 'list';
98                $h->pageTitle = $h->lang["sb_base_all"];
99                break;
100            case 'sort':
101                $h->pageType = 'list';
102                $sort = $h->cage->get->testPage('sort');
103                $sort_lang = 'sb_base_' . str_replace('-', '_', $sort);
104                $h->pageTitle = $h->lang[$sort_lang];
105                break;
106            default:
107                // no default or we'd mess up anything set by other plugins
108        }
109       
110        $h->pluginHook('sb_base_theme_index_top');
111       
112        if (!$h->pageName && $h->cage->get->keyExists('pg')) {
113            $h->pageName = 'index';
114            $h->pageType = 'list';
115            $h->pageTitle = $h->lang["sb_base_site_name"];
116        }
117       
118        // stop here if not a list or the pageType has been set elsewhere:
119        if (!empty($h->pageType) && ($h->pageType != 'list') && ($h->pageType != 'post')) {
120            return false;
121        }
122       
123        // get settings
124        $h->vars['sb_base_settings'] = $h->getSerializedSettings('sb_base');
125        $h->vars['posts_per_page'] = $h->vars['sb_base_settings']['posts_per_page'];
126       
127        // if a list, get the posts:
128        switch ($h->pageType)
129        {
130            case 'list':
131                $h->vars['post_count'] = $sb_funcs->prepareList($h, '', 'count');   // get the number of posts
132                $h->vars['post_query'] = $sb_funcs->prepareList($h, '', 'query');   // and the SQL query used
133                break;
134            case 'post':
135                // if a post is already set (e.g. from the sb_categories plugin), we don't want to
136                // do the default stuff below. We do, however, need the "target", "editorial" stuff after it, though...
137                break;
138            default:
139                // Probably a post, let's check:
140                if (is_numeric($h->pageName)) {
141                    // Page name is a number so it must be a post with non-friendly urls
142                    $exists = $h->readPost($h->pageName);    // read current post
143                    if (!$exists) { $h->pageTitle = $h->lang['main_theme_page_not_found']; return false; }
144                    $h->pageTitle = $h->post->title;
145                    $h->pageType = 'post';
146                } elseif ($post_id = $h->isPostUrl($h->pageName)) {
147                    // Page name belongs to a story
148                    $h->readPost($post_id);    // read current post
149                    $h->pageTitle = $h->post->title;
150                    $h->pageType = 'post';
151                }
152        } // close switch
153       
154        // user defined settings:
155       
156        if (!$h->currentUser->settings) {
157            // logged out users get the default settings:
158            $h->currentUser->settings = $h->getDefaultSettings('site');
159        }
160       
161        // open links in a new tab?
162        if ($h->currentUser->settings['new_tab']) {
163            $h->vars['target'] = 'target="_blank"';
164        } else {
165            $h->vars['target'] = '';
166        }
167       
168        // open link to the source or the site post?
169        if ($h->currentUser->settings['link_action']) {
170            $h->vars['link_action'] = 'source';
171        } else {
172            $h->vars['link_action'] = '';
173        }
174       
175        // editorial (story with an internal link)
176        if (strstr($h->post->origUrl, BASEURL)) {
177            $h->vars['editorial'] = true;
178        } else {
179            $h->vars['editorial'] = false;
180        }
181       
182        // get settings from Submit
183        if (!isset($h->vars['submit_settings'])) {
184            $h->vars['submit_settings'] = $h->getSerializedSettings('submit');
185        }
186    }
187   
188   
189    /**
190     * Match meta tag to a post's description (keywords is done in the Tags plugin)
191     */
192    public function header_meta($h)
193    {   
194        if ($h->pageType != 'post') { return false; }
195        $meta_content = sanitize($h->post->content, 'all');
196        $meta_content = truncate($meta_content, 200);
197        echo '<meta name="description" content="' . $meta_content . '">' . "\n";
198        return true;
199    }
200   
201   
202    /**
203     * Add "Latest" to the navigation bar
204     */
205    public function navigation($h)
206    {
207        // highlight "Latest" as active tab
208        if ($h->pageName == 'latest') { $status = "id='navigation_active'"; } else { $status = ""; }
209       
210        // display the link in the navigation bar
211        echo "<li><a  " . $status . " href='" . $h->url(array('page'=>'latest')) . "'>" . $h->lang["sb_base_latest"] . "</a></li>\n";
212    }
213   
214   
215    /**
216     * Replace the default breadcrumbs in specific circumstances
217     */
218    public function breadcrumbs($h)
219    {
220        if ($h->pageName == 'index') {
221            $h->pageTitle = $h->lang["sb_base_top"];
222        }
223       
224        switch ($h->pageName) {
225            case 'index':
226                return $h->pageTitle . ' ' . $h->rssBreadcrumbsLink('top');
227                break;
228            case 'latest':
229                return $h->pageTitle . ' ' . $h->rssBreadcrumbsLink('new');
230                break;
231            case 'upcoming':
232                return $h->pageTitle . ' ' . $h->rssBreadcrumbsLink('upcoming');
233                break;
234            case 'all':
235                return $h->pageTitle . ' ' . $h->rssBreadcrumbsLink();
236                break;
237        }
238    }
239   
240   
241    /**
242     * Determine which template to show and do preparation of variables, etc.
243     */
244    public function theme_index_main($h)
245    {
246        // stop here if not a list of a post
247        if (($h->pageType != 'list') && ($h->pageType != 'post')) { return false; }
248       
249        // necessary settings:
250        $h->vars['use_content'] = $h->vars['submit_settings']['content'];
251        $h->vars['use_summary'] = $h->vars['submit_settings']['summary'];
252        $h->vars['summary_length'] = $h->vars['submit_settings']['summary_length'];
253       
254        switch ($h->pageType)
255        {
256            case 'post':
257                // This post is visible if it's not buried/pending OR if the viewer has edit post permissions...
258               
259                // defaults:
260                $buried = false; $pending = false; $can_edit = false;
261               
262                // check if buried:
263                if ($h->post->status == 'buried') {
264                    $buried = true;
265                    $h->messages[$h->lang["sb_base_post_buried"]] = "red";
266                }
267               
268                // check if pending:
269                if ($h->post->status == 'pending') {
270                    $pending = true;
271                    $h->messages[$h->lang["sb_base_post_pending"]] = "red";
272                }
273               
274                // check if global edit permissions
275                if ($h->currentUser->getPermission('can_edit_posts') == 'yes') { $can_edit = true; }
276
277                // display post or show error message
278                if (!$buried && !$pending){
279                    $h->displayTemplate('sb_post');
280                } elseif ($can_edit) {
281                    $h->showMessages();
282                    $h->displayTemplate('sb_post');
283                } else {
284                    $h->showMessages();
285                }
286               
287                return true;
288                break;
289               
290            case 'list':
291               
292                $h->displayTemplate('sb_list');
293                return true;
294        }
295    }
296   
297   
298    /**
299     * Archive option on Maintenance page
300     */
301    public function admin_maintenance_database($h)
302    {
303        $sb_base_settings = $h->getSerializedSettings();
304        $archive = $sb_base_settings['archive'];
305        echo "<li><a href='" . BASEURL . "admin_index.php?page=maintenance&amp;action=update_archive'>";
306        echo $h->lang["sb_base_maintenance_update_archive"] . "</a> - ";
307        if ($archive == 'no_archive') {
308            echo $h->lang["sb_base_maintenance_update_archive_remove"];
309        } else {
310            echo $h->lang["sb_base_maintenance_update_archive_desc_1"];
311            echo $h->lang["sb_base_settings_post_archive_$archive"];
312            echo $h->lang["sb_base_maintenance_update_archive_desc_2"];
313        }
314        echo "</li>";
315    }
316   
317   
318    /**
319     * Perform archiving tasks
320     */
321    public function admin_maintenance_top($h)
322    {
323        if ($h->cage->get->testAlnumLines('action') != 'update_archive') { return false; }
324       
325        $sb_base_settings = $h->getSerializedSettings();
326        $archive = $sb_base_settings['archive'];
327       
328        // FIRST, WE NEED TO RESET THE ARCHIVE, setting all archive fields to "N":
329       
330        // posts
331        if ($h->db->table_exists('posts')) {
332            $sql = "UPDATE " . DB_PREFIX . "posts SET post_archived = %s";
333            $h->db->query($h->db->prepare($sql, 'N'));
334        }
335       
336        // postmeta
337        if ($h->db->table_exists('postmeta')) {
338            $sql = "UPDATE " . DB_PREFIX . "postmeta SET postmeta_archived = %s";
339            $h->db->query($h->db->prepare($sql, 'N'));
340        }
341       
342        // postvotes
343        if ($h->db->table_exists('postvotes')) {
344            $sql = "UPDATE " . DB_PREFIX . "postvotes SET vote_archived = %s";
345            $h->db->query($h->db->prepare($sql, 'N'));
346        }
347       
348        // comments
349        if ($h->db->table_exists('comments')) {
350            $sql = "UPDATE " . DB_PREFIX . "comments SET comment_archived = %s";
351            $h->db->query($h->db->prepare($sql, 'N'));
352        }
353       
354        // commentvotes
355        if ($h->db->table_exists('commentvotes')) {
356            $sql = "UPDATE " . DB_PREFIX . "commentvotes SET cvote_archived = %s";
357            $h->db->query($h->db->prepare($sql, 'N'));
358        }
359       
360        // tags
361        if ($h->db->table_exists('tags')) {
362            $sql = "UPDATE " . DB_PREFIX . "tags SET tags_archived = %s";
363            $h->db->query($h->db->prepare($sql, 'N'));
364        }
365       
366        // useractivity
367        if ($h->db->table_exists('useractivity')) {
368            $sql = "UPDATE " . DB_PREFIX . "useractivity SET useract_archived = %s";
369            $h->db->query($h->db->prepare($sql, 'N'));
370        }
371       
372        // RETURN NOW IF NO_ARCHIVE IS SET *****************************
373        if ($archive == 'no_archive') {
374            $h->message = $h->lang['sb_base_maintenance_archive_removed'];
375            $h->messageType = 'green';
376            $h->showMessage();
377            return true;
378        }
379       
380        // NEXT, START ARCHIVING! *****************************
381        $archive_text = "-" . $archive . " days"; // e.g. "-365 days"
382        $archive_date = date('YmdHis', strtotime($archive_text));
383       
384        // posts
385        if ($h->db->table_exists('posts')) {
386            $sql = "UPDATE " . DB_PREFIX . "posts SET post_archived = %s WHERE post_date <= %s";
387            $h->db->query($h->db->prepare($sql, 'Y', $archive_date));
388        }
389       
390        // postmeta
391        if ($h->db->table_exists('postmeta')) {
392            // No date field in postmeta table so join with posts table...
393            $sql = "UPDATE " . DB_PREFIX . "postmeta, " . DB_PREFIX . "posts  SET " . DB_PREFIX . "postmeta.postmeta_archived = %s WHERE (" . DB_PREFIX . "posts.post_date <= %s) AND (" . DB_PREFIX . "posts.post_id = " . DB_PREFIX . "postmeta.postmeta_postid)";
394            $h->db->query($h->db->prepare($sql, 'Y', $archive_date));
395        }
396       
397        // postvotes
398        if ($h->db->table_exists('postvotes')) {
399            $sql = "UPDATE " . DB_PREFIX . "postvotes SET vote_archived = %s WHERE vote_date <= %s";
400            $h->db->query($h->db->prepare($sql, 'Y', $archive_date));
401        }
402       
403        // comments
404        if ($h->db->table_exists('comments')) {
405            $sql = "UPDATE " . DB_PREFIX . "comments SET comment_archived = %s WHERE comment_date <= %s";
406            $h->db->query($h->db->prepare($sql, 'Y', $archive_date));
407        }
408       
409        // commentvotes
410        if ($h->db->table_exists('commentvotes')) {
411            $sql = "UPDATE " . DB_PREFIX . "commentvotes SET cvote_archived = %s WHERE cvote_date <= %s";
412            $h->db->query($h->db->prepare($sql, 'Y', $archive_date));
413        }
414       
415        // tags
416        if ($h->db->table_exists('tags')) {
417            $sql = "UPDATE " . DB_PREFIX . "tags SET tags_archived = %s WHERE tags_date <= %s";
418            $h->db->query($h->db->prepare($sql, 'Y', $archive_date));
419        }
420
421        // useractivity
422        if ($h->db->table_exists('useractivity')) {
423            $sql = "UPDATE " . DB_PREFIX . "useractivity SET useract_archived = %s WHERE useract_date <= %s";
424            $h->db->query($h->db->prepare($sql, 'Y', $archive_date));
425        }
426
427        $h->message = $h->lang['sb_base_maintenance_archive_updated'];
428        $h->messageType = 'green';
429        $h->showMessage();
430        return true;
431
432    }
433   
434   
435    /**
436     * Show stats on Admin home page
437     */
438    public function admin_theme_main_stats($h, $vars)
439    {
440        echo "<li>&nbsp;</li>";
441   
442        foreach ($vars as $stat_type) {
443            $posts = $h->post->stats($h, $stat_type);
444            if (!$posts) { $posts = 0; }
445            $lang_name = 'sb_base_admin_stats_' . $stat_type;
446            echo "<li>" . $h->lang[$lang_name] . ": " . $posts . "</li>";
447        }
448    }
449   
450   
451    /**
452     * User Settings - before saving
453     */
454    public function user_settings_pre_save($h)
455    {
456        // Open posts in a new tab?
457        if ($h->cage->post->getAlpha('new_tab') == 'yes') {
458            $h->vars['settings']['new_tab'] = "checked";
459        } else {
460            $h->vars['settings']['new_tab'] = "";
461        }
462       
463        // List links open source url or post page?
464        if ($h->cage->post->getAlpha('link_action') == 'source') {
465            $h->vars['settings']['link_action'] = "checked";
466        } else {
467            $h->vars['settings']['link_action'] = "";
468        }
469    }
470   
471   
472    /**
473     * User Settings - fill the form
474     */
475    public function user_settings_fill_form($h)
476    {
477        if (!isset($h->vars['settings']) || !$h->vars['settings']) { return false; }
478       
479        if ($h->vars['settings']['new_tab']) {
480            $h->vars['new_tab_yes'] = "checked";
481            $h->vars['new_tab_no'] = "";
482        } else {
483            $h->vars['new_tab_yes'] = "";
484            $h->vars['new_tab_no'] = "checked";
485        }
486       
487        if ($h->vars['settings']['link_action']) {
488            $h->vars['link_action_source'] = "checked";
489            $h->vars['link_action_post'] = "";
490        } else {
491            $h->vars['link_action_source'] = "";
492            $h->vars['link_action_post'] = "checked";
493        }
494    }
495   
496   
497    /**
498     * User Settings - html for form
499     */
500    public function user_settings_extra_settings($h)
501    {
502        if (!isset($h->vars['settings']) || !$h->vars['settings']) { return false; }
503       
504        echo "<tr>\n";
505            // OPEN POSTS IN A NEW TAB?
506        echo "<td>" . $h->lang['sb_base_users_settings_open_new_tab'] . "</td>\n";
507        echo "<td><input type='radio' name='new_tab' value='yes' " . $h->vars['new_tab_yes'] . "> " . $h->lang['users_settings_yes'] . " &nbsp;&nbsp;\n";
508        echo "<input type='radio' name='new_tab' value='no' " . $h->vars['new_tab_no'] . "> " . $h->lang['users_settings_no'] . "</td>\n";
509        echo "</tr>\n";
510       
511        echo "<tr>\n";
512            // OPEN POSTS IN A NEW TAB?
513        echo "<td>" . $h->lang['sb_base_users_settings_link_action'] . "</td>\n";
514        echo "<td><input type='radio' name='link_action' value='source' " . $h->vars['link_action_source'] . "> " . $h->lang['sb_base_users_settings_source'] . " &nbsp;&nbsp;\n";
515        echo "<input type='radio' name='link_action' value='post' " . $h->vars['link_action_post'] . "> " . $h->lang['sb_base_users_settings_post'] . "</td>\n";
516        echo "</tr>\n";
517    }
518   
519   
520    /**
521     * Add sorting options
522     */
523    public function submit_post_breadcrumbs($h)
524    {
525        if ($h->isPage('submit2')) { return false; } // don't show sorting on Submit Confirm
526       
527        // exit if this isn't a page of type list, user or profile
528        $page_type = $h->pageType;
529        if ($page_type != 'list' && $page_type != 'user' && $page_type != 'profile') { return false; }
530       
531        // go set up the links
532        $this->setUpSortLinks($h);
533       
534
535    }
536   
537   
538    /**
539     * Prepare sort links
540     */
541    public function theme_index_pre_main($h)
542    {
543        $pagename = $h->pageName;
544       
545        // check if we're looking at a category
546        if ($h->subPage == 'category') {
547            $category = $h->vars['category_id'];
548        }
549       
550        // check if we're looking at a tag
551        if ($h->subPage == 'tags') {
552            $tag = $h->vars['tag'];
553        }
554       
555        // check if we're looking at a media type
556        if ($h->cage->get->keyExists('media')) {
557            $media = $h->cage->get->testAlnumLines('media');
558        }
559       
560        // check if we're looking at a user
561        if ($h->cage->get->keyExists('user')) {
562            $user = $h->cage->get->testUsername('user');
563        }
564       
565        // check if we're looking at a sorted page
566        if ($h->cage->get->keyExists('sort')) {
567            $sort = $h->cage->get->testAlnumLines('sort');
568        }
569       
570        // POPULAR LINK
571        if (isset($category)) { $url = $h->url(array('category'=>$category));
572         } elseif (isset($tag)) { $url = $h->url(array('tag'=>$tag));
573         } elseif (isset($media)) { $url = $h->url(array('media'=>$media));
574         } elseif (isset($user)) { $url = $h->url(array('page'=>'index', 'user'=>$user));
575         } else { $url = $h->url(array()); }
576        $h->vars['popular_link'] = $url;
577         
578        // POPULAR ACTIVE OR INACTIVE
579        if (($pagename == 'index') && (!isset($sort)) && $h->pageType != 'profile') {
580            $h->vars['popular_active'] = "class='active'";
581        } else { $h->vars['popular_active'] = ""; }
582       
583        // UPCOMING LINK
584        if (isset($category)) { $url = $h->url(array('page'=>'upcoming', 'category'=>$category));
585         } elseif (isset($tag)) { $url = $h->url(array('page'=>'upcoming', 'tag'=>$tag));
586         } elseif (isset($media)) { $url = $h->url(array('page'=>'upcoming', 'media'=>$media));
587         } elseif (isset($user)) { $url = $h->url(array('page'=>'upcoming', 'user'=>$user));
588         } else { $url = $h->url(array('page'=>'upcoming')); }
589        $h->vars['upcoming_link'] = $url;
590       
591        // UPCOMING ACTIVE OR INACTIVE
592        if ($pagename == 'upcoming' && !isset($sort)) {
593            $h->vars['upcoming_active'] = "class='active'";
594        } else { $h->vars['upcoming_active'] = ""; }
595       
596        // LATEST LINK
597        if (isset($category)) { $url = $h->url(array('page'=>'latest', 'category'=>$category));
598         } elseif (isset($tag)) { $url = $h->url(array('page'=>'latest', 'tag'=>$tag));
599         } elseif (isset($media)) { $url = $h->url(array('page'=>'latest', 'media'=>$media));
600         } elseif (isset($user)) { $url = $h->url(array('page'=>'latest', 'user'=>$user));
601         } else { $url = $h->url(array('page'=>'latest')); }
602        $h->vars['latest_link'] = $url;
603
604        // LATEST ACTIVE OR INACTIVE
605        if ($pagename == 'latest' && !isset($sort)) {
606            $h->vars['latest_active'] = "class='active'";
607        } else { $h->vars['latest_active'] = ""; }
608       
609        // ALL LINK
610        if (isset($category)) { $url = $h->url(array('page'=>'all', 'category'=>$category));
611         } elseif (isset($tag)) { $url = $h->url(array('page'=>'all', 'tag'=>$tag));
612         } elseif (isset($media)) { $url = $h->url(array('page'=>'all', 'media'=>$media));
613         } elseif (isset($user)) { $url = $h->url(array('page'=>'all', 'user'=>$user));
614         } else { $url = $h->url(array('page'=>'all')); }
615        $h->vars['all_link'] = $url;
616
617        // ALL ACTIVE OR INACTIVE
618        if ($pagename == 'all' && !isset($sort)) {
619            $h->vars['all_active'] = "class='active'";
620        } else { $h->vars['all_active'] = ""; }
621       
622        // 24 HOURS LINK
623        if (isset($category)) { $url = $h->url(array('sort'=>'top-24-hours', 'category'=>$category));
624         } elseif (isset($tag)) { $url = $h->url(array('sort'=>'top-24-hours', 'tag'=>$tag));
625         } elseif (isset($media)) { $url = $h->url(array('sort'=>'top-24-hours', 'media'=>$media));
626         } elseif (isset($user)) { $url = $h->url(array('sort'=>'top-24-hours', 'user'=>$user));
627         } else { $url = $h->url(array('sort'=>'top-24-hours')); }
628        $h->vars['24_hours_link'] = $url;
629
630        // 24 HOURS ACTIVE OR INACTIVE
631        if (isset($sort) && $sort == 'top-24-hours') {
632            $h->vars['top_24_hours_active'] = "class='active'";
633        } else { $h->vars['top_24_hours_active'] = ""; }
634       
635        // 48 HOURS LINK
636        if (isset($category)) { $url = $h->url(array('sort'=>'top-48-hours', 'category'=>$category));
637         } elseif (isset($tag)) { $url = $h->url(array('sort'=>'top-48-hours', 'tag'=>$tag));
638         } elseif (isset($media)) { $url = $h->url(array('sort'=>'top-48-hours', 'media'=>$media));
639         } elseif (isset($user)) { $url = $h->url(array('sort'=>'top-48-hours', 'user'=>$user));
640         } else { $url = $h->url(array('sort'=>'top-48-hours')); }
641        $h->vars['48_hours_link'] = $url;
642
643        // 48 HOURS ACTIVE OR INACTIVE
644        if (isset($sort) && $sort == 'top-48-hours') {
645            $h->vars['top_48_hours_active'] = "class='active'";
646        } else { $h->vars['top_48_hours_active'] = ""; }
647       
648        // 7 DAYS LINK
649        if (isset($category)) { $url = $h->url(array('sort'=>'top-7-days', 'category'=>$category));
650         } elseif (isset($tag)) { $url = $h->url(array('sort'=>'top-7-days', 'tag'=>$tag));
651         } elseif (isset($media)) { $url = $h->url(array('sort'=>'top-7-days', 'media'=>$media));
652         } elseif (isset($user)) { $url = $h->url(array('sort'=>'top-7-days', 'user'=>$user));
653         } else { $url = $h->url(array('sort'=>'top-7-days')); }
654        $h->vars['7_days_link'] = $url;
655
656        // 7 DAYS ACTIVE OR INACTIVE
657        if (isset($sort) && $sort == 'top-7-days') {
658            $h->vars['top_7_days_active'] = "class='active'";
659        } else { $h->vars['top_7_days_active'] = ""; }
660       
661        // 30 DAYS LINK
662        if (isset($category)) { $url = $h->url(array('sort'=>'top-30-days', 'category'=>$category));
663         } elseif (isset($tag)) { $url = $h->url(array('sort'=>'top-30-days', 'tag'=>$tag));
664         } elseif (isset($media)) { $url = $h->url(array('sort'=>'top-30-days', 'media'=>$media));
665         } elseif (isset($user)) { $url = $h->url(array('sort'=>'top-30-days', 'user'=>$user));
666         } else { $url = $h->url(array('sort'=>'top-30-days')); }
667        $h->vars['30_days_link'] = $url;
668
669        // 30 DAYS ACTIVE OR INACTIVE
670        if (isset($sort) && $sort == 'top-30-days') {
671            $h->vars['top_30_days_active'] = "class='active'";
672        } else { $h->vars['top_30_days_active'] = ""; }
673       
674        // 365 DAYS LINK
675        if (isset($category)) { $url = $h->url(array('sort'=>'top-365-days', 'category'=>$category));
676         } elseif (isset($tag)) { $url = $h->url(array('sort'=>'top-365-days', 'tag'=>$tag));
677         } elseif (isset($media)) { $url = $h->url(array('sort'=>'top-365-days', 'media'=>$media));
678         } elseif (isset($user)) { $url = $h->url(array('sort'=>'top-365-days', 'user'=>$user));
679         } else { $url = $h->url(array('sort'=>'top-365-days')); }
680        $h->vars['365_days_link'] = $url;
681
682        // 365 DAYS ACTIVE OR INACTIVE
683        if (isset($sort) && $sort == 'top-365-days') {
684            $h->vars['top_365_days_active'] = "class='active'";
685        } else { $h->vars['top_365_days_active'] = ""; }
686       
687        // ALL TIME LINK
688        if (isset($category)) { $url = $h->url(array('sort'=>'top-all-time', 'category'=>$category));
689         } elseif (isset($tag)) { $url = $h->url(array('sort'=>'top-all-time', 'tag'=>$tag));
690         } elseif (isset($media)) { $url = $h->url(array('sort'=>'top-all-time', 'media'=>$media));
691         } elseif (isset($user)) { $url = $h->url(array('sort'=>'top-all-time', 'user'=>$user));
692         } else { $url = $h->url(array('sort'=>'top-all-time')); }
693        $h->vars['all_time_link'] = $url;
694       
695        // ALL TIME ACTIVE OR INACTIVE
696        if (isset($sort) && $sort == 'top-all-time') {
697            $h->vars['top_all_time_active'] = "class='active'";
698        } else { $h->vars['top_all_time_active'] = ""; }
699       
700        // display the sort links
701        $h->displayTemplate('sb_sort_filter');
702    }
703}
704?>
Note: See TracBrowser for help on using the repository browser.