Example #1
0
 /**
  * Constructor
  * @praam int $category_id
  */
 public function __construct($category_id = false, $recurse = true)
 {
     parent::__construct();
     if (filter_var($category_id, FILTER_VALIDATE_INT)) {
         $this->id = $category_id;
     } elseif (is_string($category_id)) {
         $this->id = $this->db->fetchOne("SELECT cid FROM nuke_links_categories WHERE slug = ?", $category_id);
     }
     if (filter_var($this->id, FILTER_VALIDATE_INT)) {
         $this->mckey = sprintf("railpage.links.category=%d", $this->id);
         if (!($row = getMemcacheObject($this->mckey))) {
             $row = $this->db->fetchRow("SELECT * FROM nuke_links_categories WHERE cid = ?", $this->id);
             if (!empty($row)) {
                 setMemcacheObject($this->mckey, $row);
             }
         }
         $this->name = $row['title'];
         $this->desc = $row['cdescription'];
         $this->parent_id = $row['parentid'];
         $this->slug = $row['slug'];
         $this->url = $this->makePermalink($this->id);
         if ($this->parent_id > 0 && $recurse) {
             $this->parent = new Category($this->parent_id);
         }
     }
 }
Example #2
0
 /**
  * Constructor
  * @since Version 3.9
  * @param int $id
  */
 public function __construct($id = false)
 {
     parent::__construct();
     if (is_string($id)) {
         $query = "SELECT id FROM timetable_points WHERE name = ? OR slug = ?";
         if ($tmpid = $this->db->fetchOne($query, array($id, $id))) {
             $id = $tmpid;
         } else {
             $this->name = $id;
             $this->commit();
         }
     }
     if (filter_var($id, FILTER_VALIDATE_INT)) {
         $this->mckey = sprintf("railpage:timetable.point=%d", $id);
         if (!($row = getMemcacheObject($this->mckey))) {
             $query = "SELECT * FROM timetable_points WHERE id = ?";
             $row = $this->db->fetchRow($query, $id);
             setMemcacheObject($this->mckey, $row);
         }
     }
     if (isset($row) && count($row)) {
         $this->id = $row['id'];
         $this->lat = $row['lat'];
         $this->lon = $row['lon'];
         $this->name = $row['name'];
         $this->slug = isset($row['slug']) ? $row['slug'] : "";
         if (!isset($row['slug']) || empty($row['slug']) || substr($row['slug'], -1, 1) == "1") {
             $this->createSlug();
             $this->commit();
         }
         $this->url = new Url(sprintf("%s/p/%s", $this->Module->url, $this->slug));
         $this->url->edit = sprintf("%s?mode=point.edit", $this->url->url);
     }
 }
Example #3
0
 /**
  * Constructor
  * @since Version 3.8.6
  * @param int|string $id
  */
 public function __construct($id = false)
 {
     parent::__construct();
     if ($id) {
         $mckey = "railpage:fwlink=" . md5($id);
         if ($row = getMemcacheObject($mckey)) {
             $this->id = $row['id'];
             $this->url = $row['url'];
             $this->title = $row['title'];
         } else {
             if (filter_var($id, FILTER_VALIDATE_INT)) {
                 $query = "SELECT * FROM fwlink WHERE id = ?";
             } else {
                 $query = "SELECT * FROM fwlink WHERE url = ?";
             }
             if ($row = $this->db->fetchRow($query, $id)) {
                 $this->id = $row['id'];
                 $this->url = $row['url'];
                 $this->title = $row['title'];
                 setMemcacheObject($mckey, $row, strtotime("+1 month"));
             }
         }
         if (!empty($this->url)) {
             $this->url_canonical = sprintf("http://%s%s", RP_HOST, $this->url);
             $this->url_short = sprintf("http://%s/fwlink?id=%d", RP_HOST, $this->id);
         }
     }
 }
Example #4
0
 /**
  * Constructor
  * @since Version 3.8.7
  * @param int $id
  */
 public function __construct($id = false)
 {
     parent::__construct();
     $this->Module = new Module("glossary");
     if (filter_var($id, FILTER_VALIDATE_INT)) {
         $this->id = $id;
         $this->mckey = sprintf("%s.entry=%d", $this->Module->namespace, $this->id);
         deleteMemcacheObject($this->mckey);
         if ($row = getMemcacheObject($this->mckey)) {
         } else {
             $query = "SELECT type, short, full, example, date, author FROM glossary WHERE id = ?";
             $row = $this->db->fetchRow($query, $this->id);
             setMemcacheObject($this->mckey, $row);
         }
         if (isset($row) && is_array($row)) {
             $this->name = $row['short'];
             $this->text = $row['full'];
             $this->example = $row['example'];
             $this->Type = new Type($row['type']);
             $this->url = sprintf("%s?mode=entry&id=%d", $this->Module->url, $this->id);
             if ($row['date'] == "0000-00-00 00:00:00") {
                 $this->Date = new DateTime();
                 $this->commit();
             } else {
                 $this->Date = new DateTime($row['date']);
             }
             $this->Author = new User($row['author']);
         }
     }
 }
 /**
  * Constructor
  * @param string $slug
  */
 public function __construct($slug)
 {
     global $ZendDB, $ZendDB_ReadOnly;
     $mckey = "railpage:news.article_slug=" . $slug;
     if ($story_id = getMemcacheObject($mckey)) {
         parent::__construct($story_id);
     } else {
         $story_id = $ZendDB_ReadOnly->fetchOne("SELECT sid FROM nuke_stories WHERE slug = ?", $slug);
         if (filter_var($story_id, FILTER_VALIDATE_INT)) {
             setMemcacheObject($mckey, $story_id, strtotime("+6 months"));
             parent::__construct($story_id);
         } else {
             throw new \Exception("Could not find a story matching URL slug " . $slug);
             return false;
         }
     }
 }
 /** 
  * Constructor
  * @since Version 3.0.1
  * @version 3.8.7
  * @param string $topic_alias
  */
 public function __construct($topic_alias = false)
 {
     parent::__construct();
     if (!$topic_alias) {
         return false;
     }
     if ($this->db instanceof \sql_db) {
         $query = "SELECT * FROM nuke_topics WHERE topicname = '" . $this->db->real_escape_string($topic_alias) . "'";
         if ($rs = $this->db->query($query)) {
             if ($rs->num_rows == 1) {
                 $row = $rs->fetch_assoc();
                 $this->id = $row['topicid'];
                 $this->alias = $topic_alias;
                 $this->title = $row['topictext'];
                 $this->image = $row['topicimage'];
             }
         } else {
             trigger_error(__CLASS__ . ": Could not retrieve topic alias " . $topic_alias);
             trigger_error($this->db->error);
             trigger_error($query);
             return false;
         }
     } else {
         $mckey = "railpage:news.topic_slug=" . $topic_alias;
         if ($row = getMemcacheObject($mckey)) {
             $this->id = $row['topicid'];
             $this->alias = $topic_alias;
             $this->title = $row['topictext'];
             $this->image = $row['topicimage'];
         } else {
             $query = "SELECT * FROM nuke_topics WHERE topicname = ?";
             if ($row = $this->db_readonly->fetchRow($query, $topic_alias)) {
                 $this->id = $row['topicid'];
                 $this->alias = $topic_alias;
                 $this->title = $row['topictext'];
                 $this->image = $row['topicimage'];
                 setMemcacheObject($mckey, $row, strtotime("+6 months"));
             }
         }
     }
 }
Example #7
0
 /**
  * List all online registered users
  * @since Version 3.0
  * @version 3.9
  * @return mixed
  */
 public function onlineUsers()
 {
     $mckey = "railpage:onlineusers";
     if ($return = getMemcacheObject($mckey)) {
         foreach ($return as $id => $row) {
             if (isset($row['last_session_ip'])) {
                 return $return;
             }
         }
     }
     $return = array();
     $query = "SELECT user_id, user_level, username, last_session_ip FROM nuke_users WHERE user_session_time > " . (time() - 60 * 10) . " ORDER BY username ASC";
     if ($result = $this->db->fetchAll($query)) {
         foreach ($result as $row) {
             $row['bot'] = false;
             $row['guest'] = false;
             $return[$row['user_id']] = $row;
         }
         setMemcacheObject($mckey, $return, strtotime("+1 minute"));
     }
     return $return;
 }
Example #8
0
 /**
  * Cache an object in Memcache
  * @deprecated 3.8.7 Calls to this method should be replaced with setMemcacheObject() with the same parameter(s)
  * @since Version 3.7.5
  * @param string|boolean $key Memcache's unique identifier for this data
  * @param mixed $value The data we wish to store in Memcache
  * @param int $exp A unix timestamp representing the expiry point. Leave as 0 for never expire
  * @return boolean
  */
 protected function setCache($key = false, $value = "thisisanemptyvalue", $exp = 0)
 {
     if (!$this->useCache) {
         return false;
     }
     return setMemcacheObject($key, $value, $exp);
 }
Example #9
0
 /**
  * Constructor
  * @since Version 3.8.7
  * @param int $id The ID of the event
  * @uses \Railpage\Events\EventCategory The category which this event is filed under
  * @uses \Railpage\Organisations\Organisation The organisation associated with this event
  * @uses \Railpage\Place The geographic place (latitude & longitude) of this event
  */
 public function __construct($id = false)
 {
     parent::__construct();
     /**
      * Record this in the debug log
      */
     if (function_exists("debug_recordInstance")) {
         debug_recordInstance(__CLASS__);
     }
     if (RP_DEBUG) {
         global $site_debug;
         $debug_timer_start = microtime(true);
     }
     $this->Module = new Module("events");
     $this->namespace = $this->Module->namespace;
     if (filter_var($id, FILTER_VALIDATE_INT)) {
         $query = "SELECT * FROM event WHERE id = ?";
         $this->mckey = sprintf("railpage:events.event=%d", $id);
     } elseif (is_string($id) && strlen($id) > 2) {
         $query = "SELECT * FROM event WHERE slug = ?";
         $this->mckey = getMemcacheObject(sprintf("railpage:events.event=%s", $id));
     }
     if (empty($this->mckey) || $this->mckey === false || !($row = getMemcacheObject($this->mckey))) {
         if (isset($query)) {
             $row = $this->db->fetchRow($query, $id);
             $this->mckey = sprintf("railpage:events.event=%d", $row['id']);
             setMemcacheObject($this->mckey, $row);
             setMemcacheObject(sprintf("railpage:events.event=%s", $row['slug']), $row['id']);
         }
     }
     if (isset($row) && is_array($row)) {
         $this->id = $row['id'];
         $this->title = $row['title'];
         $this->desc = $row['description'];
         $this->meta = json_decode($row['meta'], true);
         $this->slug = $row['slug'];
         $this->flickr_tag = "railpage:event=" . $this->id;
         if (filter_var($row['category_id'], FILTER_VALIDATE_INT)) {
             $this->Category = new EventCategory($row['category_id']);
         }
         if (filter_var($row['organisation_id'], FILTER_VALIDATE_INT)) {
             $this->Organisation = new Organisation($row['organisation_id']);
         }
         if (round($row['lat'], 3) != "0.000" && round($row['lon'], 3) != "0.000") {
             $this->Place = new Place($row['lat'], $row['lon']);
         }
         $this->createUrls();
         $this->Templates = new stdClass();
         $this->Templates->view = sprintf("%s/event.tpl", $this->Module->Paths->html);
     }
     if (RP_DEBUG) {
         $site_debug[] = __CLASS__ . "::" . __METHOD__ . " completed in " . round(microtime(true) - $debug_timer_start, 5) . "s";
     }
 }
Example #10
0
 /**
  * Generate JSON object for this article
  * @since Version 3.8.7
  * @return string
  */
 public function makeJSON()
 {
     if ($this->date instanceof DateTime) {
         $timezone = $this->date->getTimezone();
     } else {
         $timezone = new DateTimeZone("Australia/Melbourne");
     }
     if (!filter_var($this->id, FILTER_VALIDATE_INT)) {
         throw new Exception("Cannot make a JSON object for the requested news article beacuse no valid article ID was found. Something's wrong....");
     }
     $response = array("namespace" => $this->Module->namespace, "module" => $this->Module->name, "article" => array("id" => $this->id, "title" => $this->title, "hits" => $this->hits, "blub" => is_object($this->blurb) ? $this->blurb->__toString() : $this->blurb, "body" => is_object($this->body) ? $this->body->__toString() : $this->body, "image" => $this->featured_image, "approved" => $this->approved, "url" => $this->url instanceof Url ? $this->url->getURLs() : array("url" => sprintf("/news/article-%d", $this->id)), "topic" => array("id" => $this->Topic->id, "title" => $this->Topic->title, "url" => $this->Topic->url instanceof Url ? $this->Topic->url->getURLs() : array("url" => sprintf("/news/topic-%d", $this->Topic->id))), "thread" => array("id" => $this->topic_id, "url" => array("view" => filter_var($this->topic_id, FILTER_VALIDATE_INT) ? sprintf("/f-t%d.htm", $this->topic_id) : "")), "date" => array("absolute" => $this->date->format("Y-m-d H:i:s"), "timezone" => $timezone->getName(), "unixtime" => $this->date->getTimestamp()), "author" => array("id" => $this->Author->id, "username" => $this->Author->username, "url" => array("view" => $this->Author->url instanceof Url ? $this->Author->url->url : $this->Author->url)), "staff" => array("id" => $this->Staff->id, "username" => $this->Staff->username, "url" => array("view" => $this->Staff->url instanceof Url ? $this->Staff->url->url : $this->Staff->url))));
     $response = json_encode($response);
     setMemcacheObject(sprintf("json:railpage.news.article=%d", $this->id), $response);
     return $response;
 }
Example #11
0
 /**
  * Get photo info and sizes
  * @since Version 3.5
  * @param int $photo_id
  * @return array
  */
 public function getPhotoLegacy($photo_id = false)
 {
     if (!$photo_id) {
         throw new Exception("Cannot fetch photo info and sizes - no photo ID given");
         return false;
     }
     $mckey = "railpage:railcam.photo.id=" . $photo_id;
     #deleteMemcacheObject($mckey);
     if ($return = getMemcacheObject($mckey)) {
         $return['photo']['time_relative'] = relative_date($return['photo']['dateuploaded']);
         return $return;
     } else {
         $use_rezzza = false;
         if ($use_rezzza) {
             $metadata = new Metadata(RP_FLICKR_API_KEY, RP_FLICKR_API_SECRET);
             $metadata->setOauthAccess($this->flickr_oauth_token, $this->flickr_oauth_secret);
             $factory = new ApiFactory($metadata, new GuzzleAdapter());
             $photo_info = $factory->call('flickr.photos.getInfo', array('photo_id' => $photo_id));
             if ($photo_info) {
                 $photo_sizes = $factory->call('flickr.photos.getSizes', array('photo_id' => $photo_id));
             }
             /**
              * do stuff!
              */
             if ($photo_info && $photo_sizes) {
                 $return = array();
                 /**
                  * Photo info
                  */
                 foreach ($photo_info->photo->attributes() as $a => $b) {
                     $return['photo'][$a] = $b->__toString();
                 }
                 foreach ($photo_info->photo->children() as $element) {
                     foreach ($element->attributes() as $a => $b) {
                         $return['photo'][$element->getName()][$a] = $b->__toString();
                     }
                     foreach ($element->children() as $child) {
                         foreach ($child->attributes() as $a => $b) {
                             $return['photo'][$element->getName()][$child->getName()][$a] = $b->__toString();
                         }
                         foreach ($child->children() as $blah) {
                             $return['photo'][$element->getName()][$child->getName()][$blah->getName()][$a] = $b->__toString();
                             foreach ($blah->attributes() as $a => $b) {
                                 $return['photo'][$element->getName()][$child->getName()][$blah->getName()][$a] = $b->__toString();
                             }
                         }
                     }
                 }
                 /**
                  * Photo sizes
                  */
                 $i = 0;
                 foreach ($photo_sizes->sizes->size as $key => $element) {
                     foreach ($element->attributes() as $a => $b) {
                         $return['photo']['sizes'][$i][$a] = $b->__toString();
                     }
                     $i++;
                 }
             }
             return $return;
         }
         $f = new flickr_railpage(RP_FLICKR_API_KEY);
         $f->oauth_token = $this->flickr_oauth_token;
         $f->oauth_secret = $this->flickr_oauth_secret;
         $f->cache = false;
         $return = array();
         if ($return = $f->photos_getInfo($photo_id)) {
             $return['photo']['sizes'] = $f->photos_getSizes($photo_id);
             $return['photo']['time_relative'] = relative_date($return['photo']['dateuploaded']);
             setMemcacheObject($mckey, $return, strtotime("+2 hours"));
         }
         return $return;
     }
 }
Example #12
0
 /**
  * Get stories from topic
  * @version 3.0
  * @since Version 3.0
  * @return mixed
  * @param int $page
  * @param int $limit
  * @param boolean $total
  */
 public function stories($page = 0, $limit = 25, $total = true)
 {
     $return = false;
     $mckey = "railpage:topic_id=" . $this->id . ".stories.page=" . $page . ".limit=" . $limit . ".total=" . (int) $total;
     $mcexp = strtotime("+1 hour");
     if (!($return = getMemcacheObject($mckey))) {
         // Get it from Sphinx
         $Sphinx = $this->getSphinx();
         $query = $Sphinx->select("*")->from("idx_news_article")->orderBy("story_time_unix", "DESC")->limit($page * $limit, $limit)->where("topic_id", "=", $this->id);
         $matches = $query->execute();
         $meta = $Sphinx->query("SHOW META");
         $meta = $meta->execute();
         if (is_array($matches) && count($matches)) {
             $return = array("total" => $meta[1]['Value'], "children" => array(), "page" => $page, "perpage" => $limit, "topic_id" => $this->id);
             foreach ($matches as $id => $row) {
                 $row['time_relative'] = time2str($row['story_time_unix']);
                 $row['time'] = $row['story_time'];
                 $row['title'] = format_topictitle($row['story_title']);
                 // Match the first sentence
                 $line = explode("\n", $row['story_blurb']);
                 $row['firstline'] = preg_replace('/([^?!.]*.).*/', '\\1', strip_tags($line[0]));
                 if (empty($row['story_slug'])) {
                     $row['slug'] = $this->createSlug($row['story_id']);
                 }
                 $row['url'] = $this->makePermaLink($row['story_slug']);
                 $row['hometext'] = $row['story_blurb'];
                 $row['bodytext'] = $row['story_body'];
                 $row['featured_image'] = $row['story_image'];
                 $row['informant'] = $row['username'];
                 $return['children'][$id] = $row;
             }
         }
     }
     if (!isset($return) || $return === false || !is_array($return)) {
         $query = "SELECT SQL_CALC_FOUND_ROWS s.*, t.topicname, t.topicimage, t.topictext, u.user_id AS informant_id FROM nuke_stories AS s LEFT JOIN nuke_topics AS t ON s.topic = t.topicid LEFT JOIN nuke_users AS u ON s.informant = u.username WHERE s.topic = ? AND s.approved = ? ORDER BY s.time DESC LIMIT ?, ?";
         $return = array();
         $return['total'] = 0;
         $return['children'] = array();
         $return['page'] = $page;
         $return['perpage'] = $limit;
         $return['topic_id'] = $this->id;
         if ($result = $this->db_readonly->fetchAll($query, array($this->id, "1", $page * $limit, $limit))) {
             $return['total'] = $this->db_readonly->fetchOne("SELECT FOUND_ROWS() AS total");
             foreach ($result as $row) {
                 if (function_exists("relative_date")) {
                     $row['time_relative'] = relative_date(strtotime($row['time']));
                 } else {
                     $row['time_relative'] = $row['time'];
                 }
                 $row['title'] = format_topictitle($row['title']);
                 // Match the first sentence
                 $line = explode("\n", $row['hometext']);
                 $row['firstline'] = preg_replace('/([^?!.]*.).*/', '\\1', strip_tags($line[0]));
                 if (empty($row['slug'])) {
                     $row['slug'] = $this->createSlug($row['sid']);
                 }
                 $row['url'] = $this->makePermaLink($row['slug']);
                 $return['children'][] = $row;
             }
         }
         setMemcacheObject($mckey, $return, $mcexp);
     }
     return $return;
 }
Example #13
0
 /**
  * Fetch a page
  * @since Version 3.5
  */
 public function fetch()
 {
     if (!$this->id) {
         throw new Exception("Cannot fetch page - no page ID given");
         return false;
     }
     if (!($row = getMemcacheObject($this->mckey))) {
         $query = "SELECT * FROM nuke_pages WHERE pid = ?";
         $row = $this->db->fetchRow($query, $this->id);
         foreach ($row as $key => $val) {
             $row[$key] = stripslashes($val);
         }
         setMemcacheObject($this->mckey, $row, strtotime("+1 month"));
     }
     $this->title = $row['title'];
     $this->subtitle = $row['subtitle'];
     $this->active = $row['active'];
     $this->header = $row['page_header'];
     $this->body = $row['text'];
     $this->footer = $row['page_footer'];
     $this->date = new DateTime($row['date']);
     $this->hits = $row['counter'];
     $this->langauge = isset($row['language']) ? $row['language'] : NULL;
     $this->permalink = $row['shortname'];
     $this->url = new Url(sprintf("/static-%s.htm", $this->permalink));
     $this->url->edit = sprintf("/admin/pages/edit/%d", $this->id);
     return true;
 }
Example #14
0
 /**
  * Build the Forums ACL
  * @since Version 3.8.7
  * @param boolean $force Force an update of the ACL
  * @todo Finish this shit
  */
 public function buildACL($force = false)
 {
     /**
      * I hate using Globals...
      */
     global $acl;
     if (!$this->User instanceof User) {
         throw new Exception("A valid user must be set before the ACL can be built");
     }
     $mckey = "railpage.forums.list";
     if ($force || !($forums = getMemcacheObject($mckey))) {
         $query = "SELECT forum_id FROM nuke_bbforums";
         $forums = $this->db->fetchAll($query);
         setMemcacheObject($mckey, $forums);
     }
     $acl_forums = array();
     /**
      * Add all the forums to the ACL
      */
     foreach ($forums as $row) {
         $acl_forum_name = sprintf("railpage.forums.forum:%d", $row['forum_id']);
         $acl_forums[$row['forum_id']] = $acl_forum_name;
         try {
             $acl->get($acl_forum_name);
         } catch (Exception $e) {
             $acl->addResource(new Zend_Acl_Resource($acl_forum_name));
         }
     }
     /**
      * Get the forum permissions from the database
      */
     $a_sql = array("auth_view", "auth_read", "auth_post", "auth_reply", "auth_edit", "auth_delete", "auth_sticky", "auth_announce", "auth_vote", "auth_pollcreate");
     $auth_fields = array('auth_view', 'auth_read', 'auth_post', 'auth_reply', 'auth_edit', 'auth_delete', 'auth_sticky', 'auth_announce', 'auth_vote', 'auth_pollcreate');
     $query = "SELECT forum_id, " . implode(", ", $a_sql) . ", " . self::AUTH_ACL . " AS auth_mod FROM nuke_bbforums";
     $db_acl = array();
     foreach ($this->db->fetchAll($query) as $row) {
         $db_acl[$row['forum_id']] = $row;
     }
     /**
      * Get the group permissions for this user
      */
     $query = "SELECT a.* FROM nuke_bbauth_access AS a WHERE a.group_id IN (SELECT group_id FROM nuke_bbuser_group WHERE user_id = ? AND user_pending = 0)";
     $gperms = array();
     foreach ($this->db->fetchAll($query, $this->User->id) as $perm) {
         $forum_id = $perm['forum_id'];
         $group_id = $perm['group_id'];
         unset($perm['forum_id']);
         unset($perm['group_id']);
         $gperms[$forum_id][$group_id] = $perm;
     }
     /**
      * Add the forum permissions to Zend_ACL
      */
     foreach ($db_acl as $forum_id => $permissions) {
         $allowed = array();
         $denied = array();
         foreach ($permissions as $item => $value) {
             switch ($value) {
                 case self::AUTH_ALL:
                     $allowed[] = $item;
                     break;
                 case self::AUTH_REG:
                     if (!$this->User->guest) {
                         $allowed[] = $item;
                     }
                     break;
                 case self::AUTH_ACL:
                     if (isset($gperms[$forum_id])) {
                         foreach ($gperms[$forum_id] as $group) {
                             foreach ($group as $gitem => $gval) {
                                 switch ($gval) {
                                     case self::AUTH_REG:
                                         $allowed[] = $item;
                                         break;
                                     case self::AUTH_ACL:
                                         // Inception
                                         break;
                                     case self::AUTH_MOD:
                                         if ($this->User->inGroup(RP_GROUP_MODERATORS)) {
                                             $allowed[] = $gitem;
                                         }
                                         break;
                                     case self::AUTH_ADMIN:
                                         if ($this->User->inGroup(RP_GROUP_ADMINS)) {
                                             $allowed[] = $gitem;
                                         }
                                         break;
                                 }
                             }
                         }
                     }
                     break;
                 case self::AUTH_MOD:
                     if ($this->User->inGroup(RP_GROUP_MODERATORS)) {
                         $allowed[] = $item;
                     }
                     break;
                 case self::AUTH_ADMIN:
                     if ($this->User->inGroup(RP_GROUP_ADMINS)) {
                         $allowed[] = $item;
                     }
                     break;
             }
         }
         foreach ($permissions as $item => $value) {
             if (!in_array($item, $allowed)) {
                 $denied[] = $item;
             }
         }
         $allowed = array_unique($allowed);
         $denied = array_unique($denied);
         $acl->allow("forums_viewer", sprintf("railpage.forums.forum:%d", $forum_id), $allowed);
         $acl->deny("forums_viewer", sprintf("railpage.forums.forum:%d", $forum_id), $denied);
     }
     $this->ZendACL = $acl;
 }
Example #15
0
 /**
  * Constructor
  * @since Version 3.8.7
  * @param int $id
  */
 public function __construct($id = NULL)
 {
     parent::__construct();
     $this->Module = new Module("images");
     if (filter_var($id, FILTER_VALIDATE_INT)) {
         /**
          * Record this in the debug log
          */
         debug_recordInstance(__CLASS__);
         $this->mckey = sprintf("railpage:image=%d", $id);
         if (!($row = getMemcacheObject($this->mckey))) {
             $query = "SELECT i.id, i.provider, i.photo_id, i.modified, i.meta, i.lat, i.lon FROM image AS i WHERE i.id = ?";
             $row = $this->db->fetchRow($query, $id);
             $row['meta'] = json_decode($row['meta'], true);
             setMemcacheObject($this->mckey, $row, strtotime("+24 hours"));
         }
         $this->id = $id;
         $this->provider = $row['provider'];
         $this->photo_id = $row['photo_id'];
         $this->Date = new DateTime($row['modified']);
         $this->title = !empty($row['meta']['title']) ? format_topictitle($row['meta']['title']) : "Untitled";
         $this->description = $row['meta']['description'];
         $this->sizes = $row['meta']['sizes'];
         $this->links = $row['meta']['links'];
         $this->meta = $row['meta']['data'];
         $this->url = new Url("/image?id=" . $this->id);
         if ($this->provider == "rpoldgallery") {
             $GalleryImage = new \Railpage\Gallery\Image($this->photo_id);
             $this->url->source = $GalleryImage->url->url;
             if (empty($this->meta['source'])) {
                 $this->meta['source'] = $this->url->source;
             }
         }
         /**
          * Normalize some sizes
          */
         if (count($this->sizes)) {
             if (!isset($this->sizes['thumb'])) {
                 foreach ($this->sizes as $size) {
                     if ($size['width'] >= 280 && $size['height'] >= 150) {
                         $this->sizes['thumb'] = $size;
                         break;
                     }
                 }
             }
             if (!isset($this->sizes['small'])) {
                 foreach ($this->sizes as $size) {
                     if ($size['width'] >= 500 && $size['height'] >= 281) {
                         $this->sizes['small'] = $size;
                         break;
                     }
                 }
             }
             $width = 0;
             foreach ($this->sizes as $size) {
                 if ($size['width'] > $width) {
                     $this->sizes['largest'] = $size;
                     $width = $size['width'];
                 }
             }
             foreach ($this->sizes as $size) {
                 if ($size['width'] >= 1920) {
                     $this->sizes['fullscreen'] = $size;
                     break;
                 }
             }
             foreach ($this->sizes as $size) {
                 if ($size['width'] > 1024 && $size['width'] <= 1920) {
                     $this->sizes['larger'] = $size;
                     break;
                 }
             }
             foreach ($this->sizes as $size) {
                 if ($size['width'] == 1024) {
                     $this->sizes['large'] = $size;
                     break;
                 }
             }
             foreach ($this->sizes as $size) {
                 if ($size['width'] == 800) {
                     $this->sizes['medium'] = $size;
                     break;
                 }
             }
         }
         if (isset($row['meta']['author'])) {
             $this->author = json_decode(json_encode($row['meta']['author']));
             if (isset($this->author->railpage_id)) {
                 $this->author->User = new User($this->author->railpage_id);
             }
         } else {
             $this->populate(true);
         }
         if (round($row['lat'], 3) != "0.000" && round($row['lon'], 3) != "0.000") {
             try {
                 $this->Place = new Place($row['lat'], $row['lon']);
             } catch (Exception $e) {
                 // Throw it away. Don't care.
             }
         }
         /**
          * Set the source URL
          */
         if (isset($this->meta['source'])) {
             $this->source = $this->meta['source'];
         } else {
             switch ($this->provider) {
                 case "flickr":
                     $this->source = "https://flic.kr/p/" . base58_encode($this->photo_id);
             }
         }
         $this->getJSON();
     }
 }
Example #16
0
 /**
  * Constructor
  * @since Version 3.8.7
  * @param int|string $id
  */
 public function __construct($id = false)
 {
     parent::__construct();
     $this->Module = new Module("Gallery");
     if (filter_var($id, FILTER_VALIDATE_INT)) {
         $this->id = $id;
         $this->mckey = sprintf("railpage:gallery.album.image=%d", $this->id);
         if (!($row = getMemcacheObject($this->mckey))) {
             $query = "SELECT * FROM gallery_mig_image WHERE id = ?";
             $row = $this->db->fetchRow($query, $id);
             setMemcacheObject($this->mckey, $row, strtotime("+1 year"));
         }
         $this->title = $row['title'];
         $this->DateTaken = new DateTime($row['date_taken']);
         $this->DateUploaded = new DateTime($row['date_uploaded']);
         $this->path = $row['path'];
         $this->url = new Url(sprintf("%s?image=%d", $this->Module->url, $this->id));
         $this->meta = json_decode($row['meta'], true);
         $this->hidden = isset($row['hidden']) ? $row['hidden'] : false;
         $this->sizes = array("original" => array("source" => sprintf("//static.railpage.com.au/albums/%s", $this->path), "width" => $this->meta['image']['raw_width'], "height" => $this->meta['image']['raw_height']));
         if (isset($this->meta['image']['resizedName'])) {
             $this->sizes['medium'] = array("source" => sprintf("//static.railpage.com.au/albums/%s/%s.%s", dirname($this->path), $this->meta['image']['resizedName'], $this->meta['image']['type']), "width" => $this->meta['image']['width'], "height" => $this->meta['image']['height']);
         }
         if (isset($this->meta['thumbnail'])) {
             $this->sizes['thumb'] = array("source" => sprintf("//static.railpage.com.au/albums/%s/%s.%s", dirname($this->path), $this->meta['thumbnail']['name'], $this->meta['thumbnail']['type']), "width" => $this->meta['thumbnail']['width'], "height" => $this->meta['thumbnail']['height']);
         }
         $this->owner = $row['owner'];
         if (filter_var($row['owner'], FILTER_VALIDATE_INT)) {
             try {
                 $this->Owner = new User($row['owner']);
             } catch (Exception $e) {
                 // Don't care
             }
         }
     }
 }
Example #17
0
 /**
  *
  * Get links within a category
  *
  */
 public function getLinks($category_id = false, $sort = "title", $direction = "ASC")
 {
     if (!$this->db || !$category_id) {
         return false;
     }
     $mckey = "railpage:links.category_id=" . $category_id . ".sort=" . $sort . ".direction=" . $direction;
     if ($return = getMemcacheObject($mckey)) {
         return $return;
     } elseif ($this->db instanceof \sql_db) {
         $return = false;
         $query = "SELECT * FROM nuke_links_links WHERE link_approved = 1 AND cid = " . $this->db->real_escape_string($category_id) . " ORDER BY " . $this->db->real_escape_string($sort) . " " . strtoupper(strtolower($this->db->real_escape_string($direction)));
         if ($rs = $this->db->query($query)) {
             $return = array();
             while ($row = $rs->fetch_assoc()) {
                 if (stripos($row['url'], "http") === false) {
                     $row['url'] = "http://" . $row['url'];
                 }
                 $return[] = $row;
             }
             setMemcacheObject($mckey, $return, strtotime("+24 hours"));
         } else {
             trigger_error("Links: Could not fetch links for category " . $category_id);
             trigger_error($this->db->error);
             trigger_error($query);
         }
         return $return;
     } else {
         $query = "SELECT * FROM nuke_links_links WHERE link_approved = 1 AND cid = ? ORDER BY " . $sort . " " . $direction;
         $params = array($category_id);
         $return = array();
         foreach ($this->db->fetchAll($query, $params) as $row) {
             if (stripos($row['url'], "http") === false) {
                 $row['url'] = "http://" . $row['url'];
             }
             $return[] = $row;
         }
         setMemcacheObject($mckey, $return, strtotime("+24 hours"));
         return $return;
     }
 }
Example #18
0
 /**
  * Get photo info and sizes
  * @since Version 3.5
  * @param int $photo_id
  * @return array
  */
 public function getPhoto($photo_id = false)
 {
     if (!$photo_id) {
         throw new Exception("Cannot fetch photo info and sizes - no photo ID given");
         return false;
     }
     $mckey = "railpage:railcam.photo.id=" . $photo_id;
     deleteMemcacheObject($mckey);
     if ($return = getMemcacheObject($mckey)) {
         $return['photo']['time_relative'] = relative_date($return['photo']['dateuploaded']);
         return $return;
     } else {
         $f = new \flickr_railpage(RP_FLICKR_API_KEY);
         $f->oauth_token = $this->flickr_oauth_token;
         $f->oauth_secret = $this->flickr_oauth_secret;
         $f->cache = false;
         $return = array();
         if ($return = $f->photos_getInfo($photo_id)) {
             $return['photo']['sizes'] = $f->photos_getSizes($photo_id);
             $return['photo']['time_relative'] = relative_date($return['photo']['dateuploaded']);
             setMemcacheObject($mckey, $return, strtotime("+2 hours"));
         }
         return $return;
     }
 }
Example #19
0
 /**
  * Set filters for this user
  * @since Version 3.8.7
  * @return $this
  */
 public function setFilters()
 {
     if (!$this->User instanceof User) {
         throw new Exception("Cannot get filters for news feed because no valid user was specified");
     }
     if (is_string($this->filter_words)) {
         $this->filter_words = explode(",", $this->filter_words);
     }
     foreach ($this->filter_words as $id => $word) {
         $this->filter_words[$id] = trim($word);
     }
     $data = array("keywords" => json_encode($this->filter_words), "topics" => json_encode($this->filter_topics), "user_id" => $this->User->id);
     if ($id = $this->db->fetchOne("SELECT id FROM news_feed WHERE user_id = ?", $this->User->id)) {
         $this->db->update("news_feed", $data, array("id = ?" => $id));
     } else {
         $this->db->insert("news_feed", $data);
     }
     unset($data['user_id']);
     setMemcacheObject(sprintf("rp:news.feed=%d", $this->User->id), $data);
     return $this;
 }
Example #20
0
 /**
  * Get WOE (Where On Earth) data from Yahoo's GeoPlanet API
  *
  * Ported from [master]/includes/functions.php
  * @since Version 3.8.7
  * @param string $lookup
  * @return array
  */
 public static function getWOEData($lookup = false)
 {
     if ($lookup === false) {
         return false;
     }
     $return = array();
     $mckey = "railpage:woe=" . $lookup;
     #deleteMemcacheObject($mckey);
     if (!($return = getMemcacheObject($mckey))) {
         global $RailpageConfig;
         if (preg_match("@[a-zA-Z]+@", $lookup) || strpos($lookup, ",")) {
             $lookup = sprintf("places.q('%s')", $lookup);
         } else {
             $lookup = sprintf("place/%s", $lookup);
         }
         $url = sprintf("http://where.yahooapis.com/v1/%s?lang=en&appid=%s&format=json", $lookup, $RailpageConfig->Yahoo->ApplicationID);
         /**
          * Load PEAR HTTP/Request2
          */
         #require_once("HTTP/Request2.php");
         /**
          * Fetch from Yahoo's GeoPlanet API
          */
         $request = new HTTP_Request2($url, HTTP_Request2::METHOD_GET);
         $request->setConfig(array("ssl_verify_peer" => false));
         $response = $request->send();
         switch ($response->getStatus()) {
             case 200:
                 $return = json_decode($response->getBody(), true);
                 break;
             case 503:
                 throw new Exception("Your call to Yahoo Web Services failed and returned an HTTP status of 503. That means: Service unavailable. An internal problem prevented us from returning data to you.");
                 break;
             case 403:
                 throw new Exception("Your call to Yahoo Web Services failed and returned an HTTP status of 403. That means: Forbidden. You do not have permission to access this resource, or are over your rate limit.");
                 break;
             case 400:
                 throw new Exception("Your call to Yahoo Web Services failed and returned an HTTP status of 400. That means:  Bad request. The parameters passed to the service did not match as expected. The exact error is returned in the XML/JSON response.");
                 break;
             default:
                 throw new Exception("Your call to Yahoo Web Services returned an unexpected HTTP status of: " . $response->getStatus());
         }
         $return['url'] = $url;
         /*
         // Zend\Http\Client code messes with the URL and tries to encode the brackets. This breaks Yahoo's API, because they're too shit to urldecode() anything
         $client = new Zend\Http\Client;
         $client->setAdapter("Zend\Http\Client\Adapter\Curl");
         $client->setUri($url);
         $client->setEncType(Zend\Http\Client::ENC_URLENCODED);
         $result = $client->send();
         
         #if ($result->isSuccess()) {
         	$return = json_decode($result->getBody(), true);
         	$return['url'] = $url;
         #}
         */
     }
     if ($return !== false) {
         setMemcacheObject($mckey, $return, strtotime("+24 hours"));
     }
     return $return;
 }
Example #21
0
 /**
  * Make a permalink for this location
  * @since Version 3.7.5
  * @return string
  * @param int $id Optional location ID - inherited by Railpage\Locations\Location so will attempt to use $this->id if none provided
  */
 public function makePermalink($id = false)
 {
     $mckey = $id ? "railpage:locations.permalink.id=" . $id : "railpage:locations.permalink.id=" . $this->id;
     if ($string = getMemcacheObject($mckey)) {
         return $string;
     } else {
         if ((!isset($this->country) || !isset($this->region) || !isset($this->slug)) && $id) {
             // Fetch it from the database
             $query = "SELECT country, region, slug FROM location WHERE id = ?";
             $data = $this->db->fetchRow($query, $id);
             if (empty($data['slug'])) {
                 $Location = new Location($id);
                 $data['slug'] = $Location->slug;
             }
         } else {
             $data['country'] = $this->country;
             $data['region'] = $this->region;
             $data['slug'] = $this->slug;
         }
         #$string = "/locations/" . strtolower(str_replace(" ", "-", $data['country'])) . "/" . strtolower(str_replace(" ", "-", $data['region'])) . "/" . $data['slug'];
         $string = strtolower(sprintf("%s/%s/%s/%s", $this->Module->url, str_replace(" ", "-", $data['country']), str_replace(" ", "-", $data['region']), $data['slug']));
         setMemcacheObject($mckey, $string, strtotime("+1 year"));
     }
     return $string;
 }
Example #22
0
 /**
  * Check if a user is a member of this group
  * @since Version 3.7.5
  * @paran int $user_id
  * @return boolean
  */
 public function userInGroup($user_id = false)
 {
     if (!$user_id) {
         return false;
     }
     $mckey = "railpage:group=" . $this->id . ".user_id=" . $user_id;
     if (RP_DEBUG) {
         global $site_debug;
         $debug_timer_start = microtime(true);
     }
     if (getMemcacheObject($mckey) == "yes") {
         return true;
     } else {
         $query = "SELECT user_id FROM nuke_bbuser_group WHERE group_id = '" . $this->db->real_escape_string($this->id) . "' AND user_id = '" . $this->db->real_escape_string($user_id) . "'";
         if ($rs = $this->db->query($query)) {
             if ($rs->num_rows == 1) {
                 if (RP_DEBUG) {
                     $site_debug[] = "Railpage: Find user ID " . $user_id . " in group ID " . $this->id . " completed in " . number_format(microtime(true) - $debug_timer_start, 8) . "s";
                 }
                 setMemcacheObject($mckey, "yes", strtotime("+1 day"));
                 return true;
             }
         }
         if (RP_DEBUG) {
             $site_debug[] = "Railpage: Find user ID " . $user_id . " in group ID " . $this->id . " completed in " . number_format(microtime(true) - $debug_timer_start, 8) . "s";
         }
         setMemcacheObject($mckey, "no", strtotime("+1 day"));
         return false;
     }
 }
Example #23
0
 /**
  * Get all child albums as an array
  * @since Version 3.8.7
  * @return array
  */
 public function getAlbums($page, $limit = 25)
 {
     if (!($return = getMemcacheObject(sprintf("railpage:gallery.old.album=%d.subalbums.page=%d.perpage=%d", $this->id, $page, $limit)))) {
         $Sphinx = $this->getSphinx();
         $query = $Sphinx->select("*")->from("idx_gallery_album")->where("parent_id", "=", $this->id)->orderBy("album_title", "ASC")->limit(($page - 1) * $limit, $limit);
         $matches = $query->execute();
         $meta = $Sphinx->query("SHOW META");
         $meta = $meta->execute();
         foreach ($matches as $id => $row) {
             $row['album_meta'] = json_decode($row['album_meta'], true);
             $matches[$id] = $row;
         }
         $return = array("total" => $meta[1]['Value'], "page" => $page, "perpage" => $limit, "albums" => $matches);
         setMemcacheObject(sprintf("railpage:gallery.old.album=%d.subalbums.page=%d.perpage=%d", $this->id, $page, $limit), $return);
     }
     return $return;
 }
Example #24
0
 /**
  * Constructor
  * @since Version 3.9
  */
 public function __construct($id = false, $provider = false)
 {
     parent::__construct();
     if ($id != false && $provider == "artc") {
         $query = "SELECT id FROM timetable_trains WHERE train_number LIKE ? AND provider = ?";
         $id = $this->db->fetchOne($query, array("%" . $id . "%", $provider));
     }
     if (filter_var($id, FILTER_VALIDATE_INT)) {
         $this->mckey = sprintf("railpage:timetable.train=%d", $id);
         if (!($row = getMemcacheObject($this->mckey))) {
             $query = "SELECT * FROM timetable_trains WHERE id = ?";
             $row = $this->db->fetchRow($query, $id);
             setMemcacheObject($this->mckey, $row);
         }
     }
     if (isset($row)) {
         $this->id = $row['id'];
         $this->number = $row['train_number'];
         $this->meta = json_decode($row['meta'], true);
         $this->provider = $row['provider'];
         $this->commodity = $row['commodity'];
         if ($row['operator_id'] > 0) {
             $this->Organisation = new Organisation($row['operator_id']);
         }
         $this->url = new Url(sprintf("%s/t/%s/%s", $this->Module->url, $this->provider, strtolower($this->number)));
         $this->url->edit = sprintf("%s?mode=edit", $this->url->url);
     }
 }