예제 #1
0
/**
* This function is called from COM_siteHeader and other places where meta tags
* are being built and will return additional meta tags.
*
* @param    string   $type     item type of the caller, e.g. 'article', 'staticpages'
* @param    string   $id       id of the current item of the caller
* @param    string   $myTags   meta tags the caller wants to add (optional)
* @return   string             all meta tags
* @since    Geeklog 2.1.0
*
*/
function PLG_getMetaTags($type, $id, array $myTags = array())
{
    global $_CONF, $_PLUGINS;
    $type = strtolower(trim($type));
    $id = trim($id);
    require_once $_CONF['path_system'] . 'classes/metatags.class.php';
    $charset = COM_getCharset();
    $htmlVersion = $_CONF['doctype'] === 'xhtml5' ? 5 : 4;
    $isXhtml = stripos($_CONF['doctype'], 'xhtml') === 0;
    $obj = new Metatags($charset, $htmlVersion, $isXhtml);
    //  $obj->setLog($_CONF['path'] . 'logs/error.log');
    // First, adds meta tags plugins want to add (the lowest priority)
    foreach ($_PLUGINS as $pi_name) {
        $function = 'plugin_getmetatags_' . $pi_name;
        if ($type !== $pi_name && function_exists($function)) {
            $metatags = $function($type, $id);
            if (is_array($metatags) && count($metatags) > 0) {
                foreach ($metatags as $tag) {
                    $obj->addTag($tag);
                }
            }
        }
    }
    // Then, adds meta tags the custom function wants to add
    $function = 'CUSTOM_getmetatags';
    if (function_exists($function)) {
        $metatags = $function($type, $id);
        if (is_array($metatags) && count($metatags) > 0) {
            foreach ($metatags as $tag) {
                $obj->addTag($tag);
            }
        }
    }
    // Finally, adds meta tags the caller itself wants to add (the highest priority)
    if (count($myTags) > 0) {
        foreach ($myTags as $tag) {
            $obj->addTag($tag);
        }
    }
    return $obj->build();
}