本文整理汇总了PHP中XenForo_Application::getInstance方法的典型用法代码示例。如果您正苦于以下问题:PHP XenForo_Application::getInstance方法的具体用法?PHP XenForo_Application::getInstance怎么用?PHP XenForo_Application::getInstance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XenForo_Application
的用法示例。
在下文中一共展示了XenForo_Application::getInstance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: rebuild
/**
* 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;
}
示例2: updateConfig
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);
}
示例3: actionZip
/**
* 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);
}
示例4: rebuild
/**
* 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;
}
示例5: run
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'));
}
示例6: _connect
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;
}
示例7: _preDispatchFirst
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);
}
示例8: extend
/**
* 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');
}
}
示例9: execute
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;
}
示例10: actionCodeEventListenersHint
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;
}
示例11: throwIfNotSetup
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');
}
}
示例12: rebuild
/**
* 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;
}
}
示例13: compareHashes
/**
* 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;
}
示例14: ConvertFilename
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;
}
}
}
示例15: installCode
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');
}
}