Skip to content

Commit

Permalink
[E] Allow to use metatags in head #1996
Browse files Browse the repository at this point in the history
  • Loading branch information
lianglee committed Sep 9, 2021
1 parent 971f77a commit 084af8f
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 8 deletions.
65 changes: 57 additions & 8 deletions libraries/ossn.lib.page.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,14 @@
* @license Open Source Social Network License (OSSN LICENSE) http://www.opensource-socialnetwork.org/licence
* @link https://www.opensource-socialnetwork.org/
*/

/**
* Register metatags init
*
* @return void
*/
function ossn_page_metatags() {
ossn_extend_view('ossn/site/head', 'ossn_view_metatags');
}
/**
* Register a page handler;
* @params: $handler = page;
Expand Down Expand Up @@ -49,7 +56,6 @@ function ossn_unregister_page($handler) {
* @return mix|null data
* @access private
*/

function ossn_load_page($handler, $page) {
global $Ossn;
$context = $handler;
Expand All @@ -58,13 +64,13 @@ function ossn_load_page($handler, $page) {
}
//set context
ossn_add_context($context);

$page = explode('/', $page);
if(isset($Ossn->page) && isset($Ossn->page[$handler]) && !empty($handler) && is_callable($Ossn->page[$handler])) {
//supply params to hook
$params['page'] = $page;
$params['handler'] = $handler;

//[E] Allow to override page handler existing pages #1746
$halt_view = ossn_call_hook('page', 'override:view', $params, false);
if($halt_view === false) {
Expand All @@ -74,13 +80,12 @@ function ossn_load_page($handler, $page) {
$contents = ob_get_clean();
}
if($halt_view) {
$contents = "";
$contents = '';
}
return ossn_call_hook('page', 'load', $params, $contents);
} else {
return ossn_error_page();
}

}

/**
Expand All @@ -90,7 +95,6 @@ function ossn_load_page($handler, $page) {
*
* @return void
*/

function ossn_set_page_owner_guid($guid) {
global $Ossn;
$Ossn->pageOwnerGuid = $guid;
Expand All @@ -101,8 +105,53 @@ function ossn_set_page_owner_guid($guid) {
*
* @return (int)
*/

function ossn_get_page_owner_guid() {
global $Ossn;
return $Ossn->pageOwnerGuid;
}

/**
* Set page meta tags
* [E] Allow to use metatags in head #1996
*
* @param string $name A name of metatag
* @param string $value Value for the metatag
* @param boolean $property You wanted to use false => name='' or true => property=''
*
* @return void
*/
function ossn_set_metatag($name = '', $value = '', $property = false) {
if(!empty($name) && !empty($value)) {
global $Ossn;
$Ossn->pageMetaTags[$name] = array(
'value' => $value,
'property' => $property,
);
}
}
/**
* View metatags
* [E] Allow to use metatags in head #1996
*
* @return void
*/
function ossn_view_metatags() {
global $Ossn;
if(isset($Ossn->pageMetaTags)) {
$results = array();
foreach($Ossn->pageMetaTags as $name => $vars) {
if(!empty($vars['value']) && isset($vars['property'])) {
$args = array();
if($vars['property'] === false) {
$args['name'] = $name;
} else {
$args['property'] = $name;
}
$args['content'] = $vars['value'];
$results[] = ossn_plugin_view('output/meta', $args);
}
}
echo PHP_EOL . implode(PHP_EOL, $results);
}
}
ossn_register_callback('ossn', 'init', 'ossn_page_metatags');
13 changes: 13 additions & 0 deletions system/plugins/default/output/meta.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php
/**
* Open Source Social Network
*
* @package (openteknik.com).ossn
* @author OSSN Core Team <info@openteknik.com>
* @copyright (C) OpenTeknik LLC
* @license Open Source Social Network License (OSSN LICENSE) http://www.opensource-socialnetwork.org/licence
* @link https://www.opensource-socialnetwork.org/
*/

$attributes = ossn_args($params);
echo "<meta {$attributes} />";

0 comments on commit 084af8f

Please sign in to comment.