Exemple #1
0
 /**
  * Mode To Module Dir
  * 
  * Move module temp fil to valid module folder [for internal use only]
  *
  * @access       public
  * @author       blair Jersyer
  * @copyright    2015
  * @param        array $module_array
  * @param			array $global_manifest
  * @param			array $manifest
  * @param  			array $extraction_data
  * @param			bool $conflict_checker
  * @since        3.0.1
  * @return 		  void
  */
 static function __move_to_module_dir($module_array, $global_manifest, $manifest, $extraction_data, $conflict_checker = false)
 {
     $module_namespace = $module_array['application']['details']['namespace'];
     // module namespace
     if ($conflict_checker === true) {
         // Check first
         foreach ($manifest as $_manifest_file) {
             // removing raw_name from old manifest to ease copy
             $relative_path_to_file = explode($extraction_data['upload_data']['raw_name'] . '/', $_manifest_file);
             $_manifest_file = APPPATH . $relative_path_to_file[1];
             if (file_exists($_manifest_file)) {
                 return array('msg' => 'file-conflict', 'extra' => urlencode($_manifest_file));
             }
         }
     }
     //
     get_instance()->load->helper('file');
     $folder_to_lower = strtolower($module_namespace);
     $module_dir_path = MODULESPATH . $folder_to_lower;
     // Creating module folder within
     if (!is_dir(MODULESPATH . $folder_to_lower)) {
         mkdir(MODULESPATH . $folder_to_lower, 0777, true);
     }
     // moving global manifest
     foreach ($global_manifest as $_manifest) {
         // creating folder if it does'nt exists
         if (!is_file($_manifest)) {
             $dir_name = basename($_manifest);
             SimpleFileManager::copy($_manifest, $module_dir_path . '/' . $dir_name);
         } else {
             $file_name = basename($_manifest);
             write_file($module_dir_path . '/' . $file_name, file_get_contents($_manifest));
         }
     }
     $relative_json_manifest = array();
     // moving manifest to system folder
     foreach ($manifest as $_manifest) {
         // removing raw_name from old manifest to ease copy
         $relative_path_to_file = explode($extraction_data['upload_data']['raw_name'] . '/', $_manifest);
         if (!is_file($_manifest)) {
             $dir_name = basename($_manifest);
             SimpleFileManager::copy($_manifest, $relative_path_to_file[1]);
         } else {
             $relative_path_to_file[1] = str_replace('/', '\\', $relative_path_to_file[1]);
             // write file on the new folder
             SimpleFileManager::file_copy($_manifest, APPPATH . $relative_path_to_file[1]);
             // relative json manifest
             $relative_json_manifest[] = str_replace('/', '\\', APPPATH . $relative_path_to_file[1]);
         }
     }
     // Creating Manifest
     file_put_contents($module_dir_path . '/manifest.json', json_encode($relative_json_manifest));
     /**
      * New Feature Assets management
      * Description : move module assets to public directory within a folder with namespace as name
      **/
     if (is_dir($module_dir_path . '/' . 'assets')) {
         if (is_dir(PUBLICPATH . $module_namespace)) {
             // checks if module folder exists on public folder
             SimpleFileManager::drop(PUBLICPATH . '/' . 'modules' . '/' . $module_namespace);
         }
         mkdir(PUBLICPATH . '/' . 'modules' . '/' . $module_namespace);
         // creating module folder within
         SimpleFileManager::extractor($module_dir_path . '/' . 'assets', PUBLICPATH . '/' . 'modules' . '/' . $module_namespace);
     }
     return true;
 }
 function install($stage, $zipball = null)
 {
     $tendoo_zip = APPPATH . 'temp/tendoo-cms.zip';
     if ($stage === 1 && $zipball != null) {
         // for downloading
         $tendoo_cms_zip = $this->curl->security(false)->get('https://codeload.github.com/Blair2004/tendoo-cms/legacy.zip/' . $zipball);
         if (!empty($tendoo_cms_zip)) {
             file_put_contents($tendoo_zip, $tendoo_cms_zip);
             return array('code' => 'archive-downloaded');
         }
         return array('code' => 'error-occured');
     } elseif ($stage === 2) {
         // for uncompressing
         if (is_file($tendoo_zip)) {
             // if zip exists
             $zip = new ZipArchive();
             $tendoo = $zip->open($tendoo_zip);
             if ($tendoo) {
                 if (is_dir(APPPATH . 'temp/core')) {
                     SimpleFileManager::drop(APPPATH . 'temp/core');
                     // if any update failed, we drop temp/core before
                 }
                 mkdir(APPPATH . 'temp/core');
                 $zip->extractTo(APPPATH . 'temp/core');
                 $zip->close();
                 unlink($tendoo_zip);
                 // removing zip file
             }
             return array('code' => 'archive-uncompressed');
         }
     } elseif ($stage === 3) {
         // updating itself
         if (is_dir(APPPATH . 'temp/core')) {
             // looping internal dir
             $dir = opendir(APPPATH . 'temp/core');
             while (false !== ($file = readdir($dir))) {
                 if (!in_array($file, array('.', '..'))) {
                     // skiping up directory
                     SimpleFileManager::extractor(APPPATH . 'temp/core/' . $file, FCPATH);
                     break;
                     // first folder is tendoo main folder (we think, since branch name can change)
                 }
             }
             SimpleFileManager::drop(APPPATH . 'temp/core');
             // dropping core update folder
             return array('code' => 'update-done');
         }
     }
     return array('code' => 'error-occured');
 }