Exemple #1
0
 public function upload()
 {
     $app = JFactory::getApplication();
     $my = JFactory::getUser();
     $cfg = EasyBlogHelper::getConfig();
     $acl = EasyBlogACLHelper::getRuleSet();
     // @rule: Only allowed users are allowed to upload images.
     if ($my->id == 0 || empty($acl->rules->upload_image)) {
         $sessionid = JRequest::getVar('sessionid');
         if ($sessionid) {
             $session = JTable::getInstance('Session');
             $session->load($sessionid);
             if (!$session->userid) {
                 $this->output($this->getMessageObj(EBLOG_MEDIA_SECURITY_ERROR, JText::_('COM_EASYBLOG_NOT_ALLOWED')));
             }
             $my = JFactory::getUser($session->userid);
         } else {
             $this->output($this->getMessageObj(EBLOG_MEDIA_SECURITY_ERROR, JText::_('COM_EASYBLOG_NOT_ALLOWED')));
         }
     }
     // Let's get the path for the current request.
     $file = JRequest::getVar('file', '', 'FILES', 'array');
     $place = JRequest::getVar('place');
     // The user might be from a subfolder?
     $source = urldecode(JRequest::getVar('path', '/'));
     // @task: Let's find the exact path first as there could be 3 possibilities here.
     // 1. Shared folder
     // 2. User folder
     $absolutePath = EasyBlogMediaManager::getAbsolutePath($source, $place);
     $absoluteURI = EasyBlogMediaManager::getAbsoluteURI($source, $place);
     // @TODO: Test if user is allowed to upload this image
     $message = $this->getMessageObj();
     $allowed = EasyImageHelper::canUploadFile($file, $message);
     if ($allowed !== true) {
         return $this->output($message);
     }
     $media = new EasyBlogMediaManager();
     $result = $media->upload($absolutePath, $absoluteURI, $file, $source, $place);
     // This should be an error if the $result is not an MMIM object.
     if (!is_object($result)) {
         $message = $this->getMessageObj('404', $result);
     } else {
         $message = $this->getMessageObj(EBLOG_MEDIA_UPLOAD_SUCCESS, JText::_('COM_EASYBLOG_IMAGE_MANAGER_UPLOAD_SUCCESS'), $result);
     }
     return $this->output($message);
 }
Exemple #2
0
 public function post()
 {
     //old  code
     /*$controller = new EasyBlogControllerMedia;
     		$op = $controller->upload();
     		*/
     $input = JFactory::getApplication()->input;
     $log_user = $this->plugin->get('user')->id;
     $res = new stdClass();
     // Let's get the path for the current request.
     $file = JRequest::getVar('file', '', 'FILES', 'array');
     if ($file['name']) {
         $place = 'user:'******'user')->id;
         // The user might be from a subfolder?
         $source = urldecode('/' . $file['name']);
         // @task: Let's find the exact path first as there could be 3 possibilities here.
         // 1. Shared folder
         // 2. User folder
         //$absolutePath 		= EasyBlogMediaManager::getAbsolutePath( $source , $place );
         //$absoluteURI		= EasyBlogMediaManager::getAbsoluteURI( $source , $place );
         $absolutePath = EasyBlogMediaManager::getPath($source);
         $absoluteURI = EasyBlogMediaManager::getUrl($source);
         $allowed = EasyImageHelper::canUploadFile($file, $message);
         if ($allowed !== true) {
             $res->status = 0;
             $res->message = 'Upload is not allowed';
             return $res;
         }
         $media = new EasyBlogMediaManager();
         $upload_result = $media->upload($absolutePath, $absoluteURI, $file, $source, $place);
         //adjustment
         $upload_result->key = $place . $source;
         $upload_result->group = 'files';
         $upload_result->parentKey = $place . '|/';
         $upload_result->friendlyPath = 'My Media/' . $source;
         unset($upload_result->variations);
         $this->plugin->setResponse($upload_result);
         return $upload_result;
     } else {
         $this->plugin->setResponse($this->getErrorResponse(404, __FUNCTION__ . ' Upload unsuccessfull.'));
     }
 }
Exemple #3
0
 function newMediaObject($blogid, $username, $password, $file)
 {
     jimport('joomla.utilities.error');
     jimport('joomla.filesystem.file');
     jimport('joomla.filesystem.folder');
     global $xmlrpcerruser, $xmlrpcI4, $xmlrpcInt, $xmlrpcBoolean, $xmlrpcDouble, $xmlrpcString, $xmlrpcDateTime, $xmlrpcBase64, $xmlrpcArray, $xmlrpcStruct, $xmlrpcValue;
     EasyBlogXMLRPCHelper::loginUser($username, $password);
     $user = JUser::getInstance($username);
     $acl = EasyBlogACLHelper::getRuleSet($user->id);
     if (empty($acl->rules->upload_image)) {
         return new xmlrpcresp(0, $xmlrpcerruser + 2, JText::_('YOU DO NOT HAVE IMAGE UPLOAD RIGHT'));
     }
     $config = EasyBlogHelper::getConfig();
     $main_image_path = $config->get('main_image_path');
     $main_image_path = rtrim($main_image_path, '/');
     $rel_upload_path = $main_image_path . '/' . $user->id;
     $userUploadPath = JPATH_ROOT . DIRECTORY_SEPARATOR . str_ireplace('/', DIRECTORY_SEPARATOR, $main_image_path . DIRECTORY_SEPARATOR . $user->id);
     $folder = JPath::clean($userUploadPath);
     $dir = $userUploadPath . DIRECTORY_SEPARATOR;
     $tmp_dir = JPATH_ROOT . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR;
     if (!JFolder::exists($dir)) {
         JFolder::create($dir);
     }
     if (strpos($file['name'], '/') !== FALSE) {
         $file['name'] = substr($file['name'], strrpos($file['name'], '/') + 1);
     } elseif (strpos($file['name'], '\\' !== FALSE)) {
         $file['name'] = substr($file['name'], strrpos($file['name'], '\\') + 1);
     }
     // Set FTP credentials, if given
     jimport('joomla.client.helper');
     JClientHelper::setCredentialsFromRequest('ftp');
     $ftp = JClientHelper::getCredentials('ftp');
     $file['name'] = JFile::makesafe($file['name']);
     //$file['name']	= substr($file['name'], 0, -4) . rand() . '.' . JFile::getExt($file['name']);
     $file['name'] = substr($file['name'], 0, -4) . '.' . JFile::getExt($file['name']);
     // write to temp folder
     $file['tmp_name'] = $tmp_dir . $file['name'];
     @JFile::write($file['tmp_name'], $file['bits']);
     $file['size'] = 0;
     $error = '';
     $allowed = EasyImageHelper::canUploadFile($file);
     if ($allowed !== true) {
         @JFile::delete($file['tmp_name']);
         return new xmlrpcresp(0, $xmlrpcerruser + 1, 'The file is not valid');
     }
     // @JFile::write( $dir . $file['name'], $file['bits']);
     // @task: Ensure that images goes through the same resizing format when uploading via media manager.
     require_once EBLOG_CLASSES . DIRECTORY_SEPARATOR . 'mediamanager.php';
     $media = new EasyBlogMediaManager();
     $result = $media->upload($dir, $userUploadPath, $file, '/', 'user');
     @JFile::delete($file['tmp_name']);
     $file['name'] = EasyBlogXMLRPCHelper::cleanImageName($file['name']);
     $fileUrl = rtrim(JURI::root(), '/') . '/' . $rel_upload_path . '/' . $file['name'];
     return new xmlrpcresp(new xmlrpcval(array('url' => new xmlrpcval($fileUrl)), 'struct'));
 }
Exemple #4
0
 /**
  * Handles photo uploads via the microblogging page.
  *
  * @access	public
  * @param	null
  **/
 public function uploadPhoto()
 {
     $my = JFactory::getUser();
     $config = EasyBlogHelper::getConfig();
     if (!$my->id) {
         return $this->outputJSON(array('type' => 'error', 'message' => JText::_('You need to be logged in first')));
     }
     $file = JRequest::getVar('photo-source', '', 'files', 'array');
     if (!isset($file['tmp_name'])) {
         return $this->outputJSON(array('type' => 'error', 'message' => JText::_('There is an error when uploading the image to the server. Perhaps the temporary folder <strong>upload_tmp_path</strong> was not configured correctly.')));
     }
     require_once EBLOG_HELPERS . DIRECTORY_SEPARATOR . 'image.php';
     // @rule: Photos should be stored in the user's home folder by default.
     $imagePath = str_ireplace(array("/", "\\"), DIRECTORY_SEPARATOR, rtrim($config->get('main_image_path'), '/'));
     $userUploadPath = JPATH_ROOT . DIRECTORY_SEPARATOR . str_replace('/', DIRECTORY_SEPARATOR, $imagePath . DIRECTORY_SEPARATOR . $my->id);
     $storageFolder = JPath::clean($userUploadPath);
     // @rule: Get the image URI
     $imageURI = rtrim(str_ireplace('\\', '/', $config->get('main_image_path')), '/') . '/' . $my->id;
     $imageURI = rtrim(JURI::root(), '/') . '/' . $imageURI;
     // Set FTP credentials, if given
     jimport('joomla.client.helper');
     JClientHelper::setCredentialsFromRequest('ftp');
     // Make the filename safe
     jimport('joomla.filesystem.file');
     $file['name'] = JFile::makeSafe($file['name']);
     // After making the filename safe, and the first character begins with . , we need to rename this file. Perhaps it's a unicode character
     $file['name'] = trim($file['name']);
     $filename = strtolower($file['name']);
     if (strpos($filename, '.') === false) {
         $filename = EB::date()->toFormat("%Y%m%d-%H%M%S") . '.' . $filename;
     } else {
         if (strpos($filename, '.') == 0) {
             $filename = EB::date()->toFormat("%Y%m%d-%H%M%S") . $filename;
         }
     }
     // remove the spacing in the filename.
     $filename = str_ireplace(' ', '-', $filename);
     $storagePath = JPath::clean($storageFolder . DIRECTORY_SEPARATOR . $filename);
     // 		// @task: try to rename the file if another image with the same name exists
     // 		if( JFile::exists( $storagePath ) )
     // 		{
     // 			$i	= 1;
     // 			while( JFile::exists( $storagePath ) )
     // 			{
     // 				$tmpName	= $i . '_' . EB::date()->toFormat( "%Y%m%d-%H%M%S" ) . '_' . $filename;
     // 				$storagePath	= JPath::clean( $storageFolder . DIRECTORY_SEPARATOR . $tmpName );
     // 				$i++;
     // 			}
     // 			$filename	= $tmpName;
     // 		}
     $allowed = EasyImageHelper::canUploadFile($file);
     if ($allowed !== true) {
         return $this->outputJSON(array('type' => 'error', 'message' => $allowed));
     }
     // @rule: Pass to EasyBlogImageHelper to upload the image
     // $result		= EasyImageHelper::upload( $storageFolder , $filename , $file , $imageURI , $storagePath );
     // 		// @task: Ensure that images goes through the same resizing format when uploading via media manager.
     $result = new stdClass();
     $result->message = JText::_('COM_EASYBLOG_IMAGE_MANAGER_UPLOAD_ERROR');
     $result->item = '';
     require_once EBLOG_CLASSES . DIRECTORY_SEPARATOR . 'mediamanager.php';
     $media = new EasyBlogMediaManager();
     $uploaded = $media->upload($file, 'user:'******'COM_EASYBLOG_IMAGE_MANAGER_UPLOAD_SUCCESS');
         $result->item = $uploaded;
     } else {
         // failed.
         $result->item->url = '';
     }
     return $this->outputJSON(array('type' => 'success', 'message' => $result->message, 'uri' => $result->item->url));
 }
Exemple #5
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);
 }
Exemple #6
0
 function _migrateBloggerImage($image, $userid, $content)
 {
     jimport('joomla.utilities.error');
     jimport('joomla.filesystem.file');
     jimport('joomla.filesystem.folder');
     $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 . str_ireplace('/', DIRECTORY_SEPARATOR, $main_image_path . DIRECTORY_SEPARATOR . $userid);
     $folder = JPath::clean($userUploadPath);
     $dir = $userUploadPath . DIRECTORY_SEPARATOR;
     $tmp_dir = JPATH_ROOT . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR;
     if (!JFolder::exists($dir)) {
         JFolder::create($dir);
     }
     //now let get the image from remove url.
     $segments = explode('/', $image);
     $fileName = $segments[count($segments) - 1];
     $fileName = JFile::makesafe($fileName);
     $tmpFileName = $tmp_dir . $fileName;
     $file['name'] = $fileName;
     $file['tmp_name'] = $tmpFileName;
     // write to JOOMLA tmp folder
     file_put_contents($tmpFileName, file_get_contents($image));
     require_once EBLOG_CLASSES . DIRECTORY_SEPARATOR . 'mediamanager.php';
     $media = new EasyBlogMediaManager();
     $result = $media->upload($file, 'user:'******'tmp_name']);
     if (isset($result->type)) {
         $relativeImagePath = $rel_upload_path . '/' . $file['name'];
         // lets replace the image from the content to this uploaded one.
         $content = str_replace($image, $relativeImagePath, $content);
     }
     return $content;
 }