e107inc / e107

e107 Bootstrap CMS (Content Management System) v2 with PHP, MySQL, HTML5, jQuery and Twitter Bootstrap. Issue Discussion Room: https://gitter.im/e107inc/e107
https://e107.org
GNU General Public License v3.0
321 stars 213 forks source link

function addMeta and testing if content is empty ? 7.3 #4022

Open Jimmi08 opened 4 years ago

Jimmi08 commented 4 years ago

I don't know if this is PHP 7.3 related, but I think somebody would notice this before.

This is help for addMeta();

     * addMeta(null, 30, array('http-equiv' => 'refresh'));
     * addMeta(null, null, array('http-equiv' => 'refresh', 'content' => 30)); // same as above

but inside there is test:

if(empty($content)){ return $this; } // content is required, otherwise ignore.

This didn't work in theme.php: e107::meta(null, null, array('http-equiv' => 'X-UA-Compatible', 'content' => "IE=edge")); This worked: e107::meta(null, "IE=edge", array('http-equiv' => 'X-UA-Compatible', 'content' => "IE=edge"));

So either help is wrong or the test should be changed. I dumped value and it was NULL.

Moc commented 2 years ago

@CaMer0n Thoughts?

lonalore commented 1 year ago

The method documentation is good, except for that one: addMeta(null, null, array('http-equiv' => 'refresh', 'content' => 30));

Btw I also created the "metatag" plugin based on the documentation of addMeta() method. Which worked fine until e107 v2.3.2 because of this change.

The problem is In addMeta() method (in application.php file), specifically this part:

if(!empty($attr))
{
    if(!in_array($name, $this->_meta_multiple)) // prevent multiple keyword tags.
    {
        $this->_meta[$name] = $attr;
    }
    else // multiple allowed.
    {
        $this->_meta[] = $attr;
    }
}

This change did not follow the documentation of the method.... -_- so it is no longer possible to render meta tags based on what is described there. :@ If the value of $name is NULL, the meta tags overwrite each other.

So it should be something like this:

if(!empty($attr))
{
    if($name && !in_array($name, $this->_meta_multiple)) // prevent multiple keyword tags.
    {
        $this->_meta[$name] = $attr;
    }
    else // multiple allowed.
    {
        $this->_meta[] = $attr;
    }
}

I use the following cases in "metatag" plugin:

/**
 * Callback for a normal meta tag.
 *
 * The format is:
 * <meta name="[name]" content="[value]" />
 *
 * @param string $name
 *  Name attribute for meta tag.
 * @param string $content
 *  Content attribute for meta tag.
 */
public function renderMeta($name, $content)
{
    if(!empty($name) && !empty($content))
    {
        e107::meta(null, $content, array(
            'name' => $name,
        ));
    }
}

/**
 * Callback for a http-equiv meta tag.
 *
 * The format is:
 * <meta http-equiv="[name]" content="[value]" />
 *
 * @param string $httpequiv
 *  Http-equiv attribute for meta tag.
 * @param string $content
 *  Content attribute for meta tag.
 */
public function renderHttpEquiv($httpequiv, $content)
{
    if(!empty($httpequiv) && !empty($content))
    {
        e107::meta(null, $content, array(
            'http-equiv' => $httpequiv,
        ));
    }
}

/**
 * Callback for a property meta tag.
 *
 * The format is:
 * <meta property="[name]" content="[value]" />
 *
 * @param string $property
 *  Property attribute for meta tag.
 * @param string $content
 *  Content attribute for meta tag.
 */
public function renderProperty($property, $content)
{
    if(!empty($property) && !empty($content))
    {
        e107::meta(null, $content, array(
            'property' => $property,
        ));
    }
}

/**
 * Callback for a itemprop meta tag.
 *
 * The format is:
 * <meta itemprop="[name]" content="[value]" />
 *
 * @param string $itemprop
 *  Itemprop attribute for meta tag.
 * @param string $content
 *  Content attribute for meta tag.
 */
public function renderItemprop($itemprop, $content)
{
    if(!empty($itemprop) && !empty($content))
    {
        e107::meta(null, $content, array(
            'itemprop' => str_replace('itemprop:', '', $itemprop),
        ));
    }
}