Ejemplo n.º 1
0
 /**
  * public static function that will upload template
  */
 public static function uploadTemplate()
 {
     jimport('joomla.filesystem.archive');
     $name = $_FILES['tempupload']['name'];
     $tempPath = JNEWS_JPATH_ROOT_NO_ADMIN . DS . 'media' . DS . JNEWS_OPTION . DS . 'templates' . DS;
     // check and set permission of the template folder
     if (!empty($name)) {
         $mediacomjNewsdir = jNews_Templates::_checkpermission(JNEWS_JPATH_ROOT_NO_ADMIN . DS . 'media' . DS . JNEWS_OPTION);
         $mediacomjNewsTemplatesdir = jNews_Templates::_checkpermission(JNEWS_JPATH_ROOT_NO_ADMIN . DS . 'media' . DS . JNEWS_OPTION . DS . 'templates');
         $mediacomjNewsTemplatesThumbnaildir = jNews_Templates::_checkpermission(JNEWS_JPATH_ROOT_NO_ADMIN . DS . 'media' . DS . JNEWS_OPTION . DS . 'templates' . DS . 'thumbnail');
         if (!$mediacomjNewsdir or !$mediacomjNewsTemplatesdir or !$mediacomjNewsTemplatesThumbnaildir) {
             echo jnews::printM('notice', 'The following directory is not writable: ' . JNEWS_JPATH_ROOT_NO_ADMIN . DS . 'media' . DS . JNEWS_OPTION);
             return false;
         }
     } else {
         //failed
         echo jnews::printM('notice', 'Did not found a file to upload.');
         return false;
     }
     // upload template
     $status = true;
     $path = JNEWS_JPATH_ROOT_NO_ADMIN . DS . 'media' . DS . JNEWS_OPTION . DS . 'templates';
     $folderName = substr($name, 0, -4);
     $result = jNews_Mailing::uploadFiles($path);
     $nameRealFolder = jNews_Templates::openZip($tempPath . $name);
     jNews_Templates::$nameNewFolder = "";
     if ($folderName !== $nameRealFolder) {
         jNews_Templates::$nameNewFolder = $nameRealFolder;
     }
     if (jNews_Templates::$nameNewFolder === "") {
         if (!is_dir($tempPath . $folderName)) {
             $status = mkdir($tempPath . $folderName, 0755);
         }
     }
     if (!$status) {
         echo jnews::printM('notice', 'The following directory is not writable: ' . $tempPath);
         return false;
     }
     if ($status && !empty($result)) {
         $resultArchive = JArchive::extract($tempPath . $name, $path);
         if ($resultArchive) {
             // delete zip afterwards
             if (fopen($tempPath . $name, 'w')) {
                 @unlink($tempPath . $name);
             }
             //we prompt a message that the upload was successful
             echo jnews::printM('green', 'Successfully uploaded the template');
             if (is_dir($tempPath . $folderName)) {
                 chmod($tempPath . $folderName, 0755);
             }
             if (jNews_Templates::$nameNewFolder === "") {
                 return file_exists($tempPath . $folderName . DS . 'index.html') ? true : false;
             } else {
                 return file_exists($tempPath . $nameRealFolder . DS . 'index.html') ? true : false;
             }
         } else {
             echo 'Joomla is unable to extract the file :' . $tempPath . $name;
         }
     } else {
         return false;
     }
 }