XpressEngine Core  1.11.2
 All Classes Namespaces Files Functions Variables Pages
addon.controller.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) NAVER <http://www.navercorp.com> */
3 
8 class addonController extends addon
9 {
10 
16  function init()
17  {
18  }
19 
26  function getCacheFilePath($type = "pc")
27  {
28  static $addon_file;
29  if(isset($addon_file))
30  {
31  return $addon_file;
32  }
33 
34  $site_module_info = Context::get('site_module_info');
35  $site_srl = $site_module_info->site_srl;
36 
37  $addon_path = _XE_PATH_ . 'files/cache/addons/';
38  $addon_file = $addon_path . $site_srl . $type . '.acivated_addons.cache.php';
39 
40  if($this->addon_file_called)
41  {
42  return $addon_file;
43  }
44 
45  $this->addon_file_called = TRUE;
46 
47  FileHandler::makeDir($addon_path);
48 
49  if(!file_exists($addon_file))
50  {
51  $this->makeCacheFile($site_srl, $type);
52  }
53 
54  return $addon_file;
55  }
56 
64  function _getMidList($selected_addon, $site_srl = 0)
65  {
66  $oAddonAdminModel = getAdminModel('addon');
67  $addon_info = $oAddonAdminModel->getAddonInfoXml($selected_addon, $site_srl);
68  return $addon_info->mid_list;
69  }
70 
79  function makeCacheFile($site_srl = 0, $type = "pc", $gtype = 'site')
80  {
81  // Add-on module for use in creating the cache file
82  $buff = array('<?php if(!defined("__XE__")) exit();', '$_m = Context::get(\'mid\');');
83  $oAddonModel = getAdminModel('addon');
84  $addon_list = $oAddonModel->getInsertedAddons($site_srl, $gtype);
85  foreach($addon_list as $addon => $val)
86  {
87  if($val->addon == "smartphone"
88  || ($type == "pc" && $val->is_used != 'Y')
89  || ($type == "mobile" && $val->is_used_m != 'Y')
90  || ($gtype == 'global' && $val->is_fixed != 'Y')
91  || !is_dir(_XE_PATH_ . 'addons/' . $addon))
92  {
93  continue;
94  }
95 
96  $extra_vars = unserialize($val->extra_vars);
97  $mid_list = $extra_vars->mid_list;
98  if(!is_array($mid_list) || count($mid_list) < 1)
99  {
100  $mid_list = NULL;
101  }
102 
103  $buff[] = '$before_time = microtime(true);';
104  $buff[] = '$rm = \'' . $extra_vars->xe_run_method . "';";
105  $buff[] = '$ml = array(';
106  if($mid_list)
107  {
108  foreach($mid_list as $mid)
109  {
110  $buff[] = "'$mid' => 1,";
111  }
112  }
113  $buff[] = ');';
114  $buff[] = sprintf('$addon_file = \'./addons/%s/%s.addon.php\';', $addon, $addon);
115 
116  if($val->extra_vars)
117  {
118  unset($extra_vars);
119  $extra_vars = base64_encode($val->extra_vars);
120  }
121  $addon_include = sprintf('unset($addon_info); $addon_info = unserialize(base64_decode(\'%s\')); @include($addon_file);', $extra_vars);
122 
123  $buff[] = 'if(file_exists($addon_file)){';
124  $buff[] = 'if($rm === \'no_run_selected\'){';
125  $buff[] = 'if(!isset($ml[$_m])){';
126  $buff[] = $addon_include;
127  $buff[] = '}}else{';
128  $buff[] = 'if(isset($ml[$_m]) || count($ml) === 0){';
129  $buff[] = $addon_include;
130  $buff[] = '}}}';
131  $buff[] = '$after_time = microtime(true);';
132  $buff[] = '$addon_time_log = new stdClass();';
133  $buff[] = '$addon_time_log->caller = $called_position;';
134  $buff[] = '$addon_time_log->called = "' . $addon . '";';
135  $buff[] = '$addon_time_log->called_extension = "' . $addon . '";';
136  $buff[] = 'writeSlowlog("addon",$after_time-$before_time,$addon_time_log);';
137  }
138  $addon_path = _XE_PATH_ . 'files/cache/addons/';
139  FileHandler::makeDir($addon_path);
140  $addon_file = $addon_path . ($gtype == 'site' ? $site_srl : '') . $type . '.acivated_addons.cache.php';
141  FileHandler::writeFile($addon_file, join(PHP_EOL, $buff));
142  }
143 
153  function doSetup($addon, $extra_vars, $site_srl = 0, $gtype = 'site')
154  {
155  if(!is_array($extra_vars->mid_list))
156  {
157  unset($extra_vars->mid_list);
158  }
159 
160  $args = new stdClass();
161  $args->addon = $addon;
162  $args->extra_vars = serialize($extra_vars);
163  if($gtype == 'global')
164  {
165  return executeQuery('addon.updateAddon', $args);
166  }
167  $args->site_srl = $site_srl;
168  return executeQuery('addon.updateSiteAddon', $args);
169  }
170 
177  function removeAddonConfig($site_srl)
178  {
179  $addon_path = _XE_PATH_ . 'files/cache/addons/';
180  $addon_file = $addon_path . $site_srl . '.acivated_addons.cache.php';
181  if(file_exists($addon_file))
182  {
183  FileHandler::removeFile($addon_file);
184  }
185 
186  $args = new stdClass();
187  $args->site_srl = $site_srl;
188  executeQuery('addon.deleteSiteAddons', $args);
189  }
190 
191 }
192 /* End of file addon.controller.php */
193 /* Location: ./modules/addon/addon.controller.php */
removeFile($filename)
foreach($sitemap as $id=> &$val) $extra_vars
Definition: ko.install.php:180
writeFile($filename, $buff, $mode="w")
doSetup($addon, $extra_vars, $site_srl=0, $gtype= 'site')
removeAddonConfig($site_srl)
$args
Definition: ko.install.php:185
$mid
string to represent run-time instance of Module (XE Module)
makeCacheFile($site_srl=0, $type="pc", $gtype= 'site')
getAdminModel($module_name)
Definition: func.inc.php:156
makeDir($path_string)
const _XE_PATH_
Definition: config.inc.php:49
executeQuery($query_id, $args=NULL, $arg_columns=NULL)
Definition: func.inc.php:203
_getMidList($selected_addon, $site_srl=0)
getCacheFilePath($type="pc")