Пример #1
0
 /**
  * Suggest events to tag
  * @since Version 3.10.0
  * @param \Railpage\Images\Image $imageObject
  * @return array
  */
 public static function SuggestEvents(Image $imageObject)
 {
     if (!$imageObject->DateCaptured instanceof DateTime) {
         return;
     }
     $Database = (new AppCore())->getDatabaseConnection();
     $query = "SELECT COUNT(*) AS num FROM image_link WHERE namespace = ? AND image_id = ?";
     $params = [(new Event())->namespace, $imageObject->id];
     if ($Database->fetchOne($query, $params) > 0) {
         return;
     }
     $Events = new Events();
     $list = $Events->getEventsForDate($imageObject->DateCaptured);
     foreach ($list as $k => $row) {
         $Event = new Event($row['event_id']);
         printArray($Event->namespace);
         die;
         $list[$k]['url'] = sprintf("/services?method=railpage.image.tag&image_id=%d&object=%s&object_id=%d", $imageObject->id, "\\Railpage\\Events\\Event", $row['event_id']);
     }
     return $list;
 }
Пример #2
0
 /**
  * Generate the calendar table
  * Borrowed from https://css-tricks.com/snippets/php/build-a-calendar-table/
  *
  * @since Version 3.9.1
  * @return string
  */
 public function generateCalendar()
 {
     /**
      * Load the Events class for later on
      */
     $Events = new Events();
     // Create array containing abbreviations of days of week.
     $daysOfWeek = array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday');
     // What is the first day of the month in question?
     $firstDayOfMonth = mktime(0, 0, 0, $this->month, 1, $this->year);
     // How many days does this month contain?
     $numberDays = date('t', $firstDayOfMonth);
     // Retrieve some information about the first day of the month in question
     $dateComponents = getdate($firstDayOfMonth);
     // What is the index value (0-6) of the first day of the month in question
     $dayOfWeek = $dateComponents['wday'];
     // Create the table tag opener and day headers
     $calendar = "<table class='calendar'>";
     //$calendar .= "<caption>" . $this->name . " " . $this->year . "</caption>";
     $calendar .= "<thead><tr>";
     // Create the calendar headers
     foreach ($daysOfWeek as $day) {
         $calendar .= "<th class='header'>" . $day . "</th>";
     }
     // Create the rest of the calendar
     // Initiate the day counter, starting with the 1st.
     $currentDay = 1;
     $calendar .= "</tr></thead><tbody><tr>";
     // The variable $dayOfWeek is used to
     // ensure that the calendar
     // display consists of exactly 7 columns.
     if ($dayOfWeek > 0) {
         for ($i = 0; $i < $dayOfWeek; $i++) {
             $calendar .= "<td class='notday'>&nbsp;</td>";
         }
     }
     $month = str_pad($this->month, 2, "0", STR_PAD_LEFT);
     while ($currentDay <= $numberDays) {
         // Seventh column (Saturday) reached. Start a new row.
         if ($dayOfWeek == 7) {
             $dayOfWeek = 0;
             $calendar .= "</tr><tr>";
         }
         $currentDayRel = str_pad($currentDay, 2, "0", STR_PAD_LEFT);
         $date = sprintf("%s-%s-%s", $this->year, $month, $currentDayRel);
         $calendar .= sprintf("<td class='isday %s' valign='top' rel='%s'>", $date == date("Y-m-d") ? "today" : "", $date);
         $calendar .= sprintf("<span class='daynum'>%d</span>", $currentDay);
         /**
          * Get events on this date
          */
         foreach ($Events->getEventsForDate(new DateTime($date)) as $row) {
             $calendar .= sprintf("<a class='event-link' href='%s'><time datetime='%s'>%s</time></a>", $row['url'], (new DateTime($row['date'] . " " . $row['start']))->format(DATE_ISO8601), $row['title']);
         }
         $calendar .= "</td>";
         // Increment counters
         $currentDay++;
         $dayOfWeek++;
     }
     // Complete the row of the last week in month, if necessary
     if ($dayOfWeek != 7) {
         $remainingDays = 7 - $dayOfWeek;
         for ($i = 0; $i < $remainingDays; $i++) {
             $calendar .= "<td class='notday'>&nbsp;</td>";
         }
     }
     $calendar .= "</tr></tbody>";
     $calendar .= "</table>";
     return $calendar;
 }
Пример #3
0
 /**
  * Yield upcoming events for this organisation
  * @since Version 3.9
  * @return \Railpage\Events\EventDate
  * @yield \Railpage\Events\EventDate
  */
 public function yieldUpcomingEvents()
 {
     $Events = new Events();
     foreach ($Events->getUpcomingEventsForOrganisation($this) as $date) {
         foreach ($date as $row) {
             (yield new EventDate($row['event_date']));
         }
     }
 }
Пример #4
0
 /**
  * Render the page 
  * @since Version 3.10.0
  * @return string
  */
 public function render()
 {
     if (!$this->userObject instanceof User) {
         throw new InvalidArgumentException("No valid user object has been provided");
     }
     #$this->smarty->clearCache($this->template, $this->unique);
     if ($this->smarty->isCached($this->template, $this->unique)) {
         Debug::LogCLI("!! Template file " . $this->template . " is already cached for unique ID " . $this->unique);
         return $this->smarty->fetch($this->template, $this->unique);
     }
     Debug::LogCLI("Template file " . $this->template . " is NOT cached for unique ID \"" . $this->unique . "\"");
     /**
      * Get user alerts
      */
     if (!$this->userObject->guest) {
         global $acl;
         $alerts = $this->userObject->getAlerts($acl);
         $this->smarty->Assign("alerts", $alerts, true);
     }
     /**
      * Get the latest jobs
      */
     $newjobs = array();
     foreach ((new Jobs())->yieldNewJobs(5) as $Job) {
         $newjobs[] = $Job->getArray();
     }
     $this->smarty->Assign("jobs", $newjobs, true);
     /**
      * Upcoming events
      */
     $Memcached = AppCore::GetMemcached();
     $cachekey = "railpage.home.upcomingevents";
     $upcoming = [];
     if (!($upcoming = $Memcached->fetch($cachekey))) {
         $Events = new Events();
         $upcoming = [];
         foreach ($Events->getUpcomingEvents(5) as $row) {
             //$Event = EventsFactory::CreateEvent($row['event_id']);
             $EventDate = new EventDate($row['id']);
             $data = $EventDate->getArray();
             $upcoming[] = $data;
         }
         $Memcached->save("railpage.home.upcomingevents", $upcoming, strtotime("+5 minutes"));
     }
     $this->smarty->Assign("upcomingevents", $upcoming);
     /**
      * New photos
      */
     $this->smarty->Assign("newphotos", RecentImages::getNewest(5));
     /**
      * Chronicle
      */
     $Chronicle = new Chronicle();
     $this->smarty->Assign("chronicle", $Chronicle->getEntriesForToday(10));
     /**
      * Get the latest railcam photo
      */
     $Camera = new Camera(1);
     $Photo = $Camera->getLatest(false);
     $railcam = $Photo->getArray();
     $railcam['sizes']['small']['source'] = ImageCache::cache($railcam['sizes']['small']['source']);
     $this->smarty->Assign("railcam", $railcam);
     $this->smarty->Assign("railcam_updated", ContentUtility::relativeTime($railcam['dates']['taken']));
     /**
      * First check if this user has a personalised news feed
      */
     if (filter_var($this->userObject->id, FILTER_VALIDATE_INT) && $this->userObject->id > 0) {
         $Feed = new Feed();
         $Feed->setUser($this->userObject)->getFilters();
         if (count($Feed->filter_words) || count($Feed->filter_topics)) {
             $latest = $Feed->findArticles(0, 20);
             foreach ($latest as $id => $article) {
                 $article['sid'] = $article['story_id'];
                 $article['catid'] = $article['topic_id'];
                 $article['hometext'] = preg_replace("@(\\[b\\]|\\[\\/b\\])@", "", $article['story_blurb']);
                 $article['informant'] = $article['username'];
                 $article['informant_id'] = $article['user_id'];
                 $article['ForumThreadId'] = $article['forum_topic_id'];
                 $article['topictext'] = $article['topic_title'];
                 $article['topic'] = $article['topic_id'];
                 $article['featured_image'] = $article['story_image'];
                 $article['title'] = $article['story_title'];
                 $article['time_relative'] = time2str($article['story_time_unix']);
                 $latest[$id] = $article;
             }
         }
     }
     $this->smarty->Assign("personalfeed", isset($latest));
     /**
      * No personal news feed - go ahead as normal
      */
     if (!isset($latest)) {
         /**
          * Instantiate the base News module
          */
         $News = new Base();
         /**
          * Get the latest 15 news articles
          */
         $latest = $News->latest(20);
     }
     /**
      * Format titles and tags for the latest news articles
      */
     foreach ($latest as $id => $data) {
         /**
          * Load the JSON for this article
          */
         if (!isset($data['sid'])) {
             $data['sid'] = $data['story_id'];
         }
         $json = json_decode(News::getArticleJSON($data['sid']), true);
         $latest[$id]['hometext'] = isset($json['article']['blub']) ? wpautop(process_bbcode($json['article']['blub'])) : wpautop(process_bbcode($json['article']['blurb']));
         $latest[$id]['hometext'] = strip_tags($latest[$id]['hometext'], "<a><p><img><br><br /><strong><em>");
         $latest[$id]['title'] = format_topictitle($data['title']);
         $latest[$id]['topic'] = $json['article']['topic'];
         $latest[$id]['topic_highlight'] = ColourUtility::String2Hex($latest[$id]['topic_title']);
         $latest[$id]['url'] = $json['article']['url'];
         $latest[$id]['author'] = $json['article']['author'];
         $latest[$id]['staff'] = $json['article']['staff'];
         if (!empty($latest[$id]['featured_image'])) {
             $latest[$id]['featured_image'] = ImageCache::cache($latest[$id]['featured_image']);
         }
         // Get the first paragraph from the home text
         preg_match("/<p>(.*)<\\/p>/", $latest[$id]['hometext'], $matches);
         $latest[$id]['hometext'] = strip_tags($matches[1]);
         if (empty($json['article']['body']) && !empty($json['article']['source'])) {
             $latest[$id]['url'] = $json['article']['source'];
         }
         /**
          * Pre-rendering
          */
         $this->smarty->addHeadTag(sprintf("<link rel='prerender' href='%s'>", $json['article']['url']['url']));
     }
     /**
      * Slice the first news article off
      */
     $newsLatest = array_shift($latest);
     /**
      * Send them to Smarty
      */
     $this->smarty->assign("newsLatest", $newsLatest);
     $this->smarty->assign("news", $latest);
     $this->smarty->assign("pagecontrols", '<p style="background: #333; background: rgba(0, 0, 0, 0.6);margin: -20px;padding: 10px;margin-top: 20px; text-align: center;">Wasting time and bandwidth since 1992</p>');
     if ($this->params['handheld']) {
         $this->smarty->assign("pagecontrols", '<p style="background: #333; background: rgba(0, 0, 0, 0.6);margin: 0px -20px;padding: 0px;margin-top: 40px; text-align: center;font-size:1em;">Wasting time and bandwidth since 1992</p>');
     }
     return $this->smarty->fetch($this->template, $this->unique);
 }