/** * Process the form * * @param array $clean reference to validated $_POST */ function formProcess(&$clean) { // Check $module, assign $table $table = $this->getTable($clean['module']); if (!$table) { throw new Exception('Unsuported $module'); } // -------------------------------------------------------------------- // Get image from database // -------------------------------------------------------------------- $query = "SELECT users_id, image FROM {$table} WHERE id = ? "; $db = suxDB::get(); $st = $db->prepare($query); $st->execute(array($clean['id'])); $image = $st->fetch(PDO::FETCH_ASSOC); if (!$image['image']) { throw new Exception('$image not found'); } if ($image['users_id'] != $_SESSION['users_id']) { // Security check if (!$this->user->isRoot()) { $access = $this->user->getAccess($clean['module']); if (!isset($GLOBALS['CONFIG']['ACCESS'][$module]['admin'])) { suxFunct::redirect(suxFunct::getPreviousURL('cropper')); } elseif ($access < $GLOBALS['CONFIG']['ACCESS'][$clean['module']]['admin']) { suxFunct::redirect(suxFunct::getPreviousURL('cropper')); } } } $path_to_dest = "{$GLOBALS['CONFIG']['PATH']}/data/{$clean['module']}/{$image['image']}"; $path_to_source = suxPhoto::t2fImage($path_to_dest); if (!is_writable($path_to_dest)) { die('Destination is not writable? ' . $path_to_dest); } // ---------------------------------------------------------------------------- // Manipulate And Rewrite Image // ---------------------------------------------------------------------------- // $image $format = explode('.', $path_to_source); $format = mb_strtolower(end($format)); if ($format == 'jpg') { $format = 'jpeg'; } // fix stupid mistake if (!($format == 'jpeg' || $format == 'gif' || $format == 'png')) { die('Invalid image format'); } // Try to adjust memory for big files suxPhoto::fudgeFactor($format, $path_to_source); $func = 'imagecreatefrom' . $format; $image = $func($path_to_source); if (!$image) { die('Invalid image format'); } // $thumb $thumb = imagecreatetruecolor($clean['x2'], $clean['y2']); $white = imagecolorallocate($thumb, 255, 255, 255); ImageFilledRectangle($thumb, 0, 0, $clean['x2'], $clean['y2'], $white); imagealphablending($thumb, true); // Output imagecopyresampled($thumb, $image, 0, 0, $clean['x1'], $clean['y1'], $clean['x2'], $clean['y2'], $clean['width'], $clean['height']); $func = 'image' . $format; $func($thumb, $path_to_dest); // Free memory imagedestroy($image); imagedestroy($thumb); $this->log->write($_SESSION['users_id'], "sux0r::cropper() {$table}, id: {$clean['id']}", 1); // Private }
<?php // Ajax // TinyMCE external image list url // http://wiki.moxiecode.com/index.php/TinyMCE:Configuration/external_image_list_url require_once dirname(__FILE__) . '/../../config.php'; require_once dirname(__FILE__) . '/../../initialize.php'; if (!isset($_SESSION['users_id'])) { exit; } $photo = new suxPhoto(); $images = $photo->getPhotosByUser(null, 0, $_SESSION['users_id']); $output = 'var tinyMCEImageList = new Array('; if ($images) { foreach ($images as $image) { $output .= "\n" . '["' . utf8_encode($image['image']) . '", "' . utf8_encode("{$GLOBALS['CONFIG']['URL']}/data/photos/" . suxPhoto::t2fImage($image['image'])) . '"],'; } } if ($images) { $output = substr($output, 0, -1); } // remove last comma $output .= "\n" . ');'; header('Content-type: text/javascript'); // Make output a real JavaScript file echo $output;
foreach ($image_dirs as $dir => $table) { $path = $CONFIG['PATH'] . "/data/{$dir}"; if (is_dir($path)) { foreach (new DirectoryIterator($path) as $file) { $pattern = '/[^_fullsize](\\.jpe?g|\\.gif|\\.png)$/i'; if ($file->isFile() && preg_match($pattern, $file)) { // Query $query = "SELECT id FROM {$table} WHERE image = " . $db->quote("{$file}"); $st = $db->query($query); if ($st->fetchColumn() <= 0) { $not_found[] = "{$path}/{$file}"; } } } } } // Purge $count = 0; foreach ($not_found as $file) { if (!$debug) { if (is_file($file)) { unlink($file); } if (is_file(suxPhoto::t2fImage($file))) { unlink(suxPhoto::t2fImage($file)); } ++$count; } echo "unlink() {$file} <br />\n"; } echo "> {$count} images deleted <br /> \n";
/** * View photo */ function view($id) { // Get nickname if (isset($_SESSION['nickname'])) { $nn = $_SESSION['nickname']; } else { $nn = 'nobody'; } // "Cache Groups" using a vertical bar | $cache_id = "{$nn}|view|{$id}"; $this->tpl->caching = 1; if (!$this->tpl->isCached('view.tpl', $cache_id)) { $this->r->arr['photos'] = $this->photo->getPhotoByID($id); if ($this->r->arr['photos'] == false || !count($this->r->arr['photos'])) { suxFunct::redirect(suxFunct::getPreviousURL()); } else { $this->r->arr['photos']['image'] = suxPhoto::t2fImage($this->r->arr['photos']['image']); // Fullsize // Album info $this->r->arr['album'] = $this->photo->getAlbumByID($this->r->arr['photos']['photoalbums_id']); $tmp = $this->user->getByID($this->r->arr['album']['users_id']); $this->r->arr['album']['nickname'] = $tmp['nickname']; // Previous, next, and page number $prev_id = null; $next_id = null; $page = 1; $query = 'SELECT id FROM photos WHERE photoalbums_id = ? ORDER BY image '; // Same order as suxPhoto->getPhotos() $db = suxDB::get(); $st = $db->prepare($query); $st->execute(array($this->r->arr['photos']['photoalbums_id'])); $i = 0; while ($prev_next = $st->fetch(PDO::FETCH_ASSOC)) { ++$i; if ($prev_next['id'] == $id) { break; } if ($i >= $this->per_page) { $i = 0; ++$page; } $prev_id = $prev_next['id']; } $prev_next = $st->fetch(PDO::FETCH_ASSOC); $next_id = $prev_next['id']; $this->r->text['prev_id'] = $prev_id; $this->r->text['next_id'] = $next_id; $this->r->text['back_url'] = suxFunct::makeUrl('photos/album/' . $this->r->arr['photos']['photoalbums_id'], array('page' => $page)); $this->r->title .= " | {$this->r->gtext['photos']} | {$this->r->arr['album']['title']}"; } } $this->tpl->display('view.tpl', $cache_id); }