Esempio n. 1
0
 public static function getCustomMarkupHtml($options, $category, $user, array $extraClasses = array())
 {
     $stylingOrder = array_map('intval', XenForo_Application::getOptions()->get("3ps_cmfu_markupStylingOrder"));
     $dr = self::_getDataRegistryModel();
     if (XenForo_Application::getOptions()->get("3ps_cmfu_useCache")) {
         $renderCache = $dr->get("3ps_cmfu_render_cache_" . $user["user_id"] . "_" . $category);
         if (!empty($renderCache)) {
             $useCache = true;
             $storeResultsInCache = false;
         } else {
             $useCache = false;
             $storeResultsInCache = true;
         }
     } else {
         $useCache = false;
         $storeResultsInCache = false;
     }
     if (!$useCache) {
         if (isset($options[$category]["presets"]) && !empty($options[$category]["presets"])) {
             $presetsModel = self::_getPresetModel();
             $presetDefs = $presetsModel->getSortedPresetsByIds($options[$category]["presets"]);
             // Squash prefix as appropriate
             if ($stylingOrder["preset"] > $stylingOrder["user"]) {
                 // Preset wins
                 foreach ($presetDefs as $preset) {
                     $config = unserialize($preset["config"]);
                     $options[$category] = array_merge($options[$category], $config["preset"]);
                 }
             } else {
                 // User wins
                 // Squash all prefixes
                 $finalPresetsDefs = array();
                 foreach ($presetDefs as $preset) {
                     $config = unserialize($preset["config"]);
                     $finalPresetsDefs = array_merge($finalPresetsDefs, $config["preset"]);
                 }
                 // Apply it onto options
                 $options[$category] = array_merge($finalPresetsDefs, $options[$category]);
             }
             unset($options[$category]["presets"]);
         }
         $insertBefore = false;
         if ($stylingOrder["default"] > 0) {
             if ($stylingOrder["preset"] > $stylingOrder["user"]) {
                 if ($stylingOrder["default"] > $stylingOrder["preset"]) {
                     $insertBefore = true;
                 }
             } else {
                 if ($stylingOrder["default"] > $stylingOrder["user"]) {
                     $insertBefore = true;
                 }
             }
         }
         $html = ThreePointStudio_CustomMarkupForUser_Helpers::assembleCustomMarkup($options, $category, $extraClasses, $insertBefore);
     } else {
         $html = $renderCache;
     }
     if ($storeResultsInCache) {
         $dr->set("3ps_cmfu_render_cache_" . $user["user_id"] . "_" . $category, $html);
     }
     return $html;
 }
Esempio n. 2
0
 protected function _getPresetAddEditResponse(array $preset = null)
 {
     $user = XenForo_Visitor::getInstance()->toArray();
     if ($preset == null) {
         $preset = array("config" => array("preset" => array()), "enable_for" => ThreePointStudio_CustomMarkupForUser_Constants::$defaultOptionsArray, "user_groups" => array());
         $options = $preset["config"];
     } else {
         $preset["enable_for"] = unserialize($preset["enable_for"]);
         $preset["user_groups"] = unserialize($preset["user_groups"]);
         $options = unserialize($preset["config"]);
     }
     $viewOptions = ThreePointStudio_CustomMarkupForUser_Helpers::prepareOptionsForView($options);
     $html = str_replace("{inner}", $user["username"], ThreePointStudio_CustomMarkupForUser_Helpers::assembleCustomMarkup($options, "preset"));
     $userGroups = array();
     foreach ($this->_getUserGroupModel()->getAllUserGroupTitles() as $userGroupId => $title) {
         $userGroups[] = array('label' => $title, 'value' => $userGroupId, 'selected' => in_array($userGroupId, $preset["user_groups"]));
     }
     $viewParams = array_merge(array("userGroups" => $userGroups, "preset" => $preset, "title" => new XenForo_Phrase("3ps_cmfu_preset"), "titleCode" => "preset", "userOptions" => $viewOptions["preset"], "currentMarkupRender" => $html), ThreePointStudio_CustomMarkupForUser_Helpers::getBaseViewParams());
     return $this->responseView('ThreePointStudio_CustomMarkupForUser_ViewAdmin_Presets', '3ps_cmfu_presets_edit', $viewParams);
 }