source: extensions/meta/main.inc.php

Last change on this file was 33080, checked in by ddtddt, 5 weeks ago

[meta] size photo id

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 9.7 KB
Line 
1<?php
2/*
3Plugin Name: meta
4Version: auto
5Description: Allows to add metadata
6Plugin URI: http://piwigo.org/ext/extension_view.php?eid=220
7Author: ddtddt
8Author URI: http://temmii.com/piwigo/
9Has Settings: webmaster
10*/
11
12// +-----------------------------------------------------------------------+
13// | meta plugin for Piwigo by TEMMII                                      |
14// +-----------------------------------------------------------------------+
15// | Copyright(C) 2008-2023 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
32if (!defined('PHPWG_ROOT_PATH'))
33    die('Hacking attempt!');
34
35global $prefixeTable, $page;
36
37define('meta_DIR', basename(dirname(__FILE__)));
38define('meta_PATH', PHPWG_PLUGINS_PATH . meta_DIR . '/');
39if (!defined('meta_TABLE')) define('meta_TABLE', $prefixeTable . 'meta');
40if (!defined('meta_img_TABLE')) define('meta_img_TABLE', $prefixeTable . 'meta_img');
41if (!defined('meta_cat_TABLE')) define('meta_cat_TABLE', $prefixeTable . 'meta_cat');
42if (!defined('METAPERSO_TABLE')) define('METAPERSO_TABLE', $prefixeTable . 'metaperso');
43if (!defined('META_AP_TABLE')) define('META_AP_TABLE', $prefixeTable . 'meta_ap');
44define('META_ADMIN',get_root_url().'admin.php?page=plugin-'.meta_DIR);
45
46add_event_handler('loading_lang', 'meta_loading_lang');   
47function meta_loading_lang(){
48  load_language('plugin.lang', meta_PATH);
49}
50
51// Plugin for admin
52if (script_basename() == 'admin') {
53    include_once(dirname(__FILE__) . '/initadmin.php');
54}
55
56//Gestion des meta dans le header
57add_event_handler('loc_begin_page_header', 'Change_Meta', 20);
58add_event_handler('loc_end_page_header', 'add_meta', 56);
59add_event_handler('loc_end_page_header', 'add_metacat', 61);
60add_event_handler('loc_end_page_header', 'add_metaimg', 71);
61add_event_handler('loc_after_page_header', 'set_meta_back');
62
63function Change_Meta(){
64  global $template, $pwg_loaded_plugins;
65  $template->set_prefilter('header', 'upmata');
66  if (isset($pwg_loaded_plugins['ExtendedDescription'])){
67    add_event_handler('AP_render_content', 'get_user_language_desc');
68  }
69}
70
71function upmata($content){
72  $search = '#<meta name="description" content=".*?">#';
73  $replacement = '<meta name="description" content="{$PLUG_META}">';
74  return preg_replace($search, $replacement, $content);
75}
76
77function add_meta(){
78  global $template, $page, $meta_infos, $pwg_loaded_plugins;
79  $meta_infos = array();
80  $meta_infos['author'] = $template->get_template_vars('INFO_AUTHOR');
81  $meta_infos['related_tags'] = $template->get_template_vars('related_tags');
82  $meta_infos['info'] = $template->get_template_vars('INFO_FILE');
83  $meta_infos['title'] = $template->get_template_vars('PAGE_TITLE');
84
85  $query = 'SELECT id,metaname,metaval FROM ' . meta_TABLE . ' WHERE metaname IN (\'author\', \'keywords\', \'Description\', \'robots\');';
86  $result = pwg_query($query);
87  $meta = array();
88  while ($row = pwg_db_fetch_assoc($result)){
89    $meta[$row['metaname']] = $row['metaval'];
90    $metaED[$row['metaname']] = trigger_change('AP_render_content', $meta[$row['metaname']]);
91  }
92
93  // Authors
94  if (!empty($meta_infos['author']) and ! empty($metaED['author'])){
95    $template->assign('INFO_AUTHOR', $meta_infos['author'] . ' - ' . $metaED['author']);
96  } elseif (!empty($metaED['author'])){
97    $template->assign('INFO_AUTHOR', $metaED['author']);
98  }
99
100  // Keywords
101  if (!empty($metaED['keywords'])){
102    $template->append('related_tags', array('name' => $metaED['keywords']));
103  }
104
105  // Description
106  if (!empty($meta_infos['title']) and ! empty($meta_infos['info']) and ! empty($metaED['Description'])) {
107    $template->assign('PLUG_META', $meta_infos['title'] . ' - ' . $meta_infos['info'] . ', ' . $metaED['Description']);
108  } elseif (!empty($meta_infos['title']) and ! empty($metaED['Description'])) {
109    $template->assign('PLUG_META', $meta_infos['title'] . ' - ' . $metaED['Description']);
110  } elseif (!empty($metaED['Description'])) {
111    $template->assign('PLUG_META', $metaED['Description']);
112  } else {
113    $template->assign('PLUG_META', $meta_infos['title']);
114  }
115
116  // Robots
117  if (!empty($meta['robots'])) {
118    $template->append('head_elements', '<meta name="robots" content="' . $meta['robots'] . '">');
119  }
120
121  //Metaperso
122  if (script_basename() !== 'admin') {
123    $metapersos = pwg_query("SELECT * FROM " . METAPERSO_TABLE . ";");
124
125    if (pwg_db_num_rows($metapersos)) {
126      while ($metaperso = pwg_db_fetch_assoc($metapersos)) {
127        $items = array(
128          'METANAME' => $metaperso['metaname'],
129          'METAVAL' => $metaperso['metaval'],
130          'METATYPE' => $metaperso['metatype']
131        );
132        $template->append('metapersos', $items);
133      }
134    }
135
136    $template->set_filename('PERSO_META', realpath(meta_PATH . 'persometa.tpl'));
137    $template->append('head_elements', $template->parse('PERSO_META', true));
138  }
139
140  if (isset($pwg_loaded_plugins['ContactForm'])){
141    global $conf;
142    if (isset($page['section']) and $page['section'] == 'contact' and isset($conf['contactmeta']) and strpos($conf['contactmeta'], ',') !== false){
143      $metacontact = explode(',', $conf['contactmeta']);
144      $metakeyED = trigger_change('AP_render_content', $metacontact[0]);
145      $metadesED = trigger_change('AP_render_content', $metacontact[1]);
146      if (!empty($metakeyED)){
147        $template->append('related_tags', array('name' => $metakeyED));
148      }
149      if (!empty($metadesED)){
150        $template->assign('PLUG_META', $metadesED);
151      }
152    }
153  }
154
155  if (isset($pwg_loaded_plugins['AdditionalPages'])){
156    if (!empty($page['additional_page']['id'])) {
157      $lire = $page['additional_page']['id'];
158      $query = 'SELECT id, metaKeyap, metadesap FROM ' . META_AP_TABLE . ' WHERE id = \'' . $lire . '\';';
159          $result = pwg_query($query);
160          $row = pwg_db_fetch_assoc($result);
161          $metaKeyapap = $row['metaKeyap'];
162          $metadesapap = $row['metadesap'];
163          $metaKeyapapED = trigger_change('AP_render_content', $metaKeyapap);
164          $metadesapED = trigger_change('AP_render_content', $metadesapap);
165    }
166        if (isset($page['section']) and $page['section'] == 'additional_page') {
167          if (!empty($metaKeyapapED)) {
168                $template->append('related_tags', array('name' => $metaKeyapapED));
169          }
170          if (!empty($metadesapED)) {
171                $template->assign('PLUG_META', $metadesapED);
172          }
173        }
174  }
175}
176
177function add_metacat() {
178  global $template, $page, $meta_infos;
179  if (!empty($page['category']['id'])) {
180    $query = 'SELECT id,metaKeycat,metadescat FROM ' . meta_cat_TABLE . ' WHERE id = \'' . $page['category']['id'] . '\';';
181        $result = pwg_query($query);
182        $row = pwg_db_fetch_assoc($result);
183        if (!empty($row['metaKeycat'])) {
184        $albumKeyED = trigger_change('AP_render_content', $row['metaKeycat']);
185          $template->append('related_tags', array('name' => $albumKeyED));
186        }
187        if (!empty($row['metadescat'])) {
188        $albumDesED = trigger_change('AP_render_content', $row['metadescat']);
189          $template->assign('PLUG_META', $albumDesED);
190        }
191  }
192}
193
194function add_metaimg(){
195  global $template, $page, $meta_infos;
196  if (!empty($page['image_id'])) {
197    $query = 'SELECT id,metaKeyimg,metadesimg FROM ' . meta_img_TABLE . ' WHERE id = \'' . $page['image_id'] . '\';';
198        $result = pwg_query($query);
199        $row = pwg_db_fetch_assoc($result);
200        if (!empty($row['metaKeyimg'])) {
201          $photoKeyED = trigger_change('AP_render_content', $row['metaKeyimg']);
202          $template->append('related_tags', array('name' => $photoKeyED));
203        }
204        if (!empty($row['metadesimg'])) {
205          $photoDesED = trigger_change('AP_render_content', $row['metadesimg']);
206          $template->assign('PLUG_META', $photoDesED);
207        }else{
208          $meta_infosph = array();
209          $meta_infosph['title'] = $template->get_template_vars('PAGE_TITLE');
210          $meta_infosph['gt'] = $template->get_template_vars('GALLERY_TITLE');
211          $meta_infosph['descimg'] = $template->get_template_vars('COMMENT_IMG');
212          if (!empty($meta_infosph['descimg'])) {
213                $template->assign('PLUG_META', strip_tags($meta_infosph['descimg']) . ' - ' . $meta_infosph['title']);
214          }else{
215                $template->assign('PLUG_META', $meta_infosph['title'] . ' - ' . $meta_infosph['gt']);
216          }
217        }
218  }
219}
220
221function set_meta_back(){
222  global $template, $meta_infos;
223  $template->assign(
224    array(
225      'INFO_AUTHOR' => $meta_infos['author'],
226      'related_tags' => $meta_infos['related_tags'],
227      'INFO_FILE' => $meta_infos['info'],
228    )
229   );
230}
231
232//adminmenu
233add_event_handler('tabsheet_before_select', 'metaalbum_tabsheet_before_select', EVENT_HANDLER_PRIORITY_NEUTRAL, 2);
234function metaalbum_tabsheet_before_select($sheets, $id){
235 if ($id == 'album'){
236        $sheets['metaalbum'] = array(
237     'caption' => '<span class="icon-file-code"></span>'.l10n('Meta'),
238     'url' => get_root_url().'admin.php?page=plugin-meta-album&amp;cat_id='.$_GET['cat_id'],
239    );
240  }
241  return $sheets;
242}
243
244?>
Note: See TracBrowser for help on using the repository browser.