OSDN Git Service

merged from v3.31sp1
[nucleus-jp/nucleus-jp-ancient.git] / utf8 / nucleus / libs / BODYACTIONS.php
1 <?php
2
3 /*
4  * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
5  * Copyright (C) 2002-2007 The Nucleus Group
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  * (see nucleus/documentation/index.html#license for more info)
12  */
13 /**
14  * A class to parses plugin calls inside items
15  *
16  * @license http://nucleuscms.org/license.txt GNU General Public License
17  * @copyright Copyright (C) 2002-2007 The Nucleus Group
18  * @version $Id: BODYACTIONS.php,v 1.7 2008-02-08 09:31:22 kimitake Exp $
19  * @version $NucleusJP: BODYACTIONS.php,v 1.6.2.1 2007/08/08 05:27:14 kimitake Exp $
20  */
21
22 class BODYACTIONS extends BaseActions {
23
24         var $currentItem;
25
26         var $template;
27
28         function BODYACTIONS () {
29                 $this->BaseActions();   
30         }
31         
32         function setCurrentItem(&$item) {
33                 $this->currentItem =& $item;
34         }
35         
36         function setTemplate($template) {
37                 $this->template =& $template;
38         }
39
40         function getDefinedActions() {
41                 return array('image', 'media', 'popup', 'plugin');
42         }
43
44         function parse_plugin($pluginName) {
45                 global $manager;
46
47                 // only continue when the plugin is really installed
48                 if (!$manager->pluginInstalled('NP_' . $pluginName)) {
49                         return;
50                 }
51
52                 $plugin =& $manager->getPlugin('NP_' . $pluginName);
53                 if (!$plugin) return;
54
55                 // get arguments
56                 $params = func_get_args();
57
58                 // remove plugin name
59                 array_shift($params);
60
61                 // add item reference (array_unshift didn't work)
62                 $params = array_merge(array(&$this->currentItem),$params);
63
64                 call_user_func_array(array(&$plugin,'doItemVar'), $params);
65         }
66         
67         function parse_image() {
68                 // image/popup calls have arguments separated by |
69                 $args = func_get_args();
70                 $args = explode('|',implode($args,', '));
71                 call_user_func_array(array(&$this,'createImageCode'),$args);
72         }
73         
74         function createImageCode($filename, $width, $height, $text = '') {
75                 global $CONF;
76
77                 // select private collection when no collection given
78                 if (!strstr($filename,'/')) {
79                         $filename = $this->currentItem->authorid . '/' . $filename;
80                 }
81
82                 $windowwidth = $width;
83                 $windowheight = $height;
84
85                 $vars['link']                   = htmlspecialchars($CONF['MediaURL']. $filename ,ENT_QUOTES);
86                 $vars['text']                   = htmlspecialchars($text ,ENT_QUOTES);
87                 $vars['image'] = '<img src="' . $vars['link'] . '" width="' . $width . '" height="' . $height . '" alt="' . $vars['text'] . '" title="' . $vars['text'] . '" />';
88                 $vars['width']                  = $width;
89                 $vars['height']                 = $height;
90                 $vars['media']                  = '<a href="' . $vars['link'] . '">' . $vars['text'] . '</a>';
91
92
93                 echo TEMPLATE::fill($this->template['IMAGE_CODE'],$vars);;
94
95         }
96         
97         function parse_media() {
98                 // image/popup calls have arguments separated by |
99                 $args = func_get_args();
100                 $args = explode('|',implode($args,', '));
101                 call_user_func_array(array(&$this,'createMediaCode'),$args);
102         }
103
104         function createMediaCode($filename, $text = '') {
105                 global $CONF;
106
107                 // select private collection when no collection given
108                 if (!strstr($filename,'/')) {
109                         $filename = $this->currentItem->authorid . '/' . $filename;
110                 }
111
112                 $vars['link']                   = htmlspecialchars($CONF['MediaURL'] . $filename ,ENT_QUOTES);
113                 $vars['text']                   = htmlspecialchars($text ,ENT_QUOTES);
114                 $vars['media']                  = '<a href="' . $vars['link'] . '">' . $vars['text'] . '</a>';
115
116                 echo TEMPLATE::fill($this->template['MEDIA_CODE'],$vars);;
117         }
118
119
120         function parse_popup() {
121                 // image/popup calls have arguments separated by |
122                 $args = func_get_args();
123                 $args = explode('|',implode($args,', '));
124                 call_user_func_array(array(&$this,'createPopupCode'),$args);
125         }
126
127         function createPopupCode($filename, $width, $height, $text = '') {
128                 global $CONF;
129
130                 // select private collection when no collection given
131                 if (!strstr($filename,'/')) {
132                         $filename = $this->currentItem->authorid . '/' . $filename;
133                 }
134
135                 $windowwidth = $width;
136                 $windowheight = $height;
137
138                 $vars['rawpopuplink']   = $CONF['Self'] . "?imagepopup=" . htmlspecialchars($filename,ENT_QUOTES) . "&amp;width=$width&amp;height=$height&amp;imagetext=" . urlencode(htmlspecialchars($text));
139                 $vars['popupcode']              = "window.open(this.href,'imagepopup','status=no,toolbar=no,scrollbars=no,resizable=yes,width=$windowwidth,height=$windowheight');return false;";
140                 $vars['popuptext']              = htmlspecialchars($text,ENT_QUOTES);
141                 $vars['popuplink']              = '<a href="' . $vars['rawpopuplink']. '" onclick="'. $vars['popupcode'].'" >' . $vars['popuptext'] . '</a>';
142                 $vars['width']                  = $width;
143                 $vars['height']                 = $height;
144                 $vars['text']                   = $text;
145                 $vars['link']                   = htmlspecialchars($CONF['MediaURL'] . $filename ,ENT_QUOTES);
146                 $vars['media']                  = '<a href="' . $vars['link'] . '">' . $vars['popuptext'] . '</a>';
147
148                 echo TEMPLATE::fill($this->template['POPUP_CODE'],$vars);
149         }
150
151 }
152 ?>