source: extensions/Extra_special_functions/trunk/main.inc.php @ 8804

Last change on this file since 8804 was 7599, checked in by pab, 14 years ago
File size: 3.2 KB
Line 
1<?php
2/*
3Plugin Name: Extra special functions
4Version: 2.1.a
5Description: Adds functions 'Flat all elements', 'Calendar by posted date', 'Calendar by creation date' and toggle function 'Display recently posted / all' into special functions.
6Plugin URI: http://piwigo.org/ext/extension_view.php?eid=460
7Author: Pavel Budka
8Author URI: http://budkovi.ic.cz
9*/
10
11if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
12
13function add_extra_functions($menu_ref_arr)
14{
15  $menu = & $menu_ref_arr[0];
16  global $filter, $user;
17 
18  if (($block = $menu->get_block('mbSpecials')) != null )
19  {
20    load_language('plugin.lang', PHPWG_PLUGINS_PATH . basename(dirname(__FILE__)) . '/');
21
22    $str = $_SERVER['QUERY_STRING'];
23    $args = explode('&',$str);
24    $filter_rec = ($filter['enabled'] && $filter['recent_period']!=-1);
25    // remove previously added extra functions from url
26    $url_rest='';
27    foreach($args as $arg) {
28    if (strncmp($arg,'filter',6) == 0)
29      ; // ommit this parameter
30    elseif (!empty($arg) && $arg[0] != '/')
31        $url_rest.='&'.$arg;
32    else
33      $cat_arg=$arg;
34      } // foreach
35    if (isset($cat_arg))
36      $cat_els = explode('/',$cat_arg);
37    else
38      $cat_els = array();
39         
40    // set of modificatiors
41    $items = array('flat' => 'display all elements in all sub-albums', 
42                'posted-monthly-calendar' => 'display a calendar by posted date',
43                'created-monthly-calendar' => 'display a calendar by creation date');
44               
45    // remove previously added extra functions from url
46    foreach($items as $item => $label)
47      if(($id=array_search($item,$cat_els)) != false)
48        unset($cat_els[$id]);
49    $cat_els=array_values($cat_els);
50               
51    // TODO: &filter=start-recent-20, &filter=stop
52   
53    // remove other functions
54//    $block->data=array();
55   
56    // add extra functions to url and to menu
57    foreach($items as $item => $label) {
58    // prepare url
59    array_push ($cat_els,$item);
60   
61    $url='';
62    foreach($cat_els as $cat_el)
63      if (empty($url)) 
64        $url.='?'.$cat_el;
65      else 
66        $url.='/'.$cat_el;
67    $url.=$url_rest;
68    array_pop($cat_els);
69   
70    // extend menu
71    array_push($block->data, 
72      array(
73        'URL' => $url,
74        'TITLE' => l10n($label),
75        'NAME' => l10n($item)
76        )
77     
78    );
79  } // for
80 
81  // add filter extra function to url and to menu
82  $url='';
83  foreach($cat_els as $cat_el)
84    if (empty($url)) 
85      $url.='?'.$cat_el;
86    else 
87      $url.='/'.$cat_el;
88  $url.=$url_rest;
89  if ($url[0] == '&') $url[0]='?'; 
90
91  // extend menu
92  if(!$filter_rec)
93    array_push($block->data, 
94      array(
95        'URL' => $url.'&'.'filter=start-recent-'.$user['recent_period'],
96        'TITLE' => l10n('display only recently posted images'),
97        'NAME' => l10n('filter-start-recent')
98        ));
99  else 
100    array_push($block->data, 
101      array(
102        'URL' => $url.'&'.'filter=stop',
103        'TITLE' => l10n('return to the display of all images'),
104        'NAME' => l10n('filter-stop')
105        ));
106 
107  } // if
108 
109} // add_link_mostcommented
110
111add_event_handler('blockmanager_apply' , 'add_extra_functions');
112
113?>
Note: See TracBrowser for help on using the repository browser.