+ ";
+ $block = new Block("Mass Tagger", $body, "left", 50);
+ $page->add_block( $block );
+ }
+}
+?>
diff --git a/contrib/mass_tagger/toggle.gif b/contrib/mass_tagger/toggle.gif
new file mode 100644
index 00000000..64c3c765
Binary files /dev/null and b/contrib/mass_tagger/toggle.gif differ
diff --git a/contrib/numeric_score/main.php b/contrib/numeric_score/main.php
old mode 100644
new mode 100755
index 963953d9..0e7d5181
--- a/contrib/numeric_score/main.php
+++ b/contrib/numeric_score/main.php
@@ -109,66 +109,67 @@ class NumericScore implements Extension {
if($event->page_matches("popular_by_day") || $event->page_matches("popular_by_month") || $event->page_matches("popular_by_year")) {
$t_images = $config->get_int("index_height") * $config->get_int("index_width");
- //TODO: Somehow make popular_by_#/2012/12/31 > popular_by_#?day=31&month=12&year=2012 (So no problems with date formats)
//TODO: Add Popular_by_week.
- $sql = "SELECT * FROM images ";
- $args = array();
-
//year
- if(int_escape($event->get_arg(0)) == 0){
+ if(empty($_GET['year'])){
$year = date("Y");
}else{
- $year = $event->get_arg(0);
+ $year = $_GET['year'];
}
//month
- if(int_escape($event->get_arg(1)) == 0 || int_escape($event->get_arg(1)) > 12){
+ if(empty($_GET['month']) || int_escape($_GET['month']) > 12){
$month = date("m");
}else{
- $month = $event->get_arg(1);
+ $month = $_GET['month'];
}
//day
- if(int_escape($event->get_arg(2)) == 0 || int_escape($event->get_arg(2)) > 31){
+ if(empty($_GET['day']) || int_escape($_GET['day']) > 31){
$day = date("d");
}else{
- $day = $event->get_arg(2);
+ $day = $_GET['day'];
}
$totaldate = $year."/".$month."/".$day;
+ $sql =
+ "SELECT * FROM images
+ WHERE EXTRACT(YEAR FROM posted) = :year
+ ";
+
+ $agrs = array("limit" => $t_images, "year" => $year);
+
if($event->page_matches("popular_by_day")){
$sql .=
- "WHERE EXTRACT(YEAR FROM posted) = :year
- AND EXTRACT(MONTH FROM posted) = :month
+ "AND EXTRACT(MONTH FROM posted) = :month
AND EXTRACT(DAY FROM posted) = :day
AND NOT numeric_score=0
";
- $dte = array($totaldate, date("F jS, Y", (strtotime($totaldate))), "Y/m/d", "day");
+ //array_push doesn't seem to like using double arrows
+ //this requires us to instead create two arrays and merge
+ $sgra = array("month" => $month, "day" => $day);
+ $args = array_merge($agrs, $sgra);
+
+ $dte = array($totaldate, date("F jS, Y", (strtotime($totaldate))), "\\y\\e\\a\\r\\=Y\\&\\m\\o\\n\\t\\h\\=m\\&\\d\\a\\y\\=d", "day");
}
if($event->page_matches("popular_by_month")){
$sql .=
- "WHERE EXTRACT(YEAR FROM posted) = :year
- AND EXTRACT(MONTH FROM posted) = :month
+ "AND EXTRACT(MONTH FROM posted) = :month
AND NOT numeric_score=0
";
+ $sgra = array("month" => $month);
+ $args = array_merge($agrs, $sgra);
+
$title = date("F Y", (strtotime($totaldate)));
- $dte = array($totaldate, $title, "Y/m", "month");
+ $dte = array($totaldate, $title, "\\y\\e\\a\\r\\=Y\\&\\m\\o\\n\\t\\h\\=m", "month");
}
if($event->page_matches("popular_by_year")){
- $sql .=
- "WHERE EXTRACT(YEAR FROM posted) = :year
- AND NOT numeric_score=0
- ";
- $dte = array($totaldate, $year, "Y", "year");
+ $sql .= "AND NOT numeric_score=0";
+ $dte = array($totaldate, $year, "\y\e\a\\r\=Y", "year");
+ $args = $agrs;
}
$sql .= " ORDER BY numeric_score DESC LIMIT :limit OFFSET 0";
//filter images by year/score != 0 > limit to max images on one page > order from highest to lowest score
- $args = array(
- "year" => $year,
- "month" => $month,
- "day" => $day,
- "limit" => $t_images
- );
$result = $database->get_all($sql, $args);
$images = array();
@@ -185,7 +186,7 @@ class NumericScore implements Extension {
}
if($event instanceof ImageDeletionEvent) {
- $database->execute("DELETE FROM numeric_score_votes WHERE image_id=?", array($event->image->id));
+ $database->execute("DELETE FROM numeric_score_votes WHERE image_id=:id", array("id" => $event->image->id));
}
if($event instanceof ParseLinkTemplateEvent) {
@@ -206,8 +207,8 @@ class NumericScore implements Extension {
"Can't find the user named ".html_escape($matches[1]));
}
$event->add_querylet(new Querylet(
- "images.id in (SELECT image_id FROM numeric_score_votes WHERE user_id=? AND score=1)",
- array($duser->id)));
+ "images.id in (SELECT image_id FROM numeric_score_votes WHERE user_id=:ns_user_id AND score=1)",
+ array("ns_user_id"=>$duser->id)));
}
if(preg_match("/^downvoted_by=(.*)$/", $event->term, $matches)) {
$duser = User::by_name($matches[1]);
@@ -216,20 +217,20 @@ class NumericScore implements Extension {
"Can't find the user named ".html_escape($matches[1]));
}
$event->add_querylet(new Querylet(
- "images.id in (SELECT image_id FROM numeric_score_votes WHERE user_id=? AND score=-1)",
- array($duser->id)));
+ "images.id in (SELECT image_id FROM numeric_score_votes WHERE user_id=:ns_user_id AND score=-1)",
+ array("ns_user_id"=>$duser->id)));
}
if(preg_match("/^upvoted_by_id=(\d+)$/", $event->term, $matches)) {
$iid = int_escape($matches[1]);
$event->add_querylet(new Querylet(
- "images.id in (SELECT image_id FROM numeric_score_votes WHERE user_id=? AND score=1)",
- array($iid)));
+ "images.id in (SELECT image_id FROM numeric_score_votes WHERE user_id=:ns_user_id AND score=1)",
+ array("ns_user_id"=>$iid)));
}
if(preg_match("/^downvoted_by_id=(\d+)$/", $event->term, $matches)) {
$iid = int_escape($matches[1]);
$event->add_querylet(new Querylet(
- "images.id in (SELECT image_id FROM numeric_score_votes WHERE user_id=? AND score=-1)",
- array($iid)));
+ "images.id in (SELECT image_id FROM numeric_score_votes WHERE user_id=:ns_user_id AND score=-1)",
+ array("ns_user_id"=>$iid)));
}
}
}
@@ -239,8 +240,8 @@ class NumericScore implements Extension {
global $config;
if($config->get_int("ext_numeric_score_version") < 1) {
- $database->Execute("ALTER TABLE images ADD COLUMN numeric_score INTEGER NOT NULL DEFAULT 0");
- $database->Execute("CREATE INDEX images__numeric_score ON images(numeric_score)");
+ $database->execute("ALTER TABLE images ADD COLUMN numeric_score INTEGER NOT NULL DEFAULT 0");
+ $database->execute("CREATE INDEX images__numeric_score ON images(numeric_score)");
$database->create_table("numeric_score_votes", "
image_id INTEGER NOT NULL,
user_id INTEGER NOT NULL,
@@ -253,24 +254,24 @@ class NumericScore implements Extension {
$config->set_int("ext_numeric_score_version", 1);
}
if($config->get_int("ext_numeric_score_version") < 2) {
- $database->Execute("CREATE INDEX numeric_score_votes__user_votes ON numeric_score_votes(user_id, score)");
+ $database->execute("CREATE INDEX numeric_score_votes__user_votes ON numeric_score_votes(user_id, score)");
$config->set_int("ext_numeric_score_version", 2);
}
}
private function add_vote($image_id, $user_id, $score) {
global $database;
- $database->Execute(
- "DELETE FROM numeric_score_votes WHERE image_id=? AND user_id=?",
- array($image_id, $user_id));
+ $database->execute(
+ "DELETE FROM numeric_score_votes WHERE image_id=:imageid AND user_id=:userid",
+ array("imageid" => $image_id, "userid" => $user_id));
if($score != 0) {
- $database->Execute(
- "INSERT INTO numeric_score_votes(image_id, user_id, score) VALUES(?, ?, ?)",
- array($image_id, $user_id, $score));
+ $database->execute(
+ "INSERT INTO numeric_score_votes(image_id, user_id, score) VALUES(:imageid, :userid, :score)",
+ array("imageid" => $image_id, "userid" => $user_id, "score" => $score));
}
$database->Execute(
- "UPDATE images SET numeric_score=(SELECT SUM(score) FROM numeric_score_votes WHERE image_id=?) WHERE id=?",
- array($image_id, $image_id));
+ "UPDATE images SET numeric_score=(SELECT SUM(score) FROM numeric_score_votes WHERE image_id=:imageid) WHERE id=:id",
+ array("imageid" => $image_id, "id" => $image_id));
}
}
?>
diff --git a/contrib/numeric_score/theme.php b/contrib/numeric_score/theme.php
index 8aa60508..f903fee9 100644
--- a/contrib/numeric_score/theme.php
+++ b/contrib/numeric_score/theme.php
@@ -67,8 +67,8 @@ class NumericScoreTheme extends Themelet {
'';
}
- $b_dte = make_link("popular_by_".$dte[3]."/".date($dte[2], (strtotime('-1 '.$dte[3], strtotime($dte[0])))));
- $f_dte = make_link("popular_by_".$dte[3]."/".date($dte[2], (strtotime('+1 '.$dte[3], strtotime($dte[0])))));
+ $b_dte = make_link("popular_by_".$dte[3]."?".date($dte[2], (strtotime('-1 '.$dte[3], strtotime($dte[0])))));
+ $f_dte = make_link("popular_by_".$dte[3]."?".date($dte[2], (strtotime('+1 '.$dte[3], strtotime($dte[0])))));
$html = '
« '.$dte[1]
.' »'
diff --git a/contrib/pm/main.php b/contrib/pm/main.php
old mode 100644
new mode 100755
index f8599057..e0190f1a
--- a/contrib/pm/main.php
+++ b/contrib/pm/main.php
@@ -93,13 +93,13 @@ class PrivMsg extends SimpleExtension {
switch($event->get_arg(0)) {
case "read":
$pm_id = int_escape($event->get_arg(1));
- $pm = $database->get_row("SELECT * FROM private_message WHERE id = ?", array($pm_id));
+ $pm = $database->get_row("SELECT * FROM private_message WHERE id = :id", array("id" => $pm_id));
if(is_null($pm)) {
$this->theme->display_error($page, "No such PM", "There is no PM #$pm_id");
}
else if(($pm["to_id"] == $user->id) || $user->is_admin()) {
$from_user = User::by_id(int_escape($pm["from_id"]));
- $database->get_row("UPDATE private_message SET is_read='Y' WHERE id = ?", array($pm_id));
+ $database->get_row("UPDATE private_message SET is_read='Y' WHERE id = :id", array("id" => $pm_id));
$this->theme->display_message($page, $from_user, $user, new PM($pm));
}
else {
@@ -109,12 +109,12 @@ class PrivMsg extends SimpleExtension {
case "delete":
if($user->check_auth_token()) {
$pm_id = int_escape($_POST["pm_id"]);
- $pm = $database->get_row("SELECT * FROM private_message WHERE id = ?", array($pm_id));
+ $pm = $database->get_row("SELECT * FROM private_message WHERE id = :id", array("id" => $pm_id));
if(is_null($pm)) {
$this->theme->display_error($page, "No such PM", "There is no PM #$pm_id");
}
else if(($pm["to_id"] == $user->id) || $user->is_admin()) {
- $database->execute("DELETE FROM private_message WHERE id = ?", array($pm_id));
+ $database->execute("DELETE FROM private_message WHERE id = :id", array("id" => $pm_id));
log_info("pm", "Deleted PM #$pm_id");
$page->set_mode("redirect");
$page->set_redirect($_SERVER["HTTP_REFERER"]);
@@ -146,9 +146,9 @@ class PrivMsg extends SimpleExtension {
INSERT INTO private_message(
from_id, from_ip, to_id,
sent_date, subject, message)
- VALUES(?, ?, ?, now(), ?, ?)",
- array($event->pm->from_id, $event->pm->from_ip,
- $event->pm->to_id, $event->pm->subject, $event->pm->message)
+ VALUES(:fromid, :fromip, :toid, now(), :subject, :message)",
+ array("fromid" => $event->pm->from_id, "fromip" => $event->pm->from_ip,
+ "toid" => $event->pm->to_id, "subject" => $event->pm->subject, "message" => $event->pm->message)
);
log_info("pm", "Sent PM to User #{$event->pm->to_id}");
}
@@ -158,11 +158,11 @@ class PrivMsg extends SimpleExtension {
global $database;
$arr = $database->get_all("
- SELECT private_message.*,user_from.name AS from_name
- FROM private_message
- JOIN users AS user_from ON user_from.id=from_id
- WHERE to_id = ?
- ", array($user->id));
+ SELECT private_message.*,user_from.name AS from_name
+ FROM private_message
+ JOIN users AS user_from ON user_from.id=from_id
+ WHERE to_id = :toid",
+ array("toid" => $user->id));
$pms = array();
foreach($arr as $pm) {
$pms[] = new PM($pm);
diff --git a/contrib/random_image/theme.php b/contrib/random_image/theme.php
index a4a7b8b7..306f984f 100644
--- a/contrib/random_image/theme.php
+++ b/contrib/random_image/theme.php
@@ -2,7 +2,26 @@
class RandomImageTheme extends Themelet {
public function display_random(Page $page, Image $image) {
- $page->add_block(new Block("Random Image", $this->build_thumb_html($image), "left", 8));
+ $page->add_block(new Block("Random Image", $this->build_random_html($image), "left", 8));
+ }
+
+ public function build_random_html(Image $image, $query=null) {
+ global $config;
+ $i_id = int_escape($image->id);
+ $h_view_link = make_link("post/view/$i_id", $query);
+ $h_thumb_link = $image->get_thumb_link();
+ $h_tip = html_escape($image->get_tooltip());
+ $tsize = get_thumbnail_size($image->width, $image->height);
+
+ return "
+
+ ";
}
}
?>
diff --git a/contrib/rating/main.php b/contrib/rating/main.php
index f6855e79..b246b14e 100644
--- a/contrib/rating/main.php
+++ b/contrib/rating/main.php
@@ -114,7 +114,8 @@ class Ratings implements Extension {
if(preg_match("/^rating=([sqeu]+)$/", $event->term, $matches)) {
$sqes = $matches[1];
$arr = array();
- for($i=0; $i_testHeaderLine($line)) {
return $line;
@@ -206,7 +206,7 @@ class HttpHeaderExpectation extends SimpleExpectation {
* @access private
*/
function _testHeaderLine($line) {
- if (count($parsed = split(':', $line, 2)) < 2) {
+ if (count($parsed = explode(':', $line, 2)) < 2) {
return false;
}
list($header, $value) = $parsed;
@@ -1538,4 +1538,4 @@ class WebTestCase extends SimpleTestCase {
return $trace->traceMethod();
}
}
-?>
\ No newline at end of file
+?>
diff --git a/contrib/tag_history/main.php b/contrib/tag_history/main.php
index 017c056d..40835fc3 100644
--- a/contrib/tag_history/main.php
+++ b/contrib/tag_history/main.php
@@ -5,72 +5,69 @@
* Description: Keep a record of tag changes, and allows you to revert changes.
*/
-class Tag_History implements Extension {
- var $theme;
-
+class Tag_History extends SimpleExtension {
// in before tags are actually set, so that "get current tags" works
public function get_priority() {return 40;}
- public function receive_event(Event $event) {
- global $config, $database, $page, $user;
- if(is_null($this->theme)) $this->theme = get_theme_object($this);
+ public function onInitExtEvent($event) {
+ global $config;
+ $config->set_default_int("history_limit", -1);
- if(($event instanceof InitExtEvent)) {
- $config->set_default_int("history_limit", -1);
-
- // shimmie is being installed so call install to create the table.
- if($config->get_int("ext_tag_history_version") < 3) {
- $this->install();
- }
+ // shimmie is being installed so call install to create the table.
+ if($config->get_int("ext_tag_history_version") < 3) {
+ $this->install();
}
-
- if(($event instanceof AdminBuildingEvent))
- {
- if(isset($_POST['revert_ip']) && $user->is_admin() && $user->check_auth_token())
- {
- $revert_ip = filter_var($_POST['revert_ip'], FILTER_VALIDATE_IP, FILTER_FLAG_NO_RES_RANGE);
-
- if ($revert_ip === false) {
- // invalid ip given.
- $this->theme->display_admin_block('Invalid IP');
+ }
+
+ public function onAdminBuildingEvent($event) {
+ global $user;
+
+ if(isset($_POST['revert_ip']) && $user->is_admin() && $user->check_auth_token()) {
+ $revert_ip = filter_var($_POST['revert_ip'], FILTER_VALIDATE_IP, FILTER_FLAG_NO_RES_RANGE);
+
+ if ($revert_ip === false) {
+ // invalid ip given.
+ $this->theme->display_admin_block('Invalid IP');
+ return;
+ }
+
+ if (isset($_POST['revert_date']) && !empty($_POST['revert_date'])) {
+ if (isValidDate($_POST['revert_date'])){
+ $revert_date = addslashes($_POST['revert_date']); // addslashes is really unnecessary since we just checked if valid, but better safe.
+ } else {
+ $this->theme->display_admin_block('Invalid Date');
return;
}
-
- if (isset($_POST['revert_date']) && !empty($_POST['revert_date'])) {
- if (isValidDate($_POST['revert_date'])){
- $revert_date = addslashes($_POST['revert_date']); // addslashes is really unnecessary since we just checked if valid, but better safe.
- } else {
- $this->theme->display_admin_block('Invalid Date');
- return;
- }
- } else {
- $revert_date = null;
- }
-
- set_time_limit(0); // reverting changes can take a long time, disable php's timelimit if possible.
-
- // Call the revert function.
- $this->process_revert_all_changes_by_ip($revert_ip, $revert_date);
- // output results
- $this->theme->display_revert_ip_results();
}
- else
- {
- $this->theme->display_admin_block(); // add a block to the admin panel
+ else {
+ $revert_date = null;
}
+
+ set_time_limit(0); // reverting changes can take a long time, disable php's timelimit if possible.
+
+ // Call the revert function.
+ $this->process_revert_all_changes_by_ip($revert_ip, $revert_date);
+ // output results
+ $this->theme->display_revert_ip_results();
}
+ else {
+ $this->theme->display_admin_block(); // add a block to the admin panel
+ }
+ }
- if (($event instanceof PageRequestEvent) && ($event->page_matches("tag_history")))
- {
- if($event->get_arg(0) == "revert")
- {
+ public function onPageRequest($event) {
+ global $config, $page, $user;
+
+ if ($event->page_matches("tag_history")) {
+ if($event->get_arg(0) == "revert") {
// this is a request to revert to a previous version of the tags
if($config->get_bool("tag_edit_anon") || !$user->is_anonymous()) {
- $this->process_revert_request($_POST['revert']);
+ if(isset($_POST['revert'])) {
+ $this->process_revert_request($_POST['revert']);
+ }
}
}
- else if($event->count_args() == 1)
- {
+ else if($event->count_args() == 1) {
// must be an attempt to view a tag history
$image_id = int_escape($event->get_arg(0));
$this->theme->display_history_page($page, $image_id, $this->get_tag_history_from_id($image_id));
@@ -79,32 +76,36 @@ class Tag_History implements Extension {
$this->theme->display_global_page($page, $this->get_global_tag_history());
}
}
-
- if(($event instanceof DisplayingImageEvent))
- {
- // handle displaying a link on the view page
- $this->theme->display_history_link($page, $event->image->id);
- }
- if(($event instanceof ImageDeletionEvent))
- {
- // handle removing of history when an image is deleted
- $this->delete_all_tag_history($event->image->id);
- }
- if(($event instanceof SetupBuildingEvent)) {
- $sb = new SetupBlock("Tag History");
- $sb->add_label("Limit to ");
- $sb->add_int_option("history_limit");
- $sb->add_label(" entires per image");
- $sb->add_label("
(-1 for unlimited)");
- $event->panel->add_block($sb);
- }
- if(($event instanceof TagSetEvent)) {
- $this->add_tag_history($event->image, $event->tags);
- }
- if($event instanceof UserBlockBuildingEvent) {
- if($user->is_admin()) {
- $event->add_link("Tag Changes", make_link("tag_history"));
- }
+ }
+
+ public function onDisplayingImage($event) {
+ global $page;
+ // handle displaying a link on the view page
+ $this->theme->display_history_link($page, $event->image->id);
+ }
+
+ public function onImageDeletion($event) {
+ // handle removing of history when an image is deleted
+ $this->delete_all_tag_history($event->image->id);
+ }
+
+ public function onSetupBuilding($event) {
+ $sb = new SetupBlock("Tag History");
+ $sb->add_label("Limit to ");
+ $sb->add_int_option("history_limit");
+ $sb->add_label(" entires per image");
+ $sb->add_label("
(-1 for unlimited)");
+ $event->panel->add_block($sb);
+ }
+
+ public function onTagSetEvent($event) {
+ $this->add_tag_history($event->image, $event->tags);
+ }
+
+ public function onUserBlockBuilding($event) {
+ global $user;
+ if($user->is_admin()) {
+ $event->add_link("Tag Changes", make_link("tag_history"));
}
}
@@ -250,6 +251,18 @@ class Tag_History implements Extension {
return ($row ? $row : array());
}
+ /* This doesn't actually get _ALL_ IPs as it limits to 1000. */
+ public function get_all_user_ips()
+ {
+ global $database;
+ $row = $database->get_all("
+ SELECT DISTINCT user_ip
+ FROM tag_histories
+ ORDER BY tag_histories.user_ip DESC
+ LIMIT 1000");
+ return ($row ? $row : array());
+ }
+
/*
* This function attempts to revert all changes by a given IP within an (optional) timeframe.
*/
diff --git a/contrib/update/main.php b/contrib/update/main.php
new file mode 100644
index 00000000..912f918a
--- /dev/null
+++ b/contrib/update/main.php
@@ -0,0 +1,178 @@
+
+ * Link: http://www.codeanimu.net
+ * License: GPLv2
+ * Description: Shimmie updater!
+ */
+class Update extends SimpleExtension {
+ public function onInitExt(Event $event) {
+ global $config;
+ $config->set_default_string("update_url", "http://nodeload.github.com/shish/shimmie2/zipball/master"); //best to avoid using https
+ $config->set_default_string("commit_hash", "");
+ }
+
+ public function onSetupBuilding($event) {
+ global $config;
+ //Would prefer to use the admin panel for this.
+ //But since the admin panel is optional...kind of stuck to using this.
+ $sb = new SetupBlock("Update");
+ $sb->position = 75;
+ $sb->add_label("Current Commit: ".$config->get_string('commit_hash'));
+ $sb->add_text_option("update_url", "
Update URL: ");
+ $sb->add_label("
Update");
+ $event->panel->add_block($sb);
+ }
+
+ public function onPageRequest(Event $event) {
+ global $config, $user;
+ if($event->page_matches("update") && $user->is_admin()) {
+ $ok = $this->update_shimmie();
+ }
+ }
+
+ private function update_shimmie() {
+ global $config, $page;
+ //This is a REALLY ugly function. (Damn my limited PHP knowledge >_<)
+ $html = "";
+ $url = $config->get_string("update_url");
+ $mfile = "master.zip";
+ if(glob("*-shimmie2*")){ //#3
+ $dir = glob("*-shimmie2*");
+ preg_match('@^([a-zA-Z0-9]+\-[0-9a-z]+\-)([^/]+)@i', $dir[0], $matches);
+ if(!empty($matches[2])){
+ $html .= "commit: ".$matches[2];
+ $commit = $matches[2];
+ mkdir("./backup");
+ $html .= "
backup folder created!";
+ $d_dir = "data/cache";
+ //This should empty the /data/cache/ folder.
+ if (is_dir($d_dir)) {
+ $objects = scandir($d_dir);
+ foreach ($objects as $object) {
+ if ($object != "." && $object != "..") {
+ if (filetype($d_dir."/".$object) == "dir") rmdir($d_dir."/".$object); else unlink($d_dir."/".$object);
+ }
+ }
+ reset($objects);
+ $html .= "
data folder emptied!";
+ }
+ copy ("./config.php", "./backup/config.php");//Although this stays the same, will keep backup just incase.
+ //FIXME: Somehow get rid of this massive rename list.
+ rename ("./core", "./backup/core");
+ rename ("./".$matches[0]."/core", "./core");
+ rename ("./lib", "./backup/lib");
+ rename ("./".$matches[0]."/lib", "./lib");
+ rename ("./themes", "./backup/themes");
+ rename ("./".$matches[0]."/themes", "./themes");
+ rename ("./.htaccess", "./backup/.htaccess");
+ rename ("./".$matches[0]."/.htaccess", "./.htaccess");
+ rename ("./doxygen.conf", "./backup/doxygen.conf");
+ rename ("./".$matches[0]."/doxygen.conf", "./doxygen.conf");
+ rename ("./index.php", "./backup/index.php");
+ rename ("./".$matches[0]."/index.php", "./index.php");
+ rename ("./install.php", "./backup/install.php");
+ rename ("./".$matches[0]."/install.php", "./install.php");
+ rename ("./ext", "./backup/ext");
+ rename ("./".$matches[0]."/ext", "./ext");
+ rename ("./contrib", "./backup/contrib");
+ rename ("./".$matches[0]."/contrib", "./contrib");
+ $html .= "
old shimmie setup has been moved to /backup/ (excluding images/thumbs)!";
+ if (is_dir($matches[0])) {
+ $objects = scandir($matches[0]);
+ foreach ($objects as $object) {
+ if ($object != "." && $object != "..") {
+ if (filetype($matches[0]."/".$object) == "dir") rmdir($matches[0]."/".$object); else unlink($matches[0]."/".$object);
+ }
+ }
+ reset($objects);
+ rmdir($matches[0]);
+ $html .= "
".$matches[0]." deleted!";
+ }
+ $html .= "
shimmie updated (although you may have gotten errors, it should have worked!";
+ $html .= "
due to the way shimmie loads extensions, all optional extensions have been disabled";
+ $config->set_string("commit_hash", $commit);
+ $html .= "
new commit_hash has been set!";
+ }else{
+ $html .= "Error! Folder does not exist!?"; //Although this should be impossible, shall have it anyway.
+ }
+ }elseif (file_exists($mfile)){ //#2
+ $zip = new ZipArchive;
+ if ($zip->open($mfile) === TRUE) {
+ $zip->extractTo('./');
+ $zip->close();
+ $html .= "extracted!";
+ $html .= "
refresh the page to continue!";
+ unlink($mfile); //Deletes master.zip
+ } else {
+ $html .= "failed!";
+ }
+ }else{ //#1
+ //Taken from the upload ext.
+ if($config->get_string("transload_engine") == "curl" && function_exists("curl_init")) {
+ $ch = curl_init($url);
+ $fp = fopen($mfile, "w");
+
+ curl_setopt($ch, CURLOPT_FILE, $fp);
+ curl_setopt($ch, CURLOPT_HEADER, 0);
+ curl_setopt($ch, CURLOPT_REFERER, $url);
+ curl_setopt($ch, CURLOPT_USERAGENT, "Shimmie-".VERSION);
+
+ curl_exec($ch);
+ curl_close($ch);
+ fclose($fp);
+ if(file_exists($mfile)){
+ $html .= "downloaded!";
+ $html .= "
refresh the page to continue!";
+ }else{
+ $html .= "download failed!";
+ $html .= "
refresh to try again!";
+ $html .= "
if you keep having this problem, you may have a problem with your transload engine!";
+ }
+ }elseif($config->get_string("transload_engine") == "wget") {
+ //this doesn't work?
+ $s_url = escapeshellarg($url);
+ system("wget $s_url --output-document=$mfile");
+ if(file_exists($mfile)){
+ $html .= "downloaded!";
+ $html .= "
refresh the page to continue!";
+ }else{
+ $html .= "download failed!";
+ $html .= "
refresh to try again!";
+ $html .= "
if you keep having this problem, you may have a problem with your transload engine!";
+ }
+ }elseif($config->get_string("transload_engine") == "fopen") {
+ $fp = @fopen($url, "r");
+ if(!$fp) {
+ return false;
+ }
+ $data = "";
+ $length = 0;
+ while(!feof($fp) && $length <= $config->get_int('upload_size')) {
+ $data .= fread($fp, 8192);
+ $length = strlen($data);
+ }
+ fclose($fp);
+
+ $fp = fopen($mfile, "w");
+ fwrite($fp, $data);
+ fclose($fp);
+ if(file_exists($mfile)){
+ $html .= "downloaded!";
+ $html .= "
refresh the page to continue!";
+ }else{
+ $html .= "download failed!";
+ $html .= "
refresh to try again!";
+ $html .= "
if you keep having this problem, you may have a problem with your transload engine!";
+ }
+ }elseif($config->get_string("transload_engine") == "none"){
+ $html .= "no transload engine set!";
+ }
+ }
+
+ $page->add_block(new Block("Update", $html));
+ }
+}
+
+?>
diff --git a/contrib/word_filter/main.php b/contrib/word_filter/main.php
index 5e4cddd2..1ce8e259 100644
--- a/contrib/word_filter/main.php
+++ b/contrib/word_filter/main.php
@@ -6,21 +6,20 @@
* Description: Simple search and replace
*/
-class WordFilter implements Extension {
+class WordFilter extends SimpleExtension {
// before emoticon filter
public function get_priority() {return 40;}
- public function receive_event(Event $event) {
- if($event instanceof TextFormattingEvent) {
- $event->formatted = $this->filter($event->formatted);
- $event->stripped = $this->filter($event->stripped);
- }
- if(($event instanceof SetupBuildingEvent)) {
- $sb = new SetupBlock("Word Filter");
- $sb->add_longtext_option("word_filter");
- $sb->add_label("
(each line should be search term and replace term, separated by a comma)");
- $event->panel->add_block($sb);
- }
+ public function onTextFormatting($event) {
+ $event->formatted = $this->filter($event->formatted);
+ $event->stripped = $this->filter($event->stripped);
+ }
+
+ public function onSetupBuilding($event) {
+ $sb = new SetupBlock("Word Filter");
+ $sb->add_longtext_option("word_filter");
+ $sb->add_label("
(each line should be search term and replace term, separated by a comma)");
+ $event->panel->add_block($sb);
}
private function filter($text) {
diff --git a/core/compat.inc.php b/core/compat.inc.php
deleted file mode 100644
index 8975f587..00000000
--- a/core/compat.inc.php
+++ /dev/null
@@ -1,95 +0,0 @@
-= 5.2.1)
-# Based on http://www.phpit.net/
-# article/creating-zip-tar-archives-dynamically-php/2/
-if(!function_exists('sys_get_temp_dir')) {
-function sys_get_temp_dir() {
- // Try to get from environment variable
- if(!empty($_ENV['TMP'])) {
- return realpath($_ENV['TMP']);
- }
- else if(!empty($_ENV['TMPDIR'])) {
- return realpath($_ENV['TMPDIR']);
- }
- else if(!empty($_ENV['TEMP'])) {
- return realpath($_ENV['TEMP']);
- }
-
- // Detect by creating a temporary file
- else {
- // Try to use system's temporary directory
- // as random name shouldn't exist
- $temp_file = tempnam(md5(uniqid(rand(), TRUE)), '');
- if($temp_file) {
- $temp_dir = realpath(dirname($temp_file));
- unlink($temp_file);
- return $temp_dir;
- }
- else {
- return FALSE;
- }
- }
-}
-}
-
-# (PHP >= 5.1)
-# from http://www.php.net/inet_pton
-if(!function_exists('inet_pton')) {
-function inet_pton($ip) {
- # ipv4
- if(strpos($ip, '.') !== FALSE) {
- $ip = pack('N',ip2long($ip));
- }
- # ipv6
- else if(strpos($ip, ':') !== FALSE) {
- $ip = explode(':', $ip);
- $res = str_pad('', (4*(8-count($ip))), '0000', STR_PAD_LEFT);
- foreach($ip as $seg) {
- $res .= str_pad($seg, 4, '0', STR_PAD_LEFT);
- }
- $ip = pack('H'.strlen($res), $res);
- }
- return $ip;
-}
-}
-
-# (PHP >= 5.1)
-# from http://www.php.net/inet_ntop
-if(!function_exists('inet_ntop')) {
-function inet_ntop($ip) {
- if (strlen($ip)==4) {
- // ipv4
- list(,$ip)=unpack('N',$ip);
- $ip=long2ip($ip);
- } elseif(strlen($ip)==16) {
- // ipv6
- $ip=bin2hex($ip);
- $ip=substr(chunk_split($ip,4,':'),0,-1);
- $ip=explode(':',$ip);
- $res='';
- foreach($ip as $seg) {
- while($seg{0}=='0') $seg=substr($seg,1);
- if ($seg!='') {
- $res.=($res==''?'':':').$seg;
- } else {
- if (strpos($res,'::')===false) {
- if (substr($res,-1)==':') continue;
- $res.=':';
- continue;
- }
- $res.=($res==''?'':':').'0';
- }
- }
- $ip=$res;
- }
- return $ip;
-}
-}
-?>
diff --git a/core/database.class.php b/core/database.class.php
index c42ce366..27805521 100644
--- a/core/database.class.php
+++ b/core/database.class.php
@@ -1,6 +1,4 @@
scoreql_to_sql($data);
$ctes = "ENGINE=InnoDB DEFAULT CHARSET='utf8'";
- return "CREATE TABLE $name ($data) $ctes";
+ return 'CREATE TABLE '.$name.' ('.$data.') '.$ctes;
}
}
class PostgreSQL extends DBEngine {
var $name = "pgsql";
+ public function init($db) {
+ $db->query("SET application_name TO 'shimmie [{$_SERVER['REMOTE_ADDR']}]';");
+ }
+
public function scoreql_to_sql($data) {
$data = str_replace("SCORE_AIPK", "SERIAL PRIMARY KEY", $data);
$data = str_replace("SCORE_INET", "INET", $data);
@@ -103,7 +105,7 @@ class PostgreSQL extends DBEngine {
public function create_table_sql($name, $data) {
$data = $this->scoreql_to_sql($data);
- return "CREATE TABLE $name ($data)";
+ return 'CREATE TABLE '.$name.' ('.$data.')';
}
}
@@ -151,14 +153,14 @@ class SQLite extends DBEngine {
$matches = array();
if(preg_match("/INDEX\s*\((.*)\)/", $bit, $matches)) {
$col = $matches[1];
- $extras .= "CREATE INDEX {$name}_{$col} on $name($col);";
+ $extras .= 'CREATE INDEX '.$name.'_'.$col.' on '.$name($col).';';
}
else {
$cols[] = $bit;
}
}
$cols_redone = implode(", ", $cols);
- return "CREATE TABLE $name ($cols_redone); $extras";
+ return 'CREATE TABLE '.$name.' ('.$cols_redone.'); '.$extras;
}
}
// }}}
@@ -183,7 +185,7 @@ class MemcacheCache implements CacheEngine {
var $memcache=null, $hits=0, $misses=0;
public function __construct($args) {
- $hp = split(":", $args);
+ $hp = explode(":", $args);
if(class_exists("Memcache")) {
$this->memcache = new Memcache;
@$this->memcache->pconnect($hp[0], $hp[1]);
@@ -286,23 +288,25 @@ class Database {
if(preg_match("/user=([^;]*)/", DATABASE_DSN, $matches)) $db_user=$matches[1];
if(preg_match("/password=([^;]*)/", DATABASE_DSN, $matches)) $db_pass=$matches[1];
- $this->db = new PDO(DATABASE_DSN, $db_user, $db_pass, array(
+ $db_params = array(
PDO::ATTR_PERSISTENT => true,
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
- ));
+ );
+ if(defined("HIPHOP")) $this->db = new PDO(DATABASE_DSN, $db_user, $db_pass);
+ else $this->db = new PDO(DATABASE_DSN, $db_user, $db_pass, $db_params);
$db_proto = $this->db->getAttribute(PDO::ATTR_DRIVER_NAME);
- if($db_proto == "mysql") {
+ if($db_proto === "mysql") {
$this->engine = new MySQL();
}
- else if($db_proto == "pgsql") {
+ else if($db_proto === "pgsql") {
$this->engine = new PostgreSQL();
}
- else if($db_proto == "sqlite") {
+ else if($db_proto === "sqlite") {
$this->engine = new SQLite();
}
else {
- die("Unknown PDO driver: $db_proto");
+ die('Unknown PDO driver: '.$db_proto);
}
$matches = array();
@@ -326,14 +330,15 @@ class Database {
*/
public function execute($query, $args=array()) {
try {
+ _count_execs($this->db, $query, $args);
$stmt = $this->db->prepare($query);
if (!array_key_exists(0, $args)) {
foreach($args as $name=>$value) {
if(is_numeric($value)) {
- $stmt->bindValue(":$name", $value, PDO::PARAM_INT);
+ $stmt->bindValue(':'.$name, $value, PDO::PARAM_INT);
}
else {
- $stmt->bindValue(":$name", $value, PDO::PARAM_STR);
+ $stmt->bindValue(':'.$name, $value, PDO::PARAM_STR);
}
}
$stmt->execute();
@@ -344,8 +349,8 @@ class Database {
return $stmt;
}
catch(PDOException $pdoe) {
- print "Message: ".$pdoe->getMessage();
- print "Error: $query";
+ print 'Message: '.$pdoe->getMessage();
+ print '
Error: '.$query;
exit;
}
}
diff --git a/core/default_config.inc.php b/core/default_config.inc.php
new file mode 100644
index 00000000..2f3003ca
--- /dev/null
+++ b/core/default_config.inc.php
@@ -0,0 +1,21 @@
+
diff --git a/core/email.class.php b/core/email.class.php
new file mode 100644
index 00000000..a3e9f555
--- /dev/null
+++ b/core/email.class.php
@@ -0,0 +1,119 @@
+to = $to;
+
+ $sub_prefix = $config->get_string("mail_sub");
+
+ if(!isset($sub_prefix)){
+ $this->subject = $subject;
+ }
+ else{
+ $this->subject = $sub_prefix." ".$subject;
+ }
+
+ $this->style = $config->get_string("mail_style");
+
+ $this->header = html_escape($header);
+ $this->header_img = $config->get_string("mail_img");
+ $this->sitename = $config->get_string("site_title");
+ $this->sitedomain = make_http(make_link(""));
+ $this->siteemail = $config->get_string("site_email");
+ $this->date = date("F j, Y");
+ $this->body = $body;
+ $this->footer = $config->get_string("mail_fot");
+ }
+
+ public function send() {
+ $headers = "From: ".$this->sitename." <".$this->siteemail.">\r\n";
+ $headers .= "Reply-To: ".$this->siteemail."\r\n";
+ $headers .= "X-Mailer: PHP/" . phpversion(). "\r\n";
+ $headers .= "errors-to: ".$this->siteemail."\r\n";
+ $headers .= "Date: " . date(DATE_RFC2822);
+ $headers .= 'MIME-Version: 1.0' . "\r\n";
+ $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
+ $message = '
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ |
+
+
+
+
+
+
+ |
+
+
+
+
+
+ ';
+ $sent = mail($this->to, $this->subject, $message, $headers);
+ if($sent){
+ log_info("mail", "Sent message '$this->subject' to '$this->to'");
+ }
+ else{
+ log_info("mail", "Error sending message '$this->subject' to '$this->to'");
+ }
+
+ return $sent;
+ }
+}
+?>
\ No newline at end of file
diff --git a/core/event.class.php b/core/event.class.php
index a158cb9d..cbff2fcf 100644
--- a/core/event.class.php
+++ b/core/event.class.php
@@ -68,7 +68,7 @@ class PageRequestEvent extends Event {
}
public function count_args() {
- return $this->arg_count - $this->part_count;
+ return (int)($this->arg_count - $this->part_count);
}
/*
@@ -76,20 +76,20 @@ class PageRequestEvent extends Event {
*/
public function get_search_terms() {
$search_terms = array();
- if($this->count_args() == 2) {
+ if($this->count_args() === 2) {
$search_terms = explode(' ', $this->get_arg(0));
}
return $search_terms;
}
public function get_page_number() {
$page_number = 1;
- if($this->count_args() == 1) {
+ if($this->count_args() === 1) {
$page_number = int_escape($this->get_arg(0));
}
- else if($this->count_args() == 2) {
+ else if($this->count_args() === 2) {
$page_number = int_escape($this->get_arg(1));
}
- if($page_number == 0) $page_number = 1; // invalid -> 0
+ if($page_number === 0) $page_number = 1; // invalid -> 0
return $page_number;
}
public function get_page_size() {
diff --git a/core/extension.class.php b/core/extension.class.php
index 5d61b347..17fd2809 100644
--- a/core/extension.class.php
+++ b/core/extension.class.php
@@ -92,6 +92,9 @@ abstract class SimpleExtension implements Extension {
var $theme;
var $_child;
+ // in PHP5.3, late static bindings can take care of this; __CLASS__
+ // used here will refer to the subclass
+ // http://php.net/manual/en/language.oop5.late-static-bindings.php
public function i_am(Extension $child) {
$this->_child = $child;
if(is_null($this->theme)) $this->theme = get_theme_object($child, false);
diff --git a/core/imageboard.pack.php b/core/imageboard.pack.php
index 14f2037e..1be135fa 100644
--- a/core/imageboard.pack.php
+++ b/core/imageboard.pack.php
@@ -27,6 +27,8 @@ $tag_n = 0; // temp hack
$_flexihash = null;
$_fh_last_opts = null;
+require_once "lib/flexihash.php";
+
/**
* An object representing an entry in the images table. As of 2.2, this no
* longer necessarily represents an image per se, but could be a video,
@@ -196,12 +198,12 @@ class Image {
}
if(count($tags) == 0) {
- $row = $database->get_row("SELECT images.* FROM images WHERE images.id $gtlt {$this->id} ORDER BY images.id $dir LIMIT 1");
+ $row = $database->get_row('SELECT images.* FROM images WHERE images.id '.$gtlt.' '.$this->id.' ORDER BY images.id '.$dir.' LIMIT 1');
}
else {
- $tags[] = "id$gtlt{$this->id}";
+ $tags[] = 'id'. $gtlt . $this->id;
$querylet = Image::build_search_querylet($tags);
- $querylet->append_sql(" ORDER BY images.id $dir LIMIT 1");
+ $querylet->append_sql(' ORDER BY images.id '.$dir.' LIMIT 1');
$row = $database->get_row($querylet->sql, $querylet->variables);
}
@@ -251,8 +253,14 @@ class Image {
*/
public function get_image_link() {
global $config;
- if(strlen($config->get_string('image_ilink')) > 0) {
- return $this->parse_link_template($config->get_string('image_ilink'));
+
+ $image_ilink = $config->get_string('image_ilink'); // store a copy for speed.
+
+ if( !empty($image_ilink) ) { /* empty is faster than strlen */
+ if(!startsWith($image_ilink, "http://") && !startsWith($image_ilink, "/")) {
+ $image_ilink = make_link($image_ilink);
+ }
+ return $this->parse_link_template($image_ilink);
}
else if($config->get_bool('nice_urls', false)) {
return $this->parse_link_template(make_link('_images/$hash/$id - $tags.$ext'));
@@ -280,8 +288,14 @@ class Image {
*/
public function get_thumb_link() {
global $config;
- if(strlen($config->get_string('image_tlink')) > 0) {
- return $this->parse_link_template($config->get_string('image_tlink'));
+
+ $image_tlink = $config->get_string('image_tlink'); // store a copy for speed.
+
+ if( !empty($image_tlink) ) { /* empty is faster than strlen */
+ if(!startsWith($image_tlink, "http://") && !startsWith($image_tlink, "/")) {
+ $image_tlink = make_link($image_tlink);
+ }
+ return $this->parse_link_template($image_tlink);
}
else if($config->get_bool('nice_urls', false)) {
return $this->parse_link_template(make_link('_thumbs/$hash/thumb.jpg'));
@@ -338,8 +352,8 @@ class Image {
*/
public function get_mime_type() {
$type = strtolower($this->ext);
- if($type == "jpg") $type = "jpeg";
- return "image/$type";
+ if($type === "jpg") $type = "jpeg";
+ return 'image/'.$type;
}
/**
@@ -379,7 +393,7 @@ class Image {
public function set_locked($tf) {
global $database;
$ln = $tf ? "Y" : "N";
- $sln = $database->engine->scoreql_to_sql("SCORE_BOOL_$ln");
+ $sln = $database->engine->scoreql_to_sql('SCORE_BOOL_'.$ln);
$sln = str_replace("'", "", $sln);
$sln = str_replace('"', "", $sln);
if($sln != $this->locked) {
@@ -458,7 +472,7 @@ class Image {
global $database;
$this->delete_tags_from_image();
$database->execute("DELETE FROM images WHERE id=:id", array("id"=>$this->id));
- log_info("core-image", "Deleted Image #{$this->id} ({$this->hash})");
+ log_info("core-image", 'Deleted Image #'.$this->id.' ('.$this->hash.')');
unlink($this->get_image_filename());
unlink($this->get_thumb_filename());
@@ -469,7 +483,7 @@ class Image {
* It DOES NOT remove anything from the database.
*/
public function remove_image_only() {
- log_info("core-image", "Removed Image File ({$this->hash})");
+ log_info("core-image", 'Removed Image File ('.$this->hash.')');
@unlink($this->get_image_filename());
@unlink($this->get_thumb_filename());
}
@@ -522,7 +536,6 @@ class Image {
if($opts != $_fh_last_opts) {
$_fh_last_opts = $opts;
- require_once("lib/flexihash.php");
$_flexihash = new Flexihash();
foreach(explode(",", $opts) as $opt) {
$parts = explode("=", $opt);
@@ -550,7 +563,7 @@ class Image {
private static function build_search_querylet($terms) {
assert(is_array($terms));
global $database;
- if($database->engine->name == "mysql")
+ if($database->engine->name === "mysql")
return Image::build_ugly_search_querylet($terms);
else
return Image::build_accurate_search_querylet($terms);
@@ -593,7 +606,7 @@ class Image {
// various types of querylet
foreach($terms as $term) {
$positive = true;
- if(strlen($term) > 0 && $term[0] == '-') {
+ if(is_string($term) && !empty($term) && ($term[0] == '-')) {
$positive = false;
$term = substr($term, 1);
}
@@ -641,7 +654,7 @@ class Image {
if(count($tag_querylets) == 0) {
$query = new Querylet("SELECT images.* FROM images ");
- if(strlen($img_search->sql) > 0) {
+ if(!empty($img_search->sql)) {
$query->append_sql(" WHERE ");
$query->append($img_search);
}
@@ -658,7 +671,7 @@ class Image {
)
"), array("tag"=>$tag_querylets[0]->tag));
- if(strlen($img_search->sql) > 0) {
+ if(!empty($img_search->sql)) {
$query->append_sql(" AND ");
$query->append($img_search);
}
@@ -760,7 +773,7 @@ class Image {
// turn each term into a specific type of querylet
foreach($terms as $term) {
$negative = false;
- if((strlen($term) > 0) && ($term[0] == '-')) {
+ if( !empty($term) && ($term[0] == '-')) {
$negative = true;
$term = substr($term, 1);
}
@@ -789,11 +802,13 @@ class Image {
foreach($tag_querylets as $tq) {
global $tag_n;
$sign = $tq->positive ? "+" : "-";
- $sql .= " $sign (tag LIKE :tag$tag_n)";
- $terms["tag$tag_n"] = $tq->tag;
+ //$sql .= " $sign (tag LIKE :tag$tag_n)";
+ $sql .= ' '.$sign.' (tag LIKE :tag'.$tag_n.')';
+ //$terms["tag$tag_n"] = $tq->tag;
+ $terms['tag'.$tag_n] = $tq->tag;
$tag_n++;
- if($sign == "+") $positive_tag_count++;
+ if($sign === "+") $positive_tag_count++;
else $negative_tag_count++;
}
$tag_search = new Querylet($sql, $terms);
@@ -815,14 +830,14 @@ class Image {
if($positive_tag_count + $negative_tag_count == 0) {
$query = new Querylet("SELECT images.*,UNIX_TIMESTAMP(posted) AS posted_timestamp FROM images ");
- if(strlen($img_search->sql) > 0) {
+ if(!empty($img_search->sql)) {
$query->append_sql(" WHERE ");
$query->append($img_search);
}
}
// one positive tag (a common case), do an optimised search
- else if($positive_tag_count == 1 && $negative_tag_count == 0) {
+ else if($positive_tag_count === 1 && $negative_tag_count === 0) {
$query = new Querylet(
// MySQL is braindead, and does a full table scan on images, running the subquery once for each row -_-
// "{$this->get_images} WHERE images.id IN (SELECT image_id FROM tags WHERE tag LIKE ?) ",
@@ -836,7 +851,7 @@ class Image {
",
$tag_search->variables);
- if(strlen($img_search->sql) > 0) {
+ if(!empty($img_search->sql)) {
$query->append_sql(" AND ");
$query->append($img_search);
}
@@ -858,24 +873,24 @@ class Image {
if($tags_ok) {
$tag_id_list = join(', ', $tag_id_array);
- $subquery = new Querylet("
- SELECT images.*, SUM({$tag_search->sql}) AS score
+ $subquery = new Querylet('
+ SELECT images.*, SUM('.$tag_search->sql.') AS score
FROM images
LEFT JOIN image_tags ON image_tags.image_id = images.id
JOIN tags ON image_tags.tag_id = tags.id
- WHERE tags.id IN ({$tag_id_list})
+ WHERE tags.id IN ('.$tag_id_list.')
GROUP BY images.id
- HAVING score = :score",
+ HAVING score = :score',
array_merge(
$tag_search->variables,
array("score"=>$positive_tag_count)
)
);
- $query = new Querylet("
+ $query = new Querylet('
SELECT *, UNIX_TIMESTAMP(posted) AS posted_timestamp
- FROM ({$subquery->sql}) AS images ", $subquery->variables);
+ FROM ('.$subquery->sql.') AS images ', $subquery->variables);
- if(strlen($img_search->sql) > 0) {
+ if(!empty($img_search->sql)) {
$query->append_sql(" WHERE ");
$query->append($img_search);
}
@@ -921,15 +936,15 @@ class Tag {
if(is_string($tags)) {
$tags = explode(' ', $tags);
}
- else if(is_array($tags)) {
+ //else if(is_array($tags)) {
// do nothing
- }
+ //}
$tags = array_map("trim", $tags);
$tag_array = array();
foreach($tags as $tag) {
- if(is_string($tag) && strlen($tag) > 0) {
+ if(is_string($tag) && !empty($tag)) {
$tag_array[] = $tag;
}
}
@@ -946,13 +961,13 @@ class Tag {
public static function implode($tags) {
assert(is_string($tags) || is_array($tags));
- if(is_string($tags)) {
- // do nothing
- }
- else if(is_array($tags)) {
+ if(is_array($tags)) {
sort($tags);
$tags = implode(' ', $tags);
}
+ //else if(is_string($tags)) {
+ // do nothing
+ //}
return $tags;
}
diff --git a/core/page.class.php b/core/page.class.php
index e6e92a9a..6570632b 100644
--- a/core/page.class.php
+++ b/core/page.class.php
@@ -225,8 +225,8 @@ class Page {
print $this->data;
break;
case "redirect":
- header("Location: {$this->redirect}");
- print "You should be redirected to {$this->redirect}";
+ header('Location: '.$this->redirect);
+ print 'You should be redirected to '.$this->redirect.'';
break;
default:
print "Invalid page mode";
@@ -242,22 +242,22 @@ class Page {
// caching failed, add all files to html_headers.
foreach(glob("lib/*.css") as $css) {
- $this->add_html_header("");
+ $this->add_html_header('');
}
$css_files = glob("ext/*/style.css");
if($css_files) {
foreach($css_files as $css_file) {
- $this->add_html_header("");
+ $this->add_html_header('');
}
}
foreach(glob("lib/*.js") as $js) {
- $this->add_html_header("");
+ $this->add_html_header('');
}
$js_files = glob("ext/*/script.js");
if($js_files) {
foreach($js_files as $js_file) {
- $this->add_html_header("");
+ $this->add_html_header('');
}
}
}
@@ -358,16 +358,16 @@ class Page {
}
}
// tell the client where to get the css cache file
- $this->add_html_header('');
+ $this->add_html_header('');
} else {
// Caching of CSS disabled.
foreach(glob("lib/*.css") as $css) {
- $this->add_html_header("");
+ $this->add_html_header('');
}
$css_files = glob("ext/*/style.css");
if($css_files) {
foreach($css_files as $css_file) {
- $this->add_html_header("");
+ $this->add_html_header('');
}
}
}
@@ -408,16 +408,16 @@ class Page {
}
}
// tell the client where to get the js cache file
- $this->add_html_header('');
+ $this->add_html_header('');
} else {
// Caching of Javascript disabled.
foreach(glob("lib/*.js") as $js) {
- $this->add_html_header("");
+ $this->add_html_header('');
}
$js_files = glob("ext/*/script.js");
if($js_files) {
foreach($js_files as $js_file) {
- $this->add_html_header("");
+ $this->add_html_header('');
}
}
}
diff --git a/core/user.class.php b/core/user.class.php
index 04ae7c7a..85d90df5 100644
--- a/core/user.class.php
+++ b/core/user.class.php
@@ -40,7 +40,7 @@ class User {
public static function by_session(/*string*/ $name, /*string*/ $session) {
global $config, $database;
- if($database->engine->name == "mysql") {
+ if($database->engine->name === "mysql") {
$query = "SELECT * FROM users WHERE name = :name AND md5(concat(pass, :ip)) = :sess";
}
else {
@@ -53,12 +53,12 @@ class User {
public static function by_id(/*int*/ $id) {
assert(is_numeric($id));
global $database;
- if($id == 1) {
- $cached = $database->cache->get("user-id:$id");
+ if($id === 1) {
+ $cached = $database->cache->get('user-id:'.$id);
if($cached) return new User($cached);
}
$row = $database->get_row("SELECT * FROM users WHERE id = :id", array("id"=>$id));
- if($id == 1) $database->cache->set("user-id:$id", $row, 300);
+ if($id === 1) $database->cache->set('user-id:'.$id, $row, 300);
return is_null($row) ? null : new User($row);
}
@@ -98,7 +98,7 @@ class User {
*/
public function is_anonymous() {
global $config;
- return ($this->id == $config->get_int('anon_id'));
+ return ($this->id === $config->get_int('anon_id'));
}
/**
@@ -108,7 +108,7 @@ class User {
*/
public function is_logged_in() {
global $config;
- return ($this->id != $config->get_int('anon_id'));
+ return ($this->id !== $config->get_int('anon_id'));
}
/**
@@ -125,20 +125,20 @@ class User {
global $database;
$yn = $admin ? 'Y' : 'N';
$database->Execute("UPDATE users SET admin=:yn WHERE id=:id", array("yn"=>$yn, "id"=>$this->id));
- log_info("core-user", "Made {$this->name} admin=$yn");
+ log_info("core-user", 'Made '.$this->name.' admin='.$yn);
}
public function set_password(/*string*/ $password) {
global $database;
$hash = md5(strtolower($this->name) . $password);
$database->Execute("UPDATE users SET pass=:hash WHERE id=:id", array("hash"=>$hash, "id"=>$this->id));
- log_info("core-user", "Set password for {$this->name}");
+ log_info("core-user", 'Set password for '.$this->name);
}
public function set_email(/*string*/ $address) {
global $database;
$database->Execute("UPDATE users SET email=:email WHERE id=:id", array("email"=>$address, "id"=>$this->id));
- log_info("core-user", "Set email for {$this->name}");
+ log_info("core-user", 'Set email for '.$this->name);
}
/**
@@ -148,7 +148,7 @@ class User {
public function get_avatar_html() {
// FIXME: configurable
global $config;
- if($config->get_string("avatar_host") == "gravatar") {
+ if($config->get_string("avatar_host") === "gravatar") {
if(!empty($this->email)) {
$hash = md5(strtolower($this->email));
$s = $config->get_string("avatar_gravatar_size");
@@ -173,14 +173,14 @@ class User {
*/
public function get_auth_token() {
global $config;
- $salt = file_get_contents("config.php");
+ $salt = DATABASE_DSN;
$addr = get_session_ip($config);
return md5(md5($this->passhash . $addr) . "salty-csrf-" . $salt);
}
public function get_auth_html() {
$at = $this->get_auth_token();
- return "";
+ return '';
}
public function check_auth_token() {
diff --git a/core/util.inc.php b/core/util.inc.php
index 731a5d9d..882c8560 100644
--- a/core/util.inc.php
+++ b/core/util.inc.php
@@ -21,6 +21,10 @@ function html_escape($input) {
* @retval int
*/
function int_escape($input) {
+ /*
+ Side note, Casting to an integer is FASTER than using intval.
+ http://hakre.wordpress.com/2010/05/13/php-casting-vs-intval/
+ */
return (int)$input;
}
@@ -56,13 +60,13 @@ function sql_escape($input) {
function bool_escape($input) {
$input = strtolower($input);
return (
- $input == "y" ||
- $input == "yes" ||
- $input == "t" ||
- $input == "true" ||
- $input == "on" ||
- $input == 1 ||
- $input == true
+ $input === "y" ||
+ $input === "yes" ||
+ $input === "t" ||
+ $input === "true" ||
+ $input === "on" ||
+ $input === 1 ||
+ $input === true
);
}
@@ -86,7 +90,7 @@ function parse_shorthand_int($limit) {
return (int)$limit;
}
- if(preg_match('/^([\d\.]+)([gmk])?b?$/i', "$limit", $m)) {
+ if(preg_match('/^([\d\.]+)([gmk])?b?$/i', (string)$limit, $m)) {
$value = $m[1];
if (isset($m[2])) {
switch(strtolower($m[2])) {
@@ -118,7 +122,7 @@ function to_shorthand_int($int) {
return sprintf("%.1fKB", $int / 1024);
}
else {
- return "$int";
+ return (string)$int;
}
}
@@ -186,6 +190,17 @@ function undb_bool($val) {
if($val === false || $val == 'N' || $val == 'n' || $val == 'F' || $val == 'f' || $val === 0) return false;
}
+function startsWith($haystack, $needle) {
+ $length = strlen($needle);
+ return (substr($haystack, 0, $length) === $needle);
+}
+
+function endsWith($haystack, $needle) {
+ $length = strlen($needle);
+ $start = $length * -1; //negative
+ return (substr($haystack, $start) === $needle);
+}
+
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\
* HTML Generation *
@@ -207,24 +222,24 @@ function make_link($page=null, $query=null) {
if(NICE_URLS || $config->get_bool('nice_urls', false)) {
#$full = "http://" . $_SERVER["SERVER_NAME"] . $_SERVER["PHP_SELF"];
$full = $_SERVER["PHP_SELF"];
- $base = str_replace("/index.php", "", $full);
+ $base = str_replace("/".basename($_SERVER["SCRIPT_FILENAME"]), "", $full);
}
else {
- $base = "./index.php?q=";
+ $base = "./".basename($_SERVER["SCRIPT_FILENAME"])."?q=";
}
if(is_null($query)) {
- return str_replace("//", "/", "$base/$page");
+ return str_replace("//", "/", $base.'/'.$page );
}
else {
if(strpos($base, "?")) {
- return "$base/$page&$query";
+ return $base .'/'. $page .'&'. $query;
}
else if(strpos($query, "#") === 0) {
- return "$base/$page$query";
+ return $base .'/'. $page . $query;
}
else {
- return "$base/$page?$query";
+ return $base .'/'. $page .'?'. $query;
}
}
}
@@ -293,14 +308,14 @@ function make_http(/*string*/ $link) {
function make_form($target, $method="POST", $multipart=False, $form_id="", $onsubmit="") {
global $user;
$auth = $user->get_auth_html();
- $extra = empty($form_id) ? '' : " id='$form_id'";
+ $extra = empty($form_id) ? '' : 'id="'. $form_id .'"';
if($multipart) {
$extra .= " enctype='multipart/form-data'";
}
if($onsubmit) {
- $extra .= " onsubmit='$onsubmit'";
+ $extra .= ' onsubmit="'.$onsubmit.'"';
}
- return "