Пример #1
0
 public function dvd($id)
 {
     $dvd = (new Dvd())->getById($id['id']);
     if (empty($dvd)) {
         return notfound();
     }
     return $this->response->view(View::create('browse.dvd', ['title' => e($dvd->title), 'dvd' => $dvd]));
 }
Пример #2
0
 public function __construct()
 {
     parent::__construct();
     if (!auth()->is()) {
         notfound();
         exit;
     }
 }
Пример #3
0
 public function add($id)
 {
     $id = current($id);
     $dvd = (new Dvd())->getById($id);
     if (empty($dvd)) {
         return notfound();
     }
     if ($dvd->rented == 1) {
         return notfound();
     }
     basket()->add($id, band2price($dvd->price_band));
     session()->addSuccess('DVD successfully added to basket');
     return redirect(l('basket'));
 }
Пример #4
0
 public function dispatch()
 {
     if (self::$_instance === NULL) {
         self::getInstance();
     }
     $routes = Routes::getInstance();
     $route = $routes->match();
     if ($route) {
         $view = $route->run();
         if ($view instanceof Response) {
             self::$_instance->response = $view;
         }
         // allow returning a response straight from the view
         self::$_instance->response = new Response($view);
         return self::$_instance->response;
     }
     return notfound();
 }
Пример #5
0
 // get the file extension
 switch ($ext) {
     case 'jpg':
         // jpg
         $src = imagecreatefromjpeg($image) or notfound();
         break;
     case 'png':
         // png
         $src = imagecreatefrompng($image) or notfound();
         break;
     case 'gif':
         // gif
         $src = imagecreatefromgif($image) or notfound();
         break;
     default:
         notfound();
 }
 // set up canvas
 $dst = imagecreatetruecolor($tn_width, $tn_height);
 imageantialias($dst, true);
 // copy resized image to new canvas
 imagecopyresampled($dst, $src, 0, 0, 0, 0, $tn_width, $tn_height, $width, $height);
 /* Sharpening adddition by Mike Harding */
 // sharpen the image (only available in PHP5.1)
 /*if (function_exists("imageconvolution")) {
 		$matrix = array(    array( -1, -1, -1 ),
 	                    array( -1, 32, -1 ),
 	                    array( -1, -1, -1 ) );
 		$divisor = 24;
 		$offset = 0;
 	
Пример #6
0
header('Content-type: text/html; charset=UTF-8');
/*$get=taddslashes($_GET);
$post=taddslashes($_POST);
*/
$get = $_GET;
$post = $_POST;
unset($GLOBALS, $_ENV, $_GET, $_POST);
empty($get['c']) && ($get['c'] = 'index');
empty($get['a']) && ($get['a'] = 'default');
define('ACTION', $get['a']);
define('REGULAR', $get['c'] . '/' . $get['a']);
//load control...
$controlfile = APP_ROOT . '/control/' . $get['c'] . '.php';
if (false === @(include $controlfile)) {
    notfound('control file "' . $controlfile . '" not found!');
}
$controlname = $get['c'] . 'control';
$control = new $controlname($get, $post);
$method = strtolower('on' . $get['a']);
if (method_exists($control, $method)) {
    $isajax = 0 === strpos($get['a'], 'ajax');
    if ($control->checkable(REGULAR) || $isajax) {
        $control->{$method}();
    } else {
        $querystring = strcode($_SERVER["QUERY_STRING"], '', 'ENCODE');
        tcookie('querystring', $querystring, 86400);
        $control->message('您无权进行当前操作,原因如下:<br/> 您所在的用户组(' . $control->user['title'] . ')无法进行此操作。', 'c=user&a=login');
    }
} else {
    notfound('control "' . $controlname . '" method "' . $method . '" not found!');
}
Пример #7
0
$songs = $song->Find('recordid=1', false, false, array('loading' => ADODB_WORK_AR));
ar_echo(ar_assert(found($songs, "'name' => 'No Hiding Place'")) ? "[OK] Found song\n" : "[!!] Find failed\n");
ar_echo("\n\n-------------------------------------------------------------------------------------------------------------------\n");
ar_echo("artist->Find('artistuniqueid=1' ... ADODB_LAZY_AR) [Lazy Method]\n");
ar_echo("-------------------------------------------------------------------------------------------------------------------\n");
$artist = new Artist();
$artists = $artist->Find('artistuniqueid=1', false, false, array('loading' => ADODB_LAZY_AR));
ar_echo(ar_assert(found($artists, "'name' => 'Elvis Costello'")) ? "[OK] Found Elvis Costello\n" : "[!!] Find failed\n");
ar_echo(ar_assert(notfound($artists, "'name' => 'No Hiding Place'")) ? "[OK] No relation yet\n" : "[!!] Found relation when I shouldn't\n");
foreach ($artists as $anartist) {
    foreach ($anartist->songs as $asong) {
        if ($asong->name) {
        }
    }
}
ar_echo(ar_assert(found($artists, "'name' => 'No Hiding Place'")) ? "[OK] Found relation: song\n" : "[!!] Missing relation: song\n");
ar_echo("\n\n-------------------------------------------------------------------------------------------------------------------\n");
ar_echo("song->Find('recordid=1' ... ADODB_LAZY_AR) [Lazy Method]\n");
ar_echo("-------------------------------------------------------------------------------------------------------------------\n");
$song = new Song();
$songs = $song->Find('recordid=1', false, false, array('loading' => ADODB_LAZY_AR));
ar_echo(ar_assert(found($songs, "'name' => 'No Hiding Place'")) ? "[OK] Found song\n" : "[!!] Find failed\n");
ar_echo(ar_assert(notfound($songs, "'name' => 'Elvis Costello'")) ? "[OK] No relation yet\n" : "[!!] Found relation when I shouldn't\n");
foreach ($songs as $asong) {
    if ($asong->artist) {
    }
}
ar_echo(ar_assert(found($songs, "'name' => 'Elvis Costello'")) ? "[OK] Found relation: artist\n" : "[!!] Missing relation: artist\n");
ar_echo("\n\n-------------------------------------------------------------------------------------------------------------------\n");
ar_echo("Test suite complete. " . ($err_count > 0 ? "{$err_count} errors found.\n" : "Success.\n"));
ar_echo("-------------------------------------------------------------------------------------------------------------------\n");
Пример #8
0
        }
    }
    return Template::render('contacts/index.html', array('form' => $form, 'contacts' => DB::model('Contacts')->order_by('date', 'desc')->all()));
}), new Route('/contact', 'contact', function ($request) {
    $form = new Form(array(new TextField('name', array('required' => true), array('placeholder' => 'Your Name')), new EmailField('email', array('required' => true), array('placeholder' => 'Your Email')), new URLField('address', array('required' => false), array('placeholder' => 'http://')), new TextField('subject', array('required' => true), array('placeholder' => 'Subject')), new TextBoxField('message', array('required' => true))));
    $test = '"hello world..." My AMPS are really good-lookin\' & my type is clean!';
    if ($request['method'] == 'post') {
        echo $request['post']['message'] . "<br>";
        $form = $form($request['post']);
        if ($form->is_valid()) {
            echo $form['message'] . "<br>";
        }
    }
    return Template::render('contact/index.html', array('form' => $form, 'test' => $test));
}), new Route('/journal/{?int:page}', 'journal', function ($request, $page = 0) {
    return Template::render('journal/index.html', array('articles' => DB::model('Articles')->order_by('date', 'desc')->all()));
}), new Route('/journal/{slug:article}', 'article', function ($request, $article) {
    $article = DB::model('Articles')->where('slug', $article)->exec();
    return Template::render('journal/article.html', array('article' => $article[0], 'tags' => DB::model('Tag')->all()));
}), new Route('/journal/{slug:tag}', 'tag', function ($request, $tag) {
    return Template::render('journal/tag.html', array('tag' => $tag));
}), new Route('/foo', 'foo', function ($request) {
    return redirect(reverse('bar'));
}), new Route('/bar', 'bar', function ($request) {
    return 'You were redirected from Foo!';
}), new Route('/404', '404', function ($request) {
    return notfound();
}), new Route('/500', '500', function ($request) {
    return error();
})));
echo Rivet::dispatch();
 function output()
 {
     // constrain submitted width or height to the default maximums
     if (!$this->w || $this->w > $this->max_w) {
         $this->desired_width = $this->max_w;
     } else {
         $this->desired_width = $this->w;
     }
     if (!$this->h || $this->h > $this->max_h) {
         $this->desired_height = $this->max_h;
     } else {
         $this->desired_height = $this->h;
     }
     // check file exists, if not try default alternative image
     if (!file_exists($this->src)) {
         if (file_exists($this->default_src)) {
             $this->src = $this->default_src;
         } else {
             $this->error = "No image or default image found.";
             return false;
         }
     }
     // filename for cache
     //$this->filename = basename($this->src);
     $this->filename = substr(preg_replace('/[^a-zA-Z0-9\\.\\_]/', '-', $this->src), -$this->cache_filepath_retain);
     // read the source dimensions
     if (!($size = @getimagesize($this->src))) {
         $this->error = "File not readable.";
         return false;
     }
     $src_width = $size[0];
     $src_height = $size[1];
     $src_aspect = $src_width / $src_height;
     if (!$this->w && !$this->h) {
         $this->error = "Must specify either a height or width.";
         return false;
     }
     // if we were only given a single desired dimension.
     // can't remember why but this mode seems to bock overstretching the image to a larger thumb
     if (!$this->w || !$this->h) {
         // find the dimensional ratios of desired comapared to source
         $x_ratio = $this->desired_width / $src_width;
         $y_ratio = $this->desired_height / $src_height;
         // if image already meets criteria, load current values in
         // if not, use ratios to load new size info
         // if both dimensions are smaller than the desired size, use the source dimensions - no scaling up will occur
         if ($src_width <= $this->desired_width && $src_height <= $this->desired_height) {
             $tn_width = $src_width;
             $tn_height = $src_height;
         } else {
             if ($x_ratio * $src_height < $this->desired_height) {
                 $tn_height = ceil($x_ratio * $src_height);
                 $tn_width = $this->desired_width;
             } else {
                 $tn_width = ceil($y_ratio * $src_width);
                 $tn_height = $this->desired_height;
             }
         }
         $canvas_width = $tn_width;
         $canvas_height = $tn_height;
     } elseif ($this->w && $this->h && $this->scaleMode == 0) {
         // correct the dimensions if the image is actually smaller than the desired thumbnail.
         // results in the canvas being smaller than requested if image is too small
         if ($this->allowOverstretch == false) {
             if ($this->desired_width > $src_width) {
                 $this->desired_width = $src_width;
             }
             if ($this->desired_height > $src_height) {
                 $this->desired_height = $src_height;
             }
         }
         $canvas_width = $this->desired_width;
         $canvas_height = $this->desired_height;
         // find the dimensional ratios of desired comapared to source
         $x_ratio = $this->desired_width / $src_width;
         $y_ratio = $this->desired_height / $src_height;
         // if the image is too tall to fit the thumbnail's proportions
         if ($x_ratio > $y_ratio) {
             $tn_width = $this->desired_width;
             $tn_height = round($this->desired_width / $src_aspect);
         } else {
             $tn_height = $this->desired_height;
             $tn_width = round($this->desired_height * $src_aspect);
         }
     } elseif ($this->w && $this->h && $this->scaleMode == 1) {
         // correct the dimensions if the image is actually smaller than the desired thumbnail.
         // results in the canvas being smaller than requested if image is too small,
         // which is probably OK as bounding box mode usually has one dimension smaller than desired.
         if ($this->allowOverstretch == false) {
             if ($this->desired_width > $src_width) {
                 $this->desired_width = $src_width;
             }
             if ($this->desired_height > $src_height) {
                 $this->desired_height = $src_height;
             }
         }
         // find the dimensional ratios of desired compared to source
         $x_ratio = $this->desired_width / $src_width;
         $y_ratio = $this->desired_height / $src_height;
         // if the image is too tall to fit the thumbnail's proportions
         if ($x_ratio > $y_ratio) {
             $tn_height = $this->desired_height;
             $tn_width = round($this->desired_height * $src_aspect);
         } else {
             $tn_width = $this->desired_width;
             $tn_height = round($this->desired_width / $src_aspect);
         }
         $canvas_width = $tn_width;
         $canvas_height = $tn_height;
     } elseif ($this->w && $this->h && $this->scaleMode == 2) {
         $canvas_width = $this->desired_width;
         $canvas_height = $this->desired_height;
         // correct the dimensions if the image is actually smaller than the desired thumbnail.
         // this calculation occurs after the canvas size is set (unlike the above modes) so that teh canvas size always stays untouched
         if ($this->allowOverstretch == false) {
             if ($this->desired_width > $src_width) {
                 $this->desired_width = $src_width;
             }
             if ($this->desired_height > $src_height) {
                 $this->desired_height = $src_height;
             }
         }
         // find the dimensional ratios of desired compared to source
         $x_ratio = $this->desired_width / $src_width;
         $y_ratio = $this->desired_height / $src_height;
         // if the image is too tall to fit the thumbnail's proportions
         if ($x_ratio > $y_ratio) {
             $tn_height = $this->desired_height;
             $tn_width = round($this->desired_height * $src_aspect);
         } else {
             $tn_width = $this->desired_width;
             $tn_height = round($this->desired_width / $src_aspect);
         }
     } else {
         $this->error = "Scalemode not recognised";
         return false;
     }
     // recenter if necessary
     if ($this->w && $this->h && $this->anchor != false && ($this->scaleMode == 0 || $this->scaleMode == 2)) {
         switch ($this->anchor) {
             case 'TL':
                 $this->offset_x = 0;
                 $this->offset_y = 0;
             case 'TC':
                 $this->offset_x = -round(($tn_width - $canvas_width) / 2);
                 $this->offset_y = 0;
                 break;
             case 'C':
             default:
                 $this->offset_x = -round(($tn_width - $canvas_width) / 2);
                 $this->offset_y = -round(($tn_height - $canvas_height) / 2);
                 break;
         }
     }
     $cached_image_path = $this->cache_path . $this->w . 'x' . $this->h . '-' . $this->anchor . '-' . $this->scaleMode . '--' . $this->filename . '.jpg';
     // filename for cache
     // if cache is enabled and there's already an image
     if (!empty($this->cache_path) && file_exists($cached_image_path)) {
         $this->srcModified = @filemtime($this->src);
         $thumbModified = @filemtime($cached_image_path);
         // if thumbnail is newer than image then output cached thumbnail and exit
         if ($this->srcModified < $thumbModified) {
             header("Content-Type: image/jpeg");
             // add other file types?
             header("Content-Length: " . filesize($cached_image_path));
             // add other file types?
             header("Last-Modified: " . gmdate("D, d M Y H:i:s", $thumbModified) . " GMT");
             readfile($cached_image_path);
             return true;
         }
     }
     // if cache file did not exist or was out of date, create a new one
     $ext = substr(strrchr($this->src, '.'), 1);
     // get the file extension
     switch ($ext) {
         case 'jpg':
             // jpg
             $src = imagecreatefromjpeg($this->src) or notfound();
             break;
         case 'png':
             // png
             $src = imagecreatefrompng($this->src) or notfound();
             break;
         case 'gif':
             // gif
             $src = imagecreatefromgif($this->src) or notfound();
             break;
         default:
             $this->error = 'unrecognised file extension';
             return false;
     }
     // set up canvas
     $dst = imagecreatetruecolor($canvas_width, $canvas_height);
     if ($this->scaleMode == 2) {
         $bgCol = imagecolorallocate($dst, $this->backgroundColour[0], $this->backgroundColour[1], $this->backgroundColour[2]);
         imagefill($dst, 0, 0, $bgCol);
     }
     imageantialias($dst, true);
     // copy resized image to new canvas
     imagecopyresampled($dst, $src, $this->offset_x, $this->offset_y, 0, 0, $tn_width, $tn_height, $src_width, $src_height);
     if ($this->sharpen) {
         /* Sharpening adddition by Mike Harding */
         // sharpen the image (only available in PHP5.1)
         if (function_exists("imageconvolution")) {
             $matrix = array(array(-1, -1, -1), array(-1, 32, -1), array(-1, -1, -1));
             $divisor = 24;
             $offset = 0;
             imageconvolution($dst, $matrix, $divisor, $offset);
         }
     }
     // attempt to save it to cache
     if (!empty($this->cache_path) || $this->cache_required) {
         if (is_writable($this->cache_path)) {
             imagejpeg($dst, $cached_image_path, $this->jpgQuality);
             // write the thumbnail to cache as well...
         } else {
             $this->error = 'Cache path set or required but not writable.';
             return false;
         }
     }
     // send the header and new image
     header("Content-type: image/jpeg");
     imagejpeg($dst, null, $this->jpgQuality);
     // clear out the resources
     imagedestroy($src);
     imagedestroy($dst);
 }
Пример #10
0
             api($data, 'years');
         }
     } else {
         $output = getData($GLOBALS['sql']['stats']['all'] . $GLOBALS['sql']['tables']['years'] . $GLOBALS['sql']['link']['years'] . " AND year = ?", [$term])[0];
         if ($output) {
             calcStat($output);
             $output["complaints"] = getComplaints("(SELECT id FROM complaints WHERE year = ?)", [$term]);
             if ($GLOBALS['filetype'] == 'html') {
                 printheader('Year: ' . $term);
                 print "<h1>Year: " . $term . "</h1>" . "\n";
                 print statsList($output) . complaintsTable($output["complaints"], "filter");
             } else {
                 api($output, 'year');
             }
         } else {
             notfound('Year');
         }
     }
 } elseif (($term = getQuery(['sbh'])) !== null) {
     $output = getData($GLOBALS['sql']['stats']['all'] . $GLOBALS['sql']['tables']['complainants'] . $GLOBALS['sql']['link']['complainants'] . " AND complainants.name IN ('" . implode("', '", $GLOBALS['sbh']) . "')")[0];
     calcStat($output);
     if (!$term) {
         $output["complainants"] = sbhData();
         $output["complaints"] = getComplaintsDetails("(SELECT id FROM complaints WHERE meetingdate > (NOW() - INTERVAL 6 MONTH) AND meetingdate < (NOW() + INTERVAL 1 DAY) AND id IN (SELECT complaints_id FROM complaints_complainants WHERE complainants_id IN (SELECT id FROM complainants WHERE complainants.name IN ('" . implode("', '", $GLOBALS['sbh']) . "'))) ORDER BY meetingdate DESC)");
         $output["links"]["internal"] = ['Therapeutic Products (Code)' => '/code/Therapeutic+Products+Advertising+Code', 'Therapeutic Services (Code)' => '/code/Therapeutic+Services+Advertising+Code', 'Therapeutic (Product)' => '/product/Therapeutic', 'Homeopathy (Search)' => '/search/homeopath', 'Acupuncture (Search)' => '/search/acupunctur', 'Chiropractic (Search)' => '/search/chiropract', 'Cancer (Search)' => '/search/cancer', 'Arthritis (Search)' => '/search/arthritis', 'BioMag (Company)' => '/company/Woolrest+Biomag', 'Bioptron (Company)' => '/company/Bioptron', 'Appeals' => '/appeals'];
         $output["links"]["external"] = ['ASA Website' => 'http://www.asa.co.nz/', 'Online Complaint Form' => 'http://www.asa.co.nz/complaints/make-a-complaint/', 'Therapeutic Products Code' => 'http://www.asa.co.nz/codes/codes/therapeutic-products-advertising-code/', 'Therapeutic Services Code' => 'http://www.asa.co.nz/codes/codes/therapeutic-services-advertising-code/', 'Ethics Code' => 'http://www.asa.co.nz/codes/codes/advertising-code-of-ethics/', 'Appeals Process' => 'http://www.asa.co.nz/decisions/the-appeals-process/', 'Recent Decisions' => 'http://old.asa.co.nz/decisions_to_media.php', 'Medicines Act 1981' => 'http://www.legislation.govt.nz/act/public/1981/0118/latest/whole.html#DLM53790', 'TAPS "Weasel" Words' => 'http://www.anza.co.nz/Section?Action=View&Section_id=45'];
         if ($GLOBALS['filetype'] == 'html') {
             printheader('ASA SBH Complainant Rankings');
             print '<h1>SBH Related Complaints</h1>';
             print statsList($output);
             print '<div class="row"><div class="col-md-9">';
Пример #11
0
    if (!preg_match("|^/([^/]+)(/)?\$|", $path, $m)) {
        notfound("Unable to parse username out of URL");
    }
    $username = $m[1];
    // find user
    $user = new User();
    try {
        $user->load($username, "login_name");
    } catch (PAException $e) {
        notfound("User {$username} not found");
    }
}
try {
    $user_generaldata = User::load_user_profile($user->user_id, 0, GENERAL);
} catch (PAException $e) {
    notfound("User {$username} exists, but unable to load profile data.");
}
function profile_block_filter($data)
{
    $ret = array();
    foreach ($data as $blk) {
        $ret[$blk['name']] = $blk;
    }
    return $ret;
}
$user_generaldata = profile_block_filter($user_generaldata);
function esc($s)
{
    return htmlspecialchars($s);
}
header("Content-Type: application/rdf+xml");
Пример #12
0
function notfound_description()
{
    return errorpage_description(notfound());
}
Пример #13
0
     $country = "";
 }
 //if no country selected, leave it blank
 //$url='http://free.worldweatheronline.com/feed/weather.ashx?format=xml&num_of_days=1&key=b4fb7e81f6063810113010&q='.urlencode($city).''.urlencode($country);
 $url = 'http://api.worldweatheronline.com/free/v2/weather.ashx?format=xml&num_of_days=1&key=4362a161f785b70a8aec959cd6bdb&q=' . urlencode($city) . '' . urlencode($country);
 //Using the free weather API provided by worldweatheronline.com
 //Get the contents of the resultant URL
 $result = file_get_contents($url);
 /*
 	Here i have defined the function str, whose purpose is to find the text between two tags from some text.
 	it accepts two parameters, tagname and the text from which we have to extract data from between	the tags		
 */
 $err = str("msg", $result);
 if (strlen($err) > 10) {
     //some error message is encountered denoting that weather for that location is not available.
     notfound($city, $country);
 }
 //function that handles when a weather not found condition happens
 $result = str_replace("<![CDATA[", "", $result);
 //unwanted xml stuff as i am not using any built in XML parser. I used RegEx in oreg_natch to get data from XML
 $result = str_replace("]]></", "</", $result);
 $city = str("query", $result);
 preg_match("/\\<current_condition\\>(.*)\\<\\/current_condition\\>/", $result, $cc);
 //to separate the current weather information from other info, we take only this into consideration
 /*
 the following code extracts the data from the XML tags using the str function which i defined later in this script.
 The weather information according to the API can be seen here : http://www.worldweatheronline.com/free-weather-feed.aspx?menu=xmldata
 */
 $observation_time = str("observation_time", $cc[1]);
 $temp_C = str("temp_C", $cc[1]);
 $temp_F = str("temp_F", $cc[1]);
function resizeImage($imgfile, $output, $max_width = NULL, $max_height = NULL)
{
    if (!is_numeric($max_height)) {
        $max_height = 1000;
    }
    if (!is_numeric($max_width)) {
        $max_width = 2000;
    }
    if (function_exists(get_magic_quotes_gpc) && get_magic_quotes_gpc()) {
        $image = stripslashes($imgfile);
    } else {
        $image = $imgfile;
    }
    // if (isset($max_width)) { if($max_width < 2000) $max_width = $max_width; }
    // if (isset($max_height)) { if($max_height < 1000) $max_height = $max_height; }
    if (strrchr($image, '/')) {
        $filename = substr(strrchr($image, '/'), 1);
        // remove folder references
    } else {
        $filename = $image;
    }
    if (!file_exists($image)) {
        return false;
    }
    $size = getimagesize($image);
    $width = $size[0];
    $height = $size[1];
    if ($width == 0) {
        return false;
    }
    // get the ratio needed
    $x_ratio = $max_width / $width;
    $y_ratio = $max_height / $height;
    // if image already meets criteria, load current values in
    // if not, use ratios to load new size info
    if ($width <= $max_width && $height <= $max_height) {
        $tn_width = $width;
        $tn_height = $height;
    } else {
        if ($x_ratio * $height < $max_height) {
            $tn_height = ceil($x_ratio * $height);
            $tn_width = $max_width;
        } else {
            $tn_width = ceil($y_ratio * $width);
            $tn_height = $max_height;
        }
    }
    /* Caching additions by Trent Davies */
    // first check cache
    // cache must be world-readable
    $resized = 'cache/' . $tn_width . 'x' . $tn_height . '-' . $filename;
    $imageModified = @filemtime($image);
    $thumbModified = @filemtime($resized);
    // read image
    $ext = strtolower(substr(strrchr($image, '.'), 1));
    // get the file extension
    switch ($ext) {
        case 'jpg':
            // jpg
            $src = imagecreatefromjpeg($image) or notfound();
            break;
        case 'png':
            // png
            $src = imagecreatefrompng($image) or notfound();
            break;
        case 'gif':
            // gif
            $src = imagecreatefromgif($image) or notfound();
            break;
        default:
            notfound();
    }
    // set up canvas
    $dst = imagecreatetruecolor($tn_width, $tn_height);
    imageantialias($dst, true);
    // copy resized image to new canvas
    imagecopyresampled($dst, $src, 0, 0, 0, 0, $tn_width, $tn_height, $width, $height);
    /* Sharpening adddition by Mike Harding */
    // sharpen the image (only available in PHP5.1)
    /*if (function_exists("imageconvolution")) {
          $matrix = array(    array( -1, -1, -1 ),
          array( -1, 32, -1 ),
          array( -1, -1, -1 ) );
          $divisor = 24;
          $offset = 0;
    	
          imageconvolution($dst, $matrix, $divisor, $offset);
          }*/
    // send the header and new image
    if ($ext == 'jpg') {
        imagejpeg($dst, $output, 90);
    } else {
        if ($ext == 'png') {
            imagepng($dst, $output, 90);
        } else {
            if ($ext == 'gif') {
                imagegif($dst, $output, 90);
            }
        }
    }
    // clear out the resources
    imagedestroy($src);
    imagedestroy($dst);
    return true;
}
Пример #15
0
<?php

include "functions.php";
$p = $_SERVER['QUERY_STRING'];
echo "<!DOCTYPE html>\n<html>\n";
display_headers(" Error : 404 - Page Not Found!  ");
echo "\n<body>";
notfound("Page you are looking for is no longer available");
echo "\n</body>\n</html>";
Пример #16
0
function doThumbnail()
{
    // define the base image dir
    $base_img_dir = "./";
    // $QUERY_STRING =
    //  f(3c9b5fa6bc0fa)  img_file
    //  w(123|15%)        width of output
    //  h(123|10%)        height of output
    //  x(123)            max width of output
    //  y(123)            max height of output
    //  t(jpg|png)        type of output
    //  q(100)            quality of jpeg
    // find tags
    preg_match_all("/\\+*(([a-z])\\(([^\\)]+)\\))\\+*/", $QUERY_STRING, $matches, PREG_SET_ORDER);
    // empty array and set regular expressions for the check
    $tags = array();
    $check = array("f" => "[0-9a-zA-Z]{13}", "w" => "[0-9]+%?", "h" => "[0-9]+%?", "x" => "[0-9]+", "y" => "[0-9]+", "t" => "jpg|png", "q" => "1?[0-9]{1,2}");
    // check tags and save correct values in array
    for ($i = 0; $i < count($matches); $i++) {
        if (isset($check[$matches[$i][2]])) {
            if (preg_match('/^(' . $check[$matches[$i][2]] . ')$/', $matches[$i][3])) {
                $tags[$matches[$i][2]] = $matches[$i][3];
            }
        }
    }
    function notfound()
    {
        header("HTTP/1.0 404 Not Found");
        exit;
    }
    // check that filename is given
    if (!isset($tags["f"])) {
        notfound();
    }
    // check if file exists
    if (!file_exists($base_img_dir . $tags["f"])) {
        notfound();
    }
    // retrieve file info
    $imginfo = getimagesize($base_img_dir . $tags["f"]);
    // load image
    switch ($imginfo[2]) {
        case 2:
            // jpg
            $img_in = imagecreatefromjpeg($base_img_dir . $tags["f"]) or notfound();
            if (!isset($tags["t"])) {
                $tags["t"] = "jpg";
            }
            break;
        case 3:
            // png
            $img_in = imagecreatefrompng($base_img_dir . $tags["f"]) or notfound();
            if (!isset($tags["t"])) {
                $tags["t"] = "png";
            }
            break;
        default:
            notfound();
    }
    // check for maximum width and height
    if (isset($tags["x"])) {
        if ($tags["x"] < imagesx($img_in)) {
            $tags["w"] = $tags["x"];
        }
    }
    if (isset($tags["y"])) {
        if ($tags["y"] < imagesy($img_in)) {
            $tags["h"] = $tags["y"];
        }
    }
    // check for need to resize
    if (isset($tags["h"]) or isset($tags["w"])) {
        // convert relative to absolute
        if (isset($tags["w"])) {
            if (strstr($tags["w"], "%")) {
                $tags["w"] = intval(substr($tags["w"], 0, -1)) / 100 * $imginfo[0];
            }
        }
        if (isset($tags["h"])) {
            if (strstr($tags["h"], "%")) {
                $tags["h"] = intval(substr($tags["h"], 0, -1)) / 100 * $imginfo[1];
            }
        }
        // resize
        if (isset($tags["w"]) and isset($tags["h"])) {
            $out_w = $tags["w"];
            $out_h = $tags["h"];
        } elseif (isset($tags["w"]) and !isset($tags["h"])) {
            $out_w = $tags["w"];
            $out_h = $imginfo[1] * ($tags["w"] / $imginfo[0]);
        } elseif (!isset($tags["w"]) and isset($tags["h"])) {
            $out_w = $imginfo[0] * ($tags["h"] / $imginfo[1]);
            $out_h = $tags["h"];
        } else {
            $out_w = $tags["w"];
            $out_h = $tags["h"];
        }
        // new image in $img_out
        $img_out = imagecreate($out_w, $out_h);
        imagecopyresized($img_out, $img_in, 0, 0, 0, 0, imagesx($img_out), imagesy($img_out), imagesx($img_in), imagesy($img_in));
    } else {
        // no resize needed
        $img_out = $img_in;
    }
    // check for a given jpeg-quality, otherwise set to default
    if (!isset($tags["q"])) {
        $tags["q"] = 75;
    }
    // returning the image
    switch ($tags["t"]) {
        case "jpg":
            header("Content-type: image/jpeg");
            imagejpeg($img_out, "", $tags["q"]);
            exit;
        case "png":
            header("Content-type: image/png");
            imagepng($img_out);
            exit;
        default:
            notfound();
    }
}