Ejemplo n.º 1
0
 public function onPageRequest($event)
 {
     global $config, $page, $user;
     if ($event->page_matches("featured_image")) {
         if ($event->get_arg(0) == "set" && $user->check_auth_token()) {
             if ($user->is_admin() && isset($_POST['image_id'])) {
                 $id = int_escape($_POST['image_id']);
                 if ($id > 0) {
                     $config->set_int("featured_id", $id);
                     $page->set_mode("redirect");
                     $page->set_redirect(make_link("post/view/{$id}"));
                 }
             }
         }
         if ($event->get_arg(0) == "download") {
             $image = Image::by_id($config->get_int("featured_id"));
             if (!is_null($image)) {
                 $page->set_mode("data");
                 $page->set_type("image/jpeg");
                 $page->set_data(file_get_contents($image->get_image_filename()));
             }
         }
         if ($event->get_arg(0) == "view") {
             $image = Image::by_id($config->get_int("featured_id"));
             if (!is_null($image)) {
                 send_event(new DisplayingImageEvent($image, $page));
             }
         }
     }
 }
Ejemplo n.º 2
0
 public function onImageInfoSet(ImageInfoSetEvent $event)
 {
     global $user;
     if (isset($_POST["tag_edit__author"])) {
         send_event(new AuthorSetEvent($event->image, $user, $_POST["tag_edit__author"]));
     }
 }
Ejemplo n.º 3
0
 public function onPageRequest($event)
 {
     global $config, $database, $page, $user;
     if ($event->page_matches("random_image")) {
         if ($event->count_args() == 1) {
             $action = $event->get_arg(0);
             $search_terms = array();
         } else {
             if ($event->count_args() == 2) {
                 $action = $event->get_arg(0);
                 $search_terms = explode(' ', $event->get_arg(1));
             }
         }
         $image = Image::by_random($search_terms);
         if ($event->get_arg(0) == "download") {
             if (!is_null($image)) {
                 $page->set_mode("data");
                 $page->set_type("image/jpeg");
                 $page->set_data(file_get_contents($image->get_image_filename()));
             }
         }
         if ($event->get_arg(0) == "view") {
             if (!is_null($image)) {
                 send_event(new DisplayingImageEvent($image, $page));
             }
         }
     }
 }
Ejemplo n.º 4
0
 public function testBulkAdd()
 {
     $this->log_in_as_admin();
     $this->get_page('admin');
     $this->assert_title("Admin Tools");
     $bae = new BulkAddEvent('asdf');
     send_event($bae);
     $this->assertContains("Error, asdf is not a readable directory", $bae->results, implode("\n", $bae->results));
     // FIXME: have BAE return a list of successes as well as errors?
     $this->markTestIncomplete();
     $this->get_page('admin');
     $this->assert_title("Admin Tools");
     send_event(new BulkAddEvent('tests'));
     # FIXME: test that the output here makes sense, no "adding foo.php ... ok"
     $this->get_page("post/list/hash=17fc89f372ed3636e28bd25cc7f3bac1/1");
     $this->assert_title(new PatternExpectation("/^Image \\d+: data/"));
     $this->click("Delete");
     $this->get_page("post/list/hash=feb01bab5698a11dd87416724c7a89e3/1");
     $this->assert_title(new PatternExpectation("/^Image \\d+: data/"));
     $this->click("Delete");
     $this->get_page("post/list/hash=e106ea2983e1b77f11e00c0c54e53805/1");
     $this->assert_title(new PatternExpectation("/^Image \\d+: data/"));
     $this->click("Delete");
     $this->log_out();
 }
Ejemplo n.º 5
0
 protected function comment_to_html($comment, $trim = false)
 {
     $inner_id = $this->inner_id;
     // because custom themes can't add params, because PHP
     global $user;
     $tfe = new TextFormattingEvent($comment->comment);
     send_event($tfe);
     //$i_uid = int_escape($comment->owner_id);
     $h_name = html_escape($comment->owner_name);
     //$h_poster_ip = html_escape($comment->poster_ip);
     $h_comment = $trim ? substr($tfe->stripped, 0, 50) . "..." : $tfe->formatted;
     $i_comment_id = int_escape($comment->comment_id);
     $i_image_id = int_escape($comment->image_id);
     $stripped_nonl = str_replace("\n", "\\n", substr($tfe->stripped, 0, 50));
     $stripped_nonl = str_replace("\r", "\\r", $stripped_nonl);
     $h_userlink = "<a href='" . make_link("user/{$h_name}") . "'>{$h_name}</a>";
     $h_date = $comment->posted;
     $h_del = $user->can("delete_comment") ? ' - <a onclick="return confirm(\'Delete comment by ' . $h_name . ':\\n' . $stripped_nonl . '\');" ' . 'href="' . make_link('comment/delete/' . $i_comment_id . '/' . $i_image_id) . '">Del</a>' : '';
     $h_reply = "[<a href='" . make_link("post/view/{$i_image_id}") . "'>Reply</a>]";
     if ($inner_id == 0) {
         return "<div class='comment' style='margin-top: 8px;'>{$h_userlink}{$h_del} {$h_date} No.{$i_comment_id} {$h_reply}<p>{$h_comment}</p></div>";
     } else {
         return "<table><tr><td nowrap class='doubledash'>&gt;&gt;</td><td>" . "<div class='reply'>{$h_userlink}{$h_del} {$h_date} No.{$i_comment_id} {$h_reply}<p>{$h_comment}</p></div>" . "</td></tr></table>";
     }
 }
Ejemplo n.º 6
0
 /**
  * Command for the current user to offer their money as bounty on another player
  *
  * @param target String The username of the player to offer a bounty on
  * @param amount int The amount of gold to spend on offering the bounty
  * @return Array
  *
  * @TODO simplify the conditional branching
  */
 public function offerBounty()
 {
     $targetName = in('target');
     $char = new Player(self_char_id());
     $target = new Player($targetName);
     $amountIn = in('amount');
     $amount = intval($amountIn) !== 0 ? intval($amountIn) : null;
     $quickstat = false;
     $success = false;
     if (!$target->id()) {
         $error = 1;
         // Target not found
     } elseif ($target->id() === $char->id()) {
         $error = 6;
         // Can't put a bounty on yourself.
     } else {
         $error = $this->validateBountyOffer($char, $target->id(), $amount);
         $amount = self::calculateMaxOffer($target->bounty(), $amount);
         if (!$error) {
             $char->set_gold($char->gold() - $amount);
             // Subtract the gold.
             $target->set_bounty($target->bounty() + $amount);
             $target->save();
             $char = $char->save();
             send_event($char->id(), $target->id(), $char->name() . " has offered " . $amount . " gold in reward for your head!");
             $success = true;
             $quickstat = 'player';
         }
     }
     return $this->render(['error' => $error, 'success' => $success, 'quickstat' => $quickstat, 'amount_in' => $amountIn, 'amount' => $amount, 'command' => 'offer', 'location' => 0, 'target' => $target]);
 }
Ejemplo n.º 7
0
 public function onImageInfoSet($event)
 {
     global $user;
     if ($_POST['favorite_action'] == "set" || $_POST['favorite_action'] == "unset") {
         send_event(new FavoriteSetEvent($event->image_id, $user, $_POST['favorite_action'] == "set"));
     }
 }
Ejemplo n.º 8
0
 public function display_reported_images(Page $page, $reports)
 {
     global $config;
     $h_reportedimages = "";
     $n = 0;
     foreach ($reports as $report) {
         $image = $report['image'];
         $h_reason = format_text($report['reason']);
         if ($config->get_bool('report_image_show_thumbs')) {
             $image_link = $this->build_thumb_html($image);
         } else {
             $image_link = "<a href=\"" . make_link("post/view/{$image->id}") . "\">{$image->id}</a>";
         }
         $reporter_name = html_escape($report['reporter_name']);
         $userlink = "<a href='" . make_link("user/{$reporter_name}") . "'>{$reporter_name}</a>";
         global $user;
         $iabbe = new ImageAdminBlockBuildingEvent($image, $user);
         send_event($iabbe);
         ksort($iabbe->parts);
         $actions = join("<br>", $iabbe->parts);
         $oe = $n++ % 2 == 0 ? "even" : "odd";
         $h_reportedimages .= "\n\t\t\t\t<tr class='{$oe}'>\n\t\t\t\t\t<td>{$image_link}</td>\n\t\t\t\t\t<td>Report by {$userlink}: {$h_reason}</td>\n\t\t\t\t\t<td class='formstretch'>\n\t\t\t\t\t\t<form action='" . make_link("image_report/remove") . "' method='POST'>\n\t\t\t\t\t\t\t<input type='hidden' name='id' value='{$report['id']}'>\n\t\t\t\t\t\t\t<input type='submit' value='Remove Report'>\n\t\t\t\t\t\t</form>\n\n\t\t\t\t\t\t<br>{$actions}\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n\t\t\t";
     }
     $thumb_width = $config->get_int("thumb_width");
     $html = "\n\t\t\t<table id='reportedimage' class='zebra'>\n\t\t\t\t<thead><td width='{$thumb_width}'>Image</td><td>Reason</td><td width='128'>Action</td></thead>\n\t\t\t\t{$h_reportedimages}\n\t\t\t</table>\n\t\t";
     $page->set_title("Reported Images");
     $page->set_heading("Reported Images");
     $page->add_block(new NavBlock());
     $page->add_block(new Block("Reported Images", $html));
 }
Ejemplo n.º 9
0
function sendMessage($from, $to, $msg, $filter = false)
{
    // Filter argument is deprecated now.
    $from_id = (int) get_char_id($from);
    $to_id = get_char_id($to);
    send_event($from_id, $to_id, $msg);
}
Ejemplo n.º 10
0
 /**
  * Generate the necessary DataUploadEvent for a given image and tags.
  */
 private function add_image($tmpname, $filename, $tags, $source, $rating, $thumbfile)
 {
     assert(file_exists($tmpname));
     $pathinfo = pathinfo($filename);
     if (!array_key_exists('extension', $pathinfo)) {
         throw new UploadException("File has no extension");
     }
     $metadata = array();
     $metadata['filename'] = $pathinfo['basename'];
     $metadata['extension'] = $pathinfo['extension'];
     $metadata['tags'] = $tags;
     $metadata['source'] = $source;
     $event = new DataUploadEvent($tmpname, $metadata);
     send_event($event);
     if ($event->image_id == -1) {
         throw new UploadException("File type not recognised");
     } else {
         if (class_exists("RatingSetEvent") && in_array($rating, array("s", "q", "e"))) {
             $ratingevent = new RatingSetEvent(Image::by_id($event->image_id), $rating);
             send_event($ratingevent);
         }
         if (file_exists($thumbfile)) {
             copy($thumbfile, warehouse_path("thumbs", $event->hash));
         }
     }
 }
Ejemplo n.º 11
0
 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 PageRequestEvent && $event->page_matches("tag_edit")) {
         if ($event->get_arg(0) == "replace") {
             if ($user->is_admin() && isset($_POST['search']) && isset($_POST['replace'])) {
                 $search = $_POST['search'];
                 $replace = $_POST['replace'];
                 $this->mass_tag_edit($search, $replace);
                 $page->set_mode("redirect");
                 $page->set_redirect(make_link("admin"));
             }
         }
     }
     if ($event instanceof ImageInfoSetEvent) {
         if ($this->can_tag()) {
             send_event(new TagSetEvent($event->image, $_POST['tag_edit__tags']));
             if ($this->can_source()) {
                 send_event(new SourceSetEvent($event->image, $_POST['tag_edit__source']));
             }
         } else {
             $this->theme->display_error($page, "Error", "Anonymous tag editing is disabled");
         }
     }
     if ($event instanceof TagSetEvent) {
         $event->image->set_tags($event->tags);
     }
     if ($event instanceof SourceSetEvent) {
         $event->image->set_source($event->source);
     }
     if ($event instanceof ImageDeletionEvent) {
         $event->image->delete_tags_from_image();
     }
     if ($event instanceof AdminBuildingEvent) {
         $this->theme->display_mass_editor($page);
     }
     // When an alias is added, oldtag becomes inaccessable
     if ($event instanceof AddAliasEvent) {
         $this->mass_tag_edit($event->oldtag, $event->newtag);
     }
     if ($event instanceof ImageInfoBoxBuildingEvent) {
         if ($config->get_bool("tag_edit_anon") || !$user->is_anonymous()) {
             $event->add_part($this->theme->get_tag_editor_html($event->image), 40);
         }
         if ($config->get_bool("source_edit_anon") || !$user->is_anonymous()) {
             $event->add_part($this->theme->get_source_editor_html($event->image), 41);
         }
     }
     if ($event instanceof SetupBuildingEvent) {
         $sb = new SetupBlock("Tag Editing");
         $sb->add_bool_option("tag_edit_anon", "Allow anonymous tag editing: ");
         $sb->add_bool_option("source_edit_anon", "<br>Allow anonymous source editing: ");
         $event->panel->add_block($sb);
     }
 }
Ejemplo n.º 12
0
 public function onPageRequest($event)
 {
     global $config, $database, $page, $user;
     if ($event->page_matches("regen_thumb") && $user->is_admin() && isset($_POST['image_id'])) {
         $image = Image::by_id(int_escape($_POST['image_id']));
         send_event(new ThumbnailGenerationEvent($image->hash, $image->ext));
         $this->theme->display_results($page, $image);
     }
 }
Ejemplo n.º 13
0
 public function onPageRequest(PageRequestEvent $event)
 {
     global $page, $user;
     if ($event->page_matches("regen_thumb") && $user->can("delete_image") && isset($_POST['image_id'])) {
         $image = Image::by_id(int_escape($_POST['image_id']));
         send_event(new ThumbnailGenerationEvent($image->hash, $image->ext, true));
         $this->theme->display_results($page, $image);
     }
 }
Ejemplo n.º 14
0
 public function _doThings($in, $out)
 {
     global $user;
     $this->log_in_as_user();
     $image_id = $this->post_image("tests/pbx_screenshot.jpg", "pbx computer screenshot");
     send_event(new CommentPostingEvent($image_id, $user, $in));
     $this->get_page("post/view/{$image_id}");
     $this->assert_text($out);
 }
Ejemplo n.º 15
0
 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) {
         if ($config->get_int("ext_ipban_version") < 5) {
             $this->install();
         }
         $this->check_ip_ban();
     }
     if ($event instanceof PageRequestEvent && $event->page_matches("ip_ban")) {
         if ($user->is_admin()) {
             if ($event->get_arg(0) == "add" && $user->check_auth_token()) {
                 if (isset($_POST['ip']) && isset($_POST['reason']) && isset($_POST['end'])) {
                     if (empty($_POST['end'])) {
                         $end = null;
                     } else {
                         $end = $_POST['end'];
                     }
                     send_event(new AddIPBanEvent($_POST['ip'], $_POST['reason'], $end));
                     $page->set_mode("redirect");
                     $page->set_redirect(make_link("ip_ban/list"));
                 }
             } else {
                 if ($event->get_arg(0) == "remove" && $user->check_auth_token()) {
                     if (isset($_POST['id'])) {
                         send_event(new RemoveIPBanEvent($_POST['id']));
                         $page->set_mode("redirect");
                         $page->set_redirect(make_link("ip_ban/list"));
                     }
                 } else {
                     if ($event->get_arg(0) == "list") {
                         $bans = isset($_GET["all"]) ? $this->get_bans() : $this->get_active_bans();
                         $this->theme->display_bans($page, $bans);
                     }
                 }
             }
         } else {
             $this->theme->display_permission_denied($page);
         }
     }
     if ($event instanceof UserBlockBuildingEvent) {
         if ($user->is_admin()) {
             $event->add_link("IP Bans", make_link("ip_ban/list"));
         }
     }
     if ($event instanceof AddIPBanEvent) {
         $this->add_ip_ban($event->ip, $event->reason, $event->end, $user);
     }
     if ($event instanceof RemoveIPBanEvent) {
         $database->Execute("DELETE FROM bans WHERE id = :id", array("id" => $event->id));
         $database->cache->delete("ip_bans");
     }
 }
Ejemplo n.º 16
0
 public function check_blocked($image_id, $words)
 {
     global $user;
     try {
         send_event(new CommentPostingEvent($image_id, $user, $words));
         $this->fail("Exception not thrown");
     } catch (CommentPostingException $e) {
         $this->assertEquals($e->getMessage(), "Comment contains banned terms");
     }
 }
Ejemplo n.º 17
0
 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 PageRequestEvent && $event->page_matches("admin")) {
         if (!$user->is_admin()) {
             $this->theme->display_permission_denied($page);
         } else {
             send_event(new AdminBuildingEvent($page));
         }
     }
     if ($event instanceof PageRequestEvent && $event->page_matches("admin_utils")) {
         if ($user->is_admin()) {
             log_info("admin", "Util: {$_POST['action']}");
             set_time_limit(0);
             $redirect = false;
             switch ($_POST['action']) {
                 case 'lowercase all tags':
                     $this->lowercase_all_tags();
                     $redirect = true;
                     break;
                 case 'recount tag use':
                     $this->recount_tag_use();
                     $redirect = true;
                     break;
                 case 'purge unused tags':
                     $this->purge_unused_tags();
                     $redirect = true;
                     break;
                 case 'convert to innodb':
                     $this->convert_to_innodb();
                     $redirect = true;
                     break;
                 case 'database dump':
                     $this->dbdump($page);
                     break;
             }
             if ($redirect) {
                 $page->set_mode("redirect");
                 $page->set_redirect(make_link("admin"));
             }
         }
     }
     if ($event instanceof AdminBuildingEvent) {
         $this->theme->display_page($page);
         $this->theme->display_form($page);
     }
     if ($event instanceof UserBlockBuildingEvent) {
         if ($user->is_admin()) {
             $event->add_link("Board Admin", make_link("admin"));
         }
     }
 }
Ejemplo n.º 18
0
 public function testCommentsPage()
 {
     global $user;
     $this->log_in_as_user();
     $image_id = $this->post_image("tests/pbx_screenshot.jpg", "pbx");
     # a good comment
     send_event(new CommentPostingEvent($image_id, $user, "Test Comment ASDFASDF"));
     $this->get_page("post/view/{$image_id}");
     $this->assert_text("ASDFASDF");
     # dupe
     try {
         send_event(new CommentPostingEvent($image_id, $user, "Test Comment ASDFASDF"));
     } catch (CommentPostingException $e) {
         $this->assertContains("try and be more original", $e->getMessage());
     }
     # empty comment
     try {
         send_event(new CommentPostingEvent($image_id, $user, ""));
     } catch (CommentPostingException $e) {
         $this->assertContains("Comments need text", $e->getMessage());
     }
     # whitespace is still empty...
     try {
         send_event(new CommentPostingEvent($image_id, $user, " \t\r\n"));
     } catch (CommentPostingException $e) {
         $this->assertContains("Comments need text", $e->getMessage());
     }
     # repetitive (aka. gzip gives >= 10x improvement)
     try {
         send_event(new CommentPostingEvent($image_id, $user, str_repeat("U", 5000)));
     } catch (CommentPostingException $e) {
         $this->assertContains("Comment too repetitive", $e->getMessage());
     }
     # test UTF8
     send_event(new CommentPostingEvent($image_id, $user, "Test Comment むちむち"));
     $this->get_page("post/view/{$image_id}");
     $this->assert_text("むちむち");
     # test that search by comment metadata works
     //		$this->get_page("post/list/commented_by=test/1");
     //		$this->assert_title("Image $image_id: pbx");
     //		$this->get_page("post/list/comments=2/1");
     //		$this->assert_title("Image $image_id: pbx");
     $this->log_out();
     $this->get_page('comment/list');
     $this->assert_title('Comments');
     $this->assert_text('ASDFASDF');
     $this->get_page('comment/list/2');
     $this->assert_title('Comments');
     $this->log_in_as_admin();
     $this->delete_image($image_id);
     $this->log_out();
     $this->get_page('comment/list');
     $this->assert_title('Comments');
     $this->assert_no_text('ASDFASDF');
 }
Ejemplo n.º 19
0
 function testImageFeed()
 {
     global $user;
     $this->log_in_as_user();
     $image_id = $this->post_image("tests/pbx_screenshot.jpg", "pbx");
     send_event(new CommentPostingEvent($image_id, $user, "ASDFASDF"));
     $this->get_page('rss/comments');
     //$this->assert_mime("application/rss+xml");
     $this->assert_no_content("Exception");
     $this->assert_content("ASDFASDF");
 }
Ejemplo n.º 20
0
 public function testEmoticons()
 {
     global $user;
     $this->log_in_as_user();
     $image_id = $this->post_image("tests/pbx_screenshot.jpg", "pbx computer screenshot");
     send_event(new CommentPostingEvent($image_id, $user, ":cool: :beans:"));
     $this->get_page("post/view/{$image_id}");
     $this->assert_no_text(":cool:");
     # FIXME: test for working image link
     //$this->assert_text(":beans:"); # FIXME: this should be left as-is
     $this->get_page("emote/list");
     //$this->assert_text(":arrow:");
 }
Ejemplo n.º 21
0
 public function onPageRequest(PageRequestEvent $event)
 {
     global $config, $database, $page, $user;
     if ($event->page_matches("image_hash_ban")) {
         if ($user->is_admin()) {
             if ($event->get_arg(0) == "dnp") {
                 $image = Image::by_id(int_escape($event->get_arg(1)));
                 if ($image) {
                     send_event(new AddImageHashBanEvent($image->hash, "DNP"));
                     send_event(new ImageDeletionEvent($image));
                 }
                 $page->set_mode("redirect");
                 $page->set_redirect($_SERVER["HTTP_REFERER"]);
             } else {
                 if ($event->get_arg(0) == "add") {
                     if (isset($_POST['hash']) && isset($_POST['reason'])) {
                         send_event(new AddImageHashBanEvent($_POST['hash'], $_POST['reason']));
                         $page->set_mode("redirect");
                         $page->set_redirect(make_link("image_hash_ban/list/1"));
                     }
                     if (isset($_POST['image_id'])) {
                         $image = Image::by_id(int_escape($_POST['image_id']));
                         if ($image) {
                             send_event(new ImageDeletionEvent($image));
                             $page->set_mode("redirect");
                             $page->set_redirect(make_link("post/list"));
                         }
                     }
                 } else {
                     if ($event->get_arg(0) == "remove") {
                         if (isset($_POST['hash'])) {
                             send_event(new RemoveImageHashBanEvent($_POST['hash']));
                             $page->set_mode("redirect");
                             $page->set_redirect(make_link("image_hash_ban/list/1"));
                         }
                     } else {
                         if ($event->get_arg(0) == "list") {
                             $page_num = 0;
                             if ($event->count_args() == 2) {
                                 $page_num = int_escape($event->get_arg(1));
                             }
                             $page_size = 100;
                             $page_count = ceil($database->get_one("SELECT COUNT(id) FROM image_bans") / $page_size);
                             $this->theme->display_Image_hash_Bans($page, $page_num, $page_count, $this->get_image_hash_bans($page_num, $page_size));
                         }
                     }
                 }
             }
         }
     }
 }
Ejemplo n.º 22
0
 protected function create_display_html(WikiPage $page)
 {
     $owner = $page->get_owner();
     $tfe = new TextFormattingEvent($page->body);
     send_event($tfe);
     global $user;
     $edit = "<table><tr>";
     $edit .= Wiki::can_edit($user, $page) ? "\n\t\t\t\t<td>" . make_form(make_link("wiki_admin/edit")) . "\n\t\t\t\t\t<input type='hidden' name='title' value='" . html_escape($page->title) . "'>\n\t\t\t\t\t<input type='hidden' name='revision' value='" . int_escape($page->revision) . "'>\n\t\t\t\t\t<input type='submit' value='Edit'>\n\t\t\t\t</form></td>\n\t\t\t" : "";
     if ($user->is_admin()) {
         $edit .= "\n\t\t\t\t<td>" . make_form(make_link("wiki_admin/delete_revision")) . "\n\t\t\t\t\t<input type='hidden' name='title' value='" . html_escape($page->title) . "'>\n\t\t\t\t\t<input type='hidden' name='revision' value='" . int_escape($page->revision) . "'>\n\t\t\t\t\t<input type='submit' value='Delete This Version'>\n\t\t\t\t</form></td>\n\t\t\t\t<td>" . make_form(make_link("wiki_admin/delete_all")) . "\n\t\t\t\t\t<input type='hidden' name='title' value='" . html_escape($page->title) . "'>\n\t\t\t\t\t<input type='submit' value='Delete All'>\n\t\t\t\t</form></td>\n\t\t\t";
     }
     $edit .= "</tr></table>";
     return "\n\t\t\t<div class='wiki-page'>\n\t\t\t{$tfe->formatted}\n\t\t\t<hr>\n\t\t\t<p class='wiki-footer'>\n\t\t\t\tRevision {$page->revision}\n\t\t\t\tby <a href='" . make_link("user/{$owner->name}") . "'>{$owner->name}</a>\n\t\t\t\tat {$page->date}\n\t\t\t\t{$edit}\n\t\t\t</p>\n\t\t\t</div>\n\t\t";
 }
Ejemplo n.º 23
0
 public function onCommand(CommandEvent $event)
 {
     if ($event->cmd == "help") {
         print "\tbulk-add [directory]\n";
         print "\t\tImport this directory\n\n";
     }
     if ($event->cmd == "bulk-add") {
         if (count($event->args) == 1) {
             $bae = new BulkAddEvent($event->args[0]);
             send_event($bae);
             print implode("\n", $bae->results);
         }
     }
 }
Ejemplo n.º 24
0
 public function receive_event(Event $event)
 {
     if (is_null($this->theme)) {
         $this->theme = get_theme_object($this);
     }
     if ($event instanceof DataUploadEvent && $this->supported_ext($event->type) && $this->check_contents($event->tmpname)) {
         $hash = $event->hash;
         $ha = substr($hash, 0, 2);
         if (!move_upload_to_archive($event)) {
             return;
         }
         send_event(new ThumbnailGenerationEvent($event->hash, $event->type));
         $image = $this->create_image_from_data(warehouse_path("images", $hash), $event->metadata);
         if (is_null($image)) {
             throw new UploadException("SVG handler failed to create image object from data");
         }
         $iae = new ImageAdditionEvent($event->user, $image);
         send_event($iae);
         $event->image_id = $iae->image->id;
     }
     if ($event instanceof ThumbnailGenerationEvent && $this->supported_ext($event->type)) {
         $hash = $event->hash;
         $ha = substr($hash, 0, 2);
         global $config;
         //			if($config->get_string("thumb_engine") == "convert") {
         //				$w = $config->get_int("thumb_width");
         //				$h = $config->get_int("thumb_height");
         //				$q = $config->get_int("thumb_quality");
         //				$mem = $config->get_int("thumb_max_memory") / 1024 / 1024; // IM takes memory in MB
         //
         //				exec("convert images/{$ha}/{$hash}[0] -geometry {$w}x{$h} -quality {$q} jpg:thumbs/{$ha}/{$hash}");
         //			}
         //			else {
         copy("ext/handle_svg/thumb.jpg", warehouse_path("thumbs", $hash));
         //			}
     }
     if ($event instanceof DisplayingImageEvent && $this->supported_ext($event->image->ext)) {
         global $page;
         $this->theme->display_image($page, $event->image);
     }
     if ($event instanceof PageRequestEvent && $event->page_matches("get_svg")) {
         global $config, $database, $page;
         $id = int_escape($event->get_arg(0));
         $image = Image::by_id($id);
         $hash = $image->hash;
         $page->set_type("image/svg+xml");
         $page->set_mode("data");
         $page->set_data(file_get_contents(warehouse_path("images", $hash)));
     }
 }
Ejemplo n.º 25
0
function add_image($tmpname, $filename, $tags)
{
    if (file_exists($tmpname)) {
        global $user;
        $pathinfo = pathinfo($filename);
        $metadata['filename'] = $pathinfo['basename'];
        $metadata['extension'] = $pathinfo['extension'];
        $metadata['tags'] = $tags;
        $metadata['source'] = null;
        $event = new DataUploadEvent($user, $tmpname, $metadata);
        send_event($event);
        if ($event->vetoed) {
            return $event->veto_reason;
        }
    }
}
Ejemplo n.º 26
0
 public function display_thread($posts, $showAdminOptions, $threadTitle, $threadID, $pageNumber, $totalPages)
 {
     global $config, $page;
     $theme_name = $config->get_string('theme');
     $data_href = $config->get_string('base_href');
     $base_href = $config->get_string('base_href');
     $html = "";
     $n = 0;
     $html = "<table id='postList' class='zebra'>" . "<thead><tr>" . "<th>User</th>" . "<th>Message</th>" . "</tr></thead>";
     foreach ($posts as $post) {
         $message = $post["message"];
         $tfe = new TextFormattingEvent($message);
         send_event($tfe);
         $message = $tfe->formatted;
         $message = str_replace('\\n\\r', '<br>', $message);
         $message = str_replace('\\r\\n', '<br>', $message);
         $message = str_replace('\\n', '<br>', $message);
         $message = str_replace('\\r', '<br>', $message);
         $message = stripslashes($message);
         $user = "******" . make_link("user/" . $post["user_name"] . "") . "'>" . $post["user_name"] . "</a>";
         $poster = User::by_name($post["user_name"]);
         $gravatar = $poster->get_avatar_html();
         $oe = $n++ % 2 == 0 ? "even" : "odd";
         if ($post["user_admin"] == "Y") {
             $rank = "<sup>admin</sup>";
         } else {
             $rank = "<sup>user</sup>";
         }
         $postID = $post['id'];
         //if($user->is_admin()){
         //$delete_link = "<a href=".make_link("forum/delete/".$threadID."/".$postID).">Delete</a>";
         //} else {
         //$delete_link = "";
         //}
         if ($showAdminOptions) {
             $delete_link = "<a href=" . make_link("forum/delete/" . $threadID . "/" . $postID) . ">Delete</a>";
         } else {
             $delete_link = "";
         }
         $html .= "<tr class='{$oe}'>" . "<td class='forum_user'>" . $user . "<br>" . $rank . "<br>" . $gravatar . "</td>" . "<td class='forum_message'>" . $message . "</td>" . "</tr>\n\t\t\t\t<tr class='{$oe}'>\n\t\t\t\t\t<td class='forum_subuser'><small>" . autodate($post["date"]) . "</small></td>\n\t\t\t\t\t<td class='forum_submessage'>" . $delete_link . "</td>\n\t\t\t\t</tr>";
     }
     $html .= "</tbody></table>";
     $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));
 }
Ejemplo n.º 27
0
 public function onDataUpload(DataUploadEvent $event)
 {
     if ($this->supported_ext($event->type) && $this->check_contents($event->tmpname)) {
         $hash = $event->hash;
         if (!move_upload_to_archive($event)) {
             return;
         }
         send_event(new ThumbnailGenerationEvent($event->hash, $event->type));
         $image = $this->create_image_from_data(warehouse_path("images", $hash), $event->metadata);
         if (is_null($image)) {
             throw new UploadException("SVG handler failed to create image object from data");
         }
         $iae = new ImageAdditionEvent($image);
         send_event($iae);
         $event->image_id = $iae->image->id;
     }
 }
Ejemplo n.º 28
0
 private function add_image($tmpname, $filename, $tags)
 {
     assert(file_exists($tmpname));
     global $user;
     $pathinfo = pathinfo($filename);
     if (!array_key_exists('extension', $pathinfo)) {
         throw new UploadException("File has no extension");
     }
     $metadata['filename'] = $pathinfo['basename'];
     $metadata['extension'] = $pathinfo['extension'];
     $metadata['tags'] = $tags;
     $metadata['source'] = null;
     $event = new DataUploadEvent($user, $tmpname, $metadata);
     send_event($event);
     if ($event->image_id == -1) {
         throw new UploadException("File type not recognised");
     }
 }
Ejemplo n.º 29
0
 public function display_signup_page($page)
 {
     global $config;
     $tac = $config->get_string("login_tac", "");
     $tfe = new TextFormattingEvent($tac);
     send_event($tfe);
     $tac = $tfe->formatted;
     if (empty($tac)) {
         $html = "";
     } else {
         $html = "<p>{$tac}</p>";
     }
     $html .= "\n\t\t<form action='" . make_link("user_admin/create") . "' method='POST'>\n\t\t\t<table style='width: 300px;'>\n\t\t\t\t<tr><td>Name</td><td><input type='text' name='name'></td></tr>\n\t\t\t\t<tr><td>Password</td><td><input type='password' name='pass1'></td></tr>\n\t\t\t\t<tr><td>Repeat Password</td><td><input type='password' name='pass2'></td></tr>\n\t\t\t\t<tr><td>Email (Optional)</td><td><input type='text' name='email'></td></tr>\n\t\t\t\t<tr><td colspan='2'><input type='Submit' value='Create Account'></td></tr>\n\t\t\t</table>\n\t\t</form>\n\t\t";
     $page->set_title("Create Account");
     $page->set_heading("Create Account");
     $page->disable_left();
     $page->add_block(new Block("Signup", $html));
 }
Ejemplo n.º 30
0
 private function add_image($tmpname, $filename, $tags)
 {
     assert(file_exists($tmpname));
     try {
         global $user;
         $pathinfo = pathinfo($filename);
         if (!array_key_exists('extension', $pathinfo)) {
             throw new UploadException("File has no extension");
         }
         $metadata['filename'] = $pathinfo['basename'];
         $metadata['extension'] = $pathinfo['extension'];
         $metadata['tags'] = $tags;
         $metadata['source'] = null;
         $event = new DataUploadEvent($user, $tmpname, $metadata);
         send_event($event);
     } catch (UploadException $ex) {
         return $ex->getMessage();
     }
 }