Esempio n. 1
0
 /**
  * Checks if the file can be uploaded
  *
  * @param array File information
  * @param string An error message to be returned
  * @return boolean
  */
 public static function canUpload($file, &$err)
 {
     //$params = &JComponentHelper::getParams( 'com_media' );
     $params = EasyBlogHelper::getConfig();
     if (empty($file['name'])) {
         $err = 'COM_EASYBLOG_WARNEMPTYFILE';
         return false;
     }
     jimport('joomla.filesystem.file');
     if ($file['name'] !== JFile::makesafe($file['name'])) {
         $err = 'COM_EASYBLOG_WARNFILENAME';
         return false;
     }
     $format = strtolower(JFile::getExt($file['name']));
     if (!EasyImageHelper::isImage($file['name'])) {
         $err = 'COM_EASYBLOG_WARNINVALIDIMG';
         return false;
     }
     $maxWidth = 160;
     $maxHeight = 160;
     // maxsize should get from eblog config
     //$maxSize	= 2000000; //2MB
     //$maxSize	= 200000; //200KB
     // 1 megabyte == 1048576 byte
     $byte = 1048576;
     $uploadMaxsize = (double) $params->get('main_upload_image_size', 0);
     $maxSize = $uploadMaxsize * $byte;
     if ($maxSize > 0 && (double) $file['size'] > $maxSize) {
         $err = 'COM_EASYBLOG_WARNFILETOOLARGE';
         return false;
     }
     $user = JFactory::getUser();
     $imginfo = null;
     if (($imginfo = getimagesize($file['tmp_name'])) === FALSE) {
         $err = 'COM_EASYBLOG_WARNINVALIDIMG';
         return false;
     }
     return true;
 }
Esempio n. 2
0
 function _processWPXMLAttachment($wpPostId, $content, $attachments, $authorId)
 {
     require_once EBLOG_HELPERS . DIRECTORY_SEPARATOR . 'connectors.php';
     foreach ($attachments as $attachment) {
         $link = $attachment['link'];
         $attachementURL = $attachment['attachment_url'];
         if (EasyImageHelper::isImage($attachementURL)) {
             $filname = EasyImageHelper::getFileName($attachementURL);
             $extension = EasyImageHelper::getFileExtension($attachementURL);
             $folder = JPATH_ROOT . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'blogs' . DIRECTORY_SEPARATOR . $wpPostId;
             if (!JFolder::exists($folder)) {
                 JFolder::create($folder);
             }
             // new image location
             $newFile = $folder . DIRECTORY_SEPARATOR . $filname;
             $connector = EB::connector();
             $connector->addUrl($attachementURL);
             $connector->execute();
             $imageraw = $connector->getResult($attachementURL);
             if ($imageraw) {
                 if (JFile::write($newFile, $imageraw)) {
                     //replace the string in the content.
                     $absImagePath = rtrim(JURI::root(), '/') . '/images/blogs/' . $wpPostId . '/' . $filname;
                     $content = str_ireplace('href="' . $link . '"', 'href="' . $absImagePath . '"', $content);
                     $pattern = '/src=[\\"\']?([^\\"\']?.*(png|jpg|jpeg|gif))[\\"\']?/i';
                     $content = preg_replace($pattern, 'src="' . $absImagePath . '"', $content);
                 }
             }
             // 				if( file_put_contents( $newFile, file_get_contents($attachementURL) ) !== false )
             // 				{
             // 				    //replace the string in the content.
             // 				    $absImagePath   = rtrim( JURI::root(), '/' ) . '/images/blogs/' . $wpPostId . '/' . $filname;
             // 				    $content		= JString::str_ireplace( 'href="' . $link . '"'  , 'href="' . $absImagePath . '"' , $content );
             //
             // 				    $pattern 		= '/src=[\"\']?([^\"\']?.*(png|jpg|jpeg|gif))[\"\']?/i';
             // 				    $content		= preg_replace( $pattern  , 'src="'.$absImagePath.'"' , $content );
             // 				}
         }
     }
     return $content;
 }