source: trunk/content/plugins/sb_base/sb_base.php @ 1309

Revision 1309, 29.4 KB checked in by nick_ramsay, 4 years ago (diff)

[Trunk] Updates version numbers and readme files for Admin Email and SB Base.

Line 
1<?php
2/**
3 * name: SB Base
4 * description: Social Bookmarking base - provides "list" and "post" templates.
5 * version: 0.6
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, profile_navigation
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        $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                $post_count = $sb_funcs->prepareList($h, '', 'count');   // get the number of posts
132                $post_query = $sb_funcs->prepareList($h, '', 'query');   // and the SQL query used
133                $h->vars['pagedResults'] = $h->pagination($post_query, $post_count, $posts_per_page, 'posts');
134                break;
135            case 'post':
136                // if a post is already set (e.g. from the sb_categories plugin), we don't want to
137                // do the default stuff below. We do, however, need the "target", "editorial" stuff after it, though...
138                break;
139            default:
140                // Probably a post, let's check:
141                if (is_numeric($h->pageName)) {
142                    // Page name is a number so it must be a post with non-friendly urls
143                    $exists = $h->readPost($h->pageName);    // read current post
144                    if (!$exists) { $h->pageTitle = $h->lang['main_theme_page_not_found']; return false; }
145                    $h->pageTitle = $h->post->title;
146                    $h->pageType = 'post';
147                } elseif ($post_id = $h->isPostUrl($h->pageName)) {
148                    // Page name belongs to a story
149                    $h->readPost($post_id);    // read current post
150                    $h->pageTitle = $h->post->title;
151                    $h->pageType = 'post';
152                }
153        } // close switch
154       
155        // user defined settings:
156       
157        if (!$h->currentUser->settings) {
158            // logged out users get the default settings:
159            $h->currentUser->settings = $h->getDefaultSettings('site');
160        }
161       
162        // open links in a new tab?
163        if ($h->currentUser->settings['new_tab']) {
164            $h->vars['target'] = 'target="_blank"';
165        } else {
166            $h->vars['target'] = '';
167        }
168       
169        // open link to the source or the site post?
170        if ($h->currentUser->settings['link_action']) {
171            $h->vars['link_action'] = 'source';
172        } else {
173            $h->vars['link_action'] = '';
174        }
175       
176        // editorial (story with an internal link)
177        if (strstr($h->post->origUrl, BASEURL)) {
178            $h->vars['editorial'] = true;
179        } else {
180            $h->vars['editorial'] = false;
181        }
182       
183        // get settings from Submit
184        if (!isset($h->vars['submit_settings'])) {
185            $h->vars['submit_settings'] = $h->getSerializedSettings('submit');
186        }
187    }
188   
189   
190    /**
191     * Match meta tag to a post's description (keywords is done in the Tags plugin)
192     */
193    public function header_meta($h)
194    {   
195        if ($h->pageType != 'post') { return false; }
196        $meta_content = sanitize($h->post->content, 'all');
197        $meta_content = truncate($meta_content, 200);
198        echo '<meta name="description" content="' . $meta_content . '" />' . "\n";
199        return true;
200    }
201   
202   
203    /**
204     * Add "Latest" to the navigation bar
205     */
206    public function navigation($h)
207    {
208        // highlight "Latest" as active tab
209        if ($h->pageName == 'latest') { $status = "id='navigation_active'"; } else { $status = ""; }
210       
211        // display the link in the navigation bar
212        echo "<li><a  " . $status . " href='" . $h->url(array('page'=>'latest')) . "'>" . $h->lang["sb_base_latest"] . "</a></li>\n";
213    }
214   
215   
216    /**
217     * Replace the default breadcrumbs in specific circumstances
218     */
219    public function breadcrumbs($h)
220    {
221        if ($h->subPage) { return false; } // don't use these breadcrumbs if on a subpage
222       
223        if ($h->pageName == 'index') {
224            $h->pageTitle = $h->lang["sb_base_top"];
225        }
226       
227        switch ($h->pageName) {
228            case 'index':
229                return $h->pageTitle . ' ' . $h->rssBreadcrumbsLink('top');
230                break;
231            case 'latest':
232                return $h->pageTitle . ' ' . $h->rssBreadcrumbsLink('new');
233                break;
234            case 'upcoming':
235                return $h->pageTitle . ' ' . $h->rssBreadcrumbsLink('upcoming');
236                break;
237            case 'all':
238                return $h->pageTitle . ' ' . $h->rssBreadcrumbsLink();
239                break;
240        }
241    }
242   
243   
244    /**
245     * Determine which template to show and do preparation of variables, etc.
246     */
247    public function theme_index_main($h)
248    {
249        // stop here if not a list of a post
250        if (($h->pageType != 'list') && ($h->pageType != 'post')) { return false; }
251       
252        // necessary settings:
253        $h->vars['use_content'] = $h->vars['submit_settings']['content'];
254        $h->vars['use_summary'] = $h->vars['submit_settings']['summary'];
255        $h->vars['summary_length'] = $h->vars['submit_settings']['summary_length'];
256       
257        switch ($h->pageType)
258        {
259            case 'post':
260                // This post is visible if it's not buried/pending OR if the viewer has edit post permissions...
261               
262                // defaults:
263                $buried = false; $pending = false; $can_edit = false;
264               
265                // check if buried:
266                if ($h->post->status == 'buried') {
267                    $buried = true;
268                    $h->messages[$h->lang["sb_base_post_buried"]] = "red";
269                }
270               
271                // check if pending:
272                if ($h->post->status == 'pending') {
273                    $pending = true;
274                    $h->messages[$h->lang["sb_base_post_pending"]] = "red";
275                }
276               
277                // check if global edit permissions
278                if ($h->currentUser->getPermission('can_edit_posts') == 'yes') { $can_edit = true; }
279
280                $h->showMessages();
281               
282                // display post or show error message
283                if (!$buried && !$pending){
284                    $h->displayTemplate('sb_post');
285                } elseif ($can_edit) {
286                    $h->displayTemplate('sb_post');
287                } else {
288                    // don't show the post
289                }
290               
291                return true;
292                break;
293               
294            case 'list':
295                if (isset($h->vars['pagedResults']->items)) {
296                    $h->displayTemplate('sb_list');
297                    echo $h->pageBar($h->vars['pagedResults']);
298                } else {
299                    $h->displayTemplate('sb_no_posts');
300                }
301                return true;
302        }
303    }
304   
305   
306    /**
307     * Archive option on Maintenance page
308     */
309    public function admin_maintenance_database($h)
310    {
311        $sb_base_settings = $h->getSerializedSettings();
312        $archive = $sb_base_settings['archive'];
313        echo "<li><a href='" . BASEURL . "admin_index.php?page=maintenance&amp;action=update_archive'>";
314        echo $h->lang["sb_base_maintenance_update_archive"] . "</a> - ";
315        if ($archive == 'no_archive') {
316            echo $h->lang["sb_base_maintenance_update_archive_remove"];
317        } else {
318            echo $h->lang["sb_base_maintenance_update_archive_desc_1"];
319            echo $h->lang["sb_base_settings_post_archive_$archive"];
320            echo $h->lang["sb_base_maintenance_update_archive_desc_2"];
321        }
322        echo "</li>";
323    }
324   
325   
326    /**
327     * Perform archiving tasks
328     */
329    public function admin_maintenance_top($h)
330    {
331        if ($h->cage->get->testAlnumLines('action') != 'update_archive') { return false; }
332       
333        $sb_base_settings = $h->getSerializedSettings();
334        $archive = $sb_base_settings['archive'];
335       
336        // FIRST, WE NEED TO RESET THE ARCHIVE, setting all archive fields to "N":
337       
338        // posts
339        if ($h->db->table_exists('posts')) {
340            $sql = "UPDATE " . DB_PREFIX . "posts SET post_archived = %s";
341            $h->db->query($h->db->prepare($sql, 'N'));
342        }
343       
344        // postmeta
345        if ($h->db->table_exists('postmeta')) {
346            $sql = "UPDATE " . DB_PREFIX . "postmeta SET postmeta_archived = %s";
347            $h->db->query($h->db->prepare($sql, 'N'));
348        }
349       
350        // postvotes
351        if ($h->db->table_exists('postvotes')) {
352            $sql = "UPDATE " . DB_PREFIX . "postvotes SET vote_archived = %s";
353            $h->db->query($h->db->prepare($sql, 'N'));
354        }
355       
356        // comments
357        if ($h->db->table_exists('comments')) {
358            $sql = "UPDATE " . DB_PREFIX . "comments SET comment_archived = %s";
359            $h->db->query($h->db->prepare($sql, 'N'));
360        }
361       
362        // commentvotes
363        if ($h->db->table_exists('commentvotes')) {
364            $sql = "UPDATE " . DB_PREFIX . "commentvotes SET cvote_archived = %s";
365            $h->db->query($h->db->prepare($sql, 'N'));
366        }
367       
368        // tags
369        if ($h->db->table_exists('tags')) {
370            $sql = "UPDATE " . DB_PREFIX . "tags SET tags_archived = %s";
371            $h->db->query($h->db->prepare($sql, 'N'));
372        }
373       
374        // useractivity
375        if ($h->db->table_exists('useractivity')) {
376            $sql = "UPDATE " . DB_PREFIX . "useractivity SET useract_archived = %s";
377            $h->db->query($h->db->prepare($sql, 'N'));
378        }
379       
380        // RETURN NOW IF NO_ARCHIVE IS SET *****************************
381        if ($archive == 'no_archive') {
382            $h->message = $h->lang['sb_base_maintenance_archive_removed'];
383            $h->messageType = 'green';
384            $h->showMessage();
385            return true;
386        }
387       
388        // NEXT, START ARCHIVING! *****************************
389        $archive_text = "-" . $archive . " days"; // e.g. "-365 days"
390        $archive_date = date('YmdHis', strtotime($archive_text));
391       
392        // posts
393        if ($h->db->table_exists('posts')) {
394            $sql = "UPDATE " . DB_PREFIX . "posts SET post_archived = %s WHERE post_date <= %s";
395            $h->db->query($h->db->prepare($sql, 'Y', $archive_date));
396        }
397       
398        // postmeta
399        if ($h->db->table_exists('postmeta')) {
400            // No date field in postmeta table so join with posts table...
401            $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)";
402            $h->db->query($h->db->prepare($sql, 'Y', $archive_date));
403        }
404       
405        // postvotes
406        if ($h->db->table_exists('postvotes')) {
407            $sql = "UPDATE " . DB_PREFIX . "postvotes SET vote_archived = %s WHERE vote_date <= %s";
408            $h->db->query($h->db->prepare($sql, 'Y', $archive_date));
409        }
410       
411        // comments
412        if ($h->db->table_exists('comments')) {
413            $sql = "UPDATE " . DB_PREFIX . "comments SET comment_archived = %s WHERE comment_date <= %s";
414            $h->db->query($h->db->prepare($sql, 'Y', $archive_date));
415        }
416       
417        // commentvotes
418        if ($h->db->table_exists('commentvotes')) {
419            $sql = "UPDATE " . DB_PREFIX . "commentvotes SET cvote_archived = %s WHERE cvote_date <= %s";
420            $h->db->query($h->db->prepare($sql, 'Y', $archive_date));
421        }
422       
423        // tags
424        if ($h->db->table_exists('tags')) {
425            $sql = "UPDATE " . DB_PREFIX . "tags SET tags_archived = %s WHERE tags_date <= %s";
426            $h->db->query($h->db->prepare($sql, 'Y', $archive_date));
427        }
428
429        // useractivity
430        if ($h->db->table_exists('useractivity')) {
431            $sql = "UPDATE " . DB_PREFIX . "useractivity SET useract_archived = %s WHERE useract_date <= %s";
432            $h->db->query($h->db->prepare($sql, 'Y', $archive_date));
433        }
434
435        $h->message = $h->lang['sb_base_maintenance_archive_updated'];
436        $h->messageType = 'green';
437        $h->showMessage();
438        return true;
439
440    }
441   
442   
443    /**
444     * Show stats on Admin home page
445     */
446    public function admin_theme_main_stats($h, $vars)
447    {
448        echo "<li>&nbsp;</li>";
449   
450        foreach ($vars as $stat_type) {
451            $posts = $h->post->stats($h, $stat_type);
452            if (!$posts) { $posts = 0; }
453            $lang_name = 'sb_base_admin_stats_' . $stat_type;
454            echo "<li>" . $h->lang[$lang_name] . ": " . $posts . "</li>";
455        }
456    }
457   
458   
459    /**
460     * User Settings - before saving
461     */
462    public function user_settings_pre_save($h)
463    {
464        // Open posts in a new tab?
465        if ($h->cage->post->getAlpha('new_tab') == 'yes') {
466            $h->vars['settings']['new_tab'] = "checked";
467        } else {
468            $h->vars['settings']['new_tab'] = "";
469        }
470       
471        // List links open source url or post page?
472        if ($h->cage->post->getAlpha('link_action') == 'source') {
473            $h->vars['settings']['link_action'] = "checked";
474        } else {
475            $h->vars['settings']['link_action'] = "";
476        }
477    }
478   
479   
480    /**
481     * User Settings - fill the form
482     */
483    public function user_settings_fill_form($h)
484    {
485        if (!isset($h->vars['settings']) || !$h->vars['settings']) { return false; }
486       
487        if ($h->vars['settings']['new_tab']) {
488            $h->vars['new_tab_yes'] = "checked";
489            $h->vars['new_tab_no'] = "";
490        } else {
491            $h->vars['new_tab_yes'] = "";
492            $h->vars['new_tab_no'] = "checked";
493        }
494       
495        if ($h->vars['settings']['link_action']) {
496            $h->vars['link_action_source'] = "checked";
497            $h->vars['link_action_post'] = "";
498        } else {
499            $h->vars['link_action_source'] = "";
500            $h->vars['link_action_post'] = "checked";
501        }
502    }
503   
504   
505    /**
506     * User Settings - html for form
507     */
508    public function user_settings_extra_settings($h)
509    {
510        if (!isset($h->vars['settings']) || !$h->vars['settings']) { return false; }
511       
512        echo "<tr>\n";
513            // OPEN POSTS IN A NEW TAB?
514        echo "<td>" . $h->lang['sb_base_users_settings_open_new_tab'] . "</td>\n";
515        echo "<td><input type='radio' name='new_tab' value='yes' " . $h->vars['new_tab_yes'] . "> " . $h->lang['users_settings_yes'] . " &nbsp;&nbsp;\n";
516        echo "<input type='radio' name='new_tab' value='no' " . $h->vars['new_tab_no'] . "> " . $h->lang['users_settings_no'] . "</td>\n";
517        echo "</tr>\n";
518       
519        echo "<tr>\n";
520            // OPEN POSTS IN A NEW TAB?
521        echo "<td>" . $h->lang['sb_base_users_settings_link_action'] . "</td>\n";
522        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";
523        echo "<input type='radio' name='link_action' value='post' " . $h->vars['link_action_post'] . "> " . $h->lang['sb_base_users_settings_post'] . "</td>\n";
524        echo "</tr>\n";
525    }
526   
527   
528    /**
529     * Add sorting options
530     */
531    public function submit_post_breadcrumbs($h)
532    {
533        if ($h->isPage('submit2')) { return false; } // don't show sorting on Submit Confirm
534       
535        // exit if this isn't a page of type list, user or profile
536        $page_type = $h->pageType;
537        if ($page_type != 'list' && $page_type != 'user' && $page_type != 'profile') { return false; }
538       
539        // go set up the links
540        $this->setUpSortLinks($h);
541       
542
543    }
544   
545   
546    /**
547     * Profile navigation link
548     */
549    public function profile_navigation($h)
550    {
551        echo "<li><a href='" . $h->url(array('page'=>'all', 'user'=>$h->vars['user']->name)) . "'>" . $h->lang["users_all_posts"] . "</a></li>\n";
552    }
553   
554   
555    /**
556     * Prepare sort links
557     */
558    public function theme_index_pre_main($h)
559    {
560        $pagename = $h->pageName;
561       
562        // check if we're looking at a category
563        if ($h->subPage == 'category') {
564            $category = $h->vars['category_id'];
565        }
566       
567        // check if we're looking at a tag
568        if ($h->subPage == 'tags') {
569            $tag = $h->vars['tag'];
570        }
571       
572        // check if we're looking at a media type
573        if ($h->cage->get->keyExists('media')) {
574            $media = $h->cage->get->testAlnumLines('media');
575        }
576       
577        // check if we're looking at a user
578        if ($h->cage->get->keyExists('user')) {
579            $user = $h->cage->get->testUsername('user');
580        }
581       
582        // check if we're looking at a sorted page
583        if ($h->cage->get->keyExists('sort')) {
584            $sort = $h->cage->get->testAlnumLines('sort');
585        }
586       
587        // POPULAR LINK
588        if (isset($category)) { $url = $h->url(array('category'=>$category));
589         } elseif (isset($tag)) { $url = $h->url(array('tag'=>$tag));
590         } elseif (isset($media)) { $url = $h->url(array('media'=>$media));
591         } elseif (isset($user)) { $url = $h->url(array('page'=>'index', 'user'=>$user));
592         } else { $url = $h->url(array()); }
593        $h->vars['popular_link'] = $url;
594         
595        // POPULAR ACTIVE OR INACTIVE
596        if (($pagename == 'index') && (!isset($sort)) && $h->pageType != 'profile') {
597            $h->vars['popular_active'] = "class='active'";
598        } else { $h->vars['popular_active'] = ""; }
599       
600        // UPCOMING LINK
601        if (isset($category)) { $url = $h->url(array('page'=>'upcoming', 'category'=>$category));
602         } elseif (isset($tag)) { $url = $h->url(array('page'=>'upcoming', 'tag'=>$tag));
603         } elseif (isset($media)) { $url = $h->url(array('page'=>'upcoming', 'media'=>$media));
604         } elseif (isset($user)) { $url = $h->url(array('page'=>'upcoming', 'user'=>$user));
605         } else { $url = $h->url(array('page'=>'upcoming')); }
606        $h->vars['upcoming_link'] = $url;
607       
608        // UPCOMING ACTIVE OR INACTIVE
609        if ($pagename == 'upcoming' && !isset($sort)) {
610            $h->vars['upcoming_active'] = "class='active'";
611        } else { $h->vars['upcoming_active'] = ""; }
612       
613        // LATEST LINK
614        if (isset($category)) { $url = $h->url(array('page'=>'latest', 'category'=>$category));
615         } elseif (isset($tag)) { $url = $h->url(array('page'=>'latest', 'tag'=>$tag));
616         } elseif (isset($media)) { $url = $h->url(array('page'=>'latest', 'media'=>$media));
617         } elseif (isset($user)) { $url = $h->url(array('page'=>'latest', 'user'=>$user));
618         } else { $url = $h->url(array('page'=>'latest')); }
619        $h->vars['latest_link'] = $url;
620
621        // LATEST ACTIVE OR INACTIVE
622        if ($pagename == 'latest' && !isset($sort)) {
623            $h->vars['latest_active'] = "class='active'";
624        } else { $h->vars['latest_active'] = ""; }
625       
626        // ALL LINK
627        if (isset($category)) { $url = $h->url(array('page'=>'all', 'category'=>$category));
628         } elseif (isset($tag)) { $url = $h->url(array('page'=>'all', 'tag'=>$tag));
629         } elseif (isset($media)) { $url = $h->url(array('page'=>'all', 'media'=>$media));
630         } elseif (isset($user)) { $url = $h->url(array('page'=>'all', 'user'=>$user));
631         } else { $url = $h->url(array('page'=>'all')); }
632        $h->vars['all_link'] = $url;
633
634        // ALL ACTIVE OR INACTIVE
635        if ($pagename == 'all' && !isset($sort)) {
636            $h->vars['all_active'] = "class='active'";
637        } else { $h->vars['all_active'] = ""; }
638       
639        // 24 HOURS LINK
640        if (isset($category)) { $url = $h->url(array('sort'=>'top-24-hours', 'category'=>$category));
641         } elseif (isset($tag)) { $url = $h->url(array('sort'=>'top-24-hours', 'tag'=>$tag));
642         } elseif (isset($media)) { $url = $h->url(array('sort'=>'top-24-hours', 'media'=>$media));
643         } elseif (isset($user)) { $url = $h->url(array('sort'=>'top-24-hours', 'user'=>$user));
644         } else { $url = $h->url(array('sort'=>'top-24-hours')); }
645        $h->vars['24_hours_link'] = $url;
646
647        // 24 HOURS ACTIVE OR INACTIVE
648        if (isset($sort) && $sort == 'top-24-hours') {
649            $h->vars['top_24_hours_active'] = "class='active'";
650        } else { $h->vars['top_24_hours_active'] = ""; }
651       
652        // 48 HOURS LINK
653        if (isset($category)) { $url = $h->url(array('sort'=>'top-48-hours', 'category'=>$category));
654         } elseif (isset($tag)) { $url = $h->url(array('sort'=>'top-48-hours', 'tag'=>$tag));
655         } elseif (isset($media)) { $url = $h->url(array('sort'=>'top-48-hours', 'media'=>$media));
656         } elseif (isset($user)) { $url = $h->url(array('sort'=>'top-48-hours', 'user'=>$user));
657         } else { $url = $h->url(array('sort'=>'top-48-hours')); }
658        $h->vars['48_hours_link'] = $url;
659
660        // 48 HOURS ACTIVE OR INACTIVE
661        if (isset($sort) && $sort == 'top-48-hours') {
662            $h->vars['top_48_hours_active'] = "class='active'";
663        } else { $h->vars['top_48_hours_active'] = ""; }
664       
665        // 7 DAYS LINK
666        if (isset($category)) { $url = $h->url(array('sort'=>'top-7-days', 'category'=>$category));
667         } elseif (isset($tag)) { $url = $h->url(array('sort'=>'top-7-days', 'tag'=>$tag));
668         } elseif (isset($media)) { $url = $h->url(array('sort'=>'top-7-days', 'media'=>$media));
669         } elseif (isset($user)) { $url = $h->url(array('sort'=>'top-7-days', 'user'=>$user));
670         } else { $url = $h->url(array('sort'=>'top-7-days')); }
671        $h->vars['7_days_link'] = $url;
672
673        // 7 DAYS ACTIVE OR INACTIVE
674        if (isset($sort) && $sort == 'top-7-days') {
675            $h->vars['top_7_days_active'] = "class='active'";
676        } else { $h->vars['top_7_days_active'] = ""; }
677       
678        // 30 DAYS LINK
679        if (isset($category)) { $url = $h->url(array('sort'=>'top-30-days', 'category'=>$category));
680         } elseif (isset($tag)) { $url = $h->url(array('sort'=>'top-30-days', 'tag'=>$tag));
681         } elseif (isset($media)) { $url = $h->url(array('sort'=>'top-30-days', 'media'=>$media));
682         } elseif (isset($user)) { $url = $h->url(array('sort'=>'top-30-days', 'user'=>$user));
683         } else { $url = $h->url(array('sort'=>'top-30-days')); }
684        $h->vars['30_days_link'] = $url;
685
686        // 30 DAYS ACTIVE OR INACTIVE
687        if (isset($sort) && $sort == 'top-30-days') {
688            $h->vars['top_30_days_active'] = "class='active'";
689        } else { $h->vars['top_30_days_active'] = ""; }
690       
691        // 365 DAYS LINK
692        if (isset($category)) { $url = $h->url(array('sort'=>'top-365-days', 'category'=>$category));
693         } elseif (isset($tag)) { $url = $h->url(array('sort'=>'top-365-days', 'tag'=>$tag));
694         } elseif (isset($media)) { $url = $h->url(array('sort'=>'top-365-days', 'media'=>$media));
695         } elseif (isset($user)) { $url = $h->url(array('sort'=>'top-365-days', 'user'=>$user));
696         } else { $url = $h->url(array('sort'=>'top-365-days')); }
697        $h->vars['365_days_link'] = $url;
698
699        // 365 DAYS ACTIVE OR INACTIVE
700        if (isset($sort) && $sort == 'top-365-days') {
701            $h->vars['top_365_days_active'] = "class='active'";
702        } else { $h->vars['top_365_days_active'] = ""; }
703       
704        // ALL TIME LINK
705        if (isset($category)) { $url = $h->url(array('sort'=>'top-all-time', 'category'=>$category));
706         } elseif (isset($tag)) { $url = $h->url(array('sort'=>'top-all-time', 'tag'=>$tag));
707         } elseif (isset($media)) { $url = $h->url(array('sort'=>'top-all-time', 'media'=>$media));
708         } elseif (isset($user)) { $url = $h->url(array('sort'=>'top-all-time', 'user'=>$user));
709         } else { $url = $h->url(array('sort'=>'top-all-time')); }
710        $h->vars['all_time_link'] = $url;
711       
712        // ALL TIME ACTIVE OR INACTIVE
713        if (isset($sort) && $sort == 'top-all-time') {
714            $h->vars['top_all_time_active'] = "class='active'";
715        } else { $h->vars['top_all_time_active'] = ""; }
716       
717        // display the sort links
718        $h->displayTemplate('sb_sort_filter');
719    }
720}
721?>
Note: See TracBrowser for help on using the repository browser.