From acbf93ef8a202a03e87deda300cd05c85d818ca7 Mon Sep 17 00:00:00 2001 From: Cameron Date: Sat, 21 Jan 2017 13:42:36 -0800 Subject: [PATCH] Page/Menu Custom Fields. --- e107_admin/cpage.php | 24 +++-- .../shortcodes/batch/page_shortcodes.php | 94 ++++++++++++++++++- e107_handlers/e_parse_class.php | 32 +++++++ e107_handlers/form_handler.php | 8 ++ 4 files changed, 140 insertions(+), 18 deletions(-) diff --git a/e107_admin/cpage.php b/e107_admin/cpage.php index 38b8e2f59..c8ad34ff2 100644 --- a/e107_admin/cpage.php +++ b/e107_admin/cpage.php @@ -134,7 +134,7 @@ class page_admin_form_ui extends e_admin_form_ui $text = " ".ADMIN_EDIT_ICON.""; - $text .= $this->submit_image('menu_delete['.$id.']', $id, 'delete', LAN_DELETE.' [ ID: '.$id.' ]', array('class' => 'action delete btn btn-default'.$delcls)); + $text .= $this->submit_image('menu_delete['.$id.']', $id, 'delete', LAN_DELETE.' [ ID: '.$id.' ]', array('class' => 'action delete btn btn-default')); return $text; } @@ -190,7 +190,7 @@ class page_chapters_ui extends e_admin_ui function init() { - if(e_DEBUG === true) + // if(e_DEBUG === true) { e107::getMessage()->addWarning("Experimental: Custom Fields"); $this->tabs = array(LAN_GENERAL,"Custom Fields"); @@ -369,17 +369,17 @@ class page_chapters_form_ui extends e_admin_form_ui - ".LAN_NAME."".LAN_TITLE."".LAN_TYPE."Params + ".LAN_NAME."".LAN_TITLE."".LAN_TYPE."Params".LAN_TOOLTIP." "; - for ($i = 0; $i <= 10; $i++) + for ($i = 0; $i <= 20; $i++) { $fieldName = $this->text('chapter_fields['.$i.'][key]',$value[$i]['key'],30, array('pattern'=>'^[a-z0-9-]*')); $fieldTitle = $this->text('chapter_fields['.$i.'][title]',$value[$i]['title'], 80); $fieldType = $this->select('chapter_fields['.$i.'][type]',$this->getFieldTypes(),$value[$i]['type'], 'useValues=1&default=blank'); - $fieldParms = $this->text('chapter_fields['.$i.'][writeParms]',$value[$i]['writeParams'], 80, array('size'=>'xxlarge')); - - $text .= "".$fieldName."".$fieldTitle."".$fieldType."".$fieldParms.""; + $fieldParms = $this->text('chapter_fields['.$i.'][writeParms]',$value[$i]['writeParms'], 80, array('size'=>'block-level')); + $fieldHelp = $this->text('chapter_fields['.$i.'][help]',$value[$i]['help'], 80, array('size'=>'block-level')); + $text .= "".$fieldName."".$fieldTitle."".$fieldType."".$fieldParms."".$fieldHelp.""; } $text .= ""; @@ -702,7 +702,7 @@ class page_admin_ui extends e_admin_ui $this->fieldpref = array("page_id","menu_name", "menu_title", 'menu_image', 'menu_template', 'menu_icon', 'page_chapter', 'menu_class'); - if(e_DEBUG) + if(deftrue('e_DEBUG')) { $this->fields['menu_name']['inline'] = true; } @@ -752,8 +752,7 @@ class page_admin_ui extends e_admin_ui $this->prefs['listBooksTemplate']['writeParms'] = $tmpl; $sql = e107::getDb(); - - $chapterFields = array(); + $sql->gen("SELECT chapter_id,chapter_name,chapter_parent, chapter_fields FROM #page_chapters ORDER BY chapter_parent asc, chapter_order"); while($row = $sql->fetch()) { @@ -781,10 +780,9 @@ class page_admin_ui extends e_admin_ui $this->fields['page_chapter']['writeParms']['optArray'] = $this->cats; $this->fields['page_chapter']['writeParms']['size'] = 'xxlarge'; - if(e_DEBUG !== false && $this->getAction() === 'create') + if($this->getAction() === 'create') { $this->fields['page_chapter']['writeParms']['ajax'] = array('src'=>e_SELF."?mode=page&action=chapter-change",'target'=>'tabadditional'); - } if(e_AJAX_REQUEST && isset($_POST['page_chapter']) ) //&& $this->getAction() === 'chapter-change' @@ -883,7 +881,7 @@ class page_admin_ui extends e_admin_ui if(!deftrue('e_DEBUG')) { - return; + // return; } diff --git a/e107_core/shortcodes/batch/page_shortcodes.php b/e107_core/shortcodes/batch/page_shortcodes.php index 5b7a397b9..7b1e5dd3b 100644 --- a/e107_core/shortcodes/batch/page_shortcodes.php +++ b/e107_core/shortcodes/batch/page_shortcodes.php @@ -606,6 +606,26 @@ class cpage_shortcodes extends e_shortcode } + function sc_cpagefieldtitle($parm=null) + { + if(empty($parm['name']) || empty($this->var['page_fields'])) + { + return null; + } + + $chap = $this->var['page_chapter']; + $key = $parm['name']; + + + if(!empty($this->chapterData[$chap]['chapter_fields'][$key]['title'])) + { + return $this->chapterData[$chap]['chapter_fields'][$key]['title']; + } + + return null; + } + + /** * Return raw HTML-usable values from page fields. * @experimental subject to change without notice. @@ -625,23 +645,65 @@ class cpage_shortcodes extends e_shortcode $key = $parm['name']; $fields = $this->chapterData[$chap]['chapter_fields']; $fieldData = e107::unserialize($this->var['page_fields']); - $type = $fields[$key]['type'];; - // @todo Move this part to form_handler somewhere. + + $raw = (!empty($parm['mode']) && $parm['mode'] === 'raw') ? true : false; + $type = (!empty($parm['type'])) ? $parm['type'] : null; + + $fieldType = $fields[$key]['type']; + + // @todo Move this part to form_handler or e_parse somewhere. + if(isset($fieldData[$key])) { $value = $fieldData[$key]; - switch($type) + switch($fieldType) { case "image": - return $tp->toImage($value); + return ($raw) ? $tp->thumbUrl($value) : $tp->toImage($value); break; case "icon": - return $tp->toIcon($value); + return ($raw) ? str_replace(".glyph", '', $value) : $tp->toIcon($value); break; + case "country": + return ($raw) ? $value : e107::getForm()->getCountry($value); + break; + + case "tags": + return ($raw) ? $value : $tp->toLabel($value,$type); + break; + + case "lanlist": + case "language": + return ($raw) ? $value : e107::getLanguage()->convert($value); + break; + + case "datestamp": + return ($raw) ? $value : $tp->toDate($value); + break; + + case "url": + case "email": + return ($raw) ? $value : $tp->toHtml($value); + break; + + case "user": + return ($raw) ? $value : e107::getSystemUser($value,true)->getName(); + break; + + case "userclass": + return ($raw) ? $value : e107::getUserClass()->getName($value); + break; + + case "textarea": + case "bbarea": + return $tp->toHtml($value, true); + break; + + default: return $tp->toHtml($value); } @@ -653,7 +715,29 @@ class cpage_shortcodes extends e_shortcode } + /** + * @experimental - subject to change without notice. Use at own risk. + * @param null $parm + * @return string + */ + function sc_cpagefields($parm=null) + { + $fieldData = e107::unserialize($this->var['page_fields']); + $text = ' + '; + + foreach($fieldData as $ok=>$v) + { + + $text .= ""; + } + + $text .= "
NameTitle
{CPAGEFIELDTITLE: name=x}
Normal
{CPAGEFIELD: name=x}
Raw
{CPAGEFIELD: name=x&mode=raw}
".$ok."".$this->sc_cpagefieldtitle(array('name'=>$ok))."".$this->sc_cpagefield(array('name'=>$ok))."".$this->sc_cpagefield(array('name'=>$ok, 'mode'=>'raw'))."
"; + + return $text; + + } diff --git a/e107_handlers/e_parse_class.php b/e107_handlers/e_parse_class.php index 164462290..407807530 100644 --- a/e107_handlers/e_parse_class.php +++ b/e107_handlers/e_parse_class.php @@ -3641,6 +3641,38 @@ class e_parser } + /** + * @param $text + * @return string + */ + public function toLabel($text, $type = null) + { + if($type === null) + { + $type = 'default'; + } + + $tmp = explode(",",$text); + + $opt = array(); + foreach($tmp as $v) + { + $opt[] = "".$v.""; + } + + return implode(" ",$opt); + } + + /** + * Take a file-path and convert it to a download link. + * @todo + * @param $text + * @return string + */ + public function toFile($text) + { + + } /** * Render an avatar based on supplied user data or current user when missing. diff --git a/e107_handlers/form_handler.php b/e107_handlers/form_handler.php index a970c1288..ab82e7006 100644 --- a/e107_handlers/form_handler.php +++ b/e107_handlers/form_handler.php @@ -4025,6 +4025,10 @@ class e_form // else same break; + case 'country': + $value = $this->getCountry($value); + break; + case 'ip': //$e107 = e107::getInstance(); $value = "".e107::getIPHandler()->ipDecode($value).'';; @@ -4950,6 +4954,10 @@ class e_form $ret = vartrue($parms['pre']).$this->number($key, $value, $maxlength, $parms).vartrue($parms['post']); break; + case 'country': + $ret = vartrue($parms['pre']).$this->country($key, $value).vartrue($parms['post']); + break; + case 'ip': $ret = vartrue($parms['pre']).$this->text($key, e107::getIPHandler()->ipDecode($value), 32, $parms).vartrue($parms['post']); break;