OSDN Git Service

git-svn-id: https://svn.sourceforge.jp/svnroot/nucleus-jp/nucleus-jp/trunk@967 1ca29b...
[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-2009 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-2009 The Nucleus Group
18  * @version $Id$
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                 // should be already tested from the parser (PARSER.php)\r
48                 // only continue when the plugin is really installed\r
49                 /*if (!$manager->pluginInstalled('NP_' . $pluginName)) {\r
50                         return;\r
51                 }*/\r
52
53                 $plugin =& $manager->getPlugin('NP_' . $pluginName);
54                 if (!$plugin) return;
55
56                 // get arguments
57                 $params = func_get_args();
58
59                 // remove plugin name
60                 array_shift($params);
61
62                 // add item reference (array_unshift didn't work)
63                 $params = array_merge(array(&$this->currentItem),$params);
64
65                 call_user_func_array(array(&$plugin,'doItemVar'), $params);
66         }
67         
68         function parse_image() {
69                 // image/popup calls have arguments separated by |
70                 $args = func_get_args();
71                 $args = explode('|',implode($args,', '));
72                 call_user_func_array(array(&$this,'createImageCode'),$args);
73         }
74         
75         function createImageCode($filename, $width, $height, $text = '') {
76                 global $CONF;
77
78                 // select private collection when no collection given
79                 if (!strstr($filename,'/')) {
80                         $filename = $this->currentItem->authorid . '/' . $filename;
81                 }
82
83                 $windowwidth = $width;
84                 $windowheight = $height;
85
86                 $vars['link']                   = htmlspecialchars($CONF['MediaURL']. $filename ,ENT_QUOTES);
87                 $vars['text']                   = htmlspecialchars($text ,ENT_QUOTES);
88                 $vars['image'] = '<img src="' . $vars['link'] . '" width="' . $width . '" height="' . $height . '" alt="' . $vars['text'] . '" title="' . $vars['text'] . '" />';
89                 $vars['width']                  = $width;
90                 $vars['height']                 = $height;
91                 $vars['media']                  = '<a href="' . $vars['link'] . '">' . $vars['text'] . '</a>';
92
93
94                 echo TEMPLATE::fill($this->template['IMAGE_CODE'],$vars);;
95
96         }
97         
98         function parse_media() {
99                 // image/popup calls have arguments separated by |
100                 $args = func_get_args();
101                 $args = explode('|',implode($args,', '));
102                 call_user_func_array(array(&$this,'createMediaCode'),$args);
103         }
104
105         function createMediaCode($filename, $text = '') {
106                 global $CONF;
107
108                 // select private collection when no collection given
109                 if (!strstr($filename,'/')) {
110                         $filename = $this->currentItem->authorid . '/' . $filename;
111                 }
112
113                 $vars['link']                   = htmlspecialchars($CONF['MediaURL'] . $filename ,ENT_QUOTES);
114                 $vars['text']                   = htmlspecialchars($text ,ENT_QUOTES);
115                 $vars['media']                  = '<a href="' . $vars['link'] . '">' . $vars['text'] . '</a>';
116
117                 echo TEMPLATE::fill($this->template['MEDIA_CODE'],$vars);;
118         }
119
120
121         function parse_popup() {
122                 // image/popup calls have arguments separated by |
123                 $args = func_get_args();
124                 $args = explode('|',implode($args,', '));
125                 call_user_func_array(array(&$this,'createPopupCode'),$args);
126         }
127
128         function createPopupCode($filename, $width, $height, $text = '') {
129                 global $CONF;
130
131                 // select private collection when no collection given
132                 if (!strstr($filename,'/')) {
133                         $filename = $this->currentItem->authorid . '/' . $filename;
134                 }
135
136                 $windowwidth = $width;
137                 $windowheight = $height;
138
139                 $vars['rawpopuplink']   = $CONF['Self'] . "?imagepopup=" . htmlspecialchars($filename,ENT_QUOTES) . "&amp;width=$width&amp;height=$height&amp;imagetext=" . urlencode(htmlspecialchars($text));
140                 $vars['popupcode']              = "window.open(this.href,'imagepopup','status=no,toolbar=no,scrollbars=no,resizable=yes,width=$windowwidth,height=$windowheight');return false;";
141                 $vars['popuptext']              = htmlspecialchars($text,ENT_QUOTES);
142                 $vars['popuplink']              = '<a href="' . $vars['rawpopuplink']. '" onclick="'. $vars['popupcode'].'" >' . $vars['popuptext'] . '</a>';
143                 $vars['width']                  = $width;
144                 $vars['height']                 = $height;
145                 $vars['text']                   = $text;
146                 $vars['link']                   = htmlspecialchars($CONF['MediaURL'] . $filename ,ENT_QUOTES);
147                 $vars['media']                  = '<a href="' . $vars['link'] . '">' . $vars['popuptext'] . '</a>';
148
149                 echo TEMPLATE::fill($this->template['POPUP_CODE'],$vars);
150         }
151
152 }
153 ?>