XpressEngine Core  1.11.2
 All Classes Namespaces Files Functions Variables Pages
widget.model.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) NAVER <http://www.navercorp.com> */
9 class widgetModel extends widget
10 {
14  function init()
15  {
16  }
17 
21  function getWidgetPath($widget_name)
22  {
23  $path = sprintf('./widgets/%s/', $widget_name);
24  if(is_dir($path)) return $path;
25 
26  return "";
27  }
28 
32  function getWidgetStylePath($widgetStyle_name)
33  {
34  $path = sprintf('./widgetstyles/%s/', $widgetStyle_name);
35  if(is_dir($path)) return $path;
36 
37  return "";
38  }
39 
43  function getWidgetStyleTpl($widgetStyle_name)
44  {
45  $path = $this->getWidgetStylePath($widgetStyle_name);
46  $tpl = sprintf('%swidgetstyle.html', $path);
47  return $tpl;
48  }
49 
55  {
56  $oAutoinstallModel = getModel('autoinstall');
57 
58  // 've Downloaded the widget and the widget's list of installed Wanted
59  $searched_list = FileHandler::readDir('./widgets');
60  $searched_count = count($searched_list);
61  if(!$searched_count) return;
62  sort($searched_list);
63  // D which pertain to the list of widgets loop spins return statement review the information you need
64  for($i=0;$i<$searched_count;$i++)
65  {
66  // The name of the widget
67  $widget = $searched_list[$i];
68  // Wanted information on the Widget
69  $widget_info = $this->getWidgetInfo($widget);
70 
71  if(!$widget_info)
72  {
73  $widget_info = new stdClass();
74  }
75 
76  // get easyinstall remove url
77  $packageSrl = $oAutoinstallModel->getPackageSrlByPath($widget_info->path);
78  $widget_info->remove_url = $oAutoinstallModel->getRemoveUrlByPackageSrl($packageSrl);
79 
80  // get easyinstall need update
81  $package = $oAutoinstallModel->getInstalledPackages($packageSrl);
82  $widget_info->need_update = $package[$packageSrl]->need_update;
83 
84  // get easyinstall update url
85  if ($widget_info->need_update == 'Y')
86  {
87  $widget_info->update_url = $oAutoinstallModel->getUpdateUrlByPackageSrl($packageSrl);
88  }
89 
90  $list[] = $widget_info;
91  }
92  return $list;
93  }
94 
100  {
101  // 've Downloaded the widget and the widget's list of installed Wanted
102  $searched_list = FileHandler::readDir('./widgetstyles');
103  $searched_count = count($searched_list);
104  if(!$searched_count) return;
105  sort($searched_list);
106  // D which pertain to the list of widgets loop spins return statement review the information you need
107  for($i=0;$i<$searched_count;$i++)
108  {
109  // The name of the widget
110  $widgetStyle = $searched_list[$i];
111  // Wanted information on the Widget
112  $widgetStyle_info = $this->getWidgetStyleInfo($widgetStyle);
113 
114  $list[] = $widgetStyle_info;
115  }
116  return $list;
117  }
118 
123  function getWidgetInfo($widget)
124  {
125  // Get a path of the requested module. Return if not exists.
126  $widget_path = $this->getWidgetPath($widget);
127  if(!$widget_path) return;
128  // Read the xml file for module skin information
129  $xml_file = sprintf("%sconf/info.xml", $widget_path);
130  if(!file_exists($xml_file)) return;
131  // If the problem by comparing the cache file and include the return variable $widget_info
132  $cache_file = sprintf(_XE_PATH_ . 'files/cache/widget/%s.%s.cache.php', $widget, Context::getLangType());
133 
134  if(file_exists($cache_file)&&filemtime($cache_file)>filemtime($xml_file))
135  {
136  @include($cache_file);
137  return $widget_info;
138  }
139  // If no cache file exists, parse the xml and then return the variable.
140  $oXmlParser = new XmlParser();
141  $tmp_xml_obj = $oXmlParser->loadXmlFile($xml_file);
142  $xml_obj = $tmp_xml_obj->widget;
143  if(!$xml_obj) return;
144 
145  $buff = '$widget_info = new stdClass;';
146 
147  if($xml_obj->version && $xml_obj->attrs->version == '0.2')
148  {
149  // Title of the widget, version
150  $buff .= sprintf('$widget_info->widget = "%s";', $widget);
151  $buff .= sprintf('$widget_info->path = "%s";', $widget_path);
152  $buff .= sprintf('$widget_info->title = "%s";', $xml_obj->title->body);
153  $buff .= sprintf('$widget_info->description = "%s";', $xml_obj->description->body);
154  $buff .= sprintf('$widget_info->version = "%s";', $xml_obj->version->body);
155  sscanf($xml_obj->date->body, '%d-%d-%d', $date_obj->y, $date_obj->m, $date_obj->d);
156  $date = sprintf('%04d%02d%02d', $date_obj->y, $date_obj->m, $date_obj->d);
157  $buff .= sprintf('$widget_info->date = "%s";', $date);
158  $buff .= sprintf('$widget_info->homepage = "%s";', $xml_obj->link->body);
159  $buff .= sprintf('$widget_info->license = "%s";', $xml_obj->license->body);
160  $buff .= sprintf('$widget_info->license_link = "%s";', $xml_obj->license->attrs->link);
161  $buff .= sprintf('$widget_info->widget_srl = $widget_srl;');
162  $buff .= sprintf('$widget_info->widget_title = $widget_title;');
163  // Author information
164  if(!is_array($xml_obj->author)) $author_list[] = $xml_obj->author;
165  else $author_list = $xml_obj->author;
166 
167  for($i=0; $i < count($author_list); $i++)
168  {
169  $buff .= '$widget_info->author['.$i.'] = new stdClass;';
170  $buff .= sprintf('$widget_info->author['.$i.']->name = "%s";', $author_list[$i]->name->body);
171  $buff .= sprintf('$widget_info->author['.$i.']->email_address = "%s";', $author_list[$i]->attrs->email_address);
172  $buff .= sprintf('$widget_info->author['.$i.']->homepage = "%s";', $author_list[$i]->attrs->link);
173  }
174  }
175  else
176  {
177  // Title of the widget, version
178  $buff .= sprintf('$widget_info->widget = "%s";', $widget);
179  $buff .= sprintf('$widget_info->path = "%s";', $widget_path);
180  $buff .= sprintf('$widget_info->title = "%s";', $xml_obj->title->body);
181  $buff .= sprintf('$widget_info->description = "%s";', $xml_obj->author->description->body);
182  $buff .= sprintf('$widget_info->version = "%s";', $xml_obj->attrs->version);
183  sscanf($xml_obj->author->attrs->date, '%d. %d. %d', $date_obj->y, $date_obj->m, $date_obj->d);
184  $date = sprintf('%04d%02d%02d', $date_obj->y, $date_obj->m, $date_obj->d);
185  $buff .= sprintf('$widget_info->date = "%s";', $date);
186  $buff .= sprintf('$widget_info->widget_srl = $widget_srl;');
187  $buff .= sprintf('$widget_info->widget_title = $widget_title;');
188  // Author information
189  $buff .= '$widget_info->author[0] = new stdClass;';
190  $buff .= sprintf('$widget_info->author[0]->name = "%s";', $xml_obj->author->name->body);
191  $buff .= sprintf('$widget_info->author[0]->email_address = "%s";', $xml_obj->author->attrs->email_address);
192  $buff .= sprintf('$widget_info->author[0]->homepage = "%s";', $xml_obj->author->attrs->link);
193  }
194  // Extra vars (user defined variables to use in a template)
195  $extra_var_groups = $xml_obj->extra_vars->group;
196  if(!$extra_var_groups) $extra_var_groups = $xml_obj->extra_vars;
197  if(!is_array($extra_var_groups)) $extra_var_groups = array($extra_var_groups);
198  foreach($extra_var_groups as $group)
199  {
200  $extra_vars = $group->var;
201  if(!is_array($group->var)) $extra_vars = array($group->var);
202 
203  if($extra_vars[0]->attrs->id || $extra_vars[0]->attrs->name)
204  {
205  $extra_var_count = count($extra_vars);
206 
207  $buff .= sprintf('$widget_info->extra_var_count = "%s";', $extra_var_count);
208  for($i=0;$i<$extra_var_count;$i++)
209  {
210  unset($var);
211  unset($options);
212  $var = $extra_vars[$i];
213 
214  $id = $var->attrs->id?$var->attrs->id:$var->attrs->name;
215  $name = $var->name->body?$var->name->body:$var->title->body;
216  $type = $var->attrs->type?$var->attrs->type:$var->type->body;
217  $buff .= sprintf('$widget_info->extra_var->%s = new stdClass;', $id);
218  if($type =='filebox')
219  {
220  $buff .= sprintf('$widget_info->extra_var->%s->filter = "%s";', $id, $var->type->attrs->filter);
221  $buff .= sprintf('$widget_info->extra_var->%s->allow_multiple = "%s";', $id, $var->type->attrs->allow_multiple);
222  }
223 
224  $buff .= sprintf('$widget_info->extra_var->%s->group = "%s";', $id, $group->title->body);
225  $buff .= sprintf('$widget_info->extra_var->%s->name = "%s";', $id, $name);
226  $buff .= sprintf('$widget_info->extra_var->%s->type = "%s";', $id, $type);
227  $buff .= sprintf('$widget_info->extra_var->%s->value = $vars->%s;', $id, $id);
228  $buff .= sprintf('$widget_info->extra_var->%s->description = "%s";', $id, str_replace('"','\"',$var->description->body));
229 
230  $options = $var->options;
231  if(!$options) continue;
232 
233  if(!is_array($options)) $options = array($options);
234  $options_count = count($options);
235  for($j=0;$j<$options_count;$j++)
236  {
237  $buff .= sprintf('$widget_info->extra_var->%s->options["%s"] = "%s";', $id, $options[$j]->value->body, $options[$j]->name->body);
238 
239  if($options[$j]->attrs->default && $options[$j]->attrs->default=='true')
240  {
241  $buff .= sprintf('$widget_info->extra_var->%s->default_options["%s"] = true;', $id, $options[$j]->value->body);
242  }
243 
244  if($options[$j]->attrs->init && $options[$j]->attrs->init=='true')
245  {
246  $buff .= sprintf('$widget_info->extra_var->%s->init_options["%s"] = true;', $id, $options[$j]->value->body);
247  }
248  }
249  }
250  }
251  }
252 
253  $buff = '<?php if(!defined("__XE__")) exit(); '.$buff.' ?>';
254  FileHandler::writeFile($cache_file, $buff);
255 
256  if(file_exists($cache_file)) @include($cache_file);
257  return $widget_info;
258  }
259 
264  function getWidgetStyleInfo($widgetStyle)
265  {
266  $widgetStyle_path = $this->getWidgetStylePath($widgetStyle);
267  if(!$widgetStyle_path) return;
268  $xml_file = sprintf("%sskin.xml", $widgetStyle_path);
269  if(!file_exists($xml_file)) return;
270  // If the problem by comparing the cache file and include the return variable $widgetStyle_info
271  $cache_file = sprintf(_XE_PATH_ . 'files/cache/widgetstyles/%s.%s.cache.php', $widgetStyle, Context::getLangType());
272 
273  if(file_exists($cache_file)&&filemtime($cache_file)>filemtime($xml_file))
274  {
275  @include($cache_file);
276  return $widgetStyle_info;
277  }
278  // If no cache file exists, parse the xml and then return the variable.
279  $oXmlParser = new XmlParser();
280  $tmp_xml_obj = $oXmlParser->loadXmlFile($xml_file);
281  $xml_obj = $tmp_xml_obj->widgetstyle;
282  if(!$xml_obj) return;
283 
284  $buff = array();
285  $buff[] = '<?php if(!defined("__XE__")) exit();';
286  $buff[] = '$widgetStyle_info = new stdClass();';
287 
288  // Title of the widget, version
289  $buff[] = sprintf('$widgetStyle_info->widgetStyle = "%s";', $widgetStyle);
290  $buff[] = sprintf('$widgetStyle_info->path = "%s";', $widgetStyle_path);
291  $buff[] = sprintf('$widgetStyle_info->title = "%s";', $xml_obj->title->body);
292  $buff[] = sprintf('$widgetStyle_info->description = "%s";', $xml_obj->description->body);
293  $buff[] = sprintf('$widgetStyle_info->version = "%s";', $xml_obj->version->body);
294  sscanf($xml_obj->date->body, '%d-%d-%d', $date_obj->y, $date_obj->m, $date_obj->d);
295  $date = sprintf('%04d%02d%02d', $date_obj->y, $date_obj->m, $date_obj->d);
296  $buff[] = sprintf('$widgetStyle_info->date = "%s";', $date);
297  $buff[] = sprintf('$widgetStyle_info->homepage = "%s";', $xml_obj->link->body);
298  $buff[] = sprintf('$widgetStyle_info->license = "%s";', $xml_obj->license->body);
299  $buff[] = sprintf('$widgetStyle_info->license_link = "%s";', $xml_obj->license->attrs->link);
300 
301  // preview
302  if(!$xml_obj->preview->body) $xml_obj->preview->body = 'preview.jpg';
303  $preview_file = sprintf("%s%s", $widgetStyle_path,$xml_obj->preview->body);
304  if(file_exists($preview_file)) $buff[] = sprintf('$widgetStyle_info->preview = "%s";', $preview_file);
305 
306  // Author information
307  if(!is_array($xml_obj->author)) $author_list[] = $xml_obj->author;
308  else $author_list = $xml_obj->author;
309 
310  foreach($author_list as $idx => $author)
311  {
312  $buff[] = sprintf('$widgetStyle_info->author[%d] = new stdClass();', $idx);
313  $buff[] = sprintf('$widgetStyle_info->author[%d]->name = "%s";', $idx, $author->name->body);
314  $buff[] = sprintf('$widgetStyle_info->author[%d]->email_address = "%s";', $idx, $author->attrs->email_address);
315  $buff[] = sprintf('$widgetStyle_info->author[%d]->homepage = "%s";', $idx, $author->attrs->link);
316  }
317 
318  // Extra vars (user defined variables to use in a template)
319  $extra_var_groups = $xml_obj->extra_vars->group;
320  if(!$extra_var_groups) $extra_var_groups = $xml_obj->extra_vars;
321  if(!is_array($extra_var_groups)) $extra_var_groups = array($extra_var_groups);
322 
323  $extra_var_count = 0;
324  $buff[] = sprintf('$widgetStyle_info->extra_var = new stdClass();', $extra_var_count);
325  foreach($extra_var_groups as $group)
326  {
327  $extra_vars = (!is_array($group->var)) ? array($group->var) : $group->var;
328 
329  if($extra_vars[0]->attrs->id || $extra_vars[0]->attrs->name)
330  {
331  foreach($extra_vars as $var)
332  {
333  $extra_var_count++;
334  $id = ($var->attrs->id) ? $var->attrs->id : $var->attrs->name;
335  $name = ($var->name->body) ? $var->name->body : $var->title->body;
336  $type = ($var->attrs->type) ? $var->attrs->type : $var->type->body;
337 
338  $buff[] = sprintf('$widgetStyle_info->extra_var->%s = new stdClass();', $id);
339  $buff[] = sprintf('$widgetStyle_info->extra_var->%s->group = "%s";', $id, $group->title->body);
340  $buff[] = sprintf('$widgetStyle_info->extra_var->%s->name = "%s";', $id, $name);
341  $buff[] = sprintf('$widgetStyle_info->extra_var->%s->type = "%s";', $id, $type);
342  if($type =='filebox')
343  {
344  $buff[] = sprintf('$widgetStyle_info->extra_var->%s->filter = "%s";', $id, $var->attrs->filter);
345  $buff[] = sprintf('$widgetStyle_info->extra_var->%s->allow_multiple = "%s";', $id, $var->attrs->allow_multiple);
346  }
347  $buff[] = sprintf('$widgetStyle_info->extra_var->%s->value = $vars->%s;', $id, $id);
348  $buff[] = sprintf('$widgetStyle_info->extra_var->%s->description = "%s";', $id, str_replace('"','\"',$var->description->body));
349 
350  if($var->options)
351  {
352  $var_options = (!is_array($var->options)) ? array($var->options) : $var->options;
353  foreach($var_options as $option_item)
354  {
355  $buff[] = sprintf('$widgetStyle_info->extra_var->%s->options["%s"] = "%s";', $id, $option_item->value->body, $option_item->name->body);
356  }
357  }
358  }
359  }
360  }
361  $buff[] = sprintf('$widgetStyle_info->extra_var_count = %d;', $extra_var_count);
362 
363  FileHandler::writeFile($cache_file, implode(PHP_EOL, $buff));
364 
365  if(file_exists($cache_file)) @include($cache_file);
366 
367  return $widgetStyle_info;
368  }
369 }
370 /* End of file widget.model.php */
371 /* Location: ./modules/widget/widget.model.php */
foreach($sitemap as $id=> &$val) $extra_vars
Definition: ko.install.php:180
writeFile($filename, $buff, $mode="w")
getWidgetStyleInfo($widgetStyle)
Modules conf/info.xml wanted to read the information It uses caching to reduce time for xml parsing ...
getWidgetPath($widget_name)
Wanted widget&#39;s path.
widget module&#39;s high class
Definition: widget.class.php:8
getWidgetStyleTpl($widgetStyle_name)
Wanted widget style path.
getWidgetStylePath($widgetStyle_name)
Wanted widget style path.
getDownloadedWidgetStyleList()
Wanted photos of the type and information Download a widget with type (generation and other means) ...
Model class for widget modules.
Definition: widget.model.php:9
init()
Initialization.
const _XE_PATH_
Definition: config.inc.php:49
getModel($module_name)
Definition: func.inc.php:145
getWidgetInfo($widget)
Modules conf/info.xml wanted to read the information It uses caching to reduce time for xml parsing ...
readDir($path, $filter= '', $to_lower=FALSE, $concat_prefix=FALSE)
getDownloadedWidgetList()
Wanted photos of the type and information Download a widget with type (generation and other means) ...