function render() { $op = $this->op = @$this->module_params['op']; if ($this->op) { if (!empty($this->module_params['comment'])) { $target = new Comment2(); $target->load($this->module_params['comment']); } else { if (!empty($this->module_params['review'])) { $target = new Review(); $target->load($this->module_params['review']); } else { if (!empty($this->module_params['uid'])) { $target = new ShadowUser('videoplay'); $target->load_by_pa((int) $this->module_params['uid']); } } } switch ($op) { case "delete": if (!empty($this->module_params['uid'])) { $target->remove(); } else { $target->delete(); } break; case "hide": case "show": if (!empty($this->module_params['uid'])) { $target->toggle_active($op == 'hide' ? -1 : 1); } else { $target->toggle_active($op == 'hide' ? 0 : 1); } break; } } switch ($this->mode) { case "comments": $inner_template = dirname(__FILE__) . '/admin_content.tpl'; list($this->contents, $this->n, $this->n_pages, $this->page, $this->per_page) = Comment2::get_recent($this->per_page, $this->page); break; case "reviews": $inner_template = dirname(__FILE__) . '/admin_content.tpl'; list($this->contents, $this->n, $this->n_pages, $this->page, $this->per_page) = Review::get_recent($this->per_page, $this->page); break; case "users": $inner_template = dirname(__FILE__) . '/admin_users.tpl'; list($this->users, $this->n, $this->n_pages, $this->page, $this->per_page) = ShadowUser::admin_paged('videoplay', $this->per_page, $this->page); break; default: return "Unknown display type.<pre>" . print_r($this, 1) . "</pre>"; break; } $inner_html_gen =& new Template($inner_template, $this); $this->inner_HTML = $inner_html_gen->fetch(); $content = parent::render(); return $content; }
public function comments() { return Comment2::find_comments_on($this->id); }
<?php require_once "includes/initialize.php"; $photo2 = Photograph2::find_by_id($_GET['id']); if (!$photo2) { $session->message("The photo could not be located."); redirect_to('index.php'); } if (isset($_POST['submit'])) { $author = trim($_POST['author']); $body = trim($_POST['body']); $new_comment = Comment2::make($photo2->id, $author, $body); if ($new_comment && $new_comment->save()) { // comment saved // No message needed; seeing the comment is proof enough. // Send email //$new_comment->try_to_send_notification(); // Important! You could just let the page render from here. // But then if the page is reloaded, the form will try // to resubmit the comment. So redirect instead: redirect_to("photo2.php?id={$photo2->id}"); } else { // Failed $message = "There was an error that prevented the comment from being saved."; } } else { $author = ""; $body = ""; } $comments = $photo2->comments(); ?>
function render_for_ajax() { $op = $this->params["op"]; // if ($op != 'paging' && empty(PA::$login_user)) return __("Login required"); switch ($op) { case "flagthis": if (empty(PA::$login_user)) { $this->err = __("Please log in or register to flag a comment!"); break; } // file the abuse report try { list($foo, $comment_id) = split(':', $this->params['flag']); $abuse_obj = new ReportAbuse(); $abuse_obj->parent_type = 'comment'; $abuse_obj->parent_id = $comment_id; $abuse_obj->reporter_id = PA::$login_uid; // TODO: possibly make this user input $abuse_obj->body = "This comment was flagged."; $id = $abuse_obj->save(); $this->note = "Your abuse report was filed."; } catch (PAException $e) { $this->err = __("There was a problem flagging this comment: ") . $e->message; } break; case "add_comment": do { if (empty(PA::$login_user)) { $this->err = __("Please log in or register to post enter a comment!"); break; } // $title = trim($this->params["title"]); // if (empty($title)) { $this->err = "Please give your comment a title."; break; } $body = trim($this->params["body"]); if (empty($body)) { $this->err = "Please enter a comment!"; break; } // validation done - now save the comment $comm = new Comment2(); $comm->author_id = PA::$login_user->user_id; $comm->subject_type = $this->params["subject_type"]; $comm->subject_id = $this->params["subject_id"]; $comm->title = $title; $comm->body = $body; if (!$comm->save()) { $this->err = __("Save failed."); break; } $this->note = __("Comment added - thank you for participating!"); // for rivers of people $activity = 'user_post_a_comment'; $extra = serialize(array('info' => PA::$login_user->login_name . ' posted a comment.', 'subject_type' => $comm->subject_type, 'subject_id' => $comm->subject_id)); Activities::save(PA::$login_uid, $activity, -1, $extra, array($activity)); } while (0); break; default: // just ignore any others break; } return $this->render(); }
public static function get($comment_id) { $comm = new Comment2(); $comm->load($comment_id); return $comm; }