Example #1
0
 public static function action_getDetails($args, &$returncode, &$profile, &$auth = false, $format = false)
 {
     if ($auth) {
         $returncode = ResponseCode::BAD_REQUEST;
         return false;
     }
     if (!$profile->perm_app_getdetails) {
         $returncode = ResponseCode::ACTION_NOT_ALLOWED;
         return false;
     }
     if (isset($args->app_id) && isset($args->itunes_id) || !isset($args->app_id) && !isset($args->itunes_id)) {
         $returncode = ResponseCode::BAD_REQUEST;
         return false;
     }
     $am = ApplicationModel::getInstance();
     $result = false;
     if (isset($args->app_id)) {
         $result = $am->getDetailsByAppIDCached($args->app_id);
     } else {
         if (isset($args->itunes_id)) {
             $result = $am->getDetailsByITunesIDCached($args->itunes_id);
         }
     }
     if (!$result) {
         $returncode = ResponseCode::RESOURCE_NOT_FOUND;
         return false;
     }
     $fields = isset($args->fields) && is_array($args->fields) ? $args->fields : array();
     $legal = $profile->allowed_app_fields;
     $realfields = ApplicationBean::getFields();
     $app = array('id' => $result->id);
     foreach ($fields as $field) {
         if ($field != 'id' && in_array($field, $realfields) && (in_array($field, $legal) || $legal[0] == 'ALL')) {
             $app[$field] = $result->{$field};
         }
     }
     $data = array('app' => $app);
     $returncode = ResponseCode::OK;
     return $data;
 }
Example #2
0
 public function createFromITunesScraper($appinfo, $iconsPreSaved = false)
 {
     $bean = new ApplicationBean();
     $bean->itunes_id = $appinfo->getITunesID();
     $bean->name = $appinfo->getName();
     $bean->releasedate = $appinfo->getReleaseDate();
     $bean->seller = $appinfo->getSeller();
     $bean->company = $appinfo->getCompany() ?: $bean->seller;
     $bean->size = $appinfo->getSize();
     $bean->price = $appinfo->getPrice();
     $bean->description = $appinfo->getDescription();
     $bean->languages = $appinfo->getLanguages();
     $bean->requirements = $appinfo->getRequirements();
     $smallicon = $appinfo->getITunesID() . 'icon-57x57.png';
     $bigicon = $appinfo->getITunesID() . 'icon-100x100.png';
     if ($iconsPreSaved || $this->saveIconsLocally($appinfo->getIconUrlPNG(), $smallicon, $bigicon)) {
         $bean->smallicon_url = '%BASE_URL%/appimages/icons/' . $smallicon;
         $bean->bigicon_url = '%BASE_URL%/appimages/icons/' . $bigicon;
     }
     $bean->set('date_added', 'NOW()', true);
     $bean->set('last_updated', 'NOW()', true);
     $catname = $appinfo->getCategory() ?: 'Unknown';
     $acm = AppCategoryModel::getInstance();
     $cat = $acm->getByName($catname);
     if (!$cat) {
         $acm->create($catname);
         if (!($cat = $acm->getByName($catname))) {
             return false;
         }
     }
     $bean->category_id = $cat->id;
     try {
         $bean->insert();
     } catch (QueryFailedException $e) {
         return false;
     }
     $shots = $appinfo->getScreenshots();
     if ($shots) {
         if (!($bean = $this->getDetailsByITunesID($appinfo->getITunesID(), false))) {
             return false;
         }
         $sm = ScreenshotModel::getInstance();
         $sm->setScreenshots($bean->id, $bean->itunes_id, $shots);
     }
     $this->indexName($bean->name, $bean->id);
     $this->cm->clearGroup('applist');
     return true;
 }