Example #1
0
 public static function action_getList($args, &$returncode, &$profile, &$auth = false, $format = false)
 {
     if ($auth) {
         $returncode = ResponseCode::BAD_REQUEST;
         return false;
     }
     if (!$profile->perm_app_getlist) {
         $returncode = ResponseCode::ACTION_NOT_ALLOWED;
         return false;
     }
     $maxResults = isset($args->max_results) && $args->max_results > 0 && $args->max_results <= 60 ? (int) $args->max_results : 15;
     $startWith = isset($args->start_result) ? (int) $args->start_result : 1;
     $showTotal = isset($args->show_total_results) ? $args->show_total_results == 1 : false;
     $sort = isset($args->sort_by) ? $args->sort_by : 'relevance';
     $fields = isset($args->fields) && is_array($args->fields) ? $args->fields : array();
     $cat = isset($args->filter->category) ? (int) $args->filter->category : 0;
     $filter = isset($args->filter->text) ? $args->filter->text : false;
     $app_ids = isset($args->filter->app_id) ? $args->filter->app_id : false;
     $itunes_ids = isset($args->filter->itunes_id) ? $args->filter->itunes_id : false;
     $am = ApplicationModel::getInstance();
     $results = $am->getAppListCached($maxResults, false, $sort, $cat, $filter, $app_ids, $itunes_ids, $startWith);
     $legal = $profile->allowed_app_fields;
     $realfields = ShortAppBean::getFields();
     $apps = array();
     foreach ($results as $result) {
         $i = count($apps);
         $apps[$i]['id'] = $result->id;
         foreach ($fields as $field) {
             if ($field != 'id' && in_array($field, $realfields) && (in_array($field, $legal) || $legal[0] == 'ALL')) {
                 $apps[$i][$field] = $result->{$field};
             }
         }
     }
     $data = array('apps' => $apps);
     if ($showTotal) {
         $total = $am->getResultCountCached($cat, $filter, $app_ids, $itunes_ids);
         $data['total_results'] = $total;
     }
     $returncode = ResponseCode::OK;
     return $data;
 }
Example #2
0
header("Content-type: text/xml; charset=utf-8");
// Constants
$PERPAGE = 15;
// Get the vars
$sort = isset($_GET['sort']) ? $_GET['sort'] : 'newvers';
$cat = isset($_GET['cat']) ? $_GET['cat'] : 0;
$page = isset($_GET['page']) ? $_GET['page'] : 1;
if (isset($_POST['filter'])) {
    $_GET['filter'] = $_POST['filter'];
}
$filter = isset($_GET['filter']) && !Config::getVal('general', 'disable_search') ? trim($_GET['filter']) : false;
if ($filter) {
    $sort = "relevance";
}
// Get the apps
$am = ApplicationModel::getInstance();
$apps = $am->getAppListCached($PERPAGE, $page, $sort, $cat, $filter);
$total = $am->getResultCountCached($cat, $filter);
$curshowing = $page * $PERPAGE;
$numNextPage = $total - $curshowing;
if ($numNextPage <= 0) {
    $numNextPage = false;
} else {
    if ($numNextPage > $PERPAGE) {
        $numNextPage = $PERPAGE;
    }
}
// Output
$cdata = '';
if (!isset($_GET['page'])) {
    $cdata .= '<ul class="iArrow iShop">' . "\n";
Example #3
0
 public function submit($itunes_id, $version, $cracker, $links, $userBean, $submittedFrom = 'Web', $ignoreUserPermissions = false)
 {
     if (!$userBean->getPermission('submit_links_existing_apps') && !$ignoreUserPermissions) {
         return self::SUBMIT_FAIL_USER_CANNOT_SUBMIT_LINKS;
     }
     if (($version = trim($version)) == '') {
         $version = 'unknown';
     }
     try {
         $appinfo = new AppStoreScraper((int) $itunes_id);
     } catch (AppNotFoundException $e) {
         return self::SUBMIT_FAIL_APP_NOT_FOUND;
     } catch (TimeoutException $e) {
         return self::SUBMIT_FAIL_ITUNES_TIMEOUT;
     }
     $am = ApplicationModel::getInstance();
     $app = $am->getDetailsByITunesID($itunes_id, false);
     if (!$app) {
         if (!$userBean->getPermission('submit_new_itunes_apps') && !$ignoreUserPermissions) {
             return self::SUBMIT_FAIL_USER_CANNOT_SUBMIT_NEW_APP;
         }
         if (!$userBean->getPermission('submit_free_itunes_apps') && strtolower($appinfo->getPrice()) == 'free' && !$ignoreUserPermissions) {
             return self::SUBMIT_FAIL_USER_CANNOT_SUBMIT_FREE_APP;
         }
         if (!$am->createFromITunesScraper($appinfo)) {
             return self::SUBMIT_FAIL_UNKNOWN_ERROR;
         }
         if (!($app = $am->getDetailsByITunesID($itunes_id, false))) {
             return self::SUBMIT_FAIL_UNKNOWN_ERROR;
         }
         $newapp = true;
     } else {
         $newapp = false;
     }
     $avm = AppVersionModel::getInstance();
     $verBean = $avm->getByAppID($app->id, $version);
     if (!$verBean) {
         $testVersion = trim(preg_replace('/(?i)\\(iP\\w+ OS 3\\S+ Tested\\)/', '', $appinfo->getVersion()));
         if (!$userBean->getPermission('submit_unknown_app_versions') && !$ignoreUserPermissions && $testVersion != $version) {
             return self::SUBMIT_FAIL_USER_CANNOT_SUBMIT_NEW_VERSION;
         }
         if (!$avm->create($app->id, $version, $appinfo->getVersionInfo())) {
             return self::SUBMIT_FAIL_UNKNOWN_ERROR;
         }
         if (!($verBean = $avm->getByAppID($app->id, $version))) {
             return self::SUBMIT_FAIL_UNKNOWN_ERROR;
         }
         $newver = true;
     } else {
         $newver = false;
     }
     $verBean = $verBean[0];
     $vers = $avm->getByAppID($app->id, false, 1);
     $updated = false;
     if (is_null($app->latest_version) || $app->latest_version == '' || $verBean->id != $vers[0]->id || $app->latest_version != $verBean->version) {
         $app->latest_version = $version;
         $app->latest_version_first_cracker = $cracker;
         $app->set('latest_version_added', 'NOW()', true);
         try {
             $app->update();
         } catch (QueryFailedException $e) {
             return self::SUBMIT_FAIL_UNKNOWN_ERROR;
         }
         $updated = true;
     }
     $submitLinks = array();
     $ulinks = $this->getUniqueURLs($links);
     foreach ($ulinks as $ulink) {
         if (substr(strtolower($ulink), 0, 7) != 'http://') {
             $ulink = "http://" . $ulink;
         }
         $parsed_url = @parse_url($ulink);
         if ($parsed_url) {
             $domain = strtolower($parsed_url['host']);
             while (preg_match('/\\..+\\./', $domain)) {
                 $domain = substr($domain, strpos($domain, '.') + 1);
             }
             $legaldomains = Config::getVal('domains', 'allowed', false);
             if (!preg_match('/[\\<\\>]/', $ulink) && (!$legaldomains || in_array($domain, $legaldomains))) {
                 $submitLinks[] = $ulink;
             }
         }
     }
     if (count($submitLinks) == 0) {
         return self::SUBMIT_FAIL_NO_VALID_LINKS;
     }
     $bean = new AppLinkBean();
     $bean->app_id = $app->id;
     $bean->version_id = $verBean->id;
     $bean->filetype = 2;
     $bean->cracker = $cracker;
     $bean->set('date_added', 'NOW()', true);
     $bean->set('last_updated', 'NOW()', true);
     $bean->submitter_id = $userBean->id;
     $bean->submitter_ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '';
     $bean->submitted_from = $submittedFrom;
     foreach ($submitLinks as $link) {
         $bean->url = $link;
         try {
             $bean->insert();
         } catch (QueryFailedException $e) {
             return self::SUBMIT_FAIL_UNKNOWN_ERROR;
         }
     }
     $this->cm->clear('alm_getByAppID_' . $app->id . '_1');
     $this->cm->clear('alm_getByAppID_' . $app->id . '_0');
     $this->cm->clear('alm_getByAppID_' . $app->id);
     if (!$newapp && ($updated || Config::getVal('general', 'update_app_every_submit') == '1')) {
         $am->updateFromITunesScraper($app->id, $appinfo);
     }
     if (count($submitLinks) != count($links)) {
         return self::SUBMIT_PARTIAL_OK;
     }
     return self::SUBMIT_OK;
 }