Skip to content

Commit

Permalink
fix multi widget trouble
Browse files Browse the repository at this point in the history
  • Loading branch information
goFrendiAsgard committed Dec 4, 2013
1 parent a02c84e commit d92ebe7
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 68 deletions.
56 changes: 14 additions & 42 deletions application/core/MY_Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -959,34 +959,14 @@ private function __cms_parse_widget_theme_path($html, $theme, $navigation_name,

// parse widget
if(strpos($html, '{{ ') !== FALSE){
$pattern = '/\{\{ widget:(.*?) \}\}/si';
$pattern = '/\{\{ widget([a-zA-Z0-9-_]*?):(.*?) \}\}/si';
// execute regex
$html = preg_replace_callback($pattern, array(
$this,
'__cms_preg_replace_callback_widget'
), $html);
}

// parse widget by name
if(strpos($html, '{{ ') !== FALSE){
$pattern = '/\{\{ widget_name:(.*?) \}\}/si';
// execute regex
$html = preg_replace_callback($pattern, array(
$this,
'__cms_preg_replace_callback_widget_by_name'
), $html);
}

// parse widget by slug
if(strpos($html, '{{ ') !== FALSE){
$pattern = '/\{\{ widget_slug:(.*?) \}\}/si';
// execute regex
$html = preg_replace_callback($pattern, array(
$this,
'__cms_preg_replace_callback_widget_by_slug'
), $html);
}

// prepare pattern and replacement for theme and path
if(strpos($html, '{{ ') !== FALSE){
$pattern = array();
Expand Down Expand Up @@ -1148,31 +1128,23 @@ private function __cms_build_nav_path($navigation_name){

private function __cms_preg_replace_callback_widget($arr){
$html = "";
if(count($arr)>1){
$slug = $arr[1];
$html = $this->__cms_build_widget($slug);
}
return $html;
}

private function __cms_preg_replace_callback_widget_by_name($arr){
$html = "";
if(count($arr)>1){
$widget_name = $arr[1];
$html = $this->__cms_build_widget(NULL, $widget_name);
}
return $html;
}

private function __cms_preg_replace_callback_widget_by_slug($arr){
$html = "";
if(count($arr)>1){
$slug = $arr[1];
$html = $this->__cms_build_widget($slug, NULL);
if(count($arr)>2){
$option = $arr[1];
$slug = NULL;
$widget_name = NULL;
if($option == '' || $option == '_slug'){
$slug = $arr[2];
}else if($option == '_name' || $option == '_code'){
$widget_name = $arr[2];
}
//$slug = $arr[1];
//var_dump(array($slug, $widget_name));
$html = $this->__cms_build_widget($slug, $widget_name);
}
return $html;
}


public function cms_layout_exists($theme, $layout)
{
return is_file('themes/' . $theme . '/views/layouts/' . $layout . '.php');
Expand Down
17 changes: 11 additions & 6 deletions application/core/MY_Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -1291,10 +1291,13 @@ public function cms_get_module_list()
public function cms_module_path($module_name = NULL)
{
if (!isset($module_name)) {
return $this->router->fetch_module();
} else {
$SQL = "SELECT module_path FROM ".cms_table_name('main_module')." WHERE module_name='" . addslashes($module_name) . "'";
$query = $this->db->query($SQL);
$module = $this->router->fetch_module();
return $module;
} else {
$query = $this->db->select('module_path')
->from(cms_table_name('main_module'))
->where('module_name', $module_name)
->get();
if ($query->num_rows() > 0) {
$row = $query->row();
return $row->module_path;
Expand All @@ -1312,8 +1315,10 @@ public function cms_module_path($module_name = NULL)
*/
public function cms_module_name($module_path)
{
$SQL = "SELECT module_name FROM ".cms_table_name('main_module')." WHERE module_path='" . addslashes($module_path) . "'";
$query = $this->db->query($SQL);
$query = $this->db->select('module_name')
->from(cms_table_name('main_module'))
->where('module_path', $module_path)
->get();
if ($query->num_rows() > 0) {
$row = $query->row();
return $row->module_name;
Expand Down
12 changes: 8 additions & 4 deletions application/helpers/cms_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ function __cms_config($key, $value = NULL, $delete = FALSE, $file_name, $config_
$str = file_get_contents($file_name);
$str = preg_replace($pattern, $replacement, $str);
@chmod($file_name,0777);
@file_put_contents($file_name, $str);
@chmod($file_name,0555);
if(strpos($str, '<?php') !== FALSE && strpos($str, '$config') !== FALSE){
@file_put_contents($file_name, $str);
@chmod($file_name,0555);
}
return FALSE;
}else{
if(!isset($value)){
Expand All @@ -37,8 +39,10 @@ function __cms_config($key, $value = NULL, $delete = FALSE, $file_name, $config_
$str = preg_replace($pattern, $replacement, $str);
}
@chmod($file_name,0777);
@file_put_contents($file_name, $str);
@chmod($file_name,0555);
if(strpos($str, '<?php') !== FALSE && strpos($str, '$config') !== FALSE){
@file_put_contents($file_name, $str);
@chmod($file_name,0555);
}
return $value;
}
}
Expand Down
8 changes: 6 additions & 2 deletions application/third_party/MX/Modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ public static function load($module) {
$alias = strtolower(basename($module));

/* create or return an existing controller from the registry */
if ( ! isset(self::$registry[$alias])) {
// removed by Go Frendi Gunawan, 04-DEC-2013, since this make widget cannot be called twice if there is another widget call
// from another widget
//if ( ! isset(self::$registry[$alias])) {

/* find the controller */
list($class) = CI::$APP->router->locate(explode('/', $module));
Expand Down Expand Up @@ -114,7 +116,9 @@ public static function load($module) {
/* create and register the new controller */
$controller = ucfirst($class);
self::$registry[$alias] = new $controller($params);
}

// removed by Go Frendi Gunawan, 04-DEC-2013
//}

return self::$registry[$alias];
}
Expand Down
18 changes: 4 additions & 14 deletions developer-note.md
Original file line number Diff line number Diff line change
Expand Up @@ -412,22 +412,12 @@ HOW TO MAKE NO-CMS
//
```

- Edit `/application/third_party/MX/Modules.php` around line `99` (function load)
- Edit `/application/MX/Modules.php` around line `89` and respective curly-bracket

```php
/* load the controller class */
// Modified by Ivan Tcholakov, 28-FEB-2012.
//$class = $class.CI::$APP->config->item('controller_suffix');
if (self::test_load_file(ucfirst($class).CI::$APP->config->item('controller_suffix'), $path)) {
$class = ucfirst($class).CI::$APP->config->item('controller_suffix');
}
elseif (self::test_load_file($class.CI::$APP->config->item('controller_suffix'), $path)) {
$class = $class.CI::$APP->config->item('controller_suffix');
}
elseif (self::test_load_file(ucfirst($class), $path)) {
$class = ucfirst($class);
}
//
// removed by Go Frendi Gunawan, 04-DEC-2013, since this make widget cannot be called twice if there is another widget call
// from another widget
//if ( ! isset(self::$registry[$alias])) {
```

- Edit `/application/MX/Modules.php` around line `239` (function parse_routes)
Expand Down

0 comments on commit d92ebe7

Please sign in to comment.