From c8ba5fe30a18a60f5a398bf1e9526d8b098bd117 Mon Sep 17 00:00:00 2001 From: Cameron Date: Fri, 8 Jan 2021 17:00:23 -0800 Subject: [PATCH] Shortcode tests for list_new, pm, rss_menu, signin and simpleParse() --- e107_handlers/e_parse_class.php | 22 +- e107_plugins/list_new/list_class.php | 104 ++++---- e107_plugins/list_new/list_shortcodes.php | 40 ++- e107_plugins/pm/pm_func.php | 2 +- e107_plugins/pm/pm_shortcodes.php | 91 ++++--- e107_plugins/rss_menu/admin_prefs.php | 81 +----- e107_plugins/rss_menu/rss.php | 5 +- e107_plugins/rss_menu/rss_shortcodes.php | 235 +++--------------- e107_plugins/signin/signin_shortcodes.php | 3 +- e107_tests/tests/unit/e_parseTest.php | 17 +- .../tests/unit/e_parse_shortcodeTest.php | 159 ++++++++++-- 11 files changed, 363 insertions(+), 396 deletions(-) diff --git a/e107_handlers/e_parse_class.php b/e107_handlers/e_parse_class.php index a899b6161..12571b8cc 100644 --- a/e107_handlers/e_parse_class.php +++ b/e107_handlers/e_parse_class.php @@ -929,7 +929,7 @@ class e_parse extends e_parser //return ($this->replaceVars[$key] !== null ? $this->replaceVars[$key]: $unset); } $key = $tmp[1]; // PHP7 fix. - return ($this->replaceVars->$key !== null ? $this->replaceVars->$key : $unset); // Doesn't work. + return (!empty($this->replaceVars) && ($this->replaceVars->$key !== null)) ? $this->replaceVars->$key : $unset; // Doesn't work. } @@ -6060,12 +6060,19 @@ class e_emotefilter class e_profanityFilter { protected $profanityList; + private $pref; public function __construct() { - global $pref; - $words = explode(',', $pref['profanity_words']); + $this->pref = e107::getPref(); + + if(empty($this->pref['profanity_words'])) + { + return null; + } + + $words = explode(',', $this->pref['profanity_words']); $word_array = array(); foreach($words as $word) { @@ -6089,14 +6096,15 @@ class e_profanityFilter public function filterProfanities($text) { - global $pref; - if (!$this->profanityList) + + if (empty($this->profanityList)) { return $text; } - if ($pref['profanity_replace']) + + if(!empty($this->pref['profanity_replace'])) { - return preg_replace("#\b".$this->profanityList."\b#is", $pref['profanity_replace'], $text); + return preg_replace("#\b".$this->profanityList."\b#is", $this->pref['profanity_replace'], $text); } return preg_replace_callback("#\b".$this->profanityList."\b#is", array($this, 'replaceProfanities'), $text); diff --git a/e107_plugins/list_new/list_class.php b/e107_plugins/list_new/list_class.php index e62c53c77..f44610716 100644 --- a/e107_plugins/list_new/list_class.php +++ b/e107_plugins/list_new/list_class.php @@ -33,6 +33,8 @@ class listclass var $list_pref; var $mode; var $shortcodes = FALSE; + private $pf; // profanity filter class. + public $data; /** * constructor @@ -180,7 +182,10 @@ class listclass $arr[$s]['amount'] = vartrue($this->list_pref[$s."_".$mode."_amount"]); $arr[$s]['order'] = vartrue($this->list_pref[$s."_".$mode."_order"]); $arr[$s]['section'] = $s; + + } + } //sort array on order values set in preferences usort($arr, function($e, $f) @@ -226,6 +231,8 @@ class listclass return; } + $content_name = ''; + $content_types = array(); //get top level categories @@ -302,63 +309,63 @@ class listclass { if ($plugin_installed = isset($pref['plug_installed'][e107::getParser()->toDB($s, true)])) { - $prf["$s_recent_menu_caption"] = $s; - $prf["$s_recent_page_caption"] = $s; - $prf["$s_new_menu_caption"] = $s; - $prf["$s_new_page_caption"] = $s; + $prf[$s."_recent_menu_caption"] = $s; + $prf[$s."_recent_page_caption"] = $s; + $prf[$s."_new_menu_caption"] = $s; + $prf[$s."_new_page_caption"] = $s; } } else { - $prf["$s_recent_menu_caption"] = $this->titles[$i]; - $prf["$s_recent_page_caption"] = $this->titles[$i]; - $prf["$s_new_menu_caption"] = $this->titles[$i]; - $prf["$s_new_page_caption"] = $this->titles[$i]; + $prf[$s."_recent_menu_caption"] = $this->titles[$i]; + $prf[$s."_recent_page_caption"] = $this->titles[$i]; + $prf[$s."_new_menu_caption"] = $this->titles[$i]; + $prf[$s."_new_page_caption"] = $this->titles[$i]; } } else { - $prf["$s_recent_menu_caption"] = $s; - $prf["$s_recent_page_caption"] = $s; - $prf["$s_new_menu_caption"] = $s; - $prf["$s_new_page_caption"] = $s; + $prf[$s."_recent_menu_caption"] = $s; + $prf[$s."_recent_page_caption"] = $s; + $prf[$s."_new_menu_caption"] = $s; + $prf[$s."_new_page_caption"] = $s; } - $prf["$s_recent_menu_display"] = "1"; - $prf["$s_recent_menu_open"] = "0"; - $prf["$s_recent_menu_author"] = "0"; - $prf["$s_recent_menu_category"] = "0"; - $prf["$s_recent_menu_date"] = "1"; - $prf["$s_recent_menu_amount"] = "5"; - $prf["$s_recent_menu_order"] = ($i+1); - $prf["$s_recent_menu_icon"] = ''; + $prf[$s."_recent_menu_display"] = "1"; + $prf[$s."_recent_menu_open"] = "0"; + $prf[$s."_recent_menu_author"] = "0"; + $prf[$s."_recent_menu_category"] = "0"; + $prf[$s."_recent_menu_date"] = "1"; + $prf[$s."_recent_menu_amount"] = "5"; + $prf[$s."_recent_menu_order"] = ($i+1); + $prf[$s."_recent_menu_icon"] = ''; - $prf["$s_recent_page_display"] = "1"; - $prf["$s_recent_page_open"] = "1"; - $prf["$s_recent_page_author"] = "1"; - $prf["$s_recent_page_category"] = "1"; - $prf["$s_recent_page_date"] = "1"; - $prf["$s_recent_page_amount"] = "10"; - $prf["$s_recent_page_order"] = ($i+1); - $prf["$s_recent_page_icon"] = "1"; + $prf[$s."_recent_page_display"] = "1"; + $prf[$s."_recent_page_open"] = "1"; + $prf[$s."_recent_page_author"] = "1"; + $prf[$s."_recent_page_category"] = "1"; + $prf[$s."_recent_page_date"] = "1"; + $prf[$s."_recent_page_amount"] = "10"; + $prf[$s."_recent_page_order"] = ($i+1); + $prf[$s."_recent_page_icon"] = "1"; - $prf["$s_new_menu_display"] = "1"; - $prf["$s_new_menu_open"] = "0"; - $prf["$s_new_menu_author"] = "0"; - $prf["$s_new_menu_category"] = "0"; - $prf["$s_new_menu_date"] = "1"; - $prf["$s_new_menu_amount"] = "5"; - $prf["$s_new_menu_order"] = ($i+1); - $prf["$s_new_menu_icon"] = "1"; + $prf[$s."_new_menu_display"] = "1"; + $prf[$s."_new_menu_open"] = "0"; + $prf[$s."_new_menu_author"] = "0"; + $prf[$s."_new_menu_category"] = "0"; + $prf[$s."_new_menu_date"] = "1"; + $prf[$s."_new_menu_amount"] = "5"; + $prf[$s."_new_menu_order"] = ($i+1); + $prf[$s."_new_menu_icon"] = "1"; - $prf["$s_new_page_display"] = "1"; - $prf["$s_new_page_open"] = "1"; - $prf["$s_new_page_author"] = "1"; - $prf["$s_new_page_category"] = "1"; - $prf["$s_new_page_date"] = "1"; - $prf["$s_new_page_amount"] = "10"; - $prf["$s_new_page_order"] = ($i+1); - $prf["$s_new_page_icon"] = "1"; + $prf[$s."_new_page_display"] = "1"; + $prf[$s."_new_page_open"] = "1"; + $prf[$s."_new_page_author"] = "1"; + $prf[$s."_new_page_category"] = "1"; + $prf[$s."_new_page_date"] = "1"; + $prf[$s."_new_page_amount"] = "10"; + $prf[$s."_new_page_order"] = ($i+1); + $prf[$s."_new_page_icon"] = "1"; } //new menu preferences @@ -583,16 +590,15 @@ class listclass if (e107::getPref('profanity_filter')) { $tp = e107::getParser(); - if (!is_object($parser->e_pf)) + if (!is_object($this->pf)) { - // require_once(e_HANDLER.'profanity_filter.php'); - $parser->e_pf = new e_profanityFilter; + $this->pf = new e_profanityFilter; } foreach ($listArray as $k => $v) { if (isset($v['heading'])) { - $listArray[$k]['heading'] = $tp->e_pf->filterProfanities($v['heading']); + $listArray[$k]['heading'] = $this->pf->filterProfanities($v['heading']); } } } @@ -781,6 +787,8 @@ class listclass { global $qs; + $text = ''; + //get preferences if(!isset($this->list_pref)) { diff --git a/e107_plugins/list_new/list_shortcodes.php b/e107_plugins/list_new/list_shortcodes.php index 1e7cf6a7c..0d8fb01f3 100644 --- a/e107_plugins/list_new/list_shortcodes.php +++ b/e107_plugins/list_new/list_shortcodes.php @@ -24,18 +24,12 @@ if (!defined('e107_INIT')) { exit; } class list_shortcodes { - var $rc; + var $rc; // list class. var $e107; var $row; - var $list_pref; + var $list_pref = array(); public $plugin; - function __construct() - { - $this->e107 = e107::getInstance(); - $this->rc = ''; - } - /* function load_globals() { @@ -90,37 +84,63 @@ class list_shortcodes function sc_list_info() { + if(empty($this->row['info'])) + { + return null; + } + return e107::getParser()->toHTML($this->row['info'], true, ""); } function sc_list_caption() { + if(empty($this->rc->data) || empty($this->rc->data['caption'])) + { + return null; + } + return e107::getParser()->toHTML($this->rc->data['caption'], true, ""); } function sc_list_displaystyle() { //open sections if content exists ? yes if true, else use individual setting of section - return (vartrue($this->list_pref[$this->rc->mode."_openifrecords"]) && is_array($this->rc->data['records']) ? "" : $this->rc->data['display']); + $mode = $this->rc->mode."_openifrecords"; + return (!empty($this->list_pref[$mode]) && isset($this->rc->data['records']) && is_array($this->rc->data['records'])) ? "" : varset($this->rc->data['display']); } function sc_list_col_cols() { + if(empty($this->list_pref[$this->rc->mode."_colomn"])) + { + return null; + } + return $this->list_pref[$this->rc->mode."_colomn"]; } function sc_list_col_welcometext() { + if(empty($this->list_pref[$this->rc->mode."_welcometext"])) + { + return null; + } + return e107::getParser()->toHTML($this->list_pref[$this->rc->mode."_welcometext"], true, ""); } function sc_list_col_cellwidth() { + if(empty($this->list_pref[$this->rc->mode."_colomn"])) + { + return 25; + } + return round((100/$this->list_pref[$this->rc->mode."_colomn"]),0); } function sc_list_timelapse() { - return $this->row['timelapse']; + return varset($this->row['timelapse']); } } diff --git a/e107_plugins/pm/pm_func.php b/e107_plugins/pm/pm_func.php index 3749bb8cd..9e5620ad4 100755 --- a/e107_plugins/pm/pm_func.php +++ b/e107_plugins/pm/pm_func.php @@ -66,7 +66,7 @@ class pmbox_manager { $this->pmDB->gen($qry); $pm_info[$which] = $this->pmDB->fetch(); - if ($which == 'inbox' && ($this->pmPrefs['animate'] == 1 || $this->pmPrefs['popup'] == 1)) + if ($which == 'inbox' && (!empty($this->pmPrefs['animate']) || !empty($this->pmPrefs['popup']))) { if($new = $this->pmDB->count('private_msg', '(*)', "WHERE pm_sent > '".USERLV."' AND pm_read = 0 AND pm_to = '".USERID."' AND pm_read_del != 1")) { diff --git a/e107_plugins/pm/pm_shortcodes.php b/e107_plugins/pm/pm_shortcodes.php index 9fb5d9e55..9c5c74738 100644 --- a/e107_plugins/pm/pm_shortcodes.php +++ b/e107_plugins/pm/pm_shortcodes.php @@ -115,7 +115,7 @@ if(!class_exists('plugin_pm_pm_shortcodes')) } - public function sc_pm_form_to($parm) + public function sc_pm_form_to($parm=null) { $userTo = $this->sc_pm_form_touser(); $classTo = $this->sc_pm_form_toclass(); @@ -128,7 +128,7 @@ if(!class_exists('plugin_pm_pm_shortcodes')) if(deftrue('BOOTSTRAP')) { - if(check_class($this->pmPrefs['opt_userclass']) ) + if(isset($this->pmPrefs['opt_userclass']) && check_class($this->pmPrefs['opt_userclass']) ) { $tab = array(); @@ -168,7 +168,7 @@ if(!class_exists('plugin_pm_pm_shortcodes')) // $type = ($this->pmPrefs['dropdown'] == TRUE ? 'list' : 'popup'); - if(check_class($this->pmPrefs['multi_class'])) + if(isset($this->pmPrefs['multi_class']) && check_class($this->pmPrefs['multi_class'])) { $ret = e107::getForm()->userpicker('pm_to', null, array('limit'=>10)); } @@ -198,7 +198,7 @@ if(!class_exists('plugin_pm_pm_shortcodes')) $ret = ""; - if(check_class($this->pmPrefs['opt_userclass']) ) + if(isset($this->pmPrefs['opt_userclass']) && check_class($this->pmPrefs['opt_userclass']) ) { //$ret = "".LAN_PM_4." "; @@ -286,19 +286,19 @@ if(!class_exists('plugin_pm_pm_shortcodes')) public function sc_pm_post_button() { - return ""; + return ""; } public function sc_pm_preview_button() { - return ""; + return ""; } public function sc_pm_attachment() { - if (check_class($this->pmPrefs['attach_class'])) + if (isset($this->pmPrefs['attach_class']) && check_class($this->pmPrefs['attach_class'])) { $ret = "
@@ -322,9 +322,9 @@ if(!class_exists('plugin_pm_pm_shortcodes')) public function sc_pm_attachment_icon() { - if($this->var['pm_attachments'] != "") + if(!empty($this->var['pm_attachments'])) { - return ATTACHMENT_ICON; + return defset('ATTACHMENT_ICON'); } } @@ -333,7 +333,7 @@ if(!class_exists('plugin_pm_pm_shortcodes')) { $tp = e107::getParser(); - if($this->var['pm_attachments'] != '') + if(!empty($this->var['pm_attachments'])) { $attachments = explode(chr(0), $this->var['pm_attachments']); $i = 0; @@ -353,7 +353,7 @@ if(!class_exists('plugin_pm_pm_shortcodes')) public function sc_pm_receipt() { - if (check_class($this->pmPrefs['receipt_class'])) + if (isset($this->pmPrefs['receipt_class']) && check_class($this->pmPrefs['receipt_class'])) { return "".LAN_PM_10; } @@ -364,50 +364,50 @@ if(!class_exists('plugin_pm_pm_shortcodes')) public function sc_pm_inbox_total() { $pm_inbox = $this->pmManager->pm_getInfo('inbox'); - return (int) $pm_inbox['inbox']['total']; + return (int) varset($pm_inbox['inbox']['total']); } public function sc_pm_inbox_unread() { $pm_inbox = $this->pmManager->pm_getInfo('inbox'); - return (int) $pm_inbox['inbox']['unread']; + return (int) varset($pm_inbox['inbox']['unread']); } public function sc_pm_inbox_filled() { $pm_inbox = $this->pmManager->pm_getInfo('inbox'); - return ((int) $pm_inbox['inbox']['filled'] > 0 ? $pm_inbox['inbox']['filled'] : ''); + return (isset($pm_inbox['inbox']['filled']) && ((int) $pm_inbox['inbox']['filled'] > 0)) ? $pm_inbox['inbox']['filled'] : ''; } public function sc_pm_outbox_total() { $pm_outbox = $this->pmManager->pm_getInfo('outbox'); - return (int) $pm_outbox['outbox']['total']; + return (int) varset($pm_outbox['outbox']['total']); } public function sc_pm_outbox_unread() { $pm_outbox = $this->pmManager->pm_getInfo('outbox'); - return (int) $pm_outbox['outbox']['unread']; + return (int) varset($pm_outbox['outbox']['unread']); } public function sc_pm_outbox_filled() { $pm_outbox = $this->pmManager->pm_getInfo('outbox'); - return ((int) $pm_outbox['outbox']['filled'] > 0 ? $pm_outbox['outbox']['filled'] : ''); + return (isset($pm_outbox['outbox']['filled']) && ((int) $pm_outbox['outbox']['filled'] > 0)) ? $pm_outbox['outbox']['filled'] : ''; } - public function sc_pm_date($parm = '') + public function sc_pm_date($parm = null) { $tp = e107::getParser(); - if($parm) + if(!empty($parm)) { return $tp->toDate($this->var['pm_sent'], $parm); } @@ -468,14 +468,23 @@ if(!class_exists('plugin_pm_pm_shortcodes')) } - public function sc_pm_subject($parm = '') + public function sc_pm_subject($parm = null) { $tp = e107::getParser(); $ret = $tp->toHTML($this->var['pm_subject'], true, 'USER_TITLE'); - $prm = explode(',',$parm); - if('link' === $prm[0]) + + if(is_string($parm)) + { + $prm = explode(',', $parm); + } + else + { + $prm = $parm; + } + + if('link' === varset($prm[0])) { $extra = ''; // TODO - go with only one route version - view/message ??? @@ -522,11 +531,11 @@ if(!class_exists('plugin_pm_pm_shortcodes')) { if($this->var['pm_read'] > 0 ) { - return PM_READ_ICON; + return defset('PM_READ_ICON'); } else { - return PM_UNREAD_ICON; + return defset('PM_UNREAD_ICON'); } } @@ -545,7 +554,7 @@ if(!class_exists('plugin_pm_pm_shortcodes')) } - public function sc_pm_avatar($parm) + public function sc_pm_avatar($parm=null) { return e107::getParser()->toAvatar($this->var, $parm); } @@ -661,7 +670,7 @@ if(!class_exists('plugin_pm_pm_shortcodes')) public function sc_pm_newpm_animate() { - if($this->pmPrefs['animate']) + if(!empty($this->pmPrefs['animate'])) { $pm_inbox = $this->pmManager->pm_getInfo('inbox'); if($pm_inbox['inbox']['new'] > 0) @@ -673,8 +682,13 @@ if(!class_exists('plugin_pm_pm_shortcodes')) } - public function sc_pm_nextprev($parm = '') + public function sc_pm_nextprev($parm = null) { + if(empty($this->pmNextPrev['total'])) + { + return null; + } + return e107::getParser()->parseTemplate("{NEXTPREV={$this->pmNextPrev['total']},{$this->pmPrefs['perpage']},{$this->pmNextPrev['start']},".e_SELF."?{$parm}.[FROM]}"); } @@ -690,15 +704,20 @@ if(!class_exists('plugin_pm_pm_shortcodes')) public function sc_pm_blocked_select() { + if(!isset($this->pmBlocked['pm_block_from'])) + { + return null; + } + return ""; } public function sc_pm_blocked_user($parm = '') { - if (!$this->pmBlocked['user_name']) + if (empty($this->pmBlocked['user_name'])) { - $ret = LAN_PM_72; + $ret = defset('LAN_PM_72', "User deleted"); // define('LAN_PM_72', 'User deleted'); } if('link' === $parm) { @@ -708,7 +727,7 @@ if(!class_exists('plugin_pm_pm_shortcodes')) } else { - $ret = $this->pmBlocked['user_name']; + $ret = varset($this->pmBlocked['user_name']); } return $ret; @@ -717,12 +736,22 @@ if(!class_exists('plugin_pm_pm_shortcodes')) public function sc_pm_blocked_date($parm='') { + if(empty($this->pmBlocked['pm_block_datestamp'])) + { + return null; + } + return e107::getDate()->convert_date($this->pmBlocked['pm_block_datestamp'], $parm); } public function sc_pm_blocked_delete() { + if(empty($this->pmBlocked['pm_block_from'])) + { + return null; + } + return " $this->pmBlocked['pm_block_from']))."'>".LAN_DELETE.""; } @@ -740,7 +769,7 @@ if(!class_exists('plugin_pm_pm_shortcodes')) $class = (!empty($parm['class'])) ? $parm['class'] : 'btn btn-sm btn-primary btn-block-level'; - return "".$tp->toGlyph('fa-edit',' ')."".LAN_PLUGIN_PM_NEW.""; + return "".$tp->toGlyph('fa-edit',' ')."".defset('LAN_PLUGIN_PM_NEW').""; } diff --git a/e107_plugins/rss_menu/admin_prefs.php b/e107_plugins/rss_menu/admin_prefs.php index 214deb4d4..77216f0ea 100644 --- a/e107_plugins/rss_menu/admin_prefs.php +++ b/e107_plugins/rss_menu/admin_prefs.php @@ -159,10 +159,9 @@ class rss_ui extends e_admin_ui global $i,$rss_shortcodes, $feed, $pref; require_once(e_PLUGIN.'rss_menu/rss_shortcodes.php'); + $rss_shortcodes = e107::getScBatch('rss_menu', true); - if(!isset($RSS_ADMIN_IMPORT_HEADER)) - { - $RSS_ADMIN_IMPORT_HEADER = " + $RSS_ADMIN_IMPORT_HEADER = "
@@ -175,10 +174,8 @@ class rss_ui extends e_admin_ui "; - } - if(!isset($RSS_ADMIN_IMPORT_TABLE)) - { - $RSS_ADMIN_IMPORT_TABLE = " + + $RSS_ADMIN_IMPORT_TABLE = " @@ -187,85 +184,22 @@ class rss_ui extends e_admin_ui "; - } - if(!isset($RSS_ADMIN_IMPORT_FOOTER)) - { - $RSS_ADMIN_IMPORT_FOOTER = " + + $RSS_ADMIN_IMPORT_FOOTER = "
".RSS_LAN_ADMIN_12."
{RSS_ADMIN_IMPORT_CHECK} {RSS_ADMIN_IMPORT_NAME} - {RSS_ADMIN_IMPORT_TEXT}{RSS_ADMIN_IMPORT_URL} {RSS_ADMIN_IMPORT_TOPICID}
".$frm->admin_button('import_rss',LAN_ADD,'submit')."
"; - } - - - // global $RSS_ADMIN_IMPORT_HEADER, $RSS_ADMIN_IMPORT_TABLE, $RSS_ADMIN_IMPORT_FOOTER; - $sqli = new db; $feedlist = array(); // @see e107_plugins/news/e_rss.php - /* - // News - $feed['name'] = ADLAN_0; - $feed['url'] = 'news'; // The identifier for the rss feed url - $feed['topic_id'] = ''; // The topic_id, empty on default (to select a certain category) - $feed['path'] = 'news'; // This is the plugin path location - $feed['text'] = RSS_PLUGIN_LAN_7; - $feed['class'] = '0'; - $feed['limit'] = '9'; - $feedlist[] = $feed; - // News categories - if($sqli ->select("news_category", "*","category_id!='' ORDER BY category_name ")) - { - while($rowi = $sqli ->fetch()) - { - $feed['name'] = ADLAN_0.' > '.$rowi['category_name']; - $feed['url'] = 'news'; - $feed['topic_id'] = $rowi['category_id']; - $feed['path'] = 'news'; - $feed['text'] = RSS_PLUGIN_LAN_10.' '.$rowi['category_name']; - $feed['class'] = '0'; - $feed['limit'] = '9'; - // $feed['exclude_class'] = ''; - $feedlist[] = $feed; - } - }*/ - - /* // Download - $feed['name'] = ADLAN_24; - $feed['url'] = 'download'; - $feed['topic_id'] = ''; - $feed['path'] = 'download'; - $feed['text'] = RSS_PLUGIN_LAN_8; - $feed['class'] = '0'; - $feed['limit'] = '9'; - $feedlist[] = $feed; - - // Download categories - if($sqli ->select("download_category", "*","download_category_id!='' ORDER BY download_category_order ")) - { - while($rowi = $sqli ->fetch()) - { - $feed['name'] = ADLAN_24.' > '.$rowi['download_category_name']; - $feed['url'] = 'download'; - $feed['topic_id'] = $rowi['download_category_id']; - $feed['path'] = 'download'; - $feed['text'] = RSS_PLUGIN_LAN_11.' '.$rowi['download_category_name']; - $feed['class'] = '0'; - $feed['limit'] = '9'; - $feedlist[] = $feed; - } - } - */ - - - // // Comments $feed['name'] = LAN_COMMENTS; $feed['url'] = 'comments'; @@ -318,10 +252,12 @@ class rss_ui extends e_admin_ui if(!$sql->select("rss", "*", "rss_path='".$feed['path']."' AND rss_url='".$feed['url']."' AND rss_topicid='".$feed['topic_id']."' ")) { $render = TRUE; + $rss_shortcodes->setVars($feed); $text .= $tp -> parseTemplate($RSS_ADMIN_IMPORT_TABLE, FALSE, $rss_shortcodes); $i++; } } + $text .= $tp -> parseTemplate($RSS_ADMIN_IMPORT_FOOTER, FALSE, $rss_shortcodes); if(!$render) @@ -330,7 +266,6 @@ class rss_ui extends e_admin_ui } else { - // $ns->tablerender(RSS_LAN_ADMIN_11, $mes->render(). $text); return $text; } diff --git a/e107_plugins/rss_menu/rss.php b/e107_plugins/rss_menu/rss.php index 83b697b8d..e97d04561 100644 --- a/e107_plugins/rss_menu/rss.php +++ b/e107_plugins/rss_menu/rss.php @@ -112,14 +112,15 @@ if (empty($rss_type)) } } - $text = $tp->parseTemplate($RSS_LIST_HEADER); + $text = $tp->parseTemplate($RSS_LIST_HEADER, true); while($row = $sql->fetch()) { + $sc->setVars($row); $text .= $tp->parseTemplate($RSS_LIST_TABLE, false, $sc); } - $text .= $tp->parseTemplate($RSS_LIST_FOOTER); + $text .= $tp->parseTemplate($RSS_LIST_FOOTER, true); $ns->tablerender(RSS_MENU_L2, $text); } diff --git a/e107_plugins/rss_menu/rss_shortcodes.php b/e107_plugins/rss_menu/rss_shortcodes.php index cde44e60d..1e0877ca6 100644 --- a/e107_plugins/rss_menu/rss_shortcodes.php +++ b/e107_plugins/rss_menu/rss_shortcodes.php @@ -11,279 +11,108 @@ */ if (!defined('e107_INIT')) { exit; } - include_once(e_HANDLER.'shortcode_handler.php'); -// $rss_shortcodes = $tp -> e_sc -> parse_scbatch(__FILE__); - class rss_menu_shortcodes extends e_shortcode { + private $tp; - - + function __construct() + { + $this->tp = e107::getParser(); + } function sc_rss_feed() { - global $row, $tp; - // $url2 = e_PLUGIN."rss_menu/rss.php?".e_LANQRY.$tp->toHTML($row['rss_url'], TRUE, 'constants').".2".($row['rss_topicid'] ? ".".$row['rss_topicid'] : ''); - $url2 = e107::url('rss_menu','rss', $row); - return "".$tp->toHTML($row['rss_name'], TRUE).""; + $url2 = e107::url('rss_menu','rss', $this->var); + return "".$this->tp->toHTML($this->var['rss_name'], TRUE).""; } function sc_rss_icon() { - global $row, $tp; - // $url2 = e_PLUGIN_ABS."rss_menu/rss.php?".e_LANQRY.$tp->toHTML($row['rss_url'], TRUE, 'constants').".2".($row['rss_topicid'] ? ".".$row['rss_topicid'] : ''); - $url2 = e107::url('rss_menu','rss', $row); - return "".RSS_ICON.""; + $url2 = e107::url('rss_menu','rss', $this->var); + return "".defset('RSS_ICON').""; } function sc_rss_text() { - global $row, $tp; - return $tp->toHTML($row['rss_text'], TRUE, "defs"); + return $this->tp->toHTML($this->var['rss_text'], TRUE, "defs"); } function sc_rss_types() { - global $row, $tp; - // $url1 = e_PLUGIN_ABS."rss_menu/rss.php?".e_LANQRY.$tp->toHTML($row['rss_url'], TRUE, 'constants').".1".($row['rss_topicid'] ? ".".$row['rss_topicid'] : ''); - // $url2 = e_PLUGIN_ABS."rss_menu/rss.php?".e_LANQRY.$tp->toHTML($row['rss_url'], TRUE, 'constants').".2".($row['rss_topicid'] ? ".".$row['rss_topicid'] : ''); - // $url3 = e_PLUGIN_ABS."rss_menu/rss.php?".e_LANQRY.$tp->toHTML($row['rss_url'], TRUE, 'constants').".3".($row['rss_topicid'] ? ".".$row['rss_topicid'] : ''); - // $url4 = e_PLUGIN_ABS."rss_menu/rss.php?".e_LANQRY.$tp->toHTML($row['rss_url'], TRUE, 'constants').".4".($row['rss_topicid'] ? ".".$row['rss_topicid'] : ''); - - $url2 = e107::url('rss_menu','rss', $row); - $url4 = e107::url('rss_menu','atom', $row); - + $url2 = e107::url('rss_menu','rss', $this->var); + $url4 = e107::url('rss_menu','atom', $this->var); if(deftrue('BOOTSTRAP')) // v2.x { $text = "
- ".$tp->toGlyph('fa-rss')." RSS - ".$tp->toGlyph('fa-rss')." Atom + ".$this->tp->toGlyph('fa-rss')." RSS + ".$this->tp->toGlyph('fa-rss')." Atom
"; return $text; } - - $text = ""; // $text .= "RSS 0.92"; $text .= "RSS 2.0"; // $text .= "RDF"; $text .= "ATOM"; + return $text; } - - - - - - - - - - - - //##### ADMIN -------------------------------------------------- - - - - function sc_rss_admin_caption($parm='') - { - global $sort; - list($field,$txt) = explode(",",$parm); - $txt = constant($txt); - return "".$txt."\n"; - } - - function sc_rss_admin_id() - { - global $row; - return $row['rss_id']; - } - - function sc_rss_admin_name() - { - global $row; - return $row['rss_name']; - } - - function sc_rss_admin_path() - { - global $row; - return $row['rss_path']; - } - - function sc_rss_admin_url() - { - global $row; - return "".$row['rss_url'].""; - } - - function sc_rss_admin_topicid() - { - global $row; - return $row['rss_topicid']; - } - - function sc_rss_admin_limit() - { - global $row, $rs; - $id = $row['rss_id']; - $frm = e107::getForm(); - return $frm->number("limit[$id]",$row['rss_limit']); - return ""; - } - - function sc_rss_admin_limitbutton() - { - $frm = e107::getForm(); - return $frm->admin_button('update_limit',LAN_UPDATE,'update'); - } - - function sc_rss_admin_options() - { - global $row, $tp; - $delname = $row['rss_name']; - $delid = $row['rss_id']; - $options = " - ".ADMIN_EDIT_ICON." - toJS(LAN_CONFIRMDEL ." [".LAN_ID.": ".$delid." : ".$delname."]\\n\\n")."')\"/>"; - return $options; - } - - function sc_rss_admin_form_name() - { - global $row; - return "\n"; - } - - function sc_rss_admin_form_url() - { - global $row,$PLUGINS_DIRECTORY; - return SITEURL.$PLUGINS_DIRECTORY."rss_menu/rss.php?".e_LANQRY." .{".LAN_TYPE."}.{".RSS_LAN_ADMIN_12."}"; - } - - function sc_rss_admin_form_topicid() - { - global $row; - return ""; - } - - function sc_rss_admin_form_path() - { - global $row; - return ""; - } - - function sc_rss_admin_form_text() - { - global $row; - return "\n"; - } - - function sc_rss_admin_form_class() - { - global $row; - $vals = array(RSS_LAN_ADMIN_21,RSS_LAN_ADMIN_22,RSS_LAN_ADMIN_23); - $text = ""; - return $text; - } - - function sc_rss_admin_form_limit() - { - global $row; - $frm = e107::getForm(); - - return $frm->number('rss_limit',$row['rss_limit'],3); - return ""; - } - - - function sc_rss_admin_form_createbutton() - { - global $row; - $qs = explode(".", e_QUERY); - $frm = e107::getForm(); - - if(isset($qs[1]) && $qs[1] == "edit" && isset($qs[2]) && is_numeric($qs[2]) ) - { - $text = " - "; - - $text .= $frm->admin_button('update_rss',LAN_UPDATE,'update'); - - } - else - { - $text = $frm->admin_button('create_rss',LAN_CREATE,'submit'); - - } - return $text; - } - function sc_rss_admin_import_check() { - global $feed, $rs, $tp, $i; - if($feed['description']) + global $rs, $i; + if(!empty($this->var['description'])) { - $feed['text'] = $feed['description']; + $this->var['text'] = $this->var['description']; } $text = ""; - $text .= ""; - $text .= ""; - $text .= ""; - $text .= ""; - $text .= ""; - $text .= ""; - $text .= ""; + $text .= ""; + $text .= ""; + $text .= ""; + $text .= ""; + $text .= ""; + $text .= ""; + $text .= ""; return $text; } function sc_rss_admin_import_path() { - global $feed, $i; - return ""; + global $i; + return ""; } function sc_rss_admin_import_name() { - global $feed, $i; - return ""; + global $i; + return ""; } function sc_rss_admin_import_text() { - global $feed; - return ($feed['description']) ? $feed['description'] : $feed['text']; + return !empty($this->var['description']) ? $this->var['description'] : $this->var['text']; } function sc_rss_admin_import_url() { - global $feed; - return $feed['url']; + return $this->var['url']; } function sc_rss_admin_import_topicid() { - global $feed; - return $feed['topic_id']; + return $this->var['topic_id']; } } diff --git a/e107_plugins/signin/signin_shortcodes.php b/e107_plugins/signin/signin_shortcodes.php index c9ca9bac9..4bcfba391 100644 --- a/e107_plugins/signin/signin_shortcodes.php +++ b/e107_plugins/signin/signin_shortcodes.php @@ -19,6 +19,7 @@ if (!defined('e107_INIT')) exit(); } +e107::plugLan('login_menu', null); class plugin_signin_signin_shortcodes extends e_shortcode { @@ -166,7 +167,7 @@ class plugin_signin_signin_shortcodes extends e_shortcode { return ""; } - if ($pref['user_tracking'] !== "session") + if (varset($pref['user_tracking']) !== "session") { return "" . ($parm ? $parm : "" . LAN_LOGINMENU_6 ); } diff --git a/e107_tests/tests/unit/e_parseTest.php b/e107_tests/tests/unit/e_parseTest.php index 00728da04..ee23686ea 100644 --- a/e107_tests/tests/unit/e_parseTest.php +++ b/e107_tests/tests/unit/e_parseTest.php @@ -710,12 +710,25 @@ while($row = $sql->fetch()) { } - +*/ public function testSimpleParse() { + $vars = array( + 'CONTACT_SUBJECT'=> "My Subject", + 'CONTACT_PERSON' => "My Name" + ); + + $template = "{CONTACT_SUBJECT} {CONTACT_PERSON}{MISSING_SHORTCODE}"; + + $result = $this->tp->simpleParse($template, $vars); + $this->assertEquals("My Subject My Name", $result); + + $result = $this->tp->simpleParse($template, null); + $this->assertEquals(" ", $result); + } -*/ + public function testToText() { $arr = array( diff --git a/e107_tests/tests/unit/e_parse_shortcodeTest.php b/e107_tests/tests/unit/e_parse_shortcodeTest.php index 4b35efacd..e0dd6e5a3 100644 --- a/e107_tests/tests/unit/e_parse_shortcodeTest.php +++ b/e107_tests/tests/unit/e_parse_shortcodeTest.php @@ -1222,6 +1222,146 @@ class e_parse_shortcodeTest extends \Codeception\Test\Unit } + public function testPMShortcodes() + { + require_once(e_PLUGIN."pm/pm_shortcodes.php"); + + try + { + /** @var plugin_pm_pm_shortcodes $sc */ + $sc = $this->make('plugin_pm_pm_shortcodes'); + } + catch (Exception $e) + { + $this->fail($e->getMessage()); + } + + $sc->__construct(); + + $vars = array( + 'pm_id' => 5, + 'pm_sent' => time(), + 'pm_read' => 0, + 'pm_from' => 1, + 'from_name' => 'admin', + 'pm_to' => 1, + 'pm_block_datestamp' => time(), + 'pm_block_from'=> 2, + + ); + + $sc->setVars($vars); + + $this->processShortcodeMethods($sc); + + } + + + public function testRSSShortcodes() + { + require_once(e_PLUGIN."rss_menu/rss_shortcodes.php"); + + try + { + /** @var rss_menu_shortcodes $sc */ + $sc = $this->make('rss_menu_shortcodes'); + } + catch (Exception $e) + { + $this->fail($e->getMessage()); + } + + $sc->__construct(); + + $vars = array( + 'rss_id' => '1', + 'rss_name' => 'News', + 'rss_url' => 'news', + 'rss_topicid' => '0', + 'rss_path' => '0', + 'rss_text' => 'The rss feed of the news', + 'rss_datestamp' => '1456448477', + 'rss_class' => '0', + 'rss_limit' => '10', + // import shortcodes. + 'name' => "Comments", + 'url' => 'comments', + 'topic_id' => '', + 'path' => 'comments', + 'text' => 'the rss feed of comments', + 'class' => '0', + 'limit' => '9', + ); + + $sc->setVars($vars); + + $this->processShortcodeMethods($sc); + + } + + + + public function testSigninShortcodes() + { + require_once(e_PLUGIN."signin/signin_shortcodes.php"); + + try + { + /** @var plugin_signin_signin_shortcodes $sc */ + $sc = $this->make('plugin_signin_signin_shortcodes'); + } + catch (Exception $e) + { + $this->fail($e->getMessage()); + } + + $sc->__construct(); + + $this->processShortcodeMethods($sc); + + } + + public function testListShortcodes() + { + require_once(e_PLUGIN."list_new/list_shortcodes.php"); + require_once(e_PLUGIN."list_new/list_class.php"); + + try + { + /** @var list_shortcodes $sc */ + $sc = $this->make('list_shortcodes'); + } + catch (Exception $e) + { + $this->fail($e->getMessage()); + } + + $sc->rc = new listclass; + + $vars = array ( + 'caption' => 'My Caption', + 'display' => '1', + 'open' => '1', + 'author' => '', + 'category' => '1', + 'date' => '', + 'icon' => '', + 'amount' => '1', + 'order' => '1', + 'section' => 'news', + ); + + + $sc->row = $vars; + + $exclude = array('sc_list_category'); // unknown issue. + + $this->processShortcodeMethods($sc, $exclude); + + } + + + /* @@ -1229,24 +1369,7 @@ class e_parse_shortcodeTest extends \Codeception\Test\Unit e107_plugins\links_page (1 usage found) links_page_shortcodes.php (1 usage found) 1