/**
  * Assign UTM parameters to an individual URL
  * @since Version 3.10.0
  * @param \Railpage\Newsletters\Newsletter $Newsletter
  * @param string $url
  * @return string
  */
 public static function CreateUTMParametersForLink(Newsletter $Newsletter, $url)
 {
     if (is_array($url)) {
         $url = $url['url'];
     }
     $utm = ["utm_source=newsletter", "utm_medium=email", sprintf("utm_campaign=%s", ContentUtility::generateUrlSlug($Newsletter->subject))];
     $parts = parse_url($url);
     if (!isset($parts['query'])) {
         $url .= "?" . implode("&", $utm);
         return $url;
     }
     $parts['query'] = array_merge(explode("&", $parts['query']), $utm);
     return ContentUtility::unparse_url($parts);
 }
示例#2
0
 /**
  * Create a URL slug
  * @since Version 3.9.1
  */
 private function createSlug()
 {
     $proposal = ContentUtility::generateUrlSlug($this->name);
     $result = $this->db->fetchAll("SELECT id_cat FROM nuke_faqCategories WHERE url_slug = ?", $proposal);
     if (count($result)) {
         $proposal .= count($result);
     }
     $this->url_slug = $proposal;
 }
示例#3
0
 /**
  * Validate changes to this manufacturer
  * @return boolean
  * @throws \Exception if $this->name is empty
  */
 public function validate()
 {
     if (empty($this->name)) {
         throw new Exception("Cannot validate changes to this locomotive manufacturer: manufacturer name cannot be empty");
     }
     if (empty($this->slug)) {
         $proposal = ContentUtility::generateUrlSlug($this->name, 30);
         $query = "SELECT manufacturer_id FROM loco_manufacturer WHERE slug = ?";
         $result = $this->db->fetchAll($query, $proposal);
         if (count($result)) {
             $proposal = $proposal . count($result);
         }
         $this->slug = $proposal;
         $this->url = new Url(sprintf("/locos/builder/%s", $this->slug));
     }
     $this->name = ContentUtility::FormatTitle($this->name);
     return true;
 }
示例#4
0
 /**
  * Validate changes to this locotype 
  * @since Version 3.8.7
  * @return true
  * @throws \Exception if $this->arrangement is empty
  */
 public function validate()
 {
     if (empty($this->name)) {
         throw new Exception("Cannot validate changes to this loco type: name cannot be empty");
         return false;
     }
     if (empty($this->slug)) {
         $proposal = ContentUtility::generateUrlSlug($this->name, 30);
         $query = "SELECT id FROM loco_type WHERE slug = ?";
         $result = $this->db->fetchAll($query, $proposal);
         if (count($result)) {
             $proposal = $proposal . count($result);
         }
         $this->slug = $proposal;
         $this->url = new Url(sprintf("%s/type/%s", $this->Module->url, $this->slug));
     }
     return true;
 }
示例#5
0
 /**
  * Generate the URL slug for this help item
  * @since Version 3.8.6
  * @return string
  */
 private function createSlug()
 {
     $proposal = ContentUtility::generateUrlSlug($this->title);
     /**
      * Check that we haven't used this slug already
      */
     $result = $this->db->fetchAll("SELECT id FROM nuke_faqAnswer WHERE url_slug = ?", $proposal);
     if (count($result)) {
         $proposal .= count($result);
     }
     /**
      * Return it
      */
     return $proposal;
 }
示例#6
0
 /**
  * Create a URL slug
  * @since Version 3.7.5
  * @return void
  */
 private function createSlug()
 {
     $proposal = ContentUtility::generateUrlSlug($this->name);
     $result = $this->db->fetchAll("SELECT id FROM location WHERE slug = ?", $proposal);
     if (count($result)) {
         $proposal .= count($result);
     }
     $this->slug = $proposal;
 }
示例#7
0
 /**
  * Validate changes to this collection
  * @since Version 3.9.1
  * @return void
  */
 private function validate()
 {
     if (empty($this->name)) {
         throw new Exception("Title cannot be empty");
     }
     if (empty($this->description)) {
         throw new Exception("Description cannot be empty");
     }
     if (empty($this->slug)) {
         $proposal = ContentUtility::generateUrlSlug($this->name);
         $num = $this->db->fetchAll("SELECT id FROM image_collection WHERE slug = ?", $proposal);
         if (count($num)) {
             $proposal .= count($num);
         }
         $this->slug = $proposal;
     }
     if (!$this->DateCreated instanceof DateTime) {
         $this->DateCreated = new DateTime();
     }
     $this->DateModified = new DateTime();
 }
示例#8
0
 /**
  * Make a URL slug
  * @since Version 3.9.1
  * @package Railpage
  * @author Michael Greenhill
  * @return void
  */
 private function makeSlug()
 {
     if (!empty($this->slug)) {
         return;
     }
     $proposal = ContentUtility::generateUrlSlug($this->name, 20);
     $query = "SELECT COUNT(id) FROM glossary WHERE slug = ?";
     $num = $this->db->fetchOne($query, $proposal);
     if ($num) {
         $proposal .= $num;
     }
     $this->slug = $proposal;
     if (filter_var($this->id, FILTER_VALIDATE_INT)) {
         $this->commit();
     }
     return;
 }
示例#9
0
 /**
  * Create a URL slug
  * @since Version 3.9.1
  */
 private function createSlug()
 {
     $proposal = ContentUtility::generateUrlSlug($this->width_metric);
     $result = $this->db->fetchAll("SELECT gauge_id FROM loco_gauge WHERE slug = ?", $proposal);
     if (count($result)) {
         $proposal .= count($result);
     }
     $this->slug = $proposal;
     return $this->slug;
 }
示例#10
0
 /**
  * Validate changes to this camera
  * @since Version 3.10.0
  * @throws \Exception if $this->name is empty
  * @throws \Exception if $this->manufacturer is empty
  * @return boolean
  */
 private function validate()
 {
     if (empty($this->name)) {
         throw new Exception("Camera name is empty");
     }
     if (empty($this->manufacturer)) {
         throw new Exception("Manufacturer name is empty");
     }
     if (empty($this->slug)) {
         $this->slug = ContentUtility::generateUrlSlug(sprintf("%s %s", $this->manufacturer, $this->name));
         try {
             $count = $this->db->fetchAll("SELECT id FROM image_camera WHERE url_slug = ?", $this->slug);
             if (count($count)) {
                 $this->slug .= count($count);
             }
         } catch (Exception $e) {
             // Don't care
         }
     }
     return true;
 }
示例#11
0
 /**
  * Generate the URL slug
  * @since Version 3.7.5
  * @param int $id
  * @param string $name
  * @return string
  */
 public function createSlug($id = false, $name = false)
 {
     $timer = Debug::GetTimer();
     if (filter_var($id, FILTER_VALIDATE_INT) && !$name) {
         $name = $this->db->fetchOne("SELECT organisation_name FROM organisation WHERE organisation_id = ?", $id);
     } elseif (filter_var($id, FILTER_VALIDATE_INT) && is_string($name)) {
         // Do nothing
     } elseif (isset($this->name) && !empty($this->name)) {
         $name = $this->name;
         $id = $this->id;
     } else {
         return false;
     }
     $proposal = ContentUtility::generateUrlSlug($name, 200);
     /**
      * Check that we haven't used this slug already
      */
     $result = $this->db->fetchAll("SELECT organisation_id FROM organisation WHERE organisation_slug = ? AND organisation_id != ?", array($proposal, $id));
     if (count($result)) {
         $proposal .= count($result);
     }
     if (isset($this->slug) || empty($this->slug)) {
         $this->slug = $proposal;
     }
     /**
      * Add this slug to the database
      */
     $data = array("organisation_slug" => $proposal);
     $where = array("organisation_id = ?" => $id);
     $rs = $this->db->update("organisation", $data, $where);
     Debug::LogEvent(__METHOD__, $timer);
     /**
      * Return it
      */
     return $proposal;
 }
示例#12
0
 /**
  * Make a URL slug for a camera from brand and model
  * @since Version 3.10.0
  * @param string $make
  * @param string $model
  * @return string
  */
 public static function makeCameraUrlSlug($make, $model)
 {
     $prop = ContentUtility::generateUrlSlug(sprintf("%s %s", $make, $model), 30);
     return $prop;
 }
示例#13
0
 /**
  * Generate the URL slug for this news article
  * @since Version 3.7.5
  * @param int $story_id
  * @return string
  */
 public function createSlug($story_id = false)
 {
     if (RP_DEBUG) {
         global $site_debug;
         $debug_timer_start = microtime(true);
     }
     // Assume ZendDB
     $find = array("(", ")", "-", "?", "!", "#", "\$", "%", "^", "&", "*", "+", "=");
     $replace = array();
     foreach ($find as $item) {
         $replace[] = "";
     }
     if ($story_id) {
         $title = $this->db->fetchOne("SELECT title FROM nuke_stories WHERE sid = ?", $story_id);
     } elseif (isset($this->title) && !empty($this->title)) {
         $title = $this->title;
         $story_id = $this->id;
     } else {
         return false;
     }
     $name = str_replace($find, $replace, $title);
     $proposal = ContentUtility::generateUrlSlug($name);
     /**
      * Trim it if the slug is too long
      */
     if (strlen($proposal) >= 256) {
         $proposal = substr($poposal, 0, 200);
     }
     /**
      * Check that we haven't used this slug already
      */
     $result = $this->db_readonly->fetchAll("SELECT sid FROM nuke_stories WHERE slug = ? AND sid != ?", array($proposal, $story_id));
     if (count($result)) {
         $proposal .= count($result);
     }
     if (isset($this->slug)) {
         $this->slug = $proposal;
     }
     /**
      * Add this slug to the database
      */
     $data = array("slug" => $proposal);
     $where = array("sid = ?" => $story_id);
     $rs = $this->db->update("nuke_stories", $data, $where);
     if (RP_DEBUG) {
         if ($rs === false) {
             $site_debug[] = "Zend_DB: FAILED create url slug for story ID " . $story_id . " in " . round(microtime(true) - $debug_timer_start, 5) . "s";
         } else {
             $site_debug[] = "Zend_DB: SUCCESS create url slug for story ID " . $story_id . " in " . round(microtime(true) - $debug_timer_start, 5) . "s";
         }
     }
     /**
      * Return it
      */
     return $proposal;
 }
示例#14
0
 /**
  * Validate changes to this competition
  * @since Version 3.9.1
  * @return boolean
  */
 private function validate()
 {
     if (empty($this->title)) {
         throw new Exception("Competition title cannot be empty");
     }
     if (empty($this->theme)) {
         throw new Exception("Competition theme cannot be empty");
     }
     if (empty($this->description)) {
         $this->description = "";
         #throw new Exception("Competition description cannot be empty");
     }
     if (empty($this->status) || !filter_var($this->status, FILTER_VALIDATE_INT)) {
         $this->status = Competitions::STATUS_CLOSED;
     }
     if (empty($this->slug)) {
         $proposal = ContentUtility::generateUrlSlug($this->title);
         $query = "SELECT id FROM image_competition WHERE slug = ?";
         $num = count($this->db->fetchAll($query, $proposal));
         if ($num > 0) {
             $proposal .= $num;
         }
         $this->slug = $proposal;
     }
     if (!$this->Author instanceof User || !filter_var($this->Author->id, FILTER_VALIDATE_INT)) {
         throw new Exception("Author is not set (hint: setAuthor(User))");
     }
     $dates = ["VotingDateOpen", "VotingDateClose", "SubmissionsDateOpen", "SubmissionsDateClose"];
     foreach ($dates as $date) {
         if (!$this->{$date} instanceof DateTime) {
             throw new Exception(sprintf("%s::%s must be an instance of DateTime", __CLASS__, $date));
         }
     }
     if ($this->VotingDateOpen > $this->VotingDateClose) {
         throw new Exception("VotingDateOpen is greater than VotingDateClose");
     }
     if ($this->SubmissionsDateOpen > $this->SubmissionsDateClose) {
         throw new Exception("SubmissionsDateOpen is greater than SubmissionsDateClose");
     }
     if ($this->SubmissionsDateClose > $this->VotingDateOpen) {
         throw new Exception("SubmissionsDateClose is greater than VotingDateOpen");
     }
     if ($this->SubmissionsDateOpen <= new DateTime()) {
         $this->status = Competitions::STATUS_OPEN;
     }
     if ($this->VotingDateClose <= new DateTime()) {
         $this->status = Competitions::STATUS_CLOSED;
     }
     if ($this->VotingDateClose->format("H:i:s") === "00:00:00") {
         $this->VotingDateClose = new DateTime($this->VotingDateClose->format("Y-m-d 23:59:59"));
     }
     if ($this->SubmissionsDateClose->format("H:i:s") === "00:00:00") {
         $this->SubmissionsDateClose = new DateTime($this->SubmissionsDateClose->format("Y-m-d 23:59:59"));
     }
     return true;
 }
示例#15
0
 /**
  * Create a URL slug
  * @since Version 3.8.7
  */
 private function createSlug()
 {
     if (!empty($this->slug)) {
         return;
     }
     $proposal = ContentUtility::generateUrlSlug($this->name, 14);
     $result = $this->db->fetchAll("SELECT id FROM event_categories WHERE slug = ?", $proposal);
     if (count($result)) {
         $proposal .= count($result);
     }
     $this->slug = $proposal;
 }
示例#16
0
 /**
  * Validate changes
  * @since Version 3.10.0
  * @return boolean
  */
 private function validate()
 {
     if (empty($this->title)) {
         throw new Exception("Title cannot be empty");
     }
     if (!$this->date instanceof DateTime) {
         $this->date = new DateTime();
     }
     if (empty($this->hits)) {
         $this->hits = 0;
     }
     if (empty($this->language)) {
         $this->language = "english";
     }
     if (empty($this->permalink)) {
         $prop = ContentUtility::generateUrlSlug($this->title);
         if ($rs = $this->db->fetchAll("SELECT pid FROM nuke_pages WHERE shortname = ?", $prop)) {
             $prop .= count($rs);
         }
         $this->permalink = $prop;
     }
     return true;
 }
示例#17
0
 /**
  * Validate changes to this album
  * @since Version 3.10.0
  * @return boolean
  * @throws \Exception if $this->name is empty
  * @throws \Exception if $this->Author is empty
  */
 private function validate()
 {
     if (empty($this->name)) {
         throw new Exception("Album name is empty");
     }
     if (empty($this->slug)) {
         $this->slug = ContentUtility::generateUrlSlug($this->name, 30);
         $query = "SELECT id FROM gallery_mig_album WHERE name = ?";
         $rs = $this->db->fetchAll($query, $this->slug);
         if (count($rs)) {
             $this->slug .= count($rs);
         }
     }
     if (!$this->Owner instanceof User) {
         $this->Owner = $this->getOwner();
     }
     if (!$this->Owner instanceof User) {
         throw new Exception("No valid album owner has been set");
     }
     return true;
 }
 public function test_generateUrlSlug()
 {
     $this->assertEquals(self::TEXT_TO, ContentUtility::generateUrlSlug(self::TEXT_FROM, 30));
 }
示例#19
0
 /**
  * Send this reminder
  * @since Version 3.8.7
  * @return \Railpage\Reminders\Reminder
  * @param boolean $markAsSent Flag to indicate if this is a test notification or not
  */
 public function send($markAsSent = false)
 {
     $this->validate();
     $Smarty = AppCore::getSmarty();
     /**
      * Set some vars
      */
     $email = array("subject" => $this->title, "body" => wpautop(format_post($this->text)));
     /**
      * Try and load the object to get some fancy stuff from it
      */
     try {
         $classname = sprintf("\\%s", $this->object);
         $Object = new $classname($this->object_id);
         $email['subtitle'] = "Railpage \\ " . $Object->Module->name;
         if (isset($Object->meta['coverphoto']) && !empty($Object->meta['coverphoto'])) {
             if ($CoverPhoto = (new Images())->getImageFromUrl($Object->meta['coverphoto'])) {
                 $email['hero'] = array("title" => isset($Object->name) ? $Object->name : $Object->title, "link" => isset($Object->url->canonical) ? $Object->url->canonical : sprintf("http://www.railpage.com.au%s", (string) $Object->url), "author" => isset($CoverPhoto->author->realname) && !empty($CoverPhoto->author->realname) ? $CoverPhoto->author->realname : $CoverPhoto->author->username);
                 if (strpos($email['hero']['link'], "http://") === false) {
                     $email['hero']['link'] = "http://www.railpage.com.au" . $email['hero']['link'];
                 }
                 if (strpos($email['hero']['link'], "railpage.com.au") === false) {
                     $email['hero']['link'] = sprintf("http://www.railpage.com.au%s", (string) $Object->url);
                 }
                 $utm = ["utm_source=reminder", "utm_medium=email", sprintf("utm_campaign=%s", ContentUtility::generateUrlSlug($this->title))];
                 $joiner = strpos($email['hero']['link'], "?") === false ? "?" : "&";
                 $email['hero']['link'] .= $joiner . implode("&", $utm);
                 foreach ($CoverPhoto->sizes as $size) {
                     if ($size >= 620) {
                         $email['hero']['image'] = $size['source'];
                     }
                 }
             }
         }
     } catch (Exception $e) {
     }
     /**
      * Process and fetch the email template
      */
     $tpl = $Smarty->ResolveTemplate("template.reminder");
     $Smarty->Assign("email", $email);
     $body = $Smarty->Fetch($tpl);
     $Notification = new Notification();
     $Notification->subject = $this->title;
     $Notification->body = $body;
     $Notification->addRecipient($this->User->id, $this->User->username, $this->User->contact_email);
     $Notification->commit();
     if ($markAsSent) {
         $this->sent = true;
         $this->Dispatched = new DateTime();
         $this->commit();
     }
     /**
      * Start composing and sending the email
      */
     /*
     $message = Swift_Message::newInstance()
         ->setSubject($this->title)
         ->setFrom(array(
             $this->Config->SMTP->username => $this->Config->SiteName
         ))
         ->setTo(array(
             $this->User->contact_email => !empty($this->User->realname) ? $this->User->realname : $this->User->username
         ))
         ->setBody($body, 'text/html');
     
     $transport = Swift_SmtpTransport::newInstance($this->Config->SMTP->host, $this->Config->SMTP->port, $this->Config->SMTP->TLS = true ? "tls" : NULL)
         ->setUsername($this->Config->SMTP->username)
         ->setPassword($this->Config->SMTP->password);
     
     $mailer = Swift_Mailer::newInstance($transport);
     
     if ($result = $mailer->send($message)) {
         if ($markAsSent) {
             $this->sent = true;
             $this->Dispatched = new DateTime;
             $this->commit();
         }
     }
     */
     return $this;
 }