public function actionPresetsSave() { $this->_assertPostOnly(); /* @var $presetsModel ThreePointStudio_CustomMarkupForUser_Model_Preset */ $presetsModel = $this->getModelFromCache("ThreePointStudio_CustomMarkupForUser_Model_Preset"); $preset_id = $this->_input->filterSingle("preset_id", XenForo_Input::UINT); if (!$preset_id) { $preset_id = 0; } $dwInput = $this->_input->filter(array("title" => XenForo_Input::STRING, "display_style_priority" => XenForo_Input::UINT, "enable_for" => array(XenForo_Input::UINT, 'array' => true), "user_groups" => array(XenForo_Input::UINT, 'array' => true))); $options = $this->_input->filterSingle("3ps_cmfu_options", XenForo_Input::ARRAY_SIMPLE); foreach ($options as $category => $catArray) { foreach ($catArray as $itemName => $itemValue) { if (ThreePointStudio_CustomMarkupForUser_Helpers::startsWith($itemName, "enable_")) { unset($options[$category][$itemName]); // Ignore any placeholders continue; } $options[$category][$itemName] = XenForo_Input::rawFilter($itemValue, ThreePointStudio_CustomMarkupForUser_Constants::$availableMarkups[$itemName]["type"]); } } foreach ($options as $category => $catArray) { foreach ($catArray as $itemName => $itemValue) { $itemArray = ThreePointStudio_CustomMarkupForUser_Constants::$availableMarkups[$itemName]; // Check if we have dependencies if (isset($itemArray["requires"])) { foreach ($itemArray["requires"] as $requirement) { if ($catArray[$requirement[0]] !== $requirement[1]) { unset($options[$category][$itemName]); // Dependency not match, skipping continue; } } } if (!call_user_func($itemArray["verify"]["func"], $itemValue)) { return $this->responseError(new XenForo_Phrase($itemArray["verify"]["error"])); // Validation failed, ragequit } } } $dwInput["config"] = serialize($options); $dwInput["user_groups"] = serialize($dwInput["user_groups"]); $dwInput["enable_for"] = serialize($dwInput["enable_for"]); $preset_id = $presetsModel->updatePreset($preset_id, $dwInput); return $this->responseRedirect(XenForo_ControllerResponse_Redirect::SUCCESS, XenForo_Link::buildAdminLink('3ps-cmfu/presets') . $this->getLastHash($preset_id)); }
protected function _prepareUserSearchCriteria(array $criteria) { if (!empty($criteria['last_activity'])) { $criteria['last_activity'] = array('>=', XenForo_Input::rawFilter($criteria['last_activity'], XenForo_Input::DATE_TIME)); } if (!empty($criteria['message_count'])) { $criteria['message_count'] = array('>=', $criteria['message_count']); } if (isset($criteria['is_banned']) && is_array($criteria['is_banned'])) { $criteria['is_banned'] = reset($criteria['is_banned']); } foreach (array('username', 'username2', 'email') as $field) { if (isset($criteria[$field]) && is_string($criteria[$field])) { $criteria[$field] = trim($criteria[$field]); } } return $criteria; }
/** * Handles the special case of 'type' being submitted as type[post][thread_id] = x, * In which case, the input should be translated as type=post, thread_id=x * * @return string */ protected function _handleInputType(array &$input = array()) { if ($this->_input->inRequest('type')) { $typeParam = $this->_request->get('type'); if (is_array($typeParam) && !empty($typeParam)) { list($type, $typeExtra) = each($typeParam); if (is_array($typeExtra)) { foreach ($typeExtra as $paramName => $paramValue) { if (!empty($paramName) && !empty($paramValue)) { $paramNameClean = XenForo_Input::rawFilter($paramName, XenForo_Input::STRING); $this->_request->setParam($paramNameClean, $paramValue); if (isset($input[$paramNameClean])) { $input[$paramNameClean] = $paramValue; } } } } return XenForo_Input::rawFilter($type, XenForo_Input::STRING); } else { return $this->_input->filterSingle('type', XenForo_Input::STRING); } } return ''; }
public function actionSave() { $response = parent::actionSave(); $userId = $this->_input->filterSingle('user_id', XenForo_Input::UINT); if ($userId == 0) { return $response; } // Not sure why, but don't do it $options = $this->_input->filterSingle("3ps_cmfu_options", XenForo_Input::ARRAY_SIMPLE); if (empty($options)) { // Nothing in here, populate it with nothingness $options = ThreePointStudio_CustomMarkupForUser_Constants::$defaultOptionsArray; } // Pre-check cleanup foreach ($options as $category => $catArray) { foreach ($catArray as $itemName => $itemValue) { if (ThreePointStudio_CustomMarkupForUser_Helpers::startsWith($itemName, "enable_")) { unset($options[$category][$itemName]); // Ignore any placeholders continue; } if ($itemName == "presets") { $options[$category][$itemName] = XenForo_Input::rawFilter($itemValue, XenForo_Input::ARRAY_SIMPLE); } else { $options[$category][$itemName] = XenForo_Input::rawFilter($itemValue, ThreePointStudio_CustomMarkupForUser_Constants::$availableMarkups[$itemName]["type"]); } } } foreach ($options as $category => $catArray) { foreach ($catArray as $itemName => $itemValue) { if ($itemName == "presets") { continue; // Don't process presets } $itemArray = ThreePointStudio_CustomMarkupForUser_Constants::$availableMarkups[$itemName]; // Check if we have dependencies if (isset($itemArray["requires"])) { foreach ($itemArray["requires"] as $requirement) { if ($catArray[$requirement[0]] !== $requirement[1]) { unset($options[$category][$itemName]); // Dependency not match, skipping continue; } } } if (!call_user_func($itemArray["verify"]["func"], $itemValue)) { return $this->responseError(new XenForo_Phrase($itemArray["verify"]["error"])); // Validation failed, ragequit } } } $dw = XenForo_DataWriter::create('XenForo_DataWriter_User'); $dw->setExistingData($userId); $dw->set("3ps_cmfu_options", serialize($options)); if (XenForo_Application::getOptions()->get("3ps_cmfu_useCache")) { $dw->rebuildCustomMarkupCache(); } $dw->save(); return $response; // No error from our end, continue executing }
public function actionPreferencesSave() { $response = parent::actionPreferencesSave(); /* @var $userModel XenForo_Model_User */ $userModel = $this->getModelFromCache("XenForo_Model_User"); $user = $userModel->getUserById(XenForo_Visitor::getUserId()); $user["user_groups"] = array_merge(array((int) $user["user_group_id"]), explode(",", $user["secondary_group_ids"])); $options = $this->_input->filterSingle("3ps_cmfu_options", XenForo_Input::ARRAY_SIMPLE); /* @var $presetsModel ThreePointStudio_CustomMarkupForUser_Model_Preset */ $presetsModel = $this->getModelFromCache("ThreePointStudio_CustomMarkupForUser_Model_Preset"); $userPermissions = array("username" => ThreePointStudio_CustomMarkupForUser_Helpers::assembleCustomMarkupPermissionForUser("username"), "usertitle" => ThreePointStudio_CustomMarkupForUser_Helpers::assembleCustomMarkupPermissionForUser("usertitle")); if (empty($options)) { // Nothing in here, populate it with nothingness $options = ThreePointStudio_CustomMarkupForUser_Constants::$defaultOptionsArray; } // Pre-check cleanup foreach ($options as $category => $catArray) { foreach ($catArray as $itemName => $itemValue) { if (ThreePointStudio_CustomMarkupForUser_Helpers::startsWith($itemName, "enable_")) { unset($options[$category][$itemName]); // Ignore any placeholders continue; } if ($itemName == "presets") { $options[$category][$itemName] = XenForo_Input::rawFilter($itemValue, XenForo_Input::ARRAY_SIMPLE); } else { $options[$category][$itemName] = XenForo_Input::rawFilter($itemValue, ThreePointStudio_CustomMarkupForUser_Constants::$availableMarkups[$itemName]["type"]); } } } foreach ($options as $category => $catArray) { foreach ($catArray as $itemName => $itemValue) { if ($itemName == "presets") { if (!is_array($itemValue)) { $options[$category]["presets"] = array(); } foreach ($itemValue as $index => $presetId) { // Can we do this? $thePreset = $presetsModel->getPresetById($presetId); $user_groups = unserialize($thePreset["user_groups"]); $intersection = array_intersect($user_groups, $user["user_groups"]); if (empty($intersection)) { unset($options[$category]["presets"][$index]); // Validation failed continue; } } } else { $itemArray = ThreePointStudio_CustomMarkupForUser_Constants::$availableMarkups[$itemName]; // Can we do this? if (!$userPermissions[$category][$itemName]) { unset($options[$category][$itemName]); // Validation failed continue; } // Yes we can! Check if we have dependencies if (isset($itemArray["requires"])) { foreach ($itemArray["requires"] as $requirement) { if ($catArray[$requirement[0]] !== $requirement[1]) { unset($options[$category][$itemName]); // Dependency not match, skipping continue; } } } if (!call_user_func($itemArray["verify"]["func"], $itemValue)) { return $this->responseError(new XenForo_Phrase($itemArray["verify"]["error"])); // Validation failed, ragequit } } } } $dw = XenForo_DataWriter::create('XenForo_DataWriter_User'); $dw->setExistingData(XenForo_Visitor::getUserId()); $dw->set("3ps_cmfu_options", serialize($options)); $dw->save(); if (XenForo_Application::getOptions()->get("3ps_cmfu_useCache")) { $dw->rebuildCustomMarkupCache(); } return $response; // No errors from our end, continue execution }