Cheetah
ChWsbInstaller.php
Go to the documentation of this file.
1 <?php
2 
8 ch_import('ChWsbInstallerUtils');
9 ch_import('ChWsbParams');
10 ch_import('ChWsbPageViewAdmin');
11 ch_import('ChWsbPFM');
12 ch_import('ChWsbModuleDb');
13 
14 define("CH_WSB_INSTALLER_SUCCESS", 0);
15 define("CH_WSB_INSTALLER_FAILED", 1);
16 
38 {
39  var $_aConfig;
43 
46 
48  {
49  parent::__construct();
50 
51  $this->_aConfig = $aConfig;
52  $this->_sBasePath = CH_DIRECTORY_PATH_MODULES;
53  $this->_sHomePath = $this->_sBasePath . $aConfig['home_dir'];
54  $this->_sModulePath = $this->_sBasePath . $aConfig['home_dir'];
55 
56  $this->_aActions = array(
57  'check_script_version' => array(
58  'title' => _t('_adm_txt_modules_check_script_version'),
59  ),
60  'check_dependencies' => array(
61  'title' => _t('_adm_txt_modules_check_dependencies'),
62  ),
63  'show_introduction' => array(
64  'title' => _t('_adm_txt_modules_show_introduction'),
65  ),
66  'check_permissions' => array(
67  'title' => _t('_adm_txt_modules_check_permissions'),
68  ),
69  'change_permissions' => array(
70  'title' => _t('_adm_txt_modules_change_permissions'),
71  ),
72  'execute_sql' => array(
73  'title' => _t('_adm_txt_modules_execute_sql'),
74  ),
75  'update_languages' => array(
76  'title' => _t('_adm_txt_modules_update_languages'),
77  ),
78  'recompile_global_paramaters' => array(
79  'title' => _t('_adm_txt_modules_recompile_global_paramaters'),
80  ),
81  'recompile_main_menu' => array(
82  'title' => _t('_adm_txt_modules_recompile_main_menu'),
83  ),
84  'recompile_member_menu' => array(
85  'title' => _t('_adm_txt_modules_recompile_member_menu'),
86  ),
87  'recompile_site_stats' => array(
88  'title' => _t('_adm_txt_modules_recompile_site_stats'),
89  ),
90  'recompile_page_builder' => array(
91  'title' => _t('_adm_txt_modules_recompile_page_builder'),
92  ),
93  'recompile_profile_fields' => array(
94  'title' => _t('_adm_txt_modules_recompile_profile_fields'),
95  ),
96  'recompile_comments' => array(
97  'title' => _t('_adm_txt_modules_recompile_comments'),
98  ),
99  'recompile_member_actions' => array(
100  'title' => _t('_adm_txt_modules_recompile_member_actions'),
101  ),
102  'recompile_tags' => array(
103  'title' => _t('_adm_txt_modules_recompile_tags'),
104  ),
105  'recompile_votes' => array(
106  'title' => _t('_adm_txt_modules_recompile_votes'),
107  ),
108  'recompile_categories' => array(
109  'title' => _t('_adm_txt_modules_recompile_categories'),
110  ),
111  'recompile_search' => array(
112  'title' => _t('_adm_txt_modules_recompile_search'),
113  ),
114  'recompile_injections' => array(
115  'title' => _t('_adm_txt_modules_recompile_injections'),
116  ),
117  'recompile_permalinks' => array(
118  'title' => _t('_adm_txt_modules_recompile_permalinks'),
119  ),
120  'recompile_alerts' => array(
121  'title' => _t('_adm_txt_modules_recompile_alerts'),
122  ),
123  'clear_db_cache' => array(
124  'title' => _t('_adm_txt_modules_clear_db_cache'),
125  ),
126  'show_conclusion' => array(
127  'title' => _t('_adm_txt_modules_show_conclusion'),
128  ),
129  );
130  $this->_aNonHashable = array(
131  'install',
132  'updates'
133  );
134  }
135 
136  function install($aParams)
137  {
138  $oModuleDb = new ChWsbModuleDb();
139  $sTitle = _t('_adm_txt_modules_operation_install', $this->_aConfig['title']);
140 
141  //--- Check whether the module was already installed ---//
142  if($oModuleDb->isModule($this->_aConfig['home_uri']))
143  return array(
144  'operation_title' => $sTitle,
145  'message' => _t('_adm_txt_modules_already_installed'),
146  'result' => false
147  );
148 
149  //--- Check mandatory settings ---//
150  if($oModuleDb->isModuleParamsUsed($this->_aConfig['home_uri'], $this->_aConfig['home_dir'], $this->_aConfig['db_prefix'], $this->_aConfig['class_prefix']))
151  return array(
152  'operation_title' => $sTitle,
153  'message' => _t('_adm_txt_modules_params_used'),
154  'result' => false
155  );
156 
157  //--- Check version compatibility ---//
158  $bCompatible = false;
159  if(isset($this->_aConfig['compatible_with']) && is_array($this->_aConfig['compatible_with']))
160  foreach($this->_aConfig['compatible_with'] as $iKey => $sVersion) {
161  $sVersion = '/^' . str_replace(array('.', 'x'), array('\.', '[0-9]+'), $sVersion) . '$/is';
162  $bCompatible = $bCompatible || (preg_match($sVersion, $GLOBALS['site']['ver'] . '.' . $GLOBALS['site']['build']) > 0);
163  }
164  if(!$bCompatible)
165  return array(
166  'operation_title' => $sTitle,
167  'message' => $this->_displayResult('check_script_version', false, '_adm_txt_modules_wrong_version_script'),
168  'result' => false
169  );
170 
171  //--- Check actions ---//
172  $aResult = $this->_perform('install', 'Installation');
173  if($aResult['result']) {
174  $sDependencies = "";
175  if(isset($this->_aConfig['install']['check_dependencies']) && (int)$this->_aConfig['install']['check_dependencies'] == 1 && isset($this->_aConfig['dependencies']) && is_array($this->_aConfig['dependencies']))
176  $sDependencies = implode(',', array_keys($this->_aConfig['dependencies']));
177 
178  db_res("INSERT IGNORE INTO `sys_modules`(`title`, `vendor`, `version`, `update_url`, `path`, `uri`, `class_prefix`, `db_prefix`, `dependencies`, `date`) VALUES ('" . $this->_aConfig['title'] . "', '" . $this->_aConfig['vendor'] . "', '" . $this->_aConfig['version'] . "', '" . $this->_aConfig['update_url'] . "', '" . $this->_aConfig['home_dir'] . "', '" . $this->_aConfig['home_uri'] . "', '" . $this->_aConfig['class_prefix'] . "', '" . $this->_aConfig['db_prefix'] . "', '" . $sDependencies . "', UNIX_TIMESTAMP())");
179  $iModuleId = (int)db_last_id();
180 
181  $aFiles = array();
182  $this->_hash($this->_sModulePath, $aFiles);
183  foreach($aFiles as $aFile)
184  db_res("INSERT IGNORE INTO `sys_modules_file_tracks`(`module_id`, `file`, `hash`) VALUES('" . $iModuleId . "', '" . $aFile['file'] . "', '" . $aFile['hash'] . "')");
185 
186  $GLOBALS['MySQL']->cleanMemory('sys_modules_' . $this->_aConfig['home_uri']);
187  $GLOBALS['MySQL']->cleanMemory('sys_modules_' . $iModuleId);
188  $GLOBALS['MySQL']->cleanMemory('sys_modules');
189  }
190  else
191  $this->_perform('uninstall', 'Uninstallation');
192 
193  $aResult['operation_title'] = $sTitle;
194  return $aResult;
195  }
196  function uninstall($aParams)
197  {
198  $oModuleDb = new ChWsbModuleDb();
199  $sTitle = _t('_adm_txt_modules_operation_uninstall', $this->_aConfig['title']);
200 
201  //--- Check whether the module was already installed ---//
202  if(!$oModuleDb->isModule($this->_aConfig['home_uri']))
203  return array(
204  'operation_title' => $sTitle,
205  'message' => _t('_adm_txt_modules_already_uninstalled'),
206  'result' => false
207  );
208 
209  //--- Check for dependent modules ---//
210  $bDependent = false;
211  $aDependents = $oModuleDb->getDependent($this->_aConfig['home_uri']);
212  if(is_array($aDependents) && !empty($aDependents)) {
213  $bDependent = true;
214 
215  $sMessage = '<br />-- -- ' . _t('_adm_txt_modules_has_dependents') . '<br />';
216  foreach($aDependents as $aDependent)
217  $sMessage .= '-- -- ' . $aDependent['title'] . '<br />';
218  }
219 
220  if($bDependent)
221  return array(
222  'operation_title' => $sTitle,
223  'message' => $this->_displayResult('check_dependencies', false, $sMessage),
224  'result' => false
225  );
226 
227  $aResult = $this->_perform('uninstall', 'Uninstallation');
228  if($aResult['result']) {
229  $iModuleId = (int)$oModuleDb->getOne("SELECT `id` FROM `sys_modules` WHERE `vendor`='" . $this->_aConfig['vendor'] . "' AND `path`='" . $this->_aConfig['home_dir'] . "' LIMIT 1");
230  $oModuleDb->query("DELETE FROM `sys_modules` WHERE `vendor`='" . $this->_aConfig['vendor'] . "' AND `path`='" . $this->_aConfig['home_dir'] . "' LIMIT 1");
231  $oModuleDb->query("DELETE FROM `sys_modules_file_tracks` WHERE `module_id`='" . $iModuleId . "'");
232 
233  $GLOBALS['MySQL']->cleanMemory ('sys_modules_' . $this->_aConfig['home_uri']);
234  $GLOBALS['MySQL']->cleanMemory ('sys_modules_' . $iModuleId);
235  $GLOBALS['MySQL']->cleanMemory ('sys_modules');
236  }
237 
238  $aResult['operation_title'] = $sTitle;
239  return $aResult;
240  }
241  function recompile($aParams)
242  {
243  $aResult = array('message' => '', 'result' => false);
244 
245  $aLanguages = $GLOBALS['MySQL']->getAll("SELECT `ID` AS `id`, `Name` AS `name`, `Title` AS `title` FROM `sys_localization_languages` WHERE 1");
246  if(isAdmin() && !empty($aLanguages)) {
247  $this->_updateLanguage(false, current($aLanguages));
248 
249  $bResult = false;
250  foreach($aLanguages as $aLanguage) {
251  $bResult = $this->_updateLanguage(true, $aLanguage) && compileLanguage($aLanguage['id']);
252  $aResult['message'] .= $aLanguage['title'] . ': <span class="' . ($bResult ? 'modules-action-success' : 'modules-action-failed') . '">' . _t($bResult ? '_adm_txt_modules_process_action_success' : '_adm_txt_modules_process_action_failed') . '</span><br />';
253 
254  $aResult['result'] |= $bResult;
255  }
256  }
257 
258  $aResult['operation_title'] = _t('_adm_txt_modules_operation_recompile', $this->_aConfig['title']);
259  return $aResult;
260  }
261  function _hash($sPath, &$aFiles)
262  {
263  if(file_exists($sPath) && is_dir($sPath) && ($rSource = opendir($sPath))) {
264  while(($sFile = readdir($rSource)) !== false) {
265  if($sFile == '.' || $sFile =='..' || $sFile[0] == '.' || in_array($sFile, $this->_aNonHashable))
266  continue;
267 
268  if(is_dir($sPath . $sFile))
269  $this->_hash($sPath . $sFile . '/', $aFiles);
270  else
271  $aFiles[] = $this->_info($sPath . $sFile);
272  }
273  closedir($rSource);
274  } else
275  $aFiles[] = $this->_info($sPath);
276  }
277  function _info($sPath)
278  {
279  return array(
280  'file' => str_replace($this->_sModulePath, '', $sPath),
281  'hash' => md5(file_get_contents($sPath))
282  );
283  }
284  function _perform($sOperationName, $sOperationTitle)
285  {
286  if(!defined('CH_SKIP_INSTALL_CHECK') && !$GLOBALS['logged']['admin'])
287  return array('message' => '', 'result' => false);
288 
289  $sMessage = '';
290  foreach($this->_aConfig[$sOperationName] as $sAction => $iEnabled) {
291  $sMethod = 'action' . str_replace (' ', '', ucwords(str_replace ('_', ' ', $sAction)));
292  if($iEnabled == 0 || !method_exists($this, $sMethod))
293  continue;
294 
295  $mixedResult = $this->$sMethod($sOperationName == 'install' || $sOperationName == 'update');
296 
297  //--- On Success ---//
298  if((is_int($mixedResult) && (int)$mixedResult == CH_WSB_INSTALLER_SUCCESS) || (isset($mixedResult['code']) && (int)$mixedResult['code'] == CH_WSB_INSTALLER_SUCCESS)) {
299  $sMessage .= $this->_displayResult($sAction, true, isset($mixedResult['content']) ? $mixedResult['content'] : '');
300  continue;
301  }
302 
303  //--- On Failed ---//
304  $sMethodFailed = $sMethod . 'Failed';
305  return array('message' => $this->_displayResult($sAction, false, method_exists($this, $sMethodFailed) ? $this->$sMethodFailed($mixedResult) : $this->actionOperationFailed($mixedResult)), 'result' => false);
306  }
307 
308  $sMessage .= $sOperationTitle . ' finished';
309  return array('message' => $sMessage, 'result' => true);
310  }
311 
313  {
314  $sMessage = '-- ' . $this->_aActions[$sAction]['title'] . ' ';
315  if(!empty($sResult) && substr($sResult, 0, 1) == '_')
316  $sResult = _t($sResult) . '<br />';
317 
318  if(!$bResult)
319  return $sMessage . '<span style="color:red; font-weight:bold;">' . $sResult . '</span>';
320 
321  if(empty($sResult))
322  $sResult = _t('_adm_txt_modules_process_action_success') . '<br />';
323  return $sMessage . '<span style="color:green; font-weight:bold;">' . $sResult . '</span>';
324  }
325 
326  //--- Action Methods ---//
327  function actionOperationFailed($mixedResult)
328  {
329  return _t('_adm_txt_modules_process_action_failed');
330  }
331  function actionCheckDependencies($bInstall = true)
332  {
333  $sContent = '';
334 
335  if($bInstall) {
336  if(!isset($this->_aConfig['dependencies']) || !is_array($this->_aConfig['dependencies']))
338 
339  $oModulesDb = new ChWsbModuleDb();
340  foreach($this->_aConfig['dependencies'] as $sModuleUri => $sModuleTitle)
341  if($sModuleUri != $this->_aConfig['home_uri'] && !$oModulesDb->isModule($sModuleUri))
342  $sContent .= '-- -- ' . $sModuleTitle . '<br />';
343 
344  if(!empty($sContent))
345  $sContent = '<br />-- -- ' . _t('_adm_txt_modules_wrong_dependency_install') . '<br />' . $sContent;
346  }
347 
348  return empty($sContent) ? CH_WSB_INSTALLER_SUCCESS : array('code' => CH_WSB_INSTALLER_FAILED, 'content' => $sContent);
349  }
350  function actionCheckDependenciesFailed($mixedResult)
351  {
352  return $mixedResult['content'];
353  }
354  function actionShowIntroduction($bInstall = true)
355  {
356  $sFile = $this->_aConfig[($bInstall ? 'install_info' : 'uninstall_info')]['introduction'];
357  $sPath = $this->_sHomePath . 'install/info/' . $sFile;
358 
359  return file_exists($sPath) ? array("code" => CH_WSB_INSTALLER_SUCCESS, "content" => "<pre>" . file_get_contents($sPath) . "</pre>") : array("code" => CH_WSB_INSTALLER_FAILED, "content" => "<pre>Could not show Introduction. Does not exist.</pre>");
360  }
361  function actionShowConclusion($bInstall = true)
362  {
363  $sFile = $this->_aConfig[($bInstall ? 'install_info' : 'uninstall_info')]['conclusion'];
364  $sPath = $this->_sHomePath . 'install/info/' . $sFile;
365 
366  return file_exists($sPath) ? array("code" => CH_WSB_INSTALLER_SUCCESS, "content" => "<pre>" . file_get_contents($sPath) . "</pre>") : array("code" => CH_WSB_INSTALLER_FAILED, "content" => "<pre>Could not show Conclusion. Does not exist.</pre>");
367  }
368  function actionCheckPermissions($bInstall = true)
369  {
370  $aPermissions = $bInstall ? $this->_aConfig['install_permissions'] : $this->_aConfig['uninstall_permissions'];
371 
372  $aResult = array();
373  foreach($aPermissions as $sPermissions => $aFiles) {
374  $sCheckFunction = 'is' . ucfirst($sPermissions);
375  $sCptPermissions = _t('_adm_txt_modules_' . $sPermissions);
376  foreach($aFiles as $sFile)
377  if(!ChWsbInstallerUtils::$sCheckFunction(ch_ltrim_str($this->_sModulePath . $sFile, CH_DIRECTORY_PATH_ROOT)))
378  $aResult[] = array('path' => $this->_sModulePath . $sFile, 'permissions' => $sCptPermissions);
379  }
380 
381  return empty($aResult) ? CH_WSB_INSTALLER_SUCCESS : array('code' => CH_WSB_INSTALLER_FAILED, 'content' => $aResult);
382  }
383  function actionCheckPermissionsFailed($mixedResult)
384  {
385  $sResult = '<br />-- -- ' . _t('_adm_txt_modules_wrong_permissions_check') . '<br />';
386  foreach($mixedResult['content'] as $aFile)
387  $sResult .= '-- -- ' . _t('_adm_txt_modules_wrong_permissions_msg', $aFile['path'], $aFile['permissions']) . '<br />';
388  return $sResult;
389  }
390  function actionChangePermissions($bInstall = true)
391  {
392  $aPermissions = $bInstall ? $this->_aConfig['install_permissions'] : $this->_aConfig['uninstall_permissions'];
393 
394  $aResult = $aChangeItems = array();
395  foreach($aPermissions as $sPermissions => $aFiles) {
396  $sCheckFunction = 'is' . ucfirst($sPermissions);
397  foreach($aFiles as $sFile) {
398  $sPath = ch_ltrim_str($this->_sModulePath . $sFile, CH_DIRECTORY_PATH_ROOT);
399  if(ChWsbInstallerUtils::$sCheckFunction($sPath))
400  continue;
401 
402  $aResult[] = array('path' => $this->_sModulePath . $sFile, 'permissions' => $sPermissions);
403  $aChangeItems[] = array('file' => $sFile, 'path' => $sPath, 'permissions' => $sPermissions);
404  }
405  }
406 
407  if(empty($aChangeItems))
409 
410  $sFtpHost = getParam('sys_ftp_host');
411  if(empty($sFtpHost))
412  $sFtpHost = $_SERVER['HTTP_HOST'];
413 
414  ch_import('ChWsbFtp');
415  $oFile = new ChWsbFtp($sFtpHost, getParam('sys_ftp_login'), getParam('sys_ftp_password'), getParam('sys_ftp_dir'));
416 
417  if(!$oFile->connect())
418  return array('code' => CH_WSB_INSTALLER_FAILED, 'content_msg' => '_adm_txt_modules_wrong_permissions_change_cannot_connect_to_ftp', 'content_data' => $aResult);
419 
420  if(!$oFile->isCheetah())
421  return array('code' => CH_WSB_INSTALLER_FAILED, 'content_msg' => '_adm_txt_modules_wrong_permissions_change_destination_not_valid', 'content_data' => $aResult);
422 
423  $aResult = array();
424  foreach($aChangeItems as $aChangeItem)
425  if(!$oFile->setPermissions($aChangeItem['path'], $aChangeItem['permissions']))
426  $aResult[] = array('path' => $this->_sModulePath . $aChangeItem['file'], 'permissions' => $aChangeItem['permissions']);
427 
428  return empty($aResult) ? CH_WSB_INSTALLER_SUCCESS : array('code' => CH_WSB_INSTALLER_FAILED, 'content_msg' => '_adm_txt_modules_wrong_permissions_change', 'content_data' => $aResult);
429  }
430  function actionChangePermissionsFailed($mixedResult)
431  {
432  if(empty($mixedResult['content_msg']) && empty($mixedResult['content_data']))
433  return $this->actionOperationFailed($mixedResult);
434 
435  $sResult = '';
436  if(!empty($mixedResult['content_msg']))
437  $sResult .= _t($mixedResult['content_msg']);
438 
439  if(!empty($mixedResult['content_data'])) {
440  $sResult .= ' ' . _t('_adm_txt_modules_wrong_permissions_change_list') . '<br />';
441  foreach($mixedResult['content_data'] as $aFile)
442  $sResult .= '-- ' . _t('_adm_txt_modules_wrong_permissions_msg', $aFile['path'], $aFile['permissions']) . '<br />';
443  }
444 
445  return $sResult;
446  }
447  function actionExecuteSql($bInstall = true)
448  {
449  if($bInstall)
450  $this->actionExecuteSql(false);
451 
452  $sPath = $this->_sHomePath . 'install/sql/' . ($bInstall ? 'install' : 'uninstall') . '.sql';
453  if(!file_exists($sPath) || !($rHandler = fopen($sPath, "r")))
455 
456  $sQuery = "";
457  $sDelimiter = ';';
458  $aResult = array();
459  while(!feof($rHandler)) {
460  $sStr = trim(fgets($rHandler));
461 
462  if(empty($sStr) || $sStr[0] == "" || $sStr[0] == "#" || ($sStr[0] == "-" && $sStr[1] == "-"))
463  continue;
464 
465  //--- Change delimiter ---//
466  if(strpos($sStr, "DELIMITER //") !== false || strpos($sStr, "DELIMITER ;") !== false) {
467  $sDelimiter = trim(str_replace('DELIMITER', '', $sStr));
468  continue;
469  }
470 
471  $sQuery .= $sStr;
472 
473  //--- Check for multiline query ---//
474  if(substr($sStr, -strlen($sDelimiter)) != $sDelimiter)
475  continue;
476 
477  //--- Execute query ---//
478  $sQuery = str_replace("[db_prefix]", $this->_aConfig['db_prefix'], $sQuery);
479  if($sDelimiter != ';')
480  $sQuery = str_replace($sDelimiter, "", $sQuery);
481 
482  try {
483  $rResult = db_res(trim($sQuery));
484  } catch (Exception $e) {
485  $aResult[] = array('query' => $sQuery, 'error' => $e->getMessage());
486  }
487 
488 
489  $sQuery = "";
490  }
491  fclose($rHandler);
492 
493  return empty($aResult) ? CH_WSB_INSTALLER_SUCCESS : array('code' => CH_WSB_INSTALLER_FAILED, 'content' => $aResult);
494  }
495  function actionExecuteSqlFailed($mixedResult)
496  {
497  $sResult = '<br />-- -- ' . _t('_adm_txt_modules_wrong_mysql_query') . '<br />';
498  foreach($mixedResult['content'] as $aQuery) {
499  $sResult .= '-- -- ' . _t('_adm_txt_modules_wrong_mysql_query_msg', $aQuery['error']) . '<br />';
500  $sResult .= '<pre>' . $aQuery['query'] . '</pre>';
501  }
502  return $sResult;
503  }
504  function actionUpdateLanguages($bInstall = true)
505  {
506  $aLanguages = array();
507  $rLanguages = db_res("SELECT `ID` AS `id`, `Name` AS `name`, `Title` AS `title` FROM `sys_localization_languages`");
508  while($aLanguage = $rLanguages->fetch())
509  $aLanguages[] = $aLanguage;
510 
511  //--- Process Language Category ---//
512  $iCategoryId = 100;
513  $sCategoryName = isset($this->_aConfig['language_category']) ? $this->_aConfig['language_category'] : '';
514  if($bInstall && !empty($sCategoryName)) {
515  $res = db_res("INSERT IGNORE INTO `sys_localization_categories` SET `Name`= ?", [$sCategoryName]);
516  if(db_affected_rows($res) <= 0 )
517  $iCategoryId = (int)db_value("SELECT `ID` FROM `sys_localization_categories` WHERE `Name`='" . $sCategoryName . "' LIMIT 1");
518  else
519  $iCategoryId = db_last_id();
520  } else if(!$bInstall && !empty($sCategoryName)) {
521  db_res("DELETE FROM `sys_localization_categories` WHERE `Name`= ?", [$sCategoryName]);
522  }
523 
524  //--- Process languages' key=>value pears ---//
525  foreach($aLanguages as $aLanguage)
526  $this->_updateLanguage($bInstall, $aLanguage, $iCategoryId);
527 
528  //--- Recompile all language files ---//
529  $aResult = array();
530  foreach($aLanguages as $aLanguage) {
531  $bResult = compileLanguage($aLanguage['id']);
532 
533  if(!$bResult)
534  $aResult[] = $aLanguage['title'];
535  }
536  return empty($aResult) ? CH_WSB_INSTALLER_SUCCESS : array('code' => CH_WSB_INSTALLER_FAILED, 'content' => $aResult);
537  }
538  function actionUpdateLanguagesFailed($mixedResult)
539  {
540  $sResult = '<br />-- -- ' . _t('_adm_txt_modules_cannot_recompile_lang') . '<br />';
541  foreach($mixedResult['content'] as $sLanguage)
542  $sResult .= '-- -- ' . $sLanguage . '<br />';
543  return $sResult;
544  }
545  function actionRecompileGlobalParamaters($bInstall = true)
546  {
547  global $MySQL;
548  ob_start();
549  $bResult = $MySQL->oParams->cache();
550  ob_get_clean();
551 
553  }
554  function actionRecompileMainMenu($bInstall = true)
555  {
556  ob_start();
557  $oChWsbMenu = new ChWsbMenu();
558  $bResult = $oChWsbMenu->compile();
559  ob_get_clean();
560 
562  }
563  function actionRecompileMemberMenu($bInstall = true)
564  {
565  ch_import('ChWsbMemberMenu');
567  $bResult = $oMemberMenu -> deleteMemberMenuCaches();
568 
570  }
571  function actionRecompileSiteStats($bInstall = true)
572  {
573  $bResult = $GLOBALS['MySQL']->cleanCache('sys_stat_site');
574 
576  }
577  function actionRecompilePageBuilder($bInstall = true)
578  {
579  ob_start();
580  $oPVCacher = new ChWsbPageViewCacher('sys_page_compose', 'sys_page_compose.inc');
581  $bResult = $oPVCacher -> createCache();
582  ob_get_clean();
583 
585  }
586  function actionRecompileProfileFields($bInstall = true)
587  {
588  ob_start();
589  $oChWsbPFMCacher = new ChWsbPFMCacher();
590  $bResult = $oChWsbPFMCacher -> createCache();
591  ob_get_clean();
592 
594  }
595  function actionRecompileComments($bInstall = true)
596  {
597  $bResult = $GLOBALS['MySQL']->cleanCache('sys_objects_cmts');
598 
600  }
601  function actionRecompileMemberActions($bInstall = true)
602  {
603  $bResult = $GLOBALS['MySQL']->cleanCache('sys_objects_actions');
604 
606  }
607  function actionRecompileTags($bInstall = true)
608  {
609  $bResult = $GLOBALS['MySQL']->cleanCache('sys_objects_tag');
610 
612  }
613  function actionRecompileVotes($bInstall = true)
614  {
615  $bResult = $GLOBALS['MySQL']->cleanCache('sys_objects_vote');
616 
618  }
619  function actionRecompileCategories($bInstall = true)
620  {
621  $bResult = $GLOBALS['MySQL']->cleanCache('sys_objects_categories');
622 
624  }
625  //TODO: Remove the method and 'recompile_search' in the config.php of all modules.
626  function actionRecompileSearch($bInstall = true)
627  {
629  }
630  function actionRecompileInjections($bInstall = true)
631  {
632  $bResult = $GLOBALS['MySQL']->cleanCache('sys_injections.inc');
633  $bResult = $bResult && $GLOBALS['MySQL']->cleanCache('sys_injections_admin.inc');
634 
636  }
637  function actionRecompilePermalinks($bInstall = true)
638  {
639  $bResult = true;
640  ob_start();
641  $oPermalinks = new ChWsbPermalinks();
642  $bResult = $bResult && $oPermalinks->cache();
643 
644  $oMenu = new ChWsbMenu();
645  $bResult = $bResult && $oMenu->compile();
646 
647  $bResult = $bResult && $GLOBALS['MySQL']->cleanCache ('sys_menu_member');
648  ob_get_clean();
649 
651  }
652  function actionRecompileAlerts($bInstall = true)
653  {
654  ob_start();
655  $bResult = $GLOBALS['MySQL']->cleanCache('sys_alerts');
656  ob_end_clean();
657 
659  }
660  function actionClearDbCache($bInstall = true)
661  {
662  $oCache = $GLOBALS['MySQL']->getDbCacheObject();
663  $bResult = $oCache->removeAllByPrefix ('db_');
664 
666  }
667 
668  //--- Get/Set Methods ---//
669  function getVendor()
670  {
671  return $this->_aConfig['vendor'];
672  }
673  function getName()
674  {
675  return $this->_aConfig['name'];
676  }
677  function getTitle()
678  {
679  return $this->_aConfig['title'];
680  }
681  function getHomeDir()
682  {
683  return $this->_aConfig['home_dir'];
684  }
685 
686  //--- Protected methods ---//
687 
688  function _updateLanguage($bInstall, $aLanguage, $iCategoryId = 0)
689  {
690  if(empty($iCategoryId))
691  $iCategoryId = (int)db_value("SELECT `ID` FROM `sys_localization_categories` WHERE `Name`='" . $this->_aConfig['language_category'] . "' LIMIT 1");
692 
693  $sPath = $this->_sHomePath . 'install/langs/' . $aLanguage['name'] . '.php';
694  if(!file_exists($sPath))
695  return false;
696 
697  include($sPath);
698  if(!(isset($aLangContent) && is_array($aLangContent)))
699  return false;
700 
701  //--- Installation ---//
702  if($bInstall)
703  foreach($aLangContent as $sKey => $sValue) {
704  $iLangKeyId = (int)db_value("SELECT `ID` FROM `sys_localization_keys` WHERE `IDCategory`='" . $iCategoryId . "' AND `Key`='" . $sKey . "' LIMIT 1");
705  if($iLangKeyId == 0) {
706  $res = db_res("INSERT INTO `sys_localization_keys`(`IDCategory`, `Key`) VALUES('" . $iCategoryId . "', '" . $sKey . "')");
707  if(db_affected_rows($res) <= 0)
708  continue;
709 
710  $iLangKeyId = db_last_id();
711  }
712  db_res("INSERT IGNORE INTO `sys_localization_strings`(`IDKey`, `IDLanguage`, `String`) VALUES('" . $iLangKeyId . "', '" . $aLanguage['id'] . "', '" . addslashes($sValue) . "')");
713  }
714  //--- Uninstallation ---//
715  else
716  foreach($aLangContent as $sKey => $sValue)
717  db_res("DELETE FROM `sys_localization_keys`, `sys_localization_strings` USING `sys_localization_keys`, `sys_localization_strings` WHERE `sys_localization_keys`.`ID`=`sys_localization_strings`.`IDKey` AND `sys_localization_keys`.`Key`='" . $sKey . "'");
718 
719  return true;
720  }
721 
722  function _addLanguage($aLanguage, $aLangInfo)
723  {
724  $oDb = new ChWsbModuleDb();
725 
726  if (getLangIdByName($aLangInfo['Name'])) // language already exists
727  return false;
728 
729  $sLangName = $aLangInfo['Name'];
730  $sLangFlag = $aLangInfo['Flag'];
731  $sLangTitle = $aLangInfo['Title'];
732  $sLangDir = isset($aLangInfo['Direction']) && $aLangInfo['Direction'] ? $aLangInfo['Direction'] : 'LTR';
733  $sLangCountryCode = isset($aLangInfo['LanguageCountry']) && $aLangInfo['LanguageCountry'] ? $aLangInfo['LanguageCountry'] : $aLangInfo['Name'] . '_' . strtoupper($aLangInfo['Flag']);
734 
735  if (!$oDb->res("INSERT INTO `sys_localization_languages` VALUES (?, ?, ?, ?, ?, ?)", [
736  NULL,
737  $sLangName,
738  $sLangFlag,
739  $sLangTitle,
740  $sLangDir,
741  $sLangCountryCode
742  ])) {
743  return false;
744  }
745  $iLangKey = $oDb->lastId();
746 
747  foreach ($aLanguage as $sKey => $sValue) {
748  $sDbKey = $sKey;
749  $sDbValue = $sValue;
750 
751  $iExistedKey = $oDb->getOne("SELECT `ID` FROM `sys_localization_keys` WHERE `Key` = ?", [$sDbKey]);
752  if (!$iExistedKey) { // key is missing, insert new key
753  if (!$oDb->res("INSERT INTO `sys_localization_keys` VALUES (NULL, ?, ?)", [CH_WSB_LANGUAGE_CATEGORY_SYSTEM, $sDbKey]))
754  continue;
755  $iExistedKey = $oDb->lastId();
756  }
757 
758  $oDb->res("INSERT INTO `sys_localization_strings` VALUES(?, ?, ?)", [$iExistedKey, $iLangKey, $sDbValue]);
759  }
760 
761  return true;
762  }
763 
764  function _removeLanguage($aLanguage, $aLangInfo)
765  {
766  $oDb = new ChWsbModuleDb();
767 
768  if (!($iLangKey = getLangIdByName($aLangInfo['Name']))) // language doesn't exists, so it is already removed somehow
769  return true;
770 
771  if (!$oDb->res("DELETE FROM `sys_localization_languages` WHERE ID = {$iLangKey}"))
772  return false;
773 
774  $oDb->res("DELETE FROM `sys_localization_strings` WHERE `IDLanguage` = {$iLangKey}");
775 
776  return true;
777  }
778 
780  {
781  $oDb = new ChWsbModuleDb();
782 
783  $aLanguage = $GLOBALS['MySQL']->getRow("SELECT `ID` AS `id`, `Name` AS `name`, `Title` AS `title` FROM `sys_localization_languages` WHERE `ID` = ?", [$iLangId]);
784  if (!$aLanguage)
785  return false;
786 
787  // save class properties
788  $aSave['config'] = $this->_aConfig;
789  $aSave['home_path'] = $this->_sHomePath;
790  $aSave['module_path'] = $this->_sModulePath;
791 
792  $aModules = $oDb->getModules();
793  foreach ($aModules as $a) {
794  $aConfig = false;
795  $bInclude = @include(CH_DIRECTORY_PATH_MODULES . $a['path'] . 'install/config.php');
796  if (!$bInclude || !$aConfig)
797  continue;
798 
799  $this->_aConfig = $aConfig;
800  $this->_sHomePath = $this->_sBasePath . $aConfig['home_dir'];
801  $this->_sModulePath = $this->_sBasePath . $aConfig['home_dir'];
802 
803  $b = $this->_updateLanguage(true, $aLanguage);
804  }
805 
806  // restore class properties
807  $this->_aConfig = $aSave['config'];
808  $this->_sHomePath = $aSave['home_path'];
809  $this->_sModulePath = $aSave['module_path'];
810 
811  return true;
812  }
813 
814  function _getPermissions($sFilePath)
815  {
816  clearstatcache();
817  $hPerms = @fileperms($sFilePath);
818  if($hPerms == false)
819  return false;
820  return substr( decoct( $hPerms ), -3 );
821  }
822 }
ChWsbInstaller\actionRecompilePageBuilder
actionRecompilePageBuilder($bInstall=true)
Definition: ChWsbInstaller.php:577
ChWsbInstaller\actionCheckPermissions
actionCheckPermissions($bInstall=true)
Definition: ChWsbInstaller.php:368
$sMessage
$sMessage
Definition: actions.inc.php:17
ChWsbInstaller\actionShowIntroduction
actionShowIntroduction($bInstall=true)
Definition: ChWsbInstaller.php:354
ChWsbInstaller\actionCheckPermissionsFailed
actionCheckPermissionsFailed($mixedResult)
Definition: ChWsbInstaller.php:383
ChWsbInstaller\__construct
__construct($aConfig)
Definition: ChWsbInstaller.php:47
ChWsbInstaller\actionClearDbCache
actionClearDbCache($bInstall=true)
Definition: ChWsbInstaller.php:660
ChWsbInstaller\actionUpdateLanguages
actionUpdateLanguages($bInstall=true)
Definition: ChWsbInstaller.php:504
ChWsbInstaller\actionUpdateLanguagesFailed
actionUpdateLanguagesFailed($mixedResult)
Definition: ChWsbInstaller.php:538
$oMenu
$oMenu
Definition: bottom_menu_compose.php:29
ChWsbInstaller\recompile
recompile($aParams)
Definition: ChWsbInstaller.php:241
ChWsbInstaller\$_sHomePath
$_sHomePath
Definition: ChWsbInstaller.php:41
ChWsbInstaller\actionExecuteSql
actionExecuteSql($bInstall=true)
Definition: ChWsbInstaller.php:447
ChWsbInstaller\getHomeDir
getHomeDir()
Definition: ChWsbInstaller.php:681
compileLanguage
compileLanguage($langID=0)
Definition: languages.inc.php:301
ChWsbInstaller\$_sBasePath
$_sBasePath
Definition: ChWsbInstaller.php:40
ChWsbInstaller\$_aActions
$_aActions
Definition: ChWsbInstaller.php:44
ChWsbInstaller\actionChangePermissionsFailed
actionChangePermissionsFailed($mixedResult)
Definition: ChWsbInstaller.php:430
CH_WSB_LANGUAGE_CATEGORY_SYSTEM
const CH_WSB_LANGUAGE_CATEGORY_SYSTEM
Definition: languages.inc.php:9
$sResult
$sResult
Definition: advanced_settings.php:26
ChWsbMemberMenu
Definition: ChWsbMemberMenu.php:92
ChWsbInstaller\actionRecompileCategories
actionRecompileCategories($bInstall=true)
Definition: ChWsbInstaller.php:619
ChWsbInstaller\getVendor
getVendor()
Definition: ChWsbInstaller.php:669
$aLangContent
$aLangContent
Definition: en.php:8
ChWsbInstaller\actionRecompilePermalinks
actionRecompilePermalinks($bInstall=true)
Definition: ChWsbInstaller.php:637
ch_import
ch_import($sClassName, $aModule=array())
Definition: utils.inc.php:1218
$aResult
$aResult
Definition: index.php:19
php
ChWsbInstaller
Definition: ChWsbInstaller.php:38
ChWsbModuleDb
Definition: ChWsbModuleDb.php:12
ChWsbInstallerUtils
Definition: ChWsbInstallerUtils.php:12
ChWsbInstaller\getTitle
getTitle()
Definition: ChWsbInstaller.php:677
ChWsbInstaller\actionRecompileTags
actionRecompileTags($bInstall=true)
Definition: ChWsbInstaller.php:607
ChWsbInstaller\actionRecompileAlerts
actionRecompileAlerts($bInstall=true)
Definition: ChWsbInstaller.php:652
ChWsbInstaller\$_aConfig
$_aConfig
Definition: ChWsbInstaller.php:39
ChWsbInstaller\actionCheckDependencies
actionCheckDependencies($bInstall=true)
Definition: ChWsbInstaller.php:331
isAdmin
isAdmin()
Definition: index.php:649
ChWsbPageViewCacher
Definition: ChWsbPageViewAdmin.php:944
$sLanguage
$sLanguage
Definition: actions.inc.php:19
$oCache
$oCache
Definition: prof.inc.php:10
ChWsbInstaller\getName
getName()
Definition: ChWsbInstaller.php:673
ChWsbInstaller\_info
_info($sPath)
Definition: ChWsbInstaller.php:277
ChWsbInstaller\_removeLanguage
_removeLanguage($aLanguage, $aLangInfo)
Definition: ChWsbInstaller.php:764
ChWsbInstaller\actionCheckDependenciesFailed
actionCheckDependenciesFailed($mixedResult)
Definition: ChWsbInstaller.php:350
ChWsbInstaller\actionRecompileSearch
actionRecompileSearch($bInstall=true)
Definition: ChWsbInstaller.php:626
$sFile
$sFile
Definition: index.php:20
$oMemberMenu
$oMemberMenu
Definition: member_menu_queries.php:20
$oModuleDb
$oModuleDb
Definition: classifieds.php:20
getParam
getParam($sParamName, $bUseCache=true)
Definition: db.inc.php:130
ChWsbInstaller\_perform
_perform($sOperationName, $sOperationTitle)
Definition: ChWsbInstaller.php:284
$sTitle
$sTitle
Definition: actions.inc.php:13
ChWsbInstaller\actionRecompileVotes
actionRecompileVotes($bInstall=true)
Definition: ChWsbInstaller.php:613
db_last_id
db_last_id()
Definition: db.inc.php:47
$oDb
global $oDb
Definition: db.inc.php:39
ChWsbInstaller\_recompileLanguageForAllModules
_recompileLanguageForAllModules($iLangId)
Definition: ChWsbInstaller.php:779
ChWsbInstaller\$_aNonHashable
$_aNonHashable
Definition: ChWsbInstaller.php:45
ChWsbInstaller\actionShowConclusion
actionShowConclusion($bInstall=true)
Definition: ChWsbInstaller.php:361
global
if(!defined("GLOBAL_MODULE")) define("GLOBAL_MODULE" global
Definition: header.inc.php:25
ChWsbInstaller\actionRecompileComments
actionRecompileComments($bInstall=true)
Definition: ChWsbInstaller.php:595
ChWsbInstaller\actionRecompileInjections
actionRecompileInjections($bInstall=true)
Definition: ChWsbInstaller.php:630
CH_WSB_INSTALLER_FAILED
const CH_WSB_INSTALLER_FAILED
Definition: ChWsbInstaller.php:15
$bResult
$bResult
Definition: get_file.php:11
$sContent
$sContent
Definition: bottom_menu_compose.php:169
ChWsbInstaller\_hash
_hash($sPath, &$aFiles)
Definition: ChWsbInstaller.php:261
_t
_t($key, $arg0="", $arg1="", $arg2="")
Definition: languages.inc.php:509
db_affected_rows
db_affected_rows($oStmt=null)
Definition: db.inc.php:56
ChWsbInstaller\actionExecuteSqlFailed
actionExecuteSqlFailed($mixedResult)
Definition: ChWsbInstaller.php:495
$aConfig
$aConfig
Definition: config.php:8
ChWsbInstaller\actionRecompileSiteStats
actionRecompileSiteStats($bInstall=true)
Definition: ChWsbInstaller.php:571
ChWsbInstaller\install
install($aParams)
Definition: ChWsbInstaller.php:136
ChWsbInstaller\_displayResult
_displayResult($sAction, $bResult, $sResult='')
Definition: ChWsbInstaller.php:312
ChWsbInstaller\_addLanguage
_addLanguage($aLanguage, $aLangInfo)
Definition: ChWsbInstaller.php:722
$aModules
$aModules
Definition: constants.inc.php:29
ChWsbInstaller\actionRecompileMemberActions
actionRecompileMemberActions($bInstall=true)
Definition: ChWsbInstaller.php:601
ChWsbInstaller\actionRecompileProfileFields
actionRecompileProfileFields($bInstall=true)
Definition: ChWsbInstaller.php:586
db_res
db_res($query, $bindings=[])
Definition: db.inc.php:39
db_value
db_value($query, $bindings=[], $error_checking=true, $index=0)
Definition: db.inc.php:98
ChWsbInstaller\$_sModulePath
$_sModulePath
Definition: ChWsbInstaller.php:42
ChWsbInstaller\_updateLanguage
_updateLanguage($bInstall, $aLanguage, $iCategoryId=0)
Definition: ChWsbInstaller.php:688
ChWsbInstaller\actionRecompileMainMenu
actionRecompileMainMenu($bInstall=true)
Definition: ChWsbInstaller.php:554
ChWsbInstaller\_getPermissions
_getPermissions($sFilePath)
Definition: ChWsbInstaller.php:814
ChWsbInstaller\actionOperationFailed
actionOperationFailed($mixedResult)
Definition: ChWsbInstaller.php:327
$sAction
$sAction
Definition: categories.php:274
ChWsbInstaller\actionChangePermissions
actionChangePermissions($bInstall=true)
Definition: ChWsbInstaller.php:390
empty
Attr AllowedRel this is empty
Definition: Attr.AllowedRel.txt:7
as
as
Definition: Filter.ExtractStyleBlocks.Escaping.txt:10
ChWsbInstaller\actionRecompileMemberMenu
actionRecompileMemberMenu($bInstall=true)
Definition: ChWsbInstaller.php:563
ch_ltrim_str
ch_ltrim_str($sString, $sPrefix, $sReplace='')
Definition: utils.inc.php:1787
CH_WSB_INSTALLER_SUCCESS
const CH_WSB_INSTALLER_SUCCESS
Definition: ChWsbInstaller.php:14
ChWsbPFMCacher
Definition: ChWsbPFM.php:1432
$GLOBALS
$GLOBALS['iAdminPage']
Definition: advanced_settings.php:10
ChWsbFtp
Definition: ChWsbFtp.php:9
ChWsbInstaller\actionRecompileGlobalParamaters
actionRecompileGlobalParamaters($bInstall=true)
Definition: ChWsbInstaller.php:545
ChWsbMenu
Definition: ChWsbMenu.php:14
ChWsbInstaller\uninstall
uninstall($aParams)
Definition: ChWsbInstaller.php:196
getLangIdByName
getLangIdByName($sLangName)
Definition: languages.inc.php:136