source: extensions/metasimple/main.inc.php @ 28566

Last change on this file since 28566 was 7675, checked in by ddtddt, 13 years ago

[extensions] - metasimple - bug Undefined variable: meta_infos - Thanks nighthawk

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 3.4 KB
Line 
1<?php
2/*
3Plugin Name: metasimple
4Version: auto
5Description: Replaces the entire contents of the metadata "description" with the category description or pictures if any. Ability to customize the description of the home page
6Plugin URI: http://piwigo.org/ext/extension_view.php?eid=456
7Author: ddtddt
8Author URI: http://piwigo.org/
9*/
10
11if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
12
13global $prefixeTable;
14
15define('metasimple_DIR' , basename(dirname(__FILE__)));
16define('metasimple_PATH' , PHPWG_PLUGINS_PATH . metasimple_DIR . '/');
17
18
19add_event_handler('loc_begin_page_header', 'Change_Metasimple',10 );
20add_event_handler('loc_end_page_header', 'add_metasimple',53);
21add_event_handler('loc_end_page_header', 'add_metadescacc',55);
22add_event_handler('loc_end_page_header', 'add_metadesccat',60);
23add_event_handler('loc_end_page_header', 'add_metadescimg',70);
24add_event_handler('loc_after_page_header', 'set_metadesc_back',80);
25
26function Change_Metasimple()
27 {
28        global $template;
29        $template->set_prefilter('header', 'upmatasimple');
30 }
31
32function upmatasimple ($content, &$smarty)
33 {
34  $search = '#<meta name="description" content=".*?">#';
35 
36  $replacement = '<meta name="description" content="{$PLUG_META}">';
37
38  return preg_replace($search, $replacement, $content);
39 }
40
41function add_metasimple()
42  //meta homepage
43        {
44                global $template, $page, $meta_infosdesc, $conf;
45        $meta_infosdesc = array();
46        $meta_infosdesc['info'] = $template->get_template_vars('INFO_FILE');
47        $meta_infosdesc['page'] = $template->get_template_vars('PAGE_TITLE');
48        $meta_infosdesc['comment'] = $template->get_template_vars('COMMENT_IMG');
49        $meta_infosdesc['title'] = $template->get_template_vars('PAGE_TITLE');
50         
51       
52        if (!empty($meta_infosdesc['title']) and !empty($meta_infosdesc['info']))
53        {
54    $template->assign('PLUG_META', $meta_infosdesc['title']. ' - ' .$meta_infosdesc['info']);
55        }
56        elseif (!empty($meta_infosdesc['title']))
57        {
58    $template->assign('PLUG_META', $meta_infosdesc['title']);
59
60        }
61        }
62
63function add_metadescacc()
64  //meta homepage
65        {
66                global $template, $page, $meta_infosdesc, $conf;
67         
68         if (isset($page['section']) and $page['section'] == 'categories' and empty($page['category']['id']))
69                {
70                        $descindex = & $conf['metasimple'];             
71                        if (!empty($descindex))
72                                {
73                                        $template->assign('PLUG_META', $descindex);
74                                }
75                        else
76                        {
77                                $template->assign('PLUG_META', $meta_infosdesc['title']);
78                        }
79                }
80        }
81
82function add_metadesccat()
83  //meta albums
84        {
85                global $template, $page, $meta_infosdesc;
86
87                          if ( !empty($page['category']['id']) )   
88                                {
89    $query = '
90    select id,comment
91      FROM ' . CATEGORIES_TABLE . '
92      WHERE id = \''.$page['category']['id'].'\'
93      ;';
94    $result = pwg_query($query);
95    $row = mysql_fetch_array($result);
96                if (!empty($row['comment']))
97                        {
98                                $template->assign('PLUG_META', $row['comment']);
99                        }
100                                }
101        }
102
103function add_metadescimg()
104  //meta photos
105        {
106                global $template, $page, $meta_infosdesc;
107                          if ( !empty($page['image_id']) )   
108                                {
109    $query = '
110    select id,comment
111      FROM ' . IMAGES_TABLE . '
112      WHERE id = \''.$page['image_id'].'\'
113      ;';
114    $result = pwg_query($query);
115    $row = mysql_fetch_array($result);
116                if (!empty($row['comment']))
117                        {
118                                $template->assign('PLUG_META', $row['comment']);
119                        }
120                                }
121        }
122
123function set_metadesc_back()
124        {
125                global $template, $meta_infosdesc;
126 
127                $template->assign
128                        (array
129                                (
130                'INFO_FILE'    => $meta_infosdesc['info'],
131                'COMMENT_IMG'    => $meta_infosdesc['comment']
132                                )
133                        );
134        }
135?>
Note: See TracBrowser for help on using the repository browser.