use Imagick;
use ImagickPixel;
+use OCP\App\AppPathNotFoundException;
class IconBuilder {
/** @var ThemingDefaults */
* @return Imagick|false
*/
public function renderAppIcon($app) {
- $appIcon = $this->util->getAppIcon($app);
- $appIconContent = file_get_contents($appIcon);
+ try {
+ $appIcon = $this->util->getAppIcon($app);
+ $appIconContent = file_get_contents($appIcon);
+ } catch (AppPathNotFoundException $e) {
+ return false;
+ }
+
if($appIconContent === false) {
return false;
}
}
public function colorSvg($app, $image) {
- $imageFile = $this->util->getAppImage($app, $image);
+ try {
+ $imageFile = $this->util->getAppImage($app, $image);
+ } catch (AppPathNotFoundException $e) {
+ return false;
+ }
$svg = file_get_contents($imageFile);
if ($svg !== false) {
$color = $this->util->elementColor($this->themingDefaults->getMailHeaderColor());
namespace OCA\Theming;
+use OCP\App\AppPathNotFoundException;
+use OCP\App\IAppManager;
use OCP\IConfig;
use OCP\Files\IRootFolder;
/** @var IRootFolder */
private $rootFolder;
+ /** @var IAppManager */
+ private $appManager;
+
/**
* Util constructor.
*
* @param IConfig $config
* @param IRootFolder $rootFolder
+ * @param IAppManager $appManager
*/
- public function __construct(IConfig $config, IRootFolder $rootFolder) {
+ public function __construct(IConfig $config, IRootFolder $rootFolder, IAppManager $appManager) {
$this->config = $config;
$this->rootFolder = $rootFolder;
+ $this->appManager = $appManager;
}
/**
*/
public function getAppIcon($app) {
$app = str_replace(array('\0', '/', '\\', '..'), '', $app);
- $appPath = \OC_App::getAppPath($app);
- if ($appPath !== false) {
+ try {
+ $appPath = $this->appManager->getAppPath($app);
$icon = $appPath . '/img/' . $app . '.svg';
if (file_exists($icon)) {
return $icon;
if (file_exists($icon)) {
return $icon;
}
- }
+ } catch (AppPathNotFoundException $e) {}
+
if($this->config->getAppValue('theming', 'logoMime', '') !== '' && $this->rootFolder->nodeExists('/themedinstancelogo')) {
return $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data/') . '/themedinstancelogo';
}
/**
* @param $app string app name
* @param $image string relative path to image in app folder
- * @return string absolute path to image
+ * @return string|false absolute path to image
*/
public function getAppImage($app, $image) {
$app = str_replace(array('\0', '/', '\\', '..'), '', $app);
$image = str_replace(array('\0', '\\', '..'), '', $image);
- $appPath = \OC_App::getAppPath($app);
- if ($app === "core") {
- $icon = \OC::$SERVERROOT . '/core/img/' . $image;
- if (file_exists($icon)) {
- return $icon;
- }
- }
- if ($appPath !== false) {
- $icon = $appPath . '/img/' . $image;
- if (file_exists($icon)) {
- return $icon;
- }
- $icon = $appPath . '/img/' . $image . '.svg';
- if (file_exists($icon)) {
- return $icon;
- }
- $icon = $appPath . '/img/' . $image . '.png';
- if (file_exists($icon)) {
- return $icon;
- }
- $icon = $appPath . '/img/' . $image . '.gif';
- if (file_exists($icon)) {
- return $icon;
- }
- $icon = $appPath . '/img/' . $image . '.jpg';
+ if ($app === "core") {
+ $icon = \OC::$SERVERROOT . '/core/img/' . $image;
if (file_exists($icon)) {
return $icon;
}
}
+
+ try {
+ $appPath = $this->appManager->getAppPath($app);
+ } catch (AppPathNotFoundException $e) {
+ return false;
+ }
+
+ $icon = $appPath . '/img/' . $image;
+ if (file_exists($icon)) {
+ return $icon;
+ }
+ $icon = $appPath . '/img/' . $image . '.svg';
+ if (file_exists($icon)) {
+ return $icon;
+ }
+ $icon = $appPath . '/img/' . $image . '.png';
+ if (file_exists($icon)) {
+ return $icon;
+ }
+ $icon = $appPath . '/img/' . $image . '.gif';
+ if (file_exists($icon)) {
+ return $icon;
+ }
+ $icon = $appPath . '/img/' . $image . '.jpg';
+ if (file_exists($icon)) {
+ return $icon;
+ }
+
return false;
}
use OCA\Theming\Controller\ThemingController;
use OCA\Theming\Util;
+use OCP\App\IAppManager;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\DataResponse;
use OCP\Files\IRootFolder;
private $rootFolder;
/** @var ITempManager */
private $tempManager;
+ /** @var IAppManager */
+ private $appManager;
public function setUp() {
$this->request = $this->getMockBuilder('OCP\IRequest')->getMock();
->getMock();
$this->l10n = $this->getMockBuilder('OCP\IL10N')->getMock();
$this->rootFolder = $this->getMockBuilder('OCP\Files\IRootFolder')->getMock();
- $this->util = new Util($this->config, $this->rootFolder);
+ $this->appManager = $this->getMockBuilder('OCP\App\IAppManager')->getMock();
+ $this->util = new Util($this->config, $this->rootFolder, $this->appManager);
$this->timeFactory->expects($this->any())
->method('getTime')
->willReturn(123);
use OCA\Theming\IconBuilder;
use OCA\Theming\ThemingDefaults;
use OCA\Theming\Util;
+use OCP\App\IAppManager;
use OCP\AppFramework\Http\NotFoundResponse;
use OCP\Files\IRootFolder;
use OCP\IConfig;
protected $util;
/** @var IconBuilder */
protected $iconBuilder;
+ /** @var IAppManager */
+ protected $appManager;
protected function setUp() {
parent::setUp();
$this->rootFolder = $this->getMockBuilder('OCP\Files\IRootFolder')->getMock();
$this->themingDefaults = $this->getMockBuilder('OCA\Theming\ThemingDefaults')
->disableOriginalConstructor()->getMock();
- $this->util = new Util($this->config, $this->rootFolder);
+ $this->appManager = $this->getMockBuilder('OCP\App\IAppManager')->getMock();
+ $this->util = new Util($this->config, $this->rootFolder, $this->appManager);
$this->iconBuilder = new IconBuilder($this->themingDefaults, $this->util);
}
namespace OCA\Theming\Tests;
use OCA\Theming\Util;
+use OCP\App\IAppManager;
use OCP\IConfig;
use OCP\Files\IRootFolder;
use Test\TestCase;
protected $config;
/** @var IRootFolder */
protected $rootFolder;
+ /** @var IAppManager */
+ protected $appManager;
protected function setUp() {
parent::setUp();
$this->config = $this->getMockBuilder('\OCP\IConfig')->getMock();
$this->rootFolder = $this->getMockBuilder('OCP\Files\IRootFolder')->getMock();
- $this->util = new Util($this->config, $this->rootFolder);
+ $this->appManager = $this->getMockBuilder('OCP\App\IAppManager')->getMock();
+ $this->util = new Util($this->config, $this->rootFolder, $this->appManager);
}
public function testInvertTextColorLight() {
* @dataProvider dataGetAppIcon
*/
public function testGetAppIcon($app, $expected) {
+ $this->appManager->expects($this->once())
+ ->method('getAppPath')
+ ->with($app)
+ ->willReturn(\OC_App::getAppPath($app));
$icon = $this->util->getAppIcon($app);
$this->assertEquals($expected, $icon);
}
* @dataProvider dataGetAppImage
*/
public function testGetAppImage($app, $image, $expected) {
+ if($app !== 'core') {
+ $this->appManager->expects($this->once())
+ ->method('getAppPath')
+ ->with($app)
+ ->willReturn(\OC_App::getAppPath($app));
+ }
$this->assertEquals($expected, $this->util->getAppImage($app, $image));
}