Updates to the controller and the new class for image handling (not complete)

git-svn-id: http://svn.cleancode.org/svn/pickles@20 4d10bc64-7434-11dc-a737-d2d0f8310089
This commit is contained in:
Josh Sherman 2008-06-14 06:21:47 +00:00
parent 8ccfdc2d1a
commit 78ff970b15
3 changed files with 108 additions and 13 deletions

View file

@ -7,43 +7,88 @@ class Controller {
$section = $action = null;
// Set up the section and action from the _REQUEST values
if (isset($_REQUEST['section'])) {
// Check for section.action.php
if (isset($_REQUEST['action']) && file_exists('../logic/' . $_REQUEST['section'] . '.' . $_REQUEST['action'] . '.php')) {
$section = $_REQUEST['section'];
$action = $_REQUEST['action'];
}
// else check for section.php
// Else check for section.php
else if (file_exists('../logic/' . $_REQUEST['section'] . '.php')) {
$section = $_REQUEST['section'];
}
// Check for section.action.tpl
// Else check for section.action.tpl
else if (isset($_REQUEST['action']) && file_exists('../templates/' . $_REQUEST['section'] . '.' . $_REQUEST['action'] . '.tpl')) {
$section = $_REQUEST['section'];
$action = $_REQUEST['action'];
}
// else check for section.tpl
// Else check for section.tpl
else if (file_exists('../templates/' . $_REQUEST['section'] . '.tpl')) {
$section = $_REQUEST['section'];
}
}
// Determine if we're on an admin page
$is_admin = preg_match('/^admin\./', $section);
// Check that the user is authenticated
if ($is_admin && !isset($_SESSION['user_id'])) {
$section = 'admin';
$action = null;
}
// If we've come this far without a section, use the default
if (!isset($section)) {
$section = Config::get('default');
}
$file = '../logic/' . $section . ($action ? '.' . $action : null) . '.php';
$template = $section . ($action ? '.' . $action : null) . '.tpl';
if (file_exists('../logic/' . $file)) {
// Check that the logic script exists and if so, load it
$file = '../logic/' . $section . ($action ? '.' . $action : null) . '.php';
if (file_exists($file)) {
require_once $file;
}
$smarty->assign('navigation', Config::get('navigation'));
// Check if we're accessing an admin sub section and load the logic script
if ($section != 'admin' && $is_admin) {
$template = $section . '.tpl';
$file = '../logic/' . $section . '.php';
if (file_exists($file)) {
require_once $file;
}
$section = 'admin';
}
// Else, just define the template
else {
$template = $section . ($action ? '.' . $action : null) . '.tpl';
}
// Load the main navigation from the config
$navigation = Config::get('navigation');
// Add the admin section if we're authenticated
if (isset($_SESSION['user_id'])) {
$navigation['admin'] = 'Admin';
if ($section == 'admin') {
$smarty->assign('admin', Config::get('admin'));
}
}
// Pass all of our controller values to Smarty
$smarty->assign('navigation', $navigation);
$smarty->assign('section', $section);
$smarty->assign('action', $action);
$smarty->assign('template', $template);
if (isset($_SESSION)) {
$smarty->assign('session', $_SESSION);
}
// Load it up
header('Content-type: text/html; charset=UTF-8');
$smarty->display('index.tpl');
}

51
classes/ImageUtils.php Normal file
View file

@ -0,0 +1,51 @@
<?php
class ImageUtils {
static function check($type, $types = array('image/jpeg', 'image/gif', 'image/png')) {
if (!is_array($types)) {
$types[0] = $types;
}
return in_array($type, $types);
}
static function move($origin, $destination) {
move_uploaded_file($origin, $destination);
imagedestroy($origin);
}
static function resize() {
}
static function convert($original, $destination, $keep_original = true) {
var_dump('convert ' . $original . ' ' . $destination);
var_dump( exec('convert ' . $original . ' ' . $destination) );
}
/*
if ($_FILES['image']['type'] == 'image/jpeg') {
$original = $directory . 'original.jpg';
$source = imagecreatefromjpeg($original);
list($width, $height) = getimagesize($original);
$sizes = array('small' => 75, 'medium' => 150, 'large' => 500);
foreach ($sizes as $name => $size) {
$temp = imagecreatetruecolor($size, $size);
imagecopyresampled($temp, $source, 0, 0, 0, 0, $size, $size, $width, $height);
imagejpeg($temp, "{$directory}{$name}.jpg", 85);
imagedestroy($temp);
}
imagedestroy($source);
*/
}
?>

View file

@ -2,7 +2,7 @@
<debug></debug>
<disable></disable>
<fckeditor></fckeditor>
<session></session>
<session>true</session>
<smarty>true</smarty>
<magpierss></magpierss>
<database>
@ -21,9 +21,8 @@
<contact>Contact</contact>
</navigation>
<admin>
<news>News</news>
<releases>Releases</releases>
<artists>Artists</artists>
<shop>Shop</shop>
<artist>Artist Profile</artist>
<user>User Account</user>
<logout>Logout</logout>
</admin>
</config>