Example #1
0
 protected static function add_rewrite_rules()
 {
     WpakWebServices::add_rewrite_tags_and_rules();
     WpakConfigFile::rewrite_rules();
     WpakThemes::rewrite_rules();
 }
Example #2
0
                ?>
 />
<?php 
            }
        }
        ?>

	<!-- Icon and Splash screen declaration -->
<?php 
        if (!empty($app_icons)) {
            ?>

	<?php 
            echo str_replace("\n", "\n\t", $app_icons);
            ?>

<?php 
        }
        ?>
</widget>
<?php 
        $content = '';
        if (!$echo) {
            $content = ob_get_contents();
            ob_end_clean();
        }
        return !$echo ? $content : '';
    }
}
WpakConfigFile::hooks();
Example #3
0
 private static function build_zip($app_id, $source, $destination, $themes, $addons, $export_type)
 {
     $answer = array('ok' => 1, 'msg' => '');
     if (!extension_loaded('zip') || !file_exists($source)) {
         $answer['msg'] = sprintf(__('The Zip archive file [%s] could not be created. Please check that you have the permissions to write to this directory.', WpAppKit::i18n_domain), $destination);
         $answer['ok'] = 0;
         return $answer;
     }
     $zip = new ZipArchive();
     //
     // ZipArchive::open() returns TRUE on success and an error code on failure, not FALSE
     // All other used ZipArchive methods return FALSE on failure
     //
     // Apparently ZipArchive::OVERWRITE is not sufficient for recent PHP versions (>= 5.2.8, cf. comments here: http://fr.php.net/manual/en/ziparchive.open.php)
     //
     if (true !== ($error_code = $zip->open($destination, ZipArchive::CREATE | ZipArchive::OVERWRITE))) {
         switch ($error_code) {
             case ZipArchive::ER_EXISTS:
                 $error = _x('File already exists', 'ZipArchive::ER_EXISTS error', WpAppKit::i18n_domain);
                 break;
             case ZipArchive::ER_INCONS:
                 $error = _x('Zip archive inconsistent', 'ZipArchive::ER_INCONS error', WpAppKit::i18n_domain);
                 break;
             case ZipArchive::ER_INVAL:
                 $error = _x('Invalid argument', 'ZipArchive::ER_INVAL error', WpAppKit::i18n_domain);
                 break;
             case ZipArchive::ER_MEMORY:
                 $error = _x('Malloc failure', 'ZipArchive::ER_MEMORY error', WpAppKit::i18n_domain);
                 break;
             case ZipArchive::ER_NOENT:
                 $error = _x('No such file', 'ZipArchive::ER_NOENT error', WpAppKit::i18n_domain);
                 break;
             case ZipArchive::ER_NOZIP:
                 $error = _x('Not a zip archive', 'ZipArchive::ER_NOZIP error', WpAppKit::i18n_domain);
                 break;
             case ZipArchive::ER_OPEN:
                 $error = _x('Can\'t open file', 'ZipArchive::ER_OPEN error', WpAppKit::i18n_domain);
                 break;
             case ZipArchive::ER_READ:
                 $error = _x('Read error', 'ZipArchive::ER_READ error', WpAppKit::i18n_domain);
                 break;
             case ZipArchive::ER_SEEK:
                 $error = _x('Seek error', 'ZipArchive::ER_SEEK error', WpAppKit::i18n_domain);
                 break;
             default:
                 $error = '';
         }
         $answer['msg'] = sprintf(__('The Zip archive file [%s] could not be opened (%s). Please check that you have the permissions to write to this directory.', WpAppKit::i18n_domain), $destination, $error);
         $answer['ok'] = 0;
         return $answer;
     }
     if (is_dir($source) === true) {
         $source_root = '';
         if ($export_type === 'phonegap-cli') {
             //PhoneGap CLI export is made in www subdirectory
             //( only config.xml stays at zip root )
             $source_root = 'www';
             if (!$zip->addEmptyDir($source_root)) {
                 $answer['msg'] = sprintf(__('Could not add directory [%s] to zip archive', WpAppKit::i18n_domain), $source_root);
                 $answer['ok'] = 0;
                 return $answer;
             }
         }
         if (!empty($source_root)) {
             $source_root .= '/';
         }
         $files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source), RecursiveIteratorIterator::SELF_FIRST);
         foreach ($files as $file) {
             $filename = str_replace($source, '', $file);
             $filename = wp_normalize_path($filename);
             $filename = ltrim($filename, '/\\');
             //Themes are included separately from the wpak themes directory
             if (preg_match('|themes[/\\\\].+|', $filename)) {
                 continue;
             }
             $zip_filename = $source_root . $filename;
             if (is_dir($file) === true) {
                 if (!$zip->addEmptyDir($zip_filename)) {
                     $answer['msg'] = sprintf(__('Could not add directory [%s] to zip archive', WpAppKit::i18n_domain), $zip_filename);
                     $answer['ok'] = 0;
                     return $answer;
                 }
             } elseif (is_file($file) === true) {
                 if ($filename == 'index.html') {
                     $index_content = self::filter_index(file_get_contents($file));
                     if (!$zip->addFromString($zip_filename, $index_content)) {
                         $answer['msg'] = sprintf(__('Could not add file [%s] to zip archive', WpAppKit::i18n_domain), $zip_filename);
                         $answer['ok'] = 0;
                         return $answer;
                     }
                 } else {
                     if (!$zip->addFile($file, $zip_filename)) {
                         $answer['msg'] = sprintf(__('Could not add file [%s] to zip archive', WpAppKit::i18n_domain), $zip_filename);
                         $answer['ok'] = 0;
                         return $answer;
                     }
                 }
             }
         }
         //Add themes files :
         if (!empty($themes)) {
             $themes_directory = WpakThemes::get_themes_directory();
             if (is_dir($themes_directory)) {
                 $files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($themes_directory), RecursiveIteratorIterator::SELF_FIRST);
                 foreach ($files as $file) {
                     $filename = str_replace($themes_directory, '', $file);
                     $filename = wp_normalize_path($filename);
                     $filename = ltrim($filename, '/\\');
                     //Filter themes :
                     $theme = preg_replace('|([^/\\\\]*)[/\\\\].*|', '$1', $filename);
                     if (!in_array($theme, $themes)) {
                         continue;
                     }
                     //Filter php directory
                     if (preg_match('|' . $theme . '[/\\\\]php|', $filename)) {
                         continue;
                     }
                     $filename = 'themes/' . $filename;
                     $zip_filename = $source_root . $filename;
                     if (is_dir($file) === true) {
                         if (!$zip->addEmptyDir($zip_filename)) {
                             $answer['msg'] = sprintf(__('Could not add directory [%s] to zip archive', WpAppKit::i18n_domain), $zip_filename);
                             $answer['ok'] = 0;
                             return $answer;
                         }
                     } elseif (is_file($file) === true) {
                         if (!$zip->addFile($file, $zip_filename)) {
                             $answer['msg'] = sprintf(__('Could not add file [%s] to zip archive', WpAppKit::i18n_domain), $zip_filename);
                             $answer['ok'] = 0;
                             return $answer;
                         }
                     }
                 }
             }
         }
         //Add addons files :
         if (!empty($addons)) {
             foreach ($addons as $addon) {
                 $addon_files = $addon->get_all_files();
                 foreach ($addon_files as $addon_file) {
                     $zip_filename = $source_root . 'addons/' . $addon->slug . '/' . $addon_file['relative'];
                     $zip->addFile($addon_file['full'], $zip_filename);
                 }
             }
         }
         //Create config.js file :
         $zip->addFromString($source_root . 'config.js', WpakConfigFile::get_config_js($app_id));
         //Create config.xml file (stays at zip root) :
         $zip->addFromString('config.xml', WpakConfigFile::get_config_xml($app_id, false, $export_type));
     } else {
         $answer['msg'] = sprintf(__('Zip archive source directory [%s] could not be found.', WpAppKit::i18n_domain), $source);
         $answer['ok'] = 0;
         return $answer;
     }
     if (!$zip->close()) {
         $answer['msg'] = __('Error during archive creation', WpAppKit::i18n_domain);
         $answer['ok'] = 0;
         return $answer;
     }
     return $answer;
 }