public function testWithOrphanedHasManyRelations() { DataObjectOnDeleteDecorator::set_disabled(true); //JanitorDebug::set_verbose(true); $page = new Page(); $page->Title = 'Page1'; $page->write(); $pageID = $page->ID; for ($i = 0; $i < 5; ++$i) { $comment = new PageComment(); $comment->Name = "Snowball {$i}"; $comment->Comment = "Comment #{$i}!"; $comment->ParentID = $pageID; $comment->write(); } $page->delete(); DataObjectOnDeleteDecorator::set_disabled(false); $task = new DataObjectRetroactiveCleanerTask(); $task->run(null); $task->deleteBackup(); $this->assertFalse((bool)DataObject::get('PageComment', "ParentID = {$pageID}"), "PageComment not cleaned properly (retroactively)"); JanitorDebug::set_verbose(false); }
function testCommenterURLWrite() { $comment = new PageComment(); // We only care about the CommenterURL, so only set that // Check a http and https URL. Add more test urls here as needed. $protocols = array('Http', 'Https'); $url = '://example.com'; foreach ($protocols as $protocol) { $comment->CommenterURL = $protocol . $url; // The protocol should stay as if, assuming it is valid $comment->write(); $this->assertEquals($comment->CommenterURL, $protocol . $url, $protocol . ':// is a valid protocol'); } }
function doUpload($data, $form) { // Gets a blog holders ID $blogHolderID = $data['BlogHolderID']; // Checks if a file is uploaded if (is_uploaded_file($_FILES['XMLFile']['tmp_name'])) { echo '<p>Processing...<br/></p>'; flush(); $file = $_FILES['XMLFile']; // check file type. only xml file is allowed if ($file['type'] != 'text/xml') { echo 'Please select Wordpress XML file'; die; } $wp = new WpParser($file['tmp_name']); $posts = $wp->parse(); // For testing only // TODO: remove $count $count = 0; echo $count; foreach ($posts as $post) { $comments = $post['Comments']; // create a blog entry $entry = new BlogEntry(); $entry->ParentID = $blogHolderID; // $posts array and $entry have the same key/field names // so we can use update here. var_dump($post); $entry->update($post); $entry->write(); $entry->publish("Stage", "Live"); // page comment(s) foreach ($comments as $comment) { $page_comment = new PageComment(); $page_comment->ParentID = $entry->ID; $page_comment->update($comment); $page_comment->write(); } // count is used for testing only // TODO: remove the next 2 lines $count++; } // delete the temporaray uploaded file unlink($file['tmp_name']); // print sucess message echo 'Complete!<br/>'; echo 'Please refresh the admin page to see the new blog entries.'; } }
public function testDataObjectDeleteWithNullableHasOneRelation() { $page = new Page(); $page->Title = 'Page'; $page->write(); $pageID = $page->ID; $author = new Member(); $author->Email = '*****@*****.**'; $author->Password = '******'; $author->write(); $authorID = $author->ID; $comment = new PageComment(); $comment->ParentID = $page->ID; $comment->AuthorID = $author->ID; $comment->write(); $commentID = $comment->ID; $author->delete(); $comment = DataObject::get_by_id('PageComment', $commentID); $this->assertInstanceOf('PageComment', $comment); $this->assertFalse((bool)$comment->AuthorID, "PageComment AuthorID not set to null when the author was deleted"); }
function postcomment($data) { // Spam filtering Cookie::set("PageCommentInterface_Name", $data['Name']); Cookie::set("PageCommentInterface_CommenterURL", $data['CommenterURL']); Cookie::set("PageCommentInterface_Comment", $data['Comment']); if (SSAkismet::isEnabled()) { try { $akismet = new SSAkismet(); $akismet->setCommentAuthor($data['Name']); $akismet->setCommentContent($data['Comment']); if ($akismet->isCommentSpam()) { if (SSAkismet::getSaveSpam()) { $comment = Object::create('PageComment'); $this->saveInto($comment); $comment->setField("IsSpam", true); $comment->write(); } echo "<b>" . _t('PageCommentInterface_Form.SPAMDETECTED', 'Spam detected!!') . "</b><br /><br />"; printf("If you believe this was in error, please email %s.", ereg_replace("@", " _(at)_", Email::getAdminEmail())); echo "<br /><br />" . _t('PageCommentInterface_Form.MSGYOUPOSTED', 'The message you posted was:') . "<br /><br />"; echo $data['Comment']; return; } } catch (Exception $e) { // Akismet didn't work, continue without spam check } } //check if spam question was right. if (MathSpamProtection::isEnabled()) { if (!MathSpamProtection::correctAnswer($data['Math'])) { if (!Director::is_ajax()) { Director::redirectBack(); } return "spamprotectionfailed"; //used by javascript for checking if the spam question was wrong } } // If commenting can only be done by logged in users, make sure the user is logged in $member = Member::currentUser(); if (PageCommentInterface::CanPostComment() && $member) { $this->Fields()->push(new HiddenField("AuthorID", "Author ID", $member->ID)); } elseif (!PageCommentInterface::CanPostComment()) { echo "You're not able to post comments to this page. Please ensure you are logged in and have an appropriate permission level."; return; } $comment = Object::create('PageComment'); $this->saveInto($comment); // Store the Session ID if needed for Spamprotection if ($session = Session::get('mollom_user_session_id')) { $comment->SessionID = $session; Session::clear('mollom_user_session_id'); } $comment->IsSpam = false; $comment->NeedsModeration = PageComment::moderationEnabled(); $comment->write(); Cookie::set("PageCommentInterface_Comment", ''); if (Director::is_ajax()) { if ($comment->NeedsModeration) { echo _t('PageCommentInterface_Form.AWAITINGMODERATION', "Your comment has been submitted and is now awaiting moderation."); } else { echo $comment->renderWith('PageCommentInterface_singlecomment'); } } else { // since it is not ajax redirect user down to their comment since it has been posted // get the pages url off the comments parent ID. if ($comment->ParentID) { $page = DataObject::get_by_id("Page", $comment->ParentID); if ($page) { // Redirect to the actual post on the page. return Director::redirect(Director::baseURL() . $page->URLSegment . '#PageComment_' . $comment->ID); } } return Director::redirectBack(); // worst case, just go back to the page } }
static function enableBBCode() { self::$bbcode = true; }
public function ins() { $pid = isset($_GET['pid']) ? addslashes($_GET['pid']) : die("no pid"); $tex = isset($_POST['tex']) ? addslashes($_POST['tex']) : die("no pid"); $type = isset($_GET['type']) ? addslashes($_GET['type']) : "page"; $json = array(); $json['bool'] = 0; $pc = new PageComment(); $pc->comment_text = $tex; $pc->comment_date = leap_mysqldate(); $pc->comment_author = Account::getMyID(); $pc->comment_page_id = $pid; $pc->comment_type = $type; $json['bool'] = $pc->save(); die(json_encode($json)); }
/** * Imports blog entries and comments from a Potgres-based typo installation into a SilverStripe blog */ function import(){ // some of the guys in the contents table are articles, some are contents. Distinguished by type = "Article" or "Comment" // fields are: id, title, author, body, body_html, extended, excerpt, keywords, created_at, updated_at, extended_html, user_id, permalink, guid, [13] // text_filter_id, whiteboard, type, article_id, email, url, ip, blog_name, name, published, allow_pings, allow_comments, blog_id // published_at, state, status_confirmed $dbconn = pg_connect("host=orwell port=5432 dbname=typo_prod user=postgres password=possty"); // create a new blogholder and call it "imported blog" $bholder = new BlogHolder(); $bholder->Title = "imported blog"; // write it! $bholder->write(); $bholder->publish("Stage", "Live"); // get the typo articles $result = pg_query($dbconn, "SELECT * FROM contents WHERE type='Article'"); while ($row = pg_fetch_row($result)) { // title [1] // author [2] // body [3] // body_html [4] (type rendered and cached the html here. This is the preferred blog entry content for migration) // keywords (space separated) [7] (tags table is just a list of the unique variants of these keywords) // created_at [8] // permalink [12] (this is like the url in sitetree, prolly not needed) // email [18] (address of the commenter) // url [19] (url of the commenter) $title = $row[1]; $author = $row[2]; $blog_entry = $row[4]; $keywords = $row[7]; $created_at = $row[8]; // sometimes it's empty. If it is, grab the body if ($blog_entry == ""){ // use "body" $blog_entry = $row[3]; } echo "blog_entry: $blog_entry"; echo "<br />\n"; // put the typo blog entry in the SS database $newEntry = new BlogEntry(); $newEntry->Title = $title; $newEntry->Author = $author; $newEntry->Content = $blog_entry; $newEntry->Tags = $keywords; $newEntry->Date = $created_at; // tie each blog entry back to the blogholder we created initially $newEntry->ParentID = $bholder->ID; // write it! $newEntry->write(); $newEntry->publish("Stage", "Live"); // grab the id so we can get the comments $old_article_id = $row[0]; // get the comments $result2 = pg_query($dbconn, "SELECT * FROM contents WHERE type = 'Comment' AND article_id = $old_article_id"); while ($row2 = pg_fetch_row($result2)) { // grab the body_html $comment = $row2[4]; // sometimes it's empty. If it is, grab the body if ($comment == ""){ // use "body" $comment = $row2[3]; } $Cauthor = $row2[2]; $Ccreated_at = $row2[8]; // put the typo blog comment in the SS database $newCEntry = new PageComment(); $newCEntry->Name = $Cauthor; $newCEntry->Comment = $comment; $newCEntry->Created = $created_at; // need to grab the newly inserted blog entry's id $newCEntry->ParentID = $newEntry->ID; // write it! $newCEntry->write(); echo "comment: $comment"; echo "<br />\n"; } $newEntry->flushCache(); // fix up the specialchars pg_query($dbconn, "UPDATE SiteTree SET Content = REPLACE(Content, \"×\", \"x\")"); pg_query($dbconn, "UPDATE SiteTree SET Content = REPLACE(Content, \"’\", \"’\")"); pg_query($dbconn, "UPDATE SiteTree SET Content = REPLACE(Content, \"‘\", \"‘\")"); pg_query($dbconn, "UPDATE SiteTree SET Content = REPLACE(Content, \"—\", \"—\")"); pg_query($dbconn, "UPDATE SiteTree SET Content = REPLACE(Content, \"“\", \"“\")"); pg_query($dbconn, "UPDATE SiteTree SET Content = REPLACE(Content, \"”\", \"”\")"); pg_query($dbconn, "UPDATE SiteTree SET Content = REPLACE(Content, \"–\", \"–\")"); pg_query($dbconn, "UPDATE SiteTree SET Content = REPLACE(Content, \"—\", \"—\")"); pg_query($dbconn, "UPDATE SiteTree SET Content = REPLACE(Content, \"…\", \"…\")"); pg_query($dbconn, "UPDATE SiteTree SET Content = REPLACE(Content, \"™\", \"™\")"); pg_query($dbconn, "UPDATE SiteTree SET Content = REPLACE(Content, \"&\", \"&\")"); pg_query($dbconn, "UPDATE PageComment SET Comment = REPLACE(Comment, \"×\", \"x\")"); pg_query($dbconn, "UPDATE PageComment SET Comment = REPLACE(Comment, \"’\", \"’\")"); pg_query($dbconn, "UPDATE PageComment SET Comment = REPLACE(Comment, \"‘\", \"‘\")"); pg_query($dbconn, "UPDATE PageComment SET Comment = REPLACE(Comment, \"—\", \"—\")"); pg_query($dbconn, "UPDATE PageComment SET Comment = REPLACE(Comment, \"“\", \"“\")"); pg_query($dbconn, "UPDATE PageComment SET Comment = REPLACE(Comment, \"”\", \"”\")"); pg_query($dbconn, "UPDATE PageComment SET Comment = REPLACE(Comment, \"–\", \"–\")"); pg_query($dbconn, "UPDATE PageComment SET Comment = REPLACE(Comment, \"—\", \"—\")"); pg_query($dbconn, "UPDATE PageComment SET Comment = REPLACE(Comment, \"…\", \"…\")"); pg_query($dbconn, "UPDATE PageComment SET Comment = REPLACE(Comment, \"™\", \"™\")"); pg_query($dbconn, "UPDATE PageComment SET Comment = REPLACE(Comment, \"&\", \"&\")"); } pg_close($dbconn); } // end function
function postcomment($data) { // Spam filtering if (SSAkismet::isEnabled()) { try { $akismet = new SSAkismet(); $akismet->setCommentAuthor($data['Name']); $akismet->setCommentContent($data['Comment']); if ($akismet->isCommentSpam()) { if (SSAkismet::getSaveSpam()) { $comment = Object::create('PageComment'); $this->saveInto($comment); $comment->setField("IsSpam", true); $comment->write(); } echo "<b>" . _t('PageCommentInterface_Form.SPAMDETECTED', 'Spam detected!!') . "</b><br /><br />"; printf("If you believe this was in error, please email %s.", ereg_replace("@", " _(at)_", Email::getAdminEmail())); echo "<br /><br />" . _t('PageCommentInterface_Form.MSGYOUPOSTED', 'The message you posted was:') . "<br /><br />"; echo $data['Comment']; return; } } catch (Exception $e) { // Akismet didn't work, continue without spam check } } //check if spam question was right. if (MathSpamProtection::isEnabled()) { if (!MathSpamProtection::correctAnswer($data['Math'])) { if (!Director::is_ajax()) { Director::redirectBack(); } return "spamprotectionfalied"; //used by javascript for checking if the spam question was wrong } } Cookie::set("PageCommentInterface_Name", $data['Name']); $comment = Object::create('PageComment'); $this->saveInto($comment); $comment->IsSpam = false; $comment->NeedsModeration = PageComment::moderationEnabled(); $comment->write(); if (Director::is_ajax()) { if ($comment->NeedsModeration) { echo _t('PageCommentInterface_Form.AWAITINGMODERATION', "Your comment has been submitted and is now awating moderation."); } else { echo $comment->renderWith('PageCommentInterface_singlecomment'); } } else { Director::redirectBack(); } }