Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 67 additions & 7 deletions lib/private/legacy/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -664,15 +664,16 @@ public static function getAppVersionByPath($path) {
* Read all 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)
* @param bool $path
* @param string $lang
* @return array|null
* @note all data is read from info.xml, not just pre-defined fields
*/
public static function getAppInfo($appId, $path = false) {
public static function getAppInfo($appId, $path = false, $lang = null) {
if ($path) {
$file = $appId;
} else {
if (isset(self::$appInfo[$appId])) {
if ($lang === null && isset(self::$appInfo[$appId])) {
return self::$appInfo[$appId];
}
$appPath = self::getAppPath($appId);
Expand All @@ -686,7 +687,7 @@ public static function getAppInfo($appId, $path = false) {
$data = $parser->parse($file);

if (is_array($data)) {
$data = OC_App::parseAppInfo($data);
$data = OC_App::parseAppInfo($data, $lang);
}
if(isset($data['ocsid'])) {
$storedId = \OC::$server->getConfig()->getAppValue($appId, 'ocsid');
Expand All @@ -695,7 +696,9 @@ public static function getAppInfo($appId, $path = false) {
}
}

self::$appInfo[$appId] = $data;
if ($lang === null) {
self::$appInfo[$appId] = $data;
}

return $data;
}
Expand Down Expand Up @@ -845,11 +848,12 @@ public static function listAllApps($onlyLocal = false,
//we don't want to show configuration for these
$blacklist = \OC::$server->getAppManager()->getAlwaysEnabledApps();
$appList = array();
$langCode = \OC::$server->getL10N('core')->getLanguageCode();

foreach ($installedApps as $app) {
if (array_search($app, $blacklist) === false) {

$info = OC_App::getAppInfo($app);
$info = OC_App::getAppInfo($app, false, $langCode);
if (!is_array($info)) {
\OCP\Util::writeLog('core', 'Could not read app info file for app "' . $app . '"', \OCP\Util::ERROR);
continue;
Expand Down Expand Up @@ -1329,13 +1333,69 @@ public static function getStorage($appId) {
}
}

protected static function findBestL10NOption($options, $lang) {
$fallback = $similarLangFallback = $englishFallback = false;

$lang = strtolower($lang);
$similarLang = $lang;
if (strpos($similarLang, '_')) {
// For "de_DE" we want to find "de" and the other way around
$similarLang = substr($lang, 0, strpos($lang, '_'));
}

foreach ($options as $option) {
if (is_array($option)) {
if ($fallback === false) {
$fallback = $option['@value'];
}

if (!isset($option['@attributes']['lang'])) {
continue;
}

$attributeLang = strtolower($option['@attributes']['lang']);
if ($attributeLang === $lang) {
return $option['@value'];
}

if ($attributeLang === $similarLang) {
$similarLangFallback = $option['@value'];
} else if (strpos($attributeLang, $similarLang . '_') === 0) {
if ($similarLangFallback === false) {
$similarLangFallback = $option['@value'];
}
}
} else {
$englishFallback = $option;
}
}

if ($similarLangFallback !== false) {
return $similarLangFallback;
} else if ($englishFallback !== false) {
return $englishFallback;
}
return (string) $fallback;
}

/**
* parses the app data array and enhanced the 'description' value
*
* @param array $data the app data
* @param string $lang
* @return array improved app data
*/
public static function parseAppInfo(array $data) {
public static function parseAppInfo(array $data, $lang = null) {

if ($lang && isset($data['name']) && is_array($data['name'])) {
$data['name'] = self::findBestL10NOption($data['name'], $lang);
}
if ($lang && isset($data['summary']) && is_array($data['summary'])) {
$data['summary'] = self::findBestL10NOption($data['summary'], $lang);
}
if ($lang && isset($data['description']) && is_array($data['description'])) {
$data['description'] = self::findBestL10NOption($data['description'], $lang);
}

// just modify the description if it is available
// otherwise this will create a $data element with an empty 'description'
Expand Down
55 changes: 51 additions & 4 deletions settings/js/apps.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,18 @@ OC.Settings.Apps = OC.Settings.Apps || {
app.previewAsIcon = true;
}

if (_.isArray(app.author)) {
var authors = [];
_.each(app.author, function (author) {
if (typeof author === 'string') {
authors.push(author);
} else {
authors.push(author['@value']);
}
});
app.author = authors.join(', ');
}

var html = template(app);
if (selector) {
selector.html(html);
Expand Down Expand Up @@ -482,6 +494,24 @@ OC.Settings.Apps = OC.Settings.Apps || {
);
},

/**
* Splits the query by spaces and tries to find all substring in the app
* @param {string} string
* @param {string} query
* @returns {boolean}
*/
_search: function(string, query) {
var keywords = query.split(' '),
stringLower = string.toLowerCase(),
found = true;

_.each(keywords, function(keyword) {
found = found && stringLower.indexOf(keyword) !== -1;
});

return found;
},

filter: function(query) {
var $appList = $('#apps-list'),
$emptyList = $('#apps-list-empty');
Expand All @@ -498,22 +528,39 @@ OC.Settings.Apps = OC.Settings.Apps || {

// App Name
var apps = _.filter(OC.Settings.Apps.State.apps, function (app) {
return app.name.toLowerCase().indexOf(query) !== -1;
return OC.Settings.Apps._search(app.name, query);
});

// App ID
apps = apps.concat(_.filter(OC.Settings.Apps.State.apps, function (app) {
return app.id.toLowerCase().indexOf(query) !== -1;
return OC.Settings.Apps._search(app.id, query);
}));

// App Description
apps = apps.concat(_.filter(OC.Settings.Apps.State.apps, function (app) {
return app.description.toLowerCase().indexOf(query) !== -1;
return OC.Settings.Apps._search(app.description, query);
}));

// Author Name
apps = apps.concat(_.filter(OC.Settings.Apps.State.apps, function (app) {
return app.author.toLowerCase().indexOf(query) !== -1;
if (_.isArray(app.author)) {
var authors = [];
_.each(app.author, function (author) {
if (typeof author === 'string') {
authors.push(author);
} else {
authors.push(author['@value']);
if (!_.isUndefined(author['@attributes']['homepage'])) {
authors.push(author['@attributes']['homepage']);
}
if (!_.isUndefined(author['@attributes']['mail'])) {
authors.push(author['@attributes']['mail']);
}
}
});
return OC.Settings.Apps._search(authors.join(' '), query);
}
return OC.Settings.Apps._search(app.author, query);
}));

// App status
Expand Down