/**
  * Get all available apps in a category
  *
  * @param string $category
  * @param bool $includeUpdateInfo Should we check whether there is an update
  *                                in the app store?
  * @return array
  */
 public function listApps($category = '', $includeUpdateInfo = true)
 {
     $category = $this->getCategory($category);
     $cacheName = 'listApps-' . $category . '-' . (int) $includeUpdateInfo;
     if (!is_null($this->cache->get($cacheName))) {
         $apps = $this->cache->get($cacheName);
     } else {
         switch ($category) {
             // installed apps
             case 0:
                 $apps = $this->getInstalledApps($includeUpdateInfo);
                 usort($apps, function ($a, $b) {
                     $a = (string) $a['name'];
                     $b = (string) $b['name'];
                     if ($a === $b) {
                         return 0;
                     }
                     return $a < $b ? -1 : 1;
                 });
                 $version = \OCP\Util::getVersion();
                 foreach ($apps as $key => $app) {
                     if (!array_key_exists('level', $app) && array_key_exists('ocsid', $app)) {
                         $remoteAppEntry = $this->ocsClient->getApplication($app['ocsid'], $version);
                         if (is_array($remoteAppEntry) && array_key_exists('level', $remoteAppEntry)) {
                             $apps[$key]['level'] = $remoteAppEntry['level'];
                         }
                     }
                 }
                 break;
                 // not-installed apps
             // not-installed apps
             case 1:
                 $apps = \OC_App::listAllApps(true, $includeUpdateInfo, $this->ocsClient);
                 $apps = array_filter($apps, function ($app) {
                     return !$app['active'];
                 });
                 $version = \OCP\Util::getVersion();
                 foreach ($apps as $key => $app) {
                     if (!array_key_exists('level', $app) && array_key_exists('ocsid', $app)) {
                         $remoteAppEntry = $this->ocsClient->getApplication($app['ocsid'], $version);
                         if (is_array($remoteAppEntry) && array_key_exists('level', $remoteAppEntry)) {
                             $apps[$key]['level'] = $remoteAppEntry['level'];
                         }
                     }
                 }
                 usort($apps, function ($a, $b) {
                     $a = (string) $a['name'];
                     $b = (string) $b['name'];
                     if ($a === $b) {
                         return 0;
                     }
                     return $a < $b ? -1 : 1;
                 });
                 break;
             default:
                 $filter = $this->config->getSystemValue('appstore.experimental.enabled', false) ? 'all' : 'approved';
                 $apps = \OC_App::getAppstoreApps($filter, $category, $this->ocsClient);
                 if (!$apps) {
                     $apps = array();
                 } else {
                     // don't list installed apps
                     $installedApps = $this->getInstalledApps(false);
                     $installedApps = array_map(function ($app) {
                         if (isset($app['ocsid'])) {
                             return $app['ocsid'];
                         }
                         return $app['id'];
                     }, $installedApps);
                     $apps = array_filter($apps, function ($app) use($installedApps) {
                         return !in_array($app['id'], $installedApps);
                     });
                     // show tooltip if app is downloaded from remote server
                     $inactiveApps = $this->getInactiveApps();
                     foreach ($apps as &$app) {
                         $app['needsDownload'] = !in_array($app['id'], $inactiveApps);
                     }
                 }
                 // sort by score
                 usort($apps, function ($a, $b) {
                     $a = (int) $a['score'];
                     $b = (int) $b['score'];
                     if ($a === $b) {
                         return 0;
                     }
                     return $a > $b ? -1 : 1;
                 });
                 break;
         }
     }
     // fix groups to be an array
     $dependencyAnalyzer = new DependencyAnalyzer(new Platform($this->config), $this->l10n);
     $apps = array_map(function ($app) use($dependencyAnalyzer) {
         // fix groups
         $groups = array();
         if (is_string($app['groups'])) {
             $groups = json_decode($app['groups']);
         }
         $app['groups'] = $groups;
         $app['canUnInstall'] = !$app['active'] && $app['removable'];
         // fix licence vs license
         if (isset($app['license']) && !isset($app['licence'])) {
             $app['licence'] = $app['license'];
         }
         // analyse dependencies
         $missing = $dependencyAnalyzer->analyze($app);
         $app['canInstall'] = empty($missing);
         $app['missingDependencies'] = $missing;
         $app['missingMinOwnCloudVersion'] = !isset($app['dependencies']['owncloud']['@attributes']['min-version']);
         $app['missingMaxOwnCloudVersion'] = !isset($app['dependencies']['owncloud']['@attributes']['max-version']);
         return $app;
     }, $apps);
     $this->cache->set($cacheName, $apps, 300);
     return ['apps' => $apps, 'status' => 'success'];
 }
예제 #2
0
 /**
  * Lists all apps, this is used in apps.php
  * @return array
  */
 public static function listAllApps($onlyLocal = false)
 {
     $installedApps = OC_App::getAllApps();
     //TODO which apps do we want to blacklist and how do we integrate
     // blacklisting with the multi apps folder feature?
     $blacklist = array('files');
     //we don't want to show configuration for these
     $appList = array();
     $l = \OC::$server->getL10N('core');
     foreach ($installedApps as $app) {
         if (array_search($app, $blacklist) === false) {
             $info = OC_App::getAppInfo($app);
             if (!isset($info['name'])) {
                 OC_Log::write('core', 'App id "' . $app . '" has no name in appinfo', OC_Log::ERROR);
                 continue;
             }
             $enabled = OC_Appconfig::getValue($app, 'enabled', 'no');
             $info['groups'] = null;
             if ($enabled === 'yes') {
                 $active = true;
             } else {
                 if ($enabled === 'no') {
                     $active = false;
                 } else {
                     $active = true;
                     $info['groups'] = $enabled;
                 }
             }
             $info['active'] = $active;
             if (isset($info['shipped']) and $info['shipped'] == 'true') {
                 $info['internal'] = true;
                 $info['internallabel'] = (string) $l->t('Recommended');
                 $info['internalclass'] = 'recommendedapp';
                 $info['removable'] = false;
             } else {
                 $info['internal'] = false;
                 $info['removable'] = true;
             }
             $info['update'] = OC_Installer::isUpdateAvailable($app);
             $appIcon = self::getAppPath($app) . '/img/' . $app . '.svg';
             if (file_exists($appIcon)) {
                 $info['preview'] = OC_Helper::imagePath($app, $app . '.svg');
                 $info['previewAsIcon'] = true;
             } else {
                 $appIcon = self::getAppPath($app) . '/img/app.svg';
                 if (file_exists($appIcon)) {
                     $info['preview'] = OC_Helper::imagePath($app, 'app.svg');
                     $info['previewAsIcon'] = true;
                 }
             }
             $info['version'] = OC_App::getAppVersion($app);
             $appList[] = $info;
         }
     }
     if ($onlyLocal) {
         $remoteApps = array();
     } else {
         $remoteApps = OC_App::getAppstoreApps();
     }
     if ($remoteApps) {
         // Remove duplicates
         foreach ($appList as $app) {
             foreach ($remoteApps as $key => $remote) {
                 if ($app['name'] === $remote['name'] || isset($app['ocsid']) && $app['ocsid'] === $remote['id']) {
                     unset($remoteApps[$key]);
                 }
             }
         }
         $combinedApps = array_merge($appList, $remoteApps);
     } else {
         $combinedApps = $appList;
     }
     // bring the apps into the right order with a custom sort function
     usort($combinedApps, function ($a, $b) {
         // priority 1: active
         if ($a['active'] != $b['active']) {
             return $b['active'] - $a['active'];
         }
         // priority 2: shipped
         $aShipped = array_key_exists('shipped', $a) && $a['shipped'] === 'true' ? 1 : 0;
         $bShipped = array_key_exists('shipped', $b) && $b['shipped'] === 'true' ? 1 : 0;
         if ($aShipped !== $bShipped) {
             return $bShipped - $aShipped;
         }
         // priority 3: recommended
         $internalClassA = isset($a['internalclass']) ? $a['internalclass'] : '';
         $internalClassB = isset($b['internalclass']) ? $b['internalclass'] : '';
         if ($internalClassA != $internalClassB) {
             $aTemp = $internalClassA == 'recommendedapp' ? 1 : 0;
             $bTemp = $internalClassB == 'recommendedapp' ? 1 : 0;
             return $bTemp - $aTemp;
         }
         // priority 4: alphabetical
         return strcasecmp($a['name'], $b['name']);
     });
     return $combinedApps;
 }
 /**
  * Get all available apps in a category
  *
  * @param int $category
  * @return array
  */
 public function listApps($category = 0)
 {
     if (!is_null($this->cache->get('listApps-' . $category))) {
         $apps = $this->cache->get('listApps-' . $category);
     } else {
         switch ($category) {
             // installed apps
             case 0:
                 $apps = $this->getInstalledApps();
                 usort($apps, function ($a, $b) {
                     $a = (string) $a['name'];
                     $b = (string) $b['name'];
                     if ($a === $b) {
                         return 0;
                     }
                     return $a < $b ? -1 : 1;
                 });
                 break;
                 // not-installed apps
             // not-installed apps
             case 1:
                 $apps = \OC_App::listAllApps(true);
                 $apps = array_filter($apps, function ($app) {
                     return !$app['active'];
                 });
                 usort($apps, function ($a, $b) {
                     $a = (string) $a['name'];
                     $b = (string) $b['name'];
                     if ($a === $b) {
                         return 0;
                     }
                     return $a < $b ? -1 : 1;
                 });
                 break;
             default:
                 $filter = $this->config->getSystemValue('appstore.experimental.enabled', false) ? 'all' : 'approved';
                 $apps = \OC_App::getAppstoreApps($filter, $category);
                 if (!$apps) {
                     $apps = array();
                 } else {
                     // don't list installed apps
                     $installedApps = $this->getInstalledApps();
                     $installedApps = array_map(function ($app) {
                         if (isset($app['ocsid'])) {
                             return $app['ocsid'];
                         }
                         return $app['id'];
                     }, $installedApps);
                     $apps = array_filter($apps, function ($app) use($installedApps) {
                         return !in_array($app['id'], $installedApps);
                     });
                 }
                 // sort by score
                 usort($apps, function ($a, $b) {
                     $a = (int) $a['score'];
                     $b = (int) $b['score'];
                     if ($a === $b) {
                         return 0;
                     }
                     return $a > $b ? -1 : 1;
                 });
                 break;
         }
     }
     // fix groups to be an array
     $dependencyAnalyzer = new DependencyAnalyzer(new Platform($this->config), $this->l10n);
     $apps = array_map(function ($app) use($dependencyAnalyzer) {
         // fix groups
         $groups = array();
         if (is_string($app['groups'])) {
             $groups = json_decode($app['groups']);
         }
         $app['groups'] = $groups;
         $app['canUnInstall'] = !$app['active'] && $app['removable'];
         // fix licence vs license
         if (isset($app['license']) && !isset($app['licence'])) {
             $app['licence'] = $app['license'];
         }
         // analyse dependencies
         $missing = $dependencyAnalyzer->analyze($app);
         $app['canInstall'] = empty($missing);
         $app['missingDependencies'] = $missing;
         return $app;
     }, $apps);
     $this->cache->set('listApps-' . $category, $apps, 300);
     return ['apps' => $apps, 'status' => 'success'];
 }
예제 #4
0
파일: app.php 프로젝트: pierreozoux/core
 /**
  * List all apps, this is used in apps.php
  *
  * @param bool $onlyLocal
  * @param bool $includeUpdateInfo Should we check whether there is an update
  *                                in the app store?
  * @param OCSClient $ocsClient
  * @return array
  */
 public static function listAllApps($onlyLocal = false, $includeUpdateInfo = true, OCSClient $ocsClient)
 {
     $installedApps = OC_App::getAllApps();
     //TODO which apps do we want to blacklist and how do we integrate
     // blacklisting with the multi apps folder feature?
     //we don't want to show configuration for these
     $blacklist = \OC::$server->getAppManager()->getAlwaysEnabledApps();
     $appList = array();
     foreach ($installedApps as $app) {
         if (array_search($app, $blacklist) === false) {
             $info = OC_App::getAppInfo($app);
             if (!isset($info['name'])) {
                 \OCP\Util::writeLog('core', 'App id "' . $app . '" has no name in appinfo', \OCP\Util::ERROR);
                 continue;
             }
             $enabled = \OC::$server->getAppConfig()->getValue($app, 'enabled', 'no');
             $info['groups'] = null;
             if ($enabled === 'yes') {
                 $active = true;
             } else {
                 if ($enabled === 'no') {
                     $active = false;
                 } else {
                     $active = true;
                     $info['groups'] = $enabled;
                 }
             }
             $info['active'] = $active;
             if (self::isShipped($app)) {
                 $info['internal'] = true;
                 $info['level'] = self::officialApp;
                 $info['removable'] = false;
             } else {
                 $info['internal'] = false;
                 $info['removable'] = true;
             }
             $info['update'] = $includeUpdateInfo ? OC_Installer::isUpdateAvailable($app) : null;
             $appPath = self::getAppPath($app);
             if ($appPath !== false) {
                 $appIcon = $appPath . '/img/' . $app . '.svg';
                 if (file_exists($appIcon)) {
                     $info['preview'] = \OC::$server->getURLGenerator()->imagePath($app, $app . '.svg');
                     $info['previewAsIcon'] = true;
                 } else {
                     $appIcon = $appPath . '/img/app.svg';
                     if (file_exists($appIcon)) {
                         $info['preview'] = \OC::$server->getURLGenerator()->imagePath($app, 'app.svg');
                         $info['previewAsIcon'] = true;
                     }
                 }
             }
             $info['version'] = OC_App::getAppVersion($app);
             $appList[] = $info;
         }
     }
     if ($onlyLocal) {
         $remoteApps = [];
     } else {
         $remoteApps = OC_App::getAppstoreApps('approved', null, $ocsClient);
     }
     if ($remoteApps) {
         // Remove duplicates
         foreach ($appList as $app) {
             foreach ($remoteApps as $key => $remote) {
                 if ($app['name'] === $remote['name'] || isset($app['ocsid']) && $app['ocsid'] === $remote['id']) {
                     unset($remoteApps[$key]);
                 }
             }
         }
         $combinedApps = array_merge($appList, $remoteApps);
     } else {
         $combinedApps = $appList;
     }
     return $combinedApps;
 }
예제 #5
0
파일: apps.php 프로젝트: ryanshoover/core
            $active = false;
        }
        $info['active'] = $active;
        if (isset($info['shipped']) and $info['shipped'] == 'true') {
            $info['internal'] = true;
            $info['internallabel'] = 'Internal App';
        } else {
            $info['internal'] = false;
            $info['internallabel'] = '3rd Party App';
        }
        $info['preview'] = OC_Helper::imagePath('settings', 'trans.png');
        $info['version'] = OC_App::getAppVersion($app);
        $appList[] = $info;
    }
}
$remoteApps = OC_App::getAppstoreApps();
if ($remoteApps) {
    // Remove duplicates
    foreach ($appList as $app) {
        foreach ($remoteApps as $key => $remote) {
            if ($app['name'] == $remote['name']) {
                unset($remoteApps[$key]);
            }
        }
    }
    $combinedApps = array_merge($appList, $remoteApps);
} else {
    $combinedApps = $appList;
}
function app_sort($a, $b)
{
예제 #6
0
파일: app.php 프로젝트: hjimmy/owncloud
 /**
  * @brief: Lists all apps, this is used in apps.php
  * @return array
  */
 public static function listAllApps()
 {
     $installedApps = OC_App::getAllApps();
     //TODO which apps do we want to blacklist and how do we integrate
     // blacklisting with the multi apps folder feature?
     $blacklist = array('files');
     //we dont want to show configuration for these
     $appList = array();
     foreach ($installedApps as $app) {
         if (array_search($app, $blacklist) === false) {
             $info = OC_App::getAppInfo($app);
             if (!isset($info['name'])) {
                 OC_Log::write('core', 'App id "' . $app . '" has no name in appinfo', OC_Log::ERROR);
                 continue;
             }
             if (OC_Appconfig::getValue($app, 'enabled', 'no') == 'yes') {
                 $active = true;
             } else {
                 $active = false;
             }
             $info['active'] = $active;
             if (isset($info['shipped']) and $info['shipped'] == 'true') {
                 $info['internal'] = true;
                 $info['internallabel'] = 'Internal App';
                 $info['internalclass'] = '';
                 $info['update'] = false;
             } else {
                 $info['internal'] = false;
                 $info['internallabel'] = '3rd Party';
                 $info['internalclass'] = 'externalapp';
                 $info['update'] = OC_Installer::isUpdateAvailable($app);
             }
             $info['preview'] = OC_Helper::imagePath('settings', 'trans.png');
             $info['version'] = OC_App::getAppVersion($app);
             $appList[] = $info;
         }
     }
     $remoteApps = OC_App::getAppstoreApps();
     if ($remoteApps) {
         // Remove duplicates
         foreach ($appList as $app) {
             foreach ($remoteApps as $key => $remote) {
                 if ($app['name'] == $remote['name']) {
                     unset($remoteApps[$key]);
                 }
             }
         }
         $combinedApps = array_merge($appList, $remoteApps);
     } else {
         $combinedApps = $appList;
     }
     // bring the apps into the right order with a custom sort funtion
     usort($combinedApps, '\\OC_App::customSort');
     return $combinedApps;
 }
예제 #7
0
 /**
  * List all apps, this is used in apps.php
  *
  * @param bool $onlyLocal
  * @return array
  */
 public static function listAllApps($onlyLocal = false)
 {
     $installedApps = OC_App::getAllApps();
     //TODO which apps do we want to blacklist and how do we integrate
     // blacklisting with the multi apps folder feature?
     $blacklist = array('files');
     //we don't want to show configuration for these
     $appList = array();
     $l = \OC::$server->getL10N('core');
     foreach ($installedApps as $app) {
         if (array_search($app, $blacklist) === false) {
             $info = OC_App::getAppInfo($app);
             if (!isset($info['name'])) {
                 OC_Log::write('core', 'App id "' . $app . '" has no name in appinfo', OC_Log::ERROR);
                 continue;
             }
             $enabled = OC_Appconfig::getValue($app, 'enabled', 'no');
             $info['groups'] = null;
             if ($enabled === 'yes') {
                 $active = true;
             } else {
                 if ($enabled === 'no') {
                     $active = false;
                 } else {
                     $active = true;
                     $info['groups'] = $enabled;
                 }
             }
             $info['active'] = $active;
             if (isset($info['shipped']) and $info['shipped'] == 'true') {
                 $info['internal'] = true;
                 $info['level'] = self::officialApp;
                 $info['removable'] = false;
             } else {
                 $info['internal'] = false;
                 $info['removable'] = true;
             }
             $info['update'] = OC_Installer::isUpdateAvailable($app);
             $appIcon = self::getAppPath($app) . '/img/' . $app . '.svg';
             if (file_exists($appIcon)) {
                 $info['preview'] = OC_Helper::imagePath($app, $app . '.svg');
                 $info['previewAsIcon'] = true;
             } else {
                 $appIcon = self::getAppPath($app) . '/img/app.svg';
                 if (file_exists($appIcon)) {
                     $info['preview'] = OC_Helper::imagePath($app, 'app.svg');
                     $info['previewAsIcon'] = true;
                 }
             }
             $info['version'] = OC_App::getAppVersion($app);
             $appList[] = $info;
         }
     }
     if ($onlyLocal) {
         $remoteApps = [];
     } else {
         $remoteApps = OC_App::getAppstoreApps();
     }
     if ($remoteApps) {
         // Remove duplicates
         foreach ($appList as $app) {
             foreach ($remoteApps as $key => $remote) {
                 if ($app['name'] === $remote['name'] || isset($app['ocsid']) && $app['ocsid'] === $remote['id']) {
                     unset($remoteApps[$key]);
                 }
             }
         }
         $combinedApps = array_merge($appList, $remoteApps);
     } else {
         $combinedApps = $appList;
     }
     return $combinedApps;
 }
예제 #8
0
 /**
  * Get all available categories
  * @param int $category
  * @return array
  */
 public function listApps($category = 0)
 {
     $apps = array();
     switch ($category) {
         // installed apps
         case 0:
             $apps = \OC_App::listAllApps(true);
             $apps = array_filter($apps, function ($app) {
                 return $app['active'];
             });
             break;
             // not-installed apps
         // not-installed apps
         case 1:
             $apps = \OC_App::listAllApps(true);
             $apps = array_filter($apps, function ($app) {
                 return !$app['active'];
             });
             break;
         default:
             if ($category === 2) {
                 $apps = \OC_App::getAppstoreApps('approved');
                 $apps = array_filter($apps, function ($app) {
                     return isset($app['internalclass']) && $app['internalclass'] === 'recommendedapp';
                 });
             } else {
                 $apps = \OC_App::getAppstoreApps('approved', $category);
             }
             if (!$apps) {
                 $apps = array();
             }
             usort($apps, function ($a, $b) {
                 $a = (int) $a['score'];
                 $b = (int) $b['score'];
                 if ($a === $b) {
                     return 0;
                 }
                 return $a > $b ? -1 : 1;
             });
             break;
     }
     // fix groups to be an array
     $apps = array_map(function ($app) {
         $groups = array();
         if (is_string($app['groups'])) {
             $groups = json_decode($app['groups']);
         }
         $app['groups'] = $groups;
         $app['canUnInstall'] = !$app['active'] && $app['removable'];
         return $app;
     }, $apps);
     return array('apps' => $apps, 'status' => 'success');
 }
예제 #9
0
 /**
  * Get all available categories
  * @param int $category
  * @return array
  */
 public function listApps($category = 0)
 {
     if (!is_null($this->cache->get('listApps-' . $category))) {
         $apps = $this->cache->get('listApps-' . $category);
     } else {
         switch ($category) {
             // installed apps
             case 0:
                 $apps = \OC_App::listAllApps(true);
                 $apps = array_filter($apps, function ($app) {
                     return $app['active'];
                 });
                 break;
                 // not-installed apps
             // not-installed apps
             case 1:
                 $apps = \OC_App::listAllApps(true);
                 $apps = array_filter($apps, function ($app) {
                     return !$app['active'];
                 });
                 break;
             default:
                 if ($category === 2) {
                     $apps = \OC_App::getAppstoreApps('approved');
                     $apps = array_filter($apps, function ($app) {
                         return isset($app['internalclass']) && $app['internalclass'] === 'recommendedapp';
                     });
                 } else {
                     $apps = \OC_App::getAppstoreApps('approved', $category);
                 }
                 if (!$apps) {
                     $apps = array();
                 }
                 usort($apps, function ($a, $b) {
                     $a = (int) $a['score'];
                     $b = (int) $b['score'];
                     if ($a === $b) {
                         return 0;
                     }
                     return $a > $b ? -1 : 1;
                 });
                 break;
         }
     }
     // fix groups to be an array
     $dependencyAnalyzer = new DependencyAnalyzer(new Platform($this->config), $this->l10n);
     $apps = array_map(function ($app) use($dependencyAnalyzer) {
         // fix groups
         $groups = array();
         if (is_string($app['groups'])) {
             $groups = json_decode($app['groups']);
         }
         $app['groups'] = $groups;
         $app['canUnInstall'] = !$app['active'] && $app['removable'];
         // fix licence vs license
         if (isset($app['license']) && !isset($app['licence'])) {
             $app['licence'] = $app['license'];
         }
         // analyse dependencies
         $missing = $dependencyAnalyzer->analyze($app);
         $app['canInstall'] = empty($missing);
         $app['missingDependencies'] = $missing;
         return $app;
     }, $apps);
     $this->cache->set('listApps-' . $category, $apps, 300);
     return ['apps' => $apps, 'status' => 'success'];
 }