From 2a0d69475696bc2dab88e5dc3510d3aba1b97f71 Mon Sep 17 00:00:00 2001 From: Diego Najar Date: Tue, 6 Feb 2018 18:26:59 +0100 Subject: [PATCH] Plugin position --- bl-kernel/abstract/plugin.class.php | 13 ++++++- .../admin/controllers/plugins-position.php | 32 ++++++++++++++++ .../admin/controllers/settings-advanced.php | 7 +++- .../admin/themes/default/css/default.css | 28 ++++++++++++++ .../themes/default/css/uikit/sortable.min.css | 2 + bl-kernel/admin/themes/default/index.php | 2 + .../themes/default/js/uikit/sortable.min.js | 2 + bl-kernel/admin/views/plugins-position.php | 38 +++++++++++++++++++ bl-kernel/admin/views/plugins.php | 2 + bl-kernel/boot/rules/69.pages.php | 18 +++------ bl-kernel/functions.php | 21 ++++++++++ bl-languages/en.json | 8 +++- 12 files changed, 157 insertions(+), 16 deletions(-) create mode 100644 bl-kernel/admin/controllers/plugins-position.php create mode 100755 bl-kernel/admin/themes/default/css/uikit/sortable.min.css create mode 100755 bl-kernel/admin/themes/default/js/uikit/sortable.min.js create mode 100644 bl-kernel/admin/views/plugins-position.php diff --git a/bl-kernel/abstract/plugin.class.php b/bl-kernel/abstract/plugin.class.php index 66d80d0a..ce15c75e 100644 --- a/bl-kernel/abstract/plugin.class.php +++ b/bl-kernel/abstract/plugin.class.php @@ -227,7 +227,7 @@ class Plugin { // Return TRUE if the installation success, otherwise FALSE. public function install($position=1) { - if($this->installed()) { + if ($this->installed()) { return false; } @@ -278,6 +278,17 @@ class Plugin { return $this->save(); } + public function setField($field, $value) + { + $this->db[$field] = Sanitize::html($value); + return $this->save(); + } + + public function setPosition($position) + { + return $this->setField('position', $position); + } + // Returns the parameters after the URI, FALSE if the URI doesn't match with the webhook // Example: https://www.mybludit.com/api/foo/bar public function webhook($URI=false, $returnsAfterURI=false, $fixed=true) diff --git a/bl-kernel/admin/controllers/plugins-position.php b/bl-kernel/admin/controllers/plugins-position.php new file mode 100644 index 00000000..cad0096c --- /dev/null +++ b/bl-kernel/admin/controllers/plugins-position.php @@ -0,0 +1,32 @@ +role()!=='admin') { + Alert::set($Language->g('You do not have sufficient permissions')); + Redirect::page('dashboard'); +} + +// ============================================================================ +// Functions +// ============================================================================ + +// ============================================================================ +// Main before POST +// ============================================================================ +if ($_SERVER['REQUEST_METHOD'] == 'POST') { + changePluginsPosition(explode(',',$_POST['plugin-list'])); + Redirect::page('plugins-position'); +} +// ============================================================================ +// POST Method +// ============================================================================ + +// ============================================================================ +// Main after POST +// ============================================================================ + +// Title of the page +$layout['title'] .= ' - '.$Language->g('Plugins'); \ No newline at end of file diff --git a/bl-kernel/admin/controllers/settings-advanced.php b/bl-kernel/admin/controllers/settings-advanced.php index f789a6a5..71f153fc 100644 --- a/bl-kernel/admin/controllers/settings-advanced.php +++ b/bl-kernel/admin/controllers/settings-advanced.php @@ -31,8 +31,13 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST') { // ============================================================================ $allPages = buildAllpages($publishedPages=true, $staticPages=true, $draftPages=false, $scheduledPages=false); +// Generate $pagesByParentByKey and pagesByParent +$pagesByParent = array(PARENT=>array()); +$pagesByParentByKey = array(PARENT=>array()); +buildPagesByParent(true, true); + // Homepage select options -$homepageOptions = array(' '=>'- '.$L->g('Latest content').' -'); +$homepageOptions = array(' '=>'- '.$L->g('Default').' -'); foreach ($allPages as $key=>$page) { $parentKey = $page->parentKey(); if ($parentKey) { diff --git a/bl-kernel/admin/themes/default/css/default.css b/bl-kernel/admin/themes/default/css/default.css index 5e9d4b28..d26c84a2 100644 --- a/bl-kernel/admin/themes/default/css/default.css +++ b/bl-kernel/admin/themes/default/css/default.css @@ -86,6 +86,10 @@ body { max-width: 1800px; } +.hint { + +} + /* TOPBAR ---------------------------------------------------------------- */ @@ -649,6 +653,30 @@ div.plugin-links > span.separator { color: #ccc; } +.plugin-position { + display: block !important; + margin: 10px 0 !important; + padding: 10px !important; + line-height: 50px !important; + height: 50px !important; + width: 30% !important; + min-width: 100px !important; + cursor: move !important; + border: 1px solid #ccc !important; + background: #fafafa; +} + +.uk-sortable-item { + background: #fafafa !important; +} + +.uk-sortable-placeholder { + background: #fafafa !important; +} + +.plugin-position-wrap { + z-index: 200; +} /* ----------- PAGINATOR ----------- */ diff --git a/bl-kernel/admin/themes/default/css/uikit/sortable.min.css b/bl-kernel/admin/themes/default/css/uikit/sortable.min.css new file mode 100755 index 00000000..fae82eb7 --- /dev/null +++ b/bl-kernel/admin/themes/default/css/uikit/sortable.min.css @@ -0,0 +1,2 @@ +/*! UIkit 2.27.5 | http://www.getuikit.com | (c) 2014 YOOtheme | MIT License */ +.uk-sortable{position:relative}.uk-sortable>*{touch-action:none}.uk-sortable a,.uk-sortable img{-webkit-touch-callout:none}.uk-sortable>:last-child{margin-bottom:0}.uk-sortable-dragged{position:absolute;z-index:1050;pointer-events:none}.uk-sortable-placeholder{opacity:0}.uk-sortable-empty{min-height:30px}.uk-sortable-handle{touch-action:none}.uk-sortable-handle:hover{cursor:move}.uk-sortable-moving,.uk-sortable-moving *{cursor:move}.uk-sortable-moving iframe{pointer-events:none} \ No newline at end of file diff --git a/bl-kernel/admin/themes/default/index.php b/bl-kernel/admin/themes/default/index.php index 664e4888..5a19f0bf 100644 --- a/bl-kernel/admin/themes/default/index.php +++ b/bl-kernel/admin/themes/default/index.php @@ -16,6 +16,7 @@ + @@ -24,6 +25,7 @@ + diff --git a/bl-kernel/admin/themes/default/js/uikit/sortable.min.js b/bl-kernel/admin/themes/default/js/uikit/sortable.min.js new file mode 100755 index 00000000..e083d2d8 --- /dev/null +++ b/bl-kernel/admin/themes/default/js/uikit/sortable.min.js @@ -0,0 +1,2 @@ +/*! UIkit 2.27.5 | http://www.getuikit.com | (c) 2014 YOOtheme | MIT License */ +!function(t){var e;window.UIkit2&&(e=t(UIkit2)),"function"==typeof define&&define.amd&&define("uikit-sortable",["uikit"],function(){return e||t(UIkit2)})}(function(t){"use strict";function e(e){e=t.$(e);do{if(e.data("sortable"))return e;e=t.$(e).parent()}while(e.length);return e}function o(t,e){var o=t.parentNode;if(e.parentNode!=o)return!1;for(var n=t.previousSibling;n&&9!==n.nodeType;){if(n===e)return!0;n=n.previousSibling}return!1}function n(t,e){var o=e;if(o==t)return null;for(;o;){if(o.parentNode===t)return o;if(o=o.parentNode,!o||!o.ownerDocument||11===o.nodeType)break}return null}function a(t){t.stopPropagation&&t.stopPropagation(),t.preventDefault&&t.preventDefault(),t.returnValue=!1}var s,r,i,l,d,h,u,p,c,f,g,m="ontouchstart"in window||"MSGesture"in window||window.DocumentTouch&&document instanceof DocumentTouch,v=m?"MSGesture"in window||window.PointerEvent?"pointerdown":"touchstart":"mousedown",b=m?"MSGesture"in window||window.PointerEvent?"pointermove":"touchmove":"mousemove",C=m?"MSGesture"in window||window.PointerEvent?"pointerup":"touchend":"mouseup";return t.component("sortable",{defaults:{animation:150,threshold:10,childClass:"uk-sortable-item",placeholderClass:"uk-sortable-placeholder",overClass:"uk-sortable-over",draggingClass:"uk-sortable-dragged",dragMovingClass:"uk-sortable-moving",baseClass:"uk-sortable",noDragClass:"uk-sortable-nodrag",emptyClass:"uk-sortable-empty",dragCustomClass:"",handleClass:!1,group:!1,stop:function(){},start:function(){},change:function(){}},boot:function(){t.ready(function(e){t.$("[data-uk-sortable]",e).each(function(){var e=t.$(this);e.data("sortable")||t.sortable(e,t.Utils.options(e.attr("data-uk-sortable")))})}),t.$html.on(b,function(e){if(u){var o=e.originalEvent.targetTouches?e.originalEvent.targetTouches[0]:e;(Math.abs(o.pageX-u.pos.x)>u.threshold||Math.abs(o.pageY-u.pos.y)>u.threshold)&&u.apply(o)}if(s){d||(d=!0,s.show(),s.$current.addClass(s.$sortable.options.placeholderClass),s.$sortable.element.children().addClass(s.$sortable.options.childClass),t.$html.addClass(s.$sortable.options.dragMovingClass));var n=s.data("mouse-offset"),a=e.originalEvent.touches&&e.originalEvent.touches[0]||e.originalEvent,r=parseInt(a.pageX,10)+n.left,i=parseInt(a.pageY,10)+n.top;if(s.css({left:r,top:i}),i+s.height()/3>document.body.offsetHeight)return;iwindow.innerHeight+t.$win.scrollTop()&&t.$win.scrollTop(t.$win.scrollTop()+Math.ceil(s.height()/3))}}),t.$html.on(C,function(t){if(u=h=!1,!r||!s)return r=s=null,void 0;var o=e(r),n=s.$sortable,a={type:t.type};o[0]&&n.dragDrop(a,n.element),n.dragEnd(a,n.element)})},init:function(){function e(){m&&g.touches&&g.touches.length?h.addEventListener(b,y,!1):(h.addEventListener("mouseover",$,!1),h.addEventListener("mouseout",w,!1))}function o(){m&&g.touches&&g.touches.length?h.removeEventListener(b,y,!1):(h.removeEventListener("mouseover",$,!1),h.removeEventListener("mouseout",w,!1))}function s(t){r&&d.dragMove(t,d)}function l(e){return function(o){var a,s,r;if(g=o,o){if(a=o.touches&&o.touches[0]||o,s=a.target||o.target,m&&document.elementFromPoint){var i=document.elementFromPoint(a.pageX-document.body.scrollLeft,a.pageY-document.body.scrollTop);i&&(s=i)}f=t.$(s)}t.$(s).hasClass("."+d.options.childClass)?e.apply(s,[o]):s!==h&&(r=n(h,s),r&&e.apply(r,[o]))}}var d=this,h=this.element[0];p=[],this.checkEmptyList(),this.element.data("sortable-group",this.options.group?this.options.group:t.Utils.uid("sortable-group"));var u=l(function(e){if(!e.data||!e.data.sortable){var o=t.$(e.target),n=o.is("a[href]")?o:o.parents("a[href]");if(!o.is(":input")){if(d.options.handleClass){var a=o.hasClass(d.options.handleClass)?o:o.closest("."+d.options.handleClass,d.element);if(!a.length)return}return e.preventDefault(),n.length&&n.one("click",function(t){t.preventDefault()}).one(C,function(){c||(n.trigger("click"),m&&n.attr("href").trim()&&(location.href=n.attr("href")))}),e.data=e.data||{},e.data.sortable=h,d.dragStart(e,this)}}}),$=l(t.Utils.debounce(function(t){return d.dragEnter(t,this)}),40),w=l(function(){var e=d.dragenterData(this);d.dragenterData(this,e-1),d.dragenterData(this)||(t.$(this).removeClass(d.options.overClass),d.dragenterData(this,!1))}),y=l(function(t){return r&&r!==this&&i!==this?(d.element.children().removeClass(d.options.overClass),i=this,d.moveElementNextTo(r,this),a(t)):!0});this.addDragHandlers=e,this.removeDragHandlers=o,window.addEventListener(b,s,!1),h.addEventListener(v,u,!1)},dragStart:function(e,o){c=!1,d=!1,l=!1;var n=this,a=t.$(e.target);if((m||2!=e.button)&&!a.is("."+n.options.noDragClass)){var i=a.closest("."+n.options.noDragClass);if(!(i.length&&this.element.find(i[0]).length||a.is(":input"))){r=o,s&&s.remove();var h=t.$(r),p=h.offset(),f=e.touches&&e.touches[0]||e;u={pos:{x:f.pageX,y:f.pageY},threshold:n.options.handleClass?1:n.options.threshold,apply:function(){s=t.$('
').css({display:"none",top:p.top,left:p.left,width:h.width(),height:h.height(),padding:h.css("padding")}).data({"mouse-offset":{left:p.left-parseInt(f.pageX,10),top:p.top-parseInt(f.pageY,10)},origin:n.element,index:h.index()}).append(h.html()).appendTo("body"),s.$current=h,s.$sortable=n,h.data({"start-list":h.parent(),"start-index":h.index(),"sortable-group":n.options.group}),n.addDragHandlers(),n.options.start(this,r),n.trigger("start.uk.sortable",[n,r,s]),c=!0,u=!1}}}}},dragMove:function(e){f=t.$(document.elementFromPoint(e.pageX-(document.body.scrollLeft||document.scrollLeft||0),e.pageY-(document.body.scrollTop||document.documentElement.scrollTop||0)));var o,n=f.closest("."+this.options.baseClass),a=n.data("sortable-group"),s=t.$(r),i=s.parent(),l=s.data("sortable-group");n[0]!==i[0]&&void 0!==l&&a===l&&(n.data("sortable").addDragHandlers(),p.push(n),n.children().addClass(this.options.childClass),n.children().length>0?(o=f.closest("."+this.options.childClass),o.length?o.before(s):n.append(s)):f.append(s),t.$doc.trigger("mouseover")),this.checkEmptyList(),this.checkEmptyList(i)},dragEnter:function(e,o){if(!r||r===o)return!0;var n=this.dragenterData(o);if(this.dragenterData(o,n+1),0===n){var a=t.$(o).parent(),s=t.$(r).data("start-list");if(a[0]!==s[0]){var i=a.data("sortable-group"),l=t.$(r).data("sortable-group");if((i||l)&&i!=l)return!1}t.$(o).addClass(this.options.overClass),this.moveElementNextTo(r,o)}return!1},dragEnd:function(e,o){var n=this;r&&(this.options.stop(o),this.trigger("stop.uk.sortable",[this])),r=null,i=null,p.push(this.element),p.forEach(function(e){t.$(e).children().each(function(){1===this.nodeType&&(t.$(this).removeClass(n.options.overClass).removeClass(n.options.placeholderClass).removeClass(n.options.childClass),n.dragenterData(this,!1))})}),p=[],t.$html.removeClass(this.options.dragMovingClass),this.removeDragHandlers(),s&&(s.remove(),s=null)},dragDrop:function(t){"drop"===t.type&&(t.stopPropagation&&t.stopPropagation(),t.preventDefault&&t.preventDefault()),this.triggerChangeEvents()},triggerChangeEvents:function(){if(r){var e=t.$(r),o=s.data("origin"),n=e.closest("."+this.options.baseClass),a=[],i=t.$(r);o[0]===n[0]&&s.data("index")!=e.index()?a.push({sortable:this,mode:"moved"}):o[0]!=n[0]&&a.push({sortable:t.$(n).data("sortable"),mode:"added"},{sortable:t.$(o).data("sortable"),mode:"removed"}),a.forEach(function(t){t.sortable&&t.sortable.element.trigger("change.uk.sortable",[t.sortable,i,t.mode])})}},dragenterData:function(e,o){return e=t.$(e),1==arguments.length?parseInt(e.data("child-dragenter"),10)||0:(o?e.data("child-dragenter",Math.max(0,o)):e.removeData("child-dragenter"),void 0)},moveElementNextTo:function(e,n){l=!0;var a=this,s=t.$(e).parent().css("min-height",""),r=o(e,n)?n:n.nextSibling,i=s.children(),d=i.length;return a.options.animation?(s.css("min-height",s.height()),i.stop().each(function(){var e=t.$(this),o=e.position();o.width=e.width(),e.data("offset-before",o)}),n.parentNode.insertBefore(e,r),t.Utils.checkDisplay(a.element.parent()),i=s.children().each(function(){var e=t.$(this);e.data("offset-after",e.position())}).each(function(){var e=t.$(this),o=e.data("offset-before");e.css({position:"absolute",top:o.top,left:o.left,minWidth:o.width})}),i.each(function(){var e=t.$(this),o=(e.data("offset-before"),e.data("offset-after"));e.css("pointer-events","none").width(),setTimeout(function(){e.animate({top:o.top,left:o.left},a.options.animation,function(){e.css({position:"",top:"",left:"",minWidth:"","pointer-events":""}).removeClass(a.options.overClass).removeData("child-dragenter"),d--,d||(s.css("min-height",""),t.Utils.checkDisplay(a.element.parent()))})},0)}),void 0):(n.parentNode.insertBefore(e,r),t.Utils.checkDisplay(a.element.parent()),void 0)},serialize:function(){var e,o,n=[];return this.element.children().each(function(a,s){e={};for(var r,i,l=0;l$L->g('Plugins Position'), 'icon'=>'puzzle-piece')); + +echo '
'.$L->g('drag-and-drop-to-set-the-position-of-the-plugin').'
'; + +echo '
'; + +HTML::formInputHidden(array( + 'name'=>'tokenCSRF', + 'value'=>$Security->getTokenCSRF() +)); + +echo '
'; + +foreach ($plugins['siteSidebar'] as $Plugin) { + echo '
'.$Plugin->name().'
'; +} + +echo '
'; +echo ''; +echo ''; +echo '
'; +?> + + \ No newline at end of file diff --git a/bl-kernel/admin/views/plugins.php b/bl-kernel/admin/views/plugins.php index 57bb10ef..443981b9 100644 --- a/bl-kernel/admin/views/plugins.php +++ b/bl-kernel/admin/views/plugins.php @@ -2,6 +2,8 @@ HTML::title(array('title'=>$L->g('Plugins'), 'icon'=>'puzzle-piece')); +echo ' '.$L->g('Change the position of the plugins').''; + echo ' diff --git a/bl-kernel/boot/rules/69.pages.php b/bl-kernel/boot/rules/69.pages.php index f9d50445..b3cb53cd 100644 --- a/bl-kernel/boot/rules/69.pages.php +++ b/bl-kernel/boot/rules/69.pages.php @@ -42,7 +42,7 @@ $page = $Page = false; N => Page Object), ) */ -$pagesByParent = array(PARENT=>array()); +//$pagesByParent = array(PARENT=>array()); // DEPREACTED // Array with pages order by parent and by key /* @@ -66,7 +66,7 @@ $pagesByParent = array(PARENT=>array()); "childKeyZ" => Page Object), ) */ -$pagesByParentByKey = array(PARENT=>array()); +//$pagesByParentByKey = array(PARENT=>array()); // DEPREACTED // Array with static content, each item is a Page Object // Order by position @@ -100,7 +100,7 @@ if ($dbPages->scheduler()) { } // Generate pages parent tree, only published pages -buildPagesByParent(true, true); +//buildPagesByParent(true, true); // Set home page is the user defined one if ($Site->homepage() && $Url->whereAmI()==='home') { @@ -111,25 +111,19 @@ if ($Site->homepage() && $Url->whereAmI()==='home') { } } -// The filter blog alway show all the content -// Change the where am i to use -if ($Url->whereAmI()==='blog') { - //$Url->setWhereAmI('home'); -} - // Build specific page if ($Url->whereAmI()==='page') { buildThePage(); } -// Build pages by tag +// Build content by tag elseif ($Url->whereAmI()==='tag') { buildPagesByTag(); } -// Build pages by category +// Build content by category elseif ($Url->whereAmI()==='category') { buildPagesByCategory(); } -// Build pages for the homepage +// Build content for the homepage elseif ( ($Url->whereAmI()==='home') || ($Url->whereAmI()==='blog') ) { buildPagesForHome(); } diff --git a/bl-kernel/functions.php b/bl-kernel/functions.php index a3068224..59f72b8c 100644 --- a/bl-kernel/functions.php +++ b/bl-kernel/functions.php @@ -336,6 +336,27 @@ function deactivatePlugin($pluginClassName) { return false; } +function changePluginsPosition($pluginClassList) { + global $plugins; + global $Syslog; + global $Language; + + foreach ($pluginClassList as $position=>$pluginClassName) { + if (isset($plugins['all'][$pluginClassName])) { + $plugin = $plugins['all'][$pluginClassName]; + $plugin->setPosition(++$position); + } + } + + // Add to syslog + $Syslog->add(array( + 'dictionaryKey'=>'plugins-sorted', + 'notes'=>'' + )); + + return true; +} + function createPage($args) { global $dbPages; global $Syslog; diff --git a/bl-languages/en.json b/bl-languages/en.json index 5ffb4d04..6a99dd65 100644 --- a/bl-languages/en.json +++ b/bl-languages/en.json @@ -29,7 +29,7 @@ "Jan": "Jan", "Feb": "Feb", "Mar": "Mar", - "Apr": "Apr", + "Apr": "Apr", "Jun": "Jun", "Jul": "Jul", "Aug": "Aug", @@ -276,5 +276,9 @@ "congratulations-you-have-successfully-installed-your-bludit": "Congratulations you have successfully installed your **Bludit**.", "this-theme-may-not-be-supported-by-this-version-of-bludit": "This theme may not be supported by this version of Bludit", "read-more": "Read more", - "remember-me": "Remember me" + "remember-me": "Remember me", + "plugins-position": "Plugin position", + "plugins-position-changed": "Plugin position changed", + "drag-and-drop-to-set-the-position-of-the-plugin": "Drag and Drop to set the position of the plugins", + "change-the-position-of-the-plugins": "Change the position of the plugins" }