aboutsummaryrefslogtreecommitdiffstats
path: root/lib/app.php
diff options
context:
space:
mode:
Diffstat (limited to 'lib/app.php')
-rwxr-xr-xlib/app.php91
1 files changed, 78 insertions, 13 deletions
diff --git a/lib/app.php b/lib/app.php
index 3daf539aa21..6c882963a02 100755
--- a/lib/app.php
+++ b/lib/app.php
@@ -34,16 +34,20 @@ class OC_App{
static private $settingsForms = array();
static private $adminForms = array();
static private $personalForms = array();
+ static private $appInfo = array();
/**
* @brief loads all apps
+ * @param array $types
* @returns true/false
*
* This function walks through the owncloud directory and loads all apps
* it can find. A directory contains an app if the file /appinfo/app.php
* exists.
+ *
+ * if $types is set, only apps of those types will be loaded
*/
- public static function loadApps(){
+ public static function loadApps($types=null){
// Did we allready load everything?
if( self::$init ){
return true;
@@ -51,13 +55,15 @@ class OC_App{
// Our very own core apps are hardcoded
foreach( array('files', 'settings') as $app ){
- require( $app.'/appinfo/app.php' );
+ if(is_null($types) or self::isType($app,$types)){
+ require( $app.'/appinfo/app.php' );
+ }
}
// The rest comes here
- $apps = OC_Appconfig::getApps();
+ $apps = self::getEnabledApps();
foreach( $apps as $app ){
- if( self::isEnabled( $app )){
+ if(is_null($types) or self::isType($app,$types)){
if(is_file(OC::$APPSROOT.'/apps/'.$app.'/appinfo/app.php')){
require( $app.'/appinfo/app.php' );
}
@@ -71,6 +77,41 @@ class OC_App{
}
/**
+ * check if an app is of a sepcific type
+ * @param string $app
+ * @param string/array $types
+ */
+ public static function isType($app,$types){
+ if(is_string($types)){
+ $types=array($types);
+ }
+ $appData=self::getAppInfo($app);
+ if(!isset($appData['types'])){
+ return false;
+ }
+ $appTypes=$appData['types'];
+ foreach($types as $type){
+ if(array_search($type,$appTypes)!==false){
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * get all enabled apps
+ */
+ public static function getEnabledApps(){
+ $apps=array();
+ $query = OC_DB::prepare( 'SELECT appid FROM *PREFIX*appconfig WHERE configkey = "enabled" AND configvalue="yes"' );
+ $query->execute();
+ while($row=$query->fetchRow()){
+ $apps[]=$row['appid'];
+ }
+ return $apps;
+ }
+
+ /**
* @brief checks whether or not an app is enabled
* @param $app app
* @returns true/false
@@ -265,24 +306,36 @@ class OC_App{
/**
* @brief Read app metadata from the info.xml file
* @param string $appid id of the app or the path of the info.xml file
+ * @param boolean path (optional)
* @returns array
*/
- public static function getAppInfo($appid){
- if(is_file($appid)){
+ public static function getAppInfo($appid,$path=false){
+ if($path){
$file=$appid;
}else{
- $file=OC::$APPSROOT.'/apps/'.$appid.'/appinfo/info.xml';
- if(!is_file($file)){
- return array();
+ if(isset(self::$appInfo[$appid])){
+ return self::$appInfo[$appid];
}
+ $file=OC::$APPSROOT.'/apps/'.$appid.'/appinfo/info.xml';
}
$data=array();
$content=file_get_contents($file);
+ if(!$content){
+ return;
+ }
$xml = new SimpleXMLElement($content);
$data['info']=array();
foreach($xml->children() as $child){
- $data[$child->getName()]=(string)$child;
+ if($child->getName()=='types'){
+ $data['types']=array();
+ foreach($child->children() as $type){
+ $data['types'][]=$type->getName();
+ }
+ }else{
+ $data[$child->getName()]=(string)$child;
+ }
}
+ self::$appInfo[$appid]=$data;
return $data;
}
@@ -381,9 +434,8 @@ class OC_App{
*/
public static function updateApps(){
// The rest comes here
- $apps = OC_Appconfig::getApps();
- foreach( $apps as $app ){
- $installedVersion=OC_Appconfig::getValue($app,'installed_version');
+ $versions = self::getAppVersions();
+ foreach( $versions as $app=>$installedVersion ){
$appInfo=OC_App::getAppInfo($app);
if (isset($appInfo['version'])) {
$currentVersion=$appInfo['version'];
@@ -396,6 +448,19 @@ class OC_App{
}
/**
+ * get the installed version of all papps
+ */
+ public static function getAppVersions(){
+ $versions=array();
+ $query = OC_DB::prepare( 'SELECT appid, configvalue FROM *PREFIX*appconfig WHERE configkey = "installed_version"' );
+ $result = $query->execute();
+ while($row = $result->fetchRow()){
+ $versions[$row['appid']]=$row['configvalue'];
+ }
+ return $versions;
+ }
+
+ /**
* update the database for the app and call the update script
* @param string appid
*/