XpressEngine Core  1.11.2
 All Classes Namespaces Files Functions Variables Pages
addon.admin.model.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) NAVER <http://www.navercorp.com> */
3 
8 class addonAdminModel extends addon
9 {
10 
16  function init()
17  {
18 
19  }
20 
27  function getAddonPath($addon_name)
28  {
29  $class_path = sprintf('./addons/%s/', $addon_name);
30  if(is_dir($class_path))
31  {
32  return $class_path;
33  }
34  return "";
35  }
36 
43  {
44  $addonList = $this->getAddonList(0, 'site');
45 
46  $oAutoinstallModel = getModel('autoinstall');
47  foreach($addonList as $key => $addon)
48  {
49  // get easyinstall remove url
50  $packageSrl = $oAutoinstallModel->getPackageSrlByPath($addon->path);
51  $addonList[$key]->remove_url = $oAutoinstallModel->getRemoveUrlByPackageSrl($packageSrl);
52 
53  // get easyinstall need update
54  $package = $oAutoinstallModel->getInstalledPackages($packageSrl);
55  $addonList[$key]->need_update = $package[$packageSrl]->need_update;
56 
57  // get easyinstall update url
58  if($addonList[$key]->need_update == 'Y')
59  {
60  $addonList[$key]->update_url = $oAutoinstallModel->getUpdateUrlByPackageSrl($packageSrl);
61  }
62  }
63 
64  return $addonList;
65  }
66 
74  function getAddonList($site_srl = 0, $gtype = 'site')
75  {
76  // Wanted to add a list of activated
77  $inserted_addons = $this->getInsertedAddons($site_srl, $gtype);
78  // Downloaded and installed add-on to the list of Wanted
79  $searched_list = FileHandler::readDir('./addons', '/^([a-zA-Z0-9-_]+)$/');
80  $searched_count = count($searched_list);
81  if(!$searched_count)
82  {
83  return;
84  }
85 
86  sort($searched_list);
87 
88  $oAddonAdminController = getAdminController('addon');
89 
90  for($i = 0; $i < $searched_count; $i++)
91  {
92  // Add the name of
93  $addon_name = $searched_list[$i];
94  if($addon_name == "smartphone")
95  {
96  continue;
97  }
98  // Add the path (files/addons precedence)
99  $path = $this->getAddonPath($addon_name);
100  // Wanted information on the add-on
101  $info = $this->getAddonInfoXml($addon_name, $site_srl, $gtype);
102 
103  if(!$info) $info = new stdClass();
104 
105  $info->addon = $addon_name;
106  $info->path = $path;
107  $info->activated = FALSE;
108  $info->mactivated = FALSE;
109  $info->fixed = FALSE;
110  // Check if a permossion is granted entered in DB
111  if(!in_array($addon_name, array_keys($inserted_addons)))
112  {
113  // If not, type in the DB type (model, perhaps because of the hate doing this haneungeo .. ㅡ. ㅜ)
114  $oAddonAdminController->doInsert($addon_name, $site_srl, $type);
115  // Is activated
116  }
117  else
118  {
119  if($inserted_addons[$addon_name]->is_used == 'Y')
120  {
121  $info->activated = TRUE;
122  }
123  if($inserted_addons[$addon_name]->is_used_m == 'Y')
124  {
125  $info->mactivated = TRUE;
126  }
127  if($gtype == 'global' && $inserted_addons[$addon_name]->is_fixed == 'Y')
128  {
129  $info->fixed = TRUE;
130  }
131  }
132 
133  $list[] = $info;
134  }
135  return $list;
136  }
137 
146  function getAddonInfoXml($addon, $site_srl = 0, $gtype = 'site')
147  {
148  // Get a path of the requested module. Return if not exists.
149  $addon_path = $this->getAddonPath($addon);
150  if(!$addon_path)
151  {
152  return;
153  }
154 
155  // Read the xml file for module skin information
156  $xml_file = sprintf("%sconf/info.xml", FileHandler::getRealpath($addon_path));
157  if(!file_exists($xml_file))
158  {
159  return;
160  }
161 
162  $oXmlParser = new XmlParser();
163  $tmp_xml_obj = $oXmlParser->loadXmlFile($xml_file);
164  $xml_obj = $tmp_xml_obj->addon;
165 
166  if(!$xml_obj)
167  {
168  return;
169  }
170 
171  // DB is set to bring history
172  $db_args = new stdClass();
173  $db_args->addon = $addon;
174  if($gtype == 'global')
175  {
176  $output = executeQuery('addon.getAddonInfo', $db_args);
177  }
178  else
179  {
180  $db_args->site_srl = $site_srl;
181  $output = executeQuery('addon.getSiteAddonInfo', $db_args);
182  }
183  $extra_vals = unserialize($output->data->extra_vars);
184 
185  $addon_info = new stdClass();
186  if($extra_vals->mid_list)
187  {
188  $addon_info->mid_list = $extra_vals->mid_list;
189  }
190  else
191  {
192  $addon_info->mid_list = array();
193  }
194 
195  if($extra_vals->xe_run_method)
196  {
197  $addon_info->xe_run_method = $extra_vals->xe_run_method;
198  }
199 
200  // Add information
201  if($xml_obj->version && $xml_obj->attrs->version == '0.2')
202  {
203  // addon format v0.2
204  $date_obj = new stdClass();
205  sscanf($xml_obj->date->body, '%d-%d-%d', $date_obj->y, $date_obj->m, $date_obj->d);
206  $addon_info->date = sprintf('%04d%02d%02d', $date_obj->y, $date_obj->m, $date_obj->d);
207 
208  $addon_info->addon_name = $addon;
209  $addon_info->title = $xml_obj->title->body;
210  $addon_info->description = trim($xml_obj->description->body);
211  $addon_info->version = $xml_obj->version->body;
212  $addon_info->homepage = $xml_obj->link->body;
213  $addon_info->license = $xml_obj->license->body;
214  $addon_info->license_link = $xml_obj->license->attrs->link;
215 
216  if(!is_array($xml_obj->author))
217  {
218  $author_list = array();
219  $author_list[] = $xml_obj->author;
220  }
221  else
222  {
223  $author_list = $xml_obj->author;
224  }
225 
226  $addon_info->author = array();
227  foreach($author_list as $author)
228  {
229  $author_obj = new stdClass();
230  $author_obj->name = $author->name->body;
231  $author_obj->email_address = $author->attrs->email_address;
232  $author_obj->homepage = $author->attrs->link;
233  $addon_info->author[] = $author_obj;
234  }
235 
236  // Expand the variable order
237  if($xml_obj->extra_vars)
238  {
239  $extra_var_groups = $xml_obj->extra_vars->group;
240  if(!$extra_var_groups)
241  {
242  $extra_var_groups = $xml_obj->extra_vars;
243  }
244  if(!is_array($extra_var_groups))
245  {
246  $extra_var_groups = array($extra_var_groups);
247  }
248 
249  foreach($extra_var_groups as $group)
250  {
251  $extra_vars = $group->var;
252  if(!is_array($group->var))
253  {
254  $extra_vars = array($group->var);
255  }
256 
257  foreach($extra_vars as $key => $val)
258  {
259  if(!$val)
260  {
261  continue;
262  }
263 
264  $obj = new stdClass();
265  if(!$val->attrs)
266  {
267  $val->attrs = new stdClass();
268  }
269  if(!$val->attrs->type)
270  {
271  $val->attrs->type = 'text';
272  }
273 
274  $obj->group = $group->title->body;
275  $obj->name = $val->attrs->name;
276  $obj->title = $val->title->body;
277  $obj->type = $val->attrs->type;
278  $obj->description = $val->description->body;
279  if($obj->name)
280  {
281  $obj->value = $extra_vals->{$obj->name};
282  }
283  if(strpos($obj->value, '|@|') != FALSE)
284  {
285  $obj->value = explode('|@|', $obj->value);
286  }
287  if($obj->type == 'mid_list' && !is_array($obj->value))
288  {
289  $obj->value = array($obj->value);
290  }
291 
292  // 'Select'type obtained from the option list.
293  if($val->options && !is_array($val->options))
294  {
295  $val->options = array($val->options);
296  }
297 
298  for($i = 0, $c = count($val->options); $i < $c; $i++)
299  {
300  $obj->options[$i] = new stdClass();
301  $obj->options[$i]->title = $val->options[$i]->title->body;
302  $obj->options[$i]->value = $val->options[$i]->attrs->value;
303  }
304 
305  $addon_info->extra_vars[] = $obj;
306  }
307  }
308  }
309  }
310  else
311  {
312  // addon format 0.1
313  $addon_info = new stdClass();
314  $addon_info->addon_name = $addon;
315  $addon_info->title = $xml_obj->title->body;
316  $addon_info->description = trim($xml_obj->author->description->body);
317  $addon_info->version = $xml_obj->attrs->version;
318 
319  $date_obj = new stdClass();
320  sscanf($xml_obj->author->attrs->date, '%d. %d. %d', $date_obj->y, $date_obj->m, $date_obj->d);
321  $addon_info->date = sprintf('%04d%02d%02d', $date_obj->y, $date_obj->m, $date_obj->d);
322 
323  $author_obj = new stdClass();
324  $author_obj->name = $xml_obj->author->name->body;
325  $author_obj->email_address = $xml_obj->author->attrs->email_address;
326  $author_obj->homepage = $xml_obj->author->attrs->link;
327 
328  $addon_info->author = array();
329  $addon_info->author[] = $author_obj;
330 
331  if($xml_obj->extra_vars)
332  {
333  // Expand the variable order
334  $extra_var_groups = $xml_obj->extra_vars->group;
335  if(!$extra_var_groups)
336  {
337  $extra_var_groups = $xml_obj->extra_vars;
338  }
339  if(!is_array($extra_var_groups))
340  {
341  $extra_var_groups = array($extra_var_groups);
342  }
343  foreach($extra_var_groups as $group)
344  {
345  $extra_vars = $group->var;
346  if(!is_array($group->var))
347  {
348  $extra_vars = array($group->var);
349  }
350 
351  $addon_info->extra_vars = array();
352  foreach($extra_vars as $key => $val)
353  {
354  if(!$val)
355  {
356  continue;
357  }
358 
359  $obj = new stdClass();
360 
361  $obj->group = $group->title->body;
362  $obj->name = $val->attrs->name;
363  $obj->title = $val->title->body;
364  $obj->type = $val->type->body ? $val->type->body : 'text';
365  $obj->description = $val->description->body;
366  if($obj->name)
367  {
368  $obj->value = $extra_vals->{$obj->name};
369  }
370  if(strpos($obj->value, '|@|') != false)
371  {
372  $obj->value = explode('|@|', $obj->value);
373  }
374  if($obj->type == 'mid_list' && !is_array($obj->value))
375  {
376  $obj->value = array($obj->value);
377  }
378  // 'Select'type obtained from the option list.
379  if($val->options && !is_array($val->options))
380  {
381  $val->options = array($val->options);
382  }
383 
384  $obj->options = array();
385  for($i = 0, $c = count($val->options); $i < $c; $i++)
386  {
387  $obj->options[$i]->title = $val->options[$i]->title->body;
388  $obj->options[$i]->value = $val->options[$i]->value->body;
389  }
390  $addon_info->extra_vars[] = $obj;
391  }
392  }
393  }
394  }
395  return $addon_info;
396  }
397 
405  function getInsertedAddons($site_srl = 0, $gtype = 'site')
406  {
407  $args = new stdClass();
408  $args->list_order = 'addon';
409  if($gtype == 'global')
410  {
411  $output = executeQueryArray('addon.getAddons', $args);
412  }
413  else
414  {
415  $args->site_srl = $site_srl;
416  $output = executeQueryArray('addon.getSiteAddons', $args);
417  }
418  if(!$output->data)
419  {
420  return array();
421  }
422 
423  $activated_count = count($output->data);
424  $addon_list = array();
425  for($i = 0; $i < $activated_count; $i++)
426  {
427  $addon = $output->data[$i];
428  $addon_list[$addon->addon] = $addon;
429  }
430  return $addon_list;
431  }
432 
442  function isActivatedAddon($addon, $site_srl = 0, $type = "pc", $gtype = 'site')
443  {
444  $args = new stdClass();
445  $args->addon = $addon;
446  if($gtype == 'global')
447  {
448  if($type == "pc")
449  {
450  $output = executeQuery('addon.getAddonIsActivated', $args);
451  }
452  else
453  {
454  $output = executeQuery('addon.getMAddonIsActivated', $args);
455  }
456  }
457  else
458  {
459  $args->site_srl = $site_srl;
460  if($type == "pc")
461  {
462  $output = executeQuery('addon.getSiteAddonIsActivated', $args);
463  }
464  else
465  {
466  $output = executeQuery('addon.getSiteMAddonIsActivated', $args);
467  }
468  }
469  if($output->data->count > 0)
470  {
471  return TRUE;
472  }
473  return FALSE;
474  }
475 
476 }
477 /* End of file addon.admin.model.php */
478 /* Location: ./modules/addon/addon.admin.model.php */
$obj
Definition: ko.install.php:262
$output
Definition: ko.install.php:193
foreach($sitemap as $id=> &$val) $extra_vars
Definition: ko.install.php:180
getAddonList($site_srl=0, $gtype= 'site')
getAddonInfoXml($addon, $site_srl=0, $gtype= 'site')
$args
Definition: ko.install.php:185
getModel($module_name)
Definition: func.inc.php:145
getAddonPath($addon_name)
executeQueryArray($query_id, $args=NULL, $arg_columns=NULL)
Definition: func.inc.php:219
getAdminController($module_name)
Definition: func.inc.php:101
readDir($path, $filter= '', $to_lower=FALSE, $concat_prefix=FALSE)
getInsertedAddons($site_srl=0, $gtype= 'site')
isActivatedAddon($addon, $site_srl=0, $type="pc", $gtype= 'site')
executeQuery($query_id, $args=NULL, $arg_columns=NULL)
Definition: func.inc.php:203