This repository has been archived by the owner on Jul 7, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge Theme Mod to Core
- Loading branch information
Showing
8 changed files
with
443 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?xml version="1.0"?> | ||
<application> | ||
<details> | ||
<name>Theme Manager</name> | ||
<namespace>theme_mod</namespace> | ||
<description>This module add theme support for Tendoo CMS</description> | ||
<author>Blair Jersyer</author> | ||
<version>1.0</version> | ||
<language>/language</language> | ||
<main>theme_mod.php</main> | ||
</details> | ||
</application> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
["D:\/xampp\/htdocs\/tendoo-cms\/application\/libraries\/Themes.php","D:\/xampp\/htdocs\/tendoo-cms\/application\/libraries\/Theme_Mod.php"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
<?php | ||
class Theme_Mod extends CI_Model | ||
{ | ||
/** | ||
* Module Constructor | ||
**/ | ||
function __construct() | ||
{ | ||
parent::__construct(); | ||
// Constant for Themes path | ||
define( 'THEMESPATH', APPPATH . 'themes/' ); | ||
|
||
$this->events->add_action( 'setup_theme', array( $this, 'test' ), 10 ); | ||
$this->events->add_action( 'after_app_init', array( $this, 'init' ), 1 ); | ||
|
||
$this->events->add_action( 'load_dashboard', array( $this, 'dashboard' ) ); | ||
$this->events->add_action( 'load_frontend', array( $this, 'frontend' ) ); | ||
$this->events->add_action( 'tendoo_settings_table', function(){ | ||
Modules::enable( 'theme_mod' ); | ||
}); | ||
} | ||
|
||
function test() | ||
{ | ||
Theme::Register_Nav_Location( 'header', __( 'Header Menu' ) ); | ||
Theme::Register_Nav_Location( 'footer', __( 'Footer Menu' ) ); | ||
Theme::Register_Nav_Location( 'bottom', __( 'Bottom Menu' ) ); | ||
} | ||
/** | ||
* Init | ||
* After APP init | ||
* Browse Theme Folder | ||
* | ||
* @access public | ||
* @return void | ||
**/ | ||
|
||
function init() | ||
{ | ||
$this->load->library( 'theme' ); | ||
$this->load->helper( 'text' ); | ||
$this->events->do_action( 'setup_theme' ); | ||
} | ||
|
||
/** | ||
* Creating a Dashboard Page | ||
**/ | ||
|
||
function dashboard() | ||
{ | ||
// Save Menu | ||
$this->events->add_filter( 'admin_menus', array( $this, 'create_menus' ) ); | ||
// Register Page | ||
$this->gui->register_page( 'menu_builder', array( $this, 'menu_builder_controller' ) ); | ||
} | ||
|
||
/** | ||
* Controller : menu_builder_controller | ||
**/ | ||
|
||
function menu_builder_controller() | ||
{ | ||
$this->enqueue->css( css_url( 'theme_mod' ) . 'style', '' ); | ||
|
||
$this->enqueue->js( js_url( 'theme_mod' ) . 'jquery.nestable', '' ); | ||
$this->enqueue->js( js_url( 'theme_mod' ) . 'sha1', '' ); | ||
|
||
$this->gui->set_title( sprintf( __( 'Menu Builder — %s' ) , get( 'core_signature' ) ) ); | ||
|
||
$this->load->view( '../modules/theme_mod/views/menu_builder' ); | ||
} | ||
|
||
/** | ||
* Create Menu | ||
**/ | ||
|
||
function create_menus( $menu ) | ||
{ | ||
$splited_1 = array_slice( $menu, 0, 2 ); | ||
$splited_2 = array_slice( $menu, 2 ); | ||
$thismenu = array( | ||
'theme_mod' => array( | ||
array( | ||
'title' => __( 'Themes' ), | ||
'href' => site_url( array( 'dashboard', 'menu_builder' ) ), | ||
'disable' => true | ||
), | ||
array( | ||
'title' => __( 'Menu' ), | ||
'href' => site_url( array( 'dashboard', 'menu_builder' ) ) | ||
) | ||
) | ||
); | ||
|
||
$menu = array_merge( $splited_1, $thismenu, $splited_2 ); | ||
$menu[ 'visit_blog' ] = array( | ||
array( | ||
'title' => __( 'Get to blog' ), | ||
'href' => site_url(), | ||
'icon' => 'fa fa-home' | ||
) | ||
); | ||
return $menu; | ||
} | ||
|
||
/** | ||
* Load Frontend with parser | ||
**/ | ||
|
||
function frontend( $params ) | ||
{ | ||
Theme::Run_Theme( $params ); | ||
} | ||
} | ||
new Theme_Mod; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,203 @@ | ||
<script> | ||
tendoo.menu = new function(){ | ||
this.store = function( menu ){ | ||
this.menus = menu; | ||
} | ||
this.get = function(){ | ||
return this.menus; | ||
} | ||
|
||
this.create = function( items ){ | ||
name = $(items).val(); | ||
if( name == '' ) { | ||
bootbox.alert( '<?php _e( 'You must provide a name for this menu.' );?>' ); | ||
return; | ||
} | ||
tendoo.options.get( 'tendoo_menus', function( menus ){ | ||
menus = menus == '[]' ? '{}' : menus; //Convert Array to Object; | ||
menus = JSON.parse( menus ); | ||
|
||
// first menu | ||
if( typeof menus == 'undefined' || menus == null ) { | ||
menus = new Object(); | ||
} | ||
|
||
// if menu doesn't exists | ||
if( ! _.contains( _.keys( menus ), 'menu_' + CryptoJS.SHA1( name ) ) ){ | ||
|
||
var menu_id = 'menu_' + CryptoJS.SHA1( name ); | ||
|
||
menus = _.extend( menus, _.object( [ menu_id ], [{ | ||
menu_name : name, | ||
menu_items : [], | ||
menu_id : menu_id | ||
}]) ); | ||
|
||
console.log( _.object( [CryptoJS.SHA1( name )], [{ foo : 'bar' }] ) ); | ||
|
||
tendoo.options.set( 'tendoo_menus', menus ); | ||
tendoo.menu.store( menus ); | ||
tendoo.menu.generate(); | ||
|
||
} else { | ||
bootbox.alert( '<?php _e( 'This menu already exists, please choose another name' );?>' ); | ||
} | ||
|
||
$(items).val(''); | ||
}); | ||
} | ||
this.generate = function() | ||
{ | ||
$('#menu_list').html(''); | ||
_.each( this.menus, function( value, key ){ | ||
$('#menu_list').append( '<option value="' + value.menu_id + '">' + value.menu_name + '</option>' ); | ||
}); | ||
} | ||
this.load = function( menus ){ | ||
if( typeof menus === 'undefined' ){ | ||
tendoo.options.get( 'tendoo_menus', function( data ){ | ||
tendoo.menu.store( JSON.parse( data ) ); | ||
tendoo.menu.generate(); | ||
}); | ||
} | ||
} | ||
this.delete_menu = function( menu_id ){ | ||
tendoo.options.get( 'tendoo_menus', function( data ){ | ||
if( menu_id == $( '#nestable' ).data( 'menu' ) ){ | ||
$( '#nestable' ).data( 'menu', void(0) ); | ||
$( '.content-header h1 small' ).html( '' ); | ||
} | ||
tendoo.menu.store( JSON.parse( data ) ); | ||
tendoo.menu.store( _.omit( tendoo.menu.get(), menu_id ) ); | ||
tendoo.options.set( 'tendoo_menus', tendoo.menu.get() ); | ||
console.log( tendoo.menu.get() ); | ||
tendoo.menu.generate(); | ||
}); | ||
} | ||
this.add_link = function( label, url ) { | ||
var check_item = ( label == '' || url == '' ) ? bootbox.alert( '<?php _e( 'Must provide "Label" and "Url"' );?>' ) : true ; | ||
if( typeof $( '#nestable' ).data( 'menu' ) != 'undefined' ) { | ||
if( check_item === true ) { | ||
var current_item = _.propertyOf( this.menus )( $( '#nestable' ).data( 'menu' ) ); | ||
current_item.menu_items.push({ | ||
id : isNaN( current_item.menu_items.length ) ? 0 : current_item.menu_items.length + 1, | ||
url : url, | ||
label : tendoo.tools.remove_tags( label ) | ||
}); | ||
this.output_menu(); | ||
this.update_menu_items( $( '#nestable' ) ); | ||
return; | ||
} | ||
return; | ||
} | ||
bootbox.alert( '<?php _e( 'You should load a menu first' );?>' ); | ||
}; | ||
this.output_menu = function() | ||
{ | ||
var current_item = _.propertyOf( this.menus )( $( '#nestable' ).data( 'menu' ) ); | ||
var menu_items = _.propertyOf( current_item )( 'menu_items' ); | ||
var output = "<ol class='dd-list dd3-list'>"; | ||
function buildItem( menu_item ) { | ||
var html = "<li class='dd-item' data-id='" + menu_item.id + "' data-url='" + menu_item.url + "' data-label='" + menu_item.label + "'>"; | ||
html += "<div class='dd-handle'>" + menu_item.label + "</div>"; | ||
|
||
if (menu_item.children) { | ||
|
||
html += "<ol class='dd-list'>"; | ||
$.each(menu_item.children, function (index, subitem) { | ||
html += buildItem(subitem); | ||
}); | ||
html += "</ol>"; | ||
|
||
} | ||
|
||
html += "</li>"; | ||
|
||
return html; | ||
} | ||
console.log( menu_items ); | ||
$.each( menu_items, function (index, menu_item) { | ||
|
||
output += buildItem(menu_item); | ||
|
||
}); | ||
|
||
output += "</ol>"; | ||
|
||
$('#nestable' ).html( output ); | ||
} | ||
this.load_menu = function( val ) | ||
{ | ||
$( '#nestable' ).data( 'menu', val ); | ||
var current_item = _.propertyOf( this.menus )( $( '#nestable' ).data( 'menu' ) ); | ||
console.log( current_item ); | ||
$( '.content-header h1 small' ).html( '<?php _e( 'Loaded : ' );?>' + current_item.menu_name ); | ||
this.output_menu(); | ||
} | ||
this.update_menu_items = function( e ){ | ||
var list = e.length ? e : $(e.target); | ||
var current_item = _.propertyOf( tendoo.menu.get() )( $( '#nestable' ).data( 'menu' ) ); | ||
// console.log( tendoo.menu.get() ); | ||
current_item.menu_items = list.nestable('serialize'); | ||
tendoo.options.set( 'tendoo_menus', JSON.stringify( tendoo.menu.get() ) ); | ||
} | ||
} | ||
|
||
$(document).ready(function(e) { | ||
|
||
$( '#create_menu' ).bind( 'click', function(){ | ||
tendoo.menu.create( $( '#menu_name' ) ); | ||
return false; | ||
}); | ||
|
||
$( '#delete_menu' ).bind( 'click', function(){ | ||
tendoo.menu.delete_menu( $( '#menu_list' ).val() ); | ||
return false; | ||
}); | ||
|
||
// Link Creation | ||
$( '.create_link' ).bind( 'click', function(){ | ||
tendoo.menu.add_link( $( '[name="link_label"]' ).val(), $( '[name="link_url"]' ).val() ); | ||
return false; | ||
}); | ||
|
||
// Load Menu | ||
$( '.load_menu' ).bind( 'click', function(){ | ||
tendoo.menu.load_menu( $( '#menu_list' ).val() ); | ||
return false; | ||
}); | ||
|
||
tendoo.menu.load(); | ||
|
||
// activate Nestable for list 1 | ||
$('#nestable').nestable({ | ||
group: 1, | ||
contentCallback : function( element ) { | ||
return element.menu_name; | ||
}, | ||
//listClass : 'list-group', | ||
//itemClass : 'list-group-item', | ||
placeClass : 'list-group-item bg-warning' | ||
}) | ||
.on('change', tendoo.menu.update_menu_items ); | ||
|
||
|
||
// output initial serialised data | ||
// updateOutput($('#nestable').data('output', $('#nestable-output'))); | ||
|
||
$('#nestable-menu').on('click', function(e) | ||
{ | ||
var target = $(e.target), | ||
action = target.data('action'); | ||
if (action === 'expand-all') { | ||
$('.dd').nestable('expandAll'); | ||
} | ||
if (action === 'collapse-all') { | ||
$('.dd').nestable('collapseAll'); | ||
} | ||
}); | ||
|
||
$('#nestable3').nestable(); | ||
|
||
}); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
$this->gui->col_width( 1, 4 ); | ||
|
||
$this->gui->add_meta( array( | ||
'col_id' => 1, | ||
'namespace' => 'menu_builder', | ||
'type' => 'unwrapped', | ||
'title' => __( 'Menu' ) | ||
) ); | ||
|
||
$this->gui->add_item( array( | ||
'type' => 'dom', | ||
'content' => $this->load->view( '../modules/theme_mod/views/menu_builder_output', array(), true ) | ||
), 'menu_builder', 1 ); | ||
|
||
$this->gui->output(); |
Oops, something went wrong.