public static function verifyOption(array &$values, XenForo_DataWriter $dw, $fieldName) { if ($dw->isInsert()) { return true; } if (empty($values['enabled'])) { return true; } try { $helper = new XenGallery_Helper_Video(null, $values['ffmpegPath'], !empty($values['transcode'])); $errors = $helper->getFfmpegErrors(); if ($errors) { $dw->error(reset($errors), $fieldName); return false; } } catch (Exception $e) { $dw->error($e->getMessage(), $fieldName); return false; } if (!empty($values['transcode'])) { try { if (!is_file($values['phpPath']) && !is_executable($values['phpPath'])) { $dw->error(new XenForo_Phrase('xengallery_php_binary_path_could_not_be_verified')); return false; } } catch (Exception $e) { $dw->error($e->getMessage(), $fieldName); return false; } } return true; }
public static function validateOption(&$choices, XenForo_DataWriter $dw, $fieldName) { if ($dw->isInsert()) { return true; } if (!in_array($choices, self::$navbarPositions)) { $dw->error(new XenForo_Phrase('invalid_argument'), $fieldName); return false; } return true; }
public static function verifyOption(&$optionValue, XenForo_DataWriter $dw, $fieldName) { if ($dw->isInsert()) { return true; } if ($optionValue == 'enabled' && !class_exists('Imagick')) { $dw->error(new XenForo_Phrase('must_have_imagick_pecl_extension'), $fieldName); return false; } return true; }
/** * Verifies the registrationWelcome setting * * @param array $values * @param XenForo_DataWriter $dw Calling DW * @param string $fieldName Name of field/option * * @return true */ public static function verifyOption(array &$values, XenForo_DataWriter $dw, $fieldName) { if ($dw->isInsert()) { // insert - just trust the default value return true; } if (!empty($values['messageEnabled'])) { /** @var XenForo_Model_User $userModel */ $userModel = XenForo_Model::create('XenForo_Model_User'); $participants = explode(',', $values['messageParticipants']); $starter = array_shift($participants); $participantUsers = $userModel->getUsersByNames($participants); $starterUser = $userModel->getUserByName($starter); if (!$starterUser) { if ($starter) { $dw->error(new XenForo_Phrase('the_following_recipients_could_not_be_found_x', array('names' => $starter)), $fieldName); } else { $dw->error(new XenForo_Phrase('please_enter_at_least_one_valid_recipient'), $fieldName); } return false; } /** @var XenForo_DataWriter_ConversationMaster $conversationDw */ $conversationDw = XenForo_DataWriter::create('XenForo_DataWriter_ConversationMaster'); $conversationDw->setExtraData(XenForo_DataWriter_ConversationMaster::DATA_ACTION_USER, $starterUser); $conversationDw->setExtraData(XenForo_DataWriter_ConversationMaster::DATA_MESSAGE, $values['messageBody']); $conversationDw->set('user_id', $starterUser['user_id']); $conversationDw->set('username', $starterUser['username']); $conversationDw->set('title', $values['messageTitle']); $conversationDw->addRecipientUserIds(array_keys($participantUsers)); // skips permissions $messageDw = $conversationDw->getFirstMessageDw(); $messageDw->set('message', $values['messageBody']); $conversationDw->preSave(); if ($conversationDw->hasErrors()) { $errors = $conversationDw->getErrors(); // Skip recipient errors. We've already verified the recipients are valid. if (isset($errors['recipients'])) { unset($errors['recipients']); } if (count($errors)) { $dw->error(reset($errors), $fieldName); return false; } } $validUsernames = XenForo_Application::arrayColumn($participantUsers, 'username'); array_unshift($validUsernames, $starter); $values['messageParticipants'] = implode(', ', array_unique($validUsernames)); } if (!empty($values['emailEnabled']) && !strlen(trim($values['emailBody']))) { $dw->error(new XenForo_Phrase('you_must_enter_email_message_to_enable_welcome_email'), $fieldName); return false; } return true; }
public static function verifyOption(&$optionValue, XenForo_DataWriter $dw, $fieldName) { if ($dw->isInsert()) { return true; } $redirects = new XenGallery_Option_Redirects(); $redirects->addOnId = 'EWRmedio'; $redirects->route = 'ewrmedio'; $redirects->replaceRoute = 'media'; $redirects->verifyOptionForAddOn($optionValue, $dw, $fieldName); return true; }
/** * Updates the build date of styles after the value of the minifyCss option changes. * * @param boolean $option * @param XenForo_DataWriter $dw * @param string $fieldName * * @return boolean */ public static function verifyOption(&$option, XenForo_DataWriter $dw, $fieldName) { if ($dw->isInsert()) { return true; // don't need to do anything } if ($option) { XenForo_Model::create('XenForo_Model_Template')->writeTemplateFiles(false, false); } else { XenForo_Model::create('XenForo_Model_Template')->deleteTemplateFiles(); } return true; }
public static function verifyOption(array &$options, XenForo_DataWriter $dw, $fieldName) { if (!$dw->isInsert()) { $grouped = array(); foreach ($options as $option) { if (!isset($option['group']) || strval($option['group']) === '') { continue; } $grouped[strval($option['group'])][] = array('group' => strval($option['group']), 'name' => strval($option['name']), 'format' => strval($option['format'])); } $options = $grouped; } return true; }
public static function verifyOption(array &$choices, XenForo_DataWriter $dw, $fieldName) { if ($dw->isInsert()) { // insert - just trust the default value return true; } $exclusions = array(); foreach (XenForo_Model::create('XenForo_Model_AdminSearch')->getAllSearchTypes() as $searchType => $handlerName) { if (empty($choices[$searchType])) { $exclusions[$searchType] = true; } } $choices = $exclusions; return true; }
public static function verifyOption(array &$choices, XenForo_DataWriter $dw, $fieldName) { if ($dw->isInsert()) { // insert - just trust the default value return true; } $exclusions = array(); /** @var XenForo_Model_Sitemap $sitemapModel */ $sitemapModel = XenForo_Model::create('XenForo_Model_Sitemap'); $types = $sitemapModel->getSitemapContentTypes(true); unset($types['core']); // always enabled foreach ($types as $type => $handlerName) { if (empty($choices[$type])) { $exclusions[$type] = true; } } $choices = $exclusions; return true; }
/** * Updates list of tags for specified piece of content. Any addition, removal * will be processed accordingly with record from database. * * @param string $contentType * @param unsigned int $contentId * @param unsigned int $contentUserId * @param array $tagTexts * @param XenForo_DataWriter $dw * @param array $options * * @return number of tags after update. * * @throws XenForo_Exception */ public static function updateTags($contentType, $contentId, $contentUserId, array $tagTexts, XenForo_DataWriter $dw, array $options = array()) { $options = array_merge(array('throwException' => true), $options); /* @var $tagModel Tinhte_XenTag_Model_Tag */ $tagModel = $dw->getModelFromCache('Tinhte_XenTag_Model_Tag'); /* @var $taggedModel Tinhte_XenTag_Model_TaggedContent */ $taggedModel = $dw->getModelFromCache('Tinhte_XenTag_Model_TaggedContent'); if ($dw->isInsert()) { // saves 1 query $existingTags = array(); } else { $existingTags = $tagModel->getTagsOfContent($contentType, $contentId); } $changed = false; $newTagTexts = array(); $removedTagTexts = array(); $updatedTags = $existingTags; $tagModel->lookForNewAndRemovedTags($existingTags, $tagTexts, $newTagTexts, $removedTagTexts); $canCreateNew = XenForo_Visitor::getInstance()->hasPermission('general', Tinhte_XenTag_Constants::PERM_USER_CREATE_NEW); $errorHandler = XenForo_DataWriter::ERROR_SILENT; if (!empty($options['throwException'])) { $errorHandler = XenForo_DataWriter::ERROR_EXCEPTION; } if (!empty($newTagTexts)) { // sondh@2012-09-21 // remove duplicate foreach (array_keys($newTagTexts) as $key) { $newTagTexts[$key] = Tinhte_XenTag_Helper::getNormalizedTagText($newTagTexts[$key]); } $newTagTexts = array_unique($newTagTexts); $newButExistingTags = $tagModel->getTagsByText($newTagTexts); foreach ($newTagTexts as $newTagText) { $newTag = $tagModel->getTagFromArrayByText($newButExistingTags, $newTagText); if (empty($newTag)) { if ($canCreateNew) { /* @var $dwTag Tinhte_XenTag_DataWriter_Tag */ $dwTag = XenForo_DataWriter::create('Tinhte_XenTag_DataWriter_Tag', $errorHandler); $dwTag->set('tag_text', $newTagText); $dwTag->set('created_user_id', $contentUserId); if ($dwTag->save()) { $newTag = $dwTag->getMergedData(); } } else { if (!empty($options['throwException'])) { throw new XenForo_Exception(new XenForo_Phrase('tinhte_xentag_you_can_not_create_new_tag'), true); } continue; } } if (empty($newTag)) { // no tag to use, abort continue; } if (!empty($newTag['is_staff']) and !XenForo_Visitor::getInstance()->hasPermission('general', Tinhte_XenTag_Constants::PERM_USER_IS_STAFF)) { if (!empty($options['throwException'])) { throw new XenForo_Exception(new XenForo_Phrase('tinhte_xentag_you_can_not_use_tag_x', array('tag_text' => $newTag['tag_text'])), true); } continue; } /* @var $dwTag Tinhte_XenTag_DataWriter_TaggedContent */ $dwTagged = XenForo_DataWriter::create('Tinhte_XenTag_DataWriter_TaggedContent', $errorHandler); $dwTagged->set('tag_id', $newTag['tag_id']); $dwTagged->set('content_type', $contentType); $dwTagged->set('content_id', $contentId); $dwTagged->set('tagged_user_id', $contentUserId); if ($dwTagged->save()) { $updatedTags[] = $newTag; self::$_newTaggeds[] = array_merge($dwTagged->getMergedData(), $newTag); $changed = true; } } } if (!empty($removedTagTexts)) { foreach ($removedTagTexts as $removedTagText) { $removedTag = $tagModel->getTagFromArrayByText($existingTags, $removedTagText); if (!empty($removedTag)) { if (!empty($removedTag['is_staff']) and !XenForo_Visitor::getInstance()->hasPermission('general', Tinhte_XenTag_Constants::PERM_USER_IS_STAFF)) { if (!empty($options['throwException'])) { throw new XenForo_Exception(new XenForo_Phrase('tinhte_xentag_you_can_not_remove_tag_x', array('tag_text' => $removedTag['tag_text'])), true); } continue; } /* @var $dwTag Tinhte_XenTag_DataWriter_TaggedContent */ $dwTagged = XenForo_DataWriter::create('Tinhte_XenTag_DataWriter_TaggedContent', $errorHandler); $data = array('tag_id' => $removedTag['tag_id'], 'content_type' => $contentType, 'content_id' => $contentId); $dwTagged->setExistingData($data, true); if ($dwTagged->delete()) { // remove the removed tag from updated tags array foreach (array_keys($updatedTags) as $key) { if ($updatedTags[$key]['tag_id'] == $removedTag['tag_id']) { unset($updatedTags[$key]); } } $changed = true; } } } } if ($changed) { $tagModel->rebuildTagsCache(); } $packedTags = $tagModel->packTags($updatedTags); foreach ($packedTags as $packedTag) { if (!is_string($packedTag)) { // at least one of the packed tag is not tag text // we need to return the packed tags array return $packedTags; } } // simply return the counter return count($packedTags); }