Example #1
0
 public function import_wordpress_xml()
 {
     if ($this->post('import-images') == 'on') {
         $this->importImages = true;
         $filesetname;
         $this->post('file-set-name') ? $this->filesetname = $this->post('file-set-name') : ($this->filesetname = t("Imported Wordpress Files"));
         $this->createFileSet = true;
     }
     $pages = array();
     if (intval($this->post('wp-file')) > 0) {
         Loader::model('file');
         $co = new Config();
         $pkg = Package::getByHandle('wordpress_site_importer');
         $co->setPackageObject($pkg);
         $co->save("WORDPRESS_IMPORT_FID", $this->post('wp-file'));
         $importFile = File::getByID($this->post('wp-file'));
         $nv = $importFile->getVersion();
         $fileUrl = $nv->getDownloadURL();
         $xml = @simplexml_load_file($fileUrl, "SimpleXMLElement", LIBXML_NOCDATA);
         $items = array();
         foreach ($xml->channel->item as $item) {
             $items[] = $item->asxml();
         }
         $db = Loader::db();
         $sql = $db->Prepare('insert into WordpressItems (wpItem) values(?)');
         foreach ($items as $item) {
             $db->Execute($sql, $item);
         }
         $categories = array();
         $namespaces = $xml->getDocNamespaces();
         foreach ($xml->xpath('/rss/channel/wp:category') as $term_arr) {
             $t = $term_arr->children($namespaces['wp']);
             $categories[] = array('term_id' => (int) $t->term_id, 'category_nicename' => (string) $t->category_nicename, 'category_parent' => (string) $t->category_parent, 'cat_name' => (string) $t->cat_name, 'category_description' => (string) $t->category_description);
         }
         Loader::model('attribute/categories/collection');
         $akt = CollectionAttributeKey::getByHandle("wordpress_category");
         for ($i = 0; $i < count($categories); $i++) {
             $opt = new SelectAttributeTypeOption(0, $categories[$i]['cat_name'], $i);
             $opt = $opt->saveOrCreate($akt);
         }
         foreach ($xml->xpath('/rss/channel/wp:tag') as $term_arr) {
             $t = $term_arr->children($namespaces['wp']);
             $tags[] = array('term_id' => (int) $t->term_id, 'tag_slug' => (string) $t->tag_slug, 'tag_name' => (string) $t->tag_name, 'tag_description' => (string) $t->tag_description);
         }
         $akt = CollectionAttributeKey::getByHandle("tags");
         for ($i = 0; $i < count($tags); $i++) {
             $opt = new SelectAttributeTypeOption(0, $tags[$i]['tag_name'], $i);
             $opt = $opt->saveOrCreate($akt);
         }
     } else {
         echo t("No file");
         exit;
     }
     $this->view();
 }
 public function install()
 {
     $pkg = parent::install();
     Loader::model('single_page');
     $single_page = SinglePage::add('/dashboard/wordpress_import', $pkg);
     $single_page->update(array('cName' => t('WordPress Import'), 'cDescription' => t('Import WordPress Sites')));
     $import_stuff = SinglePage::add('/dashboard/wordpress_import/import', $pkg);
     $import_stuff->update(array('cName' => t('Import')));
     $import_stuff = SinglePage::add('/dashboard/wordpress_import/file', $pkg);
     $import_stuff->update(array('cName' => t('File')));
     $select = AttributeType::getByHandle('select');
     $wpCategory = CollectionAttributeKey::getByHandle('wordpress_category');
     if (!$wpCategory instanceof CollectionAttributeKey) {
         $wpCategory = CollectionAttributeKey::add($select, array('akSelectAllowMultipleValues' => 1, 'akSelectOptionDisplayOrder' => 'popularity_desc', 'akSelectAllowOtherValues' => 1, 'akHandle' => 'wordpress_category', 'akName' => t('Wordpress Category')), $pkg);
     }
     $tags = CollectionAttributeKey::getByHandle('tags');
     if (!$tags instanceof CollectionAttributeKey) {
         $tags = CollectionAttributeKey::add($select, array('akSelectAllowMultipleValues' => 1, 'akSelectOptionDisplayOrder' => 'popularity_desc', 'akSelectAllowOtherValues' => 1, 'akHandle' => 'tagsy', 'akName' => t('Tags')), $pkg);
     }
     $co = new Config();
     $co->setPackageObject($pkg);
     $co->save("WORDPRESS_IMPORT_FID", 0);
 }
Example #3
0
 public function clearConfig($cfKey)
 {
     $co = new Config();
     $co->setPackageObject($this);
     return $co->clear($cfKey);
 }
Example #4
0
 public function testSaveWithPackage()
 {
     $store = $this->getStoreMock();
     $store->expects($this->once())->method('set')->with($this->equalTo('test'), $this->equalTo('someValue'), $this->equalTo('112'));
     Config::setStore($store);
     $packagemock = $this->getMock('stdClass', array('getPackageID'));
     $packagemock->expects($this->once())->method('getPackageID')->will($this->returnValue('112'));
     $config = new Config();
     $config->setPackageObject($packagemock);
     $config->save('test', 'someValue');
 }
 function import_wordpress_site()
 {
     $db = Loader::db();
     Loader::library('formatting', 'wordpress_site_importer');
     $this->importImages = $this->post('import-images');
     $this->createFileSet = $this->importImages;
     $unImported = $db->GetOne("SELECT COUNT(*) FROM WordpressItems where imported = 0");
     if ($unImported > 0) {
         $data = array('remain' => $unImported, 'processed' => '', 'titles' => array());
         $xml = $db->GetAll("SELECT wpItem,id FROM WordpressItems where imported = 0 LIMIT 10");
         $data['processed'] = sizeof($xml);
         /*	var_dump($xml);
         			exit;
         			*/
     } else {
         // sort out by parent ID here
         $pageroot = Page::getByID($this->post('new-root-pages'));
         $postroot = Page::getByID($this->post('new-root-posts'));
         $pages = $db->getAll("SELECT cID, wpID, wpParentID, wpPostType FROM WordpressItems");
         $all_categories = array();
         foreach ($pages as $page) {
             if (intval($page['wpParentID']) > 0) {
                 // have a parent id, figure out where this one goes
                 $q = "SELECT cID FROM WordpressItems WHERE wpID = ?";
                 $v = array($page['wpParentID']);
                 $parentCID = $db->getOne($q, $v);
                 if (intval($parentCID) > 0) {
                     $newParent = Page::getByID($parentCID);
                     $rowPage = Page::getByID($page['cID']);
                     $rowPage->move($newParent);
                 }
             }
         }
         echo 0;
         exit;
     }
     $co = new Config();
     $pkg = Package::getByHandle('wordpress_site_importer');
     $co->setPackageObject($pkg);
     $importFID = $co->get("WORDPRESS_IMPORT_FID");
     Loader::model('file');
     $importFile = File::getByID($importFID);
     $nv = $importFile->getVersion();
     $fileUrl = $nv->getDownloadURL();
     $meta_xml = @simplexml_load_file($fileUrl);
     $categories = array();
     $meta_namespaces = $meta_xml->getDocNamespaces();
     foreach ($meta_xml->xpath('/rss/channel/wp:category') as $term_arr) {
         $t = $term_arr->children($meta_namespaces['wp']);
         $nicename = (string) $t->category_nicename;
         $categories[$nicename] = array('term_id' => (int) $t->term_id, 'category_nicename' => (string) $t->category_nicename, 'category_parent' => (string) $t->category_parent, 'cat_name' => (string) $t->cat_name, 'category_description' => (string) $t->category_description);
     }
     foreach ($meta_xml->xpath('/rss/channel/wp:tag') as $term_arr) {
         $t = $term_arr->children($meta_namespaces['wp']);
         $slug = (string) $t->tag_slug;
         $tags[$slug] = array('term_id' => (int) $t->term_id, 'tag_slug' => (string) $t->tag_slug, 'tag_name' => (string) $t->tag_name, 'tag_description' => (string) $t->tag_description);
     }
     $ids = array();
     foreach ($xml as $wpItem) {
         libxml_use_internal_errors;
         $item = @new SimpleXMLElement($wpItem['wpItem']);
         $p = new PageLite();
         //Use that namespace
         $title = (string) $item->title;
         $datePublic = $item->pubDate;
         $namespaces = $item->getNameSpaces(true);
         //Now we don't have the URL hard-coded
         $wp = $item->children($namespaces['wp']);
         if ($wp->status == "auto-draft") {
             $ids[] = $wpItem['id'];
             $data['titles'][] = $title;
             continue;
         }
         $wpPostID = (int) $wp->post_id;
         $content = $item->children($namespaces['content']);
         $content = wpautop((string) $content->encoded);
         /*
         	find the caption in the caption.
         	replace [caption ... with <div class="wp-caption-frame"> //alternatively there should be a custom image template that creates a caption.
         	that might be the more c5 way to do this.
         	then [/caption] with the image and then <span class="wp-caption-text">$caption_text</span></div>
         	???
         */
         $comments = $wp->comment;
         $all_comments = array();
         if (count($comments) > 0) {
             if (intval($comments->comment_id) > 0) {
                 // single comment
                 $comment_details = array();
                 $comment_details['commentText'] = (string) $comments->comment_content;
                 $comment_details['name'] = (string) $comments->comment_author;
                 $comment_details['email'] = (string) $comments->comment_author_email;
                 $comment_details['approved'] = (int) $comments->comment_approved;
                 $comment_details['comment_type'] = (string) $comments->comment_type;
                 $comment_details['comment_date'] = (string) $comments->comment_date;
                 $all_comments[] = $comment_details;
             } else {
                 // we have multiple comments for this post, loop over them in turn.
                 foreach ($comments as $comment) {
                     $comment_details = array();
                     $comment_details['commentText'] = (string) $comment->comment_content;
                     $comment_details['name'] = (string) $comment->comment_author;
                     $comment_details['email'] = (string) $comment->comment_author_email;
                     $comment_details['approved'] = (int) $comment->comment_approved;
                     $comment_details['comment_type'] = (string) $comments->comment_type;
                     $comment_details['comment_date'] = (string) $comments->comment_date;
                     $all_comments[] = $comment_details;
                 }
             }
         }
         $excerpt = $item->children($namespaces['excerpt']);
         $postDate = (string) $wp->post_date;
         $postType = (string) $wp->post_type;
         $dc = $item->children($namespaces['dc']);
         $author = (string) $dc->creator;
         $parentID = (int) $wp->post_parent;
         $out_tags = array();
         $out_categories = array();
         foreach ($item->category as $c) {
             $att = $c->attributes();
             if (isset($att['nicename'])) {
                 $nicename = (string) $att['nicename'];
                 if ($att['domain'] == "category") {
                     $realname = $categories[$nicename]['cat_name'];
                     $out_categories[] = $realname;
                 } else {
                     $realname = $tags[$nicename]['tag_name'];
                     $out_tags[] = $realname;
                 }
             }
         }
         $p->setTitle($title);
         $p->setContent($content);
         $p->setAuthor($author);
         $p->setWpParentID($parentID);
         $p->setPostDate($postDate);
         $p->setPostType($postType);
         $p->setCategory($out_categories);
         $p->setTags($out_tags);
         $p->setPostID($wpPostID);
         $p->setExcerpt($excerpt);
         $p->setComments($all_comments);
         //so we just throw these guys in an array
         $pages[$wpItem['id']] = $p;
         //postID is unique
         $ids[] = $wpItem['id'];
         $data['titles'][] = $title;
     }
     if (count($pages) > 0) {
         //call the function below
         $this->buildSiteFromWordPress($pages);
     }
     $db->Execute('UPDATE WordpressItems set imported=1 where id in(' . implode(',', $ids) . ')');
     $json = Loader::helper('json');
     echo $json->encode($data);
     exit;
 }