app.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737
  1. <?php
  2. /**
  3. * ownCloud
  4. *
  5. * @author Frank Karlitschek
  6. * @author Jakob Sack
  7. * @copyright 2012 Frank Karlitschek frank@owncloud.org
  8. *
  9. * This library is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
  11. * License as published by the Free Software Foundation; either
  12. * version 3 of the License, or any later version.
  13. *
  14. * This library is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public
  20. * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  21. *
  22. */
  23. /**
  24. * This class manages the apps. It allows them to register and integrate in the
  25. * owncloud ecosystem. Furthermore, this class is responsible for installing,
  26. * upgrading and removing apps.
  27. */
  28. class OC_App{
  29. static private $activeapp = '';
  30. static private $navigation = array();
  31. static private $settingsForms = array();
  32. static private $adminForms = array();
  33. static private $personalForms = array();
  34. static private $appInfo = array();
  35. static private $appTypes = array();
  36. static private $loadedApps = array();
  37. static private $checkedApps = array();
  38. /**
  39. * @brief loads all apps
  40. * @param array $types
  41. * @return bool
  42. *
  43. * This function walks through the owncloud directory and loads all apps
  44. * it can find. A directory contains an app if the file /appinfo/app.php
  45. * exists.
  46. *
  47. * if $types is set, only apps of those types will be loaded
  48. */
  49. public static function loadApps($types=null) {
  50. // Load the enabled apps here
  51. $apps = self::getEnabledApps();
  52. // prevent app.php from printing output
  53. ob_start();
  54. foreach( $apps as $app ) {
  55. if((is_null($types) or self::isType($app, $types)) && !in_array($app, self::$loadedApps)) {
  56. self::loadApp($app);
  57. self::$loadedApps[] = $app;
  58. }
  59. }
  60. ob_end_clean();
  61. if (!defined('DEBUG') || !DEBUG) {
  62. if (is_null($types)
  63. && empty(OC_Util::$core_scripts)
  64. && empty(OC_Util::$core_styles)) {
  65. OC_Util::$core_scripts = OC_Util::$scripts;
  66. OC_Util::$scripts = array();
  67. OC_Util::$core_styles = OC_Util::$styles;
  68. OC_Util::$styles = array();
  69. }
  70. }
  71. // return
  72. return true;
  73. }
  74. /**
  75. * load a single app
  76. * @param string $app
  77. */
  78. public static function loadApp($app) {
  79. if(is_file(self::getAppPath($app).'/appinfo/app.php')) {
  80. self::checkUpgrade($app);
  81. require_once $app.'/appinfo/app.php';
  82. }
  83. }
  84. /**
  85. * check if an app is of a specific type
  86. * @param string $app
  87. * @param string/array $types
  88. * @return bool
  89. */
  90. public static function isType($app,$types) {
  91. if(is_string($types)) {
  92. $types=array($types);
  93. }
  94. $appTypes=self::getAppTypes($app);
  95. foreach($types as $type) {
  96. if(array_search($type, $appTypes)!==false) {
  97. return true;
  98. }
  99. }
  100. return false;
  101. }
  102. /**
  103. * get the types of an app
  104. * @param string $app
  105. * @return array
  106. */
  107. private static function getAppTypes($app) {
  108. //load the cache
  109. if(count(self::$appTypes)==0) {
  110. self::$appTypes=OC_Appconfig::getValues(false, 'types');
  111. }
  112. if(isset(self::$appTypes[$app])) {
  113. return explode(',', self::$appTypes[$app]);
  114. }else{
  115. return array();
  116. }
  117. }
  118. /**
  119. * read app types from info.xml and cache them in the database
  120. */
  121. public static function setAppTypes($app) {
  122. $appData=self::getAppInfo($app);
  123. if(isset($appData['types'])) {
  124. $appTypes=implode(',', $appData['types']);
  125. }else{
  126. $appTypes='';
  127. }
  128. OC_Appconfig::setValue($app, 'types', $appTypes);
  129. }
  130. /**
  131. * get all enabled apps
  132. */
  133. public static function getEnabledApps() {
  134. if(!OC_Config::getValue('installed', false))
  135. return array();
  136. $apps=array('files');
  137. $query = OC_DB::prepare( 'SELECT `appid` FROM `*PREFIX*appconfig` WHERE `configkey` = \'enabled\' AND `configvalue`=\'yes\'' );
  138. $result=$query->execute();
  139. while($row=$result->fetchRow()) {
  140. if(array_search($row['appid'], $apps)===false) {
  141. $apps[]=$row['appid'];
  142. }
  143. }
  144. return $apps;
  145. }
  146. /**
  147. * @brief checks whether or not an app is enabled
  148. * @param string $app app
  149. * @return bool
  150. *
  151. * This function checks whether or not an app is enabled.
  152. */
  153. public static function isEnabled( $app ) {
  154. if( 'files'==$app or 'yes' == OC_Appconfig::getValue( $app, 'enabled' )) {
  155. return true;
  156. }
  157. return false;
  158. }
  159. /**
  160. * @brief enables an app
  161. * @param mixed $app app
  162. * @return bool
  163. *
  164. * This function set an app as enabled in appconfig.
  165. */
  166. public static function enable( $app ) {
  167. if(!OC_Installer::isInstalled($app)) {
  168. // check if app is a shipped app or not. OCS apps have an integer as id, shipped apps use a string
  169. if(!is_numeric($app)) {
  170. $app = OC_Installer::installShippedApp($app);
  171. }else{
  172. $download=OC_OCSClient::getApplicationDownload($app, 1);
  173. if(isset($download['downloadlink']) and $download['downloadlink']!='') {
  174. $app=OC_Installer::installApp(array('source'=>'http','href'=>$download['downloadlink']));
  175. }
  176. }
  177. }
  178. if($app!==false) {
  179. // check if the app is compatible with this version of ownCloud
  180. $info=OC_App::getAppInfo($app);
  181. $version=OC_Util::getVersion();
  182. if(!isset($info['require']) or ($version[0]>$info['require'])) {
  183. OC_Log::write('core', 'App "'.$info['name'].'" can\'t be installed because it is not compatible with this version of ownCloud', OC_Log::ERROR);
  184. return false;
  185. }else{
  186. OC_Appconfig::setValue( $app, 'enabled', 'yes' );
  187. return true;
  188. }
  189. }else{
  190. return false;
  191. }
  192. }
  193. /**
  194. * @brief disables an app
  195. * @param string $app app
  196. * @return bool
  197. *
  198. * This function set an app as disabled in appconfig.
  199. */
  200. public static function disable( $app ) {
  201. // check if app is a shiped app or not. if not delete
  202. OC_Appconfig::setValue( $app, 'enabled', 'no' );
  203. }
  204. /**
  205. * @brief adds an entry to the navigation
  206. * @param string $data array containing the data
  207. * @return bool
  208. *
  209. * This function adds a new entry to the navigation visible to users. $data
  210. * is an associative array.
  211. * The following keys are required:
  212. * - id: unique id for this entry ('addressbook_index')
  213. * - href: link to the page
  214. * - name: Human readable name ('Addressbook')
  215. *
  216. * The following keys are optional:
  217. * - icon: path to the icon of the app
  218. * - order: integer, that influences the position of your application in
  219. * the navigation. Lower values come first.
  220. */
  221. public static function addNavigationEntry( $data ) {
  222. $data['active']=false;
  223. if(!isset($data['icon'])) {
  224. $data['icon']='';
  225. }
  226. OC_App::$navigation[] = $data;
  227. return true;
  228. }
  229. /**
  230. * @brief marks a navigation entry as active
  231. * @param string $id id of the entry
  232. * @return bool
  233. *
  234. * This function sets a navigation entry as active and removes the 'active'
  235. * property from all other entries. The templates can use this for
  236. * highlighting the current position of the user.
  237. */
  238. public static function setActiveNavigationEntry( $id ) {
  239. self::$activeapp = $id;
  240. return true;
  241. }
  242. /**
  243. * @brief gets the active Menu entry
  244. * @return string id or empty string
  245. *
  246. * This function returns the id of the active navigation entry (set by
  247. * setActiveNavigationEntry
  248. */
  249. public static function getActiveNavigationEntry() {
  250. return self::$activeapp;
  251. }
  252. /**
  253. * @brief Returns the Settings Navigation
  254. * @return array
  255. *
  256. * This function returns an array containing all settings pages added. The
  257. * entries are sorted by the key 'order' ascending.
  258. */
  259. public static function getSettingsNavigation() {
  260. $l=OC_L10N::get('lib');
  261. $settings = array();
  262. // by default, settings only contain the help menu
  263. if(OC_Config::getValue('knowledgebaseenabled', true)==true) {
  264. $settings = array(
  265. array( "id" => "help", "order" => 1000, "href" => OC_Helper::linkTo( "settings", "help.php" ), "name" => $l->t("Help"), "icon" => OC_Helper::imagePath( "settings", "help.svg" ))
  266. );
  267. }
  268. // if the user is logged-in
  269. if (OC_User::isLoggedIn()) {
  270. // personal menu
  271. $settings[] = array( "id" => "personal", "order" => 1, "href" => OC_Helper::linkTo( "settings", "personal.php" ), "name" => $l->t("Personal"), "icon" => OC_Helper::imagePath( "settings", "personal.svg" ));
  272. // if there are some settings forms
  273. if(!empty(self::$settingsForms))
  274. // settings menu
  275. $settings[]=array( "id" => "settings", "order" => 1000, "href" => OC_Helper::linkTo( "settings", "settings.php" ), "name" => $l->t("Settings"), "icon" => OC_Helper::imagePath( "settings", "settings.svg" ));
  276. //SubAdmins are also allowed to access user management
  277. if(OC_SubAdmin::isSubAdmin($_SESSION["user_id"]) || OC_Group::inGroup( $_SESSION["user_id"], "admin" )) {
  278. // admin users menu
  279. $settings[] = array( "id" => "core_users", "order" => 2, "href" => OC_Helper::linkTo( "settings", "users.php" ), "name" => $l->t("Users"), "icon" => OC_Helper::imagePath( "settings", "users.svg" ));
  280. }
  281. // if the user is an admin
  282. if(OC_Group::inGroup( $_SESSION["user_id"], "admin" )) {
  283. // admin apps menu
  284. $settings[] = array( "id" => "core_apps", "order" => 3, "href" => OC_Helper::linkTo( "settings", "apps.php" ).'?installed', "name" => $l->t("Apps"), "icon" => OC_Helper::imagePath( "settings", "apps.svg" ));
  285. $settings[]=array( "id" => "admin", "order" => 1000, "href" => OC_Helper::linkTo( "settings", "admin.php" ), "name" => $l->t("Admin"), "icon" => OC_Helper::imagePath( "settings", "admin.svg" ));
  286. }
  287. }
  288. $navigation = self::proceedNavigation($settings);
  289. return $navigation;
  290. }
  291. /// This is private as well. It simply works, so don't ask for more details
  292. private static function proceedNavigation( $list ) {
  293. foreach( $list as &$naventry ) {
  294. $naventry['subnavigation'] = array();
  295. if( $naventry['id'] == self::$activeapp ) {
  296. $naventry['active'] = true;
  297. }
  298. else{
  299. $naventry['active'] = false;
  300. }
  301. } unset( $naventry );
  302. usort( $list, create_function( '$a, $b', 'if( $a["order"] == $b["order"] ) {return 0;}elseif( $a["order"] < $b["order"] ) {return -1;}else{return 1;}' ));
  303. return $list;
  304. }
  305. /**
  306. * Get the path where to install apps
  307. */
  308. public static function getInstallPath() {
  309. if(OC_Config::getValue('appstoreenabled', true)==false) {
  310. return false;
  311. }
  312. foreach(OC::$APPSROOTS as $dir) {
  313. if(isset($dir['writable']) && $dir['writable']===true)
  314. return $dir['path'];
  315. }
  316. OC_Log::write('core', 'No application directories are marked as writable.', OC_Log::ERROR);
  317. return null;
  318. }
  319. protected static function findAppInDirectories($appid) {
  320. static $app_dir = array();
  321. if (isset($app_dir[$appid])) {
  322. return $app_dir[$appid];
  323. }
  324. foreach(OC::$APPSROOTS as $dir) {
  325. if(file_exists($dir['path'].'/'.$appid)) {
  326. return $app_dir[$appid]=$dir;
  327. }
  328. }
  329. return false;
  330. }
  331. /**
  332. * Get the directory for the given app.
  333. * If the app is defined in multiple directory, the first one is taken. (false if not found)
  334. */
  335. public static function getAppPath($appid) {
  336. if( ($dir = self::findAppInDirectories($appid)) != false) {
  337. return $dir['path'].'/'.$appid;
  338. }
  339. return false;
  340. }
  341. /**
  342. * Get the path for the given app on the access
  343. * If the app is defined in multiple directory, the first one is taken. (false if not found)
  344. */
  345. public static function getAppWebPath($appid) {
  346. if( ($dir = self::findAppInDirectories($appid)) != false) {
  347. return OC::$WEBROOT.$dir['url'].'/'.$appid;
  348. }
  349. return false;
  350. }
  351. /**
  352. * get the last version of the app, either from appinfo/version or from appinfo/info.xml
  353. */
  354. public static function getAppVersion($appid) {
  355. $file= self::getAppPath($appid).'/appinfo/version';
  356. $version=@file_get_contents($file);
  357. if($version) {
  358. return trim($version);
  359. }else{
  360. $appData=self::getAppInfo($appid);
  361. return isset($appData['version'])? $appData['version'] : '';
  362. }
  363. }
  364. /**
  365. * @brief Read all app metadata from the info.xml file
  366. * @param string $appid id of the app or the path of the info.xml file
  367. * @param boolean $path (optional)
  368. * @return array
  369. * @note all data is read from info.xml, not just pre-defined fields
  370. */
  371. public static function getAppInfo($appid,$path=false) {
  372. if($path) {
  373. $file=$appid;
  374. }else{
  375. if(isset(self::$appInfo[$appid])) {
  376. return self::$appInfo[$appid];
  377. }
  378. $file= self::getAppPath($appid).'/appinfo/info.xml';
  379. }
  380. $data=array();
  381. $content=@file_get_contents($file);
  382. if(!$content) {
  383. return null;
  384. }
  385. $xml = new SimpleXMLElement($content);
  386. $data['info']=array();
  387. $data['remote']=array();
  388. $data['public']=array();
  389. foreach($xml->children() as $child) {
  390. /**
  391. * @var $child SimpleXMLElement
  392. */
  393. if($child->getName()=='remote') {
  394. foreach($child->children() as $remote) {
  395. /**
  396. * @var $remote SimpleXMLElement
  397. */
  398. $data['remote'][$remote->getName()]=(string)$remote;
  399. }
  400. }elseif($child->getName()=='public') {
  401. foreach($child->children() as $public) {
  402. /**
  403. * @var $public SimpleXMLElement
  404. */
  405. $data['public'][$public->getName()]=(string)$public;
  406. }
  407. }elseif($child->getName()=='types') {
  408. $data['types']=array();
  409. foreach($child->children() as $type) {
  410. /**
  411. * @var $type SimpleXMLElement
  412. */
  413. $data['types'][]=$type->getName();
  414. }
  415. }elseif($child->getName()=='description') {
  416. $xml=(string)$child->asXML();
  417. $data[$child->getName()]=substr($xml, 13, -14);//script <description> tags
  418. }else{
  419. $data[$child->getName()]=(string)$child;
  420. }
  421. }
  422. self::$appInfo[$appid]=$data;
  423. return $data;
  424. }
  425. /**
  426. * @brief Returns the navigation
  427. * @return array
  428. *
  429. * This function returns an array containing all entries added. The
  430. * entries are sorted by the key 'order' ascending. Additional to the keys
  431. * given for each app the following keys exist:
  432. * - active: boolean, signals if the user is on this navigation entry
  433. * - children: array that is empty if the key 'active' is false or
  434. * contains the subentries if the key 'active' is true
  435. */
  436. public static function getNavigation() {
  437. $navigation = self::proceedNavigation( self::$navigation );
  438. return $navigation;
  439. }
  440. /**
  441. * get the id of loaded app
  442. * @return string
  443. */
  444. public static function getCurrentApp() {
  445. $script=substr($_SERVER["SCRIPT_NAME"], strlen(OC::$WEBROOT)+1);
  446. $topFolder=substr($script, 0, strpos($script, '/'));
  447. if($topFolder=='apps') {
  448. $length=strlen($topFolder);
  449. return substr($script, $length+1, strpos($script, '/', $length+1)-$length-1);
  450. }else{
  451. return $topFolder;
  452. }
  453. }
  454. /**
  455. * get the forms for either settings, admin or personal
  456. */
  457. public static function getForms($type) {
  458. $forms=array();
  459. switch($type) {
  460. case 'settings':
  461. $source=self::$settingsForms;
  462. break;
  463. case 'admin':
  464. $source=self::$adminForms;
  465. break;
  466. case 'personal':
  467. $source=self::$personalForms;
  468. break;
  469. default:
  470. return array();
  471. }
  472. foreach($source as $form) {
  473. $forms[]=include $form;
  474. }
  475. return $forms;
  476. }
  477. /**
  478. * register a settings form to be shown
  479. */
  480. public static function registerSettings($app,$page) {
  481. self::$settingsForms[]= $app.'/'.$page.'.php';
  482. }
  483. /**
  484. * register an admin form to be shown
  485. */
  486. public static function registerAdmin($app,$page) {
  487. self::$adminForms[]= $app.'/'.$page.'.php';
  488. }
  489. /**
  490. * register a personal form to be shown
  491. */
  492. public static function registerPersonal($app,$page) {
  493. self::$personalForms[]= $app.'/'.$page.'.php';
  494. }
  495. /**
  496. * @brief: get a list of all apps in the apps folder
  497. * @return array or app names (string IDs)
  498. * @todo: change the name of this method to getInstalledApps, which is more accurate
  499. */
  500. public static function getAllApps() {
  501. $apps=array();
  502. foreach ( OC::$APPSROOTS as $apps_dir ) {
  503. if(! is_readable($apps_dir['path'])) {
  504. OC_Log::write('core', 'unable to read app folder : ' .$apps_dir['path'] , OC_Log::WARN);
  505. continue;
  506. }
  507. $dh = opendir( $apps_dir['path'] );
  508. while( $file = readdir( $dh ) ) {
  509. if (
  510. $file[0] != '.'
  511. and is_file($apps_dir['path'].'/'.$file.'/appinfo/app.php' )
  512. ) {
  513. $apps[] = $file;
  514. }
  515. }
  516. }
  517. return $apps;
  518. }
  519. /**
  520. * @brief: get a list of all apps on apps.owncloud.com
  521. * @return array, multi-dimensional array of apps. Keys: id, name, type, typename, personid, license, detailpage, preview, changed, description
  522. */
  523. public static function getAppstoreApps( $filter = 'approved' ) {
  524. $catagoryNames = OC_OCSClient::getCategories();
  525. if ( is_array( $catagoryNames ) ) {
  526. // Check that categories of apps were retrieved correctly
  527. if ( ! $categories = array_keys( $catagoryNames ) ) {
  528. return false;
  529. }
  530. $page = 0;
  531. $remoteApps = OC_OCSClient::getApplications( $categories, $page, $filter );
  532. $app1 = array();
  533. $i = 0;
  534. foreach ( $remoteApps as $app ) {
  535. $app1[$i] = $app;
  536. $app1[$i]['author'] = $app['personid'];
  537. $app1[$i]['ocs_id'] = $app['id'];
  538. $app1[$i]['internal'] = $app1[$i]['active'] = 0;
  539. // rating img
  540. if($app['score']>=0 and $app['score']<5) $img=OC_Helper::imagePath( "core", "rating/s1.png" );
  541. elseif($app['score']>=5 and $app['score']<15) $img=OC_Helper::imagePath( "core", "rating/s2.png" );
  542. elseif($app['score']>=15 and $app['score']<25) $img=OC_Helper::imagePath( "core", "rating/s3.png" );
  543. elseif($app['score']>=25 and $app['score']<35) $img=OC_Helper::imagePath( "core", "rating/s4.png" );
  544. elseif($app['score']>=35 and $app['score']<45) $img=OC_Helper::imagePath( "core", "rating/s5.png" );
  545. elseif($app['score']>=45 and $app['score']<55) $img=OC_Helper::imagePath( "core", "rating/s6.png" );
  546. elseif($app['score']>=55 and $app['score']<65) $img=OC_Helper::imagePath( "core", "rating/s7.png" );
  547. elseif($app['score']>=65 and $app['score']<75) $img=OC_Helper::imagePath( "core", "rating/s8.png" );
  548. elseif($app['score']>=75 and $app['score']<85) $img=OC_Helper::imagePath( "core", "rating/s9.png" );
  549. elseif($app['score']>=85 and $app['score']<95) $img=OC_Helper::imagePath( "core", "rating/s10.png" );
  550. elseif($app['score']>=95 and $app['score']<100) $img=OC_Helper::imagePath( "core", "rating/s11.png" );
  551. $app1[$i]['score'] = '<img src="'.$img.'"> Score: '.$app['score'].'%';
  552. $i++;
  553. }
  554. }
  555. if ( empty( $app1 ) ) {
  556. return false;
  557. } else {
  558. return $app1;
  559. }
  560. }
  561. /**
  562. * check if the app need updating and update when needed
  563. */
  564. public static function checkUpgrade($app) {
  565. if (in_array($app, self::$checkedApps)) {
  566. return;
  567. }
  568. self::$checkedApps[] = $app;
  569. $versions = self::getAppVersions();
  570. $currentVersion=OC_App::getAppVersion($app);
  571. if ($currentVersion) {
  572. $installedVersion = $versions[$app];
  573. if (version_compare($currentVersion, $installedVersion, '>')) {
  574. OC_Log::write($app, 'starting app upgrade from '.$installedVersion.' to '.$currentVersion, OC_Log::DEBUG);
  575. try {
  576. OC_App::updateApp($app);
  577. }
  578. catch (Exception $e) {
  579. echo 'Failed to upgrade "'.$app.'". Exception="'.$e->getMessage().'"';
  580. die;
  581. }
  582. OC_Appconfig::setValue($app, 'installed_version', OC_App::getAppVersion($app));
  583. }
  584. }
  585. }
  586. /**
  587. * check if the current enabled apps are compatible with the current
  588. * ownCloud version. disable them if not.
  589. * This is important if you upgrade ownCloud and have non ported 3rd
  590. * party apps installed.
  591. */
  592. public static function checkAppsRequirements($apps = array()) {
  593. if (empty($apps)) {
  594. $apps = OC_App::getEnabledApps();
  595. }
  596. $version = OC_Util::getVersion();
  597. foreach($apps as $app) {
  598. // check if the app is compatible with this version of ownCloud
  599. $info = OC_App::getAppInfo($app);
  600. if(!isset($info['require']) or (($version[0].'.'.$version[1])>$info['require'])) {
  601. OC_Log::write('core', 'App "'.$info['name'].'" ('.$app.') can\'t be used because it is not compatible with this version of ownCloud', OC_Log::ERROR);
  602. OC_App::disable( $app );
  603. }
  604. }
  605. }
  606. /**
  607. * get the installed version of all apps
  608. */
  609. public static function getAppVersions() {
  610. static $versions;
  611. if (isset($versions)) { // simple cache, needs to be fixed
  612. return $versions; // when function is used besides in checkUpgrade
  613. }
  614. $versions=array();
  615. $query = OC_DB::prepare( 'SELECT `appid`, `configvalue` FROM `*PREFIX*appconfig` WHERE `configkey` = \'installed_version\'' );
  616. $result = $query->execute();
  617. while($row = $result->fetchRow()) {
  618. $versions[$row['appid']]=$row['configvalue'];
  619. }
  620. return $versions;
  621. }
  622. /**
  623. * update the database for the app and call the update script
  624. * @param string $appid
  625. */
  626. public static function updateApp($appid) {
  627. if(file_exists(self::getAppPath($appid).'/appinfo/database.xml')) {
  628. OC_DB::updateDbFromStructure(self::getAppPath($appid).'/appinfo/database.xml');
  629. }
  630. if(!self::isEnabled($appid)) {
  631. return;
  632. }
  633. if(file_exists(self::getAppPath($appid).'/appinfo/update.php')) {
  634. self::loadApp($appid);
  635. include self::getAppPath($appid).'/appinfo/update.php';
  636. }
  637. //set remote/public handlers
  638. $appData=self::getAppInfo($appid);
  639. foreach($appData['remote'] as $name=>$path) {
  640. OCP\CONFIG::setAppValue('core', 'remote_'.$name, $appid.'/'.$path);
  641. }
  642. foreach($appData['public'] as $name=>$path) {
  643. OCP\CONFIG::setAppValue('core', 'public_'.$name, $appid.'/'.$path);
  644. }
  645. self::setAppTypes($appid);
  646. }
  647. /**
  648. * @param string $appid
  649. * @return OC_FilesystemView
  650. */
  651. public static function getStorage($appid) {
  652. if(OC_App::isEnabled($appid)) {//sanity check
  653. if(OC_User::isLoggedIn()) {
  654. $view = new OC_FilesystemView('/'.OC_User::getUser());
  655. if(!$view->file_exists($appid)) {
  656. $view->mkdir($appid);
  657. }
  658. return new OC_FilesystemView('/'.OC_User::getUser().'/'.$appid);
  659. }else{
  660. OC_Log::write('core', 'Can\'t get app storage, app, user not logged in', OC_Log::ERROR);
  661. return false;
  662. }
  663. }else{
  664. OC_Log::write('core', 'Can\'t get app storage, app '.$appid.' not enabled', OC_Log::ERROR);
  665. return false;
  666. }
  667. }
  668. }