Esempio n. 1
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;
 }
Esempio n. 2
0
 public function getUniqueName($storagePath, $fileName)
 {
     jimport('joomla.filesystem.file');
     $i = 1;
     $itemPath = JPath::clean($storagePath . DIRECTORY_SEPARATOR . $fileName);
     // @task: Now, we need to ensure that this file doesn't exist on the system.
     if (JFile::exists($itemPath)) {
         while (JFile::exists($itemPath)) {
             // get file extension here:
             $ext = EasyImageHelper::getFileExtension($fileName);
             $ext = '.' . $ext;
             $tmpFileName = str_replace($ext, '', $fileName);
             $tmp = $tmpFileName . '_' . EasyBlogHelper::getDate()->toFormat("%Y%m%d-%H%M%S") . '_' . $i . $ext;
             // Reset the itempath.
             $itemPath = JPath::clean($storagePath . DIRECTORY_SEPARATOR . $tmp);
             $i++;
         }
         // Get the new file name for this item.
         $fileName = $tmp;
     }
     return $fileName;
 }