Beispiel #1
0
 /**
  * Generate proper permalink for a blog entry
  **/
 function getPermalink($value)
 {
     $ejax = new Ejax();
     $value = urldecode($value);
     $permalink = EasyBlogHelper::getPermalink($value);
     $ejax->value('permalink', $permalink);
     $ejax->send();
 }
Beispiel #2
0
 public static function editPost($postid, $username, $password, $content, $publish)
 {
     $mainframe = JFactory::getApplication();
     global $xmlrpcerruser, $xmlrpcI4, $xmlrpcInt, $xmlrpcBoolean, $xmlrpcDouble, $xmlrpcString, $xmlrpcDateTime, $xmlrpcBase64, $xmlrpcArray, $xmlrpcStruct, $xmlrpcValue;
     EasyBlogXMLRPCHelper::loginUser($username, $password);
     jimport('joomla.application.component.model');
     $my = JFactory::getUser($username);
     $acl = EasyBlogACLHelper::getRuleSet($my->id);
     if (empty($my->id)) {
         return new xmlrpcresp(0, $xmlrpcerruser + 1, JText::_('NO PERMISSION TO CREATE BLOG'));
     }
     if (empty($acl->rules->add_entry)) {
         return new xmlrpcresp(0, $xmlrpcerruser + 1, JText::_('NO PERMISSION TO CREATE BLOG'));
     }
     $isNew = true;
     // create a new blog jtable object
     $isDraft = false;
     $blog = '';
     if (empty($acl->rules->publish_entry)) {
         // Try to load this draft to see if it exists
         $blog = EasyBlogHelper::getTable('Draft');
         $isDraft = true;
     } else {
         $blog = EasyBlogHelper::getTable('Blog', 'Table');
     }
     if (isset($postid) && !empty($postid)) {
         $isNew = false;
         //we are doing editing
         $blog->load($postid);
     }
     //prepare initial blog settings.
     $config = EasyBlogHelper::getConfig();
     $isPrivate = $config->get('main_blogprivacy', '0');
     $allowComment = $config->get('main_comment', 1);
     $allowSubscribe = $config->get('main_subscription', 1);
     $showFrontpage = $config->get('main_newblogonfrontpage', 0);
     $sendEmails = $config->get('main_sendemailnotifications', 1);
     //check if user have permission to enable privacy.
     $aclBlogPrivacy = $acl->rules->enable_privacy;
     $isPrivate = empty($aclBlogPrivacy) ? '0' : $isPrivate;
     $showFrontpage = empty($acl->rules->contribute_frontpage) ? '0' : $showFrontpage;
     /**
      * Map the data input into blog's recognised data format
      */
     $post = array();
     $post['permalink'] = $blog->permalink;
     if (isset($content["wp_slug"])) {
         $post['permalink'] = $content["wp_slug"];
     }
     //check if comment is allow on this blog
     if (isset($content["mt_allow_comments"])) {
         if (!is_numeric($content["mt_allow_comments"])) {
             switch ($content["mt_allow_comments"]) {
                 case "closed":
                     $post['allowcomment'] = 0;
                     break;
                 case "open":
                     $post['allowcomment'] = 1;
                     break;
                 default:
                     $post['allowcomment'] = $allowComment;
                     break;
             }
         } else {
             switch ((int) $content["mt_allow_comments"]) {
                 case 0:
                 case 2:
                     $post['allowcomment'] = 0;
                     break;
                 case 1:
                     $post['allowcomment'] = 1;
                     break;
                 default:
                     $post['allowcomment'] = $allowComment;
                     break;
             }
         }
     }
     //end if allowcomment
     $post['title'] = $content['title'];
     $post['intro'] = '';
     $post['content'] = '';
     if (isset($content['mt_text_more']) && $content['mt_text_more']) {
         $post['intro'] = $content['description'];
         $post['content'] = $content['mt_text_more'];
     } else {
         if (isset($content['more_text']) && $content['more_text']) {
             $post['intro'] = $content['description'];
             $post['content'] = $content['more_text'];
         } else {
             $post['content'] = $content['description'];
         }
     }
     // if introtext still empty and excerpt is provide, then we use it.
     if (empty($post['intro']) && isset($content['mt_excerpt'])) {
         $post['intro'] = $content['mt_excerpt'];
     }
     //set category
     if (isset($content['categories'])) {
         $categoryTitle = '';
         if (is_array($content['categories'])) {
             //always get the 1st option. currently not supported multi categories
             $categoryTitle = @$content['categories'][0];
         } else {
             $categoryTitle = $content['categories'];
         }
         if (empty($categoryTitle)) {
             if ($isNew) {
                 $post['category_id'] = 1;
             }
             // by default the 1 is the uncategorised.
         } else {
             $db = EasyBlogHelper::db();
             $query = 'SELECT `id` FROM `#__easyblog_category`';
             $query .= ' WHERE `title` = ' . $db->Quote($categoryTitle);
             $db->setQuery($query);
             $result = $db->loadResult();
             if (!empty($result)) {
                 $post['category_id'] = $result;
             } else {
                 $post['category_id'] = 1;
             }
         }
     } else {
         if ($isNew) {
             $post['category_id'] = 1;
         }
     }
     $post['published'] = $publish;
     $post['private'] = $isPrivate;
     if (isset($content["post_status"])) {
         switch ($content["post_status"]) {
             case 'publish':
                 $post['published'] = 1;
                 break;
             case 'private':
                 $post['published'] = 1;
                 $post['private'] = 1;
                 break;
             case 'draft':
                 $post['published'] = 0;
                 break;
             case 'schedule':
                 $post['published'] = 2;
                 break;
             case 'pending':
             default:
                 $post['published'] = 0;
                 break;
         }
     }
     // echo '<pre>';
     // var_dump($post['published']);
     // var_dump($post['content']);
     // echo '</pre>';
     // exit;
     // Do some timestamp voodoo
     $tzoffset = EasyBlogDateHelper::getOffSet();
     $overwriteDate = false;
     if (!empty($content['date_created_gmt'])) {
         $date = EasyBlogHelper::getDate($content['date_created_gmt']);
         $blog->created = $date->toFormat();
     } else {
         if (!empty($content['dateCreated'])) {
             $date = EasyBlogHelper::getDate($content['dateCreated']);
             //$date   = EasyBlogDateHelper::dateWithOffSet( $content['dateCreated'] );
             $today = EasyBlogHelper::getDate();
             // somehow blogsy time always return the current time 5 sec faster.
             if ($date->toUnix() > $today->toUnix() + 5) {
                 $post['published'] = 2;
                 $overwriteDate['created'] = $today->toFormat();
                 $overwriteDate['publish_up'] = $date->toFormat();
             } else {
                 $blog->created = $date->toFormat();
                 $overwriteDate['created'] = $date->toFormat();
             }
             // echo $date->toUnix();
             // echo '##';
             // echo $date->toFormat();
             // echo '##';
             // echo $today->toFormat();
             // echo '##';
             // echo $today->toUnix();
             // echo '##';
             // echo $today->toUnix() + 5;
             // exit;
         } else {
             if (!$isNew) {
                 $date = EasyBlogDateHelper::dateWithOffSet($blog->created);
                 $blog->created = $date->toFormat();
                 $date = EasyBlogDateHelper::dateWithOffSet($blog->publish_up);
                 $blog->publish_up = $date->toFormat();
             }
         }
     }
     // we bind this attribute incase if easyblog was a old version.
     $post['issitewide'] = '1';
     //bind the inputs
     $blog->bind($post, true);
     $blog->intro = $post['intro'];
     $blog->content = $post['content'];
     $blog->created_by = $my->id;
     $blog->ispending = 0;
     //(empty($acl->rules->publish_entry)) ? 1 : 0;
     $blog->published = $post['published'];
     if ($overwriteDate !== false) {
         $blog->created = $overwriteDate['created'];
         if (isset($overwriteDate['publish_up'])) {
             $blog->publish_up = $overwriteDate['publish_up'];
         }
     }
     $blog->subscription = $allowSubscribe;
     $blog->frontpage = $showFrontpage;
     $blog->send_notification_emails = $sendEmails;
     $blog->permalink = empty($post['permalink']) ? EasyBlogHelper::getPermalink($blog->title) : $post['permalink'];
     // add in fancy box style.
     $postcontent = $blog->intro . $blog->content;
     // cater for wlw
     $pattern = '#<a.*?\\><img[^>]*><\\/a>#i';
     preg_match_all($pattern, $postcontent, $matches);
     if ($matches && count($matches[0]) > 0) {
         foreach ($matches[0] as $match) {
             $input = $match;
             $largeImgPath = '';
             //getting large image path
             $pattern = '#<a[^>]*>#i';
             preg_match($pattern, $input, $anchors);
             if ($anchors) {
                 preg_match('/href\\s*=\\s*[\\""\']?([^\\""\'\\s>]*)/i', $anchors[0], $adata);
                 if ($adata) {
                     $largeImgPath = $adata[1];
                 }
             }
             $input = $match;
             $pattern = '#<img[^>]*>#i';
             preg_match($pattern, $input, $images);
             if ($images) {
                 preg_match('/src\\s*=\\s*[\\""\']?([^\\""\'\\s>]*)/i', $images[0], $data);
                 if ($data) {
                     $largeImgPath = empty($largeImgPath) ? $data[1] : $largeImgPath;
                     $largeImgPath = urldecode($largeImgPath);
                     $largeImgPath = str_replace(' ', '-', $largeImgPath);
                     $encodedurl = urldecode($data[1]);
                     $encodedurl = str_replace(' ', '-', $encodedurl);
                     $images[0] = str_replace($data[1], $encodedurl, $images[0]);
                     $blog->intro = str_replace($input, '<a class="easyblog-thumb-preview" href="' . $largeImgPath . '">' . $images[0] . '</a>', $blog->intro);
                     $blog->content = str_replace($input, '<a class="easyblog-thumb-preview" href="' . $largeImgPath . '">' . $images[0] . '</a>', $blog->content);
                 }
             }
         }
     } else {
         $pattern = '#<img[^>]*>#i';
         preg_match_all($pattern, $postcontent, $matches);
         if ($matches && count($matches[0]) > 0) {
             foreach ($matches[0] as $match) {
                 $input = $match;
                 preg_match('/src\\s*=\\s*[\\""\']?([^\\""\'\\s>]*)/i', $input, $data);
                 if ($data) {
                     $oriImage = $data[1];
                     $data[1] = urldecode($data[1]);
                     $data[1] = str_replace(' ', '-', $data[1]);
                     $encodedurl = urldecode($oriImage);
                     $encodedurl = str_replace(' ', '-', $encodedurl);
                     $imageurl = str_replace($oriImage, $encodedurl, $input);
                     $blog->intro = str_replace($input, '<a class="easyblog-thumb-preview" href="' . $data[1] . '">' . $imageurl . '</a>', $blog->intro);
                     $blog->content = str_replace($input, '<a class="easyblog-thumb-preview" href="' . $data[1] . '">' . $imageurl . '</a>', $blog->content);
                 }
             }
         }
     }
     if ($isDraft) {
         $blog->pending_approval = true;
         // we need to process trackbacks and tags here.
         //adding trackback.
         if (!empty($acl->rules->add_trackback)) {
             $trackback = isset($content['mt_tb_ping_urls']) ? $content['mt_tb_ping_urls'] : '';
             if (!empty($trackback) && count($trackback) > 0) {
                 $trackback = implode("\n", $trackback);
                 $blog->trackbacks = $trackback;
             }
         }
         // add new tag
         $tags = isset($content['mt_keywords']) ? $content['mt_keywords'] : '';
         $blog->tags = $tags;
     }
     if (!$blog->store()) {
         $msg = $blog->getError();
         $msg = empty($msg) ? 'Post store failed' : $msg;
         return new xmlrpcresp(0, $xmlrpcerruser + 1, $msg);
     }
     if ($isDraft && !empty($blog->id)) {
         // if this post is under moderation, we will stop here.
         return new xmlrpcresp(new xmlrpcval($blog->id, $xmlrpcString));
     }
     /**
      * JomSocial userpoint.
      */
     if ($isNew && $blog->published == '1' && $my->id != 0) {
         // Assign EasySocial points
         $easysocial = EasyBlogHelper::getHelper('EasySocial');
         $easysocial->assignPoints('blog.create', $my->id);
         if ($config->get('main_jomsocial_userpoint')) {
             $jsUserPoint = JPATH_ROOT . DIRECTORY_SEPARATOR . 'components' . DIRECTORY_SEPARATOR . 'com_community' . DIRECTORY_SEPARATOR . 'libraries' . DIRECTORY_SEPARATOR . 'userpoints.php';
             if (JFile::exists($jsUserPoint)) {
                 require_once $jsUserPoint;
                 CUserPoints::assignPoint('com_easyblog.blog.add', $my->id);
             }
         }
         // @rule: Integrations with EasyDiscuss
         EasyBlogHelper::getHelper('EasyDiscuss')->log('easyblog.new.blog', $my->id, JText::sprintf('COM_EASYBLOG_EASYDISCUSS_HISTORY_NEW_BLOG', $blog->title));
         EasyBlogHelper::getHelper('EasyDiscuss')->addPoint('easyblog.new.blog', $my->id);
         EasyBlogHelper::getHelper('EasyDiscuss')->addBadge('easyblog.new.blog', $my->id);
         // Assign badge for users that report blog post.
         // Only give points if the viewer is viewing another person's blog post.
         EasyBlogHelper::getHelper('EasySocial')->assignBadge('blog.create', JText::_('COM_EASYBLOG_EASYSOCIAL_BADGE_CREATE_BLOG_POST'));
         // @rule: Mighty Touch karma points
         EasyBlogHelper::getHelper('MightyTouch')->setKarma($my->id, 'new_blog');
     }
     //add jomsocial activities
     if ($blog->published == '1' && $config->get('main_jomsocial_activity')) {
         EasyBlogXMLRPCHelper::addJomsocialActivities($blog, $isNew);
     }
     // AlphaUserPoints
     // since 1.2
     if (EasyBlogHelper::isAUPEnabled()) {
         // get blog post URL
         $url = EasyBlogRouter::_('index.php?option=com_easyblog&view=entry&id=' . $blog->id);
         AlphaUserPointsHelper::newpoints('plgaup_easyblog_add_blog', '', 'easyblog_add_blog_' . $blog->id, JText::sprintf('AUP NEW BLOG CREATED', $url, $blog->title));
     }
     //adding trackback.
     if (!empty($acl->rules->add_trackback)) {
         $trackback = isset($content['mt_tb_ping_urls']) ? $content['mt_tb_ping_urls'] : '';
         EasyBlogXMLRPCHelper::addTrackback($trackback, $blog, $my);
     }
     // add new tag
     $date = EasyBlogHelper::getDate();
     $tags = isset($content['mt_keywords']) ? $content['mt_keywords'] : '';
     $postTagModel = EasyBlogHelper::getModel('PostTag');
     if ($blog->id != '0') {
         //Delete existing associated tags.
         $postTagModel->deletePostTag($blog->id);
     }
     if (!empty($tags)) {
         $arrTags = explode(',', $tags);
         $tagModel = EasyBlogHelper::getModel('Tags');
         foreach ($arrTags as $tag) {
             if (!empty($tag)) {
                 $table = EasyBlogHelper::getTable('Tag', 'Table');
                 //@task: Only add tags if it doesn't exist.
                 if (!$table->exists($tag)) {
                     if ($acl->rules->create_tag) {
                         $tagInfo['created_by'] = $my->id;
                         $tagInfo['title'] = JString::trim($tag);
                         $tagInfo['created'] = $date->toMySQL();
                         $table->bind($tagInfo);
                         $table->published = 1;
                         $table->status = '';
                         $table->store();
                     }
                 } else {
                     $table->load($tag, true);
                 }
                 //@task: Store in the post tag
                 $postTagModel->add($table->id, $blog->id, $date->toMySQL());
             }
         }
     }
     if ($blog->published) {
         $allowed = array(EBLOG_OAUTH_LINKEDIN, EBLOG_OAUTH_FACEBOOK, EBLOG_OAUTH_TWITTER);
         $blog->autopost($allowed, $allowed);
     }
     return new xmlrpcresp(new xmlrpcval($blog->id, $xmlrpcString));
 }
Beispiel #3
0
 public function processMailbox()
 {
     /*
      * Check enabled
      */
     $config = EasyBlogHelper::getConfig();
     $debug = JRequest::getBool('debug', false);
     if (!$config->get('main_remotepublishing_mailbox') && !$config->get('main_comment_email')) {
         return;
     }
     /*
      * Check Prerequisites setting
      */
     $userid = 0;
     if ($config->get('main_remotepublishing_mailbox_userid') == 0 && !$config->get('main_remotepublishing_mailbox_syncuser')) {
         echo 'Mailbox: Unspecified default user id.' . "<br />\n";
         return false;
     }
     /*
      * Check time interval
      */
     $interval = (int) $config->get('main_remotepublishing_mailbox_run_interval');
     $nextrun = (int) $config->get('main_remotepublishing_mailbox_next_run');
     $nextrun = EasyBlogHelper::getDate($nextrun)->toUnix();
     $timenow = EasyBlogHelper::getDate()->toUnix();
     if ($nextrun !== 0 && $timenow < $nextrun) {
         if (!$debug) {
             echo 'time now: ' . EasyBlogHelper::getDate($timenow)->toMySQL() . "<br />\n";
             echo 'next email run: ' . EasyBlogHelper::getDate($nextrun)->toMySQL() . "<br />\n";
             return;
         }
     }
     $txOffset = EasyBlogDateHelper::getOffSet();
     $newnextrun = EasyBlogHelper::getDate('+ ' . $interval . ' minutes', $txOffset)->toUnix();
     // use $configTable to avoid variable name conflict
     $configTable = EasyBlogHelper::getTable('configs');
     $configTable->load('config');
     $parameters = EasyBlogHelper::getRegistry($configTable->params);
     $parameters->set('main_remotepublishing_mailbox_next_run', $newnextrun);
     $configTable->params = $parameters->toString('ini');
     $configTable->store();
     /*
      * Connect to mailbox
      */
     require_once JPATH_ROOT . DIRECTORY_SEPARATOR . 'components' . DIRECTORY_SEPARATOR . 'com_easyblog' . DIRECTORY_SEPARATOR . 'classes' . DIRECTORY_SEPARATOR . 'mailbox.php';
     $mailbox = new EasyblogMailbox();
     if (!$mailbox->connect()) {
         $mailbox->disconnect();
         echo 'Mailbox: Could not connect to mailbox.';
         return false;
     }
     /*
      * Get data from mailbox
      */
     $total_mails = $mailbox->getMessageCount();
     if ($total_mails < 1) {
         // No mails in mailbox
         $mailbox->disconnect();
         echo 'Mailbox: No emails found.';
         return false;
     }
     // Let's get the correct mails
     $prefix = $config->get('main_remotepublishing_mailbox_prefix');
     $search_criteria = 'UNSEEN';
     if (!empty($prefix)) {
         $search_criteria .= ' SUBJECT "' . $prefix . '"';
     }
     $sequence_list = $mailbox->searchMessages($search_criteria);
     if ($sequence_list === false) {
         // Email with matching subject not found
         $mailbox->disconnect();
         echo 'Mailbox: No matching mails found. ' . $search_criteria;
         echo $debug ? ' criteria: ' . $search_criteria . ' ' : '';
         return false;
     }
     /*
      * Found the mails according to prefix,
      * Let's process each of them
      */
     $total = 0;
     $enable_attachment = $config->get('main_remotepublishing_mailbox_image_attachment');
     $format = $config->get('main_remotepublishing_mailbox_format');
     $limit = $config->get('main_remotepublishing_mailbox_fetch_limit');
     // there's not limit function for imap, so we work around with the array
     // get the oldest message first
     sort($sequence_list);
     $sequence_list = array_slice($sequence_list, 0, $limit);
     foreach ($sequence_list as $sequence) {
         // first, extract from the header
         $msg_info = $mailbox->getMessageInfo($sequence);
         if ($msg_info === false) {
             echo 'Mailbox: Could not get message header.';
             echo $debug ? ' sequence:' . $sequence . ' ' : '';
             continue;
         }
         $uid = $msg_info->message_id;
         $date = $msg_info->MailDate;
         $udate = $msg_info->udate;
         $size = $msg_info->Size;
         $subject = $msg_info->subject;
         $from = '';
         if (isset($msg_info->from)) {
             $senderInfo = $msg_info->from[0];
             if (!empty($senderInfo->mailbox) && !empty($senderInfo->host)) {
                 $from = $senderInfo->mailbox . '@' . $senderInfo->host;
             }
         }
         if (empty($from)) {
             $from = $msg_info->fromemail;
         }
         // @rule: Try to map the sender's email to a user email on the site.
         if ($config->get('main_remotepublishing_mailbox_syncuser')) {
             $db = EasyBlogHelper::db();
             $query = 'SELECT ' . $db->nameQuote('id') . ' FROM ' . $db->nameQuote('#__users') . ' ' . 'WHERE ' . $db->nameQuote('email') . '=' . $db->Quote($from);
             $db->setQuery($query);
             $userid = $db->loadResult();
             // Check if they have permissions
             if ($userid) {
                 $acl = EasyBlogACLHelper::getRuleSet($userid);
                 if (!$acl->rules->add_entry) {
                     continue;
                 }
             }
         } else {
             // sync user email is not require. use the default selected user.
             $userid = $config->get('main_remotepublishing_mailbox_userid');
         }
         if ($userid == 0) {
             echo 'Mailbox: Unable to detect the user based on the email ' . $from . "<br />\n";
             echo $debug ? ' sequence:' . $sequence . ' ' : '';
             continue;
         }
         $date = EasyBlogHelper::getDate($date);
         $date = $date->toMySQL();
         $subject = str_ireplace($prefix, '', $subject);
         $filter = JFilterInput::getInstance();
         $subject = $filter->clean($subject, 'string');
         // @task: If subject is empty, we need to append this with a temporary string. Otherwise user can't edit it from the back end.
         if (empty($subject)) {
             $subject = JText::_('COM_EASYBLOG_MICROBLOG_EMPTY_SUBJECT');
         }
         // filter email according to the whitelist
         $filter = JFilterInput::getInstance();
         $whitelist = $config->get('main_remotepublishing_mailbox_from_whitelist');
         $whitelist = $filter->clean($whitelist, 'string');
         $whitelist = trim($whitelist);
         if (!empty($whitelist)) {
             // Ok. I bluffed we only accept comma seperated values. *wink*
             $pattern = '([\\w\\.\\-]+\\@(?:[a-z0-9\\.\\-]+\\.)+(?:[a-z0-9\\-]{2,4}))';
             preg_match_all($pattern, $whitelist, $matches);
             $emails = $matches[0];
             if (!in_array($from, $emails)) {
                 echo 'Mailbox: Message sender is block: #' . $sequence . ' ' . $subject;
                 continue;
             }
         }
         // this is the magic
         $message = new EasyblogMailboxMessage($mailbox->stream, $sequence);
         $message->getMessage();
         $html = $message->getHTML();
         $plain = $message->getPlain();
         $plain = nl2br($plain);
         $body = $format == 'html' ? $html : $plain;
         $body = $body ? $body : $plain;
         // If plain text is empty, just fall back to html
         if (empty($plain)) {
             $body = nl2br(strip_tags($html));
         }
         $safeHtmlFilter = JFilterInput::getInstance(null, null, 1, 1);
         // JFilterInput doesn't strip css tags
         $body = preg_replace("'<style[^>]*>.*?</style>'si", '', $body);
         $body = $safeHtmlFilter->clean($body, 'html');
         $body = trim($body);
         $attachments = array();
         if ($enable_attachment) {
             $attachments = $message->getAttachment();
             // process attached images
             if (!empty($attachments)) {
                 $config = EasyBlogHelper::getConfig();
                 $main_image_path = $config->get('main_image_path');
                 $main_image_path = rtrim($main_image_path, '/');
                 $rel_upload_path = $main_image_path . '/' . $userid;
                 $userUploadPath = JPATH_ROOT . DIRECTORY_SEPARATOR . $main_image_path . DIRECTORY_SEPARATOR . $userid;
                 $userUploadPath = JPath::clean($userUploadPath);
                 $dir = $userUploadPath . DIRECTORY_SEPARATOR;
                 $tmp_dir = JPATH_ROOT . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR;
                 $uri = JURI::base() . $main_image_path . '/' . $userid . '/';
                 if (!JFolder::exists($dir)) {
                     JFolder::create($dir);
                 }
                 foreach ($attachments as $attachment) {
                     // clean up file name
                     if (strpos($attachment['name'], '/') !== FALSE) {
                         $attachment['name'] = substr($attachment['name'], strrpos($attachment['name'], '/') + 1);
                     } elseif (strpos($attachment['name'], '\\' !== FALSE)) {
                         $attachment['name'] = substr($attachment['name'], strrpos($attachment['name'], '\\') + 1);
                     }
                     // @task: check if the attachment has file extension. ( assuming is images )
                     $imgExts = array('jpg', 'png', 'gif', 'JPG', 'PNG', 'GIF', 'jpeg', 'JPEG');
                     $imageSegment = explode('.', $attachment['name']);
                     if (!in_array($imageSegment[count($imageSegment) - 1], $imgExts)) {
                         $attachment['name'] = $attachment['name'] . '.jpg';
                     }
                     // @task: Store the file into a temporary location first.
                     $attachment['tmp_name'] = $tmp_dir . $attachment['name'];
                     JFile::write($attachment['tmp_name'], $attachment['data']);
                     require_once EBLOG_CLASSES . DIRECTORY_SEPARATOR . 'mediamanager.php';
                     // @task: Ensure that images goes through the same resizing format when uploading via media manager.
                     $media = new EasyBlogMediaManager();
                     $result = $media->upload($dir, $uri, $attachment, '/', 'user');
                     // get the image file name and path
                     if (is_object($result) && property_exists($result, 'title')) {
                         $atmTitle = $result->title;
                         $atmURL = $result->url;
                     } else {
                         $atmTitle = $attachment['name'];
                         $atmURL = $uri . $attachment['name'];
                     }
                     // @task: Once the attachment is processed, delete the temporary file.
                     JFile::delete($attachment['tmp_name']);
                     // now we need to replace the img tag in the email which the source is an attachment id :(
                     $attachId = $attachment['id'];
                     if (!empty($attachId)) {
                         $attachId = str_replace('<', '', $attachId);
                         $attachId = str_replace('>', '', $attachId);
                         $imgPattern = array('/<div><img[^>]*src="[A-Za-z0-9:^>]*' . $attachId . '"[^>]*\\/><\\/div>/si', '/<img[^>]*src="[A-Za-z0-9:^>]*' . $attachId . '"[^>]*\\/>/si');
                         $imgReplace = array('', '');
                         $body = preg_replace($imgPattern, $imgReplace, $body);
                     }
                     // insert image into blog post
                     $body .= '<p><a class="easyblog-thumb-preview" href="' . $atmURL . '" title="' . $atmTitle . '"><img width="' . $config->get('main_thumbnail_width') . '" title="' . $atmTitle . '." alt="" src="' . $atmURL . '" /></a></p>';
                 }
             }
         }
         if ($format == 'plain') {
             $body = nl2br($body);
         }
         // tidy up the content so that the content do not contain incomplete html tag.
         $body = EasyBlogHelper::getHelper('string')->tidyHTMLContent($body);
         $type = $config->get('main_remotepublishing_mailbox_type');
         // insert $body, $subject, $from, $date
         $blog = EasyBlogHelper::getTable('Blog', 'Table');
         // @task: Store the blog post
         $blog->set('title', $subject);
         $blog->set('permalink', EasyBlogHelper::getPermalink($blog->title));
         $blog->set('source', 'email');
         $blog->set('created_by', $userid);
         $blog->set('created', $date);
         $blog->set('modified', $date);
         $blog->set('publish_up', $date);
         $blog->set($type, $body);
         $blog->set('category_id', $config->get('main_remotepublishing_mailbox_categoryid'));
         $blog->set('published', $config->get('main_remotepublishing_mailbox_publish'));
         $blog->set('frontpage', $config->get('main_remotepublishing_mailbox_frontpage'));
         $blog->set('send_notification_emails', $config->get('main_remotepublishing_mailbox_publish'));
         $blog->set('issitewide', true);
         // @task: Set the blog's privacy here.
         $blog->set('private', $config->get('main_remotepublishing_mailbox_privacy'));
         // Store the blog post
         if (!$blog->store()) {
             echo 'Mailbox: Message store failed. > ' . $subject . ' :: ' . $blog->getError();
             continue;
         }
         if ($mailbox->service == 'pop3') {
             $mailbox->deleteMessage($sequence);
         }
         if ($mailbox->service == 'imap') {
             $mailbox->setMessageFlag($sequence, '\\Seen');
         }
         // @rule: Autoposting to social network sites.
         if ($blog->published == POST_ID_PUBLISHED) {
             $blog->autopost(array(EBLOG_OAUTH_LINKEDIN, EBLOG_OAUTH_FACEBOOK, EBLOG_OAUTH_TWITTER), array(EBLOG_OAUTH_LINKEDIN, EBLOG_OAUTH_FACEBOOK, EBLOG_OAUTH_TWITTER));
             $blog->notify(false);
         }
         $total++;
     }
     /*
      * Disconnect from mailbox
      */
     $mailbox->disconnect();
     /*
      * Generate report
      */
     echo JText::sprintf('%1s blog posts fetched from mailbox: ' . $config->get('main_remotepublishing_mailbox_remotesystemname') . '.', $total);
 }
Beispiel #4
0
 function _processLyftenBloggie($migrateComment)
 {
     $db = EasyBlogHelper::db();
     $jSession = JFactory::getSession();
     $ejax = new EJax();
     $migrator = EB::migrator()->getAdapter('k2');
     $migrateStat = $jSession->get('EBLOG_MIGRATOR_JOOMLA_STAT', '', 'EASYBLOG');
     if (empty($migrateStat)) {
         $migrateStat = new stdClass();
         $migrateStat->blog = 0;
         $migrateStat->category = 0;
         $migrateStat->comments = 0;
         $migrateStat->images = 0;
         $migrateStat->user = array();
     }
     $query = 'SELECT * FROM `#__bloggies_entries` AS a';
     $query .= ' WHERE NOT EXISTS (';
     $query .= ' SELECT content_id FROM `#__easyblog_migrate_content` AS b WHERE b.`content_id` = a.`id` and `component` = ' . $db->Quote('com_lyftenbloggie');
     $query .= ' )';
     $query .= ' ORDER BY a.`id` LIMIT 1';
     $db->setQuery($query);
     $row = $db->loadObject();
     if (is_null($row)) {
         // now we migrate the remaining categories
         $this->_migrateLyftenCategories();
         //at here, we check whether there are any records processed. if yes,
         //show the statistic.
         $ejax->append('progress-status3', JText::_('COM_EASYBLOG_MIGRATOR_FINISHED'));
         $ejax->script("divSrolltoBottomLyften();");
         //update statistic
         $stat = '========================================== <br />';
         $stat .= JText::_('COM_EASYBLOG_MIGRATOR_TOTAL_BLOGS') . ': ' . $migrateStat->blog . '<br />';
         $stat .= JText::_('COM_EASYBLOG_MIGRATOR_TOTAL_COMMENTS') . ': ' . $migrateStat->comments . '<br />';
         //$stat  .= 'Total images migrated : ' . $migrateStat->images . '<br />';
         $statUser = $migrateStat->user;
         if (!empty($statUser)) {
             $stat .= '<br />';
             $stat .= JText::_('COM_EASYBLOG_MIGRATOR_TOTAL_USERS_CONTRIBUTIONS') . ': ' . 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-status3', $stat);
         $ejax->script("\$( '#migrator-submit3' ).html('" . JText::_('COM_EASYBLOG_MIGRATOR_MIGRATION_COMPLETED') . "');");
         $ejax->script("\$( '#migrator-submit3' ).attr('disabled' , '');");
         $ejax->script("\$( '#icon-wait3' ).css( 'display' , 'none' );");
     } else {
         // here we should process the migration
         // step 1 : create user if not exists in eblog_users - create user through profile jtable load method.
         // step 2: create categories / tags if needed.
         // step 3: migrate comments if needed.
         $date = EB::date();
         $blogObj = new stdClass();
         //default
         $blogObj->category_id = 1;
         //assume 1 is the uncategorized id.
         if (!empty($row->catid)) {
             $joomlaCat = $this->_getLyftenCategory($row->catid);
             $eCat = $this->_isEblogCategoryExists($joomlaCat);
             if ($eCat === false) {
                 $eCat = $this->_createEblogCategory($joomlaCat);
             }
             $blogObj->category_id = $eCat;
         }
         //load user profile
         $profile = EB::user($row->created_by);
         $blog = EB::table('Blog');
         //assigning blog data
         $blogObj->created_by = $profile->id;
         $blogObj->created = !empty($row->created) ? $row->created : $date->toMySQL();
         $blogObj->modified = !empty($row->modified) ? $row->modified : $date->toMySQL();
         $blogObj->title = $row->title;
         $blogObj->permalink = EasyBlogHelper::getPermalink($row->title);
         if (empty($row->fulltext)) {
             $blogObj->intro = '';
             $blogObj->content = $row->introtext;
         } else {
             $blogObj->intro = $row->introtext;
             $blogObj->content = $row->fulltext;
         }
         $blogObj->published = $row->state == '1' ? '1' : '0';
         // set to unpublish for now.
         $blogObj->publish_up = !empty($row->created) ? $row->created : $date->toMySQL();
         $blogObj->publish_down = '0000-00-00 00:00:00';
         $blogObj->hits = $row->hits;
         $blogObj->frontpage = 1;
         $blogObj->allowcomment = 1;
         $blogObj->subscription = 1;
         $blog->bind($blogObj);
         $blog->store();
         //add meta description
         $migrator->migrateContentMeta($row->metakey, $row->metadesc, $blog->id);
         //step 2: tags
         $query = 'insert into `#__easyblog_post_tag` (`tag_id`, `post_id`, `created`)';
         $query .= ' select a.`id`, ' . $db->Quote($blog->id) . ', ' . $db->Quote($date->toMySQL());
         $query .= ' from `#__easyblog_tag` as a inner join `#__bloggies_tags` as b';
         $query .= ' on a.`title` = b.`name`';
         $query .= ' inner join `#__bloggies_relations` as c on b.`id` = c.`tag`';
         $query .= ' where c.`entry` = ' . $db->Quote($row->id);
         $db->setQuery($query);
         $db->query();
         // migrate Jcomments from lyftenbloggie into EasyBlog
         // $this->_migrateJCommentIntoEasyBlog($row->id, $blog->id, 'com_lyftenbloggie');
         // step 3
         if ($migrateComment) {
             //required frontend model file.
             require_once JPATH_ROOT . DIRECTORY_SEPARATOR . 'components' . DIRECTORY_SEPARATOR . 'com_easyblog' . DIRECTORY_SEPARATOR . 'models' . DIRECTORY_SEPARATOR . 'comment.php';
             $model = new EasyBlogModelComment();
             $queryComment = 'SELECT * FROM `#__bloggies_comments` WHERE `entry_id` = ' . $db->Quote($row->id);
             $queryComment .= ' ORDER BY `id`';
             $db->setQuery($queryComment);
             $resultComment = $db->loadObjectList();
             if (count($resultComment) > 0) {
                 $lft = 1;
                 $rgt = 2;
                 foreach ($resultComment as $itemComment) {
                     $now = EB::date();
                     $commt = EB::table('Comment');
                     $commt->post_id = $blog->id;
                     $commt->comment = $itemComment->content;
                     $commt->title = '';
                     $commt->name = $itemComment->author;
                     $commt->email = $itemComment->author_email;
                     $commt->url = $itemComment->author_url;
                     $commt->created_by = $itemComment->user_id;
                     $commt->created = $itemComment->date;
                     $commt->published = $itemComment->state == '1' ? '1' : '0';
                     $commt->lft = $lft;
                     $commt->rgt = $rgt;
                     $commt->store();
                     //update state
                     $migrateStat->comments++;
                     // next set of siblings
                     $lft = $rgt + 1;
                     $rgt = $lft + 1;
                 }
                 //end foreach
             }
             //end if count(comment)
         }
         //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 = $row->id;
         $migrator->post_id = $blog->id;
         $migrator->session_id = $jSession->getToken();
         $migrator->component = 'com_lyftenbloggie';
         $migrator->store();
         $ejax->append('progress-status3', JText::_('COM_EASYBLOG_MIGRATOR_MIGRATED_LYFTEN') . ':' . $row->id . JText::_('COM_EASYBLOG_MIGRATOR_EASYBLOG') . ': ' . $blog->id . '<br />');
         $ejax->script("ejax.load('migrators','_processLyftenBloggie', '{$migrateComment}');");
     }
     //end if else isnull
     $ejax->send();
 }
Beispiel #5
0
 function _processSmartBlog($migrateComment, $migrateImage, $imagePath)
 {
     $db = EasyBlogHelper::db();
     $jSession = JFactory::getSession();
     $ejax = new EJax();
     //check if com_blog installed.
     if (!JFile::exists(JPATH_ROOT . DIRECTORY_SEPARATOR . 'components' . DIRECTORY_SEPARATOR . 'com_blog' . DIRECTORY_SEPARATOR . 'blog.php')) {
         $ejax->append('progress-status2', JText::_('COM_EASYBLOG_MIGRATOR_SMARTBLOG_ERROR'));
         $ejax->script("\$( '#migrator-submit2' ).html('" . JText::_('COM_EASYBLOG_MIGRATOR_ABORTED') . "');");
         $ejax->script("\$( '#migrator-submit2' ).attr('disabled' , '');");
         $ejax->script("\$( '#icon-wait2' ).css( 'display' , 'none' );");
         $ejax->send();
         exit;
     }
     $migrateStat = $jSession->get('EBLOG_MIGRATOR_JOOMLA_STAT', '', 'EASYBLOG');
     if (empty($migrateStat)) {
         $migrateStat = new stdClass();
         $migrateStat->blog = 0;
         $migrateStat->category = 0;
         $migrateStat->comments = 0;
         $migrateStat->images = 0;
         $migrateStat->user = array();
     }
     $query = 'SELECT * FROM `#__blog_postings` AS a';
     $query .= ' WHERE NOT EXISTS (';
     $query .= ' SELECT content_id FROM `#__easyblog_migrate_content` AS b WHERE b.`content_id` = a.`id` and `component` = ' . $db->Quote('com_blog');
     $query .= ' )';
     $query .= ' ORDER BY a.`id` LIMIT 1';
     $db->setQuery($query);
     $row = $db->loadObject();
     if (is_null($row)) {
         //at here, we check whether there are any records processed. if yes,
         //show the statistic.
         $ejax->append('progress-status2', JText::_('COM_EASYBLOG_MIGRATOR_FINISHED'));
         $ejax->script("divSrolltoBottomSmartBlog();");
         //update statistic
         $stat = '========================================== <br />';
         $stat .= JText::_('COM_EASYBLOG_MIGRATOR_TOTAL_BLOGS') . ': ' . $migrateStat->blog . '<br />';
         $stat .= 'Total comments migrated : ' . $migrateStat->comments . '<br />';
         $stat .= 'Total images migrated : ' . $migrateStat->images . '<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-status2', $stat);
         $ejax->script("\$( '#migrator-submit2' ).html('" . JText::_('COM_EASYBLOG_MIGRATOR_MIGRATION_COMPLETED') . "');");
         $ejax->script("\$( '#migrator-submit2' ).attr('disabled' , '');");
         $ejax->script("\$( '#icon-wait2' ).css( 'display' , 'none' );");
     } else {
         // here we should process the migration
         // step 1 : create user if not exists in eblog_users - create user through profile jtable load method.
         // step 2 : migrate image files.
         //      step 2.1: create folder if not exist.
         // step 3: migrate comments if needed.
         $date = EB::date();
         $blogObj = new stdClass();
         //default
         $blogObj->category_id = 1;
         //assume 1 is the uncategorized id.
         //load user profile
         $profile = EB::user($row->user_id);
         $blog = EB::table('Blog');
         //assigning blog data
         $blogObj->created_by = $profile->id;
         $blogObj->created = !empty($row->post_date) ? $row->post_date : $date->toMySQL();
         $blogObj->modified = !empty($row->post_update) ? $row->post_update : $date->toMySQL();
         $blogObj->title = $row->post_title;
         $blogObj->permalink = EasyBlogHelper::getPermalink($row->post_title);
         $blogObj->intro = '';
         $blogObj->content = $row->post_desc;
         $blogObj->published = $row->published;
         $blogObj->publish_up = !empty($row->post_date) ? $row->post_date : $date->toMySQL();
         $blogObj->publish_down = '0000-00-00 00:00:00';
         $blogObj->hits = $row->post_hits;
         $blogObj->frontpage = 1;
         $blog->bind($blogObj);
         //step 2
         $imageMigrated = false;
         if ($migrateImage) {
             $newImagePath = JPATH_ROOT . DIRECTORY_SEPARATOR . 'images';
             if (!empty($imagePath)) {
                 $tmpimagePath = str_ireplace('/', DIRECTORY_SEPARATOR, $imagePath);
                 $newImagePath .= DIRECTORY_SEPARATOR . $tmpimagePath;
                 $newImagePath = JFolder::makeSafe($newImagePath);
             }
             if (!JFolder::exists($newImagePath)) {
                 JFolder::create($newImagePath);
             }
             $src = JPATH_ROOT . DIRECTORY_SEPARATOR . 'components' . DIRECTORY_SEPARATOR . 'com_blog' . DIRECTORY_SEPARATOR . 'Images' . DIRECTORY_SEPARATOR . 'blogimages' . DIRECTORY_SEPARATOR . 'th' . $row->post_image;
             $dest = $newImagePath . DIRECTORY_SEPARATOR . $row->post_image;
             if (JFile::exists($src)) {
                 $imageMigrated = JFile::copy($src, $dest);
             }
         }
         if ($imageMigrated) {
             $destSafeURL = str_ireplace(DIRECTORY_SEPARATOR, '/', $imagePath);
             $destSafeURL = 'images/' . $destSafeURL . '/' . $row->post_image;
             $imageContent = '<p><img style="padding:0px 10px 10px 0px;" align="left" src="' . $destSafeURL . '" border="0" /> </p>';
             $blog->content = $imageContent . $blog->content;
             $migrateStat->images++;
         }
         $blog->store();
         // step 3
         if ($migrateComment) {
             //required frontend model file.
             require_once JPATH_ROOT . DIRECTORY_SEPARATOR . 'components' . DIRECTORY_SEPARATOR . 'com_easyblog' . DIRECTORY_SEPARATOR . 'models' . DIRECTORY_SEPARATOR . 'comment.php';
             $model = new EasyBlogModelComment();
             $queryComment = 'SELECT * FROM `#__blog_comment` WHERE `post_id` = ' . $db->Quote($row->id);
             $queryComment .= ' ORDER BY `id`';
             $db->setQuery($queryComment);
             $resultComment = $db->loadObjectList();
             if (count($resultComment) > 0) {
                 foreach ($resultComment as $itemComment) {
                     //load user profile
                     $commentor = EB::user($itemComment->user_id);
                     $user = JFactory::getUser($itemComment->user_id);
                     $now = EB::date();
                     $commt = EB::table('Comment');
                     $commt->post_id = $blog->id;
                     $commt->comment = $itemComment->comment_desc;
                     $commt->title = $itemComment->comment_title;
                     $commt->name = $user->name;
                     $commt->email = $user->email;
                     $commt->url = $commentor->url;
                     $commt->created_by = $itemComment->user_id;
                     $commt->created = $itemComment->comment_date;
                     $commt->published = $itemComment->published;
                     //adding new comment
                     $latestCmmt = $model->getLatestComment($blog->id, '0');
                     $lft = 1;
                     $rgt = 2;
                     if (!empty($latestCmmt)) {
                         $lft = $latestCmmt->rgt + 1;
                         $rgt = $latestCmmt->rgt + 2;
                         $model->updateCommentSibling($blog->id, $latestCmmt->rgt);
                     }
                     $commt->lft = $lft;
                     $commt->rgt = $rgt;
                     $commt->store();
                     //update state
                     $migrateStat->comments++;
                 }
                 //end foreach
             }
             //end if count(comment)
         }
         //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 = $row->id;
         $migrator->post_id = $blog->id;
         $migrator->session_id = $jSession->getToken();
         $migrator->component = 'com_blog';
         $migrator->store();
         $ejax->append('progress-status2', JText::_('COM_EASYBLOG_MIGRATOR_MIGRATED_SMARTBLOG') . ': ' . $row->id . JText::_('COM_EASYBLOG_MIGRATOR_EASYBLOG') . ' :' . $blog->id . '<br />');
         $ejax->script("ejax.load('migrators','_processSmartBlog','{$migrateComment}', '{$migrateImage}', '{$imagePath}');");
     }
     $ejax->send();
 }
Beispiel #6
0
 function import($feedObj, $maxItems = 0)
 {
     jimport('simplepie.simplepie');
     $config = EasyBlogHelper::getConfig();
     $itemMigrated = 0;
     $isDomSupported = false;
     $defaultAllowedHTML = '<img>,<a>,<br>,<table>,<tbody>,<th>,<tr>,<td>,<div>,<span>,<p>,<h1>,<h2>,<h3>,<h4>,<h5>,<h6>';
     if (class_exists('DomDocument')) {
         $isDomSupported = true;
         require_once EBLOG_CLASSES . DIRECTORY_SEPARATOR . 'readability' . DIRECTORY_SEPARATOR . 'Readability.php';
     }
     $params = EasyBlogHelper::getRegistry($feedObj->params);
     $maxItems = $maxItems ? $maxItems : $params->get('feedamount', 0);
     $feedURL = $feedObj->url;
     require_once EBLOG_HELPERS . DIRECTORY_SEPARATOR . 'connectors.php';
     $connector = new EasyBlogConnectorsHelper();
     $connector->addUrl($feedURL);
     $connector->execute();
     $content = $connector->getResult($feedURL);
     // to ensure the leading no text before the <?xml> tag
     //$pattern	= '/(.*?)(?=<\?xml)/ims';
     $pattern = '/(.*?)<\\?xml version/is';
     $replacement = '<?xml version';
     $content = preg_replace($pattern, $replacement, $content, 1);
     if (strpos($content, '<?xml version') === false) {
         // look like the content missing the xml header. lets manually add in.
         $content = '<?xml version="1.0" encoding="utf-8"?>' . $content;
     }
     $parser = new SimplePie();
     $parser->strip_htmltags(false);
     $parser->set_raw_data($content);
     $parser->init();
     $items = '';
     $items = $parser->get_items();
     if (count($items) > 0) {
         //lets process the data insert
         $myCnt = 0;
         foreach ($items as $item) {
             @ini_set('max_execution_time', 180);
             if (!empty($maxItems) && $myCnt == $maxItems) {
                 break;
             }
             $timezoneSec = $item->get_date('Z');
             $itemdate = $item->get_date('U');
             $itemdate = $itemdate - $timezoneSec;
             $mydate = date('Y-m-d H:i:s', $itemdate);
             $feedUid = $item->get_id();
             $feedPath = $item->get_link();
             $feedHistory = EasyBlogHelper::getTable('FeedHistory');
             $newHistoryId = '';
             if ($feedHistory->isExists($feedObj->id, $feedUid)) {
                 continue;
             } else {
                 //log the feed item so that in future it will not process again.
                 $date = EasyBlogHelper::getDate();
                 $newHistory = EasyBlogHelper::getTable('FeedHistory');
                 $newHistory->feed_id = $feedObj->id;
                 $newHistory->uid = $feedUid;
                 $newHistory->created = $date->toMySQL();
                 $newHistory->store();
                 $newHistoryId = $newHistory->id;
             }
             $blogObj = new stdClass();
             // set the default setting from the feed configuration via backend.
             $blogObj->category_id = $feedObj->item_category;
             $blogObj->published = $feedObj->item_published;
             $blogObj->frontpage = $feedObj->item_frontpage;
             $blogObj->created_by = $feedObj->item_creator;
             $blogObj->allowcomment = $config->get('main_comment', 1);
             $blogObj->subscription = $config->get('main_subscription', 1);
             $blogObj->issitewide = '1';
             $text = $item->get_content();
             // @rule: Append copyright text
             $blogObj->copyrights = $params->get('copyrights', '');
             if ($feedObj->item_get_fulltext && $isDomSupported) {
                 $feedItemUrl = urldecode($item->get_link());
                 $fiConnector = new EasyBlogConnectorsHelper();
                 $fiConnector->addUrl($feedItemUrl);
                 $fiConnector->execute();
                 $fiContent = $fiConnector->getResult($feedItemUrl);
                 // to ensure the leading no text before the <?xml> tag
                 $pattern = '/(.*?)<html/is';
                 $replacement = '<html';
                 $fiContent = preg_replace($pattern, $replacement, $fiContent, 1);
                 if (!empty($fiContent)) {
                     $fiContent = EasyBlogHelper::getHelper('string')->forceUTF8($fiContent);
                     $readability = new Readability($fiContent);
                     $readability->debug = false;
                     $readability->convertLinksToFootnotes = false;
                     $result = $readability->init();
                     if ($result) {
                         $content = $readability->getContent()->innerHTML;
                         //$content	= EasyBlogHelper::getHelper( 'string' )->fixUTF8( $content );
                         $content = EasyBlogFeedsHelper::tidyContent($content);
                         if (stristr(html_entity_decode($content), '<!DOCTYPE html') === false) {
                             $text = $content;
                             $text = $this->_processRelLinktoAbs($text, $feedPath);
                         }
                     }
                 }
             }
             // strip un-allowed html tag.
             $text = strip_tags($text, $params->get('allowed', $defaultAllowedHTML));
             // Append original source link into article if necessary
             if ($params->get('sourceLinks')) {
                 JFactory::getLanguage()->load('com_easyblog', JPATH_ROOT);
                 $text .= '<div><a href="' . $item->get_link() . '" target="_blank">' . JText::_('COM_EASYBLOG_FEEDS_ORIGINAL_LINK') . '</a></div>';
             }
             if ($feedObj->author) {
                 $feedAuthor = $item->get_author();
                 if (!empty($feedAuthor)) {
                     $authorName = $feedAuthor->get_name();
                     $authorEmail = $feedAuthor->get_email();
                     if (!empty($authorName)) {
                         // Store it as copyright column instead
                         $text .= '<div>' . JText::sprintf('COM_EASYBLOG_FEEDS_ORIGINAL_AUTHOR', $authorName) . '</div>';
                     } else {
                         if (!empty($authorEmail)) {
                             $authorArr = explode(' ', $authorEmail);
                             if (isset($authorArr[1])) {
                                 $authorName = $authorArr[1];
                                 $authorName = str_replace(array('(', ')'), '', $authorName);
                                 $text .= '<div>' . JText::sprintf('COM_EASYBLOG_FEEDS_ORIGINAL_AUTHOR', $authorName) . '</div>';
                             }
                         }
                     }
                 }
             }
             if ($feedObj->item_content == 'intro') {
                 $blogObj->intro = $text;
             } else {
                 $blogObj->content = $text;
             }
             $creationDate = $mydate;
             $blogObj->created = $mydate;
             $blogObj->modified = $mydate;
             $blogObj->title = $item->get_title();
             if (empty($blogObj->title)) {
                 $blogObj->title = $this->_getTitleFromLink($item->get_link());
             }
             $blogObj->title = EasyBlogStringHelper::unhtmlentities($blogObj->title);
             $blogObj->permalink = EasyBlogHelper::getPermalink($blogObj->title);
             $blogObj->publish_up = $mydate;
             $blogObj->isnew = !$feedObj->item_published ? true : false;
             $blog = EasyBlogHelper::getTable('blog');
             $blog->bind($blogObj);
             if ($feedObj->item_published) {
                 $blog->notify();
             }
             if ($blog->store()) {
                 $myCnt++;
                 //update the history with blog id
                 if (!empty($newHistoryId)) {
                     $tmpHistory = EasyBlogHelper::getTable('FeedHistory');
                     $tmpHistory->load($newHistoryId);
                     $tmpHistory->post_id = $blog->id;
                     $tmpHistory->store();
                 }
                 $itemMigrated++;
                 if ($feedObj->item_published) {
                     //insert activity here.
                     EasyBlogHelper::addJomSocialActivityBlog($blog, true, true);
                     // Determines if admin wants to auto post this item to the social sites.
                     if ($params->get('autopost')) {
                         $allowed = array(EBLOG_OAUTH_LINKEDIN, EBLOG_OAUTH_FACEBOOK, EBLOG_OAUTH_TWITTER);
                         // @rule: Process centralized options first
                         // See if there are any global postings enabled.
                         $blog->autopost($allowed, $allowed);
                     }
                 }
             }
             //end if
         }
     }
     return $itemMigrated;
 }
Beispiel #7
0
 public static function getBlogSefPermalink($id, $external = false)
 {
     $config = EasyBlogHelper::getConfig();
     static $permalinks = null;
     if (!isset($permalinks[$id])) {
         JTable::addIncludePath(EBLOG_TABLES);
         $db = EasyBlogHelper::db();
         $query = 'SELECT a.* FROM ' . EasyBlogHelper::getHelper('SQL')->nameQuote('#__easyblog_post') . ' as a ' . 'WHERE a.`id` ' . '=' . $db->Quote($id);
         $db->setQuery($query);
         $data = $db->loadObject();
         $config = EasyBlogHelper::getConfig();
         if (empty($data)) {
             // blog post not exists
             $permalinks[$id] = JText::_('COM_EASYBLOG_INVALID_PERMALINK_POST');
             return $permalinks[$id];
         }
         // Empty permalinks needs to be regenerated.
         if (empty($data->permalink)) {
             $data->permalink = EasyBlogHelper::getPermalink($data->title);
             $query = 'UPDATE #__easyblog_post SET permalink=' . $db->Quote($data->permalink) . ' ' . 'WHERE ' . EasyBlogHelper::getHelper('SQL')->nameQuote('id') . '=' . $db->Quote($id);
             $db->setQuery($query);
             $db->Query();
         }
         if ($config->get('main_sef_unicode')) {
             $data->permalink = $data->id . '-' . urlencode($data->permalink);
         }
         switch ($config->get('main_sef')) {
             // Date based SEF mode
             case 'date':
                 $date = EasyBlogHelper::getDate($data->created);
                 $data->permalink = $date->toFormat('%Y') . '/' . $date->toFormat('%m') . '/' . $date->toFormat('%d') . '/' . $data->permalink;
                 break;
             case 'datecategory':
                 $date = EasyBlogHelper::getDate($data->created);
                 $catPermalink = EasyBlogRouter::getCategoryPermalink($data->category_id);
                 $data->permalink = $catPermalink . '/' . $date->toFormat('%Y') . '/' . $date->toFormat('%m') . '/' . $date->toFormat('%d') . '/' . $data->permalink;
                 break;
             case 'category':
                 $catPermalink = EasyBlogRouter::getCategoryPermalink($data->category_id);
                 $data->permalink = $catPermalink . '/' . $data->permalink;
                 break;
             case 'custom':
                 $data->permalink = self::getCustomPermalink($data);
                 break;
                 // Default SEF mode leave it unchanged
             // Default SEF mode leave it unchanged
             default:
                 break;
         }
         if ($external) {
             $uri = JURI::getInstance();
             return $uri->toString(array('scheme', 'host', 'port')) . '/' . $data->permalink;
         }
         $permalinks[$id] = $data->permalink;
     }
     return $permalinks[$id];
 }
Beispiel #8
0
 /**
  * Generate proper permalink for a blog entry
  **/
 function getPermalink($value)
 {
     $ajax = new Ejax();
     $permalink = EasyBlogHelper::getPermalink($value);
     $ajax->assign('permalink-url', $permalink);
     $ajax->script('$( "#edit-permalink" ).show();');
     $ajax->script('$( "#permalink-value" ).show();');
     $ajax->value('permalink-data', $permalink);
     $ajax->send();
 }