function removeimage($id) { $sql = "delete from `rentorhire_images` where photo_id='" . $id . "'"; $result = $this->mysql->query($sql); $ph = new photo(); $ph->deletePhoto($id); }
public function slideshow() { expHistory::set('viewable', $this->params); $where = $this->aggregateWhereClause(); $order = 'rank'; $s = new photo(); $slides = $s->find('all', $where, $order); assign_to_template(array('slides' => $slides)); }
private static function _create_random_item($root = null, $rand = null) { $root = $root ? $root : ORM::factory("item", 1); $rand = $rand ? $rand : rand(); $item = photo::create($root, MODPATH . "gallery/tests/test.jpg", "{$rand}.jpg", $rand, $rand); return $item; }
/** * 注册内部管理账户 * * @access public * @param string phoneNum 手机号 * @param string password 登陆密码md5 * @return array */ public function create() { #参数检查 $this->params = $this->require_params(array('phoneNum', 'password')); $this->params['nickname'] = F::request('nickname', ''); $this->params['project'] = F::request('project', ''); $this->params['project'] = str_replace(',', ',', $this->params['project']); if (!FValidator::phone($this->params['phoneNum'])) { throw new Exception('手机号格式非法', 100); } #检查手机是否已经注册 $userId = $this->userModel->getUserIdByUsername($this->params['phoneNum']); if (!$userId) { #生成一个新的账户 $userId = $this->userModel->create($this->params['phoneNum'], $this->params['password'], self::ADMIN_ACCOUNT); } else { #更新账户密码信息 $updateResult = $this->userModel->updatePassword($userId, $this->params['password']); } #保存图片信息 $filePath = 'avatar/' . $userId . '_' . md5_file($_FILES['photo']['tmp_name']) . '.' . end(explode('.', $_FILES['photo']['name'])); $this->photoTool->copyImageWithSize($_FILES['photo']['tmp_name'], self::IMG_PATH_BASE . $filePath, 60, 60); $this->params['photo'] = $filePath; #更新用户昵称 $this->userModel->updateUserProfile($userId, $this->params['nickname'], $filePath); #授权相关项目授权 $this->userModel->getProjectAuth($userId, explode(',', $this->params['project'])); #跳转回user_add页面 header('location:http://' . $_SERVER['HTTP_HOST'] . '/' . self::CRM_ADMIN_BASE . 'user_add.php'); }
public function add_photo($id) { $album = ORM::factory("item", $id); access::required("view", $album); access::required("add", $album); access::verify_csrf(); $file_validation = new Validation($_FILES); $file_validation->add_rules("Filedata", "upload::valid", "upload::type[gif,jpg,png,flv,mp4]"); if ($file_validation->validate()) { // SimpleUploader.swf does not yet call /start directly, so simulate it here for now. if (!batch::in_progress()) { batch::start(); } $temp_filename = upload::save("Filedata"); try { $name = substr(basename($temp_filename), 10); // Skip unique identifier Kohana adds $title = item::convert_filename_to_title($name); $path_info = pathinfo($temp_filename); if (array_key_exists("extension", $path_info) && in_array(strtolower($path_info["extension"]), array("flv", "mp4"))) { $movie = movie::create($album, $temp_filename, $name, $title); log::success("content", t("Added a movie"), html::anchor("movies/{$movie->id}", t("view movie"))); } else { $photo = photo::create($album, $temp_filename, $name, $title); log::success("content", t("Added a photo"), html::anchor("photos/{$photo->id}", t("view photo"))); } } catch (Exception $e) { unlink($temp_filename); throw $e; } unlink($temp_filename); } print "File Received"; }
public function form_edit($photo_id) { $photo = ORM::factory("item", $photo_id); access::required("view", $photo); access::required("edit", $photo); print photo::get_edit_form($photo); }
public function exif_extract_test() { $rand = rand(); $root = ORM::factory("item", 1); $photo = photo::create($root, MODPATH . "exif/tests/data/image.jpg", "{$rand}.jpg", $rand, $rand); $expected = array(array("caption" => "Camera Maker", "value" => "Pentax Corporation"), array("caption" => "Camera Model", "value" => "PENTAX K10D"), array("caption" => "Aperture", "value" => "f/2.8"), array("caption" => "Color Space", "value" => "Uncalibrated"), array("caption" => "Exposure Value", "value" => "4294.67 EV"), array("caption" => "Exposure Program", "value" => "Program"), array("caption" => "Exposure Time", "value" => "1/60 sec"), array("caption" => "Flash", "value" => "No Flash"), array("caption" => "Focal Length", "value" => "50 mm"), array("caption" => "ISO", "value" => "6553700"), array("caption" => "Metering Mode", "value" => "Multi-Segment"), array("caption" => "Date/Time", "value" => "2008:03:17 17:41:25"), array("caption" => "Copyright", "value" => "(C) 2008 - T. Almdal"), array("caption" => "Orientation", "value" => "1: Normal (0 deg)"), array("caption" => "Resolution Unit", "value" => "Inch"), array("caption" => "X Resolution", "value" => "240 dots per ResolutionUnit"), array("caption" => "Y Resolution", "value" => "240 dots per ResolutionUnit"), array("caption" => "Brightness Value", "value" => "0"), array("caption" => "Scene Type", "value" => "0"), array("caption" => "Subject Distance", "value" => "0")); $this->assert_equal($expected, exif::get($photo)); }
function saveProfile($verify) { $sim = new simulator(); $handle = fopen("php://stdin", "r"); $pic = new photo(); $clr = new color(); echo "Enter Header Picture"; $this->temp = $pic->returnPhoto($verify); $size = count($this->temp); for ($x = 0; $x <= $size - 1; $x++) { echo $x . " " . $this->temp[$x] . "\n"; } echo "Press Number to add photo"; $pho = fgets($handle); $photo = "Header Picture: " . $this->temp[1]; echo "Enter Profile Picture"; for ($x = 0; $x <= $size - 1; $x++) { echo $x . " " . $this->temp[$x] . "\n"; } $ppho = fgets($handle); $pPhoto = "Profile Picture:" . $this->temp[1]; echo "Enter Full Name"; $full_name = fgets($handle); echo "Enter Bio"; $bio = fgets($handle); echo "Enter Location"; $location = fgets($handle); echo "Enter Website"; $website = fgets($handle); echo "Enter DOB "; $dob = fgets($handle); echo "Enter Theme Color"; $clrs = $clr->returnColors(); for ($x = 0; $x <= $size - 1; $x++) { echo $x . " " . $clrs[$x] . "\n"; } $t = fgets($handle); $theme_color = $clrs[1]; $myfile = fopen("{$verify}" . "profile", "w") or die("Unable to open file!"); fwrite($myfile, $photo . "\n" . $pPhoto . "\n" . $full_name . $bio . $location . $website . $dob . $theme_color); echo "Profile Made"; $sim->followUp($verify); }
public function get_file_metadata_with_valid_extension_but_illegal_file_contents_test() { copy(MODPATH . "gallery/tests/Photo_Helper_Test.php", TMPPATH . "test_php_with_jpg_extension.jpg"); try { $metadata = photo::get_file_metadata(TMPPATH . "test_php_with_jpg_extension.jpg"); $this->assert_true(false, "Shouldn't get here"); } catch (Exception $e) { // pass } unlink(TMPPATH . "test_php_with_jpg_extension.jpg"); }
static function add_from_server($task) { $context = unserialize($task->context); try { $paths = array_keys(unserialize(module::get_var("server_add", "authorized_paths"))); $path = $paths[$context["next_path"]]; if (!empty($context["files"][$path])) { $file = $context["files"][$path][$context["position"]]; $parent = ORM::factory("item", $file["parent_id"]); access::required("server_add", $parent); access::required("add", $parent); if (!$parent->is_album()) { throw new Exception("@todo BAD_ALBUM"); } $name = $file["name"]; if ($file["type"] == "album") { $album = ORM::factory("item")->where("name", $name)->where("parent_id", $parent->id)->find(); if (!$album->loaded) { $album = album::create($parent, $name, $name, null, user::active()->id); } // Now that we have a new album. Go through the remaining files to import and change the // parent_id of any file that has the same relative path as this album's path. $album_path = "{$file['path']}/{$name}"; for ($idx = $context["position"] + 1; $idx < count($context["files"][$path]); $idx++) { if (strpos($context["files"][$path][$idx]["path"], $album_path) === 0) { $context["files"][$path][$idx]["parent_id"] = $album->id; } } } else { $extension = strtolower(substr(strrchr($name, '.'), 1)); $source_path = "{$path}{$file['path']}/{$name}"; if (in_array($extension, array("flv", "mp4"))) { $movie = movie::create($parent, $source_path, $name, $name, null, user::active()->id); } else { $photo = photo::create($parent, $source_path, $name, $name, null, user::active()->id); } } $context["counter"]++; if (++$context["position"] >= count($context["files"][$path])) { $context["next_path"]++; $context["position"] = 0; } } else { $context["next_path"]++; } } catch (Exception $e) { $context["errors"][$path] = $e->getMessage(); } $task->context = serialize($context); $task->state = "success"; $task->percent_complete = $context["counter"] / (double) $context["total"] * 100; $task->done = $context["counter"] == (double) $context["total"]; }
function tweetInput($verify) { $pic = new photo(); $twt = new tweet(); $dbh = new dbHandler(); $handle = fopen("php://stdin", "r"); echo "Write your Tweet\n "; $tweet = fgets($handle); $text = " Tweet: " . $tweet; echo "Write Location"; $loc = fgets($handle); $location = "Location: " . $loc; echo "Enter Photo\n"; $this->pic_array = $pic->returnPhoto($verify); $size = count($this->pic_array); for ($x = 0; $x <= $size - 1; $x++) { echo $x . " " . $this->pic_array[$x] . "\n"; } $pho = fgets($handle); $photo = "Picture: " . $this->pic_array[1]; $twt->post_tweet($verify, $text, $location, $photo); }
public function setup() { $this->_server = $_SERVER; $root = ORM::factory("item", 1); $this->_album = album::create($root, rand(), "test album"); access::deny(identity::everybody(), "view_full", $this->_album); access::deny(identity::registered_users(), "view_full", $this->_album); $rand = rand(); $this->_item = photo::create($this->_album, MODPATH . "gallery/tests/test.jpg", "{$rand}.jpg", $rand, $rand); $this->_proxy = ORM::factory("digibug_proxy"); $this->_proxy->uuid = md5(rand()); $this->_proxy->item_id = $this->_item->id; $this->_proxy->save(); }
static function item_before_create($item) { $max_size = module::get_var("max_size", "max_size", 600); if ($item->is_photo()) { list($width, $height, $mime_type) = photo::get_file_metadata($item->data_file); if ($width > $max_size || $height > $max_size) { $tempnam = tempnam(TMPPATH, "size"); $tmpfile = $tempnam . "." . pathinfo($item->data_file, PATHINFO_EXTENSION); gallery_graphics::resize($item->data_file, $tmpfile, array("width" => $max_size, "height" => $max_size, "master" => Image::AUTO)); rename($tmpfile, $item->data_file); unlink($tempnam); } } }
public function add_photo($id) { $album = ORM::factory("item", $id); access::required("view", $album); access::required("add", $album); access::verify_csrf(); $file_validation = new Validation($_FILES); $file_validation->add_rules("Filedata", "upload::valid", "upload::required", "upload::type[gif,jpg,jpeg,png,flv,mp4]"); if ($file_validation->validate()) { // SimpleUploader.swf does not yet call /start directly, so simulate it here for now. if (!batch::in_progress()) { batch::start(); } $temp_filename = upload::save("Filedata"); try { $name = substr(basename($temp_filename), 10); // Skip unique identifier Kohana adds $title = item::convert_filename_to_title($name); $path_info = @pathinfo($temp_filename); if (array_key_exists("extension", $path_info) && in_array(strtolower($path_info["extension"]), array("flv", "mp4"))) { $item = movie::create($album, $temp_filename, $name, $title); log::success("content", t("Added a movie"), html::anchor("movies/{$item->id}", t("view movie"))); } else { $item = photo::create($album, $temp_filename, $name, $title); log::success("content", t("Added a photo"), html::anchor("photos/{$item->id}", t("view photo"))); } // We currently have no way of showing errors if validation fails, so only call our event // handlers if validation passes. $form = $this->_get_add_form($album); if ($form->validate()) { module::event("add_photos_form_completed", $item, $form); } } catch (Exception $e) { Kohana_Log::add("alert", $e->__toString()); if (file_exists($temp_filename)) { unlink($temp_filename); } header("HTTP/1.1 500 Internal Server Error"); print "ERROR: " . $e->getMessage(); return; } unlink($temp_filename); print "FILEID: {$item->id}"; } else { header("HTTP/1.1 400 Bad Request"); print "ERROR: " . t("Invalid Upload"); } }
public function change_photo_no_csrf_fails_test() { $controller = new Photos_Controller(); $root = ORM::factory("item", 1); $this->_photo = photo::create($root, MODPATH . "gallery/tests/test.jpg", "test", "test", "test"); $_POST["name"] = "new name"; $_POST["title"] = "new title"; $_POST["description"] = "new description"; access::allow(group::everybody(), "edit", $root); try { $controller->_update($this->_photo); $this->assert_true(false, "This should fail"); } catch (Exception $e) { // pass } }
public function generate_album_cover_from_png_test() { $input_file = MODPATH . "gallery/tests/test.jpg"; $output_file = TMPPATH . test::random_name() . ".png"; gallery_graphics::resize($input_file, $output_file, null, null); $album = test::random_album(); $photo = test::random_photo_unsaved($album); $photo->set_data_file($output_file); $photo->name = "album_cover_from_png.png"; $photo->save(); $album->reload(); // Check that the image was correctly resized and converted to jpg $this->assert_equal(array(200, 150, "image/jpeg", "jpg"), photo::get_file_metadata($album->thumb_path())); // Check that the items table got updated $this->assert_equal(array(200, 150), array($album->thumb_width, $album->thumb_height)); // Check that the image is not marked dirty $this->assert_equal(0, $album->thumb_dirty); }
echo $item->url(); ?> "> <?php if ($item->has_thumb()) { ?> <img src="<?php echo $item->thumb_url(); ?> " alt="<?php echo html::purify($item->title)->for_html_attr(); ?> " <?php echo photo::img_dimensions($item->thumb_width, $item->thumb_height, 75); ?> /> <?php } else { ?> <?php echo t("No thumbnail"); ?> <?php } ?> </a> </div> </div> <p><?php
public function resize_jpg_to_png_without_options_test() { // Input is a 1024x768 jpg, output is png without options - should not attempt resize $input_file = MODPATH . "gallery/tests/test.jpg"; $output_file = TMPPATH . test::random_name() . ".png"; gallery_graphics::resize($input_file, $output_file, null, null); // Output is converted from input without resize $this->assert_equal(array(1024, 768, "image/png", "png"), photo::get_file_metadata($output_file)); }
} else { header("Location: ../views/signinPage.php?message=" . urlencode("Login again!")); } ?> <!DOCTYPE html> <html lang="en"> <head> <?php require_once "engine.php"; require_once "../models/user.php"; require_once "../models/photo.php"; require_once "../models/album.php"; require_once "../models/DataAccessHelper.php"; echo $includes; $imgsrc = array(); $rs = photo::getImageusername($temp['username']); foreach ($rs as $row) { $imgsrc[] = 'data:image/jpg;base64,' . base64_encode($row['imageFile']); } ?> <title> PhotoShare </title> </head> <script> </script> <body> <?php echo $navbar;
/** * Import a single photo or movie. */ static function import_item(&$queue) { $g2_item_id = array_shift($queue); if (self::map($g2_item_id)) { return t("Item with id: %id already imported, skipping", array("id" => $g2_item_id)); } try { self::$current_g2_item = $g2_item = g2(GalleryCoreApi::loadEntitiesById($g2_item_id)); $g2_path = g2($g2_item->fetchPath()); } catch (Exception $e) { return t("Failed to import Gallery 2 item with id: %id\n%exception", array("id" => $g2_item_id, "exception" => $e->__toString())); } $parent = ORM::factory("item", self::map($g2_item->getParentId())); $g2_type = $g2_item->getEntityType(); $corrupt = 0; if (!file_exists($g2_path)) { // If the Gallery 2 source image isn't available, this operation is going to fail. That can // happen in cases where there's corruption in the source Gallery 2. In that case, fall // back on using a broken image. It's important that we import *something* otherwise // anything that refers to this item in Gallery 2 will have a dangling pointer in Gallery 3 // // Note that this will change movies to be photos, if there's a broken movie. Hopefully // this case is rare enough that we don't need to take any heroic action here. g2_import::log(t("%path missing in import; replacing it with a placeholder", array("path" => $g2_path))); $g2_path = MODPATH . "g2_import/data/broken-image.gif"; $g2_type = "GalleryPhotoItem"; $corrupt = 1; } $message = array(); switch ($g2_type) { case "GalleryPhotoItem": if (!in_array($g2_item->getMimeType(), array("image/jpeg", "image/gif", "image/png"))) { Kohana::log("alert", "{$g2_path} is an unsupported image type; using a placeholder gif"); $message[] = t("'%path' is an unsupported image type, using a placeholder", array("path" => $g2_path)); $g2_path = MODPATH . "g2_import/data/broken-image.gif"; $corrupt = 1; } try { $item = photo::create($parent, $g2_path, $g2_item->getPathComponent(), self::_decode_html_special_chars($g2_item->getTitle()), self::_decode_html_special_chars(self::extract_description($g2_item)), self::map($g2_item->getOwnerId())); } catch (Exception $e) { Kohana::log("alert", "Corrupt image {$g2_path}\n" . $e->__toString()); $message[] = t("Corrupt image '%path'", array("path" => $g2_path)); $message[] = $e->__toString(); $corrupt = 1; } break; case "GalleryMovieItem": // @todo we should transcode other types into FLV if (in_array($g2_item->getMimeType(), array("video/mp4", "video/x-flv"))) { try { $item = movie::create($parent, $g2_path, $g2_item->getPathComponent(), self::_decode_html_special_chars($g2_item->getTitle()), self::_decode_html_special_chars(self::extract_description($g2_item)), self::map($g2_item->getOwnerId())); } catch (Exception $e) { Kohana::log("alert", "Corrupt movie {$g2_path}\n" . $e->__toString()); $message[] = t("Corrupt movie '%path'", array("path" => $g2_path)); $message[] = $e->__toString(); $corrupt = 1; } } else { Kohana::log("alert", "{$g2_path} is an unsupported movie type"); $message[] = t("'%path' is an unsupported movie type", array("path" => $g2_path)); $corrupt = 1; } break; default: // Ignore break; } if (!empty($item)) { self::import_keywords_as_tags($g2_item->getKeywords(), $item); } if (isset($item)) { self::set_map($g2_item_id, $item->id); $item->view_count = g2(GalleryCoreApi::fetchItemViewCount($g2_item_id)); $item->save(); } if ($corrupt) { $url_generator = $GLOBALS["gallery"]->getUrlGenerator(); // @todo we need a more persistent warning $g2_item_url = $url_generator->generateUrl(array("itemId" => $g2_item->getId())); // Why oh why did I ever approve the session id placeholder idea in G2? $g2_item_url = str_replace('&g2_GALLERYSID=TMP_SESSION_ID_DI_NOISSES_PMT', '', $g2_item_url); if (!empty($item)) { $message[] = t("<a href=\"%g2_url\">%title</a> from Gallery 2 could not be processed; " . "(imported as <a href=\"%g3_url\">%title</a>)", array("g2_url" => $g2_item_url, "g3_url" => $item->url(), "title" => $g2_item->getTitle())); } else { $message[] = t("<a href=\"%g2_url\">%title</a> from Gallery 2 could not be processed", array("g2_url" => $g2_item_url, "title" => $g2_item->getTitle())); } } self::$current_g2_item = null; return $message; }
private static function _add_album_or_photo($desired_type = null) { srand(time()); $parents = ORM::factory("item")->where("type", "album")->find_all()->as_array(); $owner_id = user::active()->id; $test_images = glob(dirname(dirname(__FILE__)) . "/data/*.[Jj][Pp][Gg]"); $parent = $parents[array_rand($parents)]; $parent->reload(); $type = $desired_type; if (!$type) { $type = rand(0, 10) ? "photo" : "album"; } if ($type == "album") { $thumb_size = module::get_var("core", "thumb_size"); $rand = rand(); $parents[] = album::create($parent, "rnd_{$rand}", "Rnd {$rand}", "random album {$rand}", $owner_id)->save(); } else { $photo_index = rand(0, count($test_images) - 1); photo::create($parent, $test_images[$photo_index], basename($test_images[$photo_index]), "rnd_" . rand(), "sample thumb", $owner_id); } }
public function form_edit($id) { $item = model_cache::get("item", $id); access::required("view", $item); access::required("edit", $item); if ($item->is_album()) { $form = album::get_edit_form($item); } else { $form = photo::get_edit_form($item); } print $form; }
/** * Handle any business logic necessary to create or modify an item. * @see ORM::save() * * @return ORM Item_Model */ public function save() { $significant_changes = $this->changed; unset($significant_changes["view_count"]); unset($significant_changes["relative_url_cache"]); unset($significant_changes["relative_path_cache"]); if (!empty($this->changed) && $significant_changes || isset($this->data_file)) { $this->updated = time(); if (!$this->loaded()) { // Create a new item. module::event("item_before_create", $this); // Set a weight if it's missing. We don't do this in the constructor because it's not a // simple assignment. if (empty($this->weight)) { $this->weight = item::get_max_weight(); } // Make an url friendly slug from the name, if necessary if (empty($this->slug)) { $this->slug = item::convert_filename_to_slug(pathinfo($this->name, PATHINFO_FILENAME)); // If the filename is all invalid characters, then the slug may be empty here. Pick a // random value. if (empty($this->slug)) { $this->slug = (string) rand(1000, 9999); } } // Get the width, height and mime type from our data file for photos and movies. if ($this->is_photo() || $this->is_movie()) { if ($this->is_photo()) { list($this->width, $this->height, $this->mime_type, $extension) = photo::get_file_metadata($this->data_file); } else { if ($this->is_movie()) { list($this->width, $this->height, $this->mime_type, $extension) = movie::get_file_metadata($this->data_file); } } // Force an extension onto the name if necessary $pi = pathinfo($this->data_file); if (empty($pi["extension"])) { $this->name = "{$this->name}.{$extension}"; } } $this->_randomize_name_or_slug_on_conflict(); parent::save(); // Build our url caches, then save again. We have to do this after it's already been // saved once because we use only information from the database to build the paths. If we // could depend on a save happening later we could defer this 2nd save. $this->_build_relative_caches(); parent::save(); // Take any actions that we can only do once all our paths are set correctly after saving. switch ($this->type) { case "album": mkdir($this->file_path()); mkdir(dirname($this->thumb_path())); mkdir(dirname($this->resize_path())); break; case "photo": case "movie": // The thumb or resize may already exist in the case where a movie and a photo generate // a thumbnail of the same name (eg, foo.flv movie and foo.jpg photo will generate // foo.jpg thumbnail). If that happens, randomize and save again. if (file_exists($this->resize_path()) || file_exists($this->thumb_path())) { $pi = pathinfo($this->name); $this->name = $pi["filename"] . "-" . random::int() . "." . $pi["extension"]; parent::save(); } copy($this->data_file, $this->file_path()); break; } // This will almost definitely trigger another save, so put it at the end so that we're // tail recursive. Null out the data file variable first, otherwise the next save will // trigger an item_updated_data_file event. $this->data_file = null; module::event("item_created", $this); } else { // Update an existing item module::event("item_before_update", $item); // If any significant fields have changed, load up a copy of the original item and // keep it around. $original = ORM::factory("item", $this->id); // Preserve the extension of the data file. Many helpers, (e.g. ImageMagick), assume // the MIME type from the extension. So when we adopt the new data file, it's important // to adopt the new extension. That ensures that the item's extension is always // appropriate for its data. We don't try to preserve the name of the data file, though, // because the name is typically a temporary randomly-generated name. if (isset($this->data_file)) { $extension = pathinfo($this->data_file, PATHINFO_EXTENSION); $new_name = pathinfo($this->name, PATHINFO_FILENAME) . ".{$extension}"; if (!empty($extension) && strcmp($this->name, $new_name)) { $this->name = $new_name; } if ($this->is_photo()) { list($this->width, $this->height, $this->mime_type, $extension) = photo::get_file_metadata($this->data_file); } else { if ($this->is_movie()) { list($this->width, $this->height, $this->mime_type, $extension) = movie::get_file_metadata($this->data_file); } } } if (array_intersect($this->changed, array("parent_id", "name", "slug"))) { $original->_build_relative_caches(); $this->relative_path_cache = null; $this->relative_url_cache = null; } $this->_randomize_name_or_slug_on_conflict(); parent::save(); // Now update the filesystem and any database caches if there were significant value // changes. If anything past this point fails, then we'll have an inconsistent database // so this code should be as robust as we can make it. // Update the MPTT pointers, if necessary. We have to do this before we generate any // cached paths! if ($original->parent_id != $this->parent_id) { parent::move_to($this->parent()); } if ($original->parent_id != $this->parent_id || $original->name != $this->name) { $this->_build_relative_caches(); // If there is a data file, then we want to preserve both the old data and the new data. // (Third-party event handlers would like access to both). The old data file will be // accessible via the $original item, and the new one via $this item. But in that case, // we don't want to rename the original as below, because the old data would end up being // clobbered by the new data file. Also, the rename isn't necessary, because the new item // data is coming from the data file anyway. So we only perform the rename if there isn't // a data file. Another way to solve this would be to copy the original file rather than // conditionally rename it, but a copy would cost far more than the rename. if (!isset($this->data_file)) { @rename($original->file_path(), $this->file_path()); } // Move all of the items associated data files if ($this->is_album()) { @rename(dirname($original->resize_path()), dirname($this->resize_path())); @rename(dirname($original->thumb_path()), dirname($this->thumb_path())); } else { @rename($original->resize_path(), $this->resize_path()); @rename($original->thumb_path(), $this->thumb_path()); } if ($original->parent_id != $this->parent_id) { // This will result in 2 events since we'll still fire the item_updated event below module::event("item_moved", $this, $original->parent()); } } // Changing the name, slug or parent ripples downwards if ($this->is_album() && ($original->name != $this->name || $original->slug != $this->slug || $original->parent_id != $this->parent_id)) { db::build()->update("items")->set("relative_url_cache", null)->set("relative_path_cache", null)->where("left_ptr", ">", $this->left_ptr)->where("right_ptr", "<", $this->right_ptr)->execute(); } // Replace the data file, if requested. if ($this->data_file && ($this->is_photo() || $this->is_movie())) { copy($this->data_file, $this->file_path()); // Get the width, height and mime type from our data file for photos and movies. if ($this->is_photo()) { list($this->width, $this->height) = photo::get_file_metadata($this->file_path()); } else { if ($this->is_movie()) { list($this->width, $this->height) = movie::get_file_metadata($this->file_path()); } } $this->thumb_dirty = 1; $this->resize_dirty = 1; } module::event("item_updated", $original, $this); if ($this->data_file) { // Null out the data file variable here, otherwise this event will trigger another // save() which will think that we're doing another file move. $this->data_file = null; if ($original->file_path() != $this->file_path()) { @unlink($original->file_path()); } module::event("item_updated_data_file", $this); } } } else { if (!empty($this->changed)) { // Insignificant changes only. Don't fire events or do any special checking to try to keep // this lightweight. parent::save(); } } return $this; }
<?php session_start(); require_once $_SERVER['DOCUMENT_ROOT'] . "/common/class/photo.class.php"; $ph = new photo(); $img = $ph->getPhotoById($_GET['id'], 3); echo '<img src="' . $img . '">';
/** * @see REST_Controller::_form_edit($resource) */ public function _form_edit($photo) { access::required("view", $photo); access::required("edit", $photo); print photo::get_edit_form($photo); }
public function moved_items_inherit_new_permissions_test() { user::set_active(user::lookup_by_name("admin")); $root = ORM::factory("item", 1); $public_album = album::create($root, rand(), "public album"); $public_photo = photo::create($public_album, MODPATH . "gallery/images/gallery.png", "", ""); access::allow(group::everybody(), "view", $public_album); $root->reload(); // Account for MPTT changes $private_album = album::create($root, rand(), "private album"); access::deny(group::everybody(), "view", $private_album); $private_photo = photo::create($private_album, MODPATH . "gallery/images/gallery.png", "", ""); // Make sure that we now have a public photo and private photo. $this->assert_true(access::group_can(group::everybody(), "view", $public_photo)); $this->assert_false(access::group_can(group::everybody(), "view", $private_photo)); // Swap the photos item::move($public_photo, $private_album); $private_album->reload(); // Reload to get new MPTT pointers and cached perms. $public_album->reload(); $private_photo->reload(); $public_photo->reload(); item::move($private_photo, $public_album); $private_album->reload(); // Reload to get new MPTT pointers and cached perms. $public_album->reload(); $private_photo->reload(); $public_photo->reload(); // Make sure that the public_photo is now private, and the private_photo is now public. $this->assert_false(access::group_can(group::everybody(), "view", $public_photo)); $this->assert_true(access::group_can(group::everybody(), "view", $private_photo)); }
/** * @see REST_Controller::_form_add($parameters) */ public function _form_add($album_id) { $album = ORM::factory("item", $album_id); access::required("view", $album); access::required("add", $album); switch ($this->input->get("type")) { case "album": print album::get_add_form($album) . html::script("modules/gallery/js/albums_form_add.js"); break; case "photo": print photo::get_add_form($album); break; default: kohana::show_404(); } }
?> <?php if ($_POST) { #更新or创建账户信息 $param['phoneNum'] = $_POST['phoneNum']; $param['password'] = $_POST['password']; $param['nickname'] = $_POST['nickname']; $param['project'] = $_POST['project']; $userId = FCurl::get('user/createUserAccount', $param); if (isset($_FILES['photo']) && $_FILES['photo']['error'] == 0) { #存在上传头像文件且上传成功 $filePath = 'avatar/' . $userId . '_' . md5_file($_FILES['photo']['tmp_name']) . '.' . end(explode('.', $_FILES['photo']['name'])); #修正图片大小 require_once 'lib/photo.class.php'; $photoTool = new photo(); $photoTool->copyImageWithSize($_FILES['photo']['tmp_name'], IMG_PATH_BASE . $filePath, 120, 120); $param = array(); $param['userId'] = $userId; $param['photo'] = $filePath; FCurl::get('user/updateUserPhoto', $param); FCurl::header('user_add.php'); } } ?> <nav class="teal lighten-1" role="navigation"> <div class="nav-wrapper"> <a id="logo-container" class="dropdown-button brand-logo" href="#!" data-activates="dropdown-quan">添加用户</a> <?php require_once 'left.php';
</tr> <tr> <th valign="top"> Description:</th> <td valign="top"><?php echo $rentorhire_data['description']; ?> </td> </tr> <tr> <th valign="top"> Related photos:</th> <td><?php $photos = $rentorhire->getPhotos($_GET['id']); if ($photos) { echo "<ul style=\"list-style:none\">"; $ph = new photo(); foreach ($photos as $photo) { $img = $ph->getPhotoById($photo['photo_id'], 2); echo '<li><a href="javascript:;" onclick="loadPage(\'/ajax/display_image.php?id=' . $photo['photo_id'] . '\')"><img src="' . $img . '" border="0"></a></li>'; } echo "</ul>"; } ?> </td> </tr> </table>
/** * Process the data file info. Get its metadata and extension. * If valid, use it to sanitize the item name and update the * width, height, and mime type. */ private function _process_data_file_info() { try { if ($this->is_photo()) { list($this->width, $this->height, $this->mime_type, $extension) = photo::get_file_metadata($this->data_file); } else { if ($this->is_movie()) { list($this->width, $this->height, $this->mime_type, $extension) = movie::get_file_metadata($this->data_file); } else { // Albums don't have data files. $this->data_file = null; return; } } // Sanitize the name based on the idenified extension, but only set $this->name if different // to ensure it isn't unnecessarily marked as "changed" $name = legal_file::sanitize_filename($this->name, $extension, $this->type); if ($this->name != $name) { $this->name = $name; } // Data file valid - make sure the flag is reset to false. $this->data_file_error = false; } catch (Exception $e) { // Data file invalid - set the flag so it's reported during item validation. $this->data_file_error = true; } }