diff --git a/apps.manifest.inc b/apps.manifest.inc index b5d8df5..3ea775f 100755 --- a/apps.manifest.inc +++ b/apps.manifest.inc @@ -11,6 +11,12 @@ define ("INCOMPATABLE", -1); define ("INSTALLABLE", 2); +/** + * Scans for apps manifests through all available local modules. + * + * @param $server: the name of a server. + * @return : array of apps found on local server. + */ function apps_server_local($server) { $apps = array(); $infos = system_rebuild_module_data(); @@ -20,10 +26,12 @@ function apps_server_local($server) { foreach($info->info['apps']['manifests'] as $mfile) { $mfile = drupal_get_path("module", $module) . "/" .$mfile; $app = drupal_parse_info_file($mfile); - foreach($app['screenshots'] as $id=>$image) { - $app['screenshots'][$id] = url(dirname($mfile) . "/" . $image); - } - $app['logo'] = url(dirname($mfile) . "/" . $app['logo']); + if (isset($app['screenshots'])) { + foreach($app['screenshots'] as $id => $image) { + $app['screenshots'][$id] = url(dirname($mfile) . "/" . $image); + } + } + $app['logo'] = url(dirname($mfile) . "/" . $app['logo']); $apps[] = $app; } } @@ -31,10 +39,11 @@ function apps_server_local($server) { } return $apps; } -/* - * returns all servers/server defined by the current profile - * PARAM server_name: the name of a server - * RETURN : an array of server arrays one server array if $server_name has a value + +/** + * Returns all servers/server defined by the current profile + * @param server_name: the name of a server + * @return : an array of server arrays one server array if $server_name has a value * * TODO: Turn Store Objects in to Object instead of arrays OPIC-372 */ @@ -71,12 +80,14 @@ function apps_servers($server_name = FALSE) { } return FALSE; } + /** - * retrieve apps from the manifest - * PARAM $server: a server object return from apps_servers - * PARAM $condition: and array of key and values to match in the app arrays - * PARAM $add_theme: if True apps_apps_add_theme will be called when done getting apps - * RETURN : an array of app info arrays + * Retrieve apps from the manifest. + * + * @param $server: a server object return from apps_servers. + * @param $condition: and array of key and values to match in the app arrays. + * @param $add_theme: if True apps_apps_add_theme will be called when done getting apps. + * @return : an array of app info arrays. */ function apps_apps($server, $condition = array(), $add_theme=FALSE) { if (!is_array($server)) { @@ -102,11 +113,12 @@ function apps_apps($server, $condition = array(), $add_theme=FALSE) { } /** - * takes an array of apps and ands #theme properties so that - * it can be drupal rendered - * PARAM $apps: an array of apps from apps_apps - * RETURN : the apps array with add #theme settings for a list - * view of the apps + * Takes an array of apps and ands #theme properties so that + * it can be drupal rendered. + * + * @param $apps: an array of apps from apps_apps. + * @return : the apps array with add #theme settings for a list + * view of the apps. */ function apps_apps_add_theme(&$apps) { foreach($apps as $id=> $app) { @@ -132,10 +144,11 @@ function apps_client_id() { } /** - * Request manifest and media assets from the app server - * PARAM $server: a server object return from apps_servers - * RETURN : an array represntation of the json manifest, with images - * relpaced by file objects + * Request manifest and media assets from the app server. + * + * @param $server: a server object return from apps_servers. + * @return : an array represntation of the json manifest, with images + * relpaced by file objects. * * TODO: Handle lack of server presense OPIC-374 */ @@ -144,8 +157,8 @@ function apps_request_manifest($server) { $manifest_cache = false; $manifest = $manifest_cache ? $manifest_cache->data : FALSE; - if(!$manifest) { - if(!$server['manifest']) { + if (!$manifest) { + if (!isset($server['manifest']) || !$server['manifest']) { $apps = apps_server_local($server); $manifest = $server; $manifest['apps'] = $apps; @@ -187,41 +200,38 @@ function apps_request_manifest($server) { return $manifest; } -/* - * Downloads images so that they can be sized with image styles +/** + * Downloads images so that they can be sized with image styles. */ function apps_request_manifest_image_process(&$manifest) { foreach($manifest['apps'] as $id => $app) { - - //Get Logo - $logo_uri = $app['logo']; + // Get logo. $logo = (array) apps_retrieve_app_image($app['logo'], "{$app['name']} Logo"); - $manifest['apps'][$id]['logo'] = !empty($logo) ? $logo : FALSE; - //Get screenshots - foreach ($app['screenshots'] as $ss_id => $ss) { - $screenshot = (array) apps_retrieve_app_image($ss, "{$app['name']} Screenshot $id"); - - if(!empty($screenshot)) { - $manifest['apps'][$id]['screenshots'][$ss_id] = $screenshot; - } - else { - unset($manifest['apps'][$id]['screenshots'][$ss_id]); + // Get screenshots. + if (isset($app['screenshots'])) { + foreach ($app['screenshots'] as $ss_id => $ss) { + $screenshot = (array) apps_retrieve_app_image($ss, "{$app['name']} Screenshot $id"); + + if(!empty($screenshot)) { + $manifest['apps'][$id]['screenshots'][$ss_id] = $screenshot; + } + else { + unset($manifest['apps'][$id]['screenshots'][$ss_id]); + } } } } - } /** - * Download a image from the manifest - * - * PARAM url: the url of the image - * PARAM title: the title of the image - * PARAM alt: the alt text of the image - * RETURN : a file object for the download file or FALSE if no image was downloaded + * Download a image from the manifest. * + * @param url: the url of the image. + * @param title: the title of the image. + * @param alt: the alt text of the image. + * @return : a file object for the download file or FALSE if no image was downloaded. */ function apps_retrieve_app_image($url, $title = FALSE, $alt = FALSE) { //to prevent strict warning need to store this in a variable @@ -273,15 +283,15 @@ function apps_retrieve_app_image($url, $title = FALSE, $alt = FALSE) { } /** - * Produce the Process Manifest + * Produce the Process Manifest. * * Starting with the json manifest and adding data around the current status of the app - * in this install + * in this install. * - * PARAM $server: a server object return from apps_servers - * RETURN : an array of the process json manifest + * @param $server: a server object return from apps_servers. + * @return : an array of the process json manifest. * - *TODO: Cache status data and clear on changes to any module status + * TODO: Cache status data and clear on changes to any module status. */ function apps_manifest($server) { $manifest = &drupal_static(__function__); @@ -301,7 +311,7 @@ function apps_manifest($server) { $app['incompatable'] = FALSE; $app['installed'] = (bool) $current_app_module; $app['disabled'] = $current_app_module && empty($current_app_module->status) && $current_app_module->schema_version > SCHEMA_UNINSTALLED; - $app['featured'] = ($app['machine_name'] == $manifest['featured app']); + $app['featured'] = (isset($manifest['featured app']) && $app['machine_name'] == $manifest['featured app']); $app['server'] = $server; // Add info to dependencies foreach($app['dependencies'] as $name_version => $downloadable) { @@ -399,22 +409,19 @@ function apps_app_callback($app, $key) { } } - /** - * default demo content enabled callback + * Default demo content enabled callback. * - * check to see if the apps demo content module is enabled + * Check to see if the apps demo content module is enabled. */ function apps_demo_content_enabled($app) { return (module_exists($app['demo content module'])); } /** - * default demo content enable callback - * - * enables the app's demo content module - * PARAM $app: an app array - * RETURN : bool if the module was enabled + * Default demo content enable callback. Enables the app's demo content module. + * @param $app: an app array. + * @return : bool if the module was enabled. */ function apps_demo_content_enable($app) { $success = module_enable(array($app['demo content module'])); @@ -423,11 +430,9 @@ function apps_demo_content_enable($app) { } /** - * default demo content disable callback - * - * disables the app's demo content module - * PARAM $app: an app array - * RETURN : bool if the module was disabled + * Default demo content disable callback. Disables the app's demo content module. + * @param $app : an app array. + * @return : bool if the module was disabled. */ function apps_demo_content_disable($app) { $success = module_disable(array($app['demo content module'])); @@ -436,7 +441,7 @@ function apps_demo_content_disable($app) { } /** - * formcall back for demo content + * Form callback for demo content. */ function apps_demo_content_form($form, &$form_state, $app) { $form = array(); @@ -470,7 +475,7 @@ function apps_demo_content_form($form, &$form_state, $app) { } /** - * callback for demp content form + * Callback for demo content form. */ function apps_demo_content_form_submit($form, &$form_state) { $app = $form_state['values']['app'];