1 | <?php |
---|
2 | /* |
---|
3 | Plugin Name: Photos from one year ago |
---|
4 | Version: auto |
---|
5 | Description: Add a "photos from one year ago" link in "Specials" menu. |
---|
6 | Plugin URI: https://piwigo.org/ext/extension_view.php?eid=893 |
---|
7 | Author: ddtddt |
---|
8 | Author URI: http://temmii.com/piwigo/ |
---|
9 | */ |
---|
10 | |
---|
11 | // +-----------------------------------------------------------------------+ |
---|
12 | // | Photos from one year ago for Piwigo by TEMMII | |
---|
13 | // +-----------------------------------------------------------------------+ |
---|
14 | // | Copyright(C) 2008-2020 ddtddt http://temmii.com/piwigo/ | |
---|
15 | // +-----------------------------------------------------------------------+ |
---|
16 | // | This program is free software; you can redistribute it and/or modify | |
---|
17 | // | it under the terms of the GNU General Public License as published by | |
---|
18 | // | the Free Software Foundation | |
---|
19 | // | | |
---|
20 | // | This program is distributed in the hope that it will be useful, but | |
---|
21 | // | WITHOUT ANY WARRANTY; without even the implied warranty of | |
---|
22 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
---|
23 | // | General Public License for more details. | |
---|
24 | // | | |
---|
25 | // | You should have received a copy of the GNU General Public License | |
---|
26 | // | along with this program; if not, write to the Free Software | |
---|
27 | // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
---|
28 | // | USA. | |
---|
29 | // +-----------------------------------------------------------------------+ |
---|
30 | |
---|
31 | defined('PHPWG_ROOT_PATH') or die('Hacking attempt!'); |
---|
32 | |
---|
33 | define('PFOYA_PATH' , PHPWG_PLUGINS_PATH . basename(dirname(__FILE__)) . '/'); |
---|
34 | |
---|
35 | add_event_handler('loading_lang', 'pfoya_loading_lang'); |
---|
36 | function pfoya_loading_lang(){ |
---|
37 | load_language('plugin.lang', PFOYA_PATH); |
---|
38 | } |
---|
39 | |
---|
40 | add_event_handler('blockmanager_apply' , 'add_link_pfoya'); |
---|
41 | add_event_handler('loc_end_section_init', 'section_init_pfoya'); |
---|
42 | |
---|
43 | function add_link_pfoya($menu_ref_arr){ |
---|
44 | global $conf; |
---|
45 | $menu = &$menu_ref_arr[0]; |
---|
46 | $position = (isset($conf['pfoya_position']) and is_numeric($conf['pfoya_position'])) ? $conf['pfoya_position'] : 5; |
---|
47 | if (($block = $menu->get_block('mbSpecials')) != null){ |
---|
48 | array_splice($block->data, $position-1, 0, |
---|
49 | array('photos_from_one_year_ago' => |
---|
50 | array( |
---|
51 | 'URL' => make_index_url(array('section' => 'photos_from_one_year_ago')), |
---|
52 | 'TITLE' => l10n('Displays photos from one year ago'), |
---|
53 | 'NAME' => l10n('Photos from one year ago') |
---|
54 | ) |
---|
55 | ) |
---|
56 | ); |
---|
57 | } |
---|
58 | } |
---|
59 | |
---|
60 | function section_init_pfoya(){ |
---|
61 | global $tokens, $page, $conf, $template; |
---|
62 | $testurl = explode('photos_from_', $_SERVER['REQUEST_URI']); |
---|
63 | if(!empty($testurl[1])){ |
---|
64 | |
---|
65 | $datepfoya = (isset($conf['pfoya_dateb'])) ? $conf['pfoya_dateb'] : "date_available"; |
---|
66 | $daydatemax= (isset($conf['pfoya_datemax'])) ? $conf['pfoya_datemax'] : 5; |
---|
67 | |
---|
68 | if($daydatemax>1)$template->assign('pfoya','a'); |
---|
69 | |
---|
70 | for ($i = 1; $i <= $daydatemax; $i++) { |
---|
71 | $daydate=date("Y-m-d", strtotime('-'.$i.' year')); |
---|
72 | $query = ' |
---|
73 | SELECT COUNT(DISTINCT(i.id)) as count |
---|
74 | FROM '.IMAGES_TABLE.' AS i |
---|
75 | INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON i.id = ic.image_id |
---|
76 | INNER JOIN '.CATEGORIES_TABLE.' AS c ON ic.category_id = c.id |
---|
77 | WHERE ' . |
---|
78 | get_sql_condition_FandF( |
---|
79 | array( |
---|
80 | 'forbidden_categories' => 'category_id', |
---|
81 | 'visible_categories' => 'category_id', |
---|
82 | 'visible_images' => 'image_id', |
---|
83 | ), |
---|
84 | '', true |
---|
85 | ); |
---|
86 | $query .= ' |
---|
87 | and DATE ('.$datepfoya.') ="'.$daydate.'";'; |
---|
88 | |
---|
89 | $row = pwg_db_fetch_assoc(pwg_query($query)); |
---|
90 | |
---|
91 | if ($i == 1){ |
---|
92 | $items = array( |
---|
93 | 'NB_IMAGES' => $row['count'], |
---|
94 | 'URL' => make_index_url(array('section' => 'photos_from_one_year_ago')), |
---|
95 | 'LABEL' => l10n('Photos from one year ago'), |
---|
96 | ); |
---|
97 | $template->append('pfoyas', $items); |
---|
98 | }else{ |
---|
99 | $items = array( |
---|
100 | 'NB_IMAGES' => $row['count'], |
---|
101 | 'URL' => make_index_url(array('section' => 'photos_from_'.$i.'_year_ago')), |
---|
102 | 'LABEL' => l10n('Photos from %d years ago',$i), |
---|
103 | ); |
---|
104 | $template->append('pfoyas', $items); |
---|
105 | } |
---|
106 | } |
---|
107 | if($testurl[1]=='one_year_ago'){ |
---|
108 | if (!in_array('photos_from_one_year_ago', $tokens)){return;} |
---|
109 | $daydate=date("Y-m-d", strtotime('-1 year')); |
---|
110 | $query = ' |
---|
111 | SELECT DISTINCT(i.id) |
---|
112 | FROM '.IMAGES_TABLE.' AS i |
---|
113 | INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON i.id = ic.image_id |
---|
114 | INNER JOIN '.CATEGORIES_TABLE.' AS c ON ic.category_id = c.id |
---|
115 | WHERE ' . |
---|
116 | get_sql_condition_FandF( |
---|
117 | array( |
---|
118 | 'forbidden_categories' => 'category_id', |
---|
119 | 'visible_categories' => 'category_id', |
---|
120 | 'visible_images' => 'image_id', |
---|
121 | ), |
---|
122 | '', true |
---|
123 | ); |
---|
124 | $query .= ' |
---|
125 | and DATE ('.$datepfoya.') ="'.$daydate.'";'; |
---|
126 | $page['section'] = 'photos_from_one_year_ago'; |
---|
127 | $page['title'] = '<a href="' . duplicate_index_url() . '">' . l10n('Photos from one year ago') . '</a>'; |
---|
128 | $page['section_title'] = '<a href="'.get_gallery_home_url().'">' . l10n('Home') . '</a>' |
---|
129 | . $conf['level_separator'] . $page['title']; |
---|
130 | $page['items'] = query2array($query, null, 'id'); |
---|
131 | $template->assign('pfoyadata',l10n('Photos from').' '.format_date($daydate)); |
---|
132 | |
---|
133 | }else{ |
---|
134 | $yurl=explode('_year_ago', $testurl[1]); |
---|
135 | $yurl=$yurl[0]; |
---|
136 | if (!in_array('photos_from_'.$yurl.'_year_ago', $tokens)){return;} |
---|
137 | $daydate=date("Y-m-d", strtotime('-'.$yurl.' year')); |
---|
138 | $query = ' |
---|
139 | SELECT DISTINCT(i.id) |
---|
140 | FROM '.IMAGES_TABLE.' AS i |
---|
141 | INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON i.id = ic.image_id |
---|
142 | INNER JOIN '.CATEGORIES_TABLE.' AS c ON ic.category_id = c.id |
---|
143 | WHERE ' . |
---|
144 | get_sql_condition_FandF( |
---|
145 | array( |
---|
146 | 'forbidden_categories' => 'category_id', |
---|
147 | 'visible_categories' => 'category_id', |
---|
148 | 'visible_images' => 'image_id', |
---|
149 | ), |
---|
150 | '', true |
---|
151 | ); |
---|
152 | $query .= ' |
---|
153 | and DATE ('.$datepfoya.') ="'.$daydate.'";'; |
---|
154 | $page['section'] = 'photos_from_'.$yurl.'_year_ago'; |
---|
155 | $page['title'] = '<a href="' . duplicate_index_url() . '">' . l10n('Photos from %d years ago',$yurl) . '</a>'; |
---|
156 | $page['section_title'] = '<a href="'.get_gallery_home_url().'">' . l10n('Home') . '</a>' |
---|
157 | . $conf['level_separator'] . $page['title']; |
---|
158 | $page['items'] =query2array($query, null, 'id'); |
---|
159 | $template->assign('pfoyadata',l10n('Photos from').' '.format_date($daydate)); |
---|
160 | } |
---|
161 | |
---|
162 | |
---|
163 | } |
---|
164 | |
---|
165 | $template->set_filename('PFOYA', realpath(PFOYA_PATH . 'pfoya.tpl')); |
---|
166 | $template->assign_var_from_handle('CONTENT', 'PFOYA'); |
---|
167 | |
---|
168 | } |
---|
169 | |
---|
170 | add_event_handler('get_stuffs_modules', 'register_pfoya_module'); |
---|
171 | |
---|
172 | function register_pfoya_module($modules){ |
---|
173 | array_push($modules, array( |
---|
174 | 'path' => PFOYA_PATH.'/blockhome', |
---|
175 | 'name' => l10n('Photos from one year ago'), |
---|
176 | 'description' => l10n('Display X photos from one year ago in the gallery or a album'), |
---|
177 | ) |
---|
178 | ); |
---|
179 | return $modules; |
---|
180 | } |
---|
181 | |
---|
182 | |
---|
183 | |
---|
184 | |
---|
185 | |
---|
186 | |
---|
187 | |
---|
188 | |
---|
189 | |
---|
190 | |
---|
191 | |
---|