/** * Get all available categories * @return array */ public function listCategories() { $categories = array(array('id' => 0, 'displayName' => (string) $this->l10n->t('Enabled')), array('id' => 1, 'displayName' => (string) $this->l10n->t('Not enabled'))); if ($this->config->getSystemValue('appstoreenabled', true)) { $categories[] = array('id' => 2, 'displayName' => (string) $this->l10n->t('Recommended')); // apps from external repo via OCS $ocs = \OC_OCSClient::getCategories(); foreach ($ocs as $k => $v) { $categories[] = array('id' => $k, 'displayName' => str_replace('ownCloud ', '', $v)); } } $categories['status'] = 'success'; return $categories; }
/** * @param mixed $app * @return bool * @throws Exception if app is not compatible with this version of ownCloud * @throws Exception if no app-name was specified */ public static function installApp($app) { $l = \OC::$server->getL10N('core'); $config = \OC::$server->getConfig(); $appData = OC_OCSClient::getApplication($app); // check if app is a shipped app or not. OCS apps have an integer as id, shipped apps use a string if (!is_numeric($app)) { $shippedVersion = self::getAppVersion($app); if ($appData && version_compare($shippedVersion, $appData['version'], '<')) { $app = self::downloadApp($app); } else { $app = OC_Installer::installShippedApp($app); } } else { // Maybe the app is already installed - compare the version in this // case and use the local already installed one. // FIXME: This is a horrible hack. I feel sad. The god of code cleanness may forgive me. $internalAppId = self::getInternalAppIdByOcs($app); if ($internalAppId !== false) { if ($appData && version_compare(\OC_App::getAppVersion($internalAppId), $appData['version'], '<')) { $app = self::downloadApp($app); } else { self::enable($internalAppId); $app = $internalAppId; } } else { $app = self::downloadApp($app); } } if ($app !== false) { // check if the app is compatible with this version of ownCloud $info = self::getAppInfo($app); $version = OC_Util::getVersion(); if (!self::isAppCompatible($version, $info)) { throw new \Exception($l->t('App \\"%s\\" can\'t be installed because it is not compatible with this version of ownCloud.', array($info['name']))); } // check for required dependencies $dependencyAnalyzer = new DependencyAnalyzer(new Platform($config), $l); $missing = $dependencyAnalyzer->analyze($app); if (!empty($missing)) { $missingMsg = join(PHP_EOL, $missing); throw new \Exception($l->t('App \\"%s\\" cannot be installed because the following dependencies are not fulfilled: %s', array($info['name'], $missingMsg))); } $config->setAppValue($app, 'enabled', 'yes'); if (isset($appData['id'])) { $config->setAppValue($app, 'ocsid', $appData['id']); } \OC_Hook::emit('OC_App', 'post_enable', array('app' => $app)); } else { throw new \Exception($l->t("No app name specified")); } return $app; }
/** * Get the download url for an application from the OCS server * @return array|null an array of application data or null * * This function returns an download url for an applications from the OCS server * @param string $id * @param integer $item * @param array $targetVersion The target ownCloud version */ public static function getApplicationDownload($id, $item, array $targetVersion) { if (OC_Config::getValue('appstoreenabled', true) == false) { return null; } $url = OC_OCSClient::getAppStoreURL() . '/content/download/' . urlencode($id) . '/' . urlencode($item); $url .= '?version=' . implode('x', $targetVersion); $xml = OC_OCSClient::getOCSresponse($url); if ($xml == false) { OC_Log::write('core', 'Unable to parse OCS content', OC_Log::FATAL); return null; } $loadEntities = libxml_disable_entity_loader(true); $data = simplexml_load_string($xml); libxml_disable_entity_loader($loadEntities); $tmp = $data->data->content; $app = array(); if (isset($tmp->downloadlink)) { $app['downloadlink'] = $tmp->downloadlink; } else { $app['downloadlink'] = ''; } return $app; }
/** * Check if an update for the app is available * @param string $app * @return string|false false or the version number of the update * * The function will check if an update for a version is available */ public static function isUpdateAvailable($app) { static $isInstanceReadyForUpdates = null; if ($isInstanceReadyForUpdates === null) { $installPath = OC_App::getInstallPath(); if ($installPath === false || $installPath === null) { $isInstanceReadyForUpdates = false; } else { $isInstanceReadyForUpdates = true; } } if ($isInstanceReadyForUpdates === false) { return false; } $ocsid = OC_Appconfig::getValue($app, 'ocsid', ''); if ($ocsid != '') { $ocsdata = OC_OCSClient::getApplication($ocsid); $ocsversion = (string) $ocsdata['version']; $currentversion = OC_App::getAppVersion($app); if (version_compare($ocsversion, $currentversion, '>')) { return $ocsversion; } else { return false; } } else { return false; } }
$l = OC_L10N::get('settings'); if (OC_Config::getValue('appstoreenabled', true) == false) { OCP\JSON::success(array('type' => 'external', 'data' => array())); } $enabledApps = OC_App::getEnabledApps(); if (is_null($enabledApps)) { OCP\JSON::error(array('data' => array('message' => $l->t('Unable to load list from App Store')))); } $apps = array(); // apps from external repo via OCS $catagoryNames = OC_OCSClient::getCategories(); if (is_array($catagoryNames)) { $categories = array_keys($catagoryNames); $page = 0; $filter = 'approved'; $externalApps = OC_OCSClient::getApplications($categories, $page, $filter); foreach ($externalApps as $app) { // show only external apps that aren't enabled yet $local = false; foreach ($enabledApps as $a) { if ($a == $app['name']) { $local = true; } } if (!$local) { if ($app['preview'] == '') { $pre = 'trans.png'; } else { $pre = $app['preview']; } $apps[] = array('name' => $app['name'], 'id' => $app['id'], 'active' => false, 'description' => $app['description'], 'author' => $app['personid'], 'license' => $app['license'], 'preview' => $pre, 'internal' => false, 'internallabel' => '3rd Party App');
/** * @brief: get a list of all apps on apps.owncloud.com * @return array, multi-dimensional array of apps. * Keys: id, name, type, typename, personid, license, detailpage, preview, changed, description */ public static function getAppstoreApps($filter = 'approved') { $categoryNames = OC_OCSClient::getCategories(\OC_Util::getVersion()); if (is_array($categoryNames)) { // Check that categories of apps were retrieved correctly if (!($categories = array_keys($categoryNames))) { return false; } $page = 0; $remoteApps = OC_OCSClient::getApplications($categories, $page, $filter, \OC_Util::getVersion()); $app1 = array(); $i = 0; foreach ($remoteApps as $app) { $app1[$i] = $app; $app1[$i]['author'] = $app['personid']; $app1[$i]['ocs_id'] = $app['id']; $app1[$i]['internal'] = $app1[$i]['active'] = 0; $app1[$i]['update'] = false; if ($app['label'] == 'recommended') { $app1[$i]['internallabel'] = 'Recommended'; $app1[$i]['internalclass'] = 'recommendedapp'; } else { $app1[$i]['internallabel'] = '3rd Party'; $app1[$i]['internalclass'] = 'externalapp'; } // rating img if ($app['score'] >= 0 and $app['score'] < 5) { $img = OC_Helper::imagePath("core", "rating/s1.png"); } elseif ($app['score'] >= 5 and $app['score'] < 15) { $img = OC_Helper::imagePath("core", "rating/s2.png"); } elseif ($app['score'] >= 15 and $app['score'] < 25) { $img = OC_Helper::imagePath("core", "rating/s3.png"); } elseif ($app['score'] >= 25 and $app['score'] < 35) { $img = OC_Helper::imagePath("core", "rating/s4.png"); } elseif ($app['score'] >= 35 and $app['score'] < 45) { $img = OC_Helper::imagePath("core", "rating/s5.png"); } elseif ($app['score'] >= 45 and $app['score'] < 55) { $img = OC_Helper::imagePath("core", "rating/s6.png"); } elseif ($app['score'] >= 55 and $app['score'] < 65) { $img = OC_Helper::imagePath("core", "rating/s7.png"); } elseif ($app['score'] >= 65 and $app['score'] < 75) { $img = OC_Helper::imagePath("core", "rating/s8.png"); } elseif ($app['score'] >= 75 and $app['score'] < 85) { $img = OC_Helper::imagePath("core", "rating/s9.png"); } elseif ($app['score'] >= 85 and $app['score'] < 95) { $img = OC_Helper::imagePath("core", "rating/s10.png"); } elseif ($app['score'] >= 95 and $app['score'] < 100) { $img = OC_Helper::imagePath("core", "rating/s11.png"); } $app1[$i]['score'] = '<img src="' . $img . '"> Score: ' . $app['score'] . '%'; $i++; } } if (empty($app1)) { return false; } else { return $app1; } }
<?php /** * Copyright (c) 2011, Frank Karlitschek karlitschek@kde.org * This file is licensed under the Affero General Public License version 3 or later. * See the COPYING-README file. */ require_once '../lib/base.php'; OC_Util::checkLoggedIn(); // Load the files we need OC_Util::addStyle("settings", "settings"); OC_App::setActiveNavigationEntry("help"); $pagesize = 7; if (isset($_GET['page'])) { $page = $_GET['page']; } else { $page = 0; } $kbe = OC_OCSClient::getKnownledgebaseEntries($page, $pagesize); $totalitems = $kbe['totalitems']; unset($kbe['totalitems']); $pagecount = ceil($totalitems / $pagesize); $tmpl = new OC_Template("settings", "help", "user"); $tmpl->assign("kbe", $kbe); $tmpl->assign("pagecount", $pagecount); $tmpl->assign("page", $page); $tmpl->printPage();
/** * @param mixed $app * @return bool * @throws Exception if app is not compatible with this version of ownCloud * @throws Exception if no app-name was specified */ public static function installApp($app) { $l = \OC::$server->getL10N('core'); $appData = OC_OCSClient::getApplication($app); // check if app is a shipped app or not. OCS apps have an integer as id, shipped apps use a string if (!is_numeric($app)) { $shippedVersion = self::getAppVersion($app); if ($appData && version_compare($shippedVersion, $appData['version'], '<')) { $app = self::downloadApp($app); } else { $app = OC_Installer::installShippedApp($app); } } else { $app = self::downloadApp($app); } if ($app !== false) { // check if the app is compatible with this version of ownCloud $info = self::getAppInfo($app); $version = OC_Util::getVersion(); if (!self::isAppCompatible($version, $info)) { throw new \Exception($l->t('App \\"%s\\" can\'t be installed because it is not compatible with this version of ownCloud.', array($info['name']))); } else { OC_Appconfig::setValue($app, 'enabled', 'yes'); if (isset($appData['id'])) { OC_Appconfig::setValue($app, 'ocsid', $appData['id']); } \OC_Hook::emit('OC_App', 'post_enable', array('app' => $app)); } } else { throw new \Exception($l->t("No app name specified")); } return $app; }
/** * @brief Get all the knowledgebase entries from the OCS server * @returns array with q and a data * * This function returns a list of all the knowledgebase entries from the OCS server */ public static function getKnownledgebaseEntries($page, $pagesize, $search = '') { if (OC_Config::getValue('knowledgebaseenabled', true) == false) { $kbe = array(); $kbe['totalitems'] = 0; return $kbe; } $p = (int) $page; $s = (int) $pagesize; if ($search != '') { $searchcmd = '&search=' . urlencode($search); } else { $searchcmd = ''; } $url = OC_OCSClient::getKBURL() . '/knowledgebase/data?type=150&page=' . $p . '&pagesize=' . $s . $searchcmd; $kbe = array(); $xml = @file_get_contents($url); if ($xml == FALSE) { OC_Log::write('core', 'Unable to parse knowledgebase content', OC_Log::FATAL); return NULL; } $data = simplexml_load_string($xml); $tmp = $data->data->content; for ($i = 0; $i < count($tmp); $i++) { $kb = array(); $kb['id'] = $tmp[$i]->id; $kb['name'] = $tmp[$i]->name; $kb['description'] = $tmp[$i]->description; $kb['answer'] = $tmp[$i]->answer; $kb['preview1'] = $tmp[$i]->smallpreviewpic1; $kb['detailpage'] = $tmp[$i]->detailpage; $kbe[] = $kb; } $total = $data->meta->totalitems; $kbe['totalitems'] = $total; return $kbe; }
/** * @brief Check if an update for the app is available * @param $name name of the application * @return boolean false or the version number of the update * * The function will check if an update for a version is available */ public static function isUpdateAvailable($app) { $ocsid = OC_Appconfig::getValue($app, 'ocsid', ''); if ($ocsid != '') { $ocsdata = OC_OCSClient::getApplication($ocsid, \OC_Util::getVersion()); $ocsversion = (string) $ocsdata['version']; $currentversion = OC_App::getAppVersion($app); if ($ocsversion != $currentversion) { return $ocsversion; } else { return false; } } else { return false; } }
/** * @brief enables an app * @param $app app * @returns true/false * * This function set an app as enabled in appconfig. */ public static function enable($app) { if (!OC_Installer::isInstalled($app)) { // check if app is a shipped app or not. OCS apps have an integer as id, shipped apps use a string if (!is_numeric($app)) { OC_Installer::installShippedApp($app); } else { $download = OC_OCSClient::getApplicationDownload($app, 1); if (isset($download['downloadlink']) and $download['downloadlink'] != '') { $app = OC_Installer::installApp(array('source' => 'http', 'href' => $download['downloadlink'])); } } } if ($app !== false) { // check if the app is compatible with this version of ownCloud $info = OC_App::getAppInfo($app); $version = OC_Util::getVersion(); if (!isset($info['require']) or $version[0] > $info['require']) { OC_Log::write('core', 'App "' . $info['name'] . '" can\'t be installed because it is not compatible with this version of ownCloud', OC_Log::ERROR); return false; } else { OC_Appconfig::setValue($app, 'enabled', 'yes'); return true; } } else { return false; } }
/** * @brief Get all the knowledgebase entries from the OCS server * @returns array with q and a data * * This function returns a list of all the knowledgebase entries from the OCS server */ public static function getKnownledgebaseEntries($page, $pagesize, $search = '') { $kbe = array('totalitems' => 0); if (OC_Config::getValue('knowledgebaseenabled', true)) { $p = (int) $page; $s = (int) $pagesize; $searchcmd = ''; if ($search) { $searchcmd = '&search=' . urlencode($search); } $url = OC_OCSClient::getKBURL() . '/knowledgebase/data?type=150&page=' . $p . '&pagesize=' . $s . $searchcmd; $xml = OC_OCSClient::getOCSresponse($url); $data = @simplexml_load_string($xml); if ($data === false) { OC_Log::write('core', 'Unable to parse knowledgebase content', OC_Log::FATAL); return null; } $tmp = $data->data->content; for ($i = 0; $i < count($tmp); $i++) { $kbe[] = array('id' => $tmp[$i]->id, 'name' => $tmp[$i]->name, 'description' => $tmp[$i]->description, 'answer' => $tmp[$i]->answer, 'preview1' => $tmp[$i]->smallpreviewpic1, 'detailpage' => $tmp[$i]->detailpage); } $kbe['totalitems'] = $data->meta->totalitems; } return $kbe; }
$l = OC_L10N::get('settings'); if (OC_Config::getValue('appstoreenabled', true) == false) { OCP\JSON::success(array('type' => 'external', 'data' => array())); } $enabledApps = OC_App::getEnabledApps(); if (is_null($enabledApps)) { OCP\JSON::error(array('data' => array('message' => $l->t('Unable to load list from App Store')))); } $apps = array(); // apps from external repo via OCS $categoryNames = OC_OCSClient::getCategories(\OC_Util::getVersion()); if (is_array($categoryNames)) { $categories = array_keys($categoryNames); $page = 0; $filter = 'approved'; $externalApps = OC_OCSClient::getApplications($categories, $page, $filter, \OC_Util::getVersion()); foreach ($externalApps as $app) { // show only external apps that aren't enabled yet $local = false; foreach ($enabledApps as $a) { if ($a === $app['name']) { $local = true; } } if (!$local) { if ($app['preview'] === '') { $pre = OC_Helper::imagePath('settings', 'trans.png'); } else { $pre = $app['preview']; } if ($app['label'] === 'recommended') {