示例#1
0
 /**
  * Processes the POST data from the previous state.
  * @param AdminState $st The next state to be populated with the POST data
  * from the previous state.
  */
 private function processPost($st)
 {
     $state = $st;
     if (isset($_POST['Uninstall'])) {
         $this->uninstall();
         $state->render();
     } else {
         if (isset($_POST["Next"])) {
             if ($_POST["Next"] == "Delete") {
                 LongTailFramework::setConfig($_POST[LONGTAIL_KEY . "config"]);
                 LongTailFramework::deleteConfig();
                 $configs = LongTailFramework::getConfigs();
                 if ($configs && count($configs) >= 2 && $_POST[LONGTAIL_KEY . "config"] == get_option($_POST[LONGTAIL_KEY . "default"])) {
                     update_option(LONGTAIL_KEY . "default", $configs[1]);
                 } else {
                     if (!$configs || count($configs) == 1) {
                         update_option(LONGTAIL_KEY . "default", "Out-of-the-Box");
                     }
                 }
                 $state = new PlayerState($_POST[LONGTAIL_KEY . "config"]);
                 $del_player = $_POST[LONGTAIL_KEY . "config"];
                 $this->feedback_message("The '{$del_player}' Player was successfully deleted.");
                 $state->render();
             } else {
                 if ($_POST["Next"] == "Create Custom Player") {
                     $_POST[LONGTAIL_KEY . "new_player"] = "Custom Player";
                 }
                 $state->getNextState()->render();
             }
         } else {
             if (isset($_POST["Previous"])) {
                 $state->getPreviousState()->render();
             } else {
                 if (isset($_POST["Cancel"])) {
                     $state->getCancelState()->render();
                 } else {
                     if (isset($_POST["Save"])) {
                         $config = $_POST[LONGTAIL_KEY . "config"];
                         LongTailFramework::setConfig($config);
                         $save_values = $this->processSubmit();
                         $success = LongTailFramework::saveConfig($this->convertToXML($save_values), esc_html($_POST[LONGTAIL_KEY . "new_player"]));
                         $configs = LongTailFramework::getConfigs();
                         if ($configs && count($configs) == 2) {
                             update_option(LONGTAIL_KEY . "default", $_POST[LONGTAIL_KEY . "config"] ? $_POST[LONGTAIL_KEY . "config"] : $_POST[LONGTAIL_KEY . "new_player"]);
                             update_option(LONGTAIL_KEY . "ootb", false);
                         }
                         $save_player = $_POST[LONGTAIL_KEY . "new_player"] ? $_POST[LONGTAIL_KEY . "new_player"] : $config;
                         if ($success) {
                             $this->feedback_message("The '{$save_player}' Player was successfully saved.");
                         } else {
                             $this->error_message("The '{$save_player}' failed to save.  Please make sure the " . LongTailFramework::getConfigPath() . " exists and is writable.  " . JW_FILE_PERMISSIONS);
                         }
                         $state->getSaveState()->render();
                     } else {
                         if (isset($_POST[LONGTAIL_KEY . "default"])) {
                             update_option(LONGTAIL_KEY . "default", $_POST[LONGTAIL_KEY . "default"]);
                         }
                         if (isset($_POST[LONGTAIL_KEY . "show_archive"])) {
                             update_option(LONGTAIL_KEY . "show_archive", true);
                         } else {
                             if (!empty($_POST)) {
                                 update_option(LONGTAIL_KEY . "show_archive", false);
                             }
                         }
                         LongTailFramework::setConfig($_POST[LONGTAIL_KEY . "config"]);
                         $state->render();
                     }
                 }
             }
         }
     }
 }
 /**
  * Creates a Plugin object which represents a given Player plugin.
  * @param file $file The xml file which represents the Plugin
  * @param &$config_values The currently loaded config values.  Used to
  * distinguish between standard flashvars and additional flashvars.
  * @return A new Plugin object
  */
 private static function processPlugin($file, &$config_values = null)
 {
     $plugin_xml = simplexml_load_file(LongTailFramework::getPluginPath() . $file);
     $title = (string) $plugin_xml->{"title"};
     $version = (string) $plugin_xml->{"version"};
     $file_name = (string) $plugin_xml->{"filename"};
     $repository = (string) $plugin_xml->{"repository"};
     $description = (string) $plugin_xml->{"description"};
     $href = (string) $plugin_xml->{"page"};
     $enabled = false;
     $config_found = true;
     $plugin_name = str_replace(".swf", "", $file_name);
     //Check if the config file exists.
     if (file_exists(LongTailFramework::getConfigPath())) {
         $config_file = simplexml_load_file(LongTailFramework::getConfigPath());
     } else {
         $config_found = false;
     }
     $enabled = strstr((string) $config_file->plugins, $repository) ? true : false;
     $f_vars = array();
     //Process the flashvars in the plugin xml file.
     foreach ($plugin_xml->flashvars as $flash_vars) {
         $f_var = array();
         $f_var_section = (string) $flash_vars["section"];
         $f_var_section = $f_var_section ? $f_var_section : "FlashVars";
         foreach ($flash_vars as $flash_var) {
             $default = (string) $flash_var->{"default"};
             //If the config file was loaded and has an entry for the current flashvar
             //use the value in the config file and set the plugin as enabled.
             if ($config_found && $config_file->{$plugin_name . "." . $flash_var->name}) {
                 $p_key = $plugin_name . "." . $flash_var->name;
                 if ($config_values != null) {
                     unset($config_values[(string) $p_key]);
                 }
                 $default = (string) $config_file->{$plugin_name . "." . $flash_var->name};
             }
             $values = (array) $flash_var->select;
             $temp_var = new FlashVar((string) $flash_var->name, $default, (string) $flash_var->description, (array) $values["option"], (string) $flash_var["type"]);
             $f_var[(string) $flash_var->name] = $temp_var;
         }
         $f_vars[$f_var_section] = $f_var;
     }
     $plugin = new Plugin($title, $version, $repository, $file_name, $enabled, $description, $f_vars, $href);
     return $plugin;
 }