コード例 #1
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);
 }
コード例 #2
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;
 }
コード例 #3
0
ファイル: Phrases.php プロジェクト: namgiangle90/tokyobaito
 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;
 }
コード例 #4
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();
 }
コード例 #5
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);
 }
コード例 #6
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);
 }
コード例 #7
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 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);
 }
コード例 #8
0
ファイル: Class.php プロジェクト: ThemeHouse-XF/ObjectFields
 public function processCustomFields(ThemeHouse_ObjectFields_Extend_ThemeHouse_Objects_DataWriter_Class $dw)
 {
     /* @var $document SimpleXMLElement */
     $document = $this->_importDocument;
     $customFields = XenForo_Helper_DevelopmentXml::fixPhpBug50670($document->custom_fields->custom_field);
     $availableFields = array();
     foreach ($customFields as $customField) {
         if ($customField && $customField['field_id']) {
             $availableFields[] = (string) $customField['field_id'];
         }
     }
     $this->_getFieldModel()->updateObjectFieldClassAssociationByClass($dw->get('object_class_id'), $availableFields);
 }
コード例 #9
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);
 }
コード例 #10
0
ファイル: Phrase.php プロジェクト: Sywooch/forums
 /**
  * Imports the master language (phrase) XML for the specified add-on.
  *
  * @param SimpleXMLElement $xml
  * @param string $addOnId
  * @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 importPhrasesAddOnXml(SimpleXMLElement $xml, $addOnId, $maxExecution = 0, $offset = 0)
 {
     $db = $this->_getDb();
     XenForo_Db::beginTransaction($db);
     $startTime = microtime(true);
     if ($offset == 0) {
         $this->deletePhrasesForAddOn($addOnId);
     }
     $phrases = XenForo_Helper_DevelopmentXml::fixPhpBug50670($xml->phrase);
     $titles = array();
     $current = 0;
     foreach ($phrases as $phrase) {
         $current++;
         if ($current <= $offset) {
             continue;
         }
         $titles[] = (string) $phrase['title'];
     }
     $existingPhrases = $this->getPhrasesInLanguageByTitles($titles, 0);
     if ($maxExecution) {
         // take off whatever we've used
         $maxExecution -= microtime(true) - $startTime;
     }
     $return = $this->importPhrasesXml($xml, 0, $addOnId, $existingPhrases, $maxExecution, $offset);
     XenForo_Db::commit($db);
     return $return;
 }
コード例 #11
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;
 }
コード例 #12
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);
 }
コード例 #13
0
ファイル: Cron.php プロジェクト: Sywooch/forums
 /**
  * Imports the cron entries 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 importCronEntriesAddOnXml(SimpleXMLElement $xml, $addOnId)
 {
     $db = $this->_getDb();
     $addonEntries = $this->getCronEntriesByAddOnId($addOnId);
     XenForo_Db::beginTransaction($db);
     $this->deleteCronEntriesForAddOn($addOnId);
     $xmlEntries = XenForo_Helper_DevelopmentXml::fixPhpBug50670($xml->entry);
     $entryIds = array();
     foreach ($xmlEntries as $entry) {
         $entryIds[] = (string) $entry['entry_id'];
     }
     $entries = $this->getCronEntriesByIds($entryIds);
     foreach ($xmlEntries as $entry) {
         $entryId = (string) $entry['entry_id'];
         $dw = XenForo_DataWriter::create('XenForo_DataWriter_CronEntry');
         if (isset($entries[$entryId])) {
             $dw->setExistingData($entries[$entryId]);
         }
         if (isset($addonEntries[$entryId])) {
             $active = $addonEntries[$entryId]['active'];
         } else {
             $active = (string) $entry['active'];
         }
         $dw->setOption(XenForo_DataWriter_CronEntry::OPTION_REBUILD_CACHE, false);
         $dw->bulkSet(array('entry_id' => $entryId, 'cron_class' => (string) $entry['cron_class'], 'cron_method' => (string) $entry['cron_method'], 'active' => $active, 'run_rules' => json_decode((string) $entry, true), 'addon_id' => $addOnId));
         $dw->save();
     }
     $this->updateMinimumNextRunTime();
     XenForo_Db::commit($db);
 }
コード例 #14
0
 /**
  * Imports the modifications 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 importModificationAddOnXml(SimpleXMLElement $xml, $addOnId)
 {
     $db = $this->_getDb();
     $addonMods = $this->getModificationsByAddOnId($addOnId);
     XenForo_Db::beginTransaction($db);
     $this->deleteModificationsForAddOn($addOnId);
     $xmlEntries = XenForo_Helper_DevelopmentXml::fixPhpBug50670($xml->modification);
     $keys = array();
     foreach ($xmlEntries as $entry) {
         $keys[] = (string) $entry['modification_key'];
     }
     $modifications = $this->getModificationsByKeys($keys);
     foreach ($xmlEntries as $modification) {
         $key = (string) $modification['modification_key'];
         $dw = XenForo_DataWriter::create($this->_dataWriterName);
         if (isset($modifications[$key])) {
             $dw->setExistingData($modifications[$key]);
         }
         if (isset($addonMods[$key])) {
             $enabled = $addonMods[$key]['enabled'];
         } else {
             $enabled = (string) $modification['enabled'];
         }
         $dw->setOption(XenForo_DataWriter_TemplateModificationAbstract::OPTION_FULL_TEMPLATE_COMPILE, false);
         $dw->setOption(XenForo_DataWriter_TemplateModificationAbstract::OPTION_REPARSE_TEMPLATE, false);
         $dw->setOption(XenForo_DataWriter_TemplateModificationAbstract::OPTION_VERIFY_MODIFICATION_KEY, false);
         $dw->bulkSet(array('addon_id' => $addOnId, 'template' => (string) $modification['template'], 'modification_key' => $key, 'description' => (string) $modification['description'], 'execution_order' => (int) $modification['execution_order'], 'enabled' => $enabled, 'action' => (string) $modification['action'], 'find' => XenForo_Helper_DevelopmentXml::processSimpleXmlCdata($modification->find[0]), 'replace' => XenForo_Helper_DevelopmentXml::processSimpleXmlCdata($modification->replace[0])));
         $this->_addExtraToAddonXmlImportDw($dw, $modification);
         $dw->save();
     }
     XenForo_Db::commit($db);
 }
コード例 #15
0
ファイル: Admin.php プロジェクト: darkearl/projectT122015
 /**
  * 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);
 }
コード例 #16
0
 /**
  * Imports the add-on admin 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 importAdminTemplatesAddOnXml(SimpleXMLElement $xml, $addOnId, $maxExecution = 0, $offset = 0)
 {
     $db = $this->_getDb();
     XenForo_Db::beginTransaction($db);
     $startTime = microtime(true);
     if ($offset == 0) {
         $this->deleteAdminTemplatesForAddOn($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->getAdminTemplatesByTitles($titles);
     $current = 0;
     $restartOffset = false;
     foreach ($templates as $template) {
         $current++;
         if ($current <= $offset) {
             continue;
         }
         $templateName = (string) $template['title'];
         $dw = XenForo_DataWriter::create('XenForo_DataWriter_AdminTemplate');
         if (isset($existingTemplates[$templateName])) {
             $dw->setExistingData($existingTemplates[$templateName], true);
         }
         $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->set('title', $templateName);
         $dw->set('template', XenForo_Helper_DevelopmentXml::processSimpleXmlCdata($template));
         $dw->set('addon_id', $addOnId);
         $dw->save();
         if ($maxExecution && microtime(true) - $startTime > $maxExecution) {
             $restartOffset = $current;
             break;
         }
     }
     XenForo_Db::commit($db);
     return $restartOffset ? $restartOffset : true;
 }
コード例 #17
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);
 }
コード例 #18
0
ファイル: Template.php プロジェクト: namgiangle90/tokyobaito
 /**
  * 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);
     $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);
         try {
             $dw->bulkSet(array('style_id' => 0, 'title' => $templateName, 'template' => XenForo_Helper_DevelopmentXml::processSimpleXmlCdata($template), 'addon_id' => $addOnId, 'version_id' => (int) $template['version_id'], 'version_string' => (string) $template['version_string']));
             $dw->save();
         } catch (XenForo_Exception $e) {
             throw new XenForo_Exception("{$templateName}: " . $e->getMessage(), true);
         }
         if ($maxExecution && microtime(true) - $startTime > $maxExecution) {
             $restartOffset = $current;
             break;
         }
     }
     if (!$restartOffset) {
         unset($existingTemplates);
         // just save memory
         // now look for templates that have been removed
         $addOnTemplates = $this->getMasterTemplatesInAddOn($addOnId);
         foreach ($templates as $template) {
             $title = (string) $template['title'];
             unset($addOnTemplates[$title]);
         }
         foreach ($addOnTemplates as $addOnTemplate) {
             $dw = XenForo_DataWriter::create('XenForo_DataWriter_Template');
             $dw->setExistingData($addOnTemplate, 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->delete();
         }
     }
     XenForo_Db::commit($db);
     return $restartOffset ? $restartOffset : true;
 }
コード例 #19
0
 /**
  * Imports a moderators XML file.
  *
  * @param SimpleXMLElement $document
  * @param integer $overwrite
  *
  * @return array List of cache rebuilders to run
  */
 public function importModeratorsXml(SimpleXMLElement $document, $overwrite = 0)
 {
     if ($document->getName() != 'moderators') {
         throw new XenForo_Exception(new XenForo_Phrase('th_provided_file_is_not_valid_moderator_xml_moderators'), true);
     }
     $db = $this->_getDb();
     /* @var $generalModerator SimpleXMLElement */
     XenForo_Db::beginTransaction($db);
     $generalModerators = XenForo_Helper_DevelopmentXml::fixPhpBug50670($document->general_moderators->general_moderator);
     foreach ($generalModerators as $generalModerator) {
         $modPerms = XenForo_Helper_DevelopmentXml::processSimpleXmlCdata($generalModerator->moderator_permissions);
         if ($modPerms) {
             $modPerms = unserialize($modPerms);
         } else {
             $modPerms = array();
         }
         $userId = (int) $generalModerator['user_id'];
         $existing = $this->getGeneralModeratorByUserId($userId);
         if (!$overwrite && $existing) {
             continue;
         }
         $isSuperModerator = (int) $generalModerator['is_super_moderator'];
         $extra = array('extra_user_group_ids' => $generalModerator['extra_user_group_ids']);
         $this->insertOrUpdateGeneralModerator($userId, $modPerms, $isSuperModerator, $extra);
     }
     $contentModerators = XenForo_Helper_DevelopmentXml::fixPhpBug50670($document->content_moderators->content_moderator);
     foreach ($contentModerators as $contentModerator) {
         $modPerms = XenForo_Helper_DevelopmentXml::processSimpleXmlCdata($contentModerator->moderator_permissions);
         if ($modPerms) {
             $modPerms = unserialize($modPerms);
         } else {
             $modPerms = array();
         }
         $contentType = (string) $contentModerator['content_type'];
         $contentId = (int) $contentModerator['content_id'];
         $userId = (int) $contentModerator['user_id'];
         $existing = $this->getContentModeratorByContentAndUserId($contentType, $contentId, $userId);
         if (!$overwrite && $existing) {
             continue;
         }
         $this->insertOrUpdateContentModerator($userId, $contentType, $contentId, $modPerms);
     }
     XenForo_Db::commit($db);
 }