Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for pages with multiple copies of tags #23

Open
mutatron opened this issue Jul 23, 2014 · 2 comments
Open

Fix for pages with multiple copies of tags #23

mutatron opened this issue Jul 23, 2014 · 2 comments

Comments

@mutatron
Copy link

A web page may have multiple og:image tags, for example, so I made each _value[$key] into an array, and then values are pushed onto the array, like so:

            if (!is_array($page->_values[$key]))
            {
                $page->_values[$key] = array();
            }
            $page->_values[$key][] = $tag->getAttribute('value');

Of course there are a few keys that need to be explicitly handled, like this:

            if (!is_array($page->_values['title']))
            {
                $page->_values['title'] = array();
            }
            $page->_values['title'][] = $titles->item(0)->textContent;
@propertunist
Copy link

thanks, would be great to get this integrated into the main code

@pressmaster
Copy link

Great idea. I went the other direction. It was only giving me the last image and I wanted the first.

    $gotImage = 0;

    foreach ($tags AS $tag) {
        if ($tag->hasAttribute('property') &&
            strpos($tag->getAttribute('property'), 'og:') === 0) {
            $key = strtr(substr($tag->getAttribute('property'), 3), '-', '_');
            if ($key === "image" && $gotImage === 0) { 
                $gotImage++; 
                $page->_values[$key] = $tag->getAttribute('content');
            }
            else if ($key != "image") { 
                $page->_values[$key] = $tag->getAttribute('content');
            }
        }

My version isn't pretty, I'm sure....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants