Example #1
0
 function backup()
 {
     global $globals;
     if ($globals['Amazon_S3_media_bucket'] && $globals['Amazon_S3_upload']) {
         return Media::put($this->pathname(), $this->type);
     }
     return true;
 }
Example #2
0
	function get_thumb($debug = false) {
		global $globals;

		$site = false;
		if (empty($this->url)) {
			if (!$this->read()) return false;
		}
		$blog = new Blog();
		$blog->id = $this->blog;
		if ($blog->read()) {
			$site = $blog->url;
		}
		$this->image_parser = new HtmlImages($this->url, $site);
		$this->image_parser->debug = $debug;
		$this->image_parser->referer = $this->get_permalink();
		echo "<!-- Meneame, before image_parser -->\n";
		$img = $this->image_parser->get();
		echo "<!-- Meneame, after image_parser -->\n";
		$this->thumb_status = 'checked';
		$this->thumb = '';
		if ($img) {
			$filepath = mnmpath.'/'.$globals['cache_dir'];
			@mkdir($filepath);
			$chain = get_cache_dir_chain($this->id);
			create_cache_dir_chain($filepath, $chain);
			$filepath .= "/$chain/thumb-$this->id.jpg";
			if ($img->type == 'local') {
				$img->scale($globals['thumb_size']);
				if($img->save($filepath)) {
					@chmod($filepath, 0777);
					$this->thumb_x = $img->x;
					$this->thumb_y = $img->y;
					// Upload to S3
					if ($globals['Amazon_S3_media_bucket'] && $globals['Amazon_S3_media_url'] && Media::put($filepath, 'thumbs', "$this->id.jpg")) {
							//$this->thumb = $globals['Amazon_S3_media_url'] . "/thumbs/$this->id.jpg";
							$this->thumb_status = 'remote';
					} else {
						//$this->thumb = $globals['base_url'].$globals['cache_dir'].'/thumbs';
						//$this->thumb .= "/$chain/$this->id.jpg";
						$this->thumb_status='local';
					}
					syslog(LOG_NOTICE, "Meneame, new thumbnail $img->url to " . $this->get_permalink());
					if ($debug)
						echo "<!-- Meneame, new thumbnail $img->url -->\n";
				} else {
					$this->thumb_status = 'error';
					if ($debug)
						echo "<!-- Meneame, error saving thumbnail ".$this->get_permalink()." -->\n";
				}
			}
			if ($img->video) $this->content_type = 'video';
		} elseif ($this->thumb_x || $this->thumb_y) {
			$this->delete_thumb();
			return false;
		}
		$this->store_thumb();
		return $this->has_thumb();
	}
Example #3
0
 /**
  * Shortcut for putting an asset into the correct silo based on its path
  *
  * @return boolean True on success
  */
 public function put()
 {
     return Media::put($this);
 }
Example #4
0
 /**
  * Copy the asset using the specified from and to paths
  *
  * @param string $pathfrom The virtual path source
  * @param string $pathto The virtual path destination
  * @return boolean true on success
  */
 public static function copy($pathfrom, $pathto)
 {
     if ($source = Media::get($pathfrom)) {
         return Media::put($pathto, $source);
     } else {
         return false;
     }
 }
Example #5
0
 function get_thumb($debug = false, $url = false)
 {
     global $globals;
     $site = false;
     if (empty($this->url)) {
         if (!$this->read()) {
             return false;
         }
     }
     $blog = new Blog();
     $blog->id = $this->blog;
     if ($blog->read()) {
         $site = $blog->url;
     }
     if (!empty($url)) {
         $this->image_parser = new HtmlImages($url);
     } else {
         $this->image_parser = new HtmlImages($this->url, $site);
         $this->image_parser->debug = $debug;
         $this->image_parser->referer = $this->get_permalink();
     }
     if ($debug) {
         echo "<!-- Meneame, before image_parser -->\n";
     }
     $img = $this->image_parser->get();
     if ($debug) {
         echo "<!-- Meneame, after image_parser: {$img->url} -->\n";
     }
     $this->thumb_status = 'checked';
     $this->thumb = '';
     if ($img) {
         Upload::create_cache_dir($this->id);
         $filepath = Upload::get_cache_dir($this->id) . "/thumb-{$this->id}.jpg";
         $oks = 0;
         if ($img->type == 'local') {
             foreach (Link::thumb_sizes() as $b => $s) {
                 $filepath = Upload::get_cache_dir($this->id) . "/{$b}-{$this->id}.jpg";
                 $thumbnail = $img->scale($s);
                 $res = $thumbnail->save($filepath);
                 if (!$res) {
                     continue;
                 }
                 $oks++;
                 @chmod($filepath, 0777);
                 if ($b == 'thumb') {
                     $this->thumb_x = $thumbnail->getWidth();
                     $this->thumb_y = $thumbnail->getHeight();
                 }
                 if ($b == 'thumb_medium' && $globals['Amazon_S3_media_bucket']) {
                     Media::put($filepath, 'thumbs', "medium_{$this->id}.jpg");
                 }
             }
             if ($oks > 0) {
                 // syslog(LOG_NOTICE, "Meneame, new thumbnail $img->url to " . $this->get_permalink());
                 if ($debug) {
                     echo "<!-- Meneame, new thumbnail {$img->url} -->\n";
                 }
             } else {
                 $this->thumb_status = 'error';
                 if ($debug) {
                     echo "<!-- Meneame, error saving thumbnail " . $this->get_permalink() . " -->\n";
                 }
             }
         }
     } elseif ($this->thumb_x || $this->thumb_y) {
         $this->delete_thumb();
         return false;
     }
     $this->store_thumb();
     return $this->has_thumb();
 }
Example #6
0
function avatars_db_store($user, $file, $now)
{
    global $db, $globals;
    // Store in S3
    if ($globals['Amazon_S3_media_bucket']) {
        if (Media::put($file, 'avatars')) {
            $db->query("update users set user_avatar = {$now}  where user_id={$user}");
            return $now;
        } else {
            return false;
        }
    }
    // Store locally
    $bytes = file_get_contents($file);
    if (strlen($bytes) > 0 && strlen($bytes) < 30000) {
        $bytes = addslashes($bytes);
        $db->query("replace into avatars set avatar_id = {$user}, avatar_image='{$bytes}'");
        $db->query("update users set user_avatar = {$now}  where user_id={$user}");
        return $now;
    }
    return false;
}