public function renderXml()
 {
     $system =& $this->_params['system'];
     $widgets =& $this->_params['widgets'];
     $document = new DOMDocument('1.0', 'utf-8');
     $document->formatOutput = true;
     $rootNode = $document->createElement('widget_framework');
     $rootNode->setAttribute('version', $system['version_string']);
     $document->appendChild($rootNode);
     foreach ($widgets as $widget) {
         $widgetNode = $document->createElement('widget');
         $widgetNode->setAttribute('title', $widget['title']);
         $widgetNode->setAttribute('class', $widget['class']);
         $optionsNode = $document->createElement('options');
         $optionsString = $widget['options'];
         if (!is_string($optionsString)) {
             $optionsString = serialize($optionsString);
         }
         $optionsData = XenForo_Helper_DevelopmentXml::createDomCdataSection($document, $optionsString);
         $optionsNode->appendChild($optionsData);
         $widgetNode->appendChild($optionsNode);
         $widgetNode->setAttribute('position', $widget['position']);
         $widgetNode->setAttribute('display_order', $widget['display_order']);
         $widgetNode->setAttribute('active', $widget['active']);
         $rootNode->appendChild($widgetNode);
     }
     $this->setDownloadFileName('widget_framework-widgets-' . XenForo_Template_Helper_Core::date(XenForo_Application::$time, 'YmdHi') . '.xml');
     return $document->saveXml();
 }
 public function renderXml()
 {
     $document = new DOMDocument('1.0', 'utf-8');
     $document->formatOutput = true;
     $rootNode = $document->createElement('errors');
     $document->appendChild($rootNode);
     if (isset($this->_params['exception']) && $this->_params['exception'] instanceof Exception) {
         $e = $this->_params['exception'];
         $exceptionMessage = $e->getMessage();
         $rootNode->appendChild(XenForo_Helper_DevelopmentXml::createDomElement($document, 'error', $exceptionMessage));
         $traceNode = $document->createElement('trace');
         foreach ($e->getTrace() as $trace) {
             $function = (isset($trace['class']) ? $trace['class'] . $trace['type'] : '') . $trace['function'];
             if (!isset($trace['file'])) {
                 $trace['file'] = '';
             }
             if (!isset($trace['line'])) {
                 $trace['line'] = '';
             }
             $entryNode = $document->createElement('entry');
             $entryNode->setAttribute('function', $function);
             $entryNode->setAttribute('file', $trace['file']);
             $entryNode->setAttribute('line', $trace['line']);
             $traceNode->appendChild($entryNode);
         }
         $rootNode->appendChild($traceNode);
     } else {
         $rootNode->appendChild($document->createElement('error', 'Unknown error, trace unavailable'));
     }
     return $document->saveXML();
 }
示例#3
0
 /**
  * Simple handler for XML redirects - do not redirect, just send status:ok and redirect:$redirectTarget
  *
  * @param integer Type of redirect. See {@link XenForo_ControllerResponse_Redirect}
  * @param string  Target to redirect to
  * @param mixed   Redirect message
  *
  * @return string XML response (response tag)
  */
 public function renderRedirect($redirectType, $redirectTarget, $redirectMessage = null, array $redirectParams = array())
 {
     $document = new DOMDocument('1.0', 'utf-8');
     $document->formatOutput = true;
     $rootNode = $document->createElement('response');
     XenForo_Helper_DevelopmentXml::createDomElements($rootNode, array('_redirectStatus' => 'ok', '_redirectTarget' => $redirectTarget, '_redirectMessage' => is_null($redirectMessage) ? new XenForo_Phrase('redirect_changes_saved_successfully') : $redirectMessage, 'jsonParams' => XenForo_ViewRenderer_Json::jsonEncodeForOutput($redirectParams)));
     $document->appendChild($rootNode);
     return $document->saveXML();
 }
示例#4
0
 public function renderXml()
 {
     $document = new DOMDocument('1.0', 'utf-8');
     $document->formatOutput = true;
     $rootNode = $document->createElement('user');
     $document->appendChild($rootNode);
     XenForo_Helper_DevelopmentXml::createDomElements($rootNode, $this->_params['user']);
     return $document->saveXML();
 }
示例#5
0
 public function appendAdminTemplatesXml(DOMElement $rootNode, $blockId)
 {
     $document = $rootNode->ownerDocument;
     $adminTemplates = $this->getAdminTemplatesByBlock($blockId);
     foreach ($adminTemplates as $template) {
         $templateNode = $document->createElement('template');
         $templateNode->setAttribute('title', $template['title']);
         $templateNode->appendChild(XenForo_Helper_DevelopmentXml::createDomCdataSection($document, $template['template']));
         $rootNode->appendChild($templateNode);
     }
 }
示例#6
0
文件: Bbm.php 项目: Sywooch/forums
 public static function scanXmlFile($xmlFile)
 {
     if (self::callbackChecker('XenForo_Helper_DevelopmentXml', 'scanFile')) {
         //Protected method
         $file = XenForo_Helper_DevelopmentXml::scanFile($xmlFile);
     } else {
         //Classic PHP method
         $file = new SimpleXMLElement($xmlFile, null, true);
     }
     return $file;
 }
示例#7
0
 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;
 }
示例#8
0
 public function importListenersXml(SimpleXMLElement $xml, $blockId)
 {
     $db = $this->_getDb();
     XenForo_Db::beginTransaction($db);
     $this->deleteListenersByBlock($blockId);
     $listeners = XenForo_Helper_DevelopmentXml::fixPhpBug50670($xml->listener);
     foreach ($listeners as $event) {
         $eventId = (string) $event['event_id'];
         $dw = XenForo_DataWriter::create('XenForo_DataWriter_CodeEventListener');
         $dw->setOption(XenForo_DataWriter_CodeEventListener::OPTION_REBUILD_CACHE, false);
         $dw->bulkSet(array('event_id' => (string) $event['event_id'], 'execute_order' => (string) $event['execute_order'], 'callback_class' => (string) $event['callback_class'], 'callback_method' => (string) $event['callback_method'], 'active' => (string) $event['active'], 'description' => (string) $event['description']));
         $dw->save();
     }
     $this->getModelFromCache('XenForo_Model_CodeEvent')->rebuildEventListenerCache();
     XenForo_Db::commit($db);
     return;
 }
示例#9
0
 public function importPhrasesXml(SimpleXMLElement $xml, $blockId)
 {
     $existingPhrases = $this->getPhrasesByBlock($blockId);
     $db = $this->_getDb();
     XenForo_Db::beginTransaction($db);
     $phrases = XenForo_Helper_DevelopmentXml::fixPhpBug50670($xml->phrase);
     foreach ($phrases as $phrase) {
         $phraseName = (string) $phrase['title'];
         $dw = XenForo_DataWriter::create('XenForo_DataWriter_Phrase');
         if (isset($existingPhrases[$phraseName])) {
             $dw->setExistingData($existingPhrases[$phraseName], true);
         }
         $dw->bulkSet(array('language_id' => '0', 'title' => $phraseName, 'phrase_text' => (string) $phrase));
         $dw->save();
     }
     XenForo_Db::commit($db);
     return;
 }
 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;
     }
 }
示例#11
0
文件: Widget.php 项目: Sywooch/forums
 public function importFromFile($fileName, $deleteAll = false)
 {
     if (!file_exists($fileName) || !is_readable($fileName)) {
         throw new XenForo_Exception(new XenForo_Phrase('please_enter_valid_file_name_requested_file_not_read'), true);
     }
     try {
         $document = new SimpleXMLElement($fileName, 0, true);
     } catch (Exception $e) {
         throw new XenForo_Exception(new XenForo_Phrase('provided_file_was_not_valid_xml_file'), true);
     }
     if ($document->getName() != 'widget_framework') {
         throw new XenForo_Exception(new XenForo_Phrase('wf_provided_file_is_not_an_widgets_xml_file'), true);
     }
     $widgets = XenForo_Helper_DevelopmentXml::fixPhpBug50670($document->widget);
     XenForo_Db::beginTransaction();
     if ($deleteAll) {
         // get global widgets from database and delete them all!
         // NOTE: ignore widget page widgets
         $existingWidgets = $this->getGlobalWidgets(false, false);
         foreach ($existingWidgets as $existingWidget) {
             $dw = XenForo_DataWriter::create('WidgetFramework_DataWriter_Widget');
             $dw->setExtraData(WidgetFramework_DataWriter_Widget::EXTRA_DATA_SKIP_REBUILD, true);
             $dw->setExistingData($existingWidget);
             $dw->delete();
         }
     }
     foreach ($widgets as $widget) {
         $dw = XenForo_DataWriter::create('WidgetFramework_DataWriter_Widget');
         $dw->setExtraData(WidgetFramework_DataWriter_Widget::EXTRA_DATA_SKIP_REBUILD, true);
         $dw->set('title', $widget['title']);
         $dw->set('class', $widget['class']);
         $dw->set('position', $widget['position']);
         $dw->set('display_order', $widget['display_order']);
         $dw->set('active', intval($widget['active']));
         $dw->set('options', unserialize(XenForo_Helper_DevelopmentXml::processSimpleXmlCdata($widget->options)));
         $dw->save();
     }
     $this->buildCache();
     XenForo_Db::commit();
 }
示例#12
0
 /**
  * Imports admin templates.
  * It does not check for conflicts.
  *
  * @param SimpleXMLElement $xml
  */
 public function importAdminTemplatesFieldXml(SimpleXMLElement $xml)
 {
     $db = $this->_getDb();
     if ($xml->template === null) {
         return;
     }
     XenForo_Db::beginTransaction($db);
     foreach ($xml->template as $template) {
         $templateName = (string) $template['title'];
         $dw = XenForo_DataWriter::create('XenForo_DataWriter_AdminTemplate');
         $existingTemplate = $this->_getAdminTemplateModel()->getAdminTemplateByTitle($templateName);
         if ($existingTemplate) {
             $dw->setExistingData($existingTemplate);
         }
         $dw->setOption(XenForo_DataWriter_AdminTemplate::OPTION_DEV_OUTPUT_DIR, '');
         $dw->setOption(XenForo_DataWriter_AdminTemplate::OPTION_FULL_COMPILE, false);
         $dw->setOption(XenForo_DataWriter_AdminTemplate::OPTION_TEST_COMPILE, false);
         $dw->bulkSet(array('title' => (string) $template['title'], 'template' => XenForo_Helper_DevelopmentXml::processSimpleXmlCdata($template), 'addon_id' => (string) $template['addon_id']));
         $dw->save();
     }
     XenForo_Db::commit($db);
 }
 public function parseSVG($filename)
 {
     $svgfile = null;
     try {
         if (method_exists('XenForo_Helper_DevelopmentXml', 'scanFile')) {
             $svgfile = XenForo_Helper_DevelopmentXml::scanFile($filename);
         } else {
             $svgfile = new SimpleXMLElement($filename, 0, true);
         }
     } catch (Exception $e) {
         XenForo_Error::logException($e, false);
         $svgfile = null;
     }
     if (empty($svgfile)) {
         return null;
     }
     // check for bad tags
     $options = XenForo_Application::getOptions();
     $badTags = array_fill_keys(explode(',', strtolower($options->SV_AttachImpro_badTags)), true);
     $badAttributes = array_fill_keys(explode(',', strtolower($options->SV_AttachmentImprovements_badAttributes)), true);
     return $this->_scanSVG($svgfile, $badTags, $badAttributes);
 }
示例#14
0
文件: Smilie.php 项目: Sywooch/forums
 /**
  * Imports a smilie XML file.
  *
  * @param SimpleXMLElement $document
  * @param string $smilieGroupId
  * @param integer $overwriteSmilieId
  *
  * @return array List of cache rebuilders to run
  */
 public function importSmiliesXml(SimpleXMLElement $document, $overwrite = 0)
 {
     if ($document->getName() != 'smilies') {
         throw new XenForo_Exception(new XenForo_Phrase('waindigo_provided_file_is_not_valid_smilie_xml_smilieimporter'), true);
     }
     $smilies = XenForo_Helper_DevelopmentXml::fixPhpBug50670($document->smilie);
     $db = $this->_getDb();
     /* @var $smilie SimpleXMLElement */
     XenForo_Db::beginTransaction($db);
     foreach ($smilies as $smilie) {
         $smilieText = XenForo_Helper_DevelopmentXml::processSimpleXmlCdata($smilie->smilie_text);
         $existing = $this->getSmiliesByText($smilieText);
         $updateText = array();
         foreach ($existing as $text => $existingSmilie) {
             if ($overwrite) {
                 if (isset($updateText[$existingSmilie['smilie_id']])) {
                     $existingSmilie['smilie_text'] = $updateText[$existingSmilie['smilie_id']];
                 }
                 $existingSmilie['smilie_text'] = preg_split('/\\R/m', $existingSmilie['smilie_text']);
                 unset($existingSmilie['smilie_text'][array_search($text, $existingSmilie['smilie_text'])]);
                 if (!empty($existingSmilie['smilie_text'])) {
                     $updateText[$existingSmilie['smilie_id']] = implode(PHP_EOL, $existingSmilie['smilie_text']);
                 } else {
                     $dw = XenForo_DataWriter::create('XenForo_DataWriter_Smilie', XenForo_DataWriter::ERROR_SILENT);
                     $dw->setExistingData($existingSmilie['smilie_id']);
                     $dw->delete();
                 }
             } else {
                 $smilieText = preg_split('/\\R/m', $smilieText);
                 if (in_array($text, $smilieText)) {
                     unset($smilieText[array_search($text, $smilieText)]);
                 }
                 $smilieText = implode(PHP_EOL, $smilieText);
                 if (!trim($smilieText)) {
                     continue;
                 }
             }
         }
         foreach ($updateText as $smilieId => $updateTextItem) {
             $dw = XenForo_DataWriter::create('XenForo_DataWriter_Smilie', XenForo_DataWriter::ERROR_SILENT);
             $dw->setExistingData($smilieId);
             $dw->set('smilie_text', $updateTextItem);
             $dw->save();
         }
         if (!trim($smilieText)) {
             continue;
         }
         $dw = XenForo_DataWriter::create('XenForo_DataWriter_Smilie', XenForo_DataWriter::ERROR_SILENT);
         $spriteParams = array('h' => (string) $smilie['h'], 'w' => (string) $smilie['w'], 'x' => (string) $smilie['x'], 'y' => (string) $smilie['y']);
         $dw->bulkSet(array('title' => XenForo_Helper_DevelopmentXml::processSimpleXmlCdata($smilie->title), 'image_url' => XenForo_Helper_DevelopmentXml::processSimpleXmlCdata($smilie->image_url), 'smilie_text' => $smilieText, 'sprite_mode' => (string) $smilie['sprite_mode'], 'sprite_params' => $spriteParams));
         $dw->save();
     }
     XenForo_Db::commit($db);
 }
 /**
  * Imports the development admin navigation XML data.
  *
  * @param string $fileName File to read the XML from
  */
 public function importStylePropertyDevelopmentXml($fileName, $styleId)
 {
     $document = XenForo_Helper_DevelopmentXml::scanFile($fileName);
     $this->importStylePropertyXml($document, $styleId, 'XenForo');
 }
示例#16
0
 public function appendOptionsXml(DOMElement $rootNode, $blockId)
 {
     $document = $rootNode->ownerDocument;
     $options = $this->getOptionsByBlock($blockId);
     foreach ($options as $option) {
         $optionNode = $document->createElement('option');
         $optionNode->setAttribute('option_id', $option['option_id']);
         $optionNode->setAttribute('edit_format', $option['edit_format']);
         $optionNode->setAttribute('data_type', $option['data_type']);
         $optionNode->setAttribute('display_order', $option['display_order']);
         if ($option['validation_class']) {
             $optionNode->setAttribute('validation_class', $option['validation_class']);
             $optionNode->setAttribute('validation_method', $option['validation_method']);
         }
         XenForo_Helper_DevelopmentXml::createDomElements($optionNode, array('option_value' => str_replace("\r\n", "\n", $option['option_value']), 'edit_format_params' => str_replace("\r\n", "\n", $option['edit_format_params']), 'sub_options' => str_replace("\r\n", "\n", $option['sub_options']), 'title' => str_replace("\r\n", "\n", $option['title'])));
         $explainNode = $optionNode->appendChild($document->createElement('explain'));
         $explainNode->appendChild($document->createCDATASection($option['explain']));
         $rootNode->appendChild($optionNode);
     }
 }
示例#17
0
 /**
  * Imports the add-on route prefixes XML.
  *
  * @param SimpleXMLElement $xml XML element pointing to the root of the prefix data
  * @param string $addOnId Add-on to import for
  */
 public function importPrefixesAddOnXml(SimpleXMLElement $xml, $addOnId)
 {
     $db = $this->_getDb();
     $currentPrefixes = $this->getAllPrefixesGroupedByRouteType();
     XenForo_Db::beginTransaction($db);
     $this->deletePrefixesForAddOn($addOnId);
     $routeTypes = XenForo_Helper_DevelopmentXml::fixPhpBug50670($xml->route_type);
     foreach ($routeTypes as $typeXml) {
         $type = (string) $typeXml['type'];
         if (!$type) {
             continue;
         }
         $conflictPrefixes = $this->getPrefixesByRouteType($type);
         $types = XenForo_Helper_DevelopmentXml::fixPhpBug50670($typeXml->prefix);
         foreach ($types as $prefix) {
             $originalPrefixValue = (string) $prefix['original_prefix'];
             $prefixInfo = array('route_type' => $type, 'route_class' => (string) $prefix['class'], 'original_prefix' => $originalPrefixValue, 'build_link' => (string) $prefix['build_link'], 'addon_id' => $addOnId);
             $dw = XenForo_DataWriter::create('XenForo_DataWriter_RoutePrefix');
             if (isset($conflictPrefixes[$originalPrefixValue])) {
                 $dw->setExistingData($conflictPrefixes[$originalPrefixValue], true);
             }
             $dw->setOption(XenForo_DataWriter_RoutePrefix::OPTION_REBUILD_CACHE, false);
             $dw->bulkSet($prefixInfo);
             $dw->save();
         }
     }
     $this->rebuildRoutePrefixCache();
     XenForo_Db::commit($db);
 }
示例#18
0
 /**
  * Installs (or upgrades) an add-on using XML from a file.
  *
  * If an upgrade add-on is given, the XML add-on ID will be checked against if.
  * If matching, an upgrade will be performed. Otherwise, installing existing add-ons will
  * be blocked.
  *
  * @param string $fileName Path to file
  * @param string|false $upgradeAddOnId ID of the add-on to upgrade, if there is one
  *
  * @return bool
  */
 public function installAddOnXmlFromFile($fileName, $upgradeAddOnId = false)
 {
     if (!file_exists($fileName) || !is_readable($fileName)) {
         throw new XenForo_Exception(new XenForo_Phrase('please_enter_valid_file_name_requested_file_not_read'), true);
     }
     try {
         $document = XenForo_Helper_DevelopmentXml::scanFile($fileName);
     } catch (Exception $e) {
         throw new XenForo_Exception(new XenForo_Phrase('provided_file_was_not_valid_xml_file'), true);
     }
     return $this->installAddOnXml($document, $upgradeAddOnId);
 }
示例#19
0
 /**
  * Imports the add-on templates XML.
  *
  * @param SimpleXMLElement $xml XML element pointing to the root of the data
  * @param string $addOnId Add-on to import for
  * @param integer $maxExecution Maximum run time in seconds
  * @param integer $offset Number of elements to skip
  *
  * @return boolean|integer True on completion; false if the XML isn't correct; integer otherwise with new offset value
  */
 public function importTemplatesAddOnXml(SimpleXMLElement $xml, $addOnId, $maxExecution = 0, $offset = 0)
 {
     $db = $this->_getDb();
     XenForo_Db::beginTransaction($db);
     $startTime = microtime(true);
     if ($offset == 0) {
         $this->deleteTemplatesForAddOn($addOnId);
     }
     $templates = XenForo_Helper_DevelopmentXml::fixPhpBug50670($xml->template);
     $titles = array();
     $current = 0;
     foreach ($templates as $template) {
         $current++;
         if ($current <= $offset) {
             continue;
         }
         $titles[] = (string) $template['title'];
     }
     $existingTemplates = $this->getTemplatesInStyleByTitles($titles, 0);
     $current = 0;
     $restartOffset = false;
     foreach ($templates as $template) {
         $current++;
         if ($current <= $offset) {
             continue;
         }
         $templateName = (string) $template['title'];
         $dw = XenForo_DataWriter::create('XenForo_DataWriter_Template');
         if (isset($existingTemplates[$templateName])) {
             $dw->setExistingData($existingTemplates[$templateName], true);
         }
         $dw->setOption(XenForo_DataWriter_Template::OPTION_DEV_OUTPUT_DIR, '');
         $dw->setOption(XenForo_DataWriter_Template::OPTION_FULL_COMPILE, false);
         $dw->setOption(XenForo_DataWriter_Template::OPTION_TEST_COMPILE, false);
         $dw->setOption(XenForo_DataWriter_Template::OPTION_CHECK_DUPLICATE, false);
         $dw->setOption(XenForo_DataWriter_Template::OPTION_REBUILD_TEMPLATE_MAP, false);
         $dw->bulkSet(array('style_id' => 0, 'title' => $templateName, 'template' => (string) $template, 'addon_id' => $addOnId, 'version_id' => (int) $template['version_id'], 'version_string' => (string) $template['version_string']));
         $dw->save();
         if ($maxExecution && microtime(true) - $startTime > $maxExecution) {
             $restartOffset = $current;
             break;
         }
     }
     XenForo_Db::commit($db);
     return $restartOffset ? $restartOffset : true;
 }
示例#20
0
 /**
  * Imports the add-on admin permission XML.
  *
  * @param SimpleXMLElement $xml XML element pointing to the root of the  data
  * @param string $addOnId Add-on to import for
  */
 public function importAdminPermissionsAddOnXml(SimpleXMLElement $xml, $addOnId)
 {
     $db = $this->_getDb();
     XenForo_Db::beginTransaction($db);
     $this->deleteAdminPermissionsForAddOn($addOnId);
     $xmlPermissions = XenForo_Helper_DevelopmentXml::fixPhpBug50670($xml->admin_permission);
     $adminPermissionIds = array();
     foreach ($xmlPermissions as $adminPermission) {
         $adminPermissionIds[] = (string) $adminPermission['admin_permission_id'];
     }
     $existingPermissions = $this->getAdminPermissionsByIds($adminPermissionIds);
     foreach ($xmlPermissions as $adminPermission) {
         $adminPermissionId = (string) $adminPermission['admin_permission_id'];
         $dw = XenForo_DataWriter::create('XenForo_DataWriter_AdminPermission');
         if (isset($existingPermissions[$adminPermissionId])) {
             $dw->setExistingData($existingPermissions[$adminPermissionId], true);
         }
         $dw->bulkSet(array('admin_permission_id' => $adminPermissionId, 'display_order' => (string) $adminPermission['display_order'], 'addon_id' => $addOnId));
         $dw->save();
     }
     $this->rebuildUserAdminPermissionCache();
     XenForo_Db::commit($db);
 }
示例#21
0
 /**
  * Imports the add-on permissions XML.
  *
  * @param SimpleXMLElement $xml XML element pointing to the root of the navigation data
  * @param string $addOnId Add-on to import for
  */
 public function importPermissionsAddOnXml(SimpleXMLElement $xml, $addOnId)
 {
     $db = $this->_getDb();
     XenForo_Db::beginTransaction($db);
     $this->deletePermissionsForAddOn($addOnId);
     $groups = $xml->permission_groups ? XenForo_Helper_DevelopmentXml::fixPhpBug50670($xml->permission_groups->permission_group) : array();
     $permissions = $xml->permissions ? XenForo_Helper_DevelopmentXml::fixPhpBug50670($xml->permissions->permission) : array();
     $interfaceGroups = $xml->interface_groups ? XenForo_Helper_DevelopmentXml::fixPhpBug50670($xml->interface_groups->interface_group) : array();
     $permissionGroupIds = array();
     foreach ($groups as $group) {
         $permissionGroupIds[] = (string) $group['permission_group_id'];
     }
     $permissionIdPairs = array();
     foreach ($permissions as $permission) {
         $permissionIdPairs[] = array((string) $permission['permission_group_id'], (string) $permission['permission_id']);
     }
     $interfaceGroupIds = array();
     foreach ($interfaceGroups as $group) {
         $interfaceGroupIds[] = (string) $group['interface_group_id'];
     }
     $existingGroups = $this->getPermissionGroupsByIds($permissionGroupIds);
     $existingPermissions = $this->getPermissionsByPairs($permissionIdPairs);
     $existingInterfaceGroups = $this->getPermissionInterfaceGroupsByIds($interfaceGroupIds);
     foreach ($groups as $group) {
         $groupId = (string) $group['permission_group_id'];
         $groupDw = XenForo_DataWriter::create('XenForo_DataWriter_PermissionGroup');
         if (isset($existingGroups[$groupId])) {
             $groupDw->setExistingData($existingGroups[$groupId], true);
         }
         $groupDw->setOption(XenForo_DataWriter_PermissionGroup::OPTION_REBUILD_CACHE, false);
         $groupDw->bulkSet(array('permission_group_id' => $groupId, 'addon_id' => $addOnId));
         $groupDw->save();
     }
     foreach ($permissions as $permission) {
         $groupId = (string) $permission['permission_group_id'];
         $permissionId = (string) $permission['permission_id'];
         $permissionDw = XenForo_DataWriter::create('XenForo_DataWriter_Permission');
         if (isset($existingPermissions[$groupId], $existingPermissions[$groupId][$permissionId])) {
             $permissionDw->setExistingData($existingPermissions[$groupId][$permissionId], true);
         }
         $permissionDw->setOption(XenForo_DataWriter_Permission::OPTION_REBUILD_CACHE, false);
         $permissionDw->setOption(XenForo_DataWriter_Permission::OPTION_DEPENDENT_CHECK, false);
         $permissionDw->bulkSet(array('permission_id' => (string) $permission['permission_id'], 'permission_group_id' => (string) $permission['permission_group_id'], 'permission_type' => (string) $permission['permission_type'], 'depend_permission_id' => (string) $permission['depend_permission_id'], 'interface_group_id' => (string) $permission['interface_group_id'], 'display_order' => (string) $permission['display_order'], 'addon_id' => $addOnId));
         if ((string) $permission['permission_type'] == 'integer') {
             $permissionDw->set('default_value_int', (string) $permission['default_value_int']);
         } else {
             $permissionDw->set('default_value', (string) $permission['default_value']);
         }
         $permissionDw->save();
     }
     foreach ($interfaceGroups as $group) {
         $groupId = (string) $group['interface_group_id'];
         $groupDw = XenForo_DataWriter::create('XenForo_DataWriter_PermissionInterfaceGroup');
         if (isset($existingInterfaceGroups[$groupId])) {
             $groupDw->setExistingData($existingInterfaceGroups[$groupId], true);
         }
         $groupDw->bulkSet(array('interface_group_id' => $groupId, 'display_order' => (string) $group['display_order'], 'addon_id' => $addOnId));
         $groupDw->save();
     }
     XenForo_Db::commit($db);
 }
示例#22
0
文件: Phrase.php 项目: Sywooch/forums
 /**
  * Imports all phrases from the phrases directory into the database
  */
 public function importPhrasesFromDevelopment()
 {
     $db = $this->_getDb();
     $phraseDir = $this->getPhraseDevelopmentDirectory();
     if (!$phraseDir && !is_dir($phraseDir)) {
         throw new XenForo_Exception("Phrase development directory not enabled or doesn't exist");
     }
     $files = glob("{$phraseDir}/*.txt");
     if (!$files) {
         throw new XenForo_Exception("Phrase development directory does not have any phrases");
     }
     $metaData = XenForo_Helper_DevelopmentXml::readMetaDataFile($phraseDir . '/_metadata.xml');
     XenForo_Db::beginTransaction($db);
     $this->deletePhrasesForAddOn('XenForo');
     $titles = array();
     foreach ($files as $templateFile) {
         $filename = basename($templateFile);
         if (preg_match('/^(.+)\\.txt$/', $filename, $match)) {
             $titles[] = $match[1];
         }
     }
     $existingPhrases = $this->getPhrasesInLanguageByTitles($titles, 0);
     foreach ($files as $file) {
         if (!is_readable($file)) {
             throw new XenForo_Exception("Phrase file '{$file}' not readable");
         }
         $filename = basename($file);
         if (preg_match('/^(.+)\\.txt$/', $filename, $match)) {
             $title = $match[1];
             $dw = XenForo_DataWriter::create('XenForo_DataWriter_Phrase');
             if (isset($existingPhrases[$title])) {
                 $dw->setExistingData($existingPhrases[$title], true);
             }
             $dw->setOption(XenForo_DataWriter_Phrase::OPTION_DEV_OUTPUT_DIR, '');
             $dw->setOption(XenForo_DataWriter_Phrase::OPTION_REBUILD_LANGUAGE_CACHE, false);
             $dw->setOption(XenForo_DataWriter_Phrase::OPTION_FULL_RECOMPILE, false);
             $dw->setOption(XenForo_DataWriter_Phrase::OPTION_REBUILD_PHRASE_MAP, false);
             $dw->setOption(XenForo_DataWriter_Phrase::OPTION_CHECK_DUPLICATE, false);
             $dw->bulkSet(array('title' => $title, 'phrase_text' => file_get_contents($file), 'language_id' => 0, 'addon_id' => 'XenForo', 'version_id' => 0, 'version_string' => ''));
             if (isset($metaData[$title])) {
                 $dw->bulkSet($metaData[$title]);
             }
             $dw->save();
             unset($dw);
         }
     }
     XenForo_Db::commit($db);
 }
示例#23
0
 /**
  * Imports the add-on fields XML.
  *
  * @param SimpleXMLElement $xml XML element pointing to the root of the data
  * @param string $addOnId Add-on to import for
  * @param integer $maxExecution Maximum run time in seconds
  * @param integer $offset Number of elements to skip
  *
  * @return boolean integer on completion; false if the XML isn't correct;
  * integer otherwise with new offset value
  */
 public function importFieldsAddOnXml(SimpleXMLElement $xml, $addOnId, $maxExecution = 0, $offset = 0)
 {
     $db = $this->_getDb();
     XenForo_Db::beginTransaction($db);
     $startTime = microtime(true);
     $fields = XenForo_Helper_DevelopmentXml::fixPhpBug50670($xml->field);
     $current = 0;
     $restartOffset = false;
     foreach ($fields as $field) {
         $current++;
         if ($current <= $offset) {
             continue;
         }
         $fieldId = (string) $field['field_id'];
         if (!$field['addon_id']) {
             $field->addAttribute('addon_id', $addOnId);
         }
         $this->importFieldXml($field, 0, $fieldId);
         if ($maxExecution && microtime(true) - $startTime > $maxExecution) {
             $restartOffset = $current;
             break;
         }
     }
     XenForo_Db::commit($db);
     return $restartOffset ? $restartOffset : true;
 }
示例#24
0
 protected function _writeMetaDataDevFileOutput($dir, $title, $data)
 {
     $metaDataFile = $dir . '/_metadata.xml';
     XenForo_Helper_DevelopmentXml::writeMetaDataOutput($metaDataFile, $title, $data, array('version_id', 'version_string'));
 }
示例#25
0
文件: BbCode.php 项目: Sywooch/forums
 /**
  * Imports the BB code media sites for an add-on.
  *
  * @param SimpleXMLElement $xml XML element pointing to the root of the event data
  * @param string $addOnId Add-on to import for
  */
 public function importBbCodeMediaSitesAddOnXml(SimpleXMLElement $xml, $addOnId)
 {
     $db = $this->_getDb();
     XenForo_Db::beginTransaction($db);
     $db->delete('xf_bb_code_media_site', 'addon_id = ' . $db->quote($addOnId));
     $xmlSites = XenForo_Helper_DevelopmentXml::fixPhpBug50670($xml->site);
     $siteIds = array();
     foreach ($xmlSites as $site) {
         $siteIds[] = (string) $site['media_site_id'];
     }
     $sites = $this->getBbCodeMediaSites(array('mediaSiteIds' => $siteIds));
     foreach ($xmlSites as $site) {
         $siteId = (string) $site['media_site_id'];
         $dw = XenForo_DataWriter::create('XenForo_DataWriter_BbCodeMediaSite');
         if (isset($sites[$siteId])) {
             $dw->setExistingData($sites[$siteId]);
         }
         $dw->bulkSet(array('media_site_id' => $siteId, 'site_title' => (string) $site['site_title'], 'site_url' => (string) $site['site_url'], 'match_urls' => (string) XenForo_Helper_DevelopmentXml::processSimpleXmlCdata($site->match_urls), 'match_is_regex' => (int) $site['match_is_regex'], 'match_callback_class' => (string) $site['match_callback_class'], 'match_callback_method' => (string) $site['match_callback_method'], 'embed_html' => (string) XenForo_Helper_DevelopmentXml::processSimpleXmlCdata($site->embed_html), 'embed_html_callback_class' => (string) $site['embed_html_callback_class'], 'embed_html_callback_method' => (string) $site['embed_html_callback_method'], 'supported' => (int) $site['supported'], 'addon_id' => $addOnId));
         $dw->save();
     }
     XenForo_Db::commit($db);
 }
示例#26
0
文件: Hooks.php 项目: Sywooch/forums
 protected function _getHookXmlNode(DOMDocument $document, array $hook)
 {
     $attributes = array('hook_id', 'active');
     $children = array('hook_title', 'template', 'hook_name');
     $hookNode = $document->createElement('hook');
     foreach ($attributes as $attribute) {
         $hookNode->setAttribute($attribute, $hook[$attribute]);
     }
     foreach ($children as $child) {
         $fieldNode = $document->createElement($child);
         $fieldNode->appendChild(XenForo_Helper_DevelopmentXml::createDomCdataSection($document, $hook[$child]));
         $hookNode->appendChild($fieldNode);
     }
     return $hookNode;
 }
示例#27
0
 /**
  * Imports the add-on admin navigation XML.
  *
  * @param SimpleXMLElement $xml XML element pointing to the root of the navigation data
  * @param string $addOnId Add-on to import for
  */
 public function importOptionsAddOnXml(SimpleXMLElement $xml, $addOnId)
 {
     $db = $this->_getDb();
     $options = $this->getAllOptions();
     XenForo_Db::beginTransaction($db);
     $this->deleteOptionsForAddOn($addOnId);
     $xmlGroups = XenForo_Helper_DevelopmentXml::fixPhpBug50670($xml->group);
     $xmlOptions = XenForo_Helper_DevelopmentXml::fixPhpBug50670($xml->option);
     $groupIds = array();
     foreach ($xmlGroups as $group) {
         $groupIds[] = (string) $group['group_id'];
     }
     $optionIds = array();
     foreach ($xmlOptions as $option) {
         $optionIds[] = (string) $option['option_id'];
     }
     $existingGroups = $this->getOptionGroupsByIds($groupIds);
     $existingOptions = $this->getOptionsByIds($optionIds);
     foreach ($xmlGroups as $group) {
         $groupId = (string) $group['group_id'];
         $groupDw = XenForo_DataWriter::create('XenForo_DataWriter_OptionGroup');
         if (isset($existingGroups[$groupId])) {
             $groupDw->setExistingData($existingGroups[$groupId], true);
         }
         $groupDw->setOption(XenForo_DataWriter_Option::OPTION_REBUILD_CACHE, false);
         $groupDw->bulkSet(array('group_id' => $groupId, 'display_order' => (string) $group['display_order'], 'debug_only' => (string) $group['debug_only'], 'addon_id' => $addOnId));
         $groupDw->save();
     }
     foreach ($xmlOptions as $option) {
         $optionId = (string) $option['option_id'];
         $optionDw = XenForo_DataWriter::create('XenForo_DataWriter_Option');
         if (isset($existingOptions[$optionId])) {
             $optionDw->setExistingData($existingOptions[$optionId], true);
         }
         $optionDw->setOption(XenForo_DataWriter_Option::OPTION_REBUILD_CACHE, false);
         $optionDw->bulkSet(array('option_id' => $optionId, 'edit_format' => (string) $option['edit_format'], 'data_type' => (string) $option['data_type'], 'can_backup' => (string) $option['can_backup'], 'addon_id' => $addOnId));
         if ((string) $option['validation_class']) {
             $optionDw->set('validation_class', (string) $option['validation_class']);
             $optionDw->set('validation_method', (string) $option['validation_method']);
         }
         $optionDw->set('default_value', (string) $option->default_value);
         $optionDw->set('edit_format_params', (string) $option->edit_format_params);
         $optionDw->set('sub_options', (string) $option->sub_options);
         $relations = array();
         foreach ($option->relation as $relation) {
             $relations[(string) $relation['group_id']] = (string) $relation['display_order'];
         }
         $optionDw->setRelations($relations);
         if (isset($options[$optionDw->get('option_id')])) {
             $optionDw->setOption(XenForo_DataWriter_Option::OPTION_VALIDATE_VALUE, false);
             $optionDw->set('option_value', $options[$optionDw->get('option_id')]['option_value']);
         }
         $optionDw->save();
     }
     $this->rebuildOptionCache();
     XenForo_Db::commit($db);
 }
示例#28
0
 /**
  * Imports the add-on email templates XML.
  *
  * @param SimpleXMLElement $xml XML element pointing to the root of the data
  * @param string $addOnId Add-on to import for
  * @param boolean $fullCompile True to recompile all templates after importing
  */
 public function importEmailTemplatesAddOnXml(SimpleXMLElement $xml, $addOnId, $fullCompile = true)
 {
     $db = $this->_getDb();
     XenForo_Db::beginTransaction($db);
     $this->deleteEmailTemplatesForAddOn($addOnId);
     $templates = XenForo_Helper_DevelopmentXml::fixPhpBug50670($xml->template);
     $titles = array();
     foreach ($templates as $template) {
         $titles[] = (string) $template['title'];
     }
     $existingTemplates = $this->getMasterEmailTemplatesByTitles($titles);
     foreach ($templates as $template) {
         $title = (string) $template['title'];
         $data = array('title' => $title, 'custom' => 0, 'subject' => (string) $template->subject, 'body_text' => (string) $template->body_text, 'body_html' => (string) $template->body_html, 'addon_id' => $addOnId);
         $dw = XenForo_DataWriter::create('XenForo_DataWriter_EmailTemplate');
         if (isset($existingTemplates[$title])) {
             $dw->setExistingData($existingTemplates[$title], true);
         }
         $dw->setOption(XenForo_DataWriter_EmailTemplate::OPTION_DEV_OUTPUT_DIR, '');
         $dw->setOption(XenForo_DataWriter_EmailTemplate::OPTION_FULL_COMPILE, false);
         $dw->setOption(XenForo_DataWriter_EmailTemplate::OPTION_TEST_COMPILE, false);
         $dw->bulkSet($data);
         $dw->save();
     }
     if ($fullCompile) {
         $this->compileAllEmailTemplates();
     }
     XenForo_Db::commit($db);
 }
示例#29
0
 /**
  * Appends the template XML for templates in the specified style.
  *
  * @param DOMElement $rootNode
  * @param integer $styleId
  * @param string|null $limitAddOnId If non-null, limits only to templates in this add-on
  * @param boolean $independent If true, all customizations from parent styles will be included in this
  */
 public function appendTemplatesStyleXml(DOMElement $rootNode, $styleId, $limitAddOnId = null, $independent = false)
 {
     $document = $rootNode->ownerDocument;
     if (!$styleId) {
         // getting master data
         $independent = false;
     }
     if ($independent) {
         $templates = $this->getAllEffectiveTemplatesInStyle($styleId);
     } else {
         $templates = $this->getAllTemplatesInStyle($styleId);
     }
     foreach ($templates as $template) {
         if ($limitAddOnId !== null && $template['addon_id'] !== $limitAddOnId) {
             // wrong add-on
             continue;
         }
         if ($independent && !$template['style_id']) {
             // master version of a template
             continue;
         }
         $templateNode = $document->createElement('template');
         $templateNode->setAttribute('title', $template['title']);
         $templateNode->setAttribute('addon_id', $template['addon_id']);
         $templateNode->setAttribute('version_id', $template['version_id']);
         $templateNode->setAttribute('version_string', $template['version_string']);
         $templateNode->setAttribute('disable_modifications', $template['disable_modifications']);
         $templateNode->appendChild(XenForo_Helper_DevelopmentXml::createDomCdataSection($document, $template['template']));
         $rootNode->appendChild($templateNode);
     }
 }
 /**
  * Imports the add-on admin navigation XML.
  *
  * @param SimpleXMLElement $xml XML element pointing to the root of the navigation data
  * @param string $addOnId Add-on to import for
  */
 public function importAdminNavigationAddOnXml(SimpleXMLElement $xml, $addOnId)
 {
     $db = $this->_getDb();
     XenForo_Db::beginTransaction($db);
     $this->deleteAdminNavigationForAddOn($addOnId);
     $xmlNav = XenForo_Helper_DevelopmentXml::fixPhpBug50670($xml->navigation);
     $navIds = array();
     foreach ($xmlNav as $nav) {
         $navIds[] = (string) $nav['navigation_id'];
     }
     $existingNavigation = $this->getAdminNavigationEntriesByIds($navIds);
     foreach ($xmlNav as $nav) {
         $navId = (string) $nav['navigation_id'];
         $dw = XenForo_DataWriter::create('XenForo_DataWriter_AdminNavigation');
         if (isset($existingNavigation[$navId])) {
             $dw->setExistingData($existingNavigation[$navId], true);
         }
         $dw->bulkSet(array('navigation_id' => $navId, 'parent_navigation_id' => (string) $nav['parent_navigation_id'], 'display_order' => (string) $nav['display_order'], 'link' => (string) $nav['link'], 'admin_permission_id' => (string) $nav['admin_permission_id'], 'debug_only' => (string) $nav['debug_only'], 'hide_no_children' => (string) $nav['hide_no_children'], 'addon_id' => $addOnId));
         $dw->save();
     }
     XenForo_Db::commit($db);
 }