app.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740
  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::linkToRoute( "settings_help" ), "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::linkToRoute( "settings_personal" ), "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::linkToRoute( "settings_settings" ), "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::linkToRoute( "settings_users" ), "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::linkToRoute( "settings_apps" ).'?installed', "name" => $l->t("Apps"), "icon" => OC_Helper::imagePath( "settings", "apps.svg" ));
  285. $settings[]=array( "id" => "admin", "order" => 1000, "href" => OC_Helper::linkToRoute( "settings_admin" ), "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. if( $naventry['id'] == self::$activeapp ) {
  295. $naventry['active'] = true;
  296. }
  297. else{
  298. $naventry['active'] = false;
  299. }
  300. } unset( $naventry );
  301. usort( $list, create_function( '$a, $b', 'if( $a["order"] == $b["order"] ) {return 0;}elseif( $a["order"] < $b["order"] ) {return -1;}else{return 1;}' ));
  302. return $list;
  303. }
  304. /**
  305. * Get the path where to install apps
  306. */
  307. public static function getInstallPath() {
  308. if(OC_Config::getValue('appstoreenabled', true)==false) {
  309. return false;
  310. }
  311. foreach(OC::$APPSROOTS as $dir) {
  312. if(isset($dir['writable']) && $dir['writable']===true)
  313. return $dir['path'];
  314. }
  315. OC_Log::write('core', 'No application directories are marked as writable.', OC_Log::ERROR);
  316. return null;
  317. }
  318. protected static function findAppInDirectories($appid) {
  319. static $app_dir = array();
  320. if (isset($app_dir[$appid])) {
  321. return $app_dir[$appid];
  322. }
  323. foreach(OC::$APPSROOTS as $dir) {
  324. if(file_exists($dir['path'].'/'.$appid)) {
  325. return $app_dir[$appid]=$dir;
  326. }
  327. }
  328. return false;
  329. }
  330. /**
  331. * Get the directory for the given app.
  332. * If the app is defined in multiple directory, the first one is taken. (false if not found)
  333. */
  334. public static function getAppPath($appid) {
  335. if( ($dir = self::findAppInDirectories($appid)) != false) {
  336. return $dir['path'].'/'.$appid;
  337. }
  338. return false;
  339. }
  340. /**
  341. * Get the path for the given app on the access
  342. * If the app is defined in multiple directory, the first one is taken. (false if not found)
  343. */
  344. public static function getAppWebPath($appid) {
  345. if( ($dir = self::findAppInDirectories($appid)) != false) {
  346. return OC::$WEBROOT.$dir['url'].'/'.$appid;
  347. }
  348. return false;
  349. }
  350. /**
  351. * get the last version of the app, either from appinfo/version or from appinfo/info.xml
  352. */
  353. public static function getAppVersion($appid) {
  354. $file= self::getAppPath($appid).'/appinfo/version';
  355. if(is_file($file) && $version = trim(file_get_contents($file))) {
  356. return $version;
  357. }else{
  358. $appData=self::getAppInfo($appid);
  359. return isset($appData['version'])? $appData['version'] : '';
  360. }
  361. }
  362. /**
  363. * @brief Read all app metadata from the info.xml file
  364. * @param string $appid id of the app or the path of the info.xml file
  365. * @param boolean $path (optional)
  366. * @return array
  367. * @note all data is read from info.xml, not just pre-defined fields
  368. */
  369. public static function getAppInfo($appid, $path=false) {
  370. if($path) {
  371. $file=$appid;
  372. }else{
  373. if(isset(self::$appInfo[$appid])) {
  374. return self::$appInfo[$appid];
  375. }
  376. $file= self::getAppPath($appid).'/appinfo/info.xml';
  377. }
  378. $data=array();
  379. $content=@file_get_contents($file);
  380. if(!$content) {
  381. return null;
  382. }
  383. $xml = new SimpleXMLElement($content);
  384. $data['info']=array();
  385. $data['remote']=array();
  386. $data['public']=array();
  387. foreach($xml->children() as $child) {
  388. /**
  389. * @var $child SimpleXMLElement
  390. */
  391. if($child->getName()=='remote') {
  392. foreach($child->children() as $remote) {
  393. /**
  394. * @var $remote SimpleXMLElement
  395. */
  396. $data['remote'][$remote->getName()]=(string)$remote;
  397. }
  398. }elseif($child->getName()=='public') {
  399. foreach($child->children() as $public) {
  400. /**
  401. * @var $public SimpleXMLElement
  402. */
  403. $data['public'][$public->getName()]=(string)$public;
  404. }
  405. }elseif($child->getName()=='types') {
  406. $data['types']=array();
  407. foreach($child->children() as $type) {
  408. /**
  409. * @var $type SimpleXMLElement
  410. */
  411. $data['types'][]=$type->getName();
  412. }
  413. }elseif($child->getName()=='description') {
  414. $xml=(string)$child->asXML();
  415. $data[$child->getName()]=substr($xml, 13, -14);//script <description> tags
  416. }else{
  417. $data[$child->getName()]=(string)$child;
  418. }
  419. }
  420. self::$appInfo[$appid]=$data;
  421. return $data;
  422. }
  423. /**
  424. * @brief Returns the navigation
  425. * @return array
  426. *
  427. * This function returns an array containing all entries added. The
  428. * entries are sorted by the key 'order' ascending. Additional to the keys
  429. * given for each app the following keys exist:
  430. * - active: boolean, signals if the user is on this navigation entry
  431. */
  432. public static function getNavigation() {
  433. $navigation = self::proceedNavigation( self::$navigation );
  434. return $navigation;
  435. }
  436. /**
  437. * get the id of loaded app
  438. * @return string
  439. */
  440. public static function getCurrentApp() {
  441. $script=substr($_SERVER["SCRIPT_NAME"], strlen(OC::$WEBROOT)+1);
  442. $topFolder=substr($script, 0, strpos($script, '/'));
  443. if (empty($topFolder)) {
  444. $path_info = OC_Request::getPathInfo();
  445. if ($path_info) {
  446. $topFolder=substr($path_info, 1, strpos($path_info, '/', 1)-1);
  447. }
  448. }
  449. if($topFolder=='apps') {
  450. $length=strlen($topFolder);
  451. return substr($script, $length+1, strpos($script, '/', $length+1)-$length-1);
  452. }else{
  453. return $topFolder;
  454. }
  455. }
  456. /**
  457. * get the forms for either settings, admin or personal
  458. */
  459. public static function getForms($type) {
  460. $forms=array();
  461. switch($type) {
  462. case 'settings':
  463. $source=self::$settingsForms;
  464. break;
  465. case 'admin':
  466. $source=self::$adminForms;
  467. break;
  468. case 'personal':
  469. $source=self::$personalForms;
  470. break;
  471. default:
  472. return array();
  473. }
  474. foreach($source as $form) {
  475. $forms[]=include $form;
  476. }
  477. return $forms;
  478. }
  479. /**
  480. * register a settings form to be shown
  481. */
  482. public static function registerSettings($app, $page) {
  483. self::$settingsForms[]= $app.'/'.$page.'.php';
  484. }
  485. /**
  486. * register an admin form to be shown
  487. */
  488. public static function registerAdmin($app, $page) {
  489. self::$adminForms[]= $app.'/'.$page.'.php';
  490. }
  491. /**
  492. * register a personal form to be shown
  493. */
  494. public static function registerPersonal($app, $page) {
  495. self::$personalForms[]= $app.'/'.$page.'.php';
  496. }
  497. /**
  498. * @brief: get a list of all apps in the apps folder
  499. * @return array or app names (string IDs)
  500. * @todo: change the name of this method to getInstalledApps, which is more accurate
  501. */
  502. public static function getAllApps() {
  503. $apps=array();
  504. foreach ( OC::$APPSROOTS as $apps_dir ) {
  505. if(! is_readable($apps_dir['path'])) {
  506. OC_Log::write('core', 'unable to read app folder : ' .$apps_dir['path'], OC_Log::WARN);
  507. continue;
  508. }
  509. $dh = opendir( $apps_dir['path'] );
  510. while( $file = readdir( $dh ) ) {
  511. if ($file[0] != '.' and is_file($apps_dir['path'].'/'.$file.'/appinfo/app.php')) {
  512. $apps[] = $file;
  513. }
  514. }
  515. }
  516. return $apps;
  517. }
  518. /**
  519. * @brief: get a list of all apps on apps.owncloud.com
  520. * @return array, multi-dimensional array of apps. Keys: id, name, type, typename, personid, license, detailpage, preview, changed, description
  521. */
  522. public static function getAppstoreApps( $filter = 'approved' ) {
  523. $catagoryNames = OC_OCSClient::getCategories();
  524. if ( is_array( $catagoryNames ) ) {
  525. // Check that categories of apps were retrieved correctly
  526. if ( ! $categories = array_keys( $catagoryNames ) ) {
  527. return false;
  528. }
  529. $page = 0;
  530. $remoteApps = OC_OCSClient::getApplications( $categories, $page, $filter );
  531. $app1 = array();
  532. $i = 0;
  533. foreach ( $remoteApps as $app ) {
  534. $app1[$i] = $app;
  535. $app1[$i]['author'] = $app['personid'];
  536. $app1[$i]['ocs_id'] = $app['id'];
  537. $app1[$i]['internal'] = $app1[$i]['active'] = 0;
  538. // rating img
  539. if($app['score']>=0 and $app['score']<5) $img=OC_Helper::imagePath( "core", "rating/s1.png" );
  540. elseif($app['score']>=5 and $app['score']<15) $img=OC_Helper::imagePath( "core", "rating/s2.png" );
  541. elseif($app['score']>=15 and $app['score']<25) $img=OC_Helper::imagePath( "core", "rating/s3.png" );
  542. elseif($app['score']>=25 and $app['score']<35) $img=OC_Helper::imagePath( "core", "rating/s4.png" );
  543. elseif($app['score']>=35 and $app['score']<45) $img=OC_Helper::imagePath( "core", "rating/s5.png" );
  544. elseif($app['score']>=45 and $app['score']<55) $img=OC_Helper::imagePath( "core", "rating/s6.png" );
  545. elseif($app['score']>=55 and $app['score']<65) $img=OC_Helper::imagePath( "core", "rating/s7.png" );
  546. elseif($app['score']>=65 and $app['score']<75) $img=OC_Helper::imagePath( "core", "rating/s8.png" );
  547. elseif($app['score']>=75 and $app['score']<85) $img=OC_Helper::imagePath( "core", "rating/s9.png" );
  548. elseif($app['score']>=85 and $app['score']<95) $img=OC_Helper::imagePath( "core", "rating/s10.png" );
  549. elseif($app['score']>=95 and $app['score']<100) $img=OC_Helper::imagePath( "core", "rating/s11.png" );
  550. $app1[$i]['score'] = '<img src="'.$img.'"> Score: '.$app['score'].'%';
  551. $i++;
  552. }
  553. }
  554. if ( empty( $app1 ) ) {
  555. return false;
  556. } else {
  557. return $app1;
  558. }
  559. }
  560. /**
  561. * check if the app need updating and update when needed
  562. */
  563. public static function checkUpgrade($app) {
  564. if (in_array($app, self::$checkedApps)) {
  565. return;
  566. }
  567. self::$checkedApps[] = $app;
  568. $versions = self::getAppVersions();
  569. $currentVersion=OC_App::getAppVersion($app);
  570. if ($currentVersion) {
  571. $installedVersion = $versions[$app];
  572. if (version_compare($currentVersion, $installedVersion, '>')) {
  573. OC_Log::write($app, 'starting app upgrade from '.$installedVersion.' to '.$currentVersion, OC_Log::DEBUG);
  574. try {
  575. OC_App::updateApp($app);
  576. }
  577. catch (Exception $e) {
  578. echo 'Failed to upgrade "'.$app.'". Exception="'.$e->getMessage().'"';
  579. die;
  580. }
  581. OC_Appconfig::setValue($app, 'installed_version', OC_App::getAppVersion($app));
  582. }
  583. }
  584. }
  585. /**
  586. * check if the current enabled apps are compatible with the current
  587. * ownCloud version. disable them if not.
  588. * This is important if you upgrade ownCloud and have non ported 3rd
  589. * party apps installed.
  590. */
  591. public static function checkAppsRequirements($apps = array()) {
  592. if (empty($apps)) {
  593. $apps = OC_App::getEnabledApps();
  594. }
  595. $version = OC_Util::getVersion();
  596. foreach($apps as $app) {
  597. // check if the app is compatible with this version of ownCloud
  598. $info = OC_App::getAppInfo($app);
  599. if(!isset($info['require']) or (($version[0].'.'.$version[1])>$info['require'])) {
  600. 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);
  601. OC_App::disable( $app );
  602. }
  603. }
  604. }
  605. /**
  606. * get the installed version of all apps
  607. */
  608. public static function getAppVersions() {
  609. static $versions;
  610. if (isset($versions)) { // simple cache, needs to be fixed
  611. return $versions; // when function is used besides in checkUpgrade
  612. }
  613. $versions=array();
  614. $query = OC_DB::prepare( 'SELECT `appid`, `configvalue` FROM `*PREFIX*appconfig` WHERE `configkey` = \'installed_version\'' );
  615. $result = $query->execute();
  616. while($row = $result->fetchRow()) {
  617. $versions[$row['appid']]=$row['configvalue'];
  618. }
  619. return $versions;
  620. }
  621. /**
  622. * update the database for the app and call the update script
  623. * @param string $appid
  624. */
  625. public static function updateApp($appid) {
  626. if(file_exists(self::getAppPath($appid).'/appinfo/preupdate.php')) {
  627. self::loadApp($appid);
  628. include self::getAppPath($appid).'/appinfo/preupdate.php';
  629. }
  630. if(file_exists(self::getAppPath($appid).'/appinfo/database.xml')) {
  631. OC_DB::updateDbFromStructure(self::getAppPath($appid).'/appinfo/database.xml');
  632. }
  633. if(!self::isEnabled($appid)) {
  634. return;
  635. }
  636. if(file_exists(self::getAppPath($appid).'/appinfo/update.php')) {
  637. self::loadApp($appid);
  638. include self::getAppPath($appid).'/appinfo/update.php';
  639. }
  640. //set remote/public handlers
  641. $appData=self::getAppInfo($appid);
  642. foreach($appData['remote'] as $name=>$path) {
  643. OCP\CONFIG::setAppValue('core', 'remote_'.$name, $appid.'/'.$path);
  644. }
  645. foreach($appData['public'] as $name=>$path) {
  646. OCP\CONFIG::setAppValue('core', 'public_'.$name, $appid.'/'.$path);
  647. }
  648. self::setAppTypes($appid);
  649. }
  650. /**
  651. * @param string $appid
  652. * @return OC_FilesystemView
  653. */
  654. public static function getStorage($appid) {
  655. if(OC_App::isEnabled($appid)) {//sanity check
  656. if(OC_User::isLoggedIn()) {
  657. $view = new OC_FilesystemView('/'.OC_User::getUser());
  658. if(!$view->file_exists($appid)) {
  659. $view->mkdir($appid);
  660. }
  661. return new OC_FilesystemView('/'.OC_User::getUser().'/'.$appid);
  662. }else{
  663. OC_Log::write('core', 'Can\'t get app storage, app, user not logged in', OC_Log::ERROR);
  664. return false;
  665. }
  666. }else{
  667. OC_Log::write('core', 'Can\'t get app storage, app '.$appid.' not enabled', OC_Log::ERROR);
  668. return false;
  669. }
  670. }
  671. }