public function onSetupBuilding(SetupBuildingEvent $event) { $tes = array(); $tes["Disabled"] = "none"; if (function_exists("curl_init")) { $tes["cURL"] = "curl"; } $tes["fopen"] = "fopen"; $tes["WGet"] = "wget"; $sb = new SetupBlock("Upload"); $sb->position = 10; // Output the limits from PHP so the user has an idea of what they can set. $sb->add_int_option("upload_count", "Max uploads: "); $sb->add_label("<i>PHP Limit = " . ini_get('max_file_uploads') . "</i>"); $sb->add_shorthand_int_option("upload_size", "<br/>Max size per file: "); $sb->add_label("<i>PHP Limit = " . ini_get('upload_max_filesize') . "</i>"); $sb->add_choice_option("transload_engine", $tes, "<br/>Transload: "); $sb->add_bool_option("upload_tlsource", "<br/>Use transloaded URL as source if none is provided: "); $event->panel->add_block($sb); }
public function receive_event(Event $event) { global $config, $database, $page, $user; if (is_null($this->theme)) { $this->theme = get_theme_object($this); } // f*****g PHP "security" measures -_-;;; $free_num = @disk_free_space(realpath("./images/")); if ($free_num === FALSE) { $is_full = false; } else { $is_full = $free_num < 100 * 1024 * 1024; } if ($event instanceof InitExtEvent) { $config->set_default_int('upload_count', 3); $config->set_default_int('upload_size', '1MB'); $config->set_default_bool('upload_anon', false); $config->set_default_bool('upload_replace', true); } if ($event instanceof PostListBuildingEvent) { if ($this->can_upload($user)) { if ($is_full) { $this->theme->display_full($page); } else { $this->theme->display_block($page); } } } if ($event instanceof PageRequestEvent) { if ($event->page_matches("upload/replace")) { /* Upload & Replace Image Request */ if (!$config->get_bool("upload_replace")) { throw new UploadException("Upload Replacing Images is not enabled."); } // check if the user is an administrator and can upload files. if (!$user->is_admin()) { $this->theme->display_permission_denied($page); } else { if ($is_full) { throw new UploadException("Can not replace Image: disk nearly full"); } // Try to get the image ID $image_id = int_escape($event->get_arg(0)); if (empty($image_id)) { $image_id = isset($_POST['image_id']) ? $_POST['image_id'] : null; } if (empty($image_id)) { throw new UploadException("Can not replace Image: No valid Image ID given."); } $image_old = Image::by_id($image_id); if (is_null($image_old)) { $this->theme->display_error($page, "Image not found", "No image in the database has the ID #{$image_id}"); } if (count($_FILES) + count($_POST) > 0) { if (count($_FILES) > 1) { throw new UploadException("Can not upload more than one image for replacing."); } $source = isset($_POST['source']) ? $_POST['source'] : null; $tags = ''; // Tags aren't changed when uploading. Set to null to stop PHP warnings. if (count($_FILES)) { foreach ($_FILES as $file) { $ok = $this->try_upload($file, $tags, $source, $image_id); break; // leave the foreach loop. } } else { foreach ($_POST as $name => $value) { if (substr($name, 0, 3) == "url" && strlen($value) > 0) { $ok = $this->try_transload($value, $tags, $source, $image_id); break; // leave the foreach loop. } } } $this->theme->display_upload_status($page, $ok); } else { if (!empty($_GET['url'])) { $url = $_GET['url']; $ok = $this->try_transload($url, $tags, $url, $image_id); $this->theme->display_upload_status($page, $ok); } else { $this->theme->display_replace_page($page, $image_id); } } } // END of if admin / can_upload } else { if ($event->page_matches("upload")) { if (!$this->can_upload($user)) { $this->theme->display_permission_denied($page); } else { /* Regular Upload Image */ if (count($_FILES) + count($_POST) > 0) { $tags = Tag::explode($_POST['tags']); $source = isset($_POST['source']) ? $_POST['source'] : null; $ok = true; foreach ($_FILES as $file) { $ok = $ok & $this->try_upload($file, $tags, $source); } foreach ($_POST as $name => $value) { if (substr($name, 0, 3) == "url" && strlen($value) > 0) { $ok = $ok & $this->try_transload($value, $tags, $source); } } $this->theme->display_upload_status($page, $ok); } else { if (!empty($_GET['url'])) { $url = $_GET['url']; $tags = array('tagme'); if (!empty($_GET['tags']) && $_GET['tags'] != "null") { $tags = Tag::explode($_GET['tags']); } $ok = $this->try_transload($url, $tags, $url); $this->theme->display_upload_status($page, $ok); } else { if (!$is_full) { $this->theme->display_page($page); } } } } // END of if can_upload } } } // END of if PageRequestEvent if ($event instanceof SetupBuildingEvent) { $tes = array(); $tes["Disabled"] = "none"; if (function_exists("curl_init")) { $tes["cURL"] = "curl"; } $tes["fopen"] = "fopen"; $tes["WGet"] = "wget"; $sb = new SetupBlock("Upload"); $sb->position = 10; // Output the limits from PHP so the user has an idea of what they can set. $sb->add_label("<i>PHP's Upload Limit = " . ini_get('max_file_uploads') . "</i><br/>"); $sb->add_int_option("upload_count", "Max uploads: "); $sb->add_label("<br/><i>PHP's Max Size Upload = " . ini_get('upload_max_filesize') . "</i><br/>"); $sb->add_shorthand_int_option("upload_size", "<br/>Max size per file: "); $sb->add_bool_option("upload_anon", "<br/>Allow anonymous uploads: "); $sb->add_bool_option("upload_replace", "<br/>Allow replacing images: "); $sb->add_choice_option("transload_engine", $tes, "<br/>Transload: "); $event->panel->add_block($sb); } if ($event instanceof DataUploadEvent) { if ($is_full) { throw new UploadException("Upload failed; disk nearly full"); } if (filesize($event->tmpname) > $config->get_int('upload_size')) { $size = to_shorthand_int(filesize($event->tmpname)); $limit = to_shorthand_int($config->get_int('upload_size')); throw new UploadException("File too large ({$size} > {$limit})"); } } }
public function onSetupBuilding(SetupBuildingEvent $event) { global $config; $sb = new SetupBlock("Image Options"); $sb->position = 30; // advanced only //$sb->add_text_option("image_ilink", "Image link: "); //$sb->add_text_option("image_tlink", "<br>Thumbnail link: "); $sb->add_text_option("image_tip", "Image tooltip: "); $sb->add_choice_option("upload_collision_handler", array('Error' => 'error', 'Merge' => 'merge'), "<br>Upload collision handler: "); if (function_exists("exif_read_data")) { $sb->add_bool_option("image_show_meta", "<br>Show metadata: "); } $event->panel->add_block($sb); $thumbers = array(); $thumbers['Built-in GD'] = "gd"; $thumbers['ImageMagick'] = "convert"; $sb = new SetupBlock("Thumbnailing"); $sb->add_choice_option("thumb_engine", $thumbers, "Engine: "); $sb->add_label("<br>Size "); $sb->add_int_option("thumb_width"); $sb->add_label(" x "); $sb->add_int_option("thumb_height"); $sb->add_label(" px at "); $sb->add_int_option("thumb_quality"); $sb->add_label(" % quality "); if ($config->get_string("thumb_engine") == "convert") { $sb->add_label("<br>ImageMagick Binary: "); $sb->add_text_option("thumb_convert_path"); } if ($config->get_string("thumb_engine") == "gd") { $sb->add_shorthand_int_option("thumb_mem_limit", "<br>Max memory use: "); } $event->panel->add_block($sb); }
public function receive_event(Event $event) { global $config, $database, $page, $user; if (is_null($this->theme)) { $this->theme = get_theme_object($this); } $is_full = disk_free_space(realpath("./images/")) < 100 * 1024 * 1024; if ($event instanceof InitExtEvent) { global $config; $config->set_default_int('upload_count', 3); $config->set_default_int('upload_size', '1MB'); $config->set_default_bool('upload_anon', false); } if ($event instanceof PostListBuildingEvent) { global $user; if ($this->can_upload($user)) { if ($is_full) { $this->theme->display_full($page); } else { $this->theme->display_block($page); } } } if ($event instanceof PageRequestEvent && $event->page_matches("upload")) { if (count($_FILES) + count($_POST) > 0) { $tags = Tag::explode($_POST['tags']); $source = isset($_POST['source']) ? $_POST['source'] : null; if ($this->can_upload($user)) { $ok = true; foreach ($_FILES as $file) { $ok = $ok & $this->try_upload($file, $tags, $source); } foreach ($_POST as $name => $value) { if (substr($name, 0, 3) == "url" && strlen($value) > 0) { $ok = $ok & $this->try_transload($value, $tags, $source); } } $this->theme->display_upload_status($page, $ok); } else { $this->theme->display_permission_denied($page); } } else { if (!empty($_GET['url'])) { global $user; if ($this->can_upload($user)) { $url = $_GET['url']; $tags = array('tagme'); if (!empty($_GET['tags']) && $_GET['tags'] != "null") { $tags = Tag::explode($_GET['tags']); } $ok = $this->try_transload($url, $tags, $url); $this->theme->display_upload_status($page, $ok); } else { $this->theme->display_permission_denied($page); } } else { if (!$is_full) { $this->theme->display_page($page); } } } } if ($event instanceof SetupBuildingEvent) { $sb = new SetupBlock("Upload"); $sb->position = 10; $sb->add_int_option("upload_count", "Max uploads: "); $sb->add_shorthand_int_option("upload_size", "<br>Max size per file: "); $sb->add_bool_option("upload_anon", "<br>Allow anonymous uploads: "); $sb->add_choice_option("transload_engine", array("Disabled" => "none", "cURL" => "curl", "fopen" => "fopen", "WGet" => "wget"), "<br>Transload: "); $event->panel->add_block($sb); } if ($event instanceof DataUploadEvent) { global $config; if ($is_full) { throw new UploadException("Upload failed; disk nearly full"); } if (filesize($event->tmpname) > $config->get_int('upload_size')) { $size = to_shorthand_int(filesize($event->tmpname)); $limit = to_shorthand_int($config->get_int('upload_size')); throw new UploadException("File too large ({$size} > {$limit})"); } } }
public function onSetupBuilding($event) { $sb = new SetupBlock("Image Options"); $sb->position = 30; // advanced only //$sb->add_text_option("image_ilink", "Image link: "); //$sb->add_text_option("image_tlink", "<br>Thumbnail link: "); $sb->add_text_option("image_tip", "Image tooltip: "); $sb->add_choice_option("upload_collision_handler", array('Error' => 'error', 'Merge' => 'merge'), "<br>Upload collision handler: "); if (!in_array("OS", $_SERVER) || $_SERVER["OS"] != 'Windows_NT') { $sb->add_bool_option("image_show_meta", "<br>Show metadata: "); } $event->panel->add_block($sb); $thumbers = array(); $thumbers['Built-in GD'] = "gd"; $thumbers['ImageMagick'] = "convert"; $sb = new SetupBlock("Thumbnailing"); $sb->add_choice_option("thumb_engine", $thumbers, "Engine: "); $sb->add_label("<br>Size "); $sb->add_int_option("thumb_width"); $sb->add_label(" x "); $sb->add_int_option("thumb_height"); $sb->add_label(" px at "); $sb->add_int_option("thumb_quality"); $sb->add_label(" % quality "); $sb->add_shorthand_int_option("thumb_mem_limit", "<br>Max memory use: "); $event->panel->add_block($sb); }
public function onSetupBuilding($event) { $sb = new SetupBlock("Image Options"); $sb->position = 30; // advanced only //$sb->add_text_option("image_ilink", "Image link: "); //$sb->add_text_option("image_tlink", "<br>Thumbnail link: "); $sb->add_text_option("image_tip", "Image tooltip: "); $sb->add_choice_option("upload_collision_handler", array('Error' => 'error', 'Merge' => 'merge'), "<br>Upload collision handler: "); if (!in_array("OS", $_SERVER) || $_SERVER["OS"] != 'Windows_NT') { $sb->add_bool_option("image_show_meta", "<br>Show metadata: "); } $sb->add_bool_option("image_jquery_confirm", "<br>Confirm Delete with jQuery: "); $expires = array(); $expires['1 Minute'] = 60; $expires['1 Hour'] = 3600; $expires['1 Day'] = 86400; $expires['1 Month (31 days)'] = 2678400; //(60*60*24*31) $expires['1 Year'] = 31536000; // 365 days (60*60*24*365) $expires['Never'] = 3153600000.0; // 100 years.. $sb->add_choice_option("image_expires", $expires, "<br>Image Expiration: "); $event->panel->add_block($sb); $thumbers = array(); $thumbers['Built-in GD'] = "gd"; $thumbers['ImageMagick'] = "convert"; $sb = new SetupBlock("Thumbnailing"); $sb->add_choice_option("thumb_engine", $thumbers, "Engine: "); $sb->add_label("<br>Size "); $sb->add_int_option("thumb_width"); $sb->add_label(" x "); $sb->add_int_option("thumb_height"); $sb->add_label(" px at "); $sb->add_int_option("thumb_quality"); $sb->add_label(" % quality "); $sb->add_shorthand_int_option("thumb_mem_limit", "<br>Max memory use: "); $event->panel->add_block($sb); }