function display($tpl = null) { // @rule: Test for user access if on 1.6 and above if (EasyBlogHelper::getJoomlaVersion() >= '1.6') { if (!JFactory::getUser()->authorise('easyblog.manage.setting', 'com_easyblog')) { JFactory::getApplication()->redirect('index.php', JText::_('JERROR_ALERTNOAUTHOR'), 'error'); JFactory::getApplication()->close(); } } //initialise variables $document = JFactory::getDocument(); $user = JFactory::getUser(); $config = EasyBlogHelper::getConfig(); $jconfig = JFactory::getConfig(); $dstOptions = array(); $iteration = -12; for ($i = 0; $i <= 24; $i++) { $dstOptions[] = JHTML::_('select.option', $iteration, $iteration); $iteration++; } $dstList = JHTML::_('select.genericlist', $dstOptions, 'main_dstoffset', 'class="inputbox" size="1"', 'value', 'text', $config->get('main_dstoffset', 0)); //check if jomcomment installed. $jcInstalled = false; if (file_exists(JPATH_ROOT . '/administrator/components/com_jomcomment/config.jomcomment.php')) { $jcInstalled = true; } //check if jcomments installed. $jcommentInstalled = false; $jCommentFile = JPATH_ROOT . '/components/com_jcomments/jcomments.php'; if (JFile::exists($jCommentFile)) { $jcommentInstalled = true; } //check if rscomments installed. $rscommentInstalled = false; $rsCommentFile = JPATH_ROOT . '/components/com_rscomments/rscomments.php'; if (JFile::exists($rsCommentFile)) { $rscommentInstalled = true; } // @task: Check if easydiscuss plugin is installed and enabled. $easydiscuss = JPluginHelper::isEnabled('content', 'easydiscuss'); $komento = JPluginHelper::isEnabled('content', 'komento'); $defaultSAId = EasyBlogHelper::getDefaultSAIds(); $joomlaVersion = EasyBlogHelper::getJoomlaVersion(); $socialButtonsOrder = $this->getSocialButtonOrder(); $this->assignRef('jConfig', $jconfig); $this->assignRef('config', $config); $this->assignRef('dstList', $dstList); $this->assignRef('jcInstalled', $jcInstalled); $this->assignRef('easydiscuss', $easydiscuss); $this->assignRef('komento', $komento); $this->assignRef('jcommentInstalled', $jcommentInstalled); $this->assignRef('rscommentInstalled', $rscommentInstalled); $this->assignRef('defaultSAId', $defaultSAId); $this->assignRef('joomlaversion', $joomlaVersion); $this->assignRef('socialButtonsOrder', $socialButtonsOrder); parent::display($tpl); }
echo JText::_('COM_EASYBLOG_MIGRATOR_BLOGGERXML_IMPORT_AS'); ?> <i data-html="true" data-placement="top" data-title="<?php echo JText::_('COM_EASYBLOG_MIGRATOR_BLOGGERXML_IMPORT_AS'); ?> " data-content="<?php echo JText::_('COM_EASYBLOG_MIGRATOR_BLOGGERXML_IMPORT_AS_DESC'); ?> " data-eb-provide="popover" class="fa fa-question-circle pull-right"></i> </label> <div class="col-md-7"> <input type="text" name="authorid" class="form-control" value="<?php echo EasyBlogHelper::getDefaultSAIds(); ?> " data-author-id /> </div> </div> <div class="form-group"> <label for="page_title" class="col-md-5"> <?php echo JText::_('COM_EASYBLOG_MIGRATOR_BLOGGERXML_IMPORT_INTO_CATEGORY'); ?> <i data-html="true" data-placement="top" data-title="<?php echo JText::_('COM_EASYBLOG_MIGRATOR_BLOGGERXML_IMPORT_INTO_CATEGORY'); ?> "
function _migrateWPXML($fileName, $authorId) { $db = EasyBlogHelper::db(); $jSession = JFactory::getSession(); $ejax = new EJax(); $migrateStat = $jSession->get('EBLOG_MIGRATOR_JOOMLA_STAT', '', 'EASYBLOG'); if (empty($migrateStat)) { $migrateStat = new stdClass(); $migrateStat->blog = 0; $migrateStat->category = 0; $migrateStat->user = array(); } $posts = $this->getXMLPostData($fileName); if (!isset($posts->post_id)) { $this->clearXMLData($fileName); //at here, we check whether there are any records processed. if yes, //show the statistic. $ejax->append('progress-status6', JText::_('COM_EASYBLOG_MIGRATOR_FINISHED')); $ejax->script("divSrolltoBottomWordPressXML();"); //update statistic $stat = '========================================== <br />'; $stat .= JText::_('COM_EASYBLOG_MIGRATOR_TOTAL_BLOGS') . ': ' . $migrateStat->blog . '<br />'; $statUser = $migrateStat->user; if (!empty($statUser)) { $stat .= '<br />'; $stat .= 'Total user\'s contribution: ' . count($statUser) . '<br />'; foreach ($statUser as $eachUser) { $stat .= JText::_('COM_EASYBLOG_MIGRATOR_TOTAL_BLOG_USER') . ' \'' . $eachUser->name . '\': ' . $eachUser->blogcount . '<br />'; } } $stat .= '<br />=========================================='; $ejax->assign('stat-status6', $stat); $ejax->script("\$( '#migrator-submit6' ).html('" . JText::_('COM_EASYBLOG_MIGRATOR_MIGRATION_COMPLETED') . "');"); $ejax->script("\$( '#migrator-submit6' ).attr('disabled' , '');"); $ejax->script("\$( '#icon-wait6' ).css( 'display' , 'none' );"); $ejax->send(); } $data = $posts->data; $contentId = $data['post_id']; $data['comments'] = $posts->comments; if (empty($contentId)) { $this->clearXMLData($fileName, true); $ejax->script("ejax.load('migrators','_migrateWPXML','{$fileName}','{$authorId}');"); $ejax->send(); } $query = 'SELECT content_id FROM `#__easyblog_migrate_content` AS b'; $query .= ' WHERE b.`content_id` = ' . $db->Quote($contentId); $query .= ' and `component` = ' . $db->Quote('xml_wordpress'); $query .= ' and `filename` = ' . $db->Quote($fileName); $db->setQuery($query); $row = $db->loadResult(); if (is_null($row)) { // step 1 : create categery if not exist in eblog_categories // step 2 : create user if not exists in eblog_users - create user through profile jtable load method. $date = EB::date(); $blogObj = new stdClass(); $adminId = empty($authorId) ? EasyBlogHelper::getDefaultSAIds() : $authorId; //default $blogObj->category_id = 1; //assume 1 is the uncategorized id. $wpCat = ''; $wpTag = array(); if (!empty($data['terms'])) { foreach ($data['terms'] as $term) { if ($term['domain'] == 'category' && empty($wpCat)) { $wpCat = new stdClass(); $wpCat->title = $term['name']; $wpCat->alias = $term['slug']; } else { if ($term['domain'] == 'post_tag') { $tmpTag = new stdClass(); $tmpTag->title = $term['name']; $tmpTag->alias = $term['slug']; $wpTag[] = $tmpTag; } } } } if (isset($wpCat->title)) { $eCat = $this->_isEblogCategoryExists($wpCat); if ($eCat === false) { $eCat = $this->_createEblogCategory($wpCat); } $blogObj->category_id = $eCat; } //load user profile $profile = EB::user($adminId); $blog = EB::table('Blog'); //assigning blog data $blogObj->created_by = $profile->id; $blogObj->created = !empty($data['post_date_gmt']) ? $data['post_date_gmt'] : $date->toMySQL(); $blogObj->modified = $date->toMySQL(); $blogObj->title = $data['post_title']; $blogObj->permalink = empty($data['post_name']) ? EasyBlogHelper::getPermalink($data['post_title']) : $data['post_name']; // Migrate caption $pattern2 = '/\\[caption.*caption="(.*)"\\]/iU'; $data['post_content'] = preg_replace($pattern2, '<div class="caption">$1</div>', $data['post_content']); $data['post_content'] = str_ireplace('[/caption]', '<br />', $data['post_content']); // process attachments. // $attachments = $this->getXMLAttachmentData( $fileName, $contentId); // if( count($attachments) > 0 ) // { // $data['post_excerpt'] = $this->_processWPXMLAttachment($contentId, $data['post_excerpt'], $attachments, $authorId); // $data['post_content'] = $this->_processWPXMLAttachment($contentId, $data['post_content'], $attachments, $authorId); // } $data['post_excerpt'] = nl2br($data['post_excerpt']); $data['post_content'] = nl2br($data['post_content']); $blogObj->intro = $data['post_excerpt']; $blogObj->content = $data['post_content']; //translating the article state into easyblog publish status. $blogState = '0'; $isPrivate = '0'; if ($data['status'] == 'private') { $isPrivate = '1'; $blogState = '1'; } else { if ($data['status'] == 'publish') { $isPrivate = '0'; $blogState = '1'; } } $blogObj->blogpassword = $data['post_password']; $blogObj->access = $isPrivate; $blogObj->published = $blogState; $blogObj->publish_up = !empty($data['post_date_gmt']) ? $data['post_date_gmt'] : $date->toMySQL(); $blogObj->publish_down = '0000-00-00 00:00:00'; $blogObj->ordering = 0; $blogObj->hits = 0; $blogObj->frontpage = 1; $blogObj->allowcomment = $data['comment_status'] == 'open' ? 1 : 0; $blog->bind($blogObj); $blog->store(); // add tags. if (count($wpTag) > 0) { foreach ($wpTag as $item) { $now = EB::date(); $tag = EB::table('Tag'); if ($tag->exists($item->title)) { $tag->load($item->title, true); } else { $tagArr = array(); $tagArr['created_by'] = $adminId; $tagArr['title'] = $item->title; $tagArr['alias'] = $item->alias; $tagArr['published'] = '1'; $tagArr['created'] = $now->toMySQL(); $tag->bind($tagArr); $tag->store(); } $postTag = EB::table('PostTag'); $postTag->tag_id = $tag->id; $postTag->post_id = $blog->id; $postTag->created = $now->toMySQL(); $postTag->store(); } } // add comments if (!empty($data['comments']) && is_array($data['comments'])) { // Sort first usort($data['comments'], array($this, '_sortWPXMLComments')); foreach ($data['comments'] as $citem) { $item = JArrayHelper::toObject($citem); if ($item->comment_parent == 0) { $this->_migrateWPComments('xml', $contentId, $blog->id, 0, $item, $data['comments']); } } } //update session value $migrateStat->blog++; $statUser = $migrateStat->user; $statUserObj = null; if (!isset($statUser[$profile->id])) { $statUserObj = new stdClass(); $statUserObj->name = $profile->nickname; $statUserObj->blogcount = 0; } else { $statUserObj = $statUser[$profile->id]; } $statUserObj->blogcount++; $statUser[$profile->id] = $statUserObj; $migrateStat->user = $statUser; $jSession->set('EBLOG_MIGRATOR_JOOMLA_STAT', $migrateStat, 'EASYBLOG'); //log the entry into migrate table. $migrator = EB::table('Migrate'); $migrator->content_id = $contentId; $migrator->post_id = $blog->id; $migrator->session_id = $jSession->getToken(); $migrator->component = 'xml_wordpress'; $migrator->filename = $fileName; $migrator->store(); //$this->clearXMLData( $fileName, $contentId); $ejax->append('progress-status6', JText::_('COM_EASYBLOG_MIGRATOR_MIGRATED_WORDPRESS_XML') . ': ' . $contentId . JText::_('COM_EASYBLOG_MIGRATOR_EASYBLOG') . ': ' . $blog->id . '<br />'); $ejax->script("ejax.load('migrators','_migrateWPXML','{$fileName}','{$authorId}');"); } else { // skip, go to next item. $ejax->script("ejax.load('migrators','_migrateWPXML','{$fileName}','{$authorId}');"); } $ejax->send(); }