Example #1
0
 public static function add_action_link($actions)
 {
     global $post;
     if ($post->post_type == 'wpak_apps') {
         if (array_key_exists('trash', $actions)) {
             $trash_mem = $actions['trash'];
             unset($actions['trash']);
             $actions['wpak-view-app-in-browser'] = '<a href="' . WpakBuild::get_appli_index_url($post->ID) . '" target="_blank">' . __('View in browser', WpAppKit::i18n_domain) . '</a>';
             $actions['trash'] = $trash_mem;
         } else {
             $actions['wpak-view-app-in-browser'] = '<a href="' . WpakBuild::get_appli_index_url($post->ID) . '" target="_blank">' . __('View in browser', WpAppKit::i18n_domain) . '</a>';
         }
     }
     return $actions;
 }
Example #2
0
 /**
  * Export app sources for PhoneGap CLI compilation
  * 
  * ## OPTIONS
  * 
  * <app_id_or_slug> : Application ID or Application slug
  * 
  * <target_directory> : Target directory where the export files will be copied
  * 
  * <export_type> : (Optionnal) Export type can be "phonegap-cli" (default if not provided) or "phonegap-build"
  * 
  * ## EXAMPLES
  * 
  *     PhoneGap CLI export : wp wpak export 123 /target/directory/
  *     PhoneGap Build export : wp wpak export 123 /target/directory/ "phonegap-build"
  *
  * @synopsis <app_id> <target_directory> [<export_type>]
  * 
  * @subcommand export
  */
 public function export($args, $assoc_args)
 {
     list($app_id_or_slug, $target_directory, $export_type) = $args;
     if (empty($export_type)) {
         $export_type = "phonegap-cli";
     }
     if (!in_array($export_type, array("phonegap-cli", "phonegap-build"))) {
         WP_CLI::error('Unknown export type "' . $export_type . '"');
     }
     //Check that the given app exists :
     if (WpakApps::app_exists($app_id_or_slug)) {
         if (is_dir($target_directory)) {
             WP_CLI::line('Export app "' . $app_id_or_slug . '" to ' . $target_directory);
             $app_id = WpakApps::get_app_id($app_id_or_slug);
             $answer = WpakBuild::build_app_sources($app_id, $export_type);
             if ($answer['ok'] === 1) {
                 $zip_file = $answer['export_full_name'];
                 WP_CLI::line("App sources zipped to " . $zip_file);
                 WP_CLI::line("Extract zip to destination");
                 //Extract to target directory :
                 WP_Filesystem();
                 $result = unzip_file($zip_file, $target_directory);
                 if (!is_wp_error($result)) {
                     WP_CLI::success("App sources extracted successfully to {$target_directory}");
                 } else {
                     WP_CLI::line('Could not extract ZIP export to : ' . $target_directory);
                     WP_CLI::error($result->get_error_message());
                 }
             } else {
                 WP_CLI::error('Export error : ' . $answer['msg']);
             }
         } else {
             WP_CLI::error('Destination directory not found : ' . $target_directory);
         }
     } else {
         WP_CLI::error('Application "' . $app_id_or_slug . '" not found');
     }
 }
Example #3
0
    public static function get_config_js($app_id, $echo = false)
    {
        $wp_ws_url = WpakWebServices::get_app_web_service_base_url($app_id);
        $theme = WpakThemesStorage::get_current_theme($app_id);
        $app_slug = WpakApps::get_app_slug($app_id);
        $app_main_infos = WpakApps::get_app_main_infos($app_id);
        $app_title = $app_main_infos['title'];
        $app_version = WpakApps::sanitize_app_version($app_main_infos['version']);
        $debug_mode = WpakBuild::get_app_debug_mode($app_id);
        $auth_key = WpakApps::get_app_is_secured($app_id) ? WpakToken::get_hash_key() : '';
        //TODO : options to choose if the auth key is displayed in config.js.
        $options = WpakOptions::get_app_options($app_id);
        $addons = WpakAddons::get_app_addons_for_config($app_id);
        if (!$echo) {
            ob_start();
        }
        //Indentation is a bit funky here so it appears ok in the config.js file source:
        ?>
define( function ( require ) {

	"use strict";

	return {
		app_slug : '<?php 
        echo $app_slug;
        ?>
',
		wp_ws_url : '<?php 
        echo $wp_ws_url;
        ?>
',
		theme : '<?php 
        echo addslashes($theme);
        ?>
',
		version : '<?php 
        echo $app_version;
        ?>
',
		app_title : '<?php 
        echo addslashes($app_title);
        ?>
',
		debug_mode : '<?php 
        echo $debug_mode;
        ?>
'<?php 
        if (!empty($auth_key)) {
            ?>
,
		auth_key : '<?php 
            echo $auth_key;
            ?>
'<?php 
        }
        ?>
,
		options : <?php 
        echo json_encode($options);
        ?>
,
		addons : <?php 
        echo json_encode($addons);
        ?>

	};

});
<?php 
        $content = '';
        if (!$echo) {
            $content = ob_get_contents();
            ob_end_clean();
        }
        return !$echo ? $content : '';
    }
 /**
  * Checks that control data sent is valid.
  * User authentication.getActionAuthData() on server side to generate $auth_data.
  * 
  * @param int $app_id App id
  * @param string $action Authentication action name
  * @param array $auth_data Authentication data (user, control, timestamp)
  * @param array $to_check Data we have to check validity for
  */
 public function check_authenticated_action($app_id, $action, $auth_data, $to_check)
 {
     $result = array('ok' => false, 'auth_error' => '', 'user' => '');
     $debug_mode = WpakBuild::get_app_debug_mode($app_id) === 'on';
     //First check user validity
     if (!empty($auth_data['user'])) {
         $user = $auth_data['user'];
         //Check user exists
         $user_wp = get_user_by('login', $user);
         if ($user_wp) {
             //Check the user is not banned :
             if ($this->check_user_is_allowed_to_authenticate($user_wp->ID, $app_id)) {
                 //Check if the user is authenticated for the given app :
                 if ($this->user_is_authenticated($user_wp->ID, $app_id)) {
                     if (!empty($auth_data['control']) && !empty($auth_data['timestamp'])) {
                         $control_key = $this->get_user_secret($user_wp->ID, $app_id);
                         //If the user is authenticated, he has a secret key
                         $control = $auth_data['control'];
                         $timestamp = $auth_data['timestamp'];
                         $control_string = '';
                         foreach ($to_check as $value) {
                             if (is_string($value) || is_numeric($value)) {
                                 $control_string .= $value;
                             } elseif (is_bool($value)) {
                                 $control_string .= $value ? '1' : '0';
                             }
                         }
                         //Check control data :
                         if ($this->check_hmac($action . $user . $timestamp . $control_string, $control_key, $control)) {
                             if ($this->check_query_time($timestamp)) {
                                 $result['ok'] = true;
                                 $result['user'] = $user;
                             } else {
                                 //If not in debug mode, don't give error details for security concern :
                                 $result['auth_error'] = $debug_mode ? 'wrong-query-time' : 'auth-error';
                                 //Don't give more details for security concern
                             }
                         } else {
                             //If not in debug mode, don't give error details for security concern :
                             $result['auth_error'] = $debug_mode ? 'wrong-hmac' : 'auth-error';
                             //Don't give more details for security concern
                         }
                     } else {
                         //If not in debug mode, don't give error details for security concern :
                         $result['auth_error'] = $debug_mode ? 'wrong-auth-data' : 'auth-error';
                         //Don't give more details for security concern
                     }
                 } else {
                     $connection_validity = $this->get_user_connection_validity($user_wp->ID, $app_id);
                     $result['auth_error'] = $connection_validity === 0 ? 'user-not-authenticated' : 'user-connection-expired';
                 }
             } else {
                 $result['auth_error'] = 'user-banned';
             }
         } else {
             $result['auth_error'] = 'wrong-user';
         }
     } else {
         $result['auth_error'] = 'no-user';
     }
     return $result;
 }
Example #5
0
    public static function inner_phonegap_infos_box($post, $current_box)
    {
        $main_infos = self::get_app_main_infos($post->ID);
        ?>
		<a href="#" class="hide-if-no-js wpak_help"><?php 
        _e('Help me', WpAppKit::i18n_domain);
        ?>
</a>
		<div class="wpak_settings">
			<p class="description"><?php 
        _e('PhoneGap config.xml informations that are going to be displayed on App Stores.<br/>They are required when exporting the App to Phonegap, but are not used for App debug and simulation in browsers.', WpAppKit::i18n_domain);
        ?>
</p>
			<fieldset>
				<legend><?php 
        _e('Application', WpAppKit::i18n_domain);
        ?>
</legend>
				<div class="field-group">
					<label><?php 
        _e('Name', WpAppKit::i18n_domain);
        ?>
</label>
					<input type="text" name="wpak_app_name" value="<?php 
        echo esc_attr($main_infos['name']);
        ?>
" id="wpak_app_name" />
				</div>
				<div class="field-group">
					<label><?php 
        _e('Description', WpAppKit::i18n_domain);
        ?>
</label>
					<textarea name="wpak_app_desc" id="wpak_app_desc"><?php 
        echo esc_textarea($main_infos['desc']);
        ?>
</textarea>
				</div>
				<div class="field-group">
					<label><?php 
        _e('ID', WpAppKit::i18n_domain);
        ?>
</label>
					<input type="text" name="wpak_app_phonegap_id" value="<?php 
        echo esc_attr($main_infos['app_phonegap_id']);
        ?>
" id="wpak_app_app_phonegap_id" />
				</div>
				<div class="field-group">
					<label><?php 
        _e('Version', WpAppKit::i18n_domain);
        ?>
</label>
					<input type="text" name="wpak_app_version" value="<?php 
        echo esc_attr($main_infos['version']);
        ?>
" id="wpak_app_version" />
				</div>
				<div class="field-group">
					<label><?php 
        _e('VersionCode (Android only)', WpAppKit::i18n_domain);
        ?>
</label>
					<input type="text" name="wpak_app_version_code" value="<?php 
        echo esc_attr($main_infos['version_code']);
        ?>
" id="wpak_app_version_code" />
				</div>
				<div class="field-group">
					<label><?php 
        _e('Icons and splashscreens', WpAppKit::i18n_domain);
        ?>
</label>
					<textarea name="wpak_app_icons" id="wpak_app_icons"><?php 
        echo esc_textarea($main_infos['icons']);
        ?>
</textarea>
					<span class="description"><?php 
        _e('Write the icons and splashscreens tags as defined in the PhoneGap documentation.<br/>Example: ', WpAppKit::i18n_domain);
        ?>
&lt;icon src="icons/ldpi.png" gap:platform="android" gap:qualifier="ldpi" /&gt;</span>
				</div>
			</fieldset>
			<fieldset>
				<legend><?php 
        _e('Author', WpAppKit::i18n_domain);
        ?>
</legend>
				<div class="field-group">
					<label><?php 
        _e('Name', WpAppKit::i18n_domain);
        ?>
</label>
					<input type="text" name="wpak_app_author" value="<?php 
        echo esc_attr($main_infos['author']);
        ?>
" id="wpak_app_author" />
				</div>
				<div class="field-group">
					<label><?php 
        _e('Website', WpAppKit::i18n_domain);
        ?>
</label>
					<input type="text" name="wpak_app_author_website" value="<?php 
        echo esc_attr($main_infos['author_website']);
        ?>
" id="wpak_app_author_website" />
				</div>
				<div class="field-group">
					<label><?php 
        _e('Email', WpAppKit::i18n_domain);
        ?>
</label>
					<input type="text" name="wpak_app_author_email" value="<?php 
        echo esc_attr($main_infos['author_email']);
        ?>
" id="wpak_app_author_email" />
				</div>
			</fieldset>
			<fieldset>
				<legend><?php 
        _e('PhoneGap', WpAppKit::i18n_domain);
        ?>
</legend>
				<div class="field-group">
					<label><?php 
        _e('Version', WpAppKit::i18n_domain);
        ?>
</label>
					<input type="text" name="wpak_app_phonegap_version" value="<?php 
        echo esc_attr($main_infos['phonegap_version']);
        ?>
" id="wpak_app_phonegap_version" />
				</div>
				<div class="field-group">
					<label><?php 
        _e('Plugins', WpAppKit::i18n_domain);
        ?>
</label>
					<textarea name="wpak_app_phonegap_plugins" id="wpak_app_phonegap_plugins"><?php 
        echo esc_textarea($main_infos['phonegap_plugins']);
        ?>
</textarea>
					<span class="description"><?php 
        _e('Write the phonegap plugins tags as defined in the PhoneGap documentation.<br/>Example : to include the "In App Browser" plugin for a Phonegap Build compilation, enter &lt;gap:plugin name="org.apache.cordova.inappbrowser" version="0.3.3" /&gt; directly in the textarea.', WpAppKit::i18n_domain);
        ?>
</span>
				</div>
			</fieldset>
			<div class="field-group wpak_phonegap_links">
				<a href="<?php 
        echo WpakBuild::get_appli_dir_url() . '/config.xml?wpak_app_id=' . self::get_app_slug($post->ID);
        ?>
" target="_blank"><?php 
        _e('View config.xml', WpAppKit::i18n_domain);
        ?>
</a>
				<a href="<?php 
        echo esc_url(wp_nonce_url(add_query_arg(array('action' => 'wpak_download_app_sources')), 'wpak_download_app_sources'));
        ?>
" class="button wpak_phonegap_export" target="_blank"><?php 
        _e('Export', WpAppKit::i18n_domain);
        ?>
</a>
			</div>
			<?php 
        wp_nonce_field('wpak-phonegap-infos-' . $post->ID, 'wpak-nonce-phonegap-infos');
        ?>
		</div>
		<?php 
    }
Example #6
0
                    }
                }
            }
            //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;
    }
    private static function filter_index($index_content)
    {
        //Add cordova.js script (set cordova.js instead of phonegap.js, because PhoneGap Developer App doesn't seem
        //to support phonegap.js). PhoneGap Build can use indifferently cordova.js or phonegap.js.
        $index_content = str_replace('<head>', "<head>\r\n\t\t<script src=\"cordova.js\"></script>\r\n\t\t", $index_content);
        //Remove script used only for app simulation in web browser :
        $index_content = preg_replace('/<script[^>]*>[^<]*var query[^<]*<\\/script>\\s*<script/is', '<script', $index_content);
        return $index_content;
    }
}
WpakBuild::hooks();