1 | <?php |
---|
2 | /* |
---|
3 | Plugin Name: Memories |
---|
4 | Version: auto |
---|
5 | Description: Add part "memories from year ago". Link in "Specials/explore" menu or Block menu or on page with PWG Stuffs. |
---|
6 | Plugin URI: https://piwigo.org/ext/extension_view.php?eid=893 |
---|
7 | Author: ddtddt |
---|
8 | Author URI: http://temmii.com/piwigo/ |
---|
9 | Has Settings: webmaster |
---|
10 | */ |
---|
11 | |
---|
12 | // +-----------------------------------------------------------------------+ |
---|
13 | // | Memories for Piwigo by TEMMII | |
---|
14 | // +-----------------------------------------------------------------------+ |
---|
15 | // | Copyright(C) 2020-2021 ddtddt http://temmii.com/piwigo/ | |
---|
16 | // +-----------------------------------------------------------------------+ |
---|
17 | // | This program is free software; you can redistribute it and/or modify | |
---|
18 | // | it under the terms of the GNU General Public License as published by | |
---|
19 | // | the Free Software Foundation | |
---|
20 | // | | |
---|
21 | // | This program is distributed in the hope that it will be useful, but | |
---|
22 | // | WITHOUT ANY WARRANTY; without even the implied warranty of | |
---|
23 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
---|
24 | // | General Public License for more details. | |
---|
25 | // | | |
---|
26 | // | You should have received a copy of the GNU General Public License | |
---|
27 | // | along with this program; if not, write to the Free Software | |
---|
28 | // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
---|
29 | // | USA. | |
---|
30 | // +-----------------------------------------------------------------------+ |
---|
31 | |
---|
32 | defined('PHPWG_ROOT_PATH') or die('Hacking attempt!'); |
---|
33 | |
---|
34 | define('PFOYA_DIR' , basename(dirname(__FILE__))); |
---|
35 | define('PFOYA_PATH' , PHPWG_PLUGINS_PATH .PFOYA_DIR . '/'); |
---|
36 | define('PFOYA_ADMIN' , get_root_url().'admin.php?page=plugin-'.PFOYA_DIR); |
---|
37 | |
---|
38 | include_once(PFOYA_PATH . 'include/function.pfoya.inc.php'); |
---|
39 | |
---|
40 | add_event_handler('loading_lang', 'pfoya_loading_lang'); |
---|
41 | function pfoya_loading_lang(){ |
---|
42 | load_language('plugin.lang', PFOYA_PATH); |
---|
43 | } |
---|
44 | |
---|
45 | global $conf; |
---|
46 | $confpfoya = safe_unserialize($conf['pfoya']); |
---|
47 | |
---|
48 | //admin menu |
---|
49 | /*add_event_handler('get_admin_plugin_menu_links', 'pfoya_admin_menu'); |
---|
50 | function pfoya_admin_menu($menu){ |
---|
51 | if (is_webmaster()){ |
---|
52 | load_language('plugin.lang', PFOYA_PATH); |
---|
53 | $menu[] = array( |
---|
54 | 'NAME' => l10n('Memories'), |
---|
55 | 'URL' => PFOYA_ADMIN, |
---|
56 | ); |
---|
57 | } |
---|
58 | return $menu; |
---|
59 | }*/ |
---|
60 | |
---|
61 | //public menu |
---|
62 | if($confpfoya['pfoya_menu']=='link'){ |
---|
63 | add_event_handler('blockmanager_apply' , 'add_link_pfoya'); |
---|
64 | function add_link_pfoya($menu_ref_arr){ |
---|
65 | global $conf; |
---|
66 | $confpfoya = safe_unserialize($conf['pfoya']); |
---|
67 | $menu = &$menu_ref_arr[0]; |
---|
68 | if (($block = $menu->get_block('mbSpecials')) != null){ |
---|
69 | array_splice($block->data, ($confpfoya['pfoya_position'])-1, 0, |
---|
70 | array('memories-1-year-ago' => |
---|
71 | array( |
---|
72 | 'URL' => make_index_url(array('section' => 'memories-1-year-ago')), |
---|
73 | 'TITLE' => l10n('Displays Memories from years ago'), |
---|
74 | 'NAME' => l10n('Memories') |
---|
75 | ) |
---|
76 | ) |
---|
77 | ); |
---|
78 | } |
---|
79 | } |
---|
80 | }else if($confpfoya['pfoya_menu']=='block'){ |
---|
81 | add_event_handler('blockmanager_register_blocks', 'register_pfoya_menubar_blocks'); |
---|
82 | add_event_handler('blockmanager_apply', 'pfoya_apply'); |
---|
83 | |
---|
84 | function register_pfoya_menubar_blocks($menu_ref_arr) { |
---|
85 | $menu = & $menu_ref_arr[0]; |
---|
86 | if ($menu->get_id() != 'menubar') |
---|
87 | return; |
---|
88 | $menu->register_block(new RegisteredBlock('mbpfoya', 'pfoya', ('Photo from year ago'))); |
---|
89 | } |
---|
90 | |
---|
91 | function pfoya_apply($menu_ref_arr) { |
---|
92 | global $template,$user; |
---|
93 | $menu = & $menu_ref_arr[0]; |
---|
94 | listyearsBlock(); |
---|
95 | $template->assign('PFOAYALINKM',make_index_url(array('section' => 'memories-1-year-ago'))); |
---|
96 | |
---|
97 | if (($block = $menu->get_block('mbpfoya')) != null) { |
---|
98 | $template->set_template_dir(PFOYA_PATH); |
---|
99 | if ($user['theme'] == 'bootstrapdefault'||$user['theme'] == 'bootstrap_darkroom'){ |
---|
100 | $block->template = 'menubar_pfoya_bootstrap.tpl'; |
---|
101 | }else if ($user['theme'] == 'smartpocket'){ |
---|
102 | $block->template = 'menubar_pfoya_smartpocket.tpl'; |
---|
103 | }else if ($user['theme'] == 'modus'){ |
---|
104 | $block->template = 'menubar_pfoya_modus.tpl'; |
---|
105 | }else{ |
---|
106 | $block->template = 'menubar_pfoya.tpl'; |
---|
107 | } |
---|
108 | } |
---|
109 | } |
---|
110 | } |
---|
111 | add_event_handler('loc_end_section_init', 'section_init_pfoya'); |
---|
112 | function section_init_pfoya(){ |
---|
113 | global $tokens, $page, $conf, $template, $user; |
---|
114 | $confpfoya = safe_unserialize($conf['pfoya']); |
---|
115 | $testurl = explode('memories-', $_SERVER['REQUEST_URI']); |
---|
116 | $template->assign('PFOAYALINK',make_index_url(array('section' => 'memories-1-year-ago'))); |
---|
117 | if(!empty($testurl[1])){ |
---|
118 | |
---|
119 | $datepfoya = $confpfoya['pfoya_dateb']; |
---|
120 | $daydatemax= $confpfoya['pfoya_datemax']; |
---|
121 | if($confpfoya['pfoya_datemax']>1 and $confpfoya['pfoya_show']==1){ |
---|
122 | $template->assign('pfoya','a'); |
---|
123 | listyears(); |
---|
124 | } |
---|
125 | if(substr($testurl[1],0,10)=='1-year-ago'){ |
---|
126 | if (!in_array('memories-1-year-ago', $tokens)){return;} |
---|
127 | $daydate=date("Y-m-d", strtotime('-1 year')); |
---|
128 | $query = ' |
---|
129 | SELECT DISTINCT(i.id) |
---|
130 | FROM '.IMAGES_TABLE.' AS i |
---|
131 | INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON i.id = ic.image_id |
---|
132 | INNER JOIN '.CATEGORIES_TABLE.' AS c ON ic.category_id = c.id |
---|
133 | WHERE ' . |
---|
134 | get_sql_condition_FandF( |
---|
135 | array( |
---|
136 | 'forbidden_categories' => 'category_id', |
---|
137 | 'visible_categories' => 'category_id', |
---|
138 | 'visible_images' => 'image_id', |
---|
139 | ), |
---|
140 | '', true |
---|
141 | ); |
---|
142 | $query .= ' |
---|
143 | and DATE ('.$datepfoya.') ="'.$daydate.'";'; |
---|
144 | $page['section'] = 'memories-1-year-ago'; |
---|
145 | $page['title'] = '<a href="' . duplicate_index_url() . '">' . l10n('1 year ago') . '</a>'; |
---|
146 | $page['section_title'] = '<a href="'.get_gallery_home_url().'">' . l10n('Home') . '</a>' |
---|
147 | . $conf['level_separator'] . $page['title']; |
---|
148 | $page['items'] = query2array($query, null, 'id'); |
---|
149 | $template->assign('pfoyadata',l10n('Photos from').' '.format_date($daydate)); |
---|
150 | |
---|
151 | }else{ |
---|
152 | $yurl=explode('-years-ago', $testurl[1]); |
---|
153 | $yurl=$yurl[0]; |
---|
154 | if (!in_array('memories-'.$yurl.'-years-ago', $tokens)){return;} |
---|
155 | $daydate=date("Y-m-d", strtotime('-'.$yurl.' year')); |
---|
156 | $query = ' |
---|
157 | SELECT DISTINCT(i.id) |
---|
158 | FROM '.IMAGES_TABLE.' AS i |
---|
159 | INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON i.id = ic.image_id |
---|
160 | INNER JOIN '.CATEGORIES_TABLE.' AS c ON ic.category_id = c.id |
---|
161 | WHERE ' . |
---|
162 | get_sql_condition_FandF( |
---|
163 | array( |
---|
164 | 'forbidden_categories' => 'category_id', |
---|
165 | 'visible_categories' => 'category_id', |
---|
166 | 'visible_images' => 'image_id', |
---|
167 | ), |
---|
168 | '', true |
---|
169 | ); |
---|
170 | $query .= ' |
---|
171 | and DATE ('.$datepfoya.') ="'.$daydate.'";'; |
---|
172 | $page['section'] = 'memories-'.$yurl.'-years-ago'; |
---|
173 | $page['title'] = '<a href="' . duplicate_index_url() . '">' . l10n('%d years ago',$yurl) . '</a>'; |
---|
174 | $page['section_title'] = '<a href="'.get_gallery_home_url().'">' . l10n('Home') . '</a>' |
---|
175 | . $conf['level_separator'] . $page['title']; |
---|
176 | $page['items'] =query2array($query, null, 'id'); |
---|
177 | $template->assign('pfoyadata',l10n('Photos from').' '.format_date($daydate)); |
---|
178 | } |
---|
179 | |
---|
180 | |
---|
181 | } |
---|
182 | if ($user['theme'] == 'bootstrapdefault'||$user['theme'] == 'bootstrap_darkroom'){ |
---|
183 | $template->set_filename('PFOYA', realpath(PFOYA_PATH . 'pfoya_bootstrap.tpl')); |
---|
184 | }else{ |
---|
185 | $template->set_filename('PFOYA', realpath(PFOYA_PATH . 'pfoya.tpl')); |
---|
186 | } |
---|
187 | |
---|
188 | |
---|
189 | $template->assign_var_from_handle('CONTENT', 'PFOYA'); |
---|
190 | |
---|
191 | } |
---|
192 | |
---|
193 | add_event_handler('get_stuffs_modules', 'register_pfoya_module'); |
---|
194 | function register_pfoya_module($modules){ |
---|
195 | array_push($modules, array( |
---|
196 | 'path' => PFOYA_PATH.'/blockhome', |
---|
197 | 'name' => l10n('Memories'), |
---|
198 | 'description' => l10n('Display X photos from 1 year ago in the gallery or a album'), |
---|
199 | ) |
---|
200 | ); |
---|
201 | return $modules; |
---|
202 | } |
---|
203 | |
---|
204 | add_event_handler('ws_add_methods', 'memories_add_methods'); |
---|
205 | function memories_add_methods($arr){ |
---|
206 | $service = &$arr[0]; |
---|
207 | |
---|
208 | $service->addMethod( |
---|
209 | 'memories.photos.list', |
---|
210 | 'ws_memories_photos_list', |
---|
211 | array( |
---|
212 | 'years' => array('default' => null, 'type' => WS_TYPE_ID), |
---|
213 | ), |
---|
214 | 'get list photos n years ago)' |
---|
215 | ); |
---|
216 | } |
---|