/** * Rebuilds the data. * * @see XenForo_CacheRebuilder_Abstract::rebuild() */ public function rebuild($position = 0, array &$options = array(), &$detailedMessage = '') { $options = array_merge(array('root' => XenForo_Application::getInstance()->getRootDir() . '/install/data'), $options); $filesRoot = $options['root']; $detailedMessage = str_repeat(' . ', $position + 1); if ($position == 0) { XenForo_Model::create('XenForo_Model_AdminNavigation')->importAdminNavigationDevelopmentXml($filesRoot . '/admin_navigation.xml'); XenForo_Model::create('XenForo_Model_Admin')->importAdminPermissionsDevelopmentXml($filesRoot . '/admin_permissions.xml'); XenForo_Model::create('XenForo_Model_Option')->importOptionsDevelopmentXml($filesRoot . '/options.xml'); XenForo_Model::create('XenForo_Model_RoutePrefix')->importPrefixesDevelopmentXml($filesRoot . '/route_prefixes.xml'); } else { if ($position == 1) { XenForo_Model::create('XenForo_Model_StyleProperty')->importStylePropertyDevelopmentXml($filesRoot . '/style_properties.xml', 0); XenForo_Model::create('XenForo_Model_StyleProperty')->importStylePropertyDevelopmentXml($filesRoot . '/admin_style_properties.xml', -1); } else { XenForo_Model::create('XenForo_Model_CodeEvent')->importEventsDevelopmentXml($filesRoot . '/code_events.xml'); XenForo_Model::create('XenForo_Model_Cron')->importCronDevelopmentXml($filesRoot . '/cron.xml'); XenForo_Model::create('XenForo_Model_Permission')->importPermissionsDevelopmentXml($filesRoot . '/permissions.xml'); XenForo_Model::create('XenForo_Model_Node')->rebuildNodeTypeCache(); XenForo_Model::create('XenForo_Model_ContentType')->rebuildContentTypeCache(); XenForo_Model::create('XenForo_Model_Smilie')->rebuildSmilieCache(); return true; } } return $position + 1; }
public static function updateConfig($key, $value) { /** @var XenForo_Application $app */ $app = XenForo_Application::getInstance(); $path = $app->getRootDir() . '/library/config.php'; $originalContents = file_get_contents($path); $varNamePattern = '#(\\n|^)(?<varName>\\$config'; foreach (explode('.', $key) as $i => $keyPart) { // try to match the quote $varNamePattern .= '\\[([\'"]?)' . preg_quote($keyPart, '#') . '\\' . ($i + 3) . '\\]'; } $varNamePattern .= ').+(\\n|$)#'; $candidates = array(); $offset = 0; while (true) { if (!preg_match($varNamePattern, $originalContents, $matches, PREG_OFFSET_CAPTURE, $offset)) { break; } $offset = $matches[0][1] + strlen($matches[0][0]); $candidates[] = $matches; } if (count($candidates) !== 1) { XenForo_Helper_File::log(__METHOD__, sprintf('count($candidates) = %d', count($candidates))); return; } $matches = reset($candidates); $replacement = $matches[1][0] . $matches['varName'][0] . ' = ' . var_export($value, true) . ';' . $matches[5][0]; $contents = substr_replace($originalContents, $replacement, $matches[0][1], strlen($matches[0][0])); DevHelper_Generator_File::writeFile($path, $contents, true, false); }
/** * Exports an add-on's XML data. * * @return XenForo_ControllerResponse_Abstract */ public function actionZip() { $addOnId = $this->_input->filterSingle('addon_id', XenForo_Input::STRING); $addOn = $this->_getAddOnOrError($addOnId); $rootDir = XenForo_Application::getInstance()->getRootDir(); $zipPath = XenForo_Helper_File::getTempDir() . '/addon-' . $addOnId . '.zip'; if (file_exists($zipPath)) { unlink($zipPath); } $zip = new ZipArchive(); $res = $zip->open($zipPath, ZipArchive::CREATE); if ($res === TRUE) { $zip->addFromString('addon-' . $addOnId . '.xml', $this->_getAddOnModel()->getAddOnXml($addOn)->saveXml()); if (is_dir($rootDir . '/library/' . $addOnId)) { $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($rootDir . '/library/' . $addOnId)); foreach ($iterator as $key => $value) { $zip->addFile(realpath($key), str_replace($rootDir . '/', '', $key)); } } if (is_dir($rootDir . '/js/' . strtolower($addOnId))) { $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($rootDir . '/js/' . strtolower($addOnId))); foreach ($iterator as $key => $value) { $zip->addFile(realpath($key), str_replace($rootDir . '/', '', $key)); } } $zip->close(); } if (!file_exists($zipPath) || !is_readable($zipPath)) { return $this->responseError(new XenForo_Phrase('devkit_error_while_creating_zip')); } $this->_routeMatch->setResponseType('raw'); $attachment = array('filename' => 'addon-' . $addOnId . '_' . $addOn['version_string'] . '.zip', 'file_size' => filesize($zipPath), 'attach_date' => XenForo_Application::$time); $viewParams = array('attachment' => $attachment, 'attachmentFile' => $zipPath); return $this->responseView('XenForo_ViewAdmin_Attachment_View', '', $viewParams); }
/** * Rebuilds the data. * * @see XenForo_CacheRebuilder_Abstract::rebuild() */ public function rebuild($position = 0, array &$options = array(), &$detailedMessage = '') { $options = array_merge(array('file' => XenForo_Application::getInstance()->getRootDir() . '/install/data/email_templates.xml'), $options); /* @var $templateModel XenForo_Model_EmailTemplate */ $templateModel = XenForo_Model::create('XenForo_Model_EmailTemplate'); $document = new SimpleXMLElement($options['file'], 0, true); $templateModel->importEmailTemplatesAddOnXml($document, 'XenForo', false); return true; }
public function run($addonId, $path) { $addonModel = XenForo_Model::create('XenForo_Model_AddOn'); $this->printMessage('Importing ' . $addonId . ' from ' . realPath($path) . '...'); $print = 'importing addon.xml...'; $print .= str_repeat(' ', $this->_column - strlen($print)); $t = microtime(true); $m = memory_get_usage(true); $this->printMessage($print, false); $xml = new SimpleXMLElement($path . '/addon.xml', 0, true); $addOnData = array('addon_id' => (string) $xml['addon_id'], 'title' => (string) $xml['title'], 'version_string' => (string) $xml['version_string'], 'version_id' => (string) $xml['version_id'], 'install_callback_class' => (string) $xml['install_callback_class'], 'install_callback_method' => (string) $xml['install_callback_method'], 'uninstall_callback_class' => (string) $xml['uninstall_callback_class'], 'uninstall_callback_method' => (string) $xml['uninstall_callback_method'], 'url' => (string) $xml['url']); $version = file_get_contents($path . '/version.txt'); if ($version) { foreach ($addOnData as &$data) { $data = str_replace('{@revision}', $version, $data); } } $addOnData['version_id'] = (int) $addOnData['version_id']; $existingAddOn = $addonModel->verifyAddOnIsInstallable($addOnData, $addonModel->getAddonById($addonId) ? $addonId : false); $db = XenForo_Application::getDb(); XenForo_Db::beginTransaction($db); if ($addOnData['install_callback_class'] && $addOnData['install_callback_method']) { call_user_func(array($addOnData['install_callback_class'], $addOnData['install_callback_method']), $existingAddOn, $addOnData); } $addOnDw = XenForo_DataWriter::create('XenForo_DataWriter_AddOn'); if ($existingAddOn) { $addOnDw->setExistingData($existingAddOn, true); } $addOnDw->bulkSet($addOnData); $addOnDw->save(); $t = abs(microtime(true) - $t); $m = abs(memory_get_usage(true) - $m); $m = $m / 1024 / 1024; $this->printMessage('done (' . number_format($t, 2) . 'sec, ' . number_format($m, 2) . 'mb)'); $this->_importXml($addonId, $path . '/admin_navigation.xml', 'AdminNavigation'); $this->_importXml($addonId, $path . '/admin_permissions.xml', 'Admin', 'importAdminPermissionsAddOnXml'); $this->_importXml($addonId, $path . '/code_events.xml', 'CodeEvent', 'importEventsAddOnXml'); $this->_importXml($addonId, $path . '/code_event_listeners.xml', 'CodeEvent', 'importEventListenersAddOnXml'); $this->_importXml($addonId, $path . '/cron.xml', 'Cron', 'importCronEntriesAddOnXml'); $this->_importXml($addonId, $path . '/email_templates.xml', 'EmailTemplate'); $this->_importXml($addonId, $path . '/options.xml', 'Option'); $this->_importXml($addonId, $path . '/permissions.xml', 'Permission'); $this->_importXml($addonId, $path . '/route_prefixes.xml', 'RoutePrefix', 'importPrefixesAddOnXml'); $this->_importXml($addonId, $path . '/style_properties.xml', 'StyleProperty', 'importStylePropertyXml', array(0, $addonId)); $this->_importXml($addonId, $path . '/admin_style_properties.xml', 'StyleProperty', 'importStylePropertyXml', array(-1, $addonId)); foreach (array('templates/admin', 'templates/master', 'phrases') as $dir) { $this->_removeDirectory(XenForo_Application::getInstance()->getRootDir() . '/' . $dir . '/' . $addonId); } $this->_importXml($addonId, $path . '/templates.xml', 'Template'); $this->_importXml($addonId, $path . '/admin_templates.xml', 'AdminTemplate'); $this->_importXml($addonId, $path . '/phrases.xml', 'Phrase'); // TODO: bbcode XenForo_Db::commit($db); $this->printEmptyLine(); $this->manualRun('rebuild', false, false, array('caches' => 'addon')); }
protected function _connect() { $xenOptions = XenForo_Application::get('options'); $appName = $xenOptions->th_infusionsoftApi_appName; if (!$appName) { return false; } $client = new Zend_XmlRpc_Client('https://' . $appName . '.infusionsoft.com/api/xmlrpc'); $client->getHttpClient()->setConfig(array('sslcert' => XenForo_Application::getInstance()->getRootDir() . 'library/ThemeHouse/InfusionsoftApi/infusionsoft.pem')); return $client; }
protected function _preDispatchFirst($action) { $configFile = XenForo_Application::getInstance()->getConfigDir() . '/config.php'; if (file_exists($configFile)) { XenForo_Application::getInstance()->loadDefaultData(); } else { XenForo_Application::set('config', XenForo_Application::getInstance()->loadDefaultConfig()); } XenForo_Application::setDebugMode(true); @set_time_limit(120); }
/** * Inject the new autoloader instance. */ public static function extend($className) { if (!self::$_alreadySetup[$className]) { $lastClass = get_class(self::getInstance()); $proxy = 'XPCP_' . $className; eval('class ' . $proxy . ' extends ' . $lastClass . '{}'); $instance = $className::getExtendedInstance(); self::setInstance($instance); // might need to change to XenForo_Autoloader::setInstance $instance->setupAutoloader(XenForo_Application::getInstance()->getRootDir() . '/library'); } }
public function execute(array $deferred, array $data, $targetRunTime, &$status) { $data = array_merge(array('file' => XenForo_Application::getInstance()->getRootDir() . '/install/data/email_templates.xml'), $data); /* @var $templateModel XenForo_Model_EmailTemplate */ $templateModel = XenForo_Model::create('XenForo_Model_EmailTemplate'); $document = XenForo_Helper_DevelopmentXml::scanFile($data['file']); $templateModel->importEmailTemplatesAddOnXml($document, 'XenForo', false); $actionPhrase = new XenForo_Phrase('importing'); $typePhrase = new XenForo_Phrase('email_templates'); $status = sprintf('%s... %s', $actionPhrase, $typePhrase); return false; }
public function actionCodeEventListenersHint() { $q = $this->_input->filterSingle('q', XenForo_Input::STRING); $classes = array(); /** @var XenForo_Application $app */ $app = XenForo_Application::getInstance(); $libraryPath = sprintf('%s/library/', $app->getRootDir()); if (strlen($q) > 0 && preg_match('/[A-Z]/', $q)) { $dirPath = ''; $pattern = ''; $classPath = DevHelper_Generator_File::getClassPath($q); if (is_file($classPath)) { $classes[] = $q; } $_dirPath = preg_replace('/\\.php$/', '', $classPath); if (is_dir($_dirPath)) { $dirPath = $_dirPath; } else { $_parentDirPath = dirname($_dirPath); if (is_dir($_parentDirPath)) { $dirPath = $_parentDirPath; $pattern = basename($_dirPath); } } if ($dirPath !== '') { $files = scandir($dirPath); foreach ($files as $file) { if (substr($file, 0, 1) === '.') { continue; } if ($pattern !== '' && strpos($file, $pattern) !== 0) { continue; } $filePath = sprintf('%s/%s', $dirPath, $file); if (is_file($filePath)) { $contents = file_get_contents($filePath); if (preg_match('/class\\s(?<class>.+?)(\\sextends|{)/', $contents, $matches)) { $classes[] = $matches['class']; } } elseif (is_dir($filePath)) { $classes[] = str_replace('/', '_', str_replace($libraryPath, '', $filePath)); } } } } $results = array(); foreach ($classes as $class) { $results[$class] = $class; } $view = $this->responseView(); $view->jsonParams = array('results' => $results); return $view; }
public static function throwIfNotSetup() { if (empty($_SERVER['SCRIPT_FILENAME'])) { throw new XenForo_Exception('Cannot get value for $_SERVER[\'SCRIPT_FILENAME\']'); } /** @var XenForo_Application $app */ $app = XenForo_Application::getInstance(); $root = $app->getRootDir(); $candidates = array(file_get_contents($root . '/index.php'), file_get_contents($root . '/admin.php')); if (in_array(file_get_contents($_SERVER['SCRIPT_FILENAME']), $candidates, true) && !self::$_DevHelper_isSetup) { throw new XenForo_Exception('DevHelper_Autoloader must be used instead of XenForo_Autoloader'); } }
/** * Rebuilds the data. * * @see XenForo_CacheRebuilder_Abstract::rebuild() */ public function rebuild($position = 0, array &$options = array(), &$detailedMessage = '') { $options = array_merge(array('file' => XenForo_Application::getInstance()->getRootDir() . '/install/data/admin_templates.xml', 'offset' => 0, 'maxExecution' => 10), $options); /* @var $templateModel XenForo_Model_AdminTemplate */ $templateModel = XenForo_Model::create('XenForo_Model_AdminTemplate'); $document = new SimpleXMLElement($options['file'], 0, true); $result = $templateModel->importAdminTemplatesAddOnXml($document, 'XenForo', $options['maxExecution'], $options['offset']); if (is_int($result)) { $options['offset'] = $result; $detailedMessage = str_repeat(' . ', $position + 1); return $position + 1; // continue again } else { return true; } }
/** * Compares the hashes of a list of files with what is actually on the disk. * * @param array $hashes [file] => hash * * @return array List of errors, [file] => missing or mismatch */ public static function compareHashes(array $hashes) { $cwd = getcwd(); chdir(XenForo_Application::getInstance()->getRootDir()); $errors = array(); foreach ($hashes as $file => $hash) { if (file_exists($file)) { if (XenForo_Helper_Hash::getFileContentsHash(file_get_contents($file)) != $hash) { $errors[$file] = 'mismatch'; } } else { $errors[$file] = 'missing'; } } chdir($cwd); return $errors; }
public static function ConvertFilename(&$attachmentFile) { $xf_code_root = XenForo_Application::getInstance()->getRootDir(); $internal_data = XenForo_Helper_File::getInternalDataPath(); $internal_data_uri = self::getInternalDataUrl(); if ($internal_data_uri && strpos($attachmentFile, $internal_data) === 0) { $attachmentFile = str_replace($internal_data, $internal_data_uri, $attachmentFile); return true; } else { if (strpos($attachmentFile, $xf_code_root) === 0) { $attachmentFile = str_replace($xf_code_root, '', $attachmentFile); return true; } else { return false; } } }
public static function installCode($existingAddOn, $addOnData) { $endVersion = $addOnData['version_id']; $strVersion = $existingAddOn ? $existingAddOn['version_id'] + 1 : 1; $install = self::getInstance(); for ($i = $strVersion; $i <= $endVersion; $i++) { $method = '_install_' . $i; if (method_exists($install, $method)) { $install->{$method}(); } } if (XenForo_Application::autoload('EWRmedio_XML_Premium')) { XenForo_Model::create('EWRmedio_XML_Premium')->rebuildServices(); } else { $targetXml = XenForo_Application::getInstance()->getRootDir() . '/library/EWRmedio/XML'; XenForo_Model::create('EWRmedio_Model_Services')->importService($targetXml . '/youtube.xml'); } }
public function getUpgrade($versionId) { $versionId = intval($versionId); if (!$versionId) { throw new XenForo_Exception('No upgrade version ID specified.'); } $searchDir = XenForo_Application::getInstance()->getRootDir() . '/library/XenForo/Install/Upgrade'; $matches = glob($searchDir . '/' . $versionId . '*.php'); foreach ($matches as $file) { $file = basename($file); if (intval($file) == $versionId) { require $searchDir . '/' . $file; $class = 'XenForo_Install_Upgrade_' . intval($file); return new $class(); } } throw new XenForo_Exception('Could not find the specified upgrade.'); }
public function execute(array $deferred, array $data, $targetRunTime, &$status) { $data = array_merge(array('root' => XenForo_Application::getInstance()->getRootDir() . '/install/data', 'position' => 0), $data); $filesRoot = $data['root']; if ($data['position'] == 0) { XenForo_Model::create('XenForo_Model_AdminNavigation')->importAdminNavigationDevelopmentXml($filesRoot . '/admin_navigation.xml'); XenForo_Model::create('XenForo_Model_Admin')->importAdminPermissionsDevelopmentXml($filesRoot . '/admin_permissions.xml'); } else { if ($data['position'] == 1) { XenForo_Model::create('XenForo_Model_Option')->importOptionsDevelopmentXml($filesRoot . '/options.xml'); XenForo_Model::create('XenForo_Model_RoutePrefix')->importPrefixesDevelopmentXml($filesRoot . '/route_prefixes.xml'); } else { if ($data['position'] == 2) { XenForo_Model::create('XenForo_Model_StyleProperty')->importStylePropertyDevelopmentXml($filesRoot . '/style_properties.xml', 0); XenForo_Model::create('XenForo_Model_StyleProperty')->importStylePropertyDevelopmentXml($filesRoot . '/admin_style_properties.xml', -1); } else { if ($data['position'] == 3) { XenForo_Model::create('XenForo_Model_CodeEvent')->importEventsDevelopmentXml($filesRoot . '/code_events.xml'); XenForo_Model::create('XenForo_Model_Cron')->importCronDevelopmentXml($filesRoot . '/cron.xml'); XenForo_Model::create('XenForo_Model_Permission')->importPermissionsDevelopmentXml($filesRoot . '/permissions.xml'); } else { XenForo_Model::create('XenForo_Model_Node')->rebuildNodeTypeCache(); XenForo_Model::create('XenForo_Model_ContentType')->rebuildContentTypeCache(); XenForo_Model::create('XenForo_Model_AddOn')->rebuildActiveAddOnCache(); XenForo_Model::create('XenForo_Model_Smilie')->rebuildSmilieCache(); XenForo_Model::create('XenForo_Model_BbCode')->rebuildBbCodeCache(); XenForo_Model::create('XenForo_Model_UserTitleLadder')->rebuildUserTitleLadderCache(); XenForo_Model::create('XenForo_Model_UserField')->rebuildUserFieldCache(); XenForo_Model::create('XenForo_Model_AdminSearch')->rebuildSearchTypesCache(); XenForo_Model::create('XenForo_Model_CodeEvent')->rebuildEventListenerCache(); XenForo_Model::create('XenForo_Model_Notice')->rebuildNoticeCache(); XenForo_Model::create('XenForo_Model_RouteFilter')->rebuildRouteFilterCache(); XenForo_Model::create('XenForo_Model_Option')->updateOption('jsLastUpdate', XenForo_Application::$time); return false; } } } } $data['position']++; $actionPhrase = new XenForo_Phrase('importing'); $typePhrase = new XenForo_Phrase('core_master_data'); $status = sprintf('%s... %s %s', $actionPhrase, $typePhrase, str_repeat(' . ', $data['position'])); return $data; }
public function execute(array $deferred, array $data, $targetRunTime, &$status) { $data = array_merge(array('file' => XenForo_Application::getInstance()->getRootDir() . '/install/data/phrases.xml', 'offset' => 0, 'position' => 0), $data); /* @var $phraseModel XenForo_Model_Phrase */ $phraseModel = XenForo_Model::create('XenForo_Model_Phrase'); $document = XenForo_Helper_DevelopmentXml::scanFile($data['file']); $result = $phraseModel->importPhrasesAddOnXml($document, 'XenForo', $targetRunTime, $data['offset']); if (is_int($result)) { $data['offset'] = $result; $data['position']++; $actionPhrase = new XenForo_Phrase('importing'); $typePhrase = new XenForo_Phrase('phrases'); $status = sprintf('%s... %s %s', $actionPhrase, $typePhrase, str_repeat(' . ', $data['position'])); return $data; // continue again } else { return false; } }
public static function createDirectory($path, $createIndexHtml = false) { $created = XenForo_Helper_File::createDirectory($path, $createIndexHtml); // XenForo won't create a directory in the root, manually do it here if (!$created) { $path = preg_replace('#/+$#', '', $path); $path = str_replace('\\', '/', $path); $parts = explode('/', $path); $checkOnRoot = implode('/', array_slice($parts, 0, count($parts) - 1)); if (XenForo_Application::getInstance()->getRootDir() == $checkOnRoot) { if (!file_exists($path)) { if (mkdir($path)) { $created = true; } } } } return $created; }
public function constructPaths($inputsXDS) { $libraryPath = XenForo_Application::getInstance()->getRootDir() . '/library'; $addon = $inputsXDS['title']; if (!empty($inputsXDS['folders_cp_name']) or !empty($inputsXDS['folders_ca_name']) or !empty($inputsXDS['folders_model_name']) or !empty($inputsXDS['folders_dw_name']) or !empty($inputsXDS['folders_install_name']) or !empty($inputsXDS['xds_prefix_public_folder_name']) or !empty($inputsXDS['xds_prefix_public_file_name']) or !empty($inputsXDS['xds_prefix_admin_folder_name']) or !empty($inputsXDS['xds_prefix_admin_file_name']) or !empty($inputsXDS['xds_prefix_admin_file_name'])) { //main folder XenForo_Helper_File::createDirectory("{$libraryPath}/{$addon}"); //ControllerAdmin Folder if (!empty($inputsXDS['folders_ca_name'])) { XenForo_Helper_File::createDirectory("{$libraryPath}/{$addon}/" . $inputsXDS['folders_ca_name'] . ""); } //ControllerPublic Folder if (!empty($inputsXDS['folders_cp_name'])) { XenForo_Helper_File::createDirectory("{$libraryPath}/{$addon}/" . $inputsXDS['folders_cp_name'] . ""); } //Model Folder if (!empty($inputsXDS['folders_model_name'])) { XenForo_Helper_File::createDirectory("{$libraryPath}/{$addon}/" . $inputsXDS['folders_model_name'] . ""); } //DataWriter Folder if (!empty($inputsXDS['folders_dw_name'])) { XenForo_Helper_File::createDirectory("{$libraryPath}/{$addon}/" . $inputsXDS['folders_dw_name'] . ""); } //Install Folder if (!empty($inputsXDS['folders_install_name'])) { XenForo_Helper_File::createDirectory("{$libraryPath}/{$addon}/" . $inputsXDS['folders_install_name'] . ""); } //Prefix Folders if (!empty($inputsXDS['xds_prefix_public_folder_name']) or !empty($inputsXDS['xds_prefix_admin_folder_name'])) { XenForo_Helper_File::createDirectory("{$libraryPath}/{$addon}/Route"); if (!empty($inputsXDS['xds_prefix_public_folder_name'])) { XenForo_Helper_File::createDirectory("{$libraryPath}/{$addon}/Route/" . $inputsXDS['xds_prefix_public_folder_name'] . ""); } if (!empty($inputsXDS['xds_prefix_admin_folder_name'])) { XenForo_Helper_File::createDirectory("{$libraryPath}/{$addon}/Route/" . $inputsXDS['xds_prefix_admin_folder_name'] . ""); } } } //Data Folder if (!empty($inputsXDS['xds_input_data_name'])) { XenForo_Helper_File::createDirectory(XenForo_Application::getInstance()->getRootDir() . '/data/' . $inputsXDS['xds_input_data_name'] . ''); } }
public function actionStep1b() { $configFile = XenForo_Application::getInstance()->getConfigDir() . '/config.php'; if (!file_exists($configFile)) { return $this->responseError(new XenForo_Phrase('config_file_x_could_not_be_found', array('file' => $configFile))); } $config = array(); require $configFile; $db = $this->_testConfig($config, $error); if ($error) { return $this->responseError($error); } $errors = $this->_getInstallModel()->getRequirementErrors($db); if ($errors) { return $this->responseError($errors); } $viewParams = array('existingInstall' => $this->_getInstallModel()->hasApplicationTables()); return $this->_getInstallWrapper(1, $this->responseView('XenForo_Install_View_Install_Step1b', 'install_step1b', $viewParams)); }
public static function frontControllerPreDispatch(XenForo_FrontController $fc, XenForo_RouteMatch &$routeMatch) { if (defined('DEVTOOLS_AUTOLOADER_SETUP') or self::$_checked or $routeMatch->getResponseType() != 'html') { return; } $paths = XenForo_Application::getInstance()->loadRequestPaths(); $url = $paths['fullBasePath'] . 'filesync.php'; if (class_exists('XenForo_Dependencies_Admin', false)) { $url .= '?admin=1'; } $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); ob_start(); curl_exec($ch); curl_close($ch); self::$_syncOutput = ob_get_contents(); $logs = explode('<pre>', self::$_syncOutput); $errors = array(); foreach ($logs as $log) { $lines = explode("\n", $log); foreach ($lines as $line) { if (strpos($line, 'E:') === 0) { $origLine = str_replace('E: ', '', $line); $line = '<strong>' . htmlspecialchars($origLine); $pos = strpos($line, ':'); $line = substr($line, 0, $pos) . '</strong><i>' . substr($line, $pos); $pos = strpos($line, ' in ' . DIRECTORY_SEPARATOR); // hacked him! $line = substr($line, 0, $pos) . '</i>' . substr($line, $pos); $errors[] = $line; DevTools_ChromePhp::error(trim($origLine)); } else { DevTools_ChromePhp::log(trim($line)); } } } ob_end_clean(); self::$_checked = true; self::$_errors = $errors; }
public function writeTemplates($fileClass, $styleId) { DevTools_Helper_File::createDirectory(XenForo_Application::getInstance()->getRootDir() . DIRECTORY_SEPARATOR . 'templates'); $templates = $this->getTemplates($styleId); $fileTemplate = new $fileClass(); foreach ($templates as $template) { $template['id'] = $template['template_id']; $filePath = $fileTemplate->getDirectory($template) . DIRECTORY_SEPARATOR . $fileTemplate->getFileName($template); if (!file_exists($filePath)) { $contents = $this->getModelFromCache('XenForo_Model_StyleProperty')->replacePropertiesInTemplateForEditor($template['template'], $styleId, $fileTemplate->getPropertiesInStyle($styleId)); $contents = $this->getModelFromCache('XenForo_Model_Template')->replaceIncludesWithLinkRel($contents); $fileTemplate->printDebugInfo('Writing ' . $fileTemplate->getDataType() . ' "' . $template['title'] . '" to ' . $filePath . '...'); DevTools_Helper_File::write($filePath, $contents); $file = new $fileClass($filePath); $file->touchDb(); $fileTemplate->printDebugInfo(" done\n"); } } foreach ($this->getModelFromCache('XenForo_Model_AddOn')->getAllAddOns() as $addon) { DevTools_Helper_File::createDirectory($fileTemplate->getDirectory($addon)); } }
public function handle($addOnId) { try { $addOnId = strtolower($addOnId); $root = XenForo_Application::getInstance()->getRootDir() . '/styles'; if (!($root = realpath($root)) || !is_dir($root)) { return; } $source = $root . '/default/' . $addOnId; if (!($source = realpath($source)) || !is_dir($source)) { return; } $available = GFNCore_Helper_Directory::read($root, false); foreach ($available as $i => $path) { if (is_dir($path) && basename($path) != 'default') { $target = $path . '/' . $addOnId; GFNCore_Helper_Directory::copy($source, $target); } } } catch (Exception $e) { XenForo_Error::logException($e, false); } }
public static function logException(Exception $e, $rollbackTransactions = true) { try { $db = XenForo_Application::get('db'); if ($db->getConnection()) { $rootDir = XenForo_Application::getInstance()->getRootDir(); $file = $e->getFile(); if (strpos($file, $rootDir) === 0) { $file = substr($file, strlen($rootDir)); if (strlen($file) && ($file[0] == '/' || $file[0] == '\\')) { $file = substr($file, 1); } } $requestPaths = XenForo_Application::get('requestPaths'); $request = array('url' => $requestPaths['fullUri'], '_GET' => $_GET, '_POST' => $_POST); if ($rollbackTransactions) { XenForo_Db::rollbackAll($db); } $db->insert('xf_error_log', array('exception_date' => XenForo_Application::$time, 'user_id' => XenForo_Visitor::hasInstance() ? XenForo_Visitor::getUserId() : null, 'ip_address' => XenForo_Model::create('XenForo_Model_Login')->convertIpToLong(), 'exception_type' => get_class($e), 'message' => $e->getMessage(), 'filename' => $file, 'line' => $e->getLine(), 'trace_string' => $e->getTraceAsString(), 'request_state' => serialize($request))); } } catch (Exception $e) { } }
public static function installCode($existingAddOn, $addOnData) { $endVersion = $addOnData['version_id']; $strVersion = $existingAddOn ? $existingAddOn['version_id'] + 1 : 50; if ($strVersion < 50) { throw new XenForo_Exception('You must uninstall the previous version of <b>[8wayRun.Com] XenPorta (Portal)</b> before you install this new version...', true); } $install = self::getInstance(); for ($i = $strVersion; $i <= $endVersion; $i++) { $method = '_install_' . $i; if (method_exists($install, $method)) { $install->{$method}(); } } $blocksModel = XenForo_Model::create('EWRporta_Model_Blocks'); $rootDir = XenForo_Application::getInstance()->getRootDir(); if ($handle = opendir($xmlDir = $rootDir . '/library/EWRporta/XML')) { while (false !== ($file = readdir($handle))) { if (stristr($file, 'xml')) { $blocksModel->installBlockXmlFromFile($xmlDir . '/' . $file); } } opendir($xmlDir); } if ($handle = opendir($xmlDir = $rootDir . '/library/EWRporta/Block/XML')) { while (false !== ($file = readdir($handle))) { if (stristr($file, 'xml')) { $blockId = str_ireplace('.xml', '', $file); if ($blocksModel->getBlockById($blockId)) { $blocksModel->installBlockXmlFromFile($xmlDir . '/' . $file); } } } opendir($xmlDir); } }
/** * Returns the path to the template development directory, if it has been configured and exists * * @return string Path to templates directory */ public function getTemplateDevelopmentDirectory() { $config = XenForo_Application::get('config'); if (!$config->debug || !$config->development->directory) { return ''; } return XenForo_Application::getInstance()->getRootDir() . '/' . $config->development->directory . '/file_output/templates'; }
/** * Gets the file name for the development output. * * @return string */ public function getOptionsDevelopmentFileName() { $config = XenForo_Application::get('config'); if (!$config->debug || !$config->development->directory) { return ''; } return XenForo_Application::getInstance()->getRootDir() . '/' . $config->development->directory . '/file_output/options.xml'; }
protected function _copyrightNotice() { if (!isset(XenForo_Application::getInstance()->adminStyleModifiedDate)) { $newContents = preg_replace('#(<div class="breadBoxBottom">\\s*<nav>.*</nav>\\s*</div>)#Us', '$1' . self::$copyrightNotice, $this->_contents); if ($newContents != $this->_contents) { $this->_contents = $newContents; } else { $this->_contents = preg_replace('#(<body.*>.*)</body>#Us', '$1' . self::$copyrightNotice . '</body>', $this->_contents); } } self::$_copyrightNotice = true; }
/** * * @param string $action */ protected function _upgradeAddOns() { $template = new XenForo_Template_Admin('PAGE_CONTAINER_SIMPLE', array('jQuerySource' => XenForo_Dependencies_Abstract::getJquerySource(), 'xenOptions' => XenForo_Application::get('options')->getOptions(), '_styleModifiedDate' => XenForo_Application::get('adminStyleModifiedDate'))); $template->setLanguageId(1); $template->setParam('title', 'Upgrading Add-ons...'); $addOns = array_keys(self::getUpgradeAddOns(true)); $addOnModel = XenForo_Model::create('XenForo_Model_AddOn'); $nextAddOnId = ''; if (count($addOns)) { $next = self::$_controller->getInput()->filterSingle('next', XenForo_Input::STRING); if ($next) { $addOn = $next; } else { $addOn = reset($addOns); } for ($i = 0; $i < count($addOns); $i++) { if ($addOns[$i] != $addOn) { unset($addOns[$i]); continue; } break; } $fileName = XenForo_Application::getInstance()->getRootDir() . '/install/data/addon-' . $addOn . '.xml'; try { $caches = $addOnModel->installAddOnXmlFromFile($fileName, $addOn); $template->setParam('contents', '<form action="' . XenForo_Link::buildAdminLink('add-ons/upgrade-all-from-xml') . '" class="xenForm formOverlay CacheRebuild" method="post"> <p id="ProgressText">Upgrading... <span class="RebuildMessage"></span> <span class="DetailedMessage"></span></p> <p id="ErrorText" style="display: none">' . new XenForo_Phrase('error_occurred_or_request_stopped') . '</p> <input type="submit" class="button" value="Continue Upgrading" /> <input type="hidden" name="_xfToken" value="' . XenForo_Visitor::getInstance()->get('csrf_token_page') . '" /> </form>'); } catch (Exception $e) { if (count($addOns) == 1) { $template->setParam('contents', 'Upgrade error (' . $addOn . '). Please use the <a href="' . XenForo_Link::buildAdminLink('add-ons/upgrade', array('addon_id' => $addOn)) . '">standard upgrade tool</a> and report any error messages to the developer.'); } else { unset($addOns[array_search($addOn, $addOns)]); $nextAddOnId = reset($addOns); $template->setParam('contents', '<form action="' . XenForo_Link::buildAdminLink('add-ons/upgrade-all-from-xml') . '" class="xenForm formOverlay CacheRebuild" method="post"> <p id="ProgressText">Upgrading... <span class="RebuildMessage"></span> <span class="DetailedMessage"></span></p> <p id="ErrorText" style="display: none">' . new XenForo_Phrase('error_occurred_or_request_stopped') . '</p> <input type="submit" class="button" value="Continue Upgrading" /> <input type="hidden" name="next" value="' . $nextAddOnId . '" /> <input type="hidden" name="_xfToken" value="' . XenForo_Visitor::getInstance()->get('csrf_token_page') . '" /> </form>'); } } } else { $caches = $addOnModel->rebuildAddOnCaches(); } if (!count($addOns) && (isset($caches) || XenForo_Application::$versionId > 1020000)) { if (self::$_controller->getRouteMatch()->getResponseType() == 'json') { header('Content-Type: application/json; charset=UTF-8'); echo json_encode(array('_redirectTarget' => XenForo_Link::buildAdminLink('index'))); } else { header('Location: ' . XenForo_Link::buildAdminLink('index')); } } elseif (count($addOns) == 1 && (isset($caches) || XenForo_Application::$versionId > 1020000)) { if (XenForo_Application::$versionId > 1020000) { $url = XenForo_Link::buildAdminLink('tools/run-deferred'); } else { $url = XenForo_Link::buildAdminLink('tools/cache-rebuild', null, array('caches' => json_encode($caches))); } if (self::$_controller->getRouteMatch()->getResponseType() == 'json') { header('Content-Type: application/json; charset=UTF-8'); echo json_encode(array('_redirectTarget' => $url)); } else { header('Location: ' . $url); } } else { if (self::$_controller->getRouteMatch()->getResponseType() == 'json') { echo json_encode(array('_redirectTarget' => XenForo_Link::buildAdminLink('add-ons/upgrade-all-from-xml', array(), array('next' => $nextAddOnId)))); } else { $output = $template->render(); $output = str_replace("<!--XenForo_Require:JS-->", '<script src="js/xenforo/cache_rebuild.js"></script>', $output); echo $output; } } exit; }