示例#1
0
 /**
  * Lookup something in the glossary
  * @since Version 3.9.1
  * @return \Railpage\Glossary\Entry
  */
 public function lookupText($text)
 {
     $cachekey = sprintf("railpage:glossary.lookup.text=%s", md5($text));
     if ($id = $this->Redis->fetch($cachekey)) {
         $Sphinx = AppCore::getSphinx();
         $query = $Sphinx->select("*")->from("idx_glossary")->match("short", $text);
         $matches = $query->execute();
         if (count($matches) === 0 && strpos($text, "-") !== false) {
             $query = $Sphinx->select("*")->from("idx_glossary")->match("short", str_replace("-", "", $text));
             $matches = $query->execute();
         }
         if (count($matches) === 1) {
             $id = $matches[0]['entry_id'];
             $this->Redis->save($cachekey, $id, strtotime("+1 year"));
         }
     }
     if (isset($id) && filter_var($id, FILTER_VALIDATE_INT)) {
         return new Entry($id);
     }
     return;
 }
示例#2
0
 /**
  * Get contributors of this locomotive
  * @since Version 3.7.5
  * @return array
  */
 public function getContributors()
 {
     $return = array();
     $Sphinx = AppCore::getSphinx();
     $query = $Sphinx->select("user_id", "username")->from("idx_logs")->match("module", "locos")->where("key", "=", "class_id")->where("value", "=", $this->id)->groupBy("user_id");
     $result = $query->execute();
     foreach ($result as $row) {
         $return[$row['user_id']] = $row['username'];
     }
     return $return;
     /*          
     $query = "SELECT DISTINCT l.user_id, u.username FROM log_general AS l LEFT JOIN nuke_users AS u ON u.user_id = l.user_id WHERE l.module = ? AND l.key = ? AND l.value = ?";
     
     foreach ($this->db->fetchAll($query, array("locos", "class_id", $this->id)) as $row) {
         $return[$row['user_id']] = $row['username']; 
     }
     
     return $return;
     */
 }
示例#3
0
 /**
  * Get contributors of this locomotive
  * @since Version 3.7.5
  * @return array
  */
 public function getContributors()
 {
     $key = sprintf(self::CACHE_KEY, $this->id) . ";contributors";
     if ($contributors = $this->Redis->fetch($key)) {
         return $contributors;
     }
     $return = array();
     $Sphinx = AppCore::getSphinx();
     $query = $Sphinx->select("user_id", "username")->from("idx_logs")->match("module", "locos")->where("key", "=", "loco_id")->where("value", "=", intval($this->id))->groupBy("user_id");
     $result = $query->execute();
     foreach ($result as $row) {
         $return[$row['user_id']] = $row['username'];
     }
     $this->Redis->save($key, $return, strtotime("+2 hours"));
     return $return;
 }
示例#4
0
 /**
  * Find a suitable cover photo
  * @since Version 3.10.0
  * @param string|object $searchQuery
  * @return string
  */
 public static function GuessCoverPhoto($searchQuery)
 {
     $defaultPhoto = "https://static.railpage.com.au/i/logo-fb.jpg";
     $cachekey = sprintf("railpage:coverphoto=%s", md5($searchQuery));
     $Memcached = AppCore::getMemcached();
     #if ($image = $Memcached->fetch($cachekey)) {
     #   return $image;
     #}
     $SphinxQL = AppCore::getSphinx();
     if (!is_string($searchQuery)) {
         return $defaultPhoto;
     }
     preg_match_all('/([a-zA-Z]|\\xC3[\\x80-\\x96\\x98-\\xB6\\xB8-\\xBF]|\\xC5[\\x92\\x93\\xA0\\xA1\\xB8\\xBD\\xBE]){4,}/', $searchQuery, $match_arr);
     $word_arr = $match_arr[0];
     $words = implode(" || ", $word_arr);
     $SphinxQL->select()->from("idx_images")->match(array("title", "description"), $words, true);
     $rs = $SphinxQL->execute();
     if (!count($rs)) {
         return $defaultPhoto;
     }
     $photo = $rs[0];
     $photo['meta'] = json_decode($photo['meta'], true);
     $photo['sizes'] = Images::NormaliseSizes($photo['meta']['sizes']);
     foreach ($photo['sizes'] as $size) {
         if ($size['width'] > 400 && $size['height'] > 300) {
             $Memcached->save($cachekey, $size['source'], 0);
             return $size['source'];
         }
     }
 }