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'] = ' '; + /* *

About the Author

@@ -101,6 +102,38 @@ $NEWS_VIEW_TEMPLATE['default']['item'] = ' */ +$NEWS_VIEW_TEMPLATE['default']['schema'] = ' +{ + "@context": "https://schema.org", + "@type": "NewsArticle", + "mainEntityOfPage": { + "@type": "WebPage", + "@id": "{NEWS_URL: full=1}" + }, + "headline": "{NEWS_TITLE}", + "description": "{NEWS_DESCRIPTION}", + "image": [ + "{SETIMAGE: w=800&h=800}{NEWS_IMAGE: item=1&return=url}" + ], + "author": { + "@type": "Person", + "name": "{NEWS_AUTHOR=nolink}" + }, + "publisher": { + "@type": "Organization", + "name": "{ORGANIZATION}", + "logo": { + "@type": "ImageObject", + "url": "{SITEBUTTON: type=url}" + } + }, + "datePublished": "{NEWS_DATE=atom}", + "dateModified": "{NEWS_MODIFIED=atom}", + "articleBody": "{NEWS_BODY=raw}" + +} +'; + // @todo add more templates. eg. 'videos' , 'slideshow images', 'full width image' - help and ideas always appreciated. diff --git a/e107_plugins/siteinfo/e_shortcode.php b/e107_plugins/siteinfo/e_shortcode.php index b3fb4b763..45f039dca 100644 --- a/e107_plugins/siteinfo/e_shortcode.php +++ b/e107_plugins/siteinfo/e_shortcode.php @@ -15,12 +15,8 @@ class siteinfo_shortcodes // must match the folder name of the plugin. { $path = e107::getParser()->replaceConstants($_POST['sitebutton']); } - else - { - $path = (strpos(SITEBUTTON, 'http:') !== false ? SITEBUTTON : e_IMAGE.SITEBUTTON); - } - if(varset($parm['type']) == 'email' || $parm == 'email') // (retain {} constants ) + if(varset($parm['type']) == 'email' || $parm == 'email' || varset($parm['type']) == 'url') // (retain {} constants ) { $h = !empty($parm['h']) ? $parm['h'] : 100; @@ -35,9 +31,19 @@ class siteinfo_shortcodes // must match the folder name of the plugin. if(defined('e_MEDIA') && is_writable(e_MEDIA."temp/") && ($resized = e107::getMedia()->resizeImage($path, e_MEDIA."temp/".basename($realPath),'h='.$h))) { - $path = e107::getParser()->createConstants($resized); + $path = e107::getParser()->createConstants($resized,'mix'); } } + else + { + $path = (strpos(SITEBUTTON, 'http:') !== false || strpos(SITEBUTTON, e_IMAGE_ABS) !== false ? SITEBUTTON : e_IMAGE.SITEBUTTON); + } + + if(varset($parm['type']) == 'url') + { + // return $path; + return e107::getParser()->replaceConstants($path,'full'); + } if(!empty($path)) { @@ -196,8 +202,14 @@ class siteinfo_shortcodes // must match the folder name of the plugin. $opts['h'] = $dimensions[1]; } - // $imageStyle = (empty($dimensions)) ? '' : " style='width: ".$dimensions[0]."px; height: ".$dimensions[1]."px' "; - // $image = "\n"; + if(varset($parm['type']) == 'url') + { + return $tp->replaceConstants($logo, 'full'); + } + elseif(varset($parm['type']) == 'email') + { + return $logo; + } $image = $tp->toImage($logo,$opts); @@ -222,4 +234,13 @@ class siteinfo_shortcodes // must match the folder name of the plugin. return (defined('THEME_DISCLAIMER') && $pref['displaythemeinfo'] ? THEME_DISCLAIMER : ''); } + function sc_organization() + { + $c = e107::getPref('contact_info'); + + $text = !empty($c['organization']) ? $c['organization'] : SITENAME; + + return e107::getParser()->toText($text); + } + } diff --git a/e107_tests/tests/unit/e_parseTest.php b/e107_tests/tests/unit/e_parseTest.php index 492394f86..7c7243840 100644 --- a/e107_tests/tests/unit/e_parseTest.php +++ b/e107_tests/tests/unit/e_parseTest.php @@ -22,7 +22,7 @@ class e_parseTest extends \Codeception\Test\Unit } catch (Exception $e) { - $this->assertTrue(false, "Couldn't load e_parser object"); + self::assertTrue(false, "Couldn't load e_parser object"); } $this->tp->__construct(); @@ -101,7 +101,7 @@ class e_parseTest extends \Codeception\Test\Unit continue; } - $this->assertEquals($var['expected'], $result); + self::assertEquals($var['expected'], $result); } @@ -135,7 +135,7 @@ TMP; $actual = $this->tp->toHTML($src, true); - $this->assertEquals($expected, $actual, "BBcode parsing failed"); + self::assertEquals($expected, $actual, "BBcode parsing failed"); $src = "[center][img]{e_IMAGE}generic/blank_avatar.jpg[/img][/center]"; @@ -144,7 +144,7 @@ TMP; $expected = "
Blank Avatar
"; - $this->assertEquals($expected, $actual, "BBcode parsing failed on [img]"); + self::assertEquals($expected, $actual, "BBcode parsing failed on [img]"); $src = << EXPECTED; $actual = $this->tp->toHTML($src, true); - $this->assertEquals($expected, $actual); + self::assertEquals($expected, $actual); /* $src = "[html] @@ -191,7 +191,7 @@ EXPECTED; $actual = $this->tp->toHTML($src,true); $expected = ''; - $this->assertEquals($expected, $actual, "BBcode parsing failed on
");*/
+				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 = '