Skip to content

Commit 1fc0280

Browse files
JS bug fix on non jd builder pages
1 parent ffee845 commit 1fc0280

File tree

7 files changed

+126
-9
lines changed

7 files changed

+126
-9
lines changed

com_jdbuilder/jdbuilder.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<author>Team Joomdev</author>
99
<authorEmail>[email protected]</authorEmail>
1010
<authorUrl>https://www.joomdev.com</authorUrl>
11-
<version>1.10.0</version>
11+
<version>1.10.1</version>
1212
<description>{jdbcomdesc}</description>
1313
<install> <!-- Runs on install -->
1414
<sql>

mod_jdbuilder/mod_jdbuilder.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<authorUrl>https://www.joomdev.com</authorUrl>
88
<copyright>Copyright (C) 2020 Joomdev, Inc. All rights reserved.</copyright>
99
<license>GNU General Public License version 2 or later; see LICENSE.txt</license>
10-
<version>1.10.0</version>
10+
<version>1.10.1</version>
1111
<description>This Module allows you to create your own Module using the JD Builder.</description>
1212
<files>
1313
<filename>mod_jdbuilder.xml</filename>

pkg_jdbuilder.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<packagerurl>https://www.joomdev.com</packagerurl>
88
<author>Team JoomDev</author>
99
<creationDate>Oct 2020</creationDate>
10-
<version>1.10.0</version>
10+
<version>1.10.1</version>
1111
<url>https://www.joomdev.com</url>
1212
<copyright>Copyright (C) 2020 Joomdev, Inc. All rights reserved.</copyright>
1313
<license>GNU General Public License version 2 or later; see LICENSE.txt</license>

plg_jdbuilder/jdbuilder.php

Lines changed: 119 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function onAfterRoute()
2929
define('JDB_JOOMLA_VERSION', Helper::getJoomlaVersion());
3030
\JDPageBuilder\Builder::init($this->app);
3131
$stat = stat(JDBPATH_PLUGIN . '/jdbuilder.php');
32-
define('JDB_MEDIA_VERSION', JDB_DEV ? 109 : md5($stat['mtime']));
32+
define('JDB_MEDIA_VERSION', JDB_DEV ? 112 : md5($stat['mtime']));
3333
if ($this->app->isClient('administrator')) {
3434
$buiderConfig = JComponentHelper::getParams('com_jdbuilder');
3535

@@ -136,7 +136,7 @@ public function onBeforeRender()
136136
exit;
137137
}
138138

139-
if ($this->app->isClient('administrator') && ($this->isPageEdit() || $this->isModuleEdit())) {
139+
if ($this->app->isClient('administrator') && ($this->isPageEdit() || $this->isArticleEdit() || $this->isModuleEdit())) {
140140
\JFactory::getDocument()->addStyleDeclaration("div.modal { z-index: 99999; } .modal-backdrop { z-index: 99998; } .modal-backdrop, .modal-backdrop.fade.in{ opacity: 0.6; filter: alpha(opacity=60); background: #464646; } #JDBSelectArticleModal{ box-shadow: none !important; border: 0; border-radius: 10px; } #JDBSelectArticleModal .modal-footer{ border-radius: 0 0 10px 10px; background: #f7f7f7; box-shadow: none !important; border: 0 !important; } #JDBSelectArticleModal .modal-header{ background: #323896; border-radius: 10px 10px 0 0; padding: 5px 20px; color: #fff; letter-spacing: 1px; } #JDBSelectArticleModal .modal-header h3{ font-size: 14px;} #JDBSelectArticleModal .modal-header button.close{border: 0; color: #fff; opacity: 1; line-height: 42px; font-size: 26px;}");
141141
\JHtml::_('script', 'system/modal-fields.js', array('version' => 'auto', 'relative' => true));
142142

@@ -160,11 +160,47 @@ public function onAfterRender()
160160
if (!$this->app->isClient('administrator') || !$this->isValidView()) {
161161
return;
162162
}
163+
if ($this->isPageEdit()) {
164+
$id = $this->app->input->get('id', 0, 'INT');
165+
$this->addBuilder($id);
166+
return;
167+
}
168+
if ($this->isHikashopEdit()) {
169+
$id = $this->app->input->get('id', 0, 'INT');
170+
$this->addBuilderOnHikashop($id);
171+
return;
172+
}
163173
if ($this->isModuleEdit()) {
164174
$this->addBodyClass();
165175
}
166176
}
167177

178+
public function setLinkAndLabel()
179+
{
180+
$articleLayouts = self::$article_layouts;
181+
$body = $this->app->getBody();
182+
$body = preg_replace_callback('/(<a\s[^>]*href=")([^"]*)("[^>]*>)(.*)(<\/a>)/siU', function ($matches) use ($articleLayouts) {
183+
$html = $matches[0];
184+
if (strpos($matches[2], 'task=article.edit')) {
185+
$uri = new JUri($matches[2]);
186+
$id = (int) $uri->getVar('id');
187+
if ($uri->getVar('option') == "com_content" && in_array($id, $articleLayouts)) {
188+
$html = $matches[1] . $uri . '&jdb=1' . $matches[3] . $matches[4] . $matches[5];
189+
if (JDB_JOOMLA_VERSION == 3) {
190+
$html .= ' <span class="label label-info">JD Page</span>';
191+
} else {
192+
$html .= ' <span class="badge badge-info">JD Page</span>';
193+
}
194+
} else {
195+
$html = '<a title="' . JText::_('JDBUILDER_EDIT_TITLE') . '" class="btn btn-micro btn-sm btn-info hasTooltip" href="' . $uri . '&jdb=1' . '"><span class="icon-pencil"></span></a>';
196+
$html .= $matches[1] . $uri . $matches[3] . $matches[4] . $matches[5];
197+
}
198+
}
199+
return $html;
200+
}, $body);
201+
$this->app->setBody($body);
202+
}
203+
168204
public function onBeforeCompileHead()
169205
{
170206
$document = \JFactory::getDocument();
@@ -186,7 +222,7 @@ public function onBeforeCompileHead()
186222
$document->addStyleSheet(\JURI::root() . 'media/com_jdbuilder/css/style.min.css', ['version' => JDB_MEDIA_VERSION]);
187223
}
188224

189-
if ($this->isPageEdit() || $this->isModuleEdit()) {
225+
if ($this->isPageEdit() || $this->isArticleEdit() || $this->isModuleEdit()) {
190226
// \JDPageBuilder\Helper::loadBuilderLanguage();
191227
\JDPageBuilder\Builder::getAdminElements();
192228
$id = $this->app->input->get('id', 0);
@@ -205,7 +241,7 @@ public function onBeforeCompileHead()
205241
public function isValidView()
206242
{
207243
$option = $this->app->input->get('option', '');
208-
return ($option == "com_jdbuilder" || $option == "com_content" || $option == "com_modules" || $option == 'com_advancedmodules');
244+
return ($option == "com_jdbuilder" || $option == "com_content" || $option == "com_modules" || $option == 'com_advancedmodules' || $option == "com_hikashop");
209245
}
210246

211247
public function isPageView()
@@ -227,6 +263,19 @@ public function isSelectArtcileModal()
227263
return ($option == "com_content" && $view == "articles" && $layout == "modal" && $tmpl == 'component' && $function == 'JDBOnSelectArticle');
228264
}
229265

266+
public function isArticleEdit()
267+
{
268+
return false;
269+
}
270+
271+
public function isHikashopEdit()
272+
{
273+
$option = $this->app->input->get('option', '');
274+
$task = $this->app->input->get('task', '');
275+
$ctrl = $this->app->input->get('ctrl', '');
276+
return ($option == "com_hikashop" && $task == "edit" && $ctrl == "product");
277+
}
278+
230279
public function isModuleEdit()
231280
{
232281
$option = $this->app->input->get('option', '');
@@ -281,6 +330,30 @@ public function addBuilder($id)
281330
$this->app->setBody($body);
282331
}
283332

333+
public function addBuilderOnHikashop($id)
334+
{
335+
return;
336+
/* $article = \JTable::getInstance("content");
337+
$article->load($id);
338+
$params = new \JRegistry();
339+
if (isset($article->attribs)) {
340+
$params->loadObject(\json_decode($article->attribs));
341+
}
342+
$layout_id = $params->get('jdbuilder_layout_id', 0);
343+
$enabled = $params->get('jdbuilder_layout_enabled', 0);
344+
$enabled = $enabled ? 1 : $this->app->input->get('jdb', 0); */
345+
346+
$enabled = true;
347+
$id = 2;
348+
$layout_id = 2;
349+
$this->addBodyClass();
350+
$body = $this->app->getBody();
351+
352+
// $body = str_replace('<fieldset class="adminform">', \JDPageBuilder\Builder::builderArticleToggle($enabled, $id, $layout_id) . '<fieldset class="adminform">' . \JDPageBuilder\Builder::builderArea($enabled, 'hikashop', $layout_id), $body);
353+
$body = str_replace('<div class="hikashop_product_part_title hikashop_product_edit_description_title">Description</div>', \JDPageBuilder\Builder::builderArticleToggle($enabled, $id, $layout_id) . '<div class="hikashop_product_part_title hikashop_product_edit_description_title">Description</div>' . \JDPageBuilder\Builder::builderArea($enabled, 'article', $layout_id), $body);
354+
$this->app->setBody($body);
355+
}
356+
284357
public function addDescription()
285358
{
286359
$body = $this->app->getBody();
@@ -449,13 +522,54 @@ public function addAdminMenu()
449522
if ($layout === "edit") {
450523
$adminMenu = '<ul class="nav disabled"><li class="disabled"><a class="no-dropdown" href="#">' . \JText::_('COM_JDBUILDER') . '</a></li></ul>';
451524
} else {
452-
$adminMenu = '<ul class="nav"><li class="dropdown"><a class="dropdown-toggle" data-toggle="dropdown" href="#">' . \JText::_('COM_JDBUILDER') . '' . \JText::_('JDBUILDER_VERSION_LABEL') . '<span class="caret"></span></a><ul class="dropdown-menu scroll-menu"><li><a class="no-dropdown" href="index.php?option=com_jdbuilder&view=pages">' . \JText::_('COM_JDBUILDER_TITLE_PAGES') . '</a></li><li><a class="no-dropdown" href="index.php?option=com_categories&extension=com_jdbuilder">' . \JText::_('JCATEGORIES') . '</a></li><li><a class="no-dropdown" href="index.php?option=com_config&view=component&component=com_jdbuilder">' . \JText::_('COM_JDBUILDER_TITLE_SETTINGS') . '</a></li></ul></li></ul>';
525+
$adminMenu = '<ul class="nav"><li class="dropdown"><a class="dropdown-toggle" data-toggle="dropdown" href="#">' . \JText::_('COM_JDBUILDER') . '' . \JText::_('JDBUILDER_VERSION_LABEL') . '<span class="caret"></span></a><ul class="dropdown-menu scroll-menu"><li><a class="no-dropdown" href="index.php?option=com_jdbuilder&view=pages">' . \JText::_('COM_JDBUILDER_TITLE_PAGES') . '</a></li><li><a class="no-dropdown" href="index.php?option=com_categories&extension=com_jdbuilder">' . \JText::_('JCATEGORIES') . '</a></li><li><a class="no-dropdown" href="index.php?option=com_jdbuilder&view=integrations">' . \JText::_('COM_JDBUILDER_TITLE_INTEGRATIONS') . '</a></li><li><a class="no-dropdown" href="index.php?option=com_config&view=component&component=com_jdbuilder">' . \JText::_('COM_JDBUILDER_TITLE_SETTINGS') . '</a></li></ul></li></ul>';
453526
}
454527
$body = $this->app->getBody();
455528
$body = str_replace('<ul id="nav-empty"', $adminMenu . '<ul id="nav-empty"', $body);
456529
$this->app->setBody($body);
457530
}
458531

532+
public function onContentBeforeSave($context, $article, $isNew)
533+
{
534+
if ($context === 'com_content.article') {
535+
$params = new \JRegistry();
536+
if (isset($article->attribs)) {
537+
$params->loadObject(\json_decode($article->attribs));
538+
}
539+
$enabled = (int) $params->get('jdbuilder_layout_enabled', 0);
540+
$layout_id = (int) $params->get('jdbuilder_layout_id', 0);
541+
$jdbform = $this->app->input->post->get('_jdbform', [], 'ARRAY');
542+
$layout = @$jdbform['layout'];
543+
if ($enabled) {
544+
$memory_limit = ini_get('memory_limit');
545+
ini_set('memory_limit', '-1');
546+
$object = new \stdClass();
547+
$db = JFactory::getDbo();
548+
if (empty($layout_id)) {
549+
$object->id = NULL;
550+
$object->layout = $layout;
551+
$object->created = time();
552+
$object->updated = time();
553+
$db->insertObject('#__jdbuilder_layouts', $object);
554+
$layoutid = $db->insertid();
555+
$params->set('jdbuilder_layout_id', $layoutid);
556+
$article->attribs = \json_encode($params->toObject());
557+
} else {
558+
$object->id = $layout_id;
559+
$object->layout = $layout;
560+
$object->updated = time();
561+
$db->updateObject('#__jdbuilder_layouts', $object, 'id');
562+
}
563+
ini_set('memory_limit', $memory_limit);
564+
}
565+
}
566+
if ($context == 'com_advancedmodules.module') {
567+
return $this->onExtensionBeforeSave($context, $article, $isNew);
568+
}
569+
570+
return true;
571+
}
572+
459573
public function onExtensionBeforeSave($context, $item, $isNew)
460574
{
461575
if (($context !== 'com_modules.module' && $context != 'com_advancedmodules.module') || $item->module !== 'mod_jdbuilder') {

plg_jdbuilder/jdbuilder.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<authorUrl>https://www.joomdev.com</authorUrl>
88
<copyright>Copyright (C) 2020 Joomdev, Inc. All rights reserved.</copyright>
99
<license>GNU General Public License version 2 or later; see LICENSE.txt</license>
10-
<version>1.10.0</version>
10+
<version>1.10.1</version>
1111
<description>{jdbplgdesc}</description>
1212
<files>
1313
<filename plugin="jdbuilder">jdbuilder.php</filename>

plg_jdbuilder/libraries/jdpagebuilder/Builder.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ abstract class Builder
3939
protected static $debug = false;
4040
protected static $debugmarker = null;
4141
protected static $logs = [];
42+
public static $enabled = false;
4243
public static $reserved_elements = ["section", "row", "column", "element", "__page"];
4344
public static $css = [
4445
'desktop' => [],
@@ -959,6 +960,7 @@ public static function beforeRenderHead()
959960

960961
public static function afterRenderHead()
961962
{
963+
if (!Builder::$enabled) return;
962964
// Add Rendered CSS in Head
963965
$document = \JFactory::getDocument();
964966
$document->addScript(\JURI::root() . 'media/jdbuilder/js/jdb.noconflict.end.js', ['version' => JDB_MEDIA_VERSION]);

plg_jdbuilder/libraries/jdpagebuilder/element/BaseElement.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ public function render($output = false)
9393
return "";
9494
}
9595
}
96+
Builder::$enabled = true;
9697
$return = [];
9798
$content = $this->getContent();
9899
$start = $this->getStart();

0 commit comments

Comments
 (0)