source: extensions/meta_og/initadmin.php @ 33039

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

[meta_og] add update

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($_POST['metaogimagesaveP']=="-10" || $_POST['metaogimagesaveP']=="-20" || $_POST['metaogimagesaveP']==$_POST['metaogidobjP']){$_POST['metaogimagesaveP']='';}
110        if(!empty($_POST['metaogidP'])){
111        $query = '
112                UPDATE ' . METAOG_TABLE . '
113                        SET metaogtitle= \''.$_POST['metaogtitlesaveP'].'\'
114                        ,metaogdescription= \''.$_POST['metaogdescriptionsaveP'].'\'
115                        ,metaogimage= \''.$_POST['metaogimagesaveP'].'\'
116                        WHERE id = \''.$_POST['metaogidP'].'\'
117    ;';
118        pwg_query($query);
119        }else{
120        $q = 'INSERT INTO ' . $prefixeTable . 'metaog(type,idobj,metaogtitle,metaogdescription,metaogimage)VALUES (2,"' . $_POST['metaogidobjP'] . '","' . $_POST['metaogtitlesaveP'] . '","' . $_POST['metaogdescriptionsaveP'] . '","' . $_POST['metaogimagesaveP'] .'");';
121    pwg_query($q);
122    }
123        header('Location:'.get_root_url().'admin.php?page=photo-'.$_POST['metaogidobjP'].'-properties');
124}
125}
126       
127//add prefiltre album
128/*
129add_event_handler('loc_begin_admin_page', 'metaogAadminf', 95);
130
131function metaogAadminf(){
132        global $template;
133        $template->set_prefilter('album_properties', 'metaogAadminfT');
134        $template->set_filename('mog_adminalbum', realpath(metaog_PATH.'mog_adminalbum.tpl'));
135        $template->assign_var_from_handle('MOG_ADMINALBUM', 'mog_adminalbum');
136}
137
138function metaogAadminfT($content){
139  $search = '#<p style="margin:0">#';
140   return preg_replace($search, '{$MOG_ADMINALBUM}', $content);
141}
142
143add_event_handler('loc_begin_admin_page', 'metaogAadminA', 60);
144 
145function metaogAadminA(){
146  if (isset($_GET['cat_id']) and !isset($_GET['image_id'])){
147        global $template, $prefixeTable, $conf;
148        $pageog=$_GET['cat_id'];
149    $metaog = pwg_db_fetch_assoc(pwg_query("SELECT * FROM " . METAOG_TABLE . " WHERE type = 3 AND idobj = '".$_GET['cat_id']."';"));
150        if(empty($metaog)){
151                $metaog['id']='';
152                $metaog['metaogtitle']='';
153                $metaog['metaogdescription']='';
154                $metaog['metaogimage']='';
155        }
156        if($conf['mogshowpa']==3||$conf['mogshowpa']==4){
157        $tab_picture = listphotosmog();
158        $metaog['path']='';
159        if (pwg_db_num_rows($tab_picture)){
160      while ($info_photos = pwg_db_fetch_assoc($tab_picture)) {
161                if($info_photos['id']==$metaog['metaogimage']){
162                  $select="SELECTED";
163                  $metaog['path']=$info_photos['path'];
164                }else{
165                  $select="";
166                }
167          if(empty($info_photos['name'])){$legend=$info_photos['file'];}else{$legend=$info_photos['name'];}
168                $items = array(
169                  'PHOTOID' => $info_photos['id'],
170                  'PHOTOINFO' => $info_photos['id'].' - '.$legend,
171                  'PHOTOSELECT' => $select,
172                  'PHOTOURL' => get_absolute_root_url().PWG_DERIVATIVE_DIR.substr($info_photos['path'], 2, -4)."-th".substr($info_photos['path'],-4),
173                );
174                $template->append('info_photos', $items);
175      }
176    }
177  if (empty($metaog['metaogimage'])){unset($metaog['metaogimage']);}
178  if(isset($metaog['metaogimage'])){   
179          $metaogpath=get_absolute_root_url().PWG_DERIVATIVE_DIR.substr($metaog['path'], 2, -4)."-th".substr($metaog['path'],-4);
180        }else{
181          $metaogpath="";
182          $metaog['metaogimage']="";
183        }
184        $template->assign('SHOWMOGI', "1");
185        }else{
186          $template->assign('SHOWMOGI', "0");
187        }
188  if(!isset($metaogpath)){$metaogpath="";}
189  $tab_album = pwg_db_fetch_assoc(pwg_query("SELECT id,representative_picture_id FROM " . CATEGORIES_TABLE . " WHERE id = '".$_GET['cat_id']."';"));
190  $template->assign(
191    'metaog_editA',
192          array(
193                'metaogidid'  => $metaog['id'],
194                'metaogidobj'  => $pageog,
195        'metaogtitle' => $metaog['metaogtitle'],
196                'metaogdescription' => $metaog['metaogdescription'],
197                'metaogimage' => $metaog['metaogimage'],
198                'metaogpath' => $metaogpath,
199                'metaogrealbum' => $tab_album['representative_picture_id'],
200    ));
201 
202  }
203  if(isset($_POST['metaogtitlesaveA']) or isset($_POST['metaogdescriptionsaveA'])or isset($_POST['metaogimagesaveA'])){
204        if($_POST['metaogimagesaveA']=="-10"|| $_POST['metaogimagesaveA']=="-20" || $_POST['metaogimagesaveA']==$tab_album['representative_picture_id']){$_POST['metaogimagesaveA']='';}
205        if(!empty($_POST['metaogidA'])){
206                if($_POST['metaogidobjA'] == $_POST['metaogimagesaveA']){$_POST['metaogimagesaveA']='';}
207        $query = '
208                UPDATE ' . METAOG_TABLE . '
209                        SET metaogtitle= \''.$_POST['metaogtitlesaveA'].'\'
210                        ,metaogdescription= \''.$_POST['metaogdescriptionsaveA'].'\'
211                        ,metaogimage= \''.$_POST['metaogimagesaveA'].'\'
212                        WHERE id = \''.$_POST['metaogidA'].'\'
213    ;';
214        pwg_query($query);
215        }else{
216        $q = 'INSERT INTO ' . $prefixeTable . 'metaog(type,idobj,metaogtitle,metaogdescription,metaogimage)VALUES (3,"' . $_POST['metaogidobjA'] . '","' . $_POST['metaogtitlesaveA'] . '","' . $_POST['metaogdescriptionsaveA'] . '","' . $_POST['metaogimagesaveA'] .'");';
217    pwg_query($q);
218    }
219        header('Location:'.get_root_url().'admin.php?page=album-'.$_POST['metaogidobjP'].'-properties');
220}
221}
222 
223*/
224?>
Note: See TracBrowser for help on using the repository browser.