Ejemplo n.º 1
0
 /**
  * Parses the manifest.xml file for a set of images. This is only used during testing.
  *
  * @version 1.0
  * @since 1.0
  *
  * @param bool $randomize | True to randomize order of images. False to use order set in manifest.xml file.
  * @return array | Array of image data arrays.
  */
 public function parseXML($content_path, $randomize = false)
 {
     $cls = new FOX_xml();
     $parsed_xml = $cls->parseFile($content_path . "manifest.xml", 1, 'tag');
     $temp = array();
     $order = explode(",", $parsed_xml["manifest"]["order"]);
     $parsed_xml = $parsed_xml["manifest"]["items"];
     if (array_key_exists("id", $parsed_xml["item"])) {
         $parsed_xml = array("0" => $parsed_xml["item"]);
     } else {
         $parsed_xml = $parsed_xml["item"];
     }
     $total_images = count($parsed_xml) - 1;
     for ($idx = 0; $idx <= $total_images; $idx++) {
         $image = array();
         $image["id"] = $parsed_xml[$idx]["file"];
         if ($parsed_xml[$idx]["meta"]["pixels_x"] > $parsed_xml[$idx]["meta"]["pixels_y"]) {
             $scale_factor = 600 / $parsed_xml[$idx]["meta"]["pixels_x"];
             $image["x"] = 600;
             $image["y"] = (int) round($parsed_xml[$idx]["meta"]["pixels_y"] * $scale_factor);
         } elseif ($parsed_xml[$idx]["meta"]["pixels_y"] > $parsed_xml[$idx]["meta"]["pixels_x"]) {
             $scale_factor = 600 / $parsed_xml[$idx]["meta"]["pixels_y"];
             $image["y"] = 600;
             $image["x"] = (int) round($parsed_xml[$idx]["meta"]["pixels_x"] * $scale_factor);
         } else {
             $image["x"] = 600;
             $image["y"] = 600;
         }
         $image["info"]["author"] = $parsed_xml[$idx]["author"];
         $image["info"]["title"] = $parsed_xml[$idx]["title"];
         $image["info"]["album"] = $parsed_xml[$idx]["album"];
         $image["meta"]["views"] = mt_rand(0, 1000000);
         $image["meta"]["likes"] = mt_rand(0, 10000);
         $image["meta"]["comments"] = mt_rand(0, 1000);
         $image["meta"]["downloads"] = mt_rand(0, 100000);
         $temp[$parsed_xml[$idx]["id"]] = $image;
     }
     unset($block_idx);
     // Set the order of the images
     // ============================================================
     $result = array();
     if ($randomize == true) {
         $result = $temp;
         shuffle($result);
     } else {
         foreach ($order as $key) {
             $result[] = $temp[$key];
         }
     }
     return $result;
 }
 /**
  * Loads the configuration data for the template the module is currently using
  *
  * @version 1.0
  * @since 1.0
  * 
  * @param string $plugin_path | Path to the plugin's root folder
  * @param string $type | Module type - "page" (page module), "album" (album module), "media" (media module)
  * @param string $slug | Module slug
  * 
  * @return bool | Exception on failure. True on Success.
  */
 public function loadTemplateConfig($plugin_path, $type, $slug)
 {
     if (!$this->init) {
         throw new FOX_exception(array('numeric' => 0, 'text' => "Descendent class must call init() before using class methods", 'file' => __FILE__, 'class' => __CLASS__, 'function' => __FUNCTION__, 'line' => __LINE__, 'child' => null));
     }
     // Child theme
     // ================================================================
     // A child theme will almost always specify its own custom CSS styles, which can be found
     // in get_stylesheet_directory(), so check here first.
     if (file_exists(get_stylesheet_directory() . '/' . $type . '/' . $slug . '/config.xml')) {
         $located_template = get_stylesheet_directory() . '/' . $type . '/' . $slug . '/config.xml';
     } elseif (file_exists(get_template_directory() . '/' . $type . '/' . $slug . '/config.xml')) {
         $located_template = get_template_directory() . '/' . $type . '/' . $slug . '/config.xml';
     } else {
         $located_template = $plugin_path . '/modules/' . $type . '/' . $slug . '/templates/config.xml';
     }
     $template_name = 'modules/' . $type . '/' . $slug . '/config.xml';
     $located_template = locate_template($template_name, $load = false, true);
     if (!$located_template) {
         return false;
     } else {
         $cls = new FOX_xml();
         $result = $cls->parseFile($located_template, 1, 'attribute');
         $primary = $result["config"]["tabs"]["primary"];
         if ($primary["targets"]) {
             if (count($primary["targets"]["loc"]) == 1) {
                 $this->targets[$primary["targets"]["loc"]["name"]["value"]] = true;
             } elseif (count($primary["targets"]["loc"]) > 1) {
                 foreach ($primary["targets"]["loc"] as $target) {
                     $this->targets[$target["name"]["value"]] = true;
                 }
                 unset($target);
             }
         }
         if ($primary["views"]) {
             if (count($primary["views"]["view"]) == 1) {
                 $this->views[$primary["views"]["view"]["name"]["value"]] = $primary["views"]["view"]["desc"]["value"];
             } elseif (count($primary["views"]["view"]) > 1) {
                 foreach ($primary["views"]["view"] as $view) {
                     $this->views[$view["name"]["value"]] = $view["desc"]["value"];
                 }
                 unset($view);
             }
         }
         if ($primary["caps"]) {
             if (count($primary["caps"]["cap"]) == 1) {
                 $this->caps[$primary["caps"]["cap"]["name"]["value"]] = $primary["caps"]["cap"]["desc"]["value"];
             } elseif (count($primary["caps"]["cap"]) > 1) {
                 foreach ($primary["caps"]["cap"] as $cap) {
                     $this->caps[$cap["name"]["value"]] = $cap["desc"]["value"];
                 }
                 unset($cap);
             }
         }
         if ($primary["thumbs"]) {
             $this->thumbs["algorithm"] = $primary["thumbs"]["algorithm"]["value"];
             $this->thumbs["page"] = $primary["thumbs"]["page"]["value"];
             $this->thumbs["row"] = $primary["thumbs"]["row"]["value"];
             $this->thumbs["base"] = $primary["thumbs"]["base"]["value"];
             $this->thumbs["scale_x"] = $primary["thumbs"]["scale_x"]["value"];
             $this->thumbs["scale_y"] = $primary["thumbs"]["scale_y"]["value"];
             $this->thumbs["order"] = $primary["thumbs"]["order"]["value"];
             $this->thumbs["direction"] = $primary["thumbs"]["direction"]["value"];
         }
         //FOX_Debug::dump($this->targets); FOX_Debug::dump($this->views); FOX_Debug::dump($this->caps); die;
         return true;
     }
 }