Ejemplo n.º 1
0
function encode_btc($btc)
{
    $btc = chr($btc['version']) . pack('H*', $btc['hash']);
    if (strlen($btc) != 21) {
        return false;
    }
    $cksum = substr(hash_sha256(hash_sha256($btc)), 0, 4);
    return base58_encode($btc . $cksum);
}
function getPhotos($id, $per_page, $safe = NULL)
{
    global $flickrBase, $accounts;
    $xml = simplexml_load_file($flickrBase . 'flickr.people.getPublicPhotos&api_key=' . $accounts['flickr']['apikey'] . '&user_id=' . $id . '&per_page=' . $per_page . '&safe_search=' . $safe);
    $array = array();
    // array to hold pictures
    foreach ($xml->photos->photo as $photo) {
        // We create an array containing each url, photo title, link (in that order)
        //http://farm{farm-id}.static.flickr.com/{server-id}/{id}_{secret}.jpg <- format to get the image from flickr
        $url = 'http://farm' . $photo['farm'] . '.static.flickr.com/' . $photo['server'] . '/' . $photo['id'] . '_' . $photo['secret'] . '.jpg';
        // url of photo
        $link = 'http://flic.kr/p/' . base58_encode($photo['id']);
        // clickable link that goes to the photo
        $item = array("url" => $url, "title" => $photo['title'], "link" => $link);
        // each photo item
        array_push($array, $item);
        // put each photo item into array
    }
    return $array;
}
Ejemplo n.º 3
0
function Shorten($link)
{
    preg_match("#/(\\d+)/#", $link, $matches);
    return 'http://flic.kr/p/' . base58_encode($matches[1]);
}
Ejemplo n.º 4
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();
     }
 }
Ejemplo n.º 5
0
 /**
  * Populate this image object
  *
  * @since Version 3.9.1
  * @return void
  *
  * @param int $option
  */
 private function load($option = null)
 {
     Debug::RecordInstance();
     $this->mckey = sprintf("railpage:image=%d", $this->id);
     if (defined("NOREDIS") && NOREDIS == true || !($row = $this->Redis->fetch($this->mckey))) {
         Debug::LogCLI("Fetching data for " . $this->id . " from database");
         $query = "SELECT i.title, i.description, i.id, i.provider, i.photo_id, i.modified, i.meta, i.lat, i.lon, i.user_id, i.geoplace, i.captured FROM image AS i WHERE i.id = ?";
         $row = $this->db->fetchRow($query, $this->id);
         $row['meta'] = json_decode($row['meta'], true);
         $this->Redis->save($this->mckey, $row, strtotime("+24 hours"));
     }
     $this->populateFromArray($row);
     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;
         }
     }
     if (!isset($row['user_id'])) {
         $row['user_id'] = 0;
     }
     /**
      * Update the database row
      */
     if ((!isset($row['title']) || empty($row['title']) || is_null($row['title'])) && !empty($this->title) || (!isset($row['description']) || empty($row['description']) || is_null($row['description'])) && !empty($this->description)) {
         $row['title'] = $this->title;
         $row['description'] = $this->description;
         $this->Redis->save($this->mckey, $row, strtotime("+24 hours"));
         $this->commit();
     }
     /**
      * Load the author. If we don't know who it is, attempt to re-populate the data
      */
     if (isset($row['meta']['author'])) {
         $this->author = json_decode(json_encode($row['meta']['author']));
         if (isset($this->author->railpage_id) && $row['user_id'] === 0) {
             $row['user_id'] == $this->author->railpage_id;
         }
         if (filter_var($row['user_id'], FILTER_VALIDATE_INT)) {
             $this->author->User = UserFactory::CreateUser($row['user_id']);
         }
     } else {
         Debug::LogCLI("No author found in local cache - refreshing from " . $this->provider);
         Debug::LogEvent("No author found in local cache - refreshing from " . $this->provider);
         $this->populate(true, $option);
     }
     /**
      * Unless otherwise instructed load the places object if lat/lng are present
      */
     if ($option != Images::OPT_NOPLACE && round($row['lat'], 3) != "0.000" && round($row['lon'], 3) != "0.000") {
         try {
             $this->Place = Place::Factory($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":
                 if (function_exists("base58_encode")) {
                     $this->source = "https://flic.kr/p/" . base58_encode($this->photo_id);
                 }
         }
     }
     /**
      * Create an array/JSON object
      */
     $this->getJSON();
 }
Ejemplo n.º 6
0
function base58check_encode($hash160)
{
    $hash = "" . $hash160;
    $eccfull = hash('sha256', hash('sha256', $hash, true), true);
    $ecc = substr($eccfull, 0, 4);
    $preaddr = $hash . $ecc;
    $bin2hex = bchexdec(bin2hex($preaddr));
    $encoded = base58_encode($bin2hex);
    $encoded = '1' . $encoded;
    return $encoded;
}