protected function processRecord($record, $columnMap, &$result, $preview = false)
 {
     foreach ($this->listeners['beforeProcessRecord'] as $listener) {
         $listener($record, $columnMap, $result, $preview);
     }
     $page = $this->getPage($record);
     if (!$page) {
         // Mainly for testing, in real imports the posts should be present already
         if (!($holder = $this->_cache_holder)) {
             $holder = BlogHolder::get()->First();
         }
         if (!$holder) {
             $holder = new BlogHolder();
             $holder->write();
         }
         $this->_cache_holder = $holder;
         $page = new BlogEntry(array('DrupalNid' => $record['nid'], 'ParentID' => $holder->ID));
         $page->write();
     }
     $record['ParentID'] = $page->ID;
     $record['BaseClass'] = 'SiteTree';
     $objId = parent::processRecord($record, $columnMap, $result, $preview);
     $obj = Comment::get()->byId($objId);
     // Created gets overwritten on new records...
     $obj->Created = $record['Created'];
     $obj->write();
     foreach ($this->listeners['afterProcessRecord'] as $listener) {
         $listener($obj, $record, $columnMap, $result, $preview);
     }
     return $objId;
 }
コード例 #2
0
 public function onAfterWrite()
 {
     parent::onAfterWrite();
     if ($this->isInsert) {
         $blog = new BlogHolder();
         $blog->ParentID = $this->ID;
         $blog->Title = "News";
         $blog->ShowInMenus = false;
         $blog->write();
         $blog->publish('Stage', 'Live');
         $calendar = new Calendar();
         $calendar->ParentID = $this->ID;
         $calendar->Title = "Calendar";
         $calendar->ShowInMenus = false;
         $calendar->write();
         $calendar->publish('Stage', 'Live');
         $leaders = new ScoutGroupLeaders();
         $leaders->ParentID = $this->ID;
         $leaders->Title = "Leaders";
         $leaders->ShowInMenus = false;
         $leaders->write();
         $leaders->publish('Stage', 'Live');
     }
     $this->isInsert = false;
 }
コード例 #3
0
 public function getCMSFields()
 {
     $f = parent::getCMSFields();
     //$f->removeByName("Content");
     //$gridFieldConfig = GridFieldConfig_RecordEditor::create();
     //$gridFieldConfig->addComponent(new GridFieldSortableRows('SortOrder'));
     /*$gridField = new GridField("StaffTeam", "Staff Teams", StaffTeam::get(), GridFieldConfig_RecordEditor::create());
     		$f->addFieldToTab("Root.Main", $gridField); // add the grid field to a tab in the CMS	*/
     return $f;
 }
コード例 #4
0
 public function loadDescendantBlogHolderIDListInto(&$idList)
 {
     $blogHolders = BlogHolder::get();
     if (count($blogHolders)) {
         foreach ($blogHolders as $holder) {
             if (!in_array($holder->ID, $idList)) {
                 $idList[] = $holder->ID;
             }
         }
     }
 }
 public function getBlogCategoriesMoreLink()
 {
     if (Config::inst()->get('BlogCategory', 'limit_to_holder')) {
         $parent = $this->owner->Parent();
     } else {
         $parent = BlogTree::get()->filter('ClassName', 'BlogTree')->First();
         if (!$parent) {
             $parent = BlogHolder::get()->First();
         }
     }
     return $parent->Link('categoryindex');
 }
 public function getCMSFields()
 {
     $fields = parent::getCMSFields();
     Requirements::javascript(THIRDPARTY_DIR . '/jquery/jquery.js');
     Requirements::javascript('wordpressconnector/javascript/WordpressPostContentSource.js');
     if (!class_exists('BlogEntry')) {
         $fields->addFieldToTab('Root.Import', new LiteralField('RequiresBlogImport', '<p>The Wordpress connector requires the blog module to import posts.</p>'));
     } else {
         $blogs = BlogHolder::get();
         $map = $blogs ? $blogs->map() : array();
         $fields->addFieldsToTab('Root.Import', array(new DropdownField('MigrationTarget', 'Blog to import into', $map), new CheckboxField('ImportComments', 'Import comments attached to the posts?', true), new CheckboxField('ImportMedia', 'Import and rewrite references to wordpress media?', true), new TextField('AssetsPath', 'Upload wordpress files to', 'Uploads/Wordpress')));
     }
     return $fields;
 }
コード例 #7
0
ファイル: BlogHolder.php プロジェクト: nicmart/comperio-site
 /**
  * Create default blog setup
  */
 function requireDefaultRecords()
 {
     parent::requireDefaultRecords();
     $blogHolder = DataObject::get_one('BlogHolder');
     //TODO: This does not check for whether this blogholder is an orphan or not
     if (!$blogHolder) {
         $blogholder = new BlogHolder();
         $blogholder->Title = "Blog";
         $blogholder->URLSegment = "blog";
         $blogholder->Status = "Published";
         $widgetarea = new WidgetArea();
         $widgetarea->write();
         $blogholder->SideBarID = $widgetarea->ID;
         $blogholder->write();
         $blogholder->publish("Stage", "Live");
         $managementwidget = new BlogManagementWidget();
         $managementwidget->ParentID = $widgetarea->ID;
         $managementwidget->write();
         $tagcloudwidget = new TagCloudWidget();
         $tagcloudwidget->ParentID = $widgetarea->ID;
         $tagcloudwidget->write();
         $archivewidget = new ArchiveWidget();
         $archivewidget->ParentID = $widgetarea->ID;
         $archivewidget->write();
         $widgetarea->write();
         $blog = new BlogEntry();
         $blog->Title = _t('BlogHolder.SUCTITLE', "SilverStripe blog module successfully installed");
         $blog->URLSegment = 'sample-blog-entry';
         $blog->Tags = _t('BlogHolder.SUCTAGS', "silverstripe, blog");
         $blog->Content = _t('BlogHolder.SUCCONTENT', "<p>Congratulations, the SilverStripe blog module has been successfully installed. This blog entry can be safely deleted. You can configure aspects of your blog (such as the widgets displayed in the sidebar) in <a href=\"admin\">the CMS</a>.</p>");
         $blog->Status = "Published";
         $blog->ParentID = $blogholder->ID;
         $blog->write();
         $blog->publish("Stage", "Live");
         DB::alteration_message("Blog page created", "created");
     }
 }
コード例 #8
0
	/**
	 * 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, \"&#215;\", \"x\")");
			pg_query($dbconn, "UPDATE SiteTree SET Content = REPLACE(Content, \"&#8217;\", \"&rsquo;\")");
			pg_query($dbconn, "UPDATE SiteTree SET Content = REPLACE(Content, \"&#8216;\", \"&lsquo;\")");
			pg_query($dbconn, "UPDATE SiteTree SET Content = REPLACE(Content, \"&#151;\", \"&mdash;\")");
			pg_query($dbconn, "UPDATE SiteTree SET Content = REPLACE(Content, \"&#8220;\", \"&ldquo;\")");
			pg_query($dbconn, "UPDATE SiteTree SET Content = REPLACE(Content, \"&#8221;\", \"&rdquo;\")");
			pg_query($dbconn, "UPDATE SiteTree SET Content = REPLACE(Content, \"&#8211;\", \"&ndash;\")");
			pg_query($dbconn, "UPDATE SiteTree SET Content = REPLACE(Content, \"&#8212;\", \"&mdash;\")");
			pg_query($dbconn, "UPDATE SiteTree SET Content = REPLACE(Content, \"&#8230;\", \"&hellip;\")");
			pg_query($dbconn, "UPDATE SiteTree SET Content = REPLACE(Content, \"&#8482;\", \"&trade;\")");
			pg_query($dbconn, "UPDATE SiteTree SET Content = REPLACE(Content, \"&#38;\", \"&amp;\")");
			
			pg_query($dbconn, "UPDATE PageComment SET Comment = REPLACE(Comment, \"&#215;\", \"x\")");
			pg_query($dbconn, "UPDATE PageComment SET Comment = REPLACE(Comment, \"&#8217;\", \"&rsquo;\")");
			pg_query($dbconn, "UPDATE PageComment SET Comment = REPLACE(Comment, \"&#8216;\", \"&lsquo;\")");
			pg_query($dbconn, "UPDATE PageComment SET Comment = REPLACE(Comment, \"&#151;\", \"&mdash;\")");
			pg_query($dbconn, "UPDATE PageComment SET Comment = REPLACE(Comment, \"&#8220;\", \"&ldquo;\")");
			pg_query($dbconn, "UPDATE PageComment SET Comment = REPLACE(Comment, \"&#8221;\", \"&rdquo;\")");
			pg_query($dbconn, "UPDATE PageComment SET Comment = REPLACE(Comment, \"&#8211;\", \"&ndash;\")");
			pg_query($dbconn, "UPDATE PageComment SET Comment = REPLACE(Comment, \"&#8212;\", \"&mdash;\")");
			pg_query($dbconn, "UPDATE PageComment SET Comment = REPLACE(Comment, \"&#8230;\", \"&hellip;\")");
			pg_query($dbconn, "UPDATE PageComment SET Comment = REPLACE(Comment, \"&#8482;\", \"&trade;\")");
			pg_query($dbconn, "UPDATE PageComment SET Comment = REPLACE(Comment, \"&#38;\", \"&amp;\")");
			
			
		}
		
		pg_close($dbconn);
		
	} // end function
 /**
  * @return BlogHolder
  */
 protected function getHolder($record)
 {
     $filter = new URLSegmentFilter();
     $urlSegment = $filter->filter($record['blog_path']);
     $tree = $this->_cache_tree;
     if (!$tree) {
         $tree = BlogTree::get()->filter(array('Title' => 'Blogs'))->First();
         if (!$tree) {
             $tree = new BlogTree(array('Title' => 'Blogs', 'ParentID' => $this->parentId));
             $tree->write();
             if ($this->publish) {
                 $tree->publish('Stage', 'Live');
             }
         }
         $this->_cache_tree = $tree;
     }
     $holder = isset($this->_cache_holders[$urlSegment]) ? $this->_cache_holders[$urlSegment] : null;
     if (!$holder) {
         $holder = BlogHolder::get()->filter(array('URLSegment' => $urlSegment, 'ParentID' => $tree->ID))->First();
         if (!$holder) {
             $holder = new BlogHolder(array('Title' => $record['blog_title'], 'URLSegment' => $urlSegment, 'ParentID' => $tree->ID));
             $holder->write();
             if ($this->publish) {
                 $holder->publish('Stage', 'Live');
             }
         }
         $this->_cache_holders[$urlSegment] = $holder;
     }
     return $holder;
 }