diff --git a/e107_admin/prefs.php b/e107_admin/prefs.php index fc0c97031..9843319dd 100644 --- a/e107_admin/prefs.php +++ b/e107_admin/prefs.php @@ -112,7 +112,7 @@ if(isset($_POST['updateprefs'])) if(isset($_POST['contact_info']) && is_array($_POST['contact_info'])) { - $core_pref->set('contact_info', []); // reset to type array if string had been used in the past. + $core_pref->set('contact_info', []); // reset to type array if string had been used in the past. } $smtp_opts = array(); diff --git a/e107_core/shortcodes/batch/news_shortcodes.php b/e107_core/shortcodes/batch/news_shortcodes.php index e4686a1c4..52ec79adc 100644 --- a/e107_core/shortcodes/batch/news_shortcodes.php +++ b/e107_core/shortcodes/batch/news_shortcodes.php @@ -99,6 +99,11 @@ class news_shortcodes extends e_shortcode e107::getBB()->clearClass(); + if($parm == 'raw') + { + $news_body = strip_tags($news_body); + } + return $news_body; } @@ -507,7 +512,12 @@ class news_shortcodes extends e_shortcode { $imgParms['loading'] = $parm['loading']; } - + + if(!empty($parm['return'])) + { + $imgParms['return'] = $parm['return']; + $parm['type'] = 'meta'; + } $imgTag = $tp->toImage($srcPath,$imgParms); @@ -522,6 +532,10 @@ class news_shortcodes extends e_shortcode return empty($src) ? e_IMAGE_ABS."generic/nomedia.png" : $src; break; + case 'meta': + return $tp->replaceConstants($imgTag, 'full'); + break; + case 'url': return "news_item)."'>".$imgTag.""; break; @@ -622,6 +636,10 @@ class news_shortcodes extends e_shortcode $ret = $con->convert_date($date, 'forum'); break; + case 'atom': + $ret = date(DATE_ATOM, $date); + break; + default : $ret = $tp->toDate($date, $parm); break; @@ -640,6 +658,10 @@ class news_shortcodes extends e_shortcode function sc_news_modified($parm=null) { + if(empty($this->news_item['news_modified'])) + { + return null; + } return $this->formatDate($this->news_item['news_modified'], $parm); } @@ -1097,7 +1119,9 @@ class news_shortcodes extends e_shortcode function sc_news_url($parm=null) { - return e107::getUrl()->create('news/view/item', $this->news_item); + $options = (!empty($parm) && is_array($parm)) ? $parm : array(); + + return e107::getUrl()->create('news/view/item', $this->news_item, $options); } diff --git a/e107_handlers/e_parse_class.php b/e107_handlers/e_parse_class.php index 8d6d1e67e..cc903bf03 100644 --- a/e107_handlers/e_parse_class.php +++ b/e107_handlers/e_parse_class.php @@ -854,27 +854,118 @@ class e_parse return e107::getScParser()->parseCodes($text, $parseSCFiles, $extraCodes, $eVars); } + /** - * @experimental - * @param string $text - * @param bool $parseSCFiles - * @param object|array $extraCodes - * @param object $eVars - * @return string + * Parses a JSON schema template, processes placeholders, and reconstructs the JSON with optional main entity and extra codes. + * + * @param string $text The JSON schema template to be parsed. + * @param bool $parseSCFiles Whether to enable the parsing of shortcode files. Defaults to true. + * @param object|null $extraCodes Optional extra codes object for placeholder parsing. + * @param array|null $mainEntity Optional data array to replace the 'mainEntity' structure in the schema. + * @return string|false The processed JSON schema string on success, or false if the input JSON is invalid. */ - public function parseSchemaTemplate($text, $parseSCFiles = true, $extraCodes = null, $eVars = null) + public function parseSchemaTemplate($text, $parseSCFiles = true, $extraCodes = null, $mainEntity = null) { + + // Initialize the parser $parse = e107::getScParser(); - $parse->setMode('schema'); - $text = e107::getScParser()->parseCodes($text, $parseSCFiles, $extraCodes, $eVars); - $text = str_replace('\n\n"; $text .= $tp->parseTemplate($FAQ_LISTALL['start'], true, $sc); - $start = TRUE; + $start = true; } $text .= $tp->parseTemplate($FAQ_LISTALL['item'], true, $sc); @@ -453,24 +445,27 @@ class faq $sc->counter++; } - if(!empty($schemaItems)) - { - $schema .= implode(",", $schemaItems); - } + $text .= ($start) ? $tp->parseTemplate($FAQ_LISTALL['end'], true, $sc) : ""; - if(!empty($schemaTemplate['end'])) + if(!empty($schemaTemplate)) { - $schema .= $tp->parseSchemaTemplate($schemaTemplate['end'],false,$sc); - } + if(isset($schemaTemplate['end']) && isset($schemaTemplate['item']) && isset($schemaTemplate['start'])) + { + $schemaTpl = $schemaTemplate['start']."\n".$schemaTemplate['item']."\n".$schemaTemplate['end']; + $schema = $tp->parseSchemaTemplate($schemaTpl, true, $sc, $data); + } + elseif(is_string($schemaTemplate)) + { + $schema = $tp->parseSchemaTemplate($schemaTemplate, true, $sc, $data); + } - if(!empty($schema)) - { - - e107::schema($schema); + if(!empty($schema)) + { + e107::schema($schema); + } } -// $text .= $tp->parseTemplate($FAQ_END, true, $sc); return $text; diff --git a/e107_plugins/faqs/faqs_shortcodes.php b/e107_plugins/faqs/faqs_shortcodes.php index 9a94400f3..74d7a0ab9 100644 --- a/e107_plugins/faqs/faqs_shortcodes.php +++ b/e107_plugins/faqs/faqs_shortcodes.php @@ -80,7 +80,7 @@ class faqs_shortcodes extends e_shortcode } - function sc_faq_question($parm='') + function sc_faq_question($parm=[]) { $tp = e107::getParser(); $parm = eHelper::scDualParams($parm); @@ -93,7 +93,7 @@ class faqs_shortcodes extends e_shortcode $faqNew = ($this->var['faq_datestamp'] > $newDate) ? " faq-new" : ""; - if($param == 'expand' && !empty($this->var['faq_answer'])) + if($param === 'expand' && !empty($this->var['faq_answer'])) { $id = "faq_".$this->var['faq_id']; @@ -130,6 +130,11 @@ class faqs_shortcodes extends e_shortcode } else { + if(isset($parm['html']) && empty($parm['html'])) + { + return e107::getParser()->toText($this->var['faq_question']); + } + $text = $tp->toHTML($this->var['faq_question'],true, 'TITLE'); } return $text; @@ -154,8 +159,13 @@ class faqs_shortcodes extends e_shortcode return "var)."' >".$tp -> toHTML($this->var['faq_question'],true,'TITLE').""; } - function sc_faq_answer() + function sc_faq_answer($parm=[]) { + if(isset($parm['html']) && empty($parm['html'])) + { + return e107::getParser()->toText($this->var['faq_answer']); + } + return e107::getParser()->toHTML($this->var['faq_answer'],true,'BODY'); } diff --git a/e107_plugins/faqs/templates/faqs_template.php b/e107_plugins/faqs/templates/faqs_template.php index fdb2fad01..0dcb7be7d 100644 --- a/e107_plugins/faqs/templates/faqs_template.php +++ b/e107_plugins/faqs/templates/faqs_template.php @@ -35,20 +35,20 @@ $FAQS_TEMPLATE['caption'] = "{FAQ_CAPTION} {FAQ_COUNT}"; /** @experimental */ -$FAQS_TEMPLATE['schema']['start'] = '{ +$FAQS_TEMPLATE['schema'] = ' +{ "@context": "https://schema.org", "@type": "FAQPage", - "mainEntity": ['; - -$FAQS_TEMPLATE['schema']['item'] = '{ - "@type": "Question", - "name": "{FAQ_QUESTION}", - "acceptedAnswer": { - "@type": "Answer", - "text": "{FAQ_ANSWER}" - } -}'; - -$FAQS_TEMPLATE['schema']['end'] = '] - } - '; + "mainEntity": [ + { + "@type": "Question", + "name": "{FAQ_QUESTION: html=0}", + "acceptedAnswer": + { + "@type": "Answer", + "text": "{FAQ_ANSWER: html=0}" + } + } + ] +} +'; diff --git a/e107_plugins/news/news.php b/e107_plugins/news/news.php index 86400e2e3..5136eac74 100644 --- a/e107_plugins/news/news.php +++ b/e107_plugins/news/news.php @@ -44,6 +44,8 @@ class news_front private $tagAuthor = null; private $comments = array(); private $pagination; + + private $schema = ''; // private $interval = 1; function __construct() @@ -824,6 +826,7 @@ class news_front $e107cache->set($cache_tag."_diz", defined("META_DESCRIPTION") ? META_DESCRIPTION : ''); $e107cache->set($cache_tag."_rows", e107::serialize($rowData,'json')); + $e107cache->set($cache_tag."_schema", $this->schema); } @@ -1238,6 +1241,12 @@ class news_front $this->setNewsFrontMeta($rows); $text = $this->renderCache($caption, $newsCachedPage); // This exits if cache used $this->comments = $rows; + + if($shema = $this->getNewsCache($this->cacheString,'schema')) + { + e107::schema($shema); + } + return $text; } else @@ -1354,6 +1363,12 @@ class news_front $render = true; } + if(!empty($tmp['schema'])) + { + $this->schema = e107::getParser()->parseSchemaTemplate($tmp['schema'], true, $nsc); + e107::schema($this->schema); + } + unset($tmp); } diff --git a/e107_plugins/news/templates/news_view_template.php b/e107_plugins/news/templates/news_view_template.php index 3c32f32df..f2d883b07 100644 --- a/e107_plugins/news/templates/news_view_template.php +++ b/e107_plugins/news/templates/news_view_template.php @@ -88,6 +88,7 @@ $NEWS_VIEW_TEMPLATE['default']['item'] = ' '; + /* *
");*/ + self::assertEquals($expected, $actual, "BBcode parsing failed on");*/ } @@ -243,7 +243,7 @@ EXPECTED; foreach ($tests as $var) { $result = $this->tp->thumbUrlDecode($var['input']); - $this->assertSame($var['expected'], $result); + self::assertSame($var['expected'], $result); } @@ -439,7 +439,7 @@ EXPECTED; } $result = $this->tp->toHTML($tests[$mod]['input'], false, 'defaults_off,' . $mod); - $this->assertSame($tests[$mod]['expected'], $result, $mod . " didn't match the expected result."); + self::assertSame($tests[$mod]['expected'], $result, $mod . " didn't match the expected result."); // $ret[$mod] = $result; } @@ -494,7 +494,7 @@ EXPECTED; continue; } - $this->assertEquals($var['expected'], $result, 'Test #' . $index . ' failed.'); + self::assertEquals($var['expected'], $result, 'Test #' . $index . ' failed.'); } @@ -504,13 +504,13 @@ EXPECTED; { $needle = '