1 | <?php |
---|
2 | //pAnchor plugin code |
---|
3 | if (!defined('PHPWG_ROOT_PATH') or !defined('PANCHOR_DIR')) die('Hacking attempt!'); |
---|
4 | |
---|
5 | function pAnchor_links($content) { |
---|
6 | //iterate thru navigation links and append #<PANCHOR_NAME> to URL string variable |
---|
7 | global $template; |
---|
8 | |
---|
9 | //picture nav buttons |
---|
10 | $links = array('first','previous','next','last'); |
---|
11 | $tags = array('U_IMG'); |
---|
12 | foreach ($links as $link) { |
---|
13 | $temp = $template->get_template_vars($link); |
---|
14 | foreach ($tags as $tag) { |
---|
15 | if (isset($temp[$tag])) { |
---|
16 | $temp[$tag] .= '#'.PANCHOR_NAME; |
---|
17 | $template->assign($link, $temp); |
---|
18 | } |
---|
19 | } |
---|
20 | } |
---|
21 | |
---|
22 | //slideshow nav buttons |
---|
23 | $links = array('slideshow'); |
---|
24 | $tags = array('U_START_PLAY', 'U_STOP_PLAY', 'U_START_REPEAT', 'U_STOP_REPEAT', 'U_DEC_PERIOD', 'U_INC_PERIOD'); |
---|
25 | foreach ($links as $link) { |
---|
26 | $temp = $template->get_template_vars($link); |
---|
27 | foreach ($tags as $tag) { |
---|
28 | if (isset($temp[$tag])) { |
---|
29 | $temp[$tag] .= '#'.PANCHOR_NAME; |
---|
30 | $template->assign($link, $temp); |
---|
31 | } |
---|
32 | } |
---|
33 | } |
---|
34 | |
---|
35 | //start slideshow nav button |
---|
36 | $temp = $template->get_template_vars('U_SLIDESHOW_START'); |
---|
37 | if (isset($temp)) { |
---|
38 | $temp .= '#'.PANCHOR_NAME; |
---|
39 | $template->assign('U_SLIDESHOW_START', $temp); |
---|
40 | } |
---|
41 | //stop slideshow nav button |
---|
42 | $temp = $template->get_template_vars('U_SLIDESHOW_STOP'); |
---|
43 | if (isset($temp)) { |
---|
44 | $temp .= '#'.PANCHOR_NAME; |
---|
45 | $template->assign('U_SLIDESHOW_STOP', $temp); |
---|
46 | } |
---|
47 | |
---|
48 | //assign anchor name to template var |
---|
49 | $template->assign('PANCHOR_NAME', PANCHOR_NAME); |
---|
50 | return $content; |
---|
51 | } //end function pAnchor_links |
---|
52 | |
---|
53 | function pAnchor_picture_prefilter($content, &$smarty) { |
---|
54 | //add the HTML page anchor tag into picture template via search string |
---|
55 | global $template; |
---|
56 | |
---|
57 | $search = '#'.PANCHOR_PICTURE_SEARCH_TAG.'#'; |
---|
58 | $replacement = '<a id="pAnchor" name="{$PANCHOR_NAME}"></a>'.PANCHOR_PICTURE_SEARCH_TAG; |
---|
59 | return preg_replace($search, $replacement, $content); |
---|
60 | } |
---|
61 | |
---|
62 | function pAnchor_slideshow_prefilter($content, &$smarty) { |
---|
63 | //add the HTML page anchor tag into slideshow template via search string |
---|
64 | global $template; |
---|
65 | |
---|
66 | $search = '#'.PANCHOR_SLIDESHOW_SEARCH_TAG.'#'; |
---|
67 | $replacement = '<a id="pAnchor" name="{$PANCHOR_NAME}"></a>'.PANCHOR_SLIDESHOW_SEARCH_TAG; |
---|
68 | return preg_replace($search, $replacement, $content); |
---|
69 | } |
---|
70 | |
---|
71 | function pAnchor_add_anchor() { |
---|
72 | //setup add anchor prefilters for picture.tpl and slideshow.tpl |
---|
73 | global $template; |
---|
74 | $template->set_prefilter('picture', 'pAnchor_picture_prefilter'); |
---|
75 | $template->set_prefilter('slideshow', 'pAnchor_slideshow_prefilter'); |
---|
76 | |
---|
77 | } |
---|
78 | |
---|
79 | function pAnchor_adj_meta_refresh() { |
---|
80 | //adjust the <META refresh header element as this controls slideshow URL |
---|
81 | global $template, $page; |
---|
82 | |
---|
83 | $temp = $template->get_template_vars('page_refresh'); |
---|
84 | if (isset($temp['U_REFRESH'])) { |
---|
85 | $temp['U_REFRESH'] = $temp['U_REFRESH'].'#'.PANCHOR_NAME; |
---|
86 | $template->assign('page_refresh', $temp); |
---|
87 | } |
---|
88 | if (isset($page['slideshow'])) { |
---|
89 | if ($page['slideshow']) { |
---|
90 | //add CSS for pAnchor to document head |
---|
91 | $template->append('head_elements', PANCHOR_CSS_SLIDESHOW); |
---|
92 | //load js for pAnchor |
---|
93 | } else { |
---|
94 | //add CSS for pAnchor to document head |
---|
95 | $template->append('head_elements', PANCHOR_CSS_PICTURE); |
---|
96 | } |
---|
97 | } |
---|
98 | //experimental feature to auto ease scroll to pAnchor when navigating |
---|
99 | //to picture or slideshow from another page (that does not have # in url) |
---|
100 | if ( PANCHOR_EASE_ENABLE == true) { |
---|
101 | $template->append('head_elements', '<script src="'.get_root_url().PANCHOR_PATH.'pAnchor.js" type="text/javascript" charset="utf-8"></script>'); |
---|
102 | } |
---|
103 | } |
---|
104 | |
---|
105 | //do NOT add anchors on ADMIN side of piwigo |
---|
106 | if (!defined('IN_ADMIN')) { |
---|
107 | add_event_handler('render_element_content', 'pAnchor_links'); |
---|
108 | |
---|
109 | add_event_handler('loc_end_picture', 'pAnchor_add_anchor'); |
---|
110 | add_event_handler('loc_end_page_header', 'pAnchor_adj_meta_refresh'); |
---|
111 | } |
---|
112 | |
---|
113 | ?> |
---|