/** * Find Railpage objects (loco, class, livery) in this image * @since Version 3.8.7 * @param string $namespace */ public function findObjects($namespace = NULL) { if (is_null($namespace)) { throw new Exception("Parameter 1 (namespace) cannot be empty"); } /** * Start the debug timer */ if (RP_DEBUG) { global $site_debug; $debug_timer_start = microtime(true); } switch ($namespace) { case "railpage.locos.loco": if (isset($this->meta['tags'])) { foreach ($this->meta['tags'] as $tag) { if (preg_match("@railpage:class=([0-9]+)@", $tag, $matches)) { $LocoClass = new LocoClass($matches[1]); } } foreach ($this->meta['tags'] as $tag) { if (isset($LocoClass) && $LocoClass instanceof LocoClass && preg_match("@railpage:loco=([a-zA-Z0-9]+)@", $tag, $matches)) { $Loco = new Locomotive(false, $LocoClass->id, $matches[1]); if (filter_var($Loco->id, FILTER_VALIDATE_INT)) { $this->addLink($Loco->namespace, $Loco->id); } } } foreach ($this->db->fetchAll("SELECT id AS class_id, flickr_tag AS class_tag FROM loco_class") as $row) { foreach ($this->meta['tags'] as $tag) { if (stristr($tag, $row['class_tag']) && strlen(str_replace($row['class_tag'] . "-", "", $tag) > 0)) { $loco_num = str_replace($row['class_tag'] . "-", "", $tag); $Loco = new Locomotive(false, $row['class_id'], $loco_num); if (filter_var($Loco->id, FILTER_VALIDATE_INT)) { $this->addLink($Loco->namespace, $Loco->id); if (!$Loco->hasCoverImage()) { $Loco->setCoverImage($this); } if (!$Loco->Class->hasCoverImage()) { $Loco->Class->setCoverImage($this); } } } } } } break; case "railpage.locos.class": if (isset($this->meta['tags'])) { foreach ($this->db->fetchAll("SELECT id AS class_id, flickr_tag AS class_tag FROM loco_class") as $row) { foreach ($this->meta['tags'] as $tag) { if ($tag == $row['class_tag']) { $LocoClass = new LocoClass($row['class_id']); if (filter_var($LocoClass->id, FILTER_VALIDATE_INT)) { $this->addLink($LocoClass->namespace, $LocoClass->id); } } } } foreach ($this->meta['tags'] as $tag) { if (preg_match("@railpage:class=([0-9]+)@", $tag, $matches)) { $LocoClass = new LocoClass($matches[1]); if (filter_var($LocoClass->id, FILTER_VALIDATE_INT)) { $this->addLink($LocoClass->namespace, $LocoClass->id); if (!$LocoClass->hasCoverImage()) { $LocoClass->setCoverImage($this); } } } } } break; case "railpage.locos.liveries.livery": if (isset($this->meta['tags'])) { foreach ($this->meta['tags'] as $tag) { if (preg_match("@railpage:livery=([0-9]+)@", $tag, $matches)) { $Livery = new Livery($matches[1]); if (filter_var($Livery->id, FILTER_VALIDATE_INT)) { $this->addLink($Livery->namespace, $Livery->id); } } } } break; } /** * End the debug timer */ if (RP_DEBUG) { $site_debug[] = __CLASS__ . "::" . __FUNCTION__ . "() : completed lookup of " . $namespace . " in for image id " . $this->id . " in " . round(microtime(true) - $debug_timer_start, 5) . "s"; } return $this; }