From 95eadbdd1f29603220658cf38c17a513105c75dc Mon Sep 17 00:00:00 2001 From: Shish Date: Tue, 24 Nov 2009 14:07:18 +0000 Subject: [PATCH] dos2unixification --- contrib/artists/theme.php | 986 +++++++++++++++++------------------ contrib/favorites/theme.php | 86 +-- contrib/forum/main.php | 790 ++++++++++++++-------------- contrib/forum/theme.php | 456 ++++++++-------- contrib/notes/theme.php | 746 +++++++++++++------------- contrib/sitemap/main.php | 108 ++-- contrib/tag_history/main.php | 438 ++++++++-------- contrib/tips/main.php | 348 ++++++------- contrib/tips/theme.php | 198 +++---- 9 files changed, 2078 insertions(+), 2078 deletions(-) diff --git a/contrib/artists/theme.php b/contrib/artists/theme.php index f1fc810f..e54d65a4 100644 --- a/contrib/artists/theme.php +++ b/contrib/artists/theme.php @@ -1,494 +1,494 @@ -Author"; - } - - public function display_artists(){ - global $page; - - $page->set_title("Artists"); - $page->set_heading("Artists"); - $page->add_block(new Block("Artists", $html, "main", 10)); - - //$this->display_paginator($page, "artist/list", null, $pageNumber, $totalPages); - } - - public function sidebar_options($mode, $artistID=NULL, $is_admin=FALSE){ - global $page; - - if($mode == "neutral"){ - $html = "
- -
"; - } - - if($mode == "editor"){ - $html = "
- -
- -
- - -
"; - - if($is_admin){ - $html .= "
- - -
"; - } - - $html .= "
- - -
- -
- - -
- -
- - -
"; - } - $page->add_block(new Block("Manage Artists", $html, "left", 10)); - } - - public function show_artist_editor($artist, $aliases, $members, $urls) - { - $artistName = $artist['name']; - $artistNotes = $artist['notes']; - $artistID = $artist['id']; - - // aliases - $aliasesString = ""; - $aliasesIDsString = ""; - foreach ($aliases as $alias) - { - $aliasesString .= $alias["alias_name"]." "; - $aliasesIDsString .= $alias["alias_id"]." "; - } - $aliasesString = rtrim($aliasesString); - $aliasesIDsString = rtrim($aliasesIDsString); - - // members - $membersString = ""; - $membersIDsString = ""; - foreach ($members as $member) - { - $membersString .= $member["name"]." "; - $membersIDsString .= $member["id"]." "; - } - $membersString = rtrim($membersString); - $membersIDsString = rtrim($membersIDsString); - - // urls - $urlsString = ""; - $urlsIDsString = ""; - foreach ($urls as $url) - { - $urlsString .= $url["url"]."\n"; - $urlsIDsString .= $url["id"]." "; - } - $urlsString = substr($urlsString, 0, strlen($urlsString) -1); - $urlsIDsString = rtrim($urlsIDsString); - - $html = -' -
- - - - - - - -
Name: -
Alias: -
Members: -
URLs: -
Notes:
-
- -'; - - global $page; - $page->add_block(new Block("Edit artist", $html, "main", 10)); - } - - public function new_artist_composer() - { - global $page; - - $html = "
- - - - - - - -
Name:
Aliases:
Members:
URLs:
Notes:
- "; - - $page->set_title("Artists"); - $page->set_heading("Artists"); - $page->add_block(new Block("Artists", $html, "main", 10)); - } - - public function list_artists($artists, $pageNumber, $totalPages) - { - global $user, $page; - - $html = "". - "". - "". - "". - "". - ""; - - - if(!$user->is_anonymous()) $html .= ""; // space for edit link - - $html .= ""; - - $n = 0; - $deletionLinkActionArray = - array('artist' => 'artist/nuke/' - , 'alias' => 'artist/alias/delete/' - , 'member' => 'artist/member/delete/' - ); - - $editionLinkActionArray = - array('artist' => 'artist/edit/' - , 'alias' => 'artist/alias/edit/' - , 'member' => 'artist/member/edit/' - ); - - $typeTextArray = - array('artist' => 'Artist' - , 'alias' => 'Alias' - , 'member' => 'Member' - ); - - foreach ($artists as $artist) - { - $oe = ($n++ % 2 == 0) ? "even" : "odd"; - - if ($artist['type'] != 'artist') - $artist['name'] = str_replace("_", " ", $artist['name']); - - $elementLink = "".str_replace("_", " ", $artist['name']).""; - $artist_link = "".str_replace("_", " ", $artist['artist_name']).""; - $user_link = "".$artist['user_name'].""; - $edit_link = "Edit"; - $del_link = "Delete"; - - $html .= "". - "". - "". - "". - ""; - - if(!$user->is_anonymous()) $html .= ""; - if($user->is_admin()) $html .= ""; - - $html .= ""; - } - - $html .= "
NameTypeLast updaterPostsAction
".$elementLink; - - //if ($artist['type'] == 'member') - // $html .= " (member of ".$artist_link.")"; - - //if ($artist['type'] == 'alias') - // $html .= " (alias for ".$artist_link.")"; - - $html .= "".$typeTextArray[$artist['type']]."".$user_link."".$artist['posts']."".$edit_link."".$del_link."
"; - - $page->set_title("Artists"); - $page->set_heading("Artists"); - $page->add_block(new Block("Artists", $html, "main", 10)); - - $this->display_paginator($page, "artist/list", null, $pageNumber, $totalPages); - } - - public function show_new_alias_composer($artistID) - { - $html = - ' - - - -
Alias: -
-
- '; - - global $page; - $page->add_block(new Block("Artist Aliases", $html, "main", 20)); - } - public function show_new_member_composer($artistID) - { - $html = - '
- - - -
Members: -
-
- '; - - global $page; - $page->add_block(new Block("Artist members", $html, "main", 30)); - } - - public function show_new_url_composer($artistID) - { - $html = - '
- - - -
URL: -
-
- '; - - global $page; - $page->add_block(new Block("Artist URLs", $html, "main", 40)); - } - - public function show_alias_editor($alias) - { - $html = - ' -
- - - - -
- '; - - global $page; - $page->add_block(new Block("Edit Alias", $html, "main", 10)); - } - - public function show_url_editor($url) - { - $html = - ' -
- - - - -
- '; - - global $page; - $page->add_block(new Block("Edit URL", $html, "main", 10)); - } - - public function show_member_editor($member) - { - $html = - ' -
- - - - -
- '; - - global $page; - $page->add_block(new Block("Edit Member", $html, "main", 10)); - } - - public function show_artist($artist, $aliases, $members, $urls, $images, $userIsLogged, $userIsAdmin) - { - global $user, $event, $page; - - $artist_link = "".str_replace("_", " ", $artist['name']).""; - - $n = 0; - - $html = " - - - - "; - - if ($userIsLogged) - $html .= ""; - - if ($userIsAdmin) - $html .= ""; - - $html .= " - - - - - "; - if ($userIsLogged) $html .= ""; - if ($userIsAdmin) $html .= ""; - $html .= ""; - - if (count($aliases) > 0) - { - $aliasViewLink = str_replace("_", " ", $aliases[0]['alias_name']); // no link anymore - $aliasEditLink = "Edit"; - $aliasDeleteLink = "Delete"; - - $html .= " - - "; - - if ($userIsLogged) - $html .= ""; - - if ($userIsAdmin) - $html .= ""; - - $html .= ""; - - if (count($aliases) > 1) - { - for ($i = 1; $i < count($aliases); $i++) - { - $aliasViewLink = str_replace("_", " ", $aliases[$i]['alias_name']); // no link anymore - $aliasEditLink = "Edit"; - $aliasDeleteLink = "Delete"; - - $html .= " - - "; - if ($userIsLogged) - $html .= ""; - if ($userIsAdmin) - $html .= ""; - - $html .= ""; - } - } - } - - if (count($members) > 0) - { - $memberViewLink = str_replace("_", " ", $members[0]['name']); // no link anymore - $memberEditLink = "Edit"; - $memberDeleteLink = "Delete"; - - $html .= " - - "; - if ($userIsLogged) - $html .= ""; - if ($userIsAdmin) - $html .= ""; - - $html .= ""; - - if (count($members) > 1) - { - for ($i = 1; $i < count($members); $i++) - { - $memberViewLink = str_replace("_", " ", $members[$i]['name']); // no link anymore - $memberEditLink = "Edit"; - $memberDeleteLink = "Delete"; - - $html .= " - - "; - if ($userIsLogged) - $html .= ""; - if ($userIsAdmin) - $html .= ""; - - $html .= ""; - } - } - } - - if (count($urls) > 0) - { - $urlViewLink = "".str_replace("_", " ", $urls[0]['url']).""; - $urlEditLink = "Edit"; - $urlDeleteLink = "Delete"; - - $html .= " - - "; - - if ($userIsLogged) - $html .= ""; - - if ($userIsAdmin) - $html .= ""; - - $html .= ""; - - if (count($urls) > 1) - { - for ($i = 1; $i < count($urls); $i++) - { - $urlViewLink = "".str_replace("_", " ", $urls[$i]['url']).""; - $urlEditLink = "Edit"; - $urlDeleteLink = "Delete"; - - $html .= " - - "; - if ($userIsLogged) - $html .= ""; - - if ($userIsAdmin) - $html .= ""; - - $html .= ""; - } - } - } - - $html .= - " - - "; - if ($userIsLogged) $html .= ""; - if ($userIsAdmin) $html .= ""; - //TODO how will notes be edited? On edit artist? (should there be an editartist?) or on a editnotes? - //same question for deletion - $html .= " -
Name:".$artist_link."
Aliases:".$aliasViewLink."".$aliasEditLink."".$aliasDeleteLink."
 ".$aliasViewLink."".$aliasEditLink."".$aliasDeleteLink."
Members:".$memberViewLink."".$memberEditLink."".$memberDeleteLink."
 ".$memberViewLink."".$memberEditLink."".$memberDeleteLink."
URLs:".$urlViewLink."".$urlEditLink."".$urlDeleteLink."
 ".$urlViewLink."".$urlEditLink."".$urlDeleteLink."
Notes:".$artist["notes"]."
"; - - $page->set_title("Artist"); - $page->set_heading("Artist"); - $page->add_block(new Block("Artist", $html, "main", 10)); - - - //we show the images for the artist - $artist_images = ""; - foreach($images as $image) { - - $thumb_html = $this->build_thumb_html($image); - - $artist_images .= ''. - ''.$thumb_html.''. - ''; - } - - $page->add_block(new Block("Artist Images", $artist_images, "main", 20)); - } - -} +Author"; + } + + public function display_artists(){ + global $page; + + $page->set_title("Artists"); + $page->set_heading("Artists"); + $page->add_block(new Block("Artists", $html, "main", 10)); + + //$this->display_paginator($page, "artist/list", null, $pageNumber, $totalPages); + } + + public function sidebar_options($mode, $artistID=NULL, $is_admin=FALSE){ + global $page; + + if($mode == "neutral"){ + $html = "
+ +
"; + } + + if($mode == "editor"){ + $html = "
+ +
+ +
+ + +
"; + + if($is_admin){ + $html .= "
+ + +
"; + } + + $html .= "
+ + +
+ +
+ + +
+ +
+ + +
"; + } + $page->add_block(new Block("Manage Artists", $html, "left", 10)); + } + + public function show_artist_editor($artist, $aliases, $members, $urls) + { + $artistName = $artist['name']; + $artistNotes = $artist['notes']; + $artistID = $artist['id']; + + // aliases + $aliasesString = ""; + $aliasesIDsString = ""; + foreach ($aliases as $alias) + { + $aliasesString .= $alias["alias_name"]." "; + $aliasesIDsString .= $alias["alias_id"]." "; + } + $aliasesString = rtrim($aliasesString); + $aliasesIDsString = rtrim($aliasesIDsString); + + // members + $membersString = ""; + $membersIDsString = ""; + foreach ($members as $member) + { + $membersString .= $member["name"]." "; + $membersIDsString .= $member["id"]." "; + } + $membersString = rtrim($membersString); + $membersIDsString = rtrim($membersIDsString); + + // urls + $urlsString = ""; + $urlsIDsString = ""; + foreach ($urls as $url) + { + $urlsString .= $url["url"]."\n"; + $urlsIDsString .= $url["id"]." "; + } + $urlsString = substr($urlsString, 0, strlen($urlsString) -1); + $urlsIDsString = rtrim($urlsIDsString); + + $html = +' +
+ + + + + + + +
Name: +
Alias: +
Members: +
URLs: +
Notes:
+
+ +'; + + global $page; + $page->add_block(new Block("Edit artist", $html, "main", 10)); + } + + public function new_artist_composer() + { + global $page; + + $html = "
+ + + + + + + +
Name:
Aliases:
Members:
URLs:
Notes:
+ "; + + $page->set_title("Artists"); + $page->set_heading("Artists"); + $page->add_block(new Block("Artists", $html, "main", 10)); + } + + public function list_artists($artists, $pageNumber, $totalPages) + { + global $user, $page; + + $html = "". + "". + "". + "". + "". + ""; + + + if(!$user->is_anonymous()) $html .= ""; // space for edit link + + $html .= ""; + + $n = 0; + $deletionLinkActionArray = + array('artist' => 'artist/nuke/' + , 'alias' => 'artist/alias/delete/' + , 'member' => 'artist/member/delete/' + ); + + $editionLinkActionArray = + array('artist' => 'artist/edit/' + , 'alias' => 'artist/alias/edit/' + , 'member' => 'artist/member/edit/' + ); + + $typeTextArray = + array('artist' => 'Artist' + , 'alias' => 'Alias' + , 'member' => 'Member' + ); + + foreach ($artists as $artist) + { + $oe = ($n++ % 2 == 0) ? "even" : "odd"; + + if ($artist['type'] != 'artist') + $artist['name'] = str_replace("_", " ", $artist['name']); + + $elementLink = "".str_replace("_", " ", $artist['name']).""; + $artist_link = "".str_replace("_", " ", $artist['artist_name']).""; + $user_link = "".$artist['user_name'].""; + $edit_link = "Edit"; + $del_link = "Delete"; + + $html .= "". + "". + "". + "". + ""; + + if(!$user->is_anonymous()) $html .= ""; + if($user->is_admin()) $html .= ""; + + $html .= ""; + } + + $html .= "
NameTypeLast updaterPostsAction
".$elementLink; + + //if ($artist['type'] == 'member') + // $html .= " (member of ".$artist_link.")"; + + //if ($artist['type'] == 'alias') + // $html .= " (alias for ".$artist_link.")"; + + $html .= "".$typeTextArray[$artist['type']]."".$user_link."".$artist['posts']."".$edit_link."".$del_link."
"; + + $page->set_title("Artists"); + $page->set_heading("Artists"); + $page->add_block(new Block("Artists", $html, "main", 10)); + + $this->display_paginator($page, "artist/list", null, $pageNumber, $totalPages); + } + + public function show_new_alias_composer($artistID) + { + $html = + ' + + + +
Alias: +
+
+ '; + + global $page; + $page->add_block(new Block("Artist Aliases", $html, "main", 20)); + } + public function show_new_member_composer($artistID) + { + $html = + '
+ + + +
Members: +
+
+ '; + + global $page; + $page->add_block(new Block("Artist members", $html, "main", 30)); + } + + public function show_new_url_composer($artistID) + { + $html = + '
+ + + +
URL: +
+
+ '; + + global $page; + $page->add_block(new Block("Artist URLs", $html, "main", 40)); + } + + public function show_alias_editor($alias) + { + $html = + ' +
+ + + + +
+ '; + + global $page; + $page->add_block(new Block("Edit Alias", $html, "main", 10)); + } + + public function show_url_editor($url) + { + $html = + ' +
+ + + + +
+ '; + + global $page; + $page->add_block(new Block("Edit URL", $html, "main", 10)); + } + + public function show_member_editor($member) + { + $html = + ' +
+ + + + +
+ '; + + global $page; + $page->add_block(new Block("Edit Member", $html, "main", 10)); + } + + public function show_artist($artist, $aliases, $members, $urls, $images, $userIsLogged, $userIsAdmin) + { + global $user, $event, $page; + + $artist_link = "".str_replace("_", " ", $artist['name']).""; + + $n = 0; + + $html = " + + + + "; + + if ($userIsLogged) + $html .= ""; + + if ($userIsAdmin) + $html .= ""; + + $html .= " + + + + + "; + if ($userIsLogged) $html .= ""; + if ($userIsAdmin) $html .= ""; + $html .= ""; + + if (count($aliases) > 0) + { + $aliasViewLink = str_replace("_", " ", $aliases[0]['alias_name']); // no link anymore + $aliasEditLink = "Edit"; + $aliasDeleteLink = "Delete"; + + $html .= " + + "; + + if ($userIsLogged) + $html .= ""; + + if ($userIsAdmin) + $html .= ""; + + $html .= ""; + + if (count($aliases) > 1) + { + for ($i = 1; $i < count($aliases); $i++) + { + $aliasViewLink = str_replace("_", " ", $aliases[$i]['alias_name']); // no link anymore + $aliasEditLink = "Edit"; + $aliasDeleteLink = "Delete"; + + $html .= " + + "; + if ($userIsLogged) + $html .= ""; + if ($userIsAdmin) + $html .= ""; + + $html .= ""; + } + } + } + + if (count($members) > 0) + { + $memberViewLink = str_replace("_", " ", $members[0]['name']); // no link anymore + $memberEditLink = "Edit"; + $memberDeleteLink = "Delete"; + + $html .= " + + "; + if ($userIsLogged) + $html .= ""; + if ($userIsAdmin) + $html .= ""; + + $html .= ""; + + if (count($members) > 1) + { + for ($i = 1; $i < count($members); $i++) + { + $memberViewLink = str_replace("_", " ", $members[$i]['name']); // no link anymore + $memberEditLink = "Edit"; + $memberDeleteLink = "Delete"; + + $html .= " + + "; + if ($userIsLogged) + $html .= ""; + if ($userIsAdmin) + $html .= ""; + + $html .= ""; + } + } + } + + if (count($urls) > 0) + { + $urlViewLink = "".str_replace("_", " ", $urls[0]['url']).""; + $urlEditLink = "Edit"; + $urlDeleteLink = "Delete"; + + $html .= " + + "; + + if ($userIsLogged) + $html .= ""; + + if ($userIsAdmin) + $html .= ""; + + $html .= ""; + + if (count($urls) > 1) + { + for ($i = 1; $i < count($urls); $i++) + { + $urlViewLink = "".str_replace("_", " ", $urls[$i]['url']).""; + $urlEditLink = "Edit"; + $urlDeleteLink = "Delete"; + + $html .= " + + "; + if ($userIsLogged) + $html .= ""; + + if ($userIsAdmin) + $html .= ""; + + $html .= ""; + } + } + } + + $html .= + " + + "; + if ($userIsLogged) $html .= ""; + if ($userIsAdmin) $html .= ""; + //TODO how will notes be edited? On edit artist? (should there be an editartist?) or on a editnotes? + //same question for deletion + $html .= " +
Name:".$artist_link."
Aliases:".$aliasViewLink."".$aliasEditLink."".$aliasDeleteLink."
 ".$aliasViewLink."".$aliasEditLink."".$aliasDeleteLink."
Members:".$memberViewLink."".$memberEditLink."".$memberDeleteLink."
 ".$memberViewLink."".$memberEditLink."".$memberDeleteLink."
URLs:".$urlViewLink."".$urlEditLink."".$urlDeleteLink."
 ".$urlViewLink."".$urlEditLink."".$urlDeleteLink."
Notes:".$artist["notes"]."
"; + + $page->set_title("Artist"); + $page->set_heading("Artist"); + $page->add_block(new Block("Artist", $html, "main", 10)); + + + //we show the images for the artist + $artist_images = ""; + foreach($images as $image) { + + $thumb_html = $this->build_thumb_html($image); + + $artist_images .= ''. + ''.$thumb_html.''. + ''; + } + + $page->add_block(new Block("Artist Images", $artist_images, "main", 20)); + } + +} ?> \ No newline at end of file diff --git a/contrib/favorites/theme.php b/contrib/favorites/theme.php index eb283006..6a45876e 100644 --- a/contrib/favorites/theme.php +++ b/contrib/favorites/theme.php @@ -1,43 +1,43 @@ -id); - if(!$is_favorited) { - $html = "
- - - -
- "; - } - else { - $html = "
- - - -
- "; - } - - return $html; - } - - public function display_people($username_array) { - global $page; - - $i_favorites = count($username_array); - $html = "$i_favorites people:"; - - foreach($username_array as $row) { - $username = html_escape($row['name']); - $html .= "
$username"; - } - - $page->add_block(new Block("Favorited By", $html, "left", 25)); - } -} - -?> +id); + if(!$is_favorited) { + $html = "
+ + + +
+ "; + } + else { + $html = "
+ + + +
+ "; + } + + return $html; + } + + public function display_people($username_array) { + global $page; + + $i_favorites = count($username_array); + $html = "$i_favorites people:"; + + foreach($username_array as $row) { + $username = html_escape($row['name']); + $html .= "
$username"; + } + + $page->add_block(new Block("Favorited By", $html, "left", 25)); + } +} + +?> diff --git a/contrib/forum/main.php b/contrib/forum/main.php index be76d166..c46fa006 100644 --- a/contrib/forum/main.php +++ b/contrib/forum/main.php @@ -1,395 +1,395 @@ - - * Alpha - * License: GPLv2 - * Description: Rough forum extension - * Documentation: - */ - -class Forum extends SimpleExtension { - public function onInitExt($event) { - global $config, $database; - - // shortcut to latest - - if ($config->get_int("forum_version") < 1) - { - $database->create_table("forum_threads", " - id SCORE_AIPK, - sticky SCORE_BOOL NOT NULL DEFAULT SCORE_BOOL_N, - title VARCHAR(255) NOT NULL, - user_id INTEGER NOT NULL, - date DATETIME NOT NULL, - uptodate DATETIME NOT NULL, - INDEX (date) - "); - - $database->create_table("forum_posts", - " id SCORE_AIPK, - thread_id INTEGER NOT NULL, - user_id INTEGER NOT NULL, - date DATETIME NOT NULL, - message TEXT, - INDEX (date), - FOREIGN KEY (thread_id) REFERENCES forum_threads (id) ON UPDATE CASCADE ON DELETE CASCADE - "); - - $config->set_int("forum_version", 1); - $config->set_int("forumTitleSubString", 25); - $config->set_int("forumThreadsPerPage", 15); - $config->set_int("forumPostsPerPage", 15); - - $config->set_int("forumMaxCharsPerPost", 512); - - log_info("forum", "extension installed"); - } - } - - public function onSetupBuilding(SetupBuildingEvent $event) { - $sb = new SetupBlock("Forum"); - $sb->add_int_option("forumTitleSubString", "Title max long: "); - $sb->add_int_option("forumThreadsPerPage", "
Threads per page: "); - $sb->add_int_option("forumPostsPerPage", "
Posts per page: "); - - $sb->add_int_option("forumMaxCharsPerPost", "
Max chars per post: "); - $event->panel->add_block($sb); - } - - public function onUserPageBuilding($event) { - global $page, $user, $database; - - $threads_count = $database->db->GetOne("SELECT COUNT(*) FROM forum_threads WHERE user_id=?", array($event->display_user->id)); - $posts_count = $database->db->GetOne("SELECT COUNT(*) FROM forum_posts WHERE user_id=?", array($event->display_user->id)); - - $days_old = ((time() - strtotime($event->display_user->join_date)) / 86400) + 1; - - $threads_rate = sprintf("%.1f", ($threads_count / $days_old)); - $posts_rate = sprintf("%.1f", ($posts_count / $days_old)); - - $event->add_stats("Forum threads: $threads_count, $threads_rate per day"); - $event->add_stats("Forum posts: $posts_count, $posts_rate per day"); - } - - - public function onPageRequest($event) { - global $page, $user; - - if($event->page_matches("forum")) { - switch($event->get_arg(0)) { - case "index": - { - $this->show_last_threads($page, $event, $user->is_admin()); - if(!$user->is_anonymous()) $this->theme->display_new_thread_composer($page); - break; - } - case "view": - { - $threadID = int_escape($event->get_arg(1)); - $pageNumber = int_escape($event->get_arg(2)); - - $this->show_posts($event, $user->is_admin()); - if($user->is_admin()) $this->theme->add_actions_block($page, $threadID); - if(!$user->is_anonymous()) $this->theme->display_new_post_composer($page, $threadID); - break; - } - case "new": - { - global $page; - $this->theme->display_new_thread_composer($page); - break; - } - case "create": - { - $redirectTo = "forum/index"; - if (!$user->is_anonymous()) - { - list($hasErrors, $errors) = $this->valid_values_for_new_thread(); - - if($hasErrors) - { - $this->theme->display_error($page, "Error", $errors); - $this->theme->display_new_thread_composer($page, $_POST["message"], $_POST["title"], false); - break; - } - - $newThreadID = $this->save_new_thread($user); - $this->save_new_post($newThreadID, $user); - $redirectTo = "forum/view/".$newThreadID."/1"; - } - - $page->set_mode("redirect"); - $page->set_redirect(make_link($redirectTo)); - - break; - } - case "delete": - $threadID = int_escape($event->get_arg(1)); - $postID = int_escape($event->get_arg(2)); - - if ($user->is_admin()) {$this->delete_post($postID);} - - $page->set_mode("redirect"); - $page->set_redirect(make_link("forum/view/".$threadID)); - break; - case "nuke": - $threadID = int_escape($event->get_arg(1)); - - if ($user->is_admin()) - $this->delete_thread($threadID); - - $page->set_mode("redirect"); - $page->set_redirect(make_link("forum/index")); - break; - case "answer": - if (!$user->is_anonymous()) - { - list($hasErrors, $errors) = $this->valid_values_for_new_post(); - - if ($hasErrors) - { - $this->theme->display_error($page, "Error", $errors); - $this->theme->display_new_post_composer($page, $_POST["threadID"], $_POST["message"], $_POST["title"], false); - break; - } - - $threadID = int_escape($_POST["threadID"]); - - $this->save_new_post($threadID, $user); - } - - $page->set_mode("redirect"); - $page->set_redirect(make_link("forum/view/".$threadID."/1")); - break; - default: - { - $page->set_mode("redirect"); - $page->set_redirect(make_link("forum/index")); - //$this->theme->display_error($page, "Invalid action", "You should check forum/index."); - break; - } - } - } - } - - private function get_total_pages_for_thread($threadID) - { - global $database, $config; - $result = $database->get_row("SELECT COUNT(1) AS count FROM forum_posts WHERE thread_id = ?", array($threadID)); - - return ceil($result["count"] / $config->get_int("forumPostsPerPage")); - } - - private function valid_values_for_new_thread() - { - $hasErrors = false; - - $errors = ""; - - if (!array_key_exists("title", $_POST)) - { - $hasErrors = true; - $errors .= "
No title supplied.
"; - } - else if (strlen($_POST["title"]) == 0) - { - $hasErrors = true; - $errors .= "
You cannot have an empty title.
"; - } - else if (strlen(mysql_real_escape_string(html_escape($_POST["title"]))) > 255) - { - $hasErrors = true; - $errors .= "
Your title is too long.
"; - } - - if (!array_key_exists("message", $_POST)) - { - $hasErrors = true; - $errors .= "
No message supplied.
"; - } - else if (strlen($_POST["message"]) == 0) - { - $hasErrors = true; - $errors .= "
You cannot have an empty message.
"; - } - - return array($hasErrors, $errors); - } - private function valid_values_for_new_post() - { - $hasErrors = false; - - $errors = ""; - if (!array_key_exists("threadID", $_POST)) - { - $hasErrors = true; - $errors = "
No thread ID supplied.
"; - } - else if (strlen($_POST["threadID"]) == 0) - { - $hasErrors = true; - $errors = "
No thread ID supplied.
"; - } - else if (is_numeric($_POST["threadID"])) - - if (!array_key_exists("message", $_POST)) - { - $hasErrors = true; - $errors .= "
No message supplied.
"; - } - else if (strlen($_POST["message"]) == 0) - { - $hasErrors = true; - $errors .= "
You cannot have an empty message.
"; - } - - return array($hasErrors, $errors); - } - private function get_thread_title($threadID) - { - global $database; - $result = $database->get_row("SELECT t.title FROM forum_threads AS t WHERE t.id = ? ", array($threadID)); - return $result["title"]; - } - - private function show_last_threads(Page $page, $event, $showAdminOptions = false) - { - global $config, $database; - $pageNumber = $event->get_arg(1); - if(is_null($pageNumber) || !is_numeric($pageNumber)) - $pageNumber = 0; - else if ($pageNumber <= 0) - $pageNumber = 0; - else - $pageNumber--; - - $threadsPerPage = $config->get_int('forumThreadsPerPage', 15); - - $threads = $database->get_all( - "SELECT f.id, f.sticky, f.title, f.date, f.uptodate, u.name AS user_name, u.email AS user_email, u.admin AS user_admin, sum(1) - 1 AS response_count ". - "FROM forum_threads AS f ". - "INNER JOIN users AS u ". - "ON f.user_id = u.id ". - "INNER JOIN forum_posts AS p ". - "ON p.thread_id = f.id ". - "GROUP BY f.id, f.sticky, f.title, f.date, u.name, u.email, u.admin ". - "ORDER BY f.sticky ASC, f.uptodate DESC LIMIT ?, ?" - , array($pageNumber * $threadsPerPage, $threadsPerPage) - ); - - $totalPages = ceil($database->db->GetOne("SELECT COUNT(*) FROM forum_threads") / $threadsPerPage); - - $this->theme->display_thread_list($page, $threads, $showAdminOptions, $pageNumber + 1, $totalPages); - } - - private function show_posts($event, $showAdminOptions = false) - { - global $config, $database, $user; - - $threadID = $event->get_arg(1); - $pageNumber = $event->get_arg(2); - if(is_null($pageNumber) || !is_numeric($pageNumber)) - $pageNumber = 0; - else if ($pageNumber <= 0) - $pageNumber = 0; - else - $pageNumber--; - - $postsPerPage = $config->get_int('forumPostsPerPage', 15); - - $posts = $database->get_all( - "SELECT p.id, p.date, p.message, u.name as user_name, u.email AS user_email, u.admin AS user_admin ". - "FROM forum_posts AS p ". - "INNER JOIN users AS u ". - "ON p.user_id = u.id ". - "WHERE thread_id = ? ". - "ORDER BY p.date ASC ". - "LIMIT ?, ? " - , array($threadID, $pageNumber * $postsPerPage, $postsPerPage) - ); - - $totalPages = ceil($database->db->GetOne("SELECT COUNT(*) FROM forum_posts WHERE thread_id = ?", array($threadID)) / $postsPerPage); - - $threadTitle = $this->get_thread_title($threadID); - - $this->theme->display_thread($posts, $showAdminOptions, $threadTitle, $threadID, $pageNumber + 1, $totalPages); - } - - private function save_new_thread($user) - { - $title = mysql_real_escape_string(html_escape($_POST["title"])); - $sticky = html_escape($_POST["sticky"]); - - if($sticky == ""){ - $sticky = "N"; - } - - global $database; - $database->execute(" - INSERT INTO forum_threads - (title, sticky, user_id, date, uptodate) - VALUES - (?, ?, ?, now(), now())", - array($title, $sticky, $user->id)); - - $result = $database->get_row("SELECT LAST_INSERT_ID() AS threadID", array()); - - log_info("forum", "Thread {$result["threadID"]} created by {$user->name}"); - - return $result["threadID"]; - } - - private function save_new_post($threadID, $user) - { - global $config; - $userID = $user->id; - $message = mysql_real_escape_string(html_escape($_POST["message"])); - - $max_characters = $config->get_int('forumMaxCharsPerPost'); - $message = substr($message, 0, $max_characters); - - global $database; - $database->execute("INSERT INTO forum_posts - (thread_id, user_id, date, message) - VALUES - (?, ?, now(), ?)" - , array($threadID, $userID, $message)); - - $result = $database->get_row("SELECT LAST_INSERT_ID() AS postID", array()); - - log_info("forum", "Post {$result["postID"]} created by {$user->name}"); - - $database->execute("UPDATE forum_threads SET uptodate=now() WHERE id=?", array ($threadID)); - } - - private function retrieve_posts($threadID, $pageNumber) - { - global $database, $config; - $postsPerPage = $config->get_int('forumPostsPerPage', 15); - - return $database->get_all( - "SELECT p.id, p.date, p.message, u.name as user_name, u.email AS user_email, u.admin AS user_admin ". - "FROM forum_posts AS p ". - "INNER JOIN users AS u ". - "ON p.user_id = u.id ". - "WHERE thread_id = ? ". - "ORDER BY p.date ASC ". - "LIMIT ?, ? " - , array($threadID, ($pageNumber - 1) * $postsPerPage, $postsPerPage)); - } - - private function delete_thread($threadID) - { - global $database; - $database->execute("DELETE FROM forum_threads WHERE id = ?", array($threadID)); - $database->execute("DELETE FROM forum_posts WHERE thread_id = ?", array($threadID)); - } - - private function delete_post($postID) - { - global $database; - $database->execute("DELETE FROM forum_posts WHERE id = ?", array($postID)); - } -} -?> + + * Alpha + * License: GPLv2 + * Description: Rough forum extension + * Documentation: + */ + +class Forum extends SimpleExtension { + public function onInitExt($event) { + global $config, $database; + + // shortcut to latest + + if ($config->get_int("forum_version") < 1) + { + $database->create_table("forum_threads", " + id SCORE_AIPK, + sticky SCORE_BOOL NOT NULL DEFAULT SCORE_BOOL_N, + title VARCHAR(255) NOT NULL, + user_id INTEGER NOT NULL, + date DATETIME NOT NULL, + uptodate DATETIME NOT NULL, + INDEX (date) + "); + + $database->create_table("forum_posts", + " id SCORE_AIPK, + thread_id INTEGER NOT NULL, + user_id INTEGER NOT NULL, + date DATETIME NOT NULL, + message TEXT, + INDEX (date), + FOREIGN KEY (thread_id) REFERENCES forum_threads (id) ON UPDATE CASCADE ON DELETE CASCADE + "); + + $config->set_int("forum_version", 1); + $config->set_int("forumTitleSubString", 25); + $config->set_int("forumThreadsPerPage", 15); + $config->set_int("forumPostsPerPage", 15); + + $config->set_int("forumMaxCharsPerPost", 512); + + log_info("forum", "extension installed"); + } + } + + public function onSetupBuilding(SetupBuildingEvent $event) { + $sb = new SetupBlock("Forum"); + $sb->add_int_option("forumTitleSubString", "Title max long: "); + $sb->add_int_option("forumThreadsPerPage", "
Threads per page: "); + $sb->add_int_option("forumPostsPerPage", "
Posts per page: "); + + $sb->add_int_option("forumMaxCharsPerPost", "
Max chars per post: "); + $event->panel->add_block($sb); + } + + public function onUserPageBuilding($event) { + global $page, $user, $database; + + $threads_count = $database->db->GetOne("SELECT COUNT(*) FROM forum_threads WHERE user_id=?", array($event->display_user->id)); + $posts_count = $database->db->GetOne("SELECT COUNT(*) FROM forum_posts WHERE user_id=?", array($event->display_user->id)); + + $days_old = ((time() - strtotime($event->display_user->join_date)) / 86400) + 1; + + $threads_rate = sprintf("%.1f", ($threads_count / $days_old)); + $posts_rate = sprintf("%.1f", ($posts_count / $days_old)); + + $event->add_stats("Forum threads: $threads_count, $threads_rate per day"); + $event->add_stats("Forum posts: $posts_count, $posts_rate per day"); + } + + + public function onPageRequest($event) { + global $page, $user; + + if($event->page_matches("forum")) { + switch($event->get_arg(0)) { + case "index": + { + $this->show_last_threads($page, $event, $user->is_admin()); + if(!$user->is_anonymous()) $this->theme->display_new_thread_composer($page); + break; + } + case "view": + { + $threadID = int_escape($event->get_arg(1)); + $pageNumber = int_escape($event->get_arg(2)); + + $this->show_posts($event, $user->is_admin()); + if($user->is_admin()) $this->theme->add_actions_block($page, $threadID); + if(!$user->is_anonymous()) $this->theme->display_new_post_composer($page, $threadID); + break; + } + case "new": + { + global $page; + $this->theme->display_new_thread_composer($page); + break; + } + case "create": + { + $redirectTo = "forum/index"; + if (!$user->is_anonymous()) + { + list($hasErrors, $errors) = $this->valid_values_for_new_thread(); + + if($hasErrors) + { + $this->theme->display_error($page, "Error", $errors); + $this->theme->display_new_thread_composer($page, $_POST["message"], $_POST["title"], false); + break; + } + + $newThreadID = $this->save_new_thread($user); + $this->save_new_post($newThreadID, $user); + $redirectTo = "forum/view/".$newThreadID."/1"; + } + + $page->set_mode("redirect"); + $page->set_redirect(make_link($redirectTo)); + + break; + } + case "delete": + $threadID = int_escape($event->get_arg(1)); + $postID = int_escape($event->get_arg(2)); + + if ($user->is_admin()) {$this->delete_post($postID);} + + $page->set_mode("redirect"); + $page->set_redirect(make_link("forum/view/".$threadID)); + break; + case "nuke": + $threadID = int_escape($event->get_arg(1)); + + if ($user->is_admin()) + $this->delete_thread($threadID); + + $page->set_mode("redirect"); + $page->set_redirect(make_link("forum/index")); + break; + case "answer": + if (!$user->is_anonymous()) + { + list($hasErrors, $errors) = $this->valid_values_for_new_post(); + + if ($hasErrors) + { + $this->theme->display_error($page, "Error", $errors); + $this->theme->display_new_post_composer($page, $_POST["threadID"], $_POST["message"], $_POST["title"], false); + break; + } + + $threadID = int_escape($_POST["threadID"]); + + $this->save_new_post($threadID, $user); + } + + $page->set_mode("redirect"); + $page->set_redirect(make_link("forum/view/".$threadID."/1")); + break; + default: + { + $page->set_mode("redirect"); + $page->set_redirect(make_link("forum/index")); + //$this->theme->display_error($page, "Invalid action", "You should check forum/index."); + break; + } + } + } + } + + private function get_total_pages_for_thread($threadID) + { + global $database, $config; + $result = $database->get_row("SELECT COUNT(1) AS count FROM forum_posts WHERE thread_id = ?", array($threadID)); + + return ceil($result["count"] / $config->get_int("forumPostsPerPage")); + } + + private function valid_values_for_new_thread() + { + $hasErrors = false; + + $errors = ""; + + if (!array_key_exists("title", $_POST)) + { + $hasErrors = true; + $errors .= "
No title supplied.
"; + } + else if (strlen($_POST["title"]) == 0) + { + $hasErrors = true; + $errors .= "
You cannot have an empty title.
"; + } + else if (strlen(mysql_real_escape_string(html_escape($_POST["title"]))) > 255) + { + $hasErrors = true; + $errors .= "
Your title is too long.
"; + } + + if (!array_key_exists("message", $_POST)) + { + $hasErrors = true; + $errors .= "
No message supplied.
"; + } + else if (strlen($_POST["message"]) == 0) + { + $hasErrors = true; + $errors .= "
You cannot have an empty message.
"; + } + + return array($hasErrors, $errors); + } + private function valid_values_for_new_post() + { + $hasErrors = false; + + $errors = ""; + if (!array_key_exists("threadID", $_POST)) + { + $hasErrors = true; + $errors = "
No thread ID supplied.
"; + } + else if (strlen($_POST["threadID"]) == 0) + { + $hasErrors = true; + $errors = "
No thread ID supplied.
"; + } + else if (is_numeric($_POST["threadID"])) + + if (!array_key_exists("message", $_POST)) + { + $hasErrors = true; + $errors .= "
No message supplied.
"; + } + else if (strlen($_POST["message"]) == 0) + { + $hasErrors = true; + $errors .= "
You cannot have an empty message.
"; + } + + return array($hasErrors, $errors); + } + private function get_thread_title($threadID) + { + global $database; + $result = $database->get_row("SELECT t.title FROM forum_threads AS t WHERE t.id = ? ", array($threadID)); + return $result["title"]; + } + + private function show_last_threads(Page $page, $event, $showAdminOptions = false) + { + global $config, $database; + $pageNumber = $event->get_arg(1); + if(is_null($pageNumber) || !is_numeric($pageNumber)) + $pageNumber = 0; + else if ($pageNumber <= 0) + $pageNumber = 0; + else + $pageNumber--; + + $threadsPerPage = $config->get_int('forumThreadsPerPage', 15); + + $threads = $database->get_all( + "SELECT f.id, f.sticky, f.title, f.date, f.uptodate, u.name AS user_name, u.email AS user_email, u.admin AS user_admin, sum(1) - 1 AS response_count ". + "FROM forum_threads AS f ". + "INNER JOIN users AS u ". + "ON f.user_id = u.id ". + "INNER JOIN forum_posts AS p ". + "ON p.thread_id = f.id ". + "GROUP BY f.id, f.sticky, f.title, f.date, u.name, u.email, u.admin ". + "ORDER BY f.sticky ASC, f.uptodate DESC LIMIT ?, ?" + , array($pageNumber * $threadsPerPage, $threadsPerPage) + ); + + $totalPages = ceil($database->db->GetOne("SELECT COUNT(*) FROM forum_threads") / $threadsPerPage); + + $this->theme->display_thread_list($page, $threads, $showAdminOptions, $pageNumber + 1, $totalPages); + } + + private function show_posts($event, $showAdminOptions = false) + { + global $config, $database, $user; + + $threadID = $event->get_arg(1); + $pageNumber = $event->get_arg(2); + if(is_null($pageNumber) || !is_numeric($pageNumber)) + $pageNumber = 0; + else if ($pageNumber <= 0) + $pageNumber = 0; + else + $pageNumber--; + + $postsPerPage = $config->get_int('forumPostsPerPage', 15); + + $posts = $database->get_all( + "SELECT p.id, p.date, p.message, u.name as user_name, u.email AS user_email, u.admin AS user_admin ". + "FROM forum_posts AS p ". + "INNER JOIN users AS u ". + "ON p.user_id = u.id ". + "WHERE thread_id = ? ". + "ORDER BY p.date ASC ". + "LIMIT ?, ? " + , array($threadID, $pageNumber * $postsPerPage, $postsPerPage) + ); + + $totalPages = ceil($database->db->GetOne("SELECT COUNT(*) FROM forum_posts WHERE thread_id = ?", array($threadID)) / $postsPerPage); + + $threadTitle = $this->get_thread_title($threadID); + + $this->theme->display_thread($posts, $showAdminOptions, $threadTitle, $threadID, $pageNumber + 1, $totalPages); + } + + private function save_new_thread($user) + { + $title = mysql_real_escape_string(html_escape($_POST["title"])); + $sticky = html_escape($_POST["sticky"]); + + if($sticky == ""){ + $sticky = "N"; + } + + global $database; + $database->execute(" + INSERT INTO forum_threads + (title, sticky, user_id, date, uptodate) + VALUES + (?, ?, ?, now(), now())", + array($title, $sticky, $user->id)); + + $result = $database->get_row("SELECT LAST_INSERT_ID() AS threadID", array()); + + log_info("forum", "Thread {$result["threadID"]} created by {$user->name}"); + + return $result["threadID"]; + } + + private function save_new_post($threadID, $user) + { + global $config; + $userID = $user->id; + $message = mysql_real_escape_string(html_escape($_POST["message"])); + + $max_characters = $config->get_int('forumMaxCharsPerPost'); + $message = substr($message, 0, $max_characters); + + global $database; + $database->execute("INSERT INTO forum_posts + (thread_id, user_id, date, message) + VALUES + (?, ?, now(), ?)" + , array($threadID, $userID, $message)); + + $result = $database->get_row("SELECT LAST_INSERT_ID() AS postID", array()); + + log_info("forum", "Post {$result["postID"]} created by {$user->name}"); + + $database->execute("UPDATE forum_threads SET uptodate=now() WHERE id=?", array ($threadID)); + } + + private function retrieve_posts($threadID, $pageNumber) + { + global $database, $config; + $postsPerPage = $config->get_int('forumPostsPerPage', 15); + + return $database->get_all( + "SELECT p.id, p.date, p.message, u.name as user_name, u.email AS user_email, u.admin AS user_admin ". + "FROM forum_posts AS p ". + "INNER JOIN users AS u ". + "ON p.user_id = u.id ". + "WHERE thread_id = ? ". + "ORDER BY p.date ASC ". + "LIMIT ?, ? " + , array($threadID, ($pageNumber - 1) * $postsPerPage, $postsPerPage)); + } + + private function delete_thread($threadID) + { + global $database; + $database->execute("DELETE FROM forum_threads WHERE id = ?", array($threadID)); + $database->execute("DELETE FROM forum_posts WHERE thread_id = ?", array($threadID)); + } + + private function delete_post($postID) + { + global $database; + $database->execute("DELETE FROM forum_posts WHERE id = ?", array($postID)); + } +} +?> diff --git a/contrib/forum/theme.php b/contrib/forum/theme.php index d31490e9..d3c83f41 100644 --- a/contrib/forum/theme.php +++ b/contrib/forum/theme.php @@ -1,229 +1,229 @@ -make_thread_list($threads, $showAdminOptions); - - $page->set_title(html_escape("Forum")); - $page->set_heading(html_escape("Forum")); - $page->add_block(new Block("Forum", $html, "main", 10)); - - $this->display_paginator($page, "forum/index", null, $pageNumber, $totalPages); - } - - - - public function display_new_thread_composer(Page $page, $threadText = null, $threadTitle = null) - { - global $config, $user; - $max_characters = $config->get_int('forumMaxCharsPerPost'); - $postUrl = make_link("forum/create"); - $html = '
'; - - - if (!is_null($threadTitle)) - $threadTitle = html_escape($threadTitle); - - if(!is_null($threadText)) - $threadText = html_escape($threadText); - - $html .= " - - - - "; - if($user->is_admin()){ - $html .= ""; - } - $html .= " -
Title:
Message:
Max characters alowed: $max_characters.
-
- "; - - $blockTitle = "Write a new thread"; - $page->set_title(html_escape($blockTitle)); - $page->set_heading(html_escape($blockTitle)); - $page->add_block(new Block($blockTitle, $html, "main", 20)); - } - - - - public function display_new_post_composer(Page $page, $threadID) - { - global $config; - - $max_characters = $config->get_int('forumMaxCharsPerPost'); - - $postUrl = make_link("forum/answer"); - $html = '
'; - - $html .= ''; - - $html .= " - - - "; - - $html .= " -
Message: -
Max characters alowed: $max_characters.
-
- "; - - $blockTitle = "Answer to this thread"; - $page->add_block(new Block($blockTitle, $html, "main", 30)); - } - - - - public function display_thread($posts, $showAdminOptions, $threadTitle, $threadID, $pageNumber, $totalPages) - { - global $config, $page/*, $user*/; - - $theme_name = $config->get_string('theme'); - $data_href = $config->get_string('base_href'); - $base_href = $config->get_string('base_href'); - - $html = ""; - $n = 0; - - $html = "". - "". - "". - "". - ""; - - foreach ($posts as $post) - { - $message = $post["message"]; - - $tfe = new TextFormattingEvent($message); - send_event($tfe); - $message = $tfe->formatted; - - $message = str_replace('\n\r', '
', $message); - $message = str_replace('\r\n', '
', $message); - $message = str_replace('\n', '
', $message); - $message = str_replace('\r', '
', $message); - - $message = stripslashes($message); - - $user = "".$post["user_name"].""; - - $poster = User::by_name($post["user_name"]); - $gravatar = $poster->get_avatar_html(); - - $oe = ($n++ % 2 == 0) ? "even" : "odd"; - - if ($post["user_admin"] == "Y") { - $rank = "admin"; - } else { - $rank = "user"; - } - - $postID = $post['id']; - - //if($user->is_admin()){ - //$delete_link = "Delete"; - //} else { - //$delete_link = ""; - //} - - if($showAdminOptions){ - $delete_link = "Delete"; - }else{ - $delete_link = ""; - } - - $html .= "". - "". - ""." - - - - "; - - } - - $html .= "
UserMessage
".$user."
".$rank."
".$gravatar."
".$message."
".autodate($post["date"])."".$delete_link."
"; - - $this->display_paginator($page, "forum/view/".$threadID, null, $pageNumber, $totalPages); - - $page->set_title(html_escape($threadTitle)); - $page->set_heading(html_escape($threadTitle)); - $page->add_block(new Block("Thread", $html, "main", 20)); - - } - - - - public function add_actions_block(Page $page, $threadID) - { - $html = 'Delete this thread and its posts.'; - - $page->add_block(new Block("Admin Actions", $html, "main", 40)); - } - - - - private function make_thread_list($threads, $showAdminOptions) - { - $html = "". - "". - "". - "". - "". - ""; - - if($showAdminOptions) - { - $html .= ""; - } - - $html .= ""; - - - $n = 0; - foreach($threads as $thread) - { - $oe = ($n++ % 2 == 0) ? "even" : "odd"; - - global $config; - $titleSubString = $config->get_int('forumTitleSubString'); - - if ($titleSubString < strlen($thread["title"])) - { - $title = substr($thread["title"], 0, $titleSubString); - $title = $title."..."; - } else { - $title = $thread["title"]; - } - - if($thread["sticky"] == "Y"){ - $sticky = "Sticky: "; - } else { - $sticky = ""; - } - - $html .= "". - '". - '". - "". - ""; - - if ($showAdminOptions) - $html .= ''; - - $html .= ""; - } - - $html .= "
TitleAuthorUpdatedResponsesActions
'.$sticky.''.$title."'.$thread["user_name"]."".autodate($thread["uptodate"])."".$thread["response_count"]."Delete
"; - - return $html; - } -} +make_thread_list($threads, $showAdminOptions); + + $page->set_title(html_escape("Forum")); + $page->set_heading(html_escape("Forum")); + $page->add_block(new Block("Forum", $html, "main", 10)); + + $this->display_paginator($page, "forum/index", null, $pageNumber, $totalPages); + } + + + + public function display_new_thread_composer(Page $page, $threadText = null, $threadTitle = null) + { + global $config, $user; + $max_characters = $config->get_int('forumMaxCharsPerPost'); + $postUrl = make_link("forum/create"); + $html = '
'; + + + if (!is_null($threadTitle)) + $threadTitle = html_escape($threadTitle); + + if(!is_null($threadText)) + $threadText = html_escape($threadText); + + $html .= " + + + + "; + if($user->is_admin()){ + $html .= ""; + } + $html .= " +
Title:
Message:
Max characters alowed: $max_characters.
+
+ "; + + $blockTitle = "Write a new thread"; + $page->set_title(html_escape($blockTitle)); + $page->set_heading(html_escape($blockTitle)); + $page->add_block(new Block($blockTitle, $html, "main", 20)); + } + + + + public function display_new_post_composer(Page $page, $threadID) + { + global $config; + + $max_characters = $config->get_int('forumMaxCharsPerPost'); + + $postUrl = make_link("forum/answer"); + $html = '
'; + + $html .= ''; + + $html .= " + + + "; + + $html .= " +
Message: +
Max characters alowed: $max_characters.
+
+ "; + + $blockTitle = "Answer to this thread"; + $page->add_block(new Block($blockTitle, $html, "main", 30)); + } + + + + public function display_thread($posts, $showAdminOptions, $threadTitle, $threadID, $pageNumber, $totalPages) + { + global $config, $page/*, $user*/; + + $theme_name = $config->get_string('theme'); + $data_href = $config->get_string('base_href'); + $base_href = $config->get_string('base_href'); + + $html = ""; + $n = 0; + + $html = "". + "". + "". + "". + ""; + + foreach ($posts as $post) + { + $message = $post["message"]; + + $tfe = new TextFormattingEvent($message); + send_event($tfe); + $message = $tfe->formatted; + + $message = str_replace('\n\r', '
', $message); + $message = str_replace('\r\n', '
', $message); + $message = str_replace('\n', '
', $message); + $message = str_replace('\r', '
', $message); + + $message = stripslashes($message); + + $user = "".$post["user_name"].""; + + $poster = User::by_name($post["user_name"]); + $gravatar = $poster->get_avatar_html(); + + $oe = ($n++ % 2 == 0) ? "even" : "odd"; + + if ($post["user_admin"] == "Y") { + $rank = "admin"; + } else { + $rank = "user"; + } + + $postID = $post['id']; + + //if($user->is_admin()){ + //$delete_link = "Delete"; + //} else { + //$delete_link = ""; + //} + + if($showAdminOptions){ + $delete_link = "Delete"; + }else{ + $delete_link = ""; + } + + $html .= "". + "". + ""." + + + + "; + + } + + $html .= "
UserMessage
".$user."
".$rank."
".$gravatar."
".$message."
".autodate($post["date"])."".$delete_link."
"; + + $this->display_paginator($page, "forum/view/".$threadID, null, $pageNumber, $totalPages); + + $page->set_title(html_escape($threadTitle)); + $page->set_heading(html_escape($threadTitle)); + $page->add_block(new Block("Thread", $html, "main", 20)); + + } + + + + public function add_actions_block(Page $page, $threadID) + { + $html = 'Delete this thread and its posts.'; + + $page->add_block(new Block("Admin Actions", $html, "main", 40)); + } + + + + private function make_thread_list($threads, $showAdminOptions) + { + $html = "". + "". + "". + "". + "". + ""; + + if($showAdminOptions) + { + $html .= ""; + } + + $html .= ""; + + + $n = 0; + foreach($threads as $thread) + { + $oe = ($n++ % 2 == 0) ? "even" : "odd"; + + global $config; + $titleSubString = $config->get_int('forumTitleSubString'); + + if ($titleSubString < strlen($thread["title"])) + { + $title = substr($thread["title"], 0, $titleSubString); + $title = $title."..."; + } else { + $title = $thread["title"]; + } + + if($thread["sticky"] == "Y"){ + $sticky = "Sticky: "; + } else { + $sticky = ""; + } + + $html .= "". + '". + '". + "". + ""; + + if ($showAdminOptions) + $html .= ''; + + $html .= ""; + } + + $html .= "
TitleAuthorUpdatedResponsesActions
'.$sticky.''.$title."'.$thread["user_name"]."".autodate($thread["uptodate"])."".$thread["response_count"]."Delete
"; + + return $html; + } +} ?> \ No newline at end of file diff --git a/contrib/notes/theme.php b/contrib/notes/theme.php index bb782cb9..f6d72111 100644 --- a/contrib/notes/theme.php +++ b/contrib/notes/theme.php @@ -1,374 +1,374 @@ - - function confirm_action() { - var r=confirm("Are You Sure?"); - if (r==true) { - return true; - } - else { - return false; - } - } - - - - -
- - -
- '; - } - public function request_button($image_id) { - return ' - -
- - -
- '; - } - public function nuke_notes_button($image_id) { - return ' -
- - -
- '; - } - public function nuke_requests_button($image_id) { - return ' - -
- - -
- '; - } - - public function search_notes_page(Page $page) { //IN DEVELOPMENT, NOT FULLY WORKING - $html = '
- - -
'; - - $page->set_title(html_escape("Search Note")); - $page->set_heading(html_escape("Search Note")); - $page->add_block(new Block("Search Note", $html, "main", 10)); - } - - // check action POST on form - public function display_note_system(Page $page, $image_id, $recovered_notes, $adminOptions) { - $html = " - -
-
- - - - - - - - - - - - - - -
- -
- -
-
-
-
- - - - - - - - - - - - - - -
- -
-
"; - - if($adminOptions) - $html .= " -
- - - - - - -
-
-"; - - $html .= "
"; - - $page->add_block(new Block(null, $html, "main", 1)); - } - - - public function display_note_list($images, $pageNumber, $totalPages) { - global $page; - $pool_images = ''; - foreach($images as $pair) { - $image = $pair[0]; - - $thumb_html = $this->build_thumb_html($image); - - $pool_images .= ''. - ''.$thumb_html.''. - ''; - - - } - $this->display_paginator($page, "note/list", null, $pageNumber, $totalPages); - - $page->set_title("Notes"); - $page->set_heading("Notes"); - $page->add_block(new Block("Notes", $pool_images, "main", 20)); - } - - public function display_note_requests($images, $pageNumber, $totalPages) { - global $page; - $pool_images = ''; - foreach($images as $pair) { - $image = $pair[0]; - - $thumb_html = $this->build_thumb_html($image); - - $pool_images .= ''. - ''.$thumb_html.''. - ''; - - - } - $this->display_paginator($page, "requests/list", null, $pageNumber, $totalPages); - - $page->set_title("Note Requests"); - $page->set_heading("Note Requests"); - $page->add_block(new Block("Note Requests", $pool_images, "main", 20)); - } - - public function display_histories($histories, $pageNumber, $totalPages) { - global $user, $page; - - $html = "". - "". - "". - "". - "". - "". - ""; - - - if(!$user->is_anonymous()){ - $html .= ""; - } - - $html .= "". - ""; - - $n = 0; - foreach($histories as $history) { - $oe = ($n++ % 2 == 0) ? "even" : "odd"; - - $image_link = "".$history['image_id'].""; - $history_link = "".$history['note_id'].".".$history['review_id'].""; - $user_link = "".$history['user_name'].""; - $revert_link = "Revert"; - - $html .= "". - "". - "". - "". - "". - ""; - - if(!$user->is_anonymous()){ - $html .= ""; - } - - } - - $html .= "
ImageNoteBodyUpdaterDateAction
".$image_link."".$history_link."".$history['note']."".$user_link."".autodate($history['date'])."".$revert_link."
"; - - $page->set_title("Note Updates"); - $page->set_heading("Note Updates"); - $page->add_block(new Block("Note Updates", $html, "main", 10)); - - $this->display_paginator($page, "note/updated", null, $pageNumber, $totalPages); - } - - public function display_history($histories, $pageNumber, $totalPages) { - global $user, $page; - - $html = "". - "". - "". - "". - "". - "". - ""; - - - if(!$user->is_anonymous()){ - $html .= ""; - } - - $html .= "". - ""; - - $n = 0; - foreach($histories as $history) { - $oe = ($n++ % 2 == 0) ? "even" : "odd"; - - $image_link = "".$history['image_id'].""; - $history_link = "".$history['note_id'].".".$history['review_id'].""; - $user_link = "".$history['user_name'].""; - $revert_link = "Revert"; - - $html .= "". - "". - "". - "". - "". - ""; - - if(!$user->is_anonymous()){ - $html .= ""; - } - - } - - $html .= "
ImageNoteBodyUpdaterDateAction
".$image_link."".$history_link."".$history['note']."".$user_link."".autodate($history['date'])."".$revert_link."
"; - - $page->set_title("Note History"); - $page->set_heading("Note History"); - $page->add_block(new Block("Note History", $html, "main", 10)); - - $this->display_paginator($page, "note/updated", null, $pageNumber, $totalPages); - } - - } + + function confirm_action() { + var r=confirm("Are You Sure?"); + if (r==true) { + return true; + } + else { + return false; + } + } + + + + +
+ + +
+ '; + } + public function request_button($image_id) { + return ' + +
+ + +
+ '; + } + public function nuke_notes_button($image_id) { + return ' +
+ + +
+ '; + } + public function nuke_requests_button($image_id) { + return ' + +
+ + +
+ '; + } + + public function search_notes_page(Page $page) { //IN DEVELOPMENT, NOT FULLY WORKING + $html = '
+ + +
'; + + $page->set_title(html_escape("Search Note")); + $page->set_heading(html_escape("Search Note")); + $page->add_block(new Block("Search Note", $html, "main", 10)); + } + + // check action POST on form + public function display_note_system(Page $page, $image_id, $recovered_notes, $adminOptions) { + $html = " + +
+
+ + + + + + + + + + + + + + +
+ +
+ +
+
+
+
+ + + + + + + + + + + + + + +
+ +
+
"; + + if($adminOptions) + $html .= " +
+ + + + + + +
+
+"; + + $html .= "
"; + + $page->add_block(new Block(null, $html, "main", 1)); + } + + + public function display_note_list($images, $pageNumber, $totalPages) { + global $page; + $pool_images = ''; + foreach($images as $pair) { + $image = $pair[0]; + + $thumb_html = $this->build_thumb_html($image); + + $pool_images .= ''. + ''.$thumb_html.''. + ''; + + + } + $this->display_paginator($page, "note/list", null, $pageNumber, $totalPages); + + $page->set_title("Notes"); + $page->set_heading("Notes"); + $page->add_block(new Block("Notes", $pool_images, "main", 20)); + } + + public function display_note_requests($images, $pageNumber, $totalPages) { + global $page; + $pool_images = ''; + foreach($images as $pair) { + $image = $pair[0]; + + $thumb_html = $this->build_thumb_html($image); + + $pool_images .= ''. + ''.$thumb_html.''. + ''; + + + } + $this->display_paginator($page, "requests/list", null, $pageNumber, $totalPages); + + $page->set_title("Note Requests"); + $page->set_heading("Note Requests"); + $page->add_block(new Block("Note Requests", $pool_images, "main", 20)); + } + + public function display_histories($histories, $pageNumber, $totalPages) { + global $user, $page; + + $html = "". + "". + "". + "". + "". + "". + ""; + + + if(!$user->is_anonymous()){ + $html .= ""; + } + + $html .= "". + ""; + + $n = 0; + foreach($histories as $history) { + $oe = ($n++ % 2 == 0) ? "even" : "odd"; + + $image_link = "".$history['image_id'].""; + $history_link = "".$history['note_id'].".".$history['review_id'].""; + $user_link = "".$history['user_name'].""; + $revert_link = "Revert"; + + $html .= "". + "". + "". + "". + "". + ""; + + if(!$user->is_anonymous()){ + $html .= ""; + } + + } + + $html .= "
ImageNoteBodyUpdaterDateAction
".$image_link."".$history_link."".$history['note']."".$user_link."".autodate($history['date'])."".$revert_link."
"; + + $page->set_title("Note Updates"); + $page->set_heading("Note Updates"); + $page->add_block(new Block("Note Updates", $html, "main", 10)); + + $this->display_paginator($page, "note/updated", null, $pageNumber, $totalPages); + } + + public function display_history($histories, $pageNumber, $totalPages) { + global $user, $page; + + $html = "". + "". + "". + "". + "". + "". + ""; + + + if(!$user->is_anonymous()){ + $html .= ""; + } + + $html .= "". + ""; + + $n = 0; + foreach($histories as $history) { + $oe = ($n++ % 2 == 0) ? "even" : "odd"; + + $image_link = "".$history['image_id'].""; + $history_link = "".$history['note_id'].".".$history['review_id'].""; + $user_link = "".$history['user_name'].""; + $revert_link = "Revert"; + + $html .= "". + "". + "". + "". + "". + ""; + + if(!$user->is_anonymous()){ + $html .= ""; + } + + } + + $html .= "
ImageNoteBodyUpdaterDateAction
".$image_link."".$history_link."".$history['note']."".$user_link."".autodate($history['date'])."".$revert_link."
"; + + $page->set_title("Note History"); + $page->set_heading("Note History"); + $page->add_block(new Block("Note History", $html, "main", 10)); + + $this->display_paginator($page, "note/updated", null, $pageNumber, $totalPages); + } + + } ?> \ No newline at end of file diff --git a/contrib/sitemap/main.php b/contrib/sitemap/main.php index 8052ce39..306c3085 100644 --- a/contrib/sitemap/main.php +++ b/contrib/sitemap/main.php @@ -1,54 +1,54 @@ - - * License: GPLv2 - * Description: Adds sitemap.xml on request. - * Documentation: - */ - -class XMLSitemap extends SimpleExtension { - public function onPageRequest($event) { - if($event->page_matches("sitemap.xml")) { - $images = Image::find_images(0, 50, array()); - $this->do_xml($images); - } - } - - private function do_xml($images) { - global $page; - $page->set_mode("data"); - $page->set_type("application/xml"); - - $data = ""; - foreach($images as $image) { - $link = make_http(make_link("post/view/{$image->id}")); - $posted = date("Y-m-d", $image->posted_timestamp); - - $data .= " - - $link - $posted - monthly - 0.8 - - "; - } - - $base_href = make_http(make_link("post/list")); - - $xml = "<"."?xml version=\"1.0\" encoding=\"utf-8\"?"."> - - - $base_href - 2009-01-01 - monthly - 1 - - $data - - "; - $page->set_data($xml); - } -} -?> + + * License: GPLv2 + * Description: Adds sitemap.xml on request. + * Documentation: + */ + +class XMLSitemap extends SimpleExtension { + public function onPageRequest($event) { + if($event->page_matches("sitemap.xml")) { + $images = Image::find_images(0, 50, array()); + $this->do_xml($images); + } + } + + private function do_xml($images) { + global $page; + $page->set_mode("data"); + $page->set_type("application/xml"); + + $data = ""; + foreach($images as $image) { + $link = make_http(make_link("post/view/{$image->id}")); + $posted = date("Y-m-d", $image->posted_timestamp); + + $data .= " + + $link + $posted + monthly + 0.8 + + "; + } + + $base_href = make_http(make_link("post/list")); + + $xml = "<"."?xml version=\"1.0\" encoding=\"utf-8\"?"."> + + + $base_href + 2009-01-01 + monthly + 1 + + $data + + "; + $page->set_data($xml); + } +} +?> diff --git a/contrib/tag_history/main.php b/contrib/tag_history/main.php index 2ce64339..6ebe9fe2 100644 --- a/contrib/tag_history/main.php +++ b/contrib/tag_history/main.php @@ -1,219 +1,219 @@ - - * Description: Keep a record of tag changes - */ - -class Tag_History implements Extension { - var $theme; - - public function receive_event(Event $event) { - global $config, $database, $page, $user; - if(is_null($this->theme)) $this->theme = get_theme_object($this); - - 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(); - } - } - - if(($event instanceof PageRequestEvent) && $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']); - } - } - 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)); - } - else { - $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); - } - } - - protected function install() - { - global $database; - global $config; - - if($config->get_int("ext_tag_history_version") < 1) { - $database->create_table("tag_histories", " - id SCORE_AIPK, - image_id INTEGER NOT NULL, - user_id INTEGER NOT NULL, - user_ip SCORE_INET NOT NULL, - tags TEXT NOT NULL, - date_set DATETIME NOT NULL, - INDEX(image_id), - FOREIGN KEY (image_id) REFERENCES images(id) ON DELETE CASCADE, - FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE - "); - $config->set_int("ext_tag_history_version", 3); - } - - if($config->get_int("ext_tag_history_version") == 1) { - $database->Execute("ALTER TABLE tag_histories ADD COLUMN user_id INTEGER NOT NULL"); - $database->Execute("ALTER TABLE tag_histories ADD COLUMN date_set DATETIME NOT NULL"); - $config->set_int("ext_tag_history_version", 2); - } - - if($config->get_int("ext_tag_history_version") == 2) { - $database->Execute("ALTER TABLE tag_histories ADD COLUMN user_ip CHAR(15) NOT NULL"); - $config->set_int("ext_tag_history_version", 3); - } - } - - /* - * this function is called when a revert request is received - */ - private function process_revert_request($revert_id) - { - global $page; - // check for the nothing case - if($revert_id=="nothing") - { - // tried to set it too the same thing so ignore it (might be a bot) - // go back to the index page with you - $page->set_mode("redirect"); - $page->set_redirect(make_link()); - return; - } - - $revert_id = int_escape($revert_id); - - // lets get this revert id assuming it exists - $result = $this->get_tag_history_from_revert($revert_id); - - if($result==null) - { - // there is no history entry with that id so either the image was deleted - // while the user was viewing the history, someone is playing with form - // variables or we have messed up in code somewhere. - die("Error: No tag history with specified id was found."); - } - - // lets get the values out of the result - $stored_result_id = $result->fields['id']; - $stored_image_id = $result->fields['image_id']; - $stored_tags = $result->fields['tags']; - - // all should be ok so we can revert by firing the SetUserTags event. - send_event(new TagSetEvent(Image::by_id($stored_image_id), $stored_tags)); - - // all should be done now so redirect the user back to the image - $page->set_mode("redirect"); - $page->set_redirect(make_link("post/view/$stored_image_id")); - } - - public function get_tag_history_from_revert($revert_id) - { - global $database; - $row = $database->execute(" - SELECT tag_histories.*, users.name - FROM tag_histories - JOIN users ON tag_histories.user_id = users.id - WHERE tag_histories.id = ?", array($revert_id)); - return ($row ? $row : null); - } - - public function get_tag_history_from_id($image_id) - { - global $database; - $row = $database->get_all(" - SELECT tag_histories.*, users.name - FROM tag_histories - JOIN users ON tag_histories.user_id = users.id - WHERE image_id = ? - ORDER BY tag_histories.id DESC", - array($image_id)); - return ($row ? $row : array()); - } - - public function get_global_tag_history() - { - global $database; - $row = $database->get_all(" - SELECT tag_histories.*, users.name - FROM tag_histories - JOIN users ON tag_histories.user_id = users.id - ORDER BY tag_histories.id DESC - LIMIT 100"); - return ($row ? $row : array()); - } - - /* - * this function is called when an image has been deleted - */ - private function delete_all_tag_history($image_id) - { - global $database; - $database->execute("DELETE FROM tag_histories WHERE image_id = ?", array($image_id)); - } - - /* - * this function is called just before an images tag are changed - */ - private function add_tag_history($image, $tags) - { - global $database; - global $config; - global $user; - - $new_tags = Tag::implode($tags); - $old_tags = Tag::implode($image->get_tag_array()); - if($new_tags == $old_tags) return; - - // add a history entry - $allowed = $config->get_int("history_limit"); - if($allowed == 0) return; - - $row = $database->execute(" - INSERT INTO tag_histories(image_id, tags, user_id, user_ip, date_set) - VALUES (?, ?, ?, ?, now())", - array($image->id, $new_tags, $user->id, $_SERVER['REMOTE_ADDR'])); - - // if needed remove oldest one - if($allowed == -1) return; - $entries = $database->db->GetOne("SELECT COUNT(*) FROM tag_histories WHERE image_id = ?", array($image->id)); - if($entries > $allowed) - { - // TODO: Make these queries better - $min_id = $database->db->GetOne("SELECT MIN(id) FROM tag_histories WHERE image_id = ?", array($image->id)); - $database->execute("DELETE FROM tag_histories WHERE id = ?", array($min_id)); - } - } -} -add_event_listener(new Tag_History(), 40); // in before tags are actually set, so that "get current tags" works -?> + + * Description: Keep a record of tag changes + */ + +class Tag_History implements Extension { + var $theme; + + public function receive_event(Event $event) { + global $config, $database, $page, $user; + if(is_null($this->theme)) $this->theme = get_theme_object($this); + + 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(); + } + } + + if(($event instanceof PageRequestEvent) && $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']); + } + } + 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)); + } + else { + $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); + } + } + + protected function install() + { + global $database; + global $config; + + if($config->get_int("ext_tag_history_version") < 1) { + $database->create_table("tag_histories", " + id SCORE_AIPK, + image_id INTEGER NOT NULL, + user_id INTEGER NOT NULL, + user_ip SCORE_INET NOT NULL, + tags TEXT NOT NULL, + date_set DATETIME NOT NULL, + INDEX(image_id), + FOREIGN KEY (image_id) REFERENCES images(id) ON DELETE CASCADE, + FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE + "); + $config->set_int("ext_tag_history_version", 3); + } + + if($config->get_int("ext_tag_history_version") == 1) { + $database->Execute("ALTER TABLE tag_histories ADD COLUMN user_id INTEGER NOT NULL"); + $database->Execute("ALTER TABLE tag_histories ADD COLUMN date_set DATETIME NOT NULL"); + $config->set_int("ext_tag_history_version", 2); + } + + if($config->get_int("ext_tag_history_version") == 2) { + $database->Execute("ALTER TABLE tag_histories ADD COLUMN user_ip CHAR(15) NOT NULL"); + $config->set_int("ext_tag_history_version", 3); + } + } + + /* + * this function is called when a revert request is received + */ + private function process_revert_request($revert_id) + { + global $page; + // check for the nothing case + if($revert_id=="nothing") + { + // tried to set it too the same thing so ignore it (might be a bot) + // go back to the index page with you + $page->set_mode("redirect"); + $page->set_redirect(make_link()); + return; + } + + $revert_id = int_escape($revert_id); + + // lets get this revert id assuming it exists + $result = $this->get_tag_history_from_revert($revert_id); + + if($result==null) + { + // there is no history entry with that id so either the image was deleted + // while the user was viewing the history, someone is playing with form + // variables or we have messed up in code somewhere. + die("Error: No tag history with specified id was found."); + } + + // lets get the values out of the result + $stored_result_id = $result->fields['id']; + $stored_image_id = $result->fields['image_id']; + $stored_tags = $result->fields['tags']; + + // all should be ok so we can revert by firing the SetUserTags event. + send_event(new TagSetEvent(Image::by_id($stored_image_id), $stored_tags)); + + // all should be done now so redirect the user back to the image + $page->set_mode("redirect"); + $page->set_redirect(make_link("post/view/$stored_image_id")); + } + + public function get_tag_history_from_revert($revert_id) + { + global $database; + $row = $database->execute(" + SELECT tag_histories.*, users.name + FROM tag_histories + JOIN users ON tag_histories.user_id = users.id + WHERE tag_histories.id = ?", array($revert_id)); + return ($row ? $row : null); + } + + public function get_tag_history_from_id($image_id) + { + global $database; + $row = $database->get_all(" + SELECT tag_histories.*, users.name + FROM tag_histories + JOIN users ON tag_histories.user_id = users.id + WHERE image_id = ? + ORDER BY tag_histories.id DESC", + array($image_id)); + return ($row ? $row : array()); + } + + public function get_global_tag_history() + { + global $database; + $row = $database->get_all(" + SELECT tag_histories.*, users.name + FROM tag_histories + JOIN users ON tag_histories.user_id = users.id + ORDER BY tag_histories.id DESC + LIMIT 100"); + return ($row ? $row : array()); + } + + /* + * this function is called when an image has been deleted + */ + private function delete_all_tag_history($image_id) + { + global $database; + $database->execute("DELETE FROM tag_histories WHERE image_id = ?", array($image_id)); + } + + /* + * this function is called just before an images tag are changed + */ + private function add_tag_history($image, $tags) + { + global $database; + global $config; + global $user; + + $new_tags = Tag::implode($tags); + $old_tags = Tag::implode($image->get_tag_array()); + if($new_tags == $old_tags) return; + + // add a history entry + $allowed = $config->get_int("history_limit"); + if($allowed == 0) return; + + $row = $database->execute(" + INSERT INTO tag_histories(image_id, tags, user_id, user_ip, date_set) + VALUES (?, ?, ?, ?, now())", + array($image->id, $new_tags, $user->id, $_SERVER['REMOTE_ADDR'])); + + // if needed remove oldest one + if($allowed == -1) return; + $entries = $database->db->GetOne("SELECT COUNT(*) FROM tag_histories WHERE image_id = ?", array($image->id)); + if($entries > $allowed) + { + // TODO: Make these queries better + $min_id = $database->db->GetOne("SELECT MIN(id) FROM tag_histories WHERE image_id = ?", array($image->id)); + $database->execute("DELETE FROM tag_histories WHERE id = ?", array($min_id)); + } + } +} +add_event_listener(new Tag_History(), 40); // in before tags are actually set, so that "get current tags" works +?> diff --git a/contrib/tips/main.php b/contrib/tips/main.php index 02e7e90c..724b45d1 100644 --- a/contrib/tips/main.php +++ b/contrib/tips/main.php @@ -1,174 +1,174 @@ - - * License: GPLv2 - * Description: Show a random line of text in the subheader space - * Documentation: - * Formatting is done with HTML - */ - -class Tips extends SimpleExtension { - public function onInitExt($event) { - global $config, $database; - - if ($config->get_int("ext_tips_version") < 1){ - $database->create_table("tips", " - id SCORE_AIPK, - enable SCORE_BOOL NOT NULL DEFAULT SCORE_BOOL_N, - image TEXT NOT NULL, - text TEXT NOT NULL, - INDEX (id) - "); - - $database->execute(" - INSERT INTO tips (enable, image, text) - VALUES (?, ?, ?)", - array("Y", "coins.png", "Do you like this extension? Please support us for developing new ones. Donate through paypal.")); - - $config->set_int("ext_tips_version", 1); - log_info("tips", "extension installed"); - } - } - - public function onPageRequest($event) { - global $page, $user; - - $this->getTip(); - - if($event->page_matches("tips")) { - switch($event->get_arg(0)) { - case "list": - { - if($user->is_admin()) { - $this->manageTips(); - $this->getAll(); - } - break; - } - case "new": - { - break; - } - case "save": - { - if($user->is_admin()) { - $this->saveTip(); - - $page->set_mode("redirect"); - $page->set_redirect(make_link("tips/list")); - } - break; - } - case "status": - { - if($user->is_admin()) { - $tipID = int_escape($event->get_arg(1)); - $this->setStatus($tipID); - - $page->set_mode("redirect"); - $page->set_redirect(make_link("tips/list")); - } - break; - } - case "delete": - { - if($user->is_admin()) { - $tipID = int_escape($event->get_arg(1)); - $this->deleteTip($tipID); - - $page->set_mode("redirect"); - $page->set_redirect(make_link("tips/list")); - } - break; - } - } - } - } - - public function onUserBlockBuilding($event) { - global $user; - if($user->is_admin()) { - $event->add_link("Tips Editor", make_link("tips/list")); - } - } - - private function manageTips() { - $data_href = get_base_href(); - $url = $data_href."/ext/tips/images/"; - - $dirPath = dir('./ext/tips/images'); - $images = array(); - while(($file = $dirPath->read()) !== false) { - if($file[0] != ".") { - $images[] = trim($file); - } - } - $dirPath->close(); - sort($images); - - $this->theme->manageTips($url, $images); - } - - private function saveTip() { - global $database; - - $enable = isset($_POST["enable"]) ? "Y" : "N"; - $image = html_escape($_POST["image"]); - $text = $_POST["text"]; - - $database->execute(" - INSERT INTO tips (enable, image, text) - VALUES (?, ?, ?)", - array($enable, $image, $text)); - - } - - private function getTip() { - global $database; - - $data_href = get_base_href(); - $url = $data_href."/ext/tips/images/"; - - $tip = $database->get_row("SELECT * ". - "FROM tips ". - "WHERE enable = 'Y' ". - "ORDER BY RAND() ". - "LIMIT 1"); - - if($tip) { - $this->theme->showTip($url, $tip); - } - } - - private function getAll() { - global $database; - - $data_href = get_base_href(); - $url = $data_href."/ext/tips/images/"; - - $tips = $database->get_all("SELECT * FROM tips ORDER BY id ASC"); - - $this->theme->showAll($url, $tips); - } - - private function setStatus($tipID) { - global $database; - - $tip = $database->get_row("SELECT * FROM tips WHERE id = ? ", array($tipID)); - - if($tip['enable'] == "Y") { - $enable = "N"; - } elseif($tip['enable'] == "N") { - $enable = "Y"; - } - - $database->execute("UPDATE tips SET enable = ? WHERE id = ?", array ($enable, $tipID)); - } - - private function deleteTip($tipID) { - global $database; - $database->execute("DELETE FROM tips WHERE id = ?", array($tipID)); - } -} -?> + + * License: GPLv2 + * Description: Show a random line of text in the subheader space + * Documentation: + * Formatting is done with HTML + */ + +class Tips extends SimpleExtension { + public function onInitExt($event) { + global $config, $database; + + if ($config->get_int("ext_tips_version") < 1){ + $database->create_table("tips", " + id SCORE_AIPK, + enable SCORE_BOOL NOT NULL DEFAULT SCORE_BOOL_N, + image TEXT NOT NULL, + text TEXT NOT NULL, + INDEX (id) + "); + + $database->execute(" + INSERT INTO tips (enable, image, text) + VALUES (?, ?, ?)", + array("Y", "coins.png", "Do you like this extension? Please support us for developing new ones. Donate through paypal.")); + + $config->set_int("ext_tips_version", 1); + log_info("tips", "extension installed"); + } + } + + public function onPageRequest($event) { + global $page, $user; + + $this->getTip(); + + if($event->page_matches("tips")) { + switch($event->get_arg(0)) { + case "list": + { + if($user->is_admin()) { + $this->manageTips(); + $this->getAll(); + } + break; + } + case "new": + { + break; + } + case "save": + { + if($user->is_admin()) { + $this->saveTip(); + + $page->set_mode("redirect"); + $page->set_redirect(make_link("tips/list")); + } + break; + } + case "status": + { + if($user->is_admin()) { + $tipID = int_escape($event->get_arg(1)); + $this->setStatus($tipID); + + $page->set_mode("redirect"); + $page->set_redirect(make_link("tips/list")); + } + break; + } + case "delete": + { + if($user->is_admin()) { + $tipID = int_escape($event->get_arg(1)); + $this->deleteTip($tipID); + + $page->set_mode("redirect"); + $page->set_redirect(make_link("tips/list")); + } + break; + } + } + } + } + + public function onUserBlockBuilding($event) { + global $user; + if($user->is_admin()) { + $event->add_link("Tips Editor", make_link("tips/list")); + } + } + + private function manageTips() { + $data_href = get_base_href(); + $url = $data_href."/ext/tips/images/"; + + $dirPath = dir('./ext/tips/images'); + $images = array(); + while(($file = $dirPath->read()) !== false) { + if($file[0] != ".") { + $images[] = trim($file); + } + } + $dirPath->close(); + sort($images); + + $this->theme->manageTips($url, $images); + } + + private function saveTip() { + global $database; + + $enable = isset($_POST["enable"]) ? "Y" : "N"; + $image = html_escape($_POST["image"]); + $text = $_POST["text"]; + + $database->execute(" + INSERT INTO tips (enable, image, text) + VALUES (?, ?, ?)", + array($enable, $image, $text)); + + } + + private function getTip() { + global $database; + + $data_href = get_base_href(); + $url = $data_href."/ext/tips/images/"; + + $tip = $database->get_row("SELECT * ". + "FROM tips ". + "WHERE enable = 'Y' ". + "ORDER BY RAND() ". + "LIMIT 1"); + + if($tip) { + $this->theme->showTip($url, $tip); + } + } + + private function getAll() { + global $database; + + $data_href = get_base_href(); + $url = $data_href."/ext/tips/images/"; + + $tips = $database->get_all("SELECT * FROM tips ORDER BY id ASC"); + + $this->theme->showAll($url, $tips); + } + + private function setStatus($tipID) { + global $database; + + $tip = $database->get_row("SELECT * FROM tips WHERE id = ? ", array($tipID)); + + if($tip['enable'] == "Y") { + $enable = "N"; + } elseif($tip['enable'] == "N") { + $enable = "Y"; + } + + $database->execute("UPDATE tips SET enable = ? WHERE id = ?", array ($enable, $tipID)); + } + + private function deleteTip($tipID) { + global $database; + $database->execute("DELETE FROM tips WHERE id = ?", array($tipID)); + } +} +?> diff --git a/contrib/tips/theme.php b/contrib/tips/theme.php index be5457cd..03b0865b 100644 --- a/contrib/tips/theme.php +++ b/contrib/tips/theme.php @@ -1,99 +1,99 @@ -"; - - foreach($images as $image){ - $select .= "\n"; - } - - $select .= ""; - - $html = " -
- - - - - - - - - - - - - - - - -
Enable:
Image:{$select}
Message:
-
-"; - - $page->set_title("Tips List"); - $page->set_heading("Tips List"); - $page->add_block(new NavBlock()); - $page->add_block(new Block("Add Tip", $html, "main", 10)); - } - - public function showTip($url, $tip) { - global $page; - - $img = ""; - if(!empty($tip['image'])) { - $img = " "; - } - $html = "
".$img.$tip['text']."
"; - $page->add_block(new Block(null, $html, "subheading", 10)); - } - - public function showAll($url, $tips){ - global $user, $page; - - $html = "". - "". - "". - "". - "". - ""; - - if($user->is_admin()){ - $html .= ""; - } - - $html .= ""; - - $n = 0; - foreach ($tips as $tip) - { - $oe = ($n++ % 2 == 0) ? "even" : "odd"; - - $tip_enable = ($tip['enable'] == "Y") ? "Yes" : "No"; - $set_link = "".$tip_enable.""; - - $html .= "". - "". - "". - ( - empty($tip['image']) ? - "" : - "" - ). - ""; - - $del_link = "Delete"; - - if($user->is_admin()){ - $html .= ""; - } - - $html .= ""; - } - $html .= "
IDEnabledImageTextAction
".$tip['id']."".$set_link."".$tip['text']."".$del_link."
"; - - $page->add_block(new Block("All Tips", $html, "main", 20)); - } -} -?> +"; + + foreach($images as $image){ + $select .= "\n"; + } + + $select .= ""; + + $html = " +
+ + + + + + + + + + + + + + + + +
Enable:
Image:{$select}
Message:
+
+"; + + $page->set_title("Tips List"); + $page->set_heading("Tips List"); + $page->add_block(new NavBlock()); + $page->add_block(new Block("Add Tip", $html, "main", 10)); + } + + public function showTip($url, $tip) { + global $page; + + $img = ""; + if(!empty($tip['image'])) { + $img = " "; + } + $html = "
".$img.$tip['text']."
"; + $page->add_block(new Block(null, $html, "subheading", 10)); + } + + public function showAll($url, $tips){ + global $user, $page; + + $html = "". + "". + "". + "". + "". + ""; + + if($user->is_admin()){ + $html .= ""; + } + + $html .= ""; + + $n = 0; + foreach ($tips as $tip) + { + $oe = ($n++ % 2 == 0) ? "even" : "odd"; + + $tip_enable = ($tip['enable'] == "Y") ? "Yes" : "No"; + $set_link = "".$tip_enable.""; + + $html .= "". + "". + "". + ( + empty($tip['image']) ? + "" : + "" + ). + ""; + + $del_link = "Delete"; + + if($user->is_admin()){ + $html .= ""; + } + + $html .= ""; + } + $html .= "
IDEnabledImageTextAction
".$tip['id']."".$set_link."".$tip['text']."".$del_link."
"; + + $page->add_block(new Block("All Tips", $html, "main", 20)); + } +} +?>