public static function read($service_answer, $query_vars, $app_id)
 {
     $service_answer = array();
     $app_id = WpakApps::get_app_id($app_id);
     $service_answer = WpakComponents::get_components_synchro_data($app_id);
     return (object) $service_answer;
 }
Example #2
0
 public static function read_one($service_answer, $id, $app_id)
 {
     $service_answer = array();
     $app_id = WpakApps::get_app_id($app_id);
     $component_slug = addslashes($id);
     $args = array();
     if (isset($_GET['before_item']) && !empty($_GET['before_item'])) {
         $args['before_item'] = addslashes($_GET['before_item']);
     }
     $service_answer = WpakComponents::get_component_data($app_id, $component_slug, $args);
     return (object) $service_answer;
 }
 public static function read($service_answer, $query_vars, $app_id)
 {
     $service_answer = array();
     $auth_params = WpakWebServiceContext::getClientAppParams();
     if (!empty($auth_params['auth_action'])) {
         $app_id = WpakApps::get_app_id($app_id);
         $auth_engine = AuthenticationSettings::get_auth_engine_instance();
         $service_answer = $auth_engine->get_webservice_answer($app_id);
     } else {
         $service_answer = array('error' => 'no-auth-action');
         //This will set webservice answer status to 0.
     }
     return (object) $service_answer;
 }
Example #4
0
 /**
  * Retrieve "Live query" web service answer.
  * 
  * Any custom input params passed through the web service GET data can be
  * retrieved via WpakWebServiceContext::getClientAppParam( 'my_param' );
  * 
  * The following input params are automatically recognized and interpreted :
  * - 'wpak_component_slug' : if present, the WS automatically retrieve data
  *   about the given component
  * - 'wpak_query_action' : optionnaly use along with 'wpak_component_slug'. Can be :
  *     -- 'get-component' : default value : retrieves default component data
  *     -- 'get-items' : retrieves only the 'wpak_items_ids' items 
  * - 'wpak_items_ids' : array of items ids to retrieve (when wpak_query_action = get-items)
  * 
  * @return array $service_answer Web service answer : Advised answer structure :
  * By default, app core automatically knows what to do with an answer containing 
  * the following keys :
  * - 'globals'
  * - 'component' or 'components'
  * But the answer structure can be totally overriden, provided it is understood on
  * app side using the dedicated hooks.
  */
 public static function read($service_answer, $query_vars, $app_id)
 {
     $app_id = WpakApps::get_app_id($app_id);
     $component_slug = WpakWebServiceContext::getClientAppParam('wpak_component_slug');
     $action = WpakWebServiceContext::getClientAppParam('wpak_query_action');
     $action = empty($action) || !in_array($action, array('get-component', 'get-items')) ? 'get-component' : $action;
     if (!empty($component_slug)) {
         $service_answer = array('globals' => array(), 'component' => array());
         if (is_array($component_slug)) {
             //The only valid action is 'get-component' if $component_slug is an array :
             if ($action == 'get-component') {
                 //Retrieve data for all given components and merge globals :
                 unset($service_answer['component']);
                 $service_answer['components'] = array();
                 foreach ($component_slug as $slug) {
                     $component_data = WpakComponents::get_component_data($app_id, $slug);
                     if (!empty($component_data)) {
                         foreach ($component_data['globals'] as $global => $items) {
                             foreach ($items as $k => $item) {
                                 $service_answer['globals'][$global][$k] = $item;
                             }
                         }
                         $service_answer['components'][$slug] = $component_data['component'];
                     }
                 }
             }
         } else {
             //Only one component given : simply retrieve its data :
             switch ($action) {
                 case 'get-component':
                     $service_answer = WpakComponents::get_component_data($app_id, $component_slug);
                     break;
                 case 'get-items':
                     $items_ids = WpakWebServiceContext::getClientAppParam('wpak_items_ids');
                     if (!empty($items_ids)) {
                         $items_ids = !is_array($items_ids) && is_numeric($items_ids) ? array(intval($items_ids)) : array_map('intval', $items_ids);
                         $service_answer = WpakComponents::get_component_items($app_id, $component_slug, $items_ids);
                     }
                     break;
             }
         }
     }
     $query_params = WpakWebServiceContext::getClientAppParams();
     $service_answer = apply_filters('wpak_live_query', $service_answer, $query_params, $app_id, $query_vars);
     return (object) $service_answer;
 }
Example #5
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 #6
0
 public static function get_app_web_service_url($app_id_or_slug, $web_service_slug)
 {
     $url = self::get_app_web_service_base_url($app_id_or_slug);
     $app_slug = WpakApps::get_app_slug($app_id_or_slug);
     $app_id = WpakApps::get_app_id($app_id_or_slug);
     if (WpakApps::get_app_is_secured($app_id)) {
         $token = WpakToken::get_token($app_slug, $web_service_slug);
         $url .= '/' . $token;
     }
     $url .= '/' . $web_service_slug;
     return $url;
 }
Example #7
0
 public static function get_app_addons($app_id_or_slug)
 {
     $app_addons = array();
     $app_id = WpakApps::get_app_id($app_id_or_slug);
     if (!empty($app_id)) {
         $app_addons_raw = get_post_meta($app_id, self::meta_id, true);
         if (!empty($app_addons_raw)) {
             //Check if the app addons are still installed :
             $all_addons = self::get_addons();
             foreach ($app_addons_raw as $addon_slug) {
                 if (array_key_exists($addon_slug, $all_addons)) {
                     $addon = $all_addons[$addon_slug];
                     $addon->set_app_static_data($app_id);
                     $addon->set_app_dynamic_data($app_id);
                     $app_addons[$addon_slug] = $addon;
                 }
             }
         }
     }
     return $app_addons;
 }