From 444348dc4db1e7ab8e6462082a6e9ab56f574234 Mon Sep 17 00:00:00 2001 From: Cameron Date: Sat, 9 Apr 2016 16:12:08 -0700 Subject: [PATCH] Issue #1512 News Grid Menu --- e107_admin/menus.php | 4 +- .../shortcodes/batch/admin_shortcodes.php | 2 + .../shortcodes/batch/news_shortcodes.php | 23 +++++-- e107_handlers/media_class.php | 6 +- e107_handlers/menumanager_class.php | 2 +- e107_handlers/news_class.php | 6 +- e107_handlers/shortcode_handler.php | 9 +-- e107_plugins/news/e_menu.php | 40 +++++++++++- e107_plugins/news/latestnews_menu.php | 12 +++- e107_plugins/news/news_categories_menu.php | 5 +- e107_plugins/news/news_grid_menu.php | 61 +++++++++++++++++++ .../news/templates/news_menu_template.php | 13 +++- e107_themes/_blank/theme.php | 2 +- 13 files changed, 163 insertions(+), 22 deletions(-) create mode 100644 e107_plugins/news/news_grid_menu.php diff --git a/e107_admin/menus.php b/e107_admin/menus.php index 525019445..37ff2bac7 100644 --- a/e107_admin/menus.php +++ b/e107_admin/menus.php @@ -380,8 +380,8 @@ TEMPL; .sortable li { border-radius: 4px } .sortable li:hover { background-color: silver; box-shadow:3px 3px 3px silver } - .regularMenu { cursor:move; border-bottom:1px dotted silver; margin-bottom:6px; padding-left:3px; padding-right:3px; padding-top:10px; padding-bottom:10px } - + .regularMenu { cursor:move; border-bottom:1px dotted silver; margin-bottom:6px; padding-left:3px; padding-right:3px; padding-top:10px; padding-bottom:10px;background-color: #E0EBF1; border-radius: 5px; } + .regularMenu span {padding:3px; font-weight:bold; color:#2F2F2F;text-align:left; } .ui-draggable { background-color: rgb(245, 245, 245); min-width:100px;} ",'jquery'); diff --git a/e107_core/shortcodes/batch/admin_shortcodes.php b/e107_core/shortcodes/batch/admin_shortcodes.php index 5b3f38c62..15f02b145 100644 --- a/e107_core/shortcodes/batch/admin_shortcodes.php +++ b/e107_core/shortcodes/batch/admin_shortcodes.php @@ -1817,6 +1817,8 @@ Inverse 10 10 global $pref; $action = ""; + return ; + $var['menumanager']['text'] = LAN_MENULAYOUT; $var['menumanager']['link'] = e_ADMIN_ABS.'menus.php'; diff --git a/e107_core/shortcodes/batch/news_shortcodes.php b/e107_core/shortcodes/batch/news_shortcodes.php index 88e54cf79..9acdf64be 100644 --- a/e107_core/shortcodes/batch/news_shortcodes.php +++ b/e107_core/shortcodes/batch/news_shortcodes.php @@ -60,6 +60,12 @@ class news_shortcodes extends e_shortcode $text = e107::getParser()->toAttribute($text); } + if(!empty($parm['limit'])) + { + $text = e107::getParser()->text_truncate($text, $parm['limit']); + } + + return $text; } @@ -485,12 +491,13 @@ class news_shortcodes extends e_shortcode function sc_newssummary($parm=null) { + $text = ''; + if($this->news_item['news_summary']) { - return $this->news_item['news_summary'].'
'; + $text = $this->news_item['news_summary']; } - - if($this->news_item['news_body']) // Auto-generate from first 2 sentences of news-body. //TODO Add Pref? + elseif($this->news_item['news_body']) // Auto-generate from first 2 sentences of news-body. //TODO Add Pref? { $tp = e107::getParser(); $text = $tp->toHtml($this->news_item['news_body'],true); @@ -501,9 +508,17 @@ class news_shortcodes extends e_shortcode if($tmp[0]) { - return trim($tmp[0]); + $text = trim($tmp[0]); } } + + if(!empty($parm['limit'])) + { + $text = e107::getParser()->text_truncate($text, $parm['limit']); + } + + + return $text; } /** diff --git a/e107_handlers/media_class.php b/e107_handlers/media_class.php index 9d6752a68..a59596db4 100644 --- a/e107_handlers/media_class.php +++ b/e107_handlers/media_class.php @@ -1101,9 +1101,9 @@ class e_media $img_data['media_url'] = $tp->createConstants($newpath,'rel'); $img_data['media_name'] = $tp->toDB(basename($newpath)); - $img_data['media_caption'] = $new_data['media_caption']; + $img_data['media_caption'] = vartrue($new_data['media_caption']); $img_data['media_category'] = vartrue($category,'_common_image'); - $img_data['media_description'] = $new_data['media_description']; + $img_data['media_description'] = vartrue($new_data['media_description']); $img_data['media_userclass'] = '0'; if($sql->insert("core_media",$img_data)) @@ -1114,7 +1114,7 @@ class e_media } else { - $this->log("Db Insert Failed "); + $this->log("Db Insert Failed: ".var_export($img_data,true)); rename($newpath,$oldpath); //move it back. return FALSE; } diff --git a/e107_handlers/menumanager_class.php b/e107_handlers/menumanager_class.php index 128922f17..d140db48d 100644 --- a/e107_handlers/menumanager_class.php +++ b/e107_handlers/menumanager_class.php @@ -1605,7 +1605,7 @@ class e_menuManager { if(!$this->dragDrop) { - return "".$caption."
". $text; + return "".$caption."
". $text; // return; diff --git a/e107_handlers/news_class.php b/e107_handlers/news_class.php index 2d0b3c750..1ecd192da 100644 --- a/e107_handlers/news_class.php +++ b/e107_handlers/news_class.php @@ -684,10 +684,12 @@ class e_news_tree extends e_front_tree_model $parser = e107::getParser(); $batch = e107::getScBatch('news') ->setScVar('param', $param); - - $batch->wrapper('news_menu/latest'); //@SecretR - Please FIXME, I'm lost in here. (Cam) + + $wrapperKey = ($parms['tmpl'].'/'.$parms['tmpl_key']); + $batch->wrapper($wrapperKey); $i = 1; + $items = $this->getTree(); if(!empty($items)) diff --git a/e107_handlers/shortcode_handler.php b/e107_handlers/shortcode_handler.php index 7d3243f95..842e62b6a 100644 --- a/e107_handlers/shortcode_handler.php +++ b/e107_handlers/shortcode_handler.php @@ -81,7 +81,7 @@ class e_parse_shortcode */ protected $wrappers = array(); protected $wrapper = null; // current wrapper being processed. - protected $wrapperDebugDone = false; + protected $wrapperDebugDone = array(); /** * Former $sc_style global variable. Internally used - performance reasons @@ -772,6 +772,7 @@ class e_parse_shortcode } elseif(E107_DBG_BBSC) { + $this->wrapper = $this->addedCodes->getWrapperID(); // e107::getMessage()->addDebug("Wrapper Empty: ".$this->addedCodes->wrapper()); } @@ -1101,7 +1102,7 @@ class e_parse_shortcode } } - if(E107_DBG_BBSC && $this->wrapperDebugDone==false && !empty($this->wrappers)) + if(E107_DBG_BBSC && $this->wrapperDebugDone[$this->wrapper]==false && !empty($this->wrapper)) { list($wrapTmpl, $wrapID1, $wrapID2) = explode('/',$this->wrapper,3); @@ -1112,10 +1113,10 @@ class e_parse_shortcode } // e107::getMessage()->addDebug("Active Wrapper: \$".$wrapActive); - $this->wrapperDebugDone = true; + $this->wrapperDebugDone[$this->wrapper] = true; global $db_debug; - $db_debug->logCode(3, $this->wrapper,null, '
To use, add to the '.$wrapTmpl.' template:
$'.$wrapActive.'[\'SHORTCODE_NAME\'] = "(html before){---}(html after)";
'); + $db_debug->logCode(3, $this->wrapper,null, '
To use, add to the file '.$wrapTmpl.'_template.php:
$'.$wrapActive.'[\'SHORTCODE_NAME\'] = "(html before){---}(html after)";
'); } if (isset($ret) && ($ret != '' || is_numeric($ret))) diff --git a/e107_plugins/news/e_menu.php b/e107_plugins/news/e_menu.php index ffa11f74f..1ab6b33cc 100644 --- a/e107_plugins/news/e_menu.php +++ b/e107_plugins/news/e_menu.php @@ -26,7 +26,7 @@ class news_menu * Configuration Fields. * @return array */ - public function config($menu='') + public function config($menu='') //TODO LAN { $fields = array(); $categories = array(); @@ -47,6 +47,16 @@ class news_menu $fields['category'] = array('title'=> LAN_CATEGORY, 'type'=>'dropdown', 'writeParms'=>array('optArray'=>$categories, 'default'=>'blank')); break; + case "news_grid": + $fields['caption'] = array('title'=> LAN_CAPTION, 'type'=>'text', 'multilan'=>true, 'writeParms'=>array('size'=>'xxlarge')); + $fields['category'] = array('title'=> LAN_CATEGORY, 'type'=>'dropdown', 'writeParms'=>array('optArray'=>$categories, 'default'=>'blank')); + $fields['layout'] = array('title'=> "Layout", 'type'=>'method', 'writeParms'=>''); + $fields['count'] = array('title'=> "Number of Items", 'type'=>'number', 'writeParms'=>array('pattern'=>'[0-9]*', 'default'=>4)); + $fields['titleLimit'] = array('title'=> "Title Character Limit", 'type'=>'number', 'writeParms'=>''); + $fields['summaryLimit'] = array('title'=> "Summary Character Limit", 'type'=>'number', 'writeParms'=>''); + // TODO Add a field for 'latest' vs 'sticky' vs 'assigned by news item (news_render_type)' + break; + case "news_categories": $fields['caption'] = array('title'=> LAN_CAPTION, 'type'=>'text', 'multilan'=>true, 'writeParms'=>array('size'=>'xxlarge')); @@ -74,3 +84,31 @@ class news_menu } + +// optional +class news_menu_form extends e_form +{ + + public function layout($curVal) + { + + $arr = array( + "col-md-6" => "
1/2
1/2
", + "col-md-4" => "
1/3
1/3
1/3
", + "col-md-3" => "
1/4
1/4
1/4
1/4
", + ); + + $text = ''; + + foreach($arr as $k=>$v) + { + + $text .= ""; + } + + $text .= "
".$this->radio('layout', $k, $curVal, array('label'=>$k))."".$v."
"; + + return $text; + } + +} \ No newline at end of file diff --git a/e107_plugins/news/latestnews_menu.php b/e107_plugins/news/latestnews_menu.php index 30a74272e..99af359c0 100644 --- a/e107_plugins/news/latestnews_menu.php +++ b/e107_plugins/news/latestnews_menu.php @@ -29,7 +29,17 @@ if(false === $cached) $ntree = e107::getObject('e_news_tree', null, e_HANDLER.'news_class.php'); - $template = e107::getTemplate('news', vartrue($parms['tmpl'], 'news_menu'), vartrue($parms['tmpl_key'], 'latest')); + if(empty($parms['tmpl'])) + { + $parms['tmpl'] = 'news_menu'; + } + + if(empty($parms['tmpl_key'])) + { + $parms['tmpl_key'] = 'latest'; + } + + $template = e107::getTemplate('news', $parms['tmpl'], $parms['tmpl_key']); $treeparm = array(); if(vartrue($parms['count'])) $treeparm['db_limit'] = '0, '.intval($parms['count']); diff --git a/e107_plugins/news/news_categories_menu.php b/e107_plugins/news/news_categories_menu.php index fcdca8a6b..d27819934 100644 --- a/e107_plugins/news/news_categories_menu.php +++ b/e107_plugins/news/news_categories_menu.php @@ -25,7 +25,10 @@ if(false === $cached) $ctree = e107::getObject('e_news_category_tree', null, e_HANDLER.'news_class.php'); - $template = e107::getTemplate('news', 'news_menu', 'category'); + $parms['tmpl'] = 'news_menu'; + $parms['tmpl_key'] = 'category'; + + $template = e107::getTemplate('news', $parms['tmpl'], $parms['tmpl_key']); $cached = $ctree->loadActive()->render($template, $parms, true); e107::getCache()->set($cacheString, $cached); diff --git a/e107_plugins/news/news_grid_menu.php b/e107_plugins/news/news_grid_menu.php new file mode 100644 index 000000000..e13769e4f --- /dev/null +++ b/e107_plugins/news/news_grid_menu.php @@ -0,0 +1,61 @@ +retrieve($cacheString); +if(false === $cached) +{ + e107::plugLan('news'); + + if(is_string($parm)) + { + parse_str($parm, $parms); + } + else + { + $parms = $parm; + } + + if(isset($parms['caption'][e_LANGUAGE])) + { + $parms['caption'] = $parms['caption'][e_LANGUAGE]; + } + + $ntree = e107::getObject('e_news_tree', null, e_HANDLER.'news_class.php'); + $template = e107::getTemplate('news', 'news_menu', 'grid'); + $gridSize = vartrue($parms['layout'],'col-md-4'); + + $parmSrch = array('{NEWSGRID}', '_titleLimit_', '_summaryLimit_'); + $parmReplace = array($gridSize, vartrue($parms['titleLimit'],0),vartrue($parms['summaryLimit'],0)); + + $template = str_replace($parmSrch , $parmReplace, $template); + + $render = (empty($parms['caption'])) ? false: true; + + $parms['tmpl'] = 'news_menu'; + $parms['tmpl_key'] = 'grid'; + + if(empty($parms['count'])) + { + $parms['count'] = 3; + } + + $parms['order'] = 'n.news_datestamp DESC'; + + $treeparm = array(); + if(vartrue($parms['count'])) $treeparm['db_limit'] = '0, '.intval($parms['count']); + if(vartrue($parms['order'])) $treeparm['db_order'] = e107::getParser()->toDb($parms['order']); + $parms['return'] = true; + + + $cached = $ntree->loadJoinActive(vartrue($parms['category'], 0), false, $treeparm)->render($template, $parms, $render); + e107::getCache()->set($cacheString, $cached); +} + +echo $cached; diff --git a/e107_plugins/news/templates/news_menu_template.php b/e107_plugins/news/templates/news_menu_template.php index 64bbebf3f..90cf8296d 100644 --- a/e107_plugins/news/templates/news_menu_template.php +++ b/e107_plugins/news/templates/news_menu_template.php @@ -90,7 +90,16 @@ $NEWS_MENU_TEMPLATE['other2']['end'] = ""; +// Grid Menu +$NEWS_MENU_TEMPLATE['grid']['start'] = '
'; +$NEWS_MENU_TEMPLATE['grid']['item'] = '
+ {SETIMAGE: w=400&h=400&crop=1} + {NEWSTHUMBNAIL=placeholder} +

{NEWSTITLE: limit=_titleLimit_}

+

{NEWSSUMMARY: limit=_summaryLimit_}

+

'.LAN_READ_MORE.'

+
'; +$NEWS_MENU_TEMPLATE['grid']['end'] = '
'; - -//$NEWS_MENU_TEMPLATE['latest']['separator'] = '
'; // Shouldn't be needed. +// $NEWS_MENU_WRAPPER['grid']['NEWSTITLE'] = "{---}"; // example diff --git a/e107_themes/_blank/theme.php b/e107_themes/_blank/theme.php index 8c57fd7c1..662c677b3 100644 --- a/e107_themes/_blank/theme.php +++ b/e107_themes/_blank/theme.php @@ -2,7 +2,7 @@ if ( ! defined('e107_INIT')) { exit(); } -e107::lan('theme','English'); +e107::lan('theme'); e107::meta('viewport', 'width=device-width, initial-scale=1.0'); //e107::meta('apple-mobile-web-app-capable','yes');