Changeset 27268 for extensions/dynareceperio/main.inc.php
- Timestamp:
- Feb 8, 2014, 6:48:13 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/dynareceperio/main.inc.php
r8426 r27268 1 1 <?php 2 // +-----------------------------------------------------------------------+3 // | Dynamic Recent Period - a Piwigo Plugin |4 // | Copyright (C) 2007-2011 Ruben ARNAUD - rub@piwigo.org |5 // +-----------------------------------------------------------------------+6 // | This program is free software; you can redistribute it and/or modify |7 // | it under the terms of the GNU General Public License as published by |8 // | the Free Software Foundation |9 // | |10 // | This program is distributed in the hope that it will be useful, but |11 // | WITHOUT ANY WARRANTY; without even the implied warranty of |12 // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |13 // | General Public License for more details. |14 // | |15 // | You should have received a copy of the GNU General Public License |16 // | along with this program; if not, write to the Free Software |17 // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |18 // | USA. |19 // +-----------------------------------------------------------------------+20 21 2 /* 22 3 Plugin Name: Dynamic Recent Period 23 4 Version: auto 24 5 Description: Computes a dynamic recent period 25 Plugin URI: http://piwigo.org/ext/extension_view.php?eid=1806 Plugin URI: auto 26 7 Author: Ruben ARNAUD 27 Author URI: http://photograph.piwigo.net/28 8 */ 29 9 30 if (!defined('PHPWG_ROOT_PATH')) 10 defined('PHPWG_ROOT_PATH') or die('Hacking attempt!'); 11 12 define('DYNARECEPERIO_ID', basename(dirname(__FILE__))); 13 define('DYNARECEPERIO_PATH', PHPWG_PLUGINS_PATH . DYNARECEPERIO_ID . '/'); 14 15 16 global $conf; 17 $conf['dynareceperio'] = unserialize($conf['dynareceperio']); 18 19 20 // ADMIN MENU LINK 21 if (defined('IN_ADMIN')) 31 22 { 32 die('Hacking attempt!'); 23 add_event_handler('get_admin_plugin_menu_links', 'dynareceperio_get_admin_plugin_menu_links'); 24 25 function dynareceperio_get_admin_plugin_menu_links($menu) 26 { 27 $menu[] = array( 28 'NAME' => 'Dynamic Recent Period', 29 'URL' => get_root_url() . 'admin.php?page=plugin-' . DYNARECEPERIO_ID, 30 ); 31 32 return $menu; 33 } 33 34 } 34 35 35 global $conf; 36 // REMOVE INPUT ON PROFILE AND USERS LIST 37 if (script_basename() == 'profile' || defined('IN_ADMIN')) 38 { 39 if ($conf['dynareceperio']['force']) 40 { 41 add_event_handler('loc_end_page_tail', 'dynareceperio_hide_recent_period'); 42 43 function dynareceperio_hide_recent_period() 44 { 45 global $template, $page; 36 46 37 $conf['dynareceperio'] = unserialize($conf['dynareceperio']); 38 39 if (script_basename() == 'profile') 40 { 41 include_once(dirname(__FILE__).'/profile.inc.php'); 42 } 43 else 44 if (script_basename() == 'admin') 45 { 46 include_once(dirname(__FILE__).'/profile.inc.php'); 47 include_once(dirname(__FILE__).'/admin.inc.php'); 48 } 49 else 50 if (script_basename() != 'profile') 51 { 52 include_once(dirname(__FILE__).'/period.inc.php'); 47 if (@$page['page'] == 'user_list') 48 { 49 $template->set_prefilter('user_list', 'dynareceperio_user_list'); 50 } 51 else if (@$page['body_id']=='theProfilePage' || (@$page['page'] == 'configuration' && @$_GET['section'] == 'default')) 52 { 53 $template->block_footer_script(array('require'=>'jquery'), 'jQuery("#recent_period").parent().hide();'); 54 } 55 } 56 57 function dynareceperio_user_list($content) 58 { 59 $search = '<div class="userProperty"><strong>{\'Recent period\'|translate}'; 60 $replace = '<div class="userProperty" style="display:none;"><strong>{\'Recent period\'|translate}'; 61 return str_replace($search, $replace, $content); 62 } 63 } 53 64 } 54 65 66 // APPLY DYNAMIC PERIOD 67 else 68 { 69 add_event_handler('init', 'dynareceperio_user_init'); 55 70 56 ?> 71 function dynareceperio_user_init() 72 { 73 global $conf, $user; 74 75 $default_period = get_default_user_value('recent_period', $user['recent_period']); 76 77 if ($conf['dynareceperio']['force'] or $default_period == $user['recent_period']) 78 { 79 $query = ' 80 SELECT MAX(D) 81 FROM ( 82 SELECT D 83 FROM ( 84 SELECT DATEDIFF(CURRENT_DATE, date_available) AS D 85 FROM '.IMAGES_TABLE.' AS i 86 INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON id=image_id 87 '.get_sql_condition_FandF( 88 array( 89 'forbidden_categories' => 'ic.category_id', 90 'visible_categories' => 'ic.category_id', 91 'visible_images' => 'id' 92 ), 93 'WHERE', 94 true 95 ).' 96 ) AS ListDate 97 WHERE D >= 0 98 GROUP BY D 99 ORDER BY D ASC 100 LIMIT '.$conf['dynareceperio']['day_number'].' 101 ) AS MaxD 102 ;'; 103 $result = pwg_query($query); 104 105 if (list($period) = pwg_db_fetch_row($result)) 106 { 107 $user['recent_period'] = max($period, $default_period); 108 } 109 } 110 } 111 }
Note: See TracChangeset
for help on using the changeset viewer.