function get_content($file, $url, $hours = 24) {
		$current_time = time(); 
		$expire_time = $hours * 60 * 60;	// 24 hours ago

		//if the cache file exists
		if(file_exists($file)) {
			$file_time = filemtime($file);

		 	if ($current_time - $expire_time < $file_time) {
				return file_get_contents($file);
			}
			else {
				// the file exists, but the time has expired
				get_content_from_url($file, $url);
			}
		}
		else {
			// file doesn't exist
			get_content_from_url($file, $url);
		}
	}
    /**
    * Show and process edit link logo form
    *
    * @param void
    * @return null
    */
    function edit_logo() {
      $link = ProjectLinks::findById(get_id());
      if (!($link instanceof ProjectLink)) {
        flash_error(lang('link dnx'));
        $this->redirectToReferer(get_url('links', 'index'));
      } // if

      if (!$link->canEdit(logged_user())) {
        flash_error(lang('no access permissions'));
        $this->redirectToReferer(get_url('links'));
      } // if

      if (!function_exists('imagecreatefromjpeg')) {
        flash_error(lang('no image functions'));
        $this->redirectTo('links');
      } // if

      $this->setTemplate('edit_logo');
      //$this->setLayout('administration');
      
      tpl_assign('link', $link);
      
      $logo = array_var($_FILES, 'new_logo');

      if (is_array($logo)) {
        try {
          $uploaded_file_size = array_var($logo, 'size', 0);
          if ($uploaded_file_size == 0) {
            $x1 = 0 + array_var($_POST, 'x1');
            $y1 = 0 + array_var($_POST, 'y1');
            $x2 = 0 + array_var($_POST, 'x2');
            $y2 = 0 + array_var($_POST, 'y2');
            $url = $link->getUrl();
            if (!string_begins_with($url, 'http://')) $url = 'http://' . $url;
            //die("$x1 $y1 $x2 $y2 $url");
            $img_data = get_content_from_url('wimg.ca', 80, $url);
            if ($img_data) {
              $src_img = imagecreatefromstring($img_data);
              $dst_img = imagecreatetruecolor(50, 50);
              imagecopyresized($dst_img, $src_img, 0, 0, $x1, $y1, 50, 50, abs($x2-$x1), abs($y2-$y1) );

              // Output and free from memory
              //header('Content-Type: image/png');
              $tempname = tempnam(ROOT . '/tmp/', 'links-snapshot' );
              imagepng($dst_img, $tempname);

              $logo["name"]='links-snapshot';
              $logo["tmp_name"]=$tempname;
              $logo["type"]='image/png';
              $logo["size"]='1';

              imagedestroy($dst_img);
              imagedestroy($src_img);
            }
          } else {
            move_uploaded_file($logo["tmp_name"], ROOT . "/tmp/" . $logo["name"]);
            $logo["tmp_name"] = ROOT . "/tmp/" . $logo["name"];
            if (!isset($logo['name']) || !isset($logo['type']) || !isset($logo['size']) || !isset($logo['tmp_name']) || !is_readable($logo['tmp_name'])) {
              throw new InvalidUploadError($logo, lang('error upload file'));
            } // if
          }
          
          $valid_types = array('image/jpg', 'image/jpeg', 'image/pjpeg', 'image/gif', 'image/png');
          $max_width   = config_option('max_logo_width', 50);
          $max_height  = config_option('max_logo_height', 50);
          
          if (!in_array($logo['type'], $valid_types) || !($image = getimagesize($logo['tmp_name']))) {
            throw new InvalidUploadError($logo, lang('invalid upload type', 'JPG, GIF, PNG'));
          } // if
          
          $old_file = $link->getLogoPath();
          
          DB::beginWork();
          
          if (!$link->setLogo($logo['tmp_name'], $max_width, $max_height, true)) {
            DB::rollback();
            flash_error(lang('error edit link logo', $e));
            $this->redirectToUrl($link->getEditLogoUrl());
          } // if
          
          ApplicationLogs::createLog($link, active_project(), ApplicationLogs::ACTION_EDIT);
          
          flash_success(lang('success edit logo'));
          DB::commit();
          
          if (is_file($old_file)) {
            @unlink($old_file);
          } // uf
          
        } catch(Exception $e) {
          flash_error(lang('error edit logo', $e));
          DB::rollback();
        } // try
        
        $this->redirectToUrl($link->getEditLogoUrl());
      } // if
    } // edit_logo
function gist_raw($id, $file)
{
    $request = "http://gist.github.com/raw/" . $id . "/" . $file;
    return get_content_from_url($request);
}