Exemple #1
0
 public function testAdd()
 {
     $Url = new Url("/test/blah");
     $this->assertInstanceOf("Railpage\\Url", $Url);
     $this->assertEquals("/test/blah", $Url->url);
     $this->assertEquals("http://www.railpage.com.au/test/blah", $Url->canonical);
     $_SERVER['debug'] = true;
     $Url = new Url("/test/blah2");
     $this->assertEquals("/test/blah2", $Url->url);
     $this->assertTrue(count($Url->getURLs()) >= 1);
 }
Exemple #2
0
 /**
  * Commit changes to a job
  * @since Version 3.8
  * @return boolean
  */
 public function commit()
 {
     try {
         $this->validate();
     } catch (Exception $e) {
         throw new Exception($e->getMessage());
         return false;
     }
     /**
      * Firstly, check if this reference ID exists anywhere in the database. If it does, update, not create.
      */
     if (filter_var($this->reference_id, FILTER_VALIDATE_INT) && $this->reference_id > 0) {
         $query = "SELECT job_id FROM jn_jobs WHERE reference_id = ?";
         if ($id = $this->db->fetchOne($query, $this->reference_id)) {
             $this->id = $id;
         }
     }
     $data = array("job_title" => $this->title, "reference_id" => $this->reference_id, "organisation_id" => $this->Organisation->id, "job_location_id" => $this->Location->id, "job_description" => $this->desc, "job_added" => $this->Open->format("Y-m-d H:i:s"), "job_expiry" => $this->expiry->format("Y-m-d H:i:s"), "job_classification_id" => $this->Classification->id, "job_salary" => $this->salary, "job_special_cond" => $this->special_cond, "job_duration" => $this->duration, "job_thread_id" => $this->thread_id, "job_urls" => json_encode($this->url->getUrls()));
     if (filter_var($this->id, FILTER_VALIDATE_INT)) {
         // Update
         if ($this->db->update("jn_jobs", $data, "job_id = " . $this->id)) {
             return true;
         }
     } else {
         // Insert
         if ($this->db->insert("jn_jobs", $data)) {
             $this->id = $this->db->lastInsertId();
             $this->url = new Url(sprintf("%s?mode=view&id=%d", $this->Module->url, $this->id));
             return $this;
         }
     }
 }
 /**
  * Process the emoticons, BBCode, rich text, embedded content etc in this object and return as HTML
  * @since Version 3.10.0
  * @param string $string
  * @param array $options
  * @return string
  */
 public static function formatText($string, $options)
 {
     AppCore::getSmarty()->addStylesheet("/themes/jiffy_simple/style/opt.embedded.css");
     $defaultOptions = ["bbcode_uid" => "sausages", "flag_html" => true, "flag_bbcode" => true, "flag_emoticons" => true, "strip_formatting" => false, "editor_version" => 1];
     $options = array_merge($defaultOptions, is_array($options) ? $options : []);
     if (empty(trim($string))) {
         throw new InvalidArgumentException("Cannot execute " . __METHOD__ . " as no text was provided!");
     }
     $cacheKey = "railpage:formatText=" . sha1((string) $string . json_encode($options)) . ";" . self::$formatTextVer;
     $cacheProvider = AppCore::getMemcached();
     $processedText = false;
     if ($processedText = $cacheProvider->fetch($cacheKey)) {
         return $processedText;
     }
     /**
      * @todo
      * - make clickable - doesn't seem to do anything? 24/03/2016
      * - convert to UTF8 - is this still required? 24/03/2016
      */
     $string = EmoticonsUtility::Process($string, $options['flag_emoticons']);
     $string = Html::cleanupBadHtml($string, $options['editor_version']);
     $string = Html::removeHeaders($string);
     $string = BbcodeUtility::Process($string, $options['flag_bbcode']);
     $string = MultimediaUtility::Process($string);
     $string = MakeClickable::Process($string);
     $string = Url::offsiteUrl((string) $string);
     if (is_object($string)) {
         $string = $string->__toString();
     }
     if ($options['strip_formatting'] == true) {
         $string = strip_tags($string);
     }
     $rs = $cacheProvider->save($cacheKey, $string, 0);
     // 3600 * 24 * 30);
     return $string;
 }
 /**
  * Get path of this route
  * @since Version 3.9
  * @return array
  */
 public function getPath()
 {
     $mckey = sprintf("railpage:gtfs.path;provider=%s;route=%s", $this->Provider->getProviderName(), $this->short_name);
     $Memcached = AppCore::GetMemcached();
     if ($path = $Memcached->fetch($mckey)) {
         return $path;
     }
     $query = sprintf("SELECT id, service_id, trip_id, trip_headsign, shape_id, meta FROM %s_trips WHERE route_id = '%s' LIMIT 1", $this->Provider->getDbPrefix(), $this->short_name);
     $result = $this->adapter->query($query, Adapter::QUERY_MODE_EXECUTE);
     if ($result) {
         foreach ($result as $row) {
             $trip = $row->getArrayCopy();
         }
     }
     if (!isset($trip)) {
         return false;
     }
     $query = "SELECT t.id, t.arrival_time, t.departure_time, t.stop_id, t.stop_sequence, t.pickup_type, t.drop_off_type, t.timepoint, t.meta AS time_meta, \r\n                    s.stop_code, s.stop_name, s.stop_lat, s.stop_lon, s.location_type, s.wheelchair_boarding, s.platform_code, s.meta AS stop_meta\r\n                    FROM %s_stop_times AS t LEFT JOIN %s_stops AS s ON t.stop_id = s.stop_id\r\n                    WHERE t.trip_id = %d ORDER BY t.stop_sequence";
     $query = sprintf($query, $this->Provider->getDbPrefix(), $this->Provider->getDbPrefix(), $trip['trip_id']);
     $result = $this->adapter->query($query, Adapter::QUERY_MODE_EXECUTE);
     $path = array();
     if ($result) {
         foreach ($result as $row) {
             $url = new Url(sprintf("/timetables?mode=stop&provider=%s&id=%d", $this->Provider->getProviderName(), $row['stop_id']));
             $row = $row->getArrayCopy();
             $row['stop_meta'] = json_decode($row['stop_meta'], true);
             $row['time_meta'] = json_decode($row['time_meta'], true);
             $row['url'] = $url->getURLs();
             $path[] = $row;
         }
     }
     $Memcached->save($mckey, $path, strtotime("+1 month"));
     return $path;
 }
 /**
  * Convert Vimeo links into embedded content
  * @since Version 3.10.0
  * @param \DOMElement $e
  * @return \DOMElement
  */
 public static function EmbedVimeo(DOMElement $e)
 {
     $timer = Debug::GetTimer();
     $url = pq($e)->attr("href");
     if (strpos($url, "vimeo.com") === false) {
         return $e;
     }
     // Fetch oEmbed
     $oembed = Url::oEmbedLookup(sprintf("https://vimeo.com/api/oembed.json?url=%s", $url));
     if (!is_array($oembed) || !isset($oembed['html'])) {
         return $e;
     }
     $video_iframe = pq($oembed['html']);
     $video_iframe->addClass("content-iframe")->addClass("content-vimeo");
     pq($e)->after("<br><br><a href='" . $url . "'>" . $oembed['title'] . " by " . $oembed['author_name'] . "</a>")->replaceWith($video_iframe);
     Debug::LogEvent(__METHOD__, $timer);
     return $e;
 }
Exemple #6
0
 /**
  * Get this job as an associative array
  * @since Versio 3.9.1
  * @return array
  */
 public function getArray()
 {
     $return = array("id" => $this->id, "title" => $this->title, "reference_id" => $this->reference_id, "description" => $this->desc, "added" => array("absolute" => $this->Open->format("Y-m-d H:i:s")), "expiry" => array("absolute" => $this->expiry->format("Y-m-d H:i:s")), "location" => array("id" => $this->Location->id, "name" => $this->Location->name), "organisation" => array("id" => $this->Organisation->id, "name" => $this->Organisation->name), "classification" => array("id" => $this->Classification->id, "name" => $this->Classification->name), "url" => $this->url->getURLs());
     return $return;
 }