source: extensions/meta/main.inc.php @ 7532

Last change on this file since 7532 was 7518, checked in by ddtddt, 13 years ago

[extensions] - meta - update for priority / metasimple

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 5.0 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://piwigo.org/
9*/
10
11if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
12
13global $prefixeTable;
14
15define('meta_DIR' , basename(dirname(__FILE__)));
16define('meta_PATH' , PHPWG_PLUGINS_PATH . meta_DIR . '/');
17define('meta_TABLE' , $prefixeTable . 'meta');
18define('meta_img_TABLE' , $prefixeTable . 'meta_img');
19define('meta_cat_TABLE' , $prefixeTable . 'meta_cat');
20
21add_event_handler('get_admin_plugin_menu_links', 'meta_admin_menu');
22function meta_admin_menu($menu)
23{
24  array_push($menu, array(
25                'NAME' => 'Meta',
26    'URL' => get_admin_plugin_menu_link(meta_PATH . 'admin/admin.php')));
27  return $menu;
28}
29
30//Gestion des meta dans le header
31add_event_handler('loc_begin_page_header', 'add_meta',56 );
32add_event_handler('loc_begin_page_header', 'add_metacat',61 );
33add_event_handler('loc_begin_page_header', 'add_metaimg',71 );
34add_event_handler('loc_after_page_header', 'set_meta_back',81);
35
36function add_meta()
37{
38                global $template, $page, $meta_infos;
39        $meta_infos = array();
40        $meta_infos['author'] = $template->get_template_vars('INFO_AUTHOR');
41        $meta_infos['related_tags'] = $template->get_template_vars('related_tags');
42        $meta_infos['info'] = $template->get_template_vars('INFO_FILE');
43        $meta_infos['comment'] = $template->get_template_vars('COMMENT_IMG');
44
45        $query = '
46  select id,metaname,metaval
47    FROM ' . meta_TABLE . '
48    WHERE metaname IN (\'author\', \'keywords\', \'Description\', \'robots\')
49    ;';
50        $result = pwg_query($query);
51        $meta = array();
52                while ($row = mysql_fetch_assoc($result))
53                        {
54                        $meta[$row['metaname']] = $row['metaval'];
55                        }
56
57        // Authors
58        if (!empty($meta_infos['author']) and !empty($meta['author']))
59        {
60                $template->assign('INFO_AUTHOR', $meta_infos['author'] . ' - ' . $meta['author']);
61        }
62        elseif (!empty($meta['author']))
63        {
64    $template->assign('INFO_AUTHOR', $meta['author']);
65        }
66 
67        // Keywords
68        if (!empty($meta['keywords']))
69        {
70    $template->append('related_tags', array('name' => $meta['keywords']));
71        }
72
73        // Description
74        if (!empty($meta_infos['info']) and !empty($meta['Description']))
75        {
76    $template->assign('INFO_FILE', $meta_infos['info'] . ', ' . $meta['Description']);
77        }
78        elseif (!empty($meta['Description']))
79        {
80    $template->assign('INFO_FILE', $meta['Description']);
81        }
82
83        // Robots
84        if (!empty($meta['robots']))
85        {
86    $template->append('head_elements', '<meta name="robots" content="'.$meta['robots'].'">');
87        }
88
89 }
90function add_metacat()
91{
92        global $template, $page, $meta_infos;
93  $meta_infos = array();
94  $meta_infos['author'] = $template->get_template_vars('INFO_AUTHOR');
95  $meta_infos['related_tags'] = $template->get_template_vars('related_tags');
96  $meta_infos['info'] = $template->get_template_vars('INFO_FILE');
97  $meta_infos['comment'] = $template->get_template_vars('COMMENT_IMG');
98 
99
100        //meta categories
101  if ( !empty($page['category']['id']) )   
102  {
103    $query = '
104    select id,metaKeycat
105      FROM ' . meta_cat_TABLE . '
106      WHERE id = \''.$page['category']['id'].'\'
107      ;';
108    $result = pwg_query($query);
109    $row = mysql_fetch_array($result);
110    if (!empty($row['metaKeycat']))
111    {
112      $template->append('related_tags', array('name' => $row['metaKeycat']));
113    }
114       
115        $query = '
116    select id,metadescat
117      FROM ' . meta_cat_TABLE . '
118      WHERE id = \''.$page['category']['id'].'\'
119      ;';
120    $result = pwg_query($query);
121    $row = mysql_fetch_array($result);
122    if (!empty($row['metadescat']))
123    {
124      $template->assign('COMMENT_IMG', $row['metadescat']);
125          $template->clear_assign('INFO_FILE');
126    }
127  }
128}
129
130function add_metaimg()
131{
132        global $template, $page, $meta_infos;
133  $meta_infos = array();
134  $meta_infos['author'] = $template->get_template_vars('INFO_AUTHOR');
135  $meta_infos['related_tags'] = $template->get_template_vars('related_tags');
136  $meta_infos['info'] = $template->get_template_vars('INFO_FILE');
137  $meta_infos['comment'] = $template->get_template_vars('COMMENT_IMG');
138  //meta images
139  if ( !empty($page['image_id']) )   
140  {
141    $query = '
142    select id,metaKeyimg
143      FROM ' . meta_img_TABLE . '
144      WHERE id = \''.$page['image_id'].'\'
145      ;';
146    $result = pwg_query($query);
147    $row = mysql_fetch_array($result);
148    if (!empty($row['metaKeyimg']))
149    {
150      $template->append('related_tags', array('name' => $row['metaKeyimg']));
151    }
152
153                $query = '
154    select id,metadesimg
155      FROM ' . meta_img_TABLE . '
156      WHERE id = \''.$page['image_id'].'\'
157      ;';
158    $result = pwg_query($query);
159    $row = mysql_fetch_array($result);
160    if (!empty($row['metadesimg']))
161    {
162      $template->assign('COMMENT_IMG', $row['metadesimg']);
163          $template->clear_assign('INFO_FILE');
164    }
165       
166  }
167}
168
169
170function set_meta_back()
171{
172  global $template, $meta_infos;
173 
174  $template->assign
175  (array
176        (
177    'INFO_AUTHOR'  => $meta_infos['author'],
178    'related_tags' => $meta_infos['related_tags'],
179    'INFO_FILE'    => $meta_infos['info'],
180        'COMMENT_IMG'  => $meta_infos['comment']
181    )
182  );
183}
184?>
Note: See TracBrowser for help on using the repository browser.