Skip to content

Commit c36e858

Browse files
committed
First commit
1 parent 1db0a37 commit c36e858

File tree

138 files changed

+13370
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

138 files changed

+13370
-0
lines changed

INSTALL.TXT

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Installation Instructions
2+
3+
1. Unzip this file in your site's packages/ directory.
4+
2. Login to your site as an administrator.
5+
3. Find the "Add Functionality" page in your dashboard.
6+
4. Find this package in the list of packages awaiting installation.
7+
5. Click the "install" button.

MIT-LICENSE.TXT

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Copyright 2018 Nour Akalay
2+
3+
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6+
7+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8+
9+
10+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

controller.php

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
<?php
2+
namespace Concrete\Package\KalmoyaElementalCloner;
3+
4+
defined('C5_EXECUTE') or die('Access denied.');
5+
6+
use Concrete\Core\Page\Page;
7+
use Concrete\Core\Package\Package;
8+
use Concrete\Core\Support\Facade\Route;
9+
use Concrete\Core\Block\BlockType\BlockType;
10+
use Concrete\Core\Page\Single as SinglePage;
11+
12+
class Controller extends Package
13+
{
14+
protected $pkgHandle = 'kalmoya_elemental_cloner';
15+
protected $appVersionRequired = '8.0.0';
16+
protected $pkgVersion = '1.0';
17+
18+
protected $pkgAutoloaderRegistries = [
19+
'vendor/kalmoya' => '\ElClKalmoya',
20+
'src/ElementalCloner' => '\KalmoyaElementalCloner',
21+
];
22+
23+
public function getPackageName()
24+
{
25+
return t('Elemental Cloner');
26+
}
27+
28+
public function getPackageDescription()
29+
{
30+
return t("Easily clone Elemental as a new theme anytime you like %s Developed by Nour Akalay @ %sKALMOYA - bespoke Concrete5 development%s", '<br /><span style="font-size:11px;">', '<a target="_blank" href="https://www.kalmoya.com">', '</a></span>');
31+
}
32+
33+
public function on_start()
34+
{
35+
define(ELEMENTAL_CLONER_PACKAGE_HANDLE, $this->pkgHandle);
36+
Route::register(
37+
'/elementalcloner/uploadThumb',
38+
'\KalmoyaElementalCloner\ThumbnailUploader::uploadThumb'
39+
);
40+
}
41+
42+
public function install()
43+
{
44+
$pkg = parent::install();
45+
46+
$this->installPages($pkg);
47+
}
48+
49+
public function upgrade()
50+
{
51+
$pkg = Package::getByHandle($this->pkgHandle);
52+
parent::upgrade();
53+
54+
$this->installPages($pkg);
55+
}
56+
57+
protected function installPages($pkg)
58+
{
59+
$singlePages = [
60+
[
61+
'path' => '/dashboard/pages/elemental_cloner',
62+
'cName' => t('Elemental Cloner'),
63+
],
64+
];
65+
66+
foreach ($singlePages as $singlePage) {
67+
$singlePageObject = Page::getByPath($singlePage['path']);
68+
// Check if it exists, if not, add it
69+
if ($singlePageObject->isError() || (!is_object($singlePageObject))) {
70+
$sp = SinglePage::add($singlePage['path'], $pkg);
71+
unset($singlePage['path']);
72+
if (!empty($singlePage)) {
73+
// And make sure we update the page with the remaining values
74+
$sp->update($singlePage);
75+
}
76+
}
77+
}
78+
}
79+
}
Lines changed: 261 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,261 @@
1+
<?php
2+
namespace Concrete\Package\KalmoyaElementalCloner\Controller\SinglePage\Dashboard\Pages;
3+
4+
defined('C5_EXECUTE') or die("Access Denied.");
5+
6+
use stdClass;
7+
use Exception;
8+
use ElClKalmoya\KalmoyaInfo as Kalmoya;
9+
use Concrete\Core\Foundation\Queue\Queue;
10+
use Concrete\Core\Page\Controller\DashboardPageController;
11+
use KalmoyaElementalCloner\ElementalClonerTool;
12+
13+
class ElementalCloner extends DashboardPageController
14+
{
15+
protected $settingsManager = false;
16+
17+
public function on_start()
18+
{
19+
$kalmoya = new Kalmoya(ELEMENTAL_CLONER_PACKAGE_HANDLE);
20+
$this->set('kalmoya', $kalmoya->getJSONKalmoya());
21+
}
22+
23+
public function run()
24+
{
25+
try {
26+
$token = $this->request->request->get('ccm_token');
27+
28+
$response = new stdClass();
29+
30+
$q = Queue::get('create_elemental_clone');
31+
$process = $this->request->request->get('process');
32+
33+
if (empty($process) && ($q->count() > 0)) {
34+
$q->deleteQueue();
35+
$q = Queue::get('create_elemental_clone');
36+
}
37+
38+
if ($process) {
39+
$messages = $q->receive(1);
40+
41+
foreach ($messages as $key => $msg) {
42+
$task = unserialize($msg->body);
43+
44+
$err = $this->validate($task);
45+
if ($err->has()) {
46+
throw new Exception($err);
47+
}
48+
49+
$response->action = $task['nextAction'];
50+
$response->actionNbr = (int) $task['actionNbr'] + 1;
51+
$response->totalActions = $this->request->request->get('totalActions');
52+
53+
if (!empty($task['action'])) {
54+
$settings = [
55+
'handle' => $task['handle'],
56+
'action' => $task['action'],
57+
'token' => $token,
58+
'name' => $task['name'],
59+
'description' => $task['description'],
60+
'thumbSource' => $task['thumbSource'],
61+
'googleFonts' => $task['googleFonts'],
62+
'fID' => $task['fID'],
63+
'filename' => $task['filename'],
64+
];
65+
66+
$cloner = $this->app->make(
67+
ElementalClonerTool::class,
68+
['settings' => $settings]
69+
);
70+
71+
$ret = $cloner->process(empty($task['nextAction']));
72+
73+
if (!$ret) {
74+
throw new Exception(t("WOW! Something was not right at all. Try again maybe?"));
75+
}
76+
}
77+
78+
if (empty($task['nextAction'])) {
79+
$response->successTitle = t("Theme Clonaging Complete!");
80+
$successMessage = [];
81+
$successMessage[] = '<ul>';
82+
$successMessage[] = t("%sYour theme was cloned successfully.%s", '<li>', '</li>');
83+
$successMessage[] = t("%sIt was renamed and customized.%s", '<li>', '</li>');
84+
85+
if (!empty($task['fID']) || !empty($task['filename'])) {
86+
$successMessage[] = t(
87+
"%sA gorgeous new thumbnail was set.%s",
88+
'<li>',
89+
'</li>'
90+
);
91+
}
92+
93+
if ('local' === $task['googleFonts']) {
94+
$successMessage[] = t(
95+
"%sAnd your Google fonts will be loaded from your server.%s",
96+
'<li>',
97+
'</li>'
98+
);
99+
}
100+
$successMessage[] = '</ul>';
101+
102+
$response->successMessage = implode(' ', $successMessage);
103+
}
104+
105+
$q->deleteMessage($msg);
106+
}
107+
108+
if (0 == $q->count()) {
109+
$q->deleteQueue();
110+
}
111+
112+
echo json_encode($response);
113+
exit;
114+
} elseif (0 == $q->count()) {
115+
$valt = $this->app->make('token');
116+
117+
if (!$valt->validate('create_elemental_clone', $token)) {
118+
throw new Exception(t("This is embarassing! Could you reload the page and try again please?"));
119+
}
120+
121+
$txt = $this->app->make('helper/text');
122+
$handle = $this->request->request->get('themeHandle');
123+
$filename = $this->request->request->get('filename');
124+
$fID = $this->request->request->get('fID');
125+
$thumbSource = $this->request->request->get('thumbSource');
126+
$googleFonts = $this->request->request->get('googleFonts');
127+
$name = $this->request->request->get('themeName');
128+
$name = empty($name) ? $txt->unhandle($handle) : $name;
129+
$description = $this->request->request->get('themeDescription');
130+
$totalActions = 2;
131+
132+
$queueData = [
133+
'name' => $name,
134+
'handle' => $handle,
135+
'description' => $description,
136+
'thumbSource' => $thumbSource,
137+
'googleFonts' => $googleFonts,
138+
'fID' => $fID,
139+
'filename' => $filename,
140+
];
141+
142+
switch ($thumbSource) {
143+
case 'upload':
144+
$fID = null;
145+
break;
146+
case 'manager':
147+
$filename = null;
148+
break;
149+
default:
150+
$filename = null;
151+
$fD = null;
152+
break;
153+
}
154+
155+
$q->send(
156+
serialize(
157+
array_merge(
158+
[
159+
'action' => 'clone',
160+
'nextAction' => 'customize',
161+
'actionNbr' => 1,
162+
],
163+
$queueData
164+
)
165+
)
166+
);
167+
168+
if ('local' === $googleFonts) {
169+
$nextAction = 'googleFonts';
170+
} elseif (!empty($filename) || !empty($fID)) {
171+
$nextAction = 'thumb';
172+
} else {
173+
$nextAction = null;
174+
}
175+
176+
$q->send(
177+
serialize(
178+
array_merge(
179+
[
180+
'action' => 'customize',
181+
'nextAction' => $nextAction,
182+
'actionNbr' => 2,
183+
],
184+
$queueData
185+
)
186+
)
187+
);
188+
189+
if ('local' === $googleFonts) {
190+
if (!empty($filename) || !empty($fID)) {
191+
$nextAction = 'thumb';
192+
} else {
193+
$nextAction = null;
194+
}
195+
++$totalActions;
196+
197+
$q->send(
198+
serialize(
199+
array_merge(
200+
[
201+
'action' => 'googleFonts',
202+
'nextAction' => $nextAction,
203+
'actionNbr' => $totalActions,
204+
],
205+
$queueData
206+
)
207+
)
208+
);
209+
}
210+
211+
if (!empty($filename) || !empty($fID)) {
212+
++$totalActions;
213+
214+
$q->send(
215+
serialize(
216+
array_merge(
217+
[
218+
'action' => 'thumb',
219+
'nextAction' => null,
220+
'actionNbr' => $totalActions,
221+
],
222+
$queueData
223+
)
224+
)
225+
);
226+
}
227+
228+
$response->action = 'clone';
229+
$response->actionNbr = 1;
230+
$response->totalActions = $totalActions;
231+
232+
echo json_encode($response);
233+
exit;
234+
}
235+
} catch (Exception $e) {
236+
$q->deleteQueue();
237+
$resp = new stdClass();
238+
$resp->error = true;
239+
$resp->errors = [(string) $e->getMessage()];
240+
echo json_encode($resp);
241+
242+
exit;
243+
}
244+
}
245+
246+
public function validate($args)
247+
{
248+
$e = $this->app->make('helper/validation/error');
249+
$vals = $this->app->make('helper/validation/strings');
250+
251+
if (!$vals->notEmpty($args['handle'])) {
252+
$e->add(t("A theme handle is required."));
253+
}
254+
255+
if ($vals->notEmpty($args['handle']) && !$vals->handle($args['handle'])) {
256+
$e->add(t("Theme handles may only contain letters, numbers and underscore %s_%s characters", '&ldquo;', '&rdquo;'));
257+
}
258+
259+
return $e;
260+
}
261+
}

0 commit comments

Comments
 (0)