source: extensions/meta_og/initadmin.php @ 32296

Last change on this file since 32296 was 32229, checked in by ddtddt, 4 years ago

[Meta_OG] add chose albums for list photos / options use other image for album and photo

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