source: extensions/meta_og/initadmin.php @ 33041

Last change on this file since 33041 was 33041, checked in by ddtddt, 5 months ago

[meta_og] bug php 8.3

File size: 9.2 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Meta Open Graph plugin for Piwigo by TEMMII                           |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2020-2023 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!');
23include_once(metaog_PATH . 'include/function.mog.inc.php');
24//Add link menu
25/*add_event_handler('get_admin_plugin_menu_links', 'metaog_admin_menu');
26function metaog_admin_menu($menu){
27  $menu[] = array(
28    'NAME' => l10n('Metadata Open Graph'),
29    'URL' => METAOG_ADMIN,
30  );
31    return $menu;
32}*/
33
34//add prefiltre photo
35add_event_handler('loc_begin_admin_page', 'metaogPadminf',95);
36
37function metaogPadminf(){
38  global $template;
39  $template->set_prefilter('picture_modify', 'metaogPadminfT');
40  $template->set_filename('mog_adminphoto', realpath(metaog_PATH.'mog_adminphoto.tpl'));
41  $template->assign_var_from_handle('MOG_ADMINPHOTO', 'mog_adminphoto');
42}
43
44function metaogPadminfT($content){
45  $search = '#<input type="hidden" name="pwg_token"#';
46  return preg_replace($search,'{$MOG_ADMINPHOTO}', $content);
47}
48
49add_event_handler('loc_begin_admin_page', 'metaogPadminA',60);
50 
51function metaogPadminA(){
52  if (isset($_GET['image_id'])){
53        global $template, $prefixeTable, $conf;
54        $pageog=$_GET['image_id'];
55    $metaog = pwg_db_fetch_assoc(pwg_query("SELECT * FROM " . METAOG_TABLE . " WHERE type = 2 AND idobj = '".$_GET['image_id']."';"));
56        if(empty($metaog)){
57                $metaog['id']='';
58                $metaog['metaogtitle']='';
59                $metaog['metaogdescription']='';
60                $metaog['metaogimage']='';
61        }
62        if(isset($conf['mogshowpai']) and $conf['mogshowpai']==true){
63        $tab_picture = listphotosmog();
64         if (pwg_db_num_rows($tab_picture)){
65      while ($info_photos = pwg_db_fetch_assoc($tab_picture)) {
66                if($info_photos['id']==$metaog['metaogimage']){
67                  $select="SELECTED";
68                  $metaog['path']=$info_photos['path'];
69                }else{
70                  $select="";
71                }
72          if(empty($info_photos['name'])){$legend=$info_photos['file'];}else{$legend=$info_photos['name'];}
73                $metaoglistphotoT[] = $info_photos['id'].' - '.$legend;
74                $metaoglistphoto[] = $info_photos['id'];
75                $metaoglistphotodataurl[] = get_absolute_root_url().PWG_DERIVATIVE_DIR.substr($info_photos['path'], 2, -4)."-th".substr($info_photos['path'],-4);
76                $items = array(
77                  'PHOTOID' => $info_photos['id'],
78                  'PHOTOINFO' => $info_photos['id'].' - '.$legend,
79                  'PHOTOSELECT' => $select,
80                  'PHOTOURL' => get_absolute_root_url().PWG_DERIVATIVE_DIR.substr($info_photos['path'], 2, -4)."-th".substr($info_photos['path'],-4),
81                );
82                $template->append('info_photos', $items);
83      }
84   }
85   if (empty($metaog['metaogimage'])){unset($metaog['metaogimage']);}
86   if(isset($metaog['metaogimage'])){   
87          $metaogpath=get_absolute_root_url().PWG_DERIVATIVE_DIR.substr($metaog['path'], 2, -4)."-th".substr($metaog['path'],-4);
88   }else{
89          $metaogpath="";
90          $metaog['metaogimage']="";
91   }
92   $template->assign('SHOWMOGI', "1");
93  }else{
94   $template->assign('SHOWMOGI', "0");
95  }
96   if(!isset($metaogpath)){$metaogpath="";}
97  $template->assign(
98    'metaog_editP',
99          array(
100                'metaogidid'  => $metaog['id'],
101                'metaogidobj'  => $pageog,
102        'metaogtitle' => $metaog['metaogtitle'],
103                'metaogdescription' => $metaog['metaogdescription'],
104                'metaogimage' => $metaog['metaogimage'],
105                'metaogpath' => $metaogpath,
106    ));
107  }
108  if(isset($_POST['metaogtitlesaveP']) or isset($_POST['metaogdescriptionsaveP'])or isset($_POST['metaogimagesaveP'])){
109        if(isset($_POST['metaogimagesaveP'])){
110                if($_POST['metaogimagesaveP']=="-10" || $_POST['metaogimagesaveP']==$_POST['metaogidobjP']){$_POST['metaogimagesaveP']='';}
111        }else{
112                $_POST['metaogimagesaveP']='';
113        }
114        if(!empty($_POST['metaogidP'])){
115        $query = '
116                UPDATE ' . METAOG_TABLE . '
117                        SET metaogtitle= \''.$_POST['metaogtitlesaveP'].'\'
118                        ,metaogdescription= \''.$_POST['metaogdescriptionsaveP'].'\'
119                        ,metaogimage= \''.$_POST['metaogimagesaveP'].'\'
120                        WHERE id = \''.$_POST['metaogidP'].'\'
121    ;';
122        pwg_query($query);
123        }else{
124        $q = 'INSERT INTO ' . $prefixeTable . 'metaog(type,idobj,metaogtitle,metaogdescription,metaogimage)VALUES (2,"' . $_POST['metaogidobjP'] . '","' . $_POST['metaogtitlesaveP'] . '","' . $_POST['metaogdescriptionsaveP'] . '","' . $_POST['metaogimagesaveP'] .'");';
125    pwg_query($q);
126    }
127        header('Location:'.get_root_url().'admin.php?page=photo-'.$_POST['metaogidobjP'].'-properties');
128}
129}
130       
131//add prefiltre album
132/*
133add_event_handler('loc_begin_admin_page', 'metaogAadminf', 95);
134
135function metaogAadminf(){
136        global $template;
137        $template->set_prefilter('album_properties', 'metaogAadminfT');
138        $template->set_filename('mog_adminalbum', realpath(metaog_PATH.'mog_adminalbum.tpl'));
139        $template->assign_var_from_handle('MOG_ADMINALBUM', 'mog_adminalbum');
140}
141
142function metaogAadminfT($content){
143  $search = '#<p style="margin:0">#';
144   return preg_replace($search, '{$MOG_ADMINALBUM}', $content);
145}
146
147add_event_handler('loc_begin_admin_page', 'metaogAadminA', 60);
148 
149function metaogAadminA(){
150  if (isset($_GET['cat_id']) and !isset($_GET['image_id'])){
151        global $template, $prefixeTable, $conf;
152        $pageog=$_GET['cat_id'];
153    $metaog = pwg_db_fetch_assoc(pwg_query("SELECT * FROM " . METAOG_TABLE . " WHERE type = 3 AND idobj = '".$_GET['cat_id']."';"));
154        if(empty($metaog)){
155                $metaog['id']='';
156                $metaog['metaogtitle']='';
157                $metaog['metaogdescription']='';
158                $metaog['metaogimage']='';
159        }
160        if($conf['mogshowpa']==3||$conf['mogshowpa']==4){
161        $tab_picture = listphotosmog();
162        $metaog['path']='';
163        if (pwg_db_num_rows($tab_picture)){
164      while ($info_photos = pwg_db_fetch_assoc($tab_picture)) {
165                if($info_photos['id']==$metaog['metaogimage']){
166                  $select="SELECTED";
167                  $metaog['path']=$info_photos['path'];
168                }else{
169                  $select="";
170                }
171          if(empty($info_photos['name'])){$legend=$info_photos['file'];}else{$legend=$info_photos['name'];}
172                $items = array(
173                  'PHOTOID' => $info_photos['id'],
174                  'PHOTOINFO' => $info_photos['id'].' - '.$legend,
175                  'PHOTOSELECT' => $select,
176                  'PHOTOURL' => get_absolute_root_url().PWG_DERIVATIVE_DIR.substr($info_photos['path'], 2, -4)."-th".substr($info_photos['path'],-4),
177                );
178                $template->append('info_photos', $items);
179      }
180    }
181  if (empty($metaog['metaogimage'])){unset($metaog['metaogimage']);}
182  if(isset($metaog['metaogimage'])){   
183          $metaogpath=get_absolute_root_url().PWG_DERIVATIVE_DIR.substr($metaog['path'], 2, -4)."-th".substr($metaog['path'],-4);
184        }else{
185          $metaogpath="";
186          $metaog['metaogimage']="";
187        }
188        $template->assign('SHOWMOGI', "1");
189        }else{
190          $template->assign('SHOWMOGI', "0");
191        }
192  if(!isset($metaogpath)){$metaogpath="";}
193  $tab_album = pwg_db_fetch_assoc(pwg_query("SELECT id,representative_picture_id FROM " . CATEGORIES_TABLE . " WHERE id = '".$_GET['cat_id']."';"));
194  $template->assign(
195    'metaog_editA',
196          array(
197                'metaogidid'  => $metaog['id'],
198                'metaogidobj'  => $pageog,
199        'metaogtitle' => $metaog['metaogtitle'],
200                'metaogdescription' => $metaog['metaogdescription'],
201                'metaogimage' => $metaog['metaogimage'],
202                'metaogpath' => $metaogpath,
203                'metaogrealbum' => $tab_album['representative_picture_id'],
204    ));
205 
206  }
207  if(isset($_POST['metaogtitlesaveA']) or isset($_POST['metaogdescriptionsaveA'])or isset($_POST['metaogimagesaveA'])){
208        if($_POST['metaogimagesaveA']=="-10"|| $_POST['metaogimagesaveA']=="-20" || $_POST['metaogimagesaveA']==$tab_album['representative_picture_id']){$_POST['metaogimagesaveA']='';}
209        if(!empty($_POST['metaogidA'])){
210                if($_POST['metaogidobjA'] == $_POST['metaogimagesaveA']){$_POST['metaogimagesaveA']='';}
211        $query = '
212                UPDATE ' . METAOG_TABLE . '
213                        SET metaogtitle= \''.$_POST['metaogtitlesaveA'].'\'
214                        ,metaogdescription= \''.$_POST['metaogdescriptionsaveA'].'\'
215                        ,metaogimage= \''.$_POST['metaogimagesaveA'].'\'
216                        WHERE id = \''.$_POST['metaogidA'].'\'
217    ;';
218        pwg_query($query);
219        }else{
220        $q = 'INSERT INTO ' . $prefixeTable . 'metaog(type,idobj,metaogtitle,metaogdescription,metaogimage)VALUES (3,"' . $_POST['metaogidobjA'] . '","' . $_POST['metaogtitlesaveA'] . '","' . $_POST['metaogdescriptionsaveA'] . '","' . $_POST['metaogimagesaveA'] .'");';
221    pwg_query($q);
222    }
223        header('Location:'.get_root_url().'admin.php?page=album-'.$_POST['metaogidobjP'].'-properties');
224}
225}
226 
227*/
228?>
Note: See TracBrowser for help on using the repository browser.