From c3da644617894b215fcb23a839f92bb9df8cbd80 Mon Sep 17 00:00:00 2001 From: Kris Arnold Date: Mon, 15 Sep 2014 16:36:05 -0500 Subject: [PATCH 01/31] fixed paths in unit tests. --- modules/cms/classes/Controller.php | 2 +- tests/unit/cms/classes/CombineAssetsTest.php | 6 +++--- tests/unit/cms/classes/ComponentManagerTest.php | 10 +++++----- tests/unit/cms/classes/ControllerTest.php | 6 +++--- tests/unit/cms/classes/FileHelperTest.php | 8 ++++---- tests/unit/cms/classes/ThemeTest.php | 4 ++-- 6 files changed, 18 insertions(+), 18 deletions(-) diff --git a/modules/cms/classes/Controller.php b/modules/cms/classes/Controller.php index 67a974799..78f9589ac 100644 --- a/modules/cms/classes/Controller.php +++ b/modules/cms/classes/Controller.php @@ -1001,4 +1001,4 @@ class Controller extends BaseController // return null; // } -} \ No newline at end of file +} diff --git a/tests/unit/cms/classes/CombineAssetsTest.php b/tests/unit/cms/classes/CombineAssetsTest.php index ad49107be..27ca1f2db 100644 --- a/tests/unit/cms/classes/CombineAssetsTest.php +++ b/tests/unit/cms/classes/CombineAssetsTest.php @@ -68,11 +68,11 @@ class CombineAssetsTest extends TestCase public function testCombine() { $combiner = new CombineAssets; - $url = $combiner->combine(['assets/css/style1.css', 'assets/css/style2.css'], '/tests/fixtures/Cms/themes/test'); + $url = $combiner->combine(['assets/css/style1.css', 'assets/css/style2.css'], '/tests/fixtures/cms/themes/test'); $this->assertNotNull($url); $this->assertRegExp('/\w+[-]\d+/i', $url); // Must contain hash-number - $url = $combiner->combine(['assets/js/script1.js', 'assets/js/script2.js'], '/tests/fixtures/Cms/themes/test'); + $url = $combiner->combine(['assets/js/script1.js', 'assets/js/script2.js'], '/tests/fixtures/cms/themes/test'); $this->assertNotNull($url); $this->assertRegExp('/\w+[-]\d+/i', $url); // Must contain hash-number } @@ -174,4 +174,4 @@ class CombineAssetsTest extends TestCase $this->assertEquals("The combiner file 'xxx' is not found.", $response->getOriginalContent()); } -} \ No newline at end of file +} diff --git a/tests/unit/cms/classes/ComponentManagerTest.php b/tests/unit/cms/classes/ComponentManagerTest.php index cc5f8a6b4..acacfac80 100644 --- a/tests/unit/cms/classes/ComponentManagerTest.php +++ b/tests/unit/cms/classes/ComponentManagerTest.php @@ -20,8 +20,8 @@ class ComponentManagerTest extends TestCase public function testListComponentDetails() { - include_once base_path() . '/tests/fixtures/System/plugins/October/Test/Components/Archive.php'; - include_once base_path() . '/tests/fixtures/System/plugins/October/Test/Components/Post.php'; + include_once base_path() . '/tests/fixtures/system/plugins/october/test/components/Archive.php'; + include_once base_path() . '/tests/fixtures/system/plugins/october/test/components/Post.php'; $manager = ComponentManager::instance(); $components = $manager->listComponentDetails(); @@ -71,7 +71,7 @@ class ComponentManagerTest extends TestCase public function testMakeComponent() { - include_once base_path() . '/tests/fixtures/System/plugins/October/Test/Components/Archive.php'; + include_once base_path() . '/tests/fixtures/system/plugins/october/test/components/Archive.php'; $pageObj = $this->spoofPageCode(); @@ -90,7 +90,7 @@ class ComponentManagerTest extends TestCase public function testDefineProperties() { - include_once base_path() . '/tests/fixtures/System/plugins/October/Test/Components/Archive.php'; + include_once base_path() . '/tests/fixtures/system/plugins/october/test/components/Archive.php'; $manager = ComponentManager::instance(); $object = $manager->makeComponent('testArchive'); $details = $object->componentDetails(); @@ -113,4 +113,4 @@ class ComponentManagerTest extends TestCase $pageObj = $parser->source($page, $layout, $controller); return $pageObj; } -} \ No newline at end of file +} diff --git a/tests/unit/cms/classes/ControllerTest.php b/tests/unit/cms/classes/ControllerTest.php index 121df73a5..1d809e2c5 100644 --- a/tests/unit/cms/classes/ControllerTest.php +++ b/tests/unit/cms/classes/ControllerTest.php @@ -299,7 +299,7 @@ ESC; public function testComponentAliases() { - include_once base_path() . '/tests/fixtures/System/plugins/October/Test/Components/Archive.php'; + include_once base_path() . '/tests/fixtures/system/plugins/october/test/components/Archive.php'; $theme = new Theme(); $theme->load('test'); @@ -359,11 +359,11 @@ ESC; $url = $controller->themeUrl(['assets/css/style1.css', 'assets/css/style2.css']); $url = substr($url, 0, strpos($url, '-')); - $this->assertEquals('/combine/88634b8fa6f4f6442ce830d38296640a', $url); + $this->assertEquals('/combine/adec0b826d103d671ab88a38b65734d7', $url); $url = $controller->themeUrl(['assets/js/script1.js', 'assets/js/script2.js']); $url = substr($url, 0, strpos($url, '-')); - $this->assertEquals('/combine/860afc990164a60a8e90682d04da27ee', $url); + $this->assertEquals('/combine/0b07ee67e15e6985d289c34b67d1a8e2', $url); } } diff --git a/tests/unit/cms/classes/FileHelperTest.php b/tests/unit/cms/classes/FileHelperTest.php index ba50d1907..2b9075ea1 100644 --- a/tests/unit/cms/classes/FileHelperTest.php +++ b/tests/unit/cms/classes/FileHelperTest.php @@ -23,7 +23,7 @@ class FileHelperTest extends TestCase 'var2'=>'value 21' ]; - $path = base_path().'/tests/fixtures/Cms/filehelper/simple.ini'; + $path = base_path().'/tests/fixtures/cms/filehelper/simple.ini'; $this->assertFileExists($path); $str = FileHelper::formatIniString($data); @@ -43,7 +43,7 @@ class FileHelperTest extends TestCase 'var2'=>'value 21' ]; - $path = base_path().'/tests/fixtures/Cms/filehelper/sections.ini'; + $path = base_path().'/tests/fixtures/cms/filehelper/sections.ini'; $this->assertFileExists($path); $str = FileHelper::formatIniString($data); @@ -71,10 +71,10 @@ class FileHelperTest extends TestCase 'var2'=>'value 21' ]; - $path = base_path().'/tests/fixtures/Cms/filehelper/subsections.ini'; + $path = base_path().'/tests/fixtures/cms/filehelper/subsections.ini'; $this->assertFileExists($path); $str = FileHelper::formatIniString($data); $this->assertEquals(file_get_contents($path), $str); } -} \ No newline at end of file +} diff --git a/tests/unit/cms/classes/ThemeTest.php b/tests/unit/cms/classes/ThemeTest.php index 28ae2fe63..dc148b977 100644 --- a/tests/unit/cms/classes/ThemeTest.php +++ b/tests/unit/cms/classes/ThemeTest.php @@ -43,7 +43,7 @@ class ThemeTest extends TestCase $pages = $theme->listPages(); $this->assertInternalType('array', $pages); - $expectedPageNum = $this->countThemePages(base_path().'/tests/fixtures/Cms/themes/test/pages'); + $expectedPageNum = $this->countThemePages(base_path().'/tests/fixtures/cms/themes/test/pages'); $this->assertEquals($expectedPageNum, count($pages)); $this->assertInstanceOf('\Cms\Classes\Page', $pages[0]); @@ -79,4 +79,4 @@ class ThemeTest extends TestCase $this->assertNotNull($activeTheme); $this->assertEquals('apitest', $activeTheme->getDirName()); } -} \ No newline at end of file +} From 23710dbbc30d6e34cbdaf0cdf99041695de77284 Mon Sep 17 00:00:00 2001 From: Sam Georges Date: Fri, 19 Sep 2014 17:21:33 +1000 Subject: [PATCH 02/31] No longer lower case partial override component alias Att: @chadstrat --- modules/cms/classes/Controller.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/cms/classes/Controller.php b/modules/cms/classes/Controller.php index 3a0de1479..6114de24e 100644 --- a/modules/cms/classes/Controller.php +++ b/modules/cms/classes/Controller.php @@ -646,7 +646,7 @@ class Controller extends BaseController * Check if the theme has an override */ if (strpos($partialName, '/') === false) { - $overrideName = strtolower($componentObj->alias) . '/' . $partialName; + $overrideName = $componentObj->alias . '/' . $partialName; $partial = Partial::loadCached($this->theme, $overrideName); } From 5cd9f30ea2a751e47e7a2da88f7f89fb3f3729b3 Mon Sep 17 00:00:00 2001 From: Sam Georges Date: Fri, 19 Sep 2014 17:22:11 +1000 Subject: [PATCH 03/31] Exception handling when plugins/ dir missing --- modules/system/classes/PluginManager.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/modules/system/classes/PluginManager.php b/modules/system/classes/PluginManager.php index 147c19ed9..9c6a5ad7b 100644 --- a/modules/system/classes/PluginManager.php +++ b/modules/system/classes/PluginManager.php @@ -297,11 +297,14 @@ class PluginManager $plugins = []; $dirPath = $this->getPath(); + if (!File::isDirectory($dirPath)) + return $plugins; + $it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dirPath)); $it->setMaxDepth(2); $it->rewind(); - while($it->valid()) { + while ($it->valid()) { if (($it->getDepth() > 1) && $it->isFile() && (strtolower($it->getFilename()) == "plugin.php")) { $filePath = dirname($it->getPathname()); $pluginName = basename($filePath); From ffc1a8490a64aa77d48c916844c0e992f461ce46 Mon Sep 17 00:00:00 2001 From: Sam Georges Date: Fri, 19 Sep 2014 17:22:44 +1000 Subject: [PATCH 04/31] Convert autoload refs to PSR-4 so they actually work --- modules/backend/composer.json | 4 ++-- modules/cms/composer.json | 4 ++-- modules/system/composer.json | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/modules/backend/composer.json b/modules/backend/composer.json index 32560e89c..4e4289b34 100644 --- a/modules/backend/composer.json +++ b/modules/backend/composer.json @@ -21,8 +21,8 @@ "october/rain": "~1.0" }, "autoload": { - "psr-0": { - "Backend": "" + "psr-4": { + "Backend\\": "" } }, "extra": { diff --git a/modules/cms/composer.json b/modules/cms/composer.json index 608865aac..df31cf58e 100644 --- a/modules/cms/composer.json +++ b/modules/cms/composer.json @@ -21,8 +21,8 @@ "october/rain": "~1.0" }, "autoload": { - "psr-0": { - "Cms": "" + "psr-4": { + "Cms\\": "" } }, "extra": { diff --git a/modules/system/composer.json b/modules/system/composer.json index 68275400f..1665f8262 100644 --- a/modules/system/composer.json +++ b/modules/system/composer.json @@ -21,8 +21,8 @@ "october/rain": "~1.0" }, "autoload": { - "psr-0": { - "System": "" + "psr-4": { + "System\\": "" } }, "extra": { From f86e1f6054837b7f329356b07ff24ef727ea3960 Mon Sep 17 00:00:00 2001 From: Sam Georges Date: Fri, 19 Sep 2014 18:23:45 +1000 Subject: [PATCH 05/31] Add composer files for demo plugin and theme, not sure where these are ignored? --- plugins/october/demo/composer.json | 33 ++++++++++++++++++++++++++++++ themes/demo/composer.json | 27 ++++++++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 plugins/october/demo/composer.json create mode 100644 themes/demo/composer.json diff --git a/plugins/october/demo/composer.json b/plugins/october/demo/composer.json new file mode 100644 index 000000000..bfddf52f1 --- /dev/null +++ b/plugins/october/demo/composer.json @@ -0,0 +1,33 @@ +{ + "name": "october/demo-plugin", + "type": "october-plugin", + "description": "Demo OctoberCMS plugin", + "keywords": ["october", "cms", "demo", "plugin"], + "license": "MIT", + + "authors": [ + { + "name": "Alexey Bobkov", + "email": "aleksey.bobkov@gmail.com", + "role": "Co-founder" + }, + { + "name": "Samuel Georges", + "email": "daftspunky@gmail.com", + "role": "Co-founder" + } + ], + "require": { + "php": ">=5.4", + }, + "autoload": { + "psr-4": { + "October\\Demo\\": "" + } + }, + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" + } + } +} \ No newline at end of file diff --git a/themes/demo/composer.json b/themes/demo/composer.json new file mode 100644 index 000000000..f4188e2a8 --- /dev/null +++ b/themes/demo/composer.json @@ -0,0 +1,27 @@ +{ + "name": "october/demo-theme", + "type": "october-theme", + "description": "Demo OctoberCMS theme", + "keywords": ["october", "cms", "demo", "theme"], + "license": "MIT", + "authors": [ + { + "name": "Alexey Bobkov", + "email": "aleksey.bobkov@gmail.com", + "role": "Co-founder" + }, + { + "name": "Samuel Georges", + "email": "daftspunky@gmail.com", + "role": "Co-founder" + } + ], + "require": { + "php": ">=5.4", + }, + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" + } + } +} \ No newline at end of file From 0ca9c3847b0c4a689e6c7c45665fa9a2b577fbd7 Mon Sep 17 00:00:00 2001 From: Sam Georges Date: Fri, 19 Sep 2014 19:42:39 +1000 Subject: [PATCH 06/31] Typos --- plugins/october/demo/composer.json | 2 +- themes/demo/composer.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/october/demo/composer.json b/plugins/october/demo/composer.json index bfddf52f1..d46dd6acd 100644 --- a/plugins/october/demo/composer.json +++ b/plugins/october/demo/composer.json @@ -18,7 +18,7 @@ } ], "require": { - "php": ">=5.4", + "php": ">=5.4" }, "autoload": { "psr-4": { diff --git a/themes/demo/composer.json b/themes/demo/composer.json index f4188e2a8..fae4c1d4c 100644 --- a/themes/demo/composer.json +++ b/themes/demo/composer.json @@ -17,7 +17,7 @@ } ], "require": { - "php": ">=5.4", + "php": ">=5.4" }, "extra": { "branch-alias": { From 6cc36d39f20d1f641b1130f730c503e4b6ac99ae Mon Sep 17 00:00:00 2001 From: Sam Georges Date: Sat, 20 Sep 2014 10:14:43 +1000 Subject: [PATCH 07/31] Refs #623 - Add persian map to inputpreset --- modules/backend/assets/js/october.inputpreset.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/modules/backend/assets/js/october.inputpreset.js b/modules/backend/assets/js/october.inputpreset.js index 21b04926b..11ab61b83 100644 --- a/modules/backend/assets/js/october.inputpreset.js +++ b/modules/backend/assets/js/october.inputpreset.js @@ -86,6 +86,9 @@ 'ظ':'th', 'ع':'aa', 'غ':'gh', 'ف':'f', 'ق':'k', 'ك':'k', 'ل':'l', 'م':'m', 'ن':'n', 'ه':'h', 'و':'o', 'ي':'y' }, + PERSIAN_MAP = { + 'آ':'a', 'ا':'a', 'پ':'p', 'چ':'ch', 'ژ':'zh', 'ک':'k', 'گ':'gh', 'ی':'y' + }, LITHUANIAN_MAP = { 'ą':'a', 'č':'c', 'ę':'e', 'ė':'e', 'į':'i', 'š':'s', 'ų':'u', 'ū':'u', 'ž':'z', @@ -111,6 +114,7 @@ POLISH_MAP, LATVIAN_MAP, ARABIC_MAP, + PERSIAN_MAP, LITHUANIAN_MAP, SERBIAN_MAP, AZERBAIJANI_MAP From 65573da89be71110af2340c45da60d7490576b5c Mon Sep 17 00:00:00 2001 From: Sam Georges Date: Sat, 20 Sep 2014 11:25:57 +1000 Subject: [PATCH 08/31] Add the ability to override backend assets and layouts using a Skin --- modules/backend/classes/BackendHelper.php | 6 +- modules/backend/classes/Controller.php | 2 +- modules/backend/classes/Skin.php | 73 ++++++++++++- modules/backend/layouts/_head.htm | 126 +++++++++++----------- modules/backend/layouts/default.htm | 2 +- modules/backend/skins/Standard.php | 35 +++++- 6 files changed, 173 insertions(+), 71 deletions(-) diff --git a/modules/backend/classes/BackendHelper.php b/modules/backend/classes/BackendHelper.php index cc1a8b5db..60dfd700e 100644 --- a/modules/backend/classes/BackendHelper.php +++ b/modules/backend/classes/BackendHelper.php @@ -2,7 +2,6 @@ use URL; use Config; -use Session; use Request; use October\Rain\Router\Helper as RouterHelper; @@ -29,9 +28,8 @@ class BackendHelper */ public function skinAsset($path = null) { - $path = RouterHelper::normalizeUrl($path); - $skinPath = Skin::getActive()->skinPath; - return URL::asset($skinPath . $path); + $skinPath = Skin::getActive()->getPath($path, true); + return URL::asset($skinPath); } /** diff --git a/modules/backend/classes/Controller.php b/modules/backend/classes/Controller.php index dee0402d9..b4dcd6b8a 100644 --- a/modules/backend/classes/Controller.php +++ b/modules/backend/classes/Controller.php @@ -127,7 +127,7 @@ class Controller extends Extendable * Define layout and view paths */ $this->layout = 'default'; - $this->layoutPath = ['modules/backend/layouts']; + $this->layoutPath = Skin::getActive()->getLayoutPaths(); // Option A: (@todo Determine which is faster by benchmark) // $relativePath = strtolower(str_replace('\\', '/', get_called_class())); diff --git a/modules/backend/classes/Skin.php b/modules/backend/classes/Skin.php index e2ded69a6..501066f20 100644 --- a/modules/backend/classes/Skin.php +++ b/modules/backend/classes/Skin.php @@ -1,6 +1,9 @@ skinPath = str_replace('\\', '/', get_called_class()); + $this->defaultSkinPath = PATH_BASE . '/modules/backend'; + + /* + * Guess the skin path + */ + $class = get_called_class(); + $classFolder = strtolower(Str::getRealClass($class)); + $classFile = realpath(dirname(File::fromClass($class))); + $this->skinPath = $classFile + ? $classFile . '/' . $classFolder + : $this->defaultSkinPath; + + $this->publicSkinPath = File::localToPublic($this->skinPath); + $this->defaultPublicSkinPath = File::localToPublic($this->defaultSkinPath); + + traceLog($this->skinPath); + } + + /** + * Looks up a path to a skin-based file, if it doesn't exist, the default path is used. + * @param string $path + * @param boolean $isPublic + * @return string + */ + public function getPath($path = null, $isPublic = false) + { + $path = RouterHelper::normalizeUrl($path); + $assetFile = $this->skinPath . $path; + + if (File::isFile($assetFile)) { + return $isPublic + ? $this->publicSkinPath . $path + : $this->skinPath . $path; + } + else { + return $isPublic + ? $this->defaultPublicSkinPath . $path + : $this->defaultSkinPath . $path; + } + } + + /** + * Returns an array of paths where skin layouts can be found. + * @return array + */ + public function getLayoutPaths() + { + return [$this->skinPath.'/layouts', $this->defaultSkinPath.'/layouts']; } /** diff --git a/modules/backend/layouts/_head.htm b/modules/backend/layouts/_head.htm index 178b8fc56..6110f8f23 100644 --- a/modules/backend/layouts/_head.htm +++ b/modules/backend/layouts/_head.htm @@ -1,78 +1,78 @@ - + <?= $this->pageTitle ?> | October CMS - - + + - - - - - - - - - - - + + + + + + + + + + + - - - - + + + + - - - - - + + + + + - - - - + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +