source: extensions/memories/blockhome/main.inc.php @ 32407

Last change on this file since 32407 was 32407, checked in by ddtddt, 3 years ago

[memories] piwigo 11

File size: 5.4 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Memories for Piwigo by TEMMII                                         |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2020-2021 ddtddt               http://temmii.com/piwigo/ |
6// +-----------------------------------------------------------------------+
7// | This program is free software; you can redistribute it and/or modify  |
8// | it under the terms of the GNU General Public License as published by  |
9// | the Free Software Foundation                                          |
10// |                                                                       |
11// | This program is distributed in the hope that it will be useful, but   |
12// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
13// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
14// | General Public License for more details.                              |
15// |                                                                       |
16// | You should have received a copy of the GNU General Public License     |
17// | along with this program; if not, write to the Free Software           |
18// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
19// | USA.                                                                  |
20// +-----------------------------------------------------------------------+
21
22if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
23
24global $page, $user, $conf, $template;
25$confpfoya = safe_unserialize($conf['pfoya']);
26
27$page_save = $page;
28$tpl_save = $template->get_template_vars('THUMBNAILS');
29$pfoyanip = $confpfoya['pfoya_nip'];
30$datepfoya = $confpfoya['pfoya_dateb'];
31
32
33if (script_basename() == 'picture'
34  or ($datas['cat_display'] == 'wo_thumb' and !empty($page['items']))
35  or ($datas['cat_display'] == 'w_thumb' and empty($page['items']) and isset($page['category']))
36  or ($datas['cat_display'] == 'selected_cats' and isset($page['category']) and !in_array($page['category']['id'], $datas['cat_selection'])))
37{
38  return false;
39}
40
41        if($confpfoya['pfoya_datemax']>1 and $confpfoya['pfoya_showps']!=0)$template->assign('pfoya','a');
42        $template->assign('renewpfoya',realpath(PFOYA_PATH.'blockhome/main.inc.php'));
43        if (isset($_SESSION['memodate'])) {
44          $daydate=date("Y-m-d", strtotime('-'.$_SESSION['memodate'].' year'));
45        }else{
46          $daydate=date("Y-m-d", strtotime('-1 year'));
47        }
48        $template->clear_assign('pfoyas');
49        for ($i = 1; $i <= $confpfoya['pfoya_datemax']; $i++) {
50        $daydate2=date("Y-m-d", strtotime('-'.$i.' year'));
51          $query = '
52                SELECT COUNT(DISTINCT(i.id)) as count
53                FROM '.IMAGES_TABLE.' AS i
54                INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON i.id = ic.image_id
55                INNER JOIN '.CATEGORIES_TABLE.' AS c ON ic.category_id = c.id
56                WHERE ' . 
57                  get_sql_condition_FandF(
58                        array(
59                          'forbidden_categories' => 'category_id',
60                          'visible_categories' => 'category_id',
61                          'visible_images' => 'image_id',
62                          ),
63                        '', true
64                        );
65          if (isset($page['category'])){
66                $query .= '
67                        AND ( c.uppercats LIKE \''.$page['category']['uppercats'].',%\' OR c.id = '.$page['category']['id'].' )
68                ';
69          }
70          $query .= '
71                and DATE ('.$datepfoya.') ="'.$daydate2.'";';
72
73          $row = pwg_db_fetch_assoc(pwg_query($query));
74       
75          $items['NB_IMAGES']=$row['count'];
76          if($confpfoya['pfoya_showps']==1){
77                if ($i == 1){
78                  $items['URL']=make_index_url(array('section' => 'memories-1-year-ago'));
79                }else{
80                  $items['URL']=make_index_url(array('section' => 'memories-'.$i.'-years-ago'));
81                }
82          }
83          if ($i == 1){
84                $items['LABEL']=l10n('1 year ago');
85          }else{
86                $items['LABEL']=l10n('%d years ago',$i);
87          }
88          if($confpfoya['pfoya_showps']==2){
89                        $items['URL']=$_SERVER["REQUEST_URI"];
90          }
91          $items['MEMODATE']=$i;
92          $template->append('pfoyas', $items);
93        }
94
95 $query = '
96SELECT DISTINCT(i.id)
97  FROM '.IMAGES_TABLE.' AS i
98    INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON i.id = ic.image_id
99    INNER JOIN '.CATEGORIES_TABLE.' AS c ON ic.category_id = c.id ';
100
101 $query .= 'WHERE ' . 
102      get_sql_condition_FandF(
103        array(
104          'forbidden_categories' => 'category_id',
105          'visible_categories' => 'category_id',
106          'visible_images' => 'image_id',
107          ),
108        '', true
109        );
110  $query .= '
111       and DATE ('.$datepfoya.') ="'.$daydate.'"';
112
113if (isset($page['category'])){
114  $query .= '
115        AND ( c.uppercats LIKE \''.$page['category']['uppercats'].',%\' OR c.id = '.$page['category']['id'].' )
116  ';
117}
118  $query .= '
119    LIMIT 0, '.$pfoyanip.'
120  ;';
121if(empty($query)){
122        if($_SESSION['memodate']<$confpfoya['pfoya_nip']){
123                $_SESSION['memodate']+=1;
124                redirect($_SERVER["REQUEST_URI"]);
125        }
126}
127 
128 
129    $page['items'] = array_from_query($query, 'id');
130        $page['start'] = 0;
131        $page['section'] = 'memories-1-year-ago';
132        $page['nb_image_page']=$pfoyanip;
133
134
135
136$tpl_thumbnails_var = array();
137$pwg_stuffs_tpl_thumbnails_var = & $tpl_thumbnails_var;
138include(PHPWG_ROOT_PATH.'include/category_default.inc.php');
139
140if (empty($pwg_stuffs_tpl_thumbnails_var)){
141  $template->assign('NOPHOTOPFOYA','b');
142}
143  $template->assign('pfoyadata',l10n('Photos from').' '.format_date($daydate));
144  $block['thumbnails'] = $pwg_stuffs_tpl_thumbnails_var;
145  $block['derivative_params'] = ImageStdParams::get_by_type(IMG_THUMB);
146  $block['TEMPLATE'] = realpath(PFOYA_PATH.'/blockhome/stuffs_homepfoya.tpl');
147$page = $page_save;
148$template->assign('THUMBNAILS', $tpl_save);
149
150?>
Note: See TracBrowser for help on using the repository browser.