";
@@ -82,6 +105,10 @@ and of course start organising your images :-)
return $table;
}
+ /**
+ * @param Page $page
+ * @param Image[] $images
+ */
protected function display_page_header(Page $page, $images) {
global $config;
@@ -102,6 +129,10 @@ and of course start organising your images :-)
$page->set_heading($page_title);
}
+ /**
+ * @param Page $page
+ * @param Image[] $images
+ */
protected function display_page_images(Page $page, $images) {
if (count($this->search_terms) > 0) {
$query = url_escape(implode(' ', $this->search_terms));
diff --git a/ext/ipban/test.php b/ext/ipban/test.php
index 5e745a2a..ec0dfe0b 100644
--- a/ext/ipban/test.php
+++ b/ext/ipban/test.php
@@ -1,6 +1,6 @@
get_page('ip_ban/list');
$this->assert_response(403);
$this->assert_title("Permission Denied");
@@ -9,7 +9,9 @@ class IPBanTest extends ShimmiePHPUnitTestCase {
$this->get_page('ip_ban/list');
$this->assert_no_text("42.42.42.42");
- /*
+
+ $this->markTestIncomplete();
+
$this->set_field('ip', '42.42.42.42');
$this->set_field('reason', 'unit testing');
$this->set_field('end', '1 week');
@@ -18,7 +20,6 @@ class IPBanTest extends ShimmiePHPUnitTestCase {
$this->assert_text("42.42.42.42");
$this->click("Remove"); // FIXME: remove which ban? :S
$this->assert_no_text("42.42.42.42");
- */
$this->get_page('ip_ban/list?all=on'); // just test it doesn't crash for now
diff --git a/ext/link_image/test.php b/ext/link_image/test.php
index 09138953..ca8e6f9b 100644
--- a/ext/link_image/test.php
+++ b/ext/link_image/test.php
@@ -1,6 +1,6 @@
log_in_as_user();
$image_id = $this->post_image("tests/pbx_screenshot.jpg", "pie");
@@ -9,7 +9,8 @@ class LinkImageTest extends ShimmiePHPUnitTestCase {
# in there, see if it takes us to the right page
$this->get_page("post/view/$image_id");
- /*
+ $this->markTestIncomplete();
+
// FIXME
$matches = array();
preg_match("#value='(http://.*(/|%2F)post(/|%2F)view(/|%2F)[0-9]+)'#", $raw, $matches);
@@ -18,7 +19,6 @@ class LinkImageTest extends ShimmiePHPUnitTestCase {
$this->get($matches[1]);
$this->assert_title("Image $image_id: pie");
}
- */
}
}
diff --git a/ext/log_db/test.php b/ext/log_db/test.php
index 3ab326fe..042a4640 100644
--- a/ext/log_db/test.php
+++ b/ext/log_db/test.php
@@ -1,6 +1,6 @@
log_in_as_admin();
$this->get_page("log/view");
$this->get_page("log/view?module=core-image");
diff --git a/ext/mass_tagger/main.php b/ext/mass_tagger/main.php
index d65b8a46..a1806d21 100644
--- a/ext/mass_tagger/main.php
+++ b/ext/mass_tagger/main.php
@@ -16,62 +16,54 @@ class MassTagger extends Extension {
public function onPostListBuilding(PostListBuildingEvent $event) {
global $config, $page, $user;
- if( !$user->is_admin() ) return;
-
- $this->theme->display_mass_tagger( $page, $event, $config );
+ if($user->is_admin()) {
+ $this->theme->display_mass_tagger( $page, $event, $config );
+ }
}
public function onPageRequest(PageRequestEvent $event) {
- global $config, $page, $user;
- if( !$event->page_matches("mass_tagger") ) return;
- if( !$user->is_admin() ) return;
-
- if($event->get_arg(0) == "tag") $this->_apply_mass_tags( $config, $page, $user, $event );
- }
-
- private function _apply_mass_tags( $config, Page $page, $user, $event ) {
- if( !isset($_POST['ids']) or !isset($_POST['tag']) ) return;
-
- $tag = $_POST['tag'];
-
- $tag_array = explode(" ",$tag);
- $pos_tag_array = array();
- $neg_tag_array = array();
- foreach($tag_array as $new_tag) {
- if (strpos($new_tag, '-') === 0)
- $neg_tag_array[] = substr($new_tag,1);
- else
- $pos_tag_array[] = $new_tag;
- }
-
- $ids = explode( ':', $_POST['ids'] );
- $ids = array_filter ( $ids , 'is_numeric' );
-
- $images = array_map( "Image::by_id", $ids );
-
- if(isset($_POST['setadd']) &&
- $_POST['setadd'] == 'set')
- {
- foreach($images as $image) {
- $image->set_tags(Tag::explode($tag));
- }
- }
- else
- {
- foreach($images as $image) {
- if (!empty($neg_tag_array)) {
- $img_tags = array_merge($pos_tag_array, explode(" ",$image->get_tag_list()));
- $img_tags = array_diff($img_tags, $neg_tag_array);
- $image->set_tags(Tag::explode($img_tags));
- }
+ global $page, $user;
+ if($event->page_matches("mass_tagger/tag") && $user->is_admin()) {
+ if( !isset($_POST['ids']) or !isset($_POST['tag']) ) return;
+
+ $tag = $_POST['tag'];
+
+ $tag_array = explode(" ",$tag);
+ $pos_tag_array = array();
+ $neg_tag_array = array();
+ foreach($tag_array as $new_tag) {
+ if (strpos($new_tag, '-') === 0)
+ $neg_tag_array[] = substr($new_tag,1);
else
- $image->set_tags(Tag::explode($tag . " " . $image->get_tag_list()));
+ $pos_tag_array[] = $new_tag;
}
+
+ $ids = explode( ':', $_POST['ids'] );
+ $ids = array_filter ( $ids , 'is_numeric' );
+
+ $images = array_map( "Image::by_id", $ids );
+
+ if(isset($_POST['setadd']) && $_POST['setadd'] == 'set') {
+ foreach($images as $image) {
+ $image->set_tags(Tag::explode($tag));
+ }
+ }
+ else {
+ foreach($images as $image) {
+ if (!empty($neg_tag_array)) {
+ $img_tags = array_merge($pos_tag_array, explode(" ",$image->get_tag_list()));
+ $img_tags = array_diff($img_tags, $neg_tag_array);
+ $image->set_tags(Tag::explode($img_tags));
+ }
+ else
+ $image->set_tags(Tag::explode($tag . " " . $image->get_tag_list()));
+ }
+ }
+
+ $page->set_mode("redirect");
+ if(!isset($_SERVER['HTTP_REFERER'])) $_SERVER['HTTP_REFERER'] = make_link();
+ $page->set_redirect($_SERVER['HTTP_REFERER']);
}
-
- $page->set_mode("redirect");
- if(!isset($_SERVER['HTTP_REFERER'])) $_SERVER['HTTP_REFERER'] = make_link();
- $page->set_redirect($_SERVER['HTTP_REFERER']);
}
}
diff --git a/ext/not_a_tag/main.php b/ext/not_a_tag/main.php
index 777d6dbe..29f4f502 100644
--- a/ext/not_a_tag/main.php
+++ b/ext/not_a_tag/main.php
@@ -28,7 +28,10 @@ class NotATag extends Extension {
$this->scan($event->tags);
}
- private function scan(/*array*/ $tags_mixed) {
+ /**
+ * @param string[] $tags_mixed
+ */
+ private function scan($tags_mixed) {
global $database;
$tags = array();
@@ -90,6 +93,11 @@ class NotATag extends Extension {
}
}
+ /**
+ * @param int $page
+ * @param int $size
+ * @return array
+ */
public function get_untags($page, $size=100) {
global $database;
diff --git a/ext/notes/main.php b/ext/notes/main.php
index 6a66996e..15327cdf 100644
--- a/ext/notes/main.php
+++ b/ext/notes/main.php
@@ -276,8 +276,7 @@ class Notes extends Extension {
(?, ?, ?, ?, now(), ?, ?, ?, ?, ?)",
array(1, $imageID, $user_id, $_SERVER['REMOTE_ADDR'], $noteX1, $noteY1, $noteHeight, $noteWidth, $noteText));
- $result = $database->get_row("SELECT LAST_INSERT_ID() AS noteID", array());
- $noteID = $result["noteID"];
+ $noteID = $database->get_last_insert_id('notes_id_seq');
log_info("notes", "Note added {$noteID} by {$user->name}");
@@ -304,9 +303,9 @@ class Notes extends Extension {
(?, ?, now())",
array($image_id, $user_id));
- $result = $database->get_row("SELECT LAST_INSERT_ID() AS requestID", array());
+ $resultID = $database->get_last_insert_id('note_request_id_seq');
- log_info("notes", "Note requested {$result["requestID"]} by {$user->name}");
+ log_info("notes", "Note requested {$requestID} by {$user->name}");
}
diff --git a/ext/numeric_score/main.php b/ext/numeric_score/main.php
index 5954afd5..9286e7e2 100644
--- a/ext/numeric_score/main.php
+++ b/ext/numeric_score/main.php
@@ -13,7 +13,12 @@
class NumericScoreSetEvent extends Event {
var $image_id, $user, $score;
- public function __construct(/*int*/ $image_id, User $user, /*int*/ $score) {
+ /**
+ * @param int $image_id
+ * @param User $user
+ * @param int $score
+ */
+ public function __construct($image_id, User $user, $score) {
$this->image_id = $image_id;
$this->user = $user;
$this->score = $score;
@@ -102,15 +107,15 @@ class NumericScore extends Extension {
if(!empty($_GET['day'])){
$D = (int) $_GET['day'];
- if($D >= 1 && $D <= 31) $day = $D;
+ $day = clamp($D, 1, 31);
}
if(!empty($_GET['month'])){
$M = (int) $_GET['month'];
- if($M >= 1 && $M <= 12) $month = $M;
+ $month = clamp($M, 1 ,12);
}
if(!empty($_GET['year'])){
$Y = (int) $_GET['year'];
- if($Y >= 1970 && $Y < 2100) $year = $Y;
+ $year = clamp($Y, 1970, 2100);
}
$totaldate = $year."/".$month."/".$day;
@@ -168,7 +173,10 @@ class NumericScore extends Extension {
$this->delete_votes_by($event->id);
}
- public function delete_votes_by(/*int*/ $user_id) {
+ /**
+ * @param int $user_id
+ */
+ public function delete_votes_by($user_id) {
global $database;
$image_ids = $database->get_col("SELECT image_id FROM numeric_score_votes WHERE user_id=?", array($user_id));
@@ -239,9 +247,9 @@ class NumericScore extends Extension {
"images.id in (SELECT image_id FROM numeric_score_votes WHERE user_id=:ns_user_id AND score=-1)",
array("ns_user_id"=>$iid)));
}
- else if(preg_match("/^order[=|:](numeric_)?(score)[_]?(desc|asc)?$/i", $event->term, $matches)){
+ else if(preg_match("/^order[=|:](?:numeric_)?(score)(?:_(desc|asc))?$/i", $event->term, $matches)){
$default_order_for_column = "DESC";
- $sort = isset($matches[3]) ? strtoupper($matches[3]) : $default_order_for_column;
+ $sort = isset($matches[2]) ? strtoupper($matches[2]) : $default_order_for_column;
Image::$order_sql = "images.numeric_score $sort";
$event->add_querylet(new Querylet("1=1")); //small hack to avoid metatag being treated as normal tag
}
@@ -250,7 +258,7 @@ class NumericScore extends Extension {
public function onTagTermParse(TagTermParseEvent $event) {
$matches = array();
- if(preg_match("/^vote[=|:](up|down|remove)$/", $event->term, $matches)) {
+ if(preg_match("/^vote[=|:](up|down|remove)$/", $event->term, $matches) && $event->parse) {
global $user;
$score = ($matches[1] == "up" ? 1 : ($matches[1] == "down" ? -1 : 0));
if(!$user->is_anonymous()) {
@@ -290,7 +298,7 @@ class NumericScore extends Extension {
* @param int $user_id
* @param int $score
*/
- private function add_vote(/*int*/ $image_id, /*int*/ $user_id, /*int*/ $score) {
+ private function add_vote($image_id, $user_id, $score) {
global $database;
$database->execute(
"DELETE FROM numeric_score_votes WHERE image_id=:imageid AND user_id=:userid",
diff --git a/ext/numeric_score/test.php b/ext/numeric_score/test.php
index f2a9807b..f492acdb 100644
--- a/ext/numeric_score/test.php
+++ b/ext/numeric_score/test.php
@@ -1,6 +1,6 @@
log_in_as_user();
$image_id = $this->post_image("tests/pbx_screenshot.jpg", "pbx");
$this->get_page("post/view/$image_id");
diff --git a/ext/oekaki/test.php b/ext/oekaki/test.php
index 8c59d263..1061595c 100644
--- a/ext/oekaki/test.php
+++ b/ext/oekaki/test.php
@@ -1,6 +1,6 @@
log_in_as_user();
$this->get_page("oekaki/create");
}
diff --git a/ext/ouroboros_api/main.php b/ext/ouroboros_api/main.php
index 674b3da8..69a98433 100644
--- a/ext/ouroboros_api/main.php
+++ b/ext/ouroboros_api/main.php
@@ -208,7 +208,7 @@ class _SafeOuroborosImage
// meta
$this->change = intval($img->id); //DaFug is this even supposed to do? ChangeID?
// Should be JSON specific, just strip this when converting to XML
- $this->created_at = array('n' => 123456789, 's' => $img->posted_timestamp, 'json_class' => 'Time');
+ $this->created_at = array('n' => 123456789, 's' => strtotime($img->posted), 'json_class' => 'Time');
$this->id = intval($img->id);
$this->parent_id = null;
if (defined('ENABLED_EXTS')) {
diff --git a/ext/pm/test.php b/ext/pm/test.php
index 20aab33b..df065139 100644
--- a/ext/pm/test.php
+++ b/ext/pm/test.php
@@ -1,6 +1,6 @@
log_in_as_admin();
$this->get_page("user/test");
@@ -31,7 +31,7 @@ class PrivMsgTest extends ShimmiePHPUnitTestCase {
$this->log_out();
}
- function testAdminAccess() {
+ public function testAdminAccess() {
$this->log_in_as_admin();
$this->get_page("user/test");
diff --git a/ext/pools/main.php b/ext/pools/main.php
index aeb01996..4788de9e 100644
--- a/ext/pools/main.php
+++ b/ext/pools/main.php
@@ -252,19 +252,21 @@ class Pools extends Extension {
* When displaying an image, optionally list all the pools that the
* image is currently a member of on a side panel, as well as a link
* to the Next image in the pool.
+ *
+ * @var DisplayingImageEvent $event
*/
public function onDisplayingImage(DisplayingImageEvent $event) {
global $config;
if($config->get_bool("poolsInfoOnViewImage")) {
$imageID = $event->image->id;
- $poolsIDs = $this->get_pool_id($imageID);
+ $poolsIDs = $this->get_pool_ids($imageID);
$show_nav = $config->get_bool("poolsShowNavLinks", false);
$navInfo = array();
foreach($poolsIDs as $poolID) {
- $pool = $this->get_single_pool($poolID['pool_id']);
+ $pool = $this->get_single_pool($poolID);
$navInfo[$pool['id']] = array();
$navInfo[$pool['id']]['info'] = $pool;
@@ -374,16 +376,10 @@ class Pools extends Extension {
private function list_pools(Page $page, /*int*/ $pageNumber) {
global $config, $database;
- if(is_null($pageNumber) || !is_numeric($pageNumber))
- $pageNumber = 0;
- else if ($pageNumber <= 0)
- $pageNumber = 0;
- else
- $pageNumber--;
+ $pageNumber = clamp($pageNumber, 1, null) - 1;
$poolsPerPage = $config->get_int("poolsListsPerPage");
-
$order_by = "";
$order = $page->get_cookie("ui-order-pool");
if($order == "created" || is_null($order)){
@@ -397,15 +393,14 @@ class Pools extends Extension {
}
$pools = $database->get_all("
- SELECT p.id, p.user_id, p.public, p.title, p.description,
- p.posts, u.name as user_name
- FROM pools AS p
- INNER JOIN users AS u
- ON p.user_id = u.id
- $order_by
- LIMIT :l OFFSET :o
- ", array("l"=>$poolsPerPage, "o"=>$pageNumber * $poolsPerPage)
- );
+ SELECT p.id, p.user_id, p.public, p.title, p.description,
+ p.posts, u.name as user_name
+ FROM pools AS p
+ INNER JOIN users AS u
+ ON p.user_id = u.id
+ $order_by
+ LIMIT :l OFFSET :o
+ ", array("l"=>$poolsPerPage, "o"=>$pageNumber * $poolsPerPage));
$totalPages = ceil($database->get_one("SELECT COUNT(*) FROM pools") / $poolsPerPage);
@@ -416,7 +411,7 @@ class Pools extends Extension {
/**
* HERE WE CREATE A NEW POOL
*
- * @return mixed
+ * @return int
* @throws PoolCreationException
*/
private function add_pool() {
@@ -438,12 +433,9 @@ class Pools extends Extension {
VALUES (:uid, :public, :title, :desc, now())",
array("uid"=>$user->id, "public"=>$public, "title"=>$_POST["title"], "desc"=>$_POST["description"]));
- $result = array();
- $result['poolID'] = $database->get_last_insert_id('pools_id_seq');
-
- log_info("pools", "Pool {$result["poolID"]} created by {$user->name}");
-
- return $result["poolID"];
+ $poolID = $database->get_last_insert_id('pools_id_seq');
+ log_info("pools", "Pool {$poolID} created by {$user->name}");
+ return $poolID;
}
/**
@@ -482,11 +474,11 @@ class Pools extends Extension {
/**
* Get all of the pool IDs that an image is in, given an image ID.
* @param int $imageID Integer ID for the image
- * @return array
+ * @return int[]
*/
- private function get_pool_id(/*int*/ $imageID) {
+ private function get_pool_ids(/*int*/ $imageID) {
global $database;
- return $database->get_all("SELECT pool_id FROM pool_images WHERE image_id=:iid", array("iid"=>$imageID));
+ return $database->get_col("SELECT pool_id FROM pool_images WHERE image_id=:iid", array("iid"=>$imageID));
}
/**
diff --git a/ext/pools/test.php b/ext/pools/test.php
index 81e9d63c..0a3cc265 100644
--- a/ext/pools/test.php
+++ b/ext/pools/test.php
@@ -1,6 +1,6 @@
get_page('pool/list');
$this->assert_title("Pools");
diff --git a/ext/random_image/test.php b/ext/random_image/test.php
index 0af4e906..ca4031c3 100644
--- a/ext/random_image/test.php
+++ b/ext/random_image/test.php
@@ -1,6 +1,6 @@
log_in_as_user();
$image_id = $this->post_image("tests/pbx_screenshot.jpg", "test");
$this->log_out();
@@ -15,7 +15,7 @@ class RandomTest extends ShimmiePHPUnitTestCase {
# FIXME: assert($raw == file(blah.jpg))
}
- function testPostListBlock() {
+ public function testPostListBlock() {
$this->log_in_as_admin();
$this->get_page("setup");
diff --git a/ext/rating/test.php b/ext/rating/test.php
index 6a0ac913..87d5e1f3 100644
--- a/ext/rating/test.php
+++ b/ext/rating/test.php
@@ -1,6 +1,6 @@
log_in_as_user();
$image_id = $this->post_image("tests/pbx_screenshot.jpg", "pbx");
diff --git a/ext/regen_thumb/test.php b/ext/regen_thumb/test.php
index 8e8f47b8..7deb66df 100644
--- a/ext/regen_thumb/test.php
+++ b/ext/regen_thumb/test.php
@@ -1,6 +1,6 @@
log_in_as_admin();
$image_id = $this->post_image("tests/pbx_screenshot.jpg", "pbx computer screenshot");
$this->get_page("post/view/$image_id");
diff --git a/ext/relatationships/main.php b/ext/relatationships/main.php
index 6cd1a7b0..8ecc6991 100644
--- a/ext/relatationships/main.php
+++ b/ext/relatationships/main.php
@@ -58,7 +58,7 @@ class Relationships extends Extension {
public function onTagTermParse(TagTermParseEvent $event) {
$matches = array();
- if(preg_match("/^parent[=|:]([0-9]+|none)$/", $event->term, $matches)) {
+ if(preg_match("/^parent[=|:]([0-9]+|none)$/", $event->term, $matches) && $event->parse) {
$parentID = $matches[1];
if($parentID == "none" || $parentID == "0"){
@@ -67,7 +67,7 @@ class Relationships extends Extension {
$this->set_parent($event->id, $parentID);
}
}
- else if(preg_match("/^child[=|:]([0-9]+)$/", $event->term, $matches)) {
+ else if(preg_match("/^child[=|:]([0-9]+)$/", $event->term, $matches) && $event->parse) {
$childID = $matches[1];
$this->set_child($event->id, $childID);
diff --git a/ext/report_image/main.php b/ext/report_image/main.php
index ee6a84ae..c64b1e63 100644
--- a/ext/report_image/main.php
+++ b/ext/report_image/main.php
@@ -141,7 +141,10 @@ class ReportImage extends Extension {
$this->delete_reports_by($event->id);
}
- public function delete_reports_by(/*int*/ $user_id) {
+ /**
+ * @param int $user_id
+ */
+ public function delete_reports_by($user_id) {
global $database;
$database->execute("DELETE FROM image_reports WHERE reporter_id=?", array($user_id));
$database->cache->delete("image-report-count");
@@ -165,7 +168,7 @@ class ReportImage extends Extension {
/**
* @param Image $image
- * @return array
+ * @return string[]
*/
public function get_reporters(Image $image) {
global $database;
@@ -206,7 +209,7 @@ class ReportImage extends Extension {
}
/**
- * @return mixed
+ * @return int
*/
public function count_reported_images() {
global $database;
@@ -220,13 +223,3 @@ class ReportImage extends Extension {
return $count;
}
}
-// ===== Changelog =====
-// * Version 0.3a / 0.3a_rc - 11/06/07 - I can no longer use the same theme.php file for both SVN and RCx. Sorry.
-// * Same deal with theme.php as it is with main.php
-// * Version 0.3 / 0.3_rc - 11/06/07 - Added the option to display thumbnails, moved the reported image list to it's
-// own page, and checked to make sure the user is an admin before letting them delete / view reported images.
-// * Version 0.2c_rc2 - 10/27/07 - Now (really!) supports Shimmie2 RC2!
-// * Version 0.2b - 10/27/07 - Now supports Shimmie2 RC2!
-// * Version 0.2a - 10/24/07 - Fixed some SQL issues. I will make sure to test before commiting :)
-// * Version 0.2 - 10/24/07 - First public release.
-
diff --git a/ext/report_image/test.php b/ext/report_image/test.php
index 8edbf66f..3af10913 100644
--- a/ext/report_image/test.php
+++ b/ext/report_image/test.php
@@ -1,6 +1,6 @@
log_in_as_user();
$image_id = $this->post_image("tests/pbx_screenshot.jpg", "pbx computer screenshot");
$this->get_page("post/view/$image_id");
diff --git a/ext/res_limit/test.php b/ext/res_limit/test.php
index 0ed418c9..50260a8b 100644
--- a/ext/res_limit/test.php
+++ b/ext/res_limit/test.php
@@ -1,6 +1,6 @@
set_int("upload_min_height", 0);
$config->set_int("upload_min_width", 0);
@@ -16,7 +16,7 @@ class ResLimitTest extends ShimmiePHPUnitTestCase {
$this->assert_no_text("ratio");
}
- function testResLimitSmall() {
+ public function testResLimitSmall() {
global $config;
$config->set_int("upload_min_height", 900);
$config->set_int("upload_min_width", 900);
@@ -33,7 +33,7 @@ class ResLimitTest extends ShimmiePHPUnitTestCase {
}
}
- function testResLimitLarge() {
+ public function testResLimitLarge() {
global $config;
$config->set_int("upload_min_height", 0);
$config->set_int("upload_min_width", 0);
@@ -50,7 +50,7 @@ class ResLimitTest extends ShimmiePHPUnitTestCase {
}
- function testResLimitRatio() {
+ public function testResLimitRatio() {
global $config;
$config->set_int("upload_min_height", -1);
$config->set_int("upload_min_width", -1);
diff --git a/ext/resize/main.php b/ext/resize/main.php
index acfa14b0..02d7bf96 100644
--- a/ext/resize/main.php
+++ b/ext/resize/main.php
@@ -75,12 +75,12 @@ class ResizeImage extends Extension {
$isanigif = 0;
if($image_obj->ext == "gif"){
$image_filename = warehouse_path("images", $image_obj->hash);
- if(!($fh = @fopen($image_filename, 'rb'))){ //check if gif is animated (via http://www.php.net/manual/en/function.imagecreatefromgif.php#104473)
- return false;
- }
- while(!feof($fh) && $isanigif < 2) {
- $chunk = fread($fh, 1024 * 100);
- $isanigif += preg_match_all('#\x00\x21\xF9\x04.{4}\x00(\x2C|\x21)#s', $chunk, $matches);
+ if(($fh = @fopen($image_filename, 'rb'))) {
+ //check if gif is animated (via http://www.php.net/manual/en/function.imagecreatefromgif.php#104473)
+ while(!feof($fh) && $isanigif < 2) {
+ $chunk = fread($fh, 1024 * 100);
+ $isanigif += preg_match_all('#\x00\x21\xF9\x04.{4}\x00(\x2C|\x21)#s', $chunk, $matches);
+ }
}
}
if($isanigif == 0){
@@ -180,51 +180,15 @@ class ResizeImage extends Extension {
if (($image_obj->width != $info[0] ) || ($image_obj->height != $info[1])) {
throw new ImageResizeException("The current image size does not match what is set in the database! - Aborting Resize.");
}
-
- /*
- Check Memory usage limits
-
- Old check: $memory_use = (filesize($image_filename)*2) + ($width*$height*4) + (4*1024*1024);
- New check: memory_use = width * height * (bits per channel) * channels * 2.5
-
- It didn't make sense to compute the memory usage based on the NEW size for the image. ($width*$height*4)
- We need to consider the size that we are GOING TO instead.
-
- The factor of 2.5 is simply a rough guideline.
- http://stackoverflow.com/questions/527532/reasonable-php-memory-limit-for-image-resize
- */
-
- if (isset($info['bits']) && isset($info['channels']))
- {
- $memory_use = ($info[0] * $info[1] * ($info['bits'] / 8) * $info['channels'] * 2.5) / 1024;
- } else {
- //
- // If we don't have bits and channel info from the image then assume default values
- // of 8 bits per color and 4 channels (R,G,B,A) -- ie: regular 24-bit color
- //
- $memory_use = ($info[0] * $info[1] * 1 * 4 * 2.5) / 1024;
- }
-
+
+ $memory_use = $this->calc_memory_use($info);
$memory_limit = get_memory_limit();
-
if ($memory_use > $memory_limit) {
throw new ImageResizeException("The image is too large to resize given the memory limits. ($memory_use > $memory_limit)");
}
-
- /* Calculate the new size of the image */
- if ( $height > 0 && $width > 0 ) {
- $new_height = $height;
- $new_width = $width;
- } else {
- // Scale the new image
- if ($width == 0) $factor = $height/$image_obj->height;
- elseif ($height == 0) $factor = $width/$image_obj->width;
- else $factor = min( $width / $image_obj->width, $height / $image_obj->height );
- $new_width = round( $image_obj->width * $factor );
- $new_height = round( $image_obj->height * $factor );
- }
-
+ list($new_height, $new_width) = $this->calc_new_size($image_obj, $width, $height);
+
/* Attempt to load the image */
switch ( $info[2] ) {
case IMAGETYPE_GIF: $image = imagecreatefromgif($image_filename); break;
@@ -303,19 +267,65 @@ class ResizeImage extends Extension {
send_event(new ThumbnailGenerationEvent($new_hash, $filetype));
/* Update the database */
- $database->Execute(
- "UPDATE images SET
- filename = :filename, filesize = :filesize, hash = :hash, width = :width, height = :height
- WHERE
- id = :id
- ",
- array(
- "filename"=>$new_filename, "filesize"=>$new_size, "hash"=>$new_hash,
- "width"=>$new_width, "height"=>$new_height, "id"=>$image_obj->id
- )
- );
+ $database->Execute("
+ UPDATE images SET filename = :filename, filesize = :filesize, hash = :hash, width = :width, height = :height
+ WHERE id = :id
+ ", array(
+ "filename"=>$new_filename, "filesize"=>$new_size, "hash"=>$new_hash,
+ "width"=>$new_width, "height"=>$new_height, "id"=>$image_obj->id
+ ));
log_info("resize", "Resized Image #{$image_obj->id} - New hash: {$new_hash}");
}
+
+ /**
+ * Check Memory usage limits
+ *
+ * Old check: $memory_use = (filesize($image_filename)*2) + ($width*$height*4) + (4*1024*1024);
+ * New check: memory_use = width * height * (bits per channel) * channels * 2.5
+ *
+ * It didn't make sense to compute the memory usage based on the NEW size for the image. ($width*$height*4)
+ * We need to consider the size that we are GOING TO instead.
+ *
+ * The factor of 2.5 is simply a rough guideline.
+ * http://stackoverflow.com/questions/527532/reasonable-php-memory-limit-for-image-resize
+ *
+ * @param $info
+ * @return int
+ */
+ private function calc_memory_use($info) {
+ if (isset($info['bits']) && isset($info['channels'])) {
+ return $memory_use = ($info[0] * $info[1] * ($info['bits'] / 8) * $info['channels'] * 2.5) / 1024;
+ }
+ else {
+ // If we don't have bits and channel info from the image then assume default values
+ // of 8 bits per color and 4 channels (R,G,B,A) -- ie: regular 24-bit color
+ return $memory_use = ($info[0] * $info[1] * 1 * 4 * 2.5) / 1024;
+ }
+ }
+
+ /**
+ * @param Image $image_obj
+ * @param $width
+ * @param $height
+ * @return int[]
+ */
+ private function calc_new_size(Image $image_obj, $width, $height) {
+ /* Calculate the new size of the image */
+ if ($height > 0 && $width > 0) {
+ $new_height = $height;
+ $new_width = $width;
+ return array($new_height, $new_width);
+ } else {
+ // Scale the new image
+ if ($width == 0) $factor = $height / $image_obj->height;
+ elseif ($height == 0) $factor = $width / $image_obj->width;
+ else $factor = min($width / $image_obj->width, $height / $image_obj->height);
+
+ $new_width = round($image_obj->width * $factor);
+ $new_height = round($image_obj->height * $factor);
+ return array($new_height, $new_width);
+ }
+ }
}
diff --git a/ext/rss_comments/main.php b/ext/rss_comments/main.php
index 7b3c17db..91b6a004 100644
--- a/ext/rss_comments/main.php
+++ b/ext/rss_comments/main.php
@@ -25,16 +25,16 @@ class RSS_Comments extends Extension {
$page->set_type("application/rss+xml");
$comments = $database->get_all("
- SELECT
+ SELECT
users.id as user_id, users.name as user_name,
comments.comment as comment, comments.id as comment_id,
comments.image_id as image_id, comments.owner_ip as poster_ip,
- UNIX_TIMESTAMP(posted) AS posted_timestamp
- FROM comments
- LEFT JOIN users ON comments.owner_id=users.id
- ORDER BY comments.id DESC
- LIMIT 10
- ");
+ comments.posted as posted
+ FROM comments
+ LEFT JOIN users ON comments.owner_id=users.id
+ ORDER BY comments.id DESC
+ LIMIT 10
+ ");
$data = "";
foreach($comments as $comment) {
@@ -42,7 +42,7 @@ class RSS_Comments extends Extension {
$comment_id = $comment['comment_id'];
$link = make_http(make_link("post/view/$image_id"));
$owner = html_escape($comment['user_name']);
- $posted = date(DATE_RSS, $comment['posted_timestamp']);
+ $posted = date(DATE_RSS, strtotime($comment['posted']));
$comment = html_escape($comment['comment']);
$content = html_escape("$owner: $comment");
diff --git a/ext/rss_images/main.php b/ext/rss_images/main.php
index 4fb500af..5edffddf 100644
--- a/ext/rss_images/main.php
+++ b/ext/rss_images/main.php
@@ -98,7 +98,7 @@ class RSS_Images extends Extension {
$owner = $image->get_owner();
$thumb_url = $image->get_thumb_link();
$image_url = $image->get_image_link();
- $posted = date(DATE_RSS, $image->posted_timestamp);
+ $posted = date(DATE_RSS, strtotime($image->posted));
$content = html_escape(
"
" . $this->theme->build_thumb_html($image) . "
" .
"
Uploaded by " . html_escape($owner->name) . "
"
diff --git a/ext/setup/test.php b/ext/setup/test.php
index 5af8fca9..2989472d 100644
--- a/ext/setup/test.php
+++ b/ext/setup/test.php
@@ -1,6 +1,6 @@
assert_no_content("\n");
}
- function testAuthAnon() {
+ public function testAuthAnon() {
$this->get_page('setup');
$this->assert_response(403);
$this->assert_title("Permission Denied");
}
- function testAuthUser() {
+ public function testAuthUser() {
$this->log_in_as_user();
$this->get_page('setup');
$this->assert_response(403);
$this->assert_title("Permission Denied");
}
- function testAuthAdmin() {
+ public function testAuthAdmin() {
$this->log_in_as_admin();
$this->get_page('setup');
$this->assert_title("Shimmie Setup");
$this->assert_text("General");
}
- function testAdvanced() {
+ public function testAdvanced() {
$this->log_in_as_admin();
$this->get_page('setup/advanced');
$this->assert_title("Shimmie Setup");
diff --git a/ext/shimmie_api/main.php b/ext/shimmie_api/main.php
index 17a77c7d..7fb13d47 100644
--- a/ext/shimmie_api/main.php
+++ b/ext/shimmie_api/main.php
@@ -19,8 +19,6 @@
class _SafeImage {
-#{"id":"2","height":"768","width":"1024","hash":"71cdfaabbcdad3f777e0b60418532e94","filesize":"439561","filename":"HeilAmu.png","ext":"png","owner_ip":"0.0.0.0","posted":"0000-00-00 00:00:00","source":null,"locked":"N","owner_id":"0","rating":"u","numeric_score":"0","text_score":"0","notes":"0","favorites":"0","posted_timestamp":-62169955200,"tag_array":["cat","kunimitsu"]}
-
public $id;
public $height;
public $width;
@@ -39,7 +37,7 @@ class _SafeImage {
$this->hash = $img->hash;
$this->filesize = $img->filesize;
$this->ext = $img->ext;
- $this->posted = $img->posted_timestamp;
+ $this->posted = strtotime($img->posted);
$this->source = $img->source;
$this->owner_id = $img->owner_id;
$this->tags = $img->get_tag_array();
@@ -48,52 +46,30 @@ class _SafeImage {
class ShimmieApi extends Extension {
public function onPageRequest(PageRequestEvent $event) {
- global $database, $page, $user;
+ global $page, $user;
if($event->page_matches("api/shimmie")) {
$page->set_mode("data");
$page->set_type("text/plain");
- if(!$event->page_matches("api/shimmie/get_tags") && !$event->page_matches("api/shimmie/get_image") && !$event->page_matches("api/shimmie/find_images") && !$event->page_matches("api/shimmie/get_user")){
- $page->set_mode("redirect");
- $page->set_redirect(make_link("ext_doc/shimmie_api"));
- }
if($event->page_matches("api/shimmie/get_tags")){
- $arg = $event->get_arg(0);
-
- if(!empty($arg)){
- $all = $database->get_all(
- "SELECT tag FROM tags WHERE tag LIKE ?",
- array($arg."%"));
- }
- elseif(isset($_GET['tag'])){
- $all = $database->get_all(
- "SELECT tag FROM tags WHERE tag LIKE ?",
- array($_GET['tag']."%"));
- }
- else {
- $all = $database->get_all("SELECT tag FROM tags");
- }
- $res = array();
- foreach($all as $row) {$res[] = $row["tag"];}
+ $tag = $event->get_arg(0);
+ if(empty($tag) && isset($_GET['tag'])) $tag = $_GET['tag'];
+ $res = $this->api_get_tags($tag);
$page->set_data(json_encode($res));
}
- if($event->page_matches("api/shimmie/get_image")) {
+ elseif($event->page_matches("api/shimmie/get_image")) {
$arg = $event->get_arg(0);
- if(!empty($arg)){
- $image = Image::by_id(int_escape($event->get_arg(0)));
- }
- elseif(isset($_GET['id'])){
- $image = Image::by_id(int_escape($_GET['id']));
- }
+ if(empty($arg) && isset($_GET['id'])) $arg = $_GET['id'];
+ $image = Image::by_id(int_escape($arg));
// FIXME: handle null image
$image->get_tag_array(); // tag data isn't loaded into the object until necessary
$safe_image = new _SafeImage($image);
$page->set_data(json_encode($safe_image));
}
- if($event->page_matches("api/shimmie/find_images")) {
+ elseif($event->page_matches("api/shimmie/find_images")) {
$search_terms = $event->get_search_terms();
$page_number = $event->get_page_number();
$page_size = $event->get_page_size();
@@ -106,7 +82,7 @@ class ShimmieApi extends Extension {
$page->set_data(json_encode($safe_images));
}
- if($event->page_matches("api/shimmie/get_user")) {
+ elseif($event->page_matches("api/shimmie/get_user")) {
$query = $user->id;
$type = "id";
if($event->count_args() == 1) {
@@ -121,41 +97,77 @@ class ShimmieApi extends Extension {
$type = "name";
}
- $all = $database->get_row(
- "SELECT id,name,joindate,class FROM users WHERE $type=?",
- array($query));
-
- if(!empty($all)){
- //FIXME?: For some weird reason, get_all seems to return twice. Unsetting second value to make things look nice..
- // - it returns data as eg array(0=>1234, 'id'=>1234, 1=>'bob', 'name'=>bob, ...);
- for($i=0; $i<4; $i++) unset($all[$i]);
- $all['uploadcount'] = Image::count_images(array("user_id=".$all['id']));
- $all['commentcount'] = $database->get_one(
- "SELECT COUNT(*) AS count FROM comments WHERE owner_id=:owner_id",
- array("owner_id"=>$all['id']));
-
- if(isset($_GET['recent'])){
- $recent = $database->get_all(
- "SELECT * FROM images WHERE owner_id=? ORDER BY id DESC LIMIT 0, 5",
- array($all['id']));
-
- $i = 0;
- foreach($recent as $all['recentposts'][$i]){
- unset($all['recentposts'][$i]['owner_id']); //We already know the owners id..
- unset($all['recentposts'][$i]['owner_ip']);
-
- for($x=0; $x<14; $x++) unset($all['recentposts'][$i][$x]);
- if(empty($all['recentposts'][$i]['author'])) unset($all['recentposts'][$i]['author']);
- if($all['recentposts'][$i]['notes'] > 0) $all['recentposts'][$i]['has_notes'] = "Y";
- else $all['recentposts'][$i]['has_notes'] = "N";
- unset($all['recentposts'][$i]['notes']);
- $i += 1;
- }
- }
- }
+ $all = $this->api_get_user($type, $query);
$page->set_data(json_encode($all));
}
+
+ else {
+ $page->set_mode("redirect");
+ $page->set_redirect(make_link("ext_doc/shimmie_api"));
+ }
+
}
}
+
+ /**
+ * @param string $arg
+ * @return string[]
+ */
+ private function api_get_tags($arg) {
+ global $database;
+ if (!empty($arg)) {
+ $all = $database->get_all("SELECT tag FROM tags WHERE tag LIKE ?", array($arg . "%"));
+ } else {
+ $all = $database->get_all("SELECT tag FROM tags");
+ }
+ $res = array();
+ foreach ($all as $row) {
+ $res[] = $row["tag"];
+ }
+ return $res;
+ }
+
+ /**
+ * @param $type
+ * @param $query
+ * @return array
+ */
+ private function api_get_user($type, $query) {
+ global $database;
+ $all = $database->get_row(
+ "SELECT id, name, joindate, class FROM users WHERE $type=?",
+ array($query)
+ );
+
+ if (!empty($all)) {
+ //FIXME?: For some weird reason, get_all seems to return twice. Unsetting second value to make things look nice..
+ // - it returns data as eg array(0=>1234, 'id'=>1234, 1=>'bob', 'name'=>bob, ...);
+ for ($i = 0; $i < 4; $i++) unset($all[$i]);
+ $all['uploadcount'] = Image::count_images(array("user_id=" . $all['id']));
+ $all['commentcount'] = $database->get_one(
+ "SELECT COUNT(*) AS count FROM comments WHERE owner_id=:owner_id",
+ array("owner_id" => $all['id']));
+
+ if (isset($_GET['recent'])) {
+ $recent = $database->get_all(
+ "SELECT * FROM images WHERE owner_id=? ORDER BY id DESC LIMIT 0, 5",
+ array($all['id']));
+
+ $i = 0;
+ foreach ($recent as $all['recentposts'][$i]) {
+ unset($all['recentposts'][$i]['owner_id']); //We already know the owners id..
+ unset($all['recentposts'][$i]['owner_ip']);
+
+ for ($x = 0; $x < 14; $x++) unset($all['recentposts'][$i][$x]);
+ if (empty($all['recentposts'][$i]['author'])) unset($all['recentposts'][$i]['author']);
+ if ($all['recentposts'][$i]['notes'] > 0) $all['recentposts'][$i]['has_notes'] = "Y";
+ else $all['recentposts'][$i]['has_notes'] = "N";
+ unset($all['recentposts'][$i]['notes']);
+ $i += 1;
+ }
+ }
+ }
+ return $all;
+ }
}
diff --git a/ext/shimmie_api/test.php b/ext/shimmie_api/test.php
index 4d4e210b..99327dba 100644
--- a/ext/shimmie_api/test.php
+++ b/ext/shimmie_api/test.php
@@ -1,6 +1,6 @@
log_in_as_user();
$image_id = $this->post_image("tests/pbx_screenshot.jpg", "pbx");
diff --git a/ext/site_description/test.php b/ext/site_description/test.php
index 4309a3ac..0ebd3d68 100644
--- a/ext/site_description/test.php
+++ b/ext/site_description/test.php
@@ -1,6 +1,6 @@
set_string("site_description", "A Shimmie testbed");
$this->get_page("post/list");
@@ -10,7 +10,7 @@ class SiteDescriptionTest extends ShimmiePHPUnitTestCase {
);
}
- function testSiteKeywords() {
+ public function testSiteKeywords() {
global $config, $page;
$config->set_string("site_keywords", "foo,bar,baz");
$this->get_page("post/list");
diff --git a/ext/sitemap/main.php b/ext/sitemap/main.php
index 904c36fc..9c34890a 100644
--- a/ext/sitemap/main.php
+++ b/ext/sitemap/main.php
@@ -56,7 +56,7 @@ class XMLSitemap extends Extension
$latestimages_urllist[$arrayid] = "post/view/$image->id";
}
- $this->add_sitemap_queue($latestimages_urllist, "monthly", "0.8", date("Y-m-d", $image->posted_timestamp));
+ $this->add_sitemap_queue($latestimages_urllist, "monthly", "0.8", date("Y-m-d", strtotime($image->posted)));
/* --- Display page --- */
// when sitemap is ok, display it from the file
@@ -88,7 +88,7 @@ class XMLSitemap extends Extension
// create url from image id's
$latestimages_urllist[$arrayid] = "post/view/$image->id";
}
- $this->add_sitemap_queue($latestimages_urllist, "monthly", "0.8", date("Y-m-d", $image->posted_timestamp));
+ $this->add_sitemap_queue($latestimages_urllist, "monthly", "0.8", date("Y-m-d", strtotime($image->posted)));
/* --- Add other tags --- */
$other_tags = $database->get_all("SELECT tag, count FROM tags ORDER BY `count` DESC LIMIT 21,10000000");
@@ -106,7 +106,7 @@ class XMLSitemap extends Extension
// create url from image id's
$otherimages[$arrayid] = "post/view/$image->id";
}
- $this->add_sitemap_queue($otherimages, "monthly", "0.6", date("Y-m-d", $image->posted_timestamp));
+ $this->add_sitemap_queue($otherimages, "monthly", "0.6", date("Y-m-d", strtotime($image->posted)));
/* --- Display page --- */
diff --git a/ext/sitemap/test.php b/ext/sitemap/test.php
index f98ec4ae..a2756249 100644
--- a/ext/sitemap/test.php
+++ b/ext/sitemap/test.php
@@ -1,6 +1,6 @@
get_page('sitemap.xml');
diff --git a/ext/tag_edit/main.php b/ext/tag_edit/main.php
index 1dfa025e..12be5ab7 100644
--- a/ext/tag_edit/main.php
+++ b/ext/tag_edit/main.php
@@ -95,11 +95,38 @@ class SourceSetEvent extends Event {
class TagSetEvent extends Event {
/** @var \Image */
public $image;
- var $tags;
+ public $tags;
+ public $metatags;
public function __construct(Image $image, $tags) {
- $this->image = $image;
- $this->tags = Tag::explode($tags);
+ $this->image = $image;
+
+ $this->tags = array();
+ $this->metatags = array();
+
+ //tags need to be sanitised, alias checked & have metatags removed before being passed to onTagSet
+ $tag_array = Tag::explode($tags);
+ $tag_array = array_map(array('Tag', 'sanitise'), $tag_array);
+ $tag_array = Tag::resolve_aliases($tag_array);
+
+ foreach($tag_array as $tag) {
+ if((strpos($tag, ':') === FALSE) && (strpos($tag, '=') === FALSE)) {
+ //Tag doesn't contain : or =, meaning it can't possibly be a metatag.
+ //This should help speed wise, as it avoids running every single tag through a bunch of preg_match instead.
+ array_push($this->tags, $tag);
+ continue;
+ }
+
+ $ttpe = new TagTermParseEvent($tag, $this->image->id, FALSE); //Only check for metatags, don't parse. Parsing is done after set_tags.
+ send_event($ttpe);
+
+ //seperate tags from metatags
+ if(!$ttpe->is_metatag()) {
+ array_push($this->tags, $tag);
+ }else{
+ array_push($this->metatags, $tag);
+ }
+ }
}
}
@@ -131,14 +158,17 @@ class LockSetEvent extends Event {
* Signal that a tag term needs parsing
*/
class TagTermParseEvent extends Event {
- var $term = null;
- var $id = null;
+ public $term = NULL; //tag
+ public $id = NULL; //image_id
/** @var bool */
- public $metatag = false;
+ public $metatag = FALSE;
+ /** @var bool */
+ public $parse = TRUE; //marks the tag to be parsed, and not just checked if valid metatag
- public function __construct($term, $id) {
- $this->term = $term;
- $this->id = $id;
+ public function __construct($term, $id, $parse) {
+ $this->term = $term;
+ $this->id = $id;
+ $this->parse = $parse;
}
/**
@@ -215,6 +245,7 @@ class TagEdit extends Extension {
if($user->can("edit_image_tag") && (!$event->image->is_locked() || $user->can("edit_image_lock"))) {
$event->image->set_tags($event->tags);
}
+ $event->image->parse_metatags($event->metatags, $event->image->id);
}
public function onSourceSet(SourceSetEvent $event) {
@@ -257,7 +288,7 @@ class TagEdit extends Extension {
public function onTagTermParse(TagTermParseEvent $event) {
$matches = array();
- if(preg_match("/^source[=|:](.*)$/i", $event->term, $matches)) {
+ if(preg_match("/^source[=|:](.*)$/i", $event->term, $matches) && $event->parse) {
$source = ($matches[1] !== "none" ? $matches[1] : null);
send_event(new SourceSetEvent(Image::by_id($event->id), $source));
}
diff --git a/ext/tag_edit/test.php b/ext/tag_edit/test.php
index fcc2ff09..498d29f4 100644
--- a/ext/tag_edit/test.php
+++ b/ext/tag_edit/test.php
@@ -1,6 +1,6 @@
log_in_as_user();
$image_id = $this->post_image("tests/pbx_screenshot.jpg", "pbx");
$this->get_page("post/view/$image_id");
@@ -21,7 +21,7 @@ class TagEditTest extends ShimmiePHPUnitTestCase {
$this->log_out();
}
- function testSourceEdit() {
+ public function testSourceEdit() {
$this->log_in_as_user();
$image_id = $this->post_image("tests/pbx_screenshot.jpg", "pbx");
$this->get_page("post/view/$image_id");
@@ -48,10 +48,12 @@ class TagEditTest extends ShimmiePHPUnitTestCase {
$this->log_out();
}
-/*
- * FIXME: Mass Tagger seems to be broken, and this test case always fails.
- *
- function testMassEdit() {
+ /*
+ * FIXME: Mass Tagger seems to be broken, and this test case always fails.
+ */
+ public function testMassEdit() {
+ $this->markTestIncomplete();
+
$this->log_in_as_admin();
$image_id = $this->post_image("tests/pbx_screenshot.jpg", "pbx");
@@ -71,6 +73,5 @@ class TagEditTest extends ShimmiePHPUnitTestCase {
$this->log_out();
}
-*/
}
diff --git a/ext/tag_editcloud/main.php b/ext/tag_editcloud/main.php
index 9efb6b99..aca32af7 100644
--- a/ext/tag_editcloud/main.php
+++ b/ext/tag_editcloud/main.php
@@ -22,7 +22,7 @@ class TagEditCloud extends Extension {
}
}
}
-
+
public function onInitExt(InitExtEvent $event) {
global $config;
$config->set_default_bool("tageditcloud_disable", false);
@@ -74,16 +74,14 @@ class TagEditCloud extends Extension {
$ignore_tags = Tag::explode($config->get_string("tageditcloud_ignoretags"));
- if(class_exists("TagCategories")){
+ if(ext_is_live("TagCategories")) {
$categories = $database->get_all("SELECT category, color FROM image_tag_categories");
$cat_color = array();
- foreach($categories as $row){
+ foreach($categories as $row) {
$cat_color[$row['category']] = $row['color'];
}
}
- $tag_data = null;
-
switch($sort_method) {
case 'a':
case 'p':
@@ -99,31 +97,29 @@ class TagEditCloud extends Extension {
break;
case 'r':
$relevant_tags = array_diff($image->get_tag_array(),$ignore_tags);
- if(count($relevant_tags) > 0) {
- $relevant_tags = implode(",",array_map(array($database,"escape"),$relevant_tags));
- $tag_data = $database->get_all("
- SELECT t2.tag AS tag, COUNT(image_id) AS count, FLOOR(LN(LN(COUNT(image_id) - :tag_min1 + 1)+1)*150)/200 AS scaled
- FROM image_tags it1
- JOIN image_tags it2 USING(image_id)
- JOIN tags t1 ON it1.tag_id = t1.id
- JOIN tags t2 ON it2.tag_id = t2.id
- WHERE t1.count >= :tag_min2 AND t1.tag IN($relevant_tags)
- GROUP BY t2.tag
- ORDER BY count DESC
- LIMIT :limit",
- array("tag_min1" => $tags_min, "tag_min2" => $tags_min, "limit" => $max_count));
+ if(count($relevant_tags) == 0) {
+ return null;
}
+ $relevant_tags = implode(",",array_map(array($database,"escape"),$relevant_tags));
+ $tag_data = $database->get_all("
+ SELECT t2.tag AS tag, COUNT(image_id) AS count, FLOOR(LN(LN(COUNT(image_id) - :tag_min1 + 1)+1)*150)/200 AS scaled
+ FROM image_tags it1
+ JOIN image_tags it2 USING(image_id)
+ JOIN tags t1 ON it1.tag_id = t1.id
+ JOIN tags t2 ON it2.tag_id = t2.id
+ WHERE t1.count >= :tag_min2 AND t1.tag IN($relevant_tags)
+ GROUP BY t2.tag
+ ORDER BY count DESC
+ LIMIT :limit",
+ array("tag_min1" => $tags_min, "tag_min2" => $tags_min, "limit" => $max_count));
break;
}
- if(is_null($tag_data)) {
- return null;
- }
-
+
$counter = 1;
foreach($tag_data as $row) {
$full_tag = $row['tag'];
- if(class_exists("TagCategories")){
+ if(ext_is_live("TagCategories")){
$tc = explode(':',$row['tag']);
if(isset($tc[1]) && isset($cat_color[$tc[0]])){
$h_tag = html_escape($tc[1]);
diff --git a/ext/tag_history/main.php b/ext/tag_history/main.php
index fe4b807a..eefe8cd0 100644
--- a/ext/tag_history/main.php
+++ b/ext/tag_history/main.php
@@ -329,7 +329,8 @@ class Tag_History extends Extension {
$image = Image::by_id($stored_image_id);
if ( ! $image instanceof Image) {
- throw new ImageDoesNotExist("Error: cannot find any image with the ID = ". $stored_image_id);
+ continue;
+ //throw new ImageDoesNotExist("Error: cannot find any image with the ID = ". $stored_image_id);
}
log_debug("tag_history", 'Reverting tags of Image #'.$stored_image_id.' to ['.$stored_tags.']');
diff --git a/ext/tag_history/test.php b/ext/tag_history/test.php
index a8730917..4914be06 100644
--- a/ext/tag_history/test.php
+++ b/ext/tag_history/test.php
@@ -1,12 +1,13 @@
log_in_as_admin();
$image_id = $this->post_image("tests/pbx_screenshot.jpg", "pbx");
$this->get_page("post/view/$image_id");
$this->assert_title("Image $image_id: pbx");
- /*
+ $this->markTestIncomplete();
+
// FIXME
$this->set_field("tag_edit__tags", "new");
$this->click("Set");
@@ -15,7 +16,6 @@ class TagHistoryTest extends ShimmiePHPUnitTestCase {
$this->assert_text("new (Set by demo");
$this->click("Revert To");
$this->assert_title("Image $image_id: pbx");
- */
$this->get_page("tag_history/all/1");
$this->assert_title("Global Tag History");
diff --git a/ext/tag_list/test.php b/ext/tag_list/test.php
index 4910f304..3d9b464f 100644
--- a/ext/tag_list/test.php
+++ b/ext/tag_list/test.php
@@ -2,7 +2,7 @@
class TagListTest extends ShimmiePHPUnitTestCase {
var $pages = array("map", "alphabetic", "popularity", "categories");
- function testTagList() {
+ public function testTagList() {
$this->get_page('tags/map');
$this->assert_title('Tag List');
@@ -18,7 +18,7 @@ class TagListTest extends ShimmiePHPUnitTestCase {
# FIXME: test that these show the right stuff
}
- function testMinCount() {
+ public function testMinCount() {
foreach($this->pages as $page) {
$this->get_page("tags/$page?mincount=999999");
$this->assert_title("Tag List");
diff --git a/ext/tips/test.php b/ext/tips/test.php
index bc5015a9..e95fb5d8 100644
--- a/ext/tips/test.php
+++ b/ext/tips/test.php
@@ -1,6 +1,6 @@
log_in_as_admin();
@@ -15,7 +15,7 @@ class TipsTest extends ShimmiePHPUnitTestCase {
$this->log_out();
}
- function testImageless() {
+ public function testImageless() {
$this->log_in_as_admin();
$this->get_page("tips/list");
@@ -37,7 +37,7 @@ class TipsTest extends ShimmiePHPUnitTestCase {
$this->log_out();
}
- function testImaged() {
+ public function testImaged() {
$this->log_in_as_admin();
$this->get_page("tips/list");
@@ -59,7 +59,7 @@ class TipsTest extends ShimmiePHPUnitTestCase {
$this->log_out();
}
- function testDisabled() {
+ public function testDisabled() {
$this->log_in_as_admin();
$this->get_page("tips/list");
diff --git a/ext/upload/main.php b/ext/upload/main.php
index 27862703..9c7b3fa0 100644
--- a/ext/upload/main.php
+++ b/ext/upload/main.php
@@ -234,8 +234,8 @@ class Upload extends Extension {
}
/**
- * @param string|int $id
- * @return array
+ * @param int $id
+ * @return string[]
*/
private function tags_for_upload_slot($id) {
if(isset($_POST["tags$id"])) {
diff --git a/ext/upload/test.php b/ext/upload/test.php
index 70f32368..b1044202 100644
--- a/ext/upload/test.php
+++ b/ext/upload/test.php
@@ -1,18 +1,18 @@
log_in_as_user();
$this->get_page("upload");
$this->assert_title("Upload");
}
- function testUpload() {
+ public function testUpload() {
$this->log_in_as_user();
$this->post_image("tests/pbx_screenshot.jpg", "pbx computer screenshot");
}
- function testRejectDupe() {
+ public function testRejectDupe() {
$this->post_image("tests/pbx_screenshot.jpg", "pbx computer screenshot");
try {
@@ -23,7 +23,7 @@ class UploadTest extends ShimmiePHPUnitTestCase {
}
}
- function testRejectUnknownFiletype() {
+ public function testRejectUnknownFiletype() {
try {
$this->post_image("index.php", "test");
}
@@ -32,16 +32,16 @@ class UploadTest extends ShimmiePHPUnitTestCase {
}
}
- function testRejectHuge() {
- /*
+ public function testRejectHuge() {
+ $this->markTestIncomplete();
+
// FIXME: huge.dat is rejected for other reasons; manual testing shows that this works
file_put_contents("huge.dat", file_get_contents("tests/pbx_screenshot.jpg") . str_repeat("U", 1024*1024*3));
- $image_id_4 = $this->post_image("index.php", "test");
+ $this->post_image("index.php", "test");
$this->assert_response(200);
$this->assert_title("Upload Status");
$this->assert_text("File too large");
unlink("huge.dat");
- */
}
}
diff --git a/ext/user/main.php b/ext/user/main.php
index 53981d60..32d31eaa 100644
--- a/ext/user/main.php
+++ b/ext/user/main.php
@@ -80,6 +80,9 @@ class UserCreationException extends SCoreException {}
class NullUserException extends SCoreException {}
class UserPage extends Extension {
+ /** @var UserPageTheme $theme */
+ var $theme;
+
public function onInitExt(InitExtEvent $event) {
global $config;
$config->set_default_bool("login_signup_enabled", true);
@@ -94,64 +97,22 @@ class UserPage extends Extension {
public function onPageRequest(PageRequestEvent $event) {
global $config, $page, $user;
- // user info is shown on all pages
- if($user->is_anonymous()) {
- $this->theme->display_login_block($page);
- }
- else {
- $ubbe = new UserBlockBuildingEvent();
- send_event($ubbe);
- ksort($ubbe->parts);
- $this->theme->display_user_block($page, $user, $ubbe->parts);
- }
+ $this->show_user_info();
if($event->page_matches("user_admin")) {
if($event->get_arg(0) == "login") {
if(isset($_POST['user']) && isset($_POST['pass'])) {
- $this->login($page);
+ $this->page_login($_POST['user'], $_POST['pass']);
}
else {
$this->theme->display_login_page($page);
}
}
else if($event->get_arg(0) == "recover") {
- $user = User::by_name($_POST['username']);
- if(is_null($user)) {
- $this->theme->display_error(404, "Error", "There's no user with that name");
- }
- else if(is_null($user->email)) {
- $this->theme->display_error(400, "Error", "That user has no registered email address");
- }
- else {
- // send email
- }
+ $this->page_recover($_POST['username']);
}
else if($event->get_arg(0) == "create") {
- if(!$config->get_bool("login_signup_enabled")) {
- $this->theme->display_signups_disabled($page);
- }
- else if(!isset($_POST['name'])) {
- $this->theme->display_signup_page($page);
- }
- else if($_POST['pass1'] != $_POST['pass2']) {
- $this->theme->display_error(400, "Password Mismatch", "Passwords don't match");
- }
- else {
- try {
- if(!captcha_check()) {
- throw new UserCreationException("Error in captcha");
- }
-
- $uce = new UserCreationEvent($_POST['name'], $_POST['pass1'], $_POST['email']);
- send_event($uce);
- $this->set_login_cookie($uce->username, $uce->password);
- $page->set_mode("redirect");
- $page->set_redirect(make_link("user"));
- }
- catch(UserCreationException $ex) {
- $this->theme->display_error(400, "User Creation Error", $ex->getMessage());
- }
- }
+ $this->page_create();
}
else if($event->get_arg(0) == "list") {
// select users.id,name,joindate,admin,
@@ -165,24 +126,7 @@ class UserPage extends Extension {
$this->theme->display_user_list($page, User::by_list(0), $user);
}
else if($event->get_arg(0) == "logout") {
- $page->add_cookie("session", "", time()+60*60*24*$config->get_int('login_memory'), "/");
- if(CACHE_HTTP || SPEED_HAX) {
- # to keep as few versions of content as possible,
- # make cookies all-or-nothing
- $page->add_cookie("user", "", time()+60*60*24*$config->get_int('login_memory'), "/");
- }
- log_info("user", "Logged out");
- $page->set_mode("redirect");
-
- // Try forwarding to same page on logout unless user comes from registration page
- if ($config->get_int("user_loginshowprofile",0) == 0 &&
- isset($_SERVER['HTTP_REFERER']) &&
- strstr($_SERVER['HTTP_REFERER'], "post/"))
- {
- $page->set_redirect ($_SERVER['HTTP_REFERER']);
- } else {
- $page->set_redirect(make_link());
- }
+ $this->page_logout();
}
if(!$user->check_auth_token()) {
@@ -369,8 +313,8 @@ class UserPage extends Extension {
global $user;
$matches = array();
- if(preg_match("/^(poster|user)[=|:](.*)$/i", $event->term, $matches)) {
- $duser = User::by_name($matches[2]);
+ if(preg_match("/^(?:poster|user)[=|:](.*)$/i", $event->term, $matches)) {
+ $duser = User::by_name($matches[1]);
if(!is_null($duser)) {
$user_id = $duser->id;
}
@@ -379,25 +323,33 @@ class UserPage extends Extension {
}
$event->add_querylet(new Querylet("images.owner_id = $user_id"));
}
- else if(preg_match("/^(poster|user)_id[=|:]([0-9]+)$/i", $event->term, $matches)) {
- $user_id = int_escape($matches[2]);
+ else if(preg_match("/^(?:poster|user)_id[=|:]([0-9]+)$/i", $event->term, $matches)) {
+ $user_id = int_escape($matches[1]);
$event->add_querylet(new Querylet("images.owner_id = $user_id"));
}
- else if($user->can("view_ip") && preg_match("/^(poster|user)_ip[=|:]([0-9\.]+)$/i", $event->term, $matches)) {
- $user_ip = $matches[2]; // FIXME: ip_escape?
+ else if($user->can("view_ip") && preg_match("/^(?:poster|user)_ip[=|:]([0-9\.]+)$/i", $event->term, $matches)) {
+ $user_ip = $matches[1]; // FIXME: ip_escape?
$event->add_querylet(new Querylet("images.owner_ip = '$user_ip'"));
}
}
+
+ private function show_user_info() {
+ global $user, $page;
+ // user info is shown on all pages
+ if ($user->is_anonymous()) {
+ $this->theme->display_login_block($page);
+ } else {
+ $ubbe = new UserBlockBuildingEvent();
+ send_event($ubbe);
+ ksort($ubbe->parts);
+ $this->theme->display_user_block($page, $user, $ubbe->parts);
+ }
+ }
// }}}
// Things done *with* the user {{{
- /**
- * @param Page $page
- */
- private function login(Page $page) {
- global $config, $user;
+ private function page_login($name, $pass) {
+ global $config, $user, $page;
- $name = $_POST['user'];
- $pass = $_POST['pass'];
if(empty($name) || empty($pass)) {
$this->theme->display_error(400, "Error", "Username or password left blank");
@@ -427,12 +379,72 @@ class UserPage extends Extension {
}
}
+ private function page_logout() {
+ global $page, $config;
+ $page->add_cookie("session", "", time() + 60 * 60 * 24 * $config->get_int('login_memory'), "/");
+ if (CACHE_HTTP || SPEED_HAX) {
+ # to keep as few versions of content as possible,
+ # make cookies all-or-nothing
+ $page->add_cookie("user", "", time() + 60 * 60 * 24 * $config->get_int('login_memory'), "/");
+ }
+ log_info("user", "Logged out");
+ $page->set_mode("redirect");
+
+ // Try forwarding to same page on logout unless user comes from registration page
+ if ($config->get_int("user_loginshowprofile", 0) == 0 &&
+ isset($_SERVER['HTTP_REFERER']) &&
+ strstr($_SERVER['HTTP_REFERER'], "post/")
+ ) {
+ $page->set_redirect($_SERVER['HTTP_REFERER']);
+ } else {
+ $page->set_redirect(make_link());
+ }
+ }
+
+ /**
+ * @param string $username
+ */
+ private function page_recover($username) {
+ $user = User::by_name($username);
+ if (is_null($user)) {
+ $this->theme->display_error(404, "Error", "There's no user with that name");
+ } else if (is_null($user->email)) {
+ $this->theme->display_error(400, "Error", "That user has no registered email address");
+ } else {
+ // send email
+ }
+ }
+
+ private function page_create() {
+ global $config, $page;
+ if (!$config->get_bool("login_signup_enabled")) {
+ $this->theme->display_signups_disabled($page);
+ } else if (!isset($_POST['name'])) {
+ $this->theme->display_signup_page($page);
+ } else if ($_POST['pass1'] != $_POST['pass2']) {
+ $this->theme->display_error(400, "Password Mismatch", "Passwords don't match");
+ } else {
+ try {
+ if (!captcha_check()) {
+ throw new UserCreationException("Error in captcha");
+ }
+
+ $uce = new UserCreationEvent($_POST['name'], $_POST['pass1'], $_POST['email']);
+ send_event($uce);
+ $this->set_login_cookie($uce->username, $uce->password);
+ $page->set_mode("redirect");
+ $page->set_redirect(make_link("user"));
+ } catch (UserCreationException $ex) {
+ $this->theme->display_error(400, "User Creation Error", $ex->getMessage());
+ }
+ }
+ }
+
/**
* @param UserCreationEvent $event
* @throws UserCreationException
*/
- private function check_user_creation(UserCreationEvent $event)
- {
+ private function check_user_creation(UserCreationEvent $event) {
$name = $event->username;
//$pass = $event->password;
//$email = $event->email;
@@ -450,8 +462,7 @@ class UserPage extends Extension {
}
}
- private function create_user(UserCreationEvent $event)
- {
+ private function create_user(UserCreationEvent $event) {
global $database, $user;
$email = (!empty($event->email)) ? $event->email : null;
diff --git a/ext/user/test.php b/ext/user/test.php
index 8c777c67..6e72ebc3 100644
--- a/ext/user/test.php
+++ b/ext/user/test.php
@@ -1,6 +1,6 @@
get_page('user');
$this->assert_title("Not Logged In");
$this->assert_no_text("Options");
diff --git a/ext/view/test.php b/ext/view/test.php
index ae63fa50..d4ae305c 100644
--- a/ext/view/test.php
+++ b/ext/view/test.php
@@ -1,6 +1,11 @@
log_in_as_user();
$image_id_1 = $this->post_image("tests/pbx_screenshot.jpg", "test");
$image_id_2 = $this->post_image("tests/bedroom_workshop.jpg", "test2");
@@ -9,8 +14,16 @@ class ViewTest extends ShimmiePHPUnitTestCase {
$this->get_page("post/view/$image_id_1");
$this->assert_title("Image $image_id_1: test");
+ }
+
+ public function testPrevNext() {
+ $this->markTestIncomplete();
+
+ $this->log_in_as_user();
+ $image_id_1 = $this->post_image("tests/pbx_screenshot.jpg", "test");
+ $image_id_2 = $this->post_image("tests/bedroom_workshop.jpg", "test2");
+ $image_id_3 = $this->post_image("tests/favicon.png", "test");
- /*
$this->click("Prev");
$this->assert_title("Image $image_id_2: test2");
@@ -19,22 +32,35 @@ class ViewTest extends ShimmiePHPUnitTestCase {
$this->click("Next");
$this->assert_title("Image not found");
- */
+ }
+
+ public function testView404() {
+ $this->log_in_as_user();
+ $image_id_1 = $this->post_image("tests/pbx_screenshot.jpg", "test");
+ $image_id_2 = $this->post_image("tests/bedroom_workshop.jpg", "test2");
+ $image_id_3 = $this->post_image("tests/favicon.png", "test");
+ $idp1 = $image_id_3 + 1;
$this->get_page("post/view/$idp1");
$this->assert_title('Image not found');
$this->get_page('post/view/-1');
$this->assert_title('Image not found');
+ }
- /*
- * FIXME: this assumes Nice URLs.
- *
+ public function testNextSearchResult() {
+ $this->markTestIncomplete();
+
+ $this->log_in_as_user();
+ $image_id_1 = $this->post_image("tests/pbx_screenshot.jpg", "test");
+ $image_id_2 = $this->post_image("tests/bedroom_workshop.jpg", "test2");
+ $image_id_3 = $this->post_image("tests/favicon.png", "test");
+
+ // FIXME: this assumes Nice URLs.
# note: skips image #2
$this->get_page("post/view/$image_id_1?search=test"); // FIXME: assumes niceurls
$this->click("Prev");
$this->assert_title("Image $image_id_3: test");
- */
}
}
diff --git a/ext/wiki/test.php b/ext/wiki/test.php
index 76a331ce..8d6e9bb2 100644
--- a/ext/wiki/test.php
+++ b/ext/wiki/test.php
@@ -1,13 +1,14 @@
get_page("wiki");
$this->assert_title("Index");
$this->assert_text("This is a default page");
}
-/*
- function testAccess() {
+ public function testAccess() {
+ $this->markTestIncomplete();
+
global $config;
foreach(array("anon", "user", "admin") as $user) {
foreach(array(false, true) as $allowed) {
@@ -39,7 +40,9 @@ class WikiTest extends ShimmiePHPUnitTestCase {
}
}
- function testLock() {
+ public function testLock() {
+ $this->markTestIncomplete();
+
global $config;
$config->set_bool("wiki_edit_anon", true);
$config->set_bool("wiki_edit_user", false);
@@ -73,7 +76,9 @@ class WikiTest extends ShimmiePHPUnitTestCase {
$this->log_out();
}
- function testDefault() {
+ public function testDefault() {
+ $this->markTestIncomplete();
+
$this->log_in_as_admin();
$this->get_page("wiki/wiki:default");
$this->assert_title("wiki:default");
@@ -90,7 +95,9 @@ class WikiTest extends ShimmiePHPUnitTestCase {
$this->log_out();
}
- function testRevisions() {
+ public function testRevisions() {
+ $this->markTestIncomplete();
+
$this->log_in_as_admin();
$this->get_page("wiki/test");
$this->assert_title("test");
@@ -111,6 +118,5 @@ class WikiTest extends ShimmiePHPUnitTestCase {
$this->click("Delete All");
$this->log_out();
}
-*/
}
diff --git a/ext/word_filter/test.php b/ext/word_filter/test.php
index e08d4747..4ac1748d 100644
--- a/ext/word_filter/test.php
+++ b/ext/word_filter/test.php
@@ -1,12 +1,12 @@
set_string("word_filter", "whore,nice lady\na duck,a kitten\n white ,\tspace\ninvalid");
}
- function _doThings($in, $out) {
+ public function _doThings($in, $out) {
global $user;
$this->log_in_as_user();
$image_id = $this->post_image("tests/pbx_screenshot.jpg", "pbx computer screenshot");
@@ -15,49 +15,49 @@ class WordFilterTest extends ShimmiePHPUnitTestCase {
$this->assert_text($out);
}
- function testRegular() {
+ public function testRegular() {
$this->_doThings(
"posted by a whore",
"posted by a nice lady"
);
}
- function testReplaceAll() {
+ public function testReplaceAll() {
$this->_doThings(
"a whore is a whore is a whore",
"a nice lady is a nice lady is a nice lady"
);
}
- function testMixedCase() {
+ public function testMixedCase() {
$this->_doThings(
"monkey WhorE",
"monkey nice lady"
);
}
- function testOnlyWholeWords() {
+ public function testOnlyWholeWords() {
$this->_doThings(
"my name is whoretta",
"my name is whoretta"
);
}
- function testMultipleWords() {
+ public function testMultipleWords() {
$this->_doThings(
"I would like a duck",
"I would like a kitten"
);
}
- function testWhitespace() {
+ public function testWhitespace() {
$this->_doThings(
"A colour is white",
"A colour is space"
);
}
- function testIgnoreInvalid() {
+ public function testIgnoreInvalid() {
$this->_doThings(
"The word was invalid",
"The word was invalid"
diff --git a/tests/test-deep.sh b/tests/test-deep.sh
new file mode 100755
index 00000000..8e63ef98
--- /dev/null
+++ b/tests/test-deep.sh
@@ -0,0 +1,9 @@
+#!/bin/sh
+php \
+ -d extension.dir=/usr/lib/php/extensions/no-debug-non-zts-20121212/ \
+ -d extension=xdebug.so \
+ -d xdebug.profiler_output_dir=./data/prof/ \
+ -d xdebug.profiler_enable=1 \
+ ./phpunit.phar \
+ --config tests/phpunit.xml \
+ --coverage-clover data/coverage.clover
diff --git a/themes/danbooru/themelet.class.php b/themes/danbooru/themelet.class.php
index c8026b5d..b2badbb1 100644
--- a/themes/danbooru/themelet.class.php
+++ b/themes/danbooru/themelet.class.php
@@ -30,7 +30,7 @@ class Themelet extends BaseThemelet {
* @param string $base_url
* @param string $query
* @param int|string $page
- * @param int|string $current_page
+ * @param int $current_page
* @param string $name
* @return string
*/
diff --git a/themes/danbooru2/index.theme.php b/themes/danbooru2/index.theme.php
index 090cd248..3f462887 100644
--- a/themes/danbooru2/index.theme.php
+++ b/themes/danbooru2/index.theme.php
@@ -1,6 +1,10 @@
";
diff --git a/themes/danbooru2/layout.class.php b/themes/danbooru2/layout.class.php
index ac8bfa13..4f459893 100644
--- a/themes/danbooru2/layout.class.php
+++ b/themes/danbooru2/layout.class.php
@@ -264,12 +264,18 @@ $header_html