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

support for terminal42/contao-pageimage #12

Closed
fritzmg opened this issue Apr 6, 2016 · 5 comments
Closed

support for terminal42/contao-pageimage #12

fritzmg opened this issue Apr 6, 2016 · 5 comments
Labels

Comments

@fritzmg
Copy link
Contributor

fritzmg commented Apr 6, 2016

I think it would be useful if the extension also supported taking the page image defined by the pageimage extension, when present. This image could be put in front of the other collected images, but after the news teaser image in the images array. So the order in the array would be

  1. news teaser image
  2. social page image
  3. pageimage
  4. content element images
@Toflar
Copy link

Toflar commented Apr 6, 2016

If so, it would be the other way around. Pageimage should support social images which should be pretty easy by setting $GLOBALS['SOCIAL_IMAGES'] in the front end module. Feel free to submit a PR there :)

@fritzmg
Copy link
Contributor Author

fritzmg commented Apr 6, 2016

Hm, I don't know, the current functionality of the social_images extension is, that it collects the images, rather than the other way around.

If it's done the other way around, can the aforementioned order of images in the array be implemented? On the news reader page the image of the news teaser should be the first one in the array (i.e. the first one to be available for the facebook share dialogue for instance), rather than the page image of the news reader page.

@qzminski
Copy link
Member

qzminski commented Apr 6, 2016

I think @Toflar is right here, it should go to the pageimage extension. That script "wants" the social_images to use its images.

The order of images problem cannot be solved in an automated way I think. Perhaps there could be a page layout setting determining the order of images so you would be able to sort things manually. What do you think about that?

@fritzmg
Copy link
Contributor Author

fritzmg commented Apr 7, 2016

Well, my reasoning was:

The core extension does not push images of its content elements into $GLOBALS['SOCIAL_IMAGES'] (obviously, of course), the social_images collects it from them.

The news extension does not push teaser images of its news entries into $GLOBALS['SOCIAL_IMAGES'] (obviously, of course), the social_images collects it from them.

However, I do get your point that other extensions can just freely push their images into the $GLOBALS['SOCIAL_IMAGES'] :).

Regarding the order: I was wrong about the news teaser image currently always being first (when present), I'll probably open an issue for that (//edit: #13).

In order to make it customizeable, maybe other extensions could (optionally) also push a priority number into the array. e.g.

// content of $GLOBALS['SOCIAL_IMAGES'] after collecting images
$GLOBALS['SOCIAL_IMAGES'] = array
(
    array
    (
        'priority' => 0,
        'path' => 'files/some_content_element_image.jpg'
    ),
    array
    (
        'priority' => 90,
        'path' => 'files/social_image_from_page.jpg'
    ),
    array
    (
        'priority' => 100,
        'path' => 'files/some_news_teaser_image.jpg'
    ),
    array
    (
        'priority' => 0,
        'path' => 'files/some_content_element_image.jpg'
    ),
    'some_image_from_another_extension_without_priority.jpg'
);

Then process the array to be backwards compatible with elements in the array without priority and path:

// processing the $GLOBALS['SOCIAL_IMAGES'] array
$GLOBALS['SOCIAL_IMAGES'] = array_map(function($element)
{
    if (!is_array($element))
    {
        return array
        (
            'path' => $element,
            'priority' => 50 // default priority
        );
    }
    return $element;
},
$GLOBALS['SOCIAL_IMAGES']);

Then sort the array according to the priority:

// sorting the array (descending)
usort($GLOBALS['SOCIAL_IMAGES'], function($a,$b)
{
    return $b['priority'] - $a['priority'];
});

Then extract the paths:

// extracting the paths
$arrImages = array_unique(array_map(function($e){ return $e['path']; }, $GLOBALS['SOCIAL_IMAGES']));

But I think this is overkill. I think in most cases you simply want to have your news teaser image (when present) first and the social page image (when present) second and the order of the other images is arbitrary.

@qzminski
Copy link
Member

qzminski commented Apr 7, 2016

I am closing this issue then as the main topic has been solved and the order images is being discussed in #13.

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

No branches or pull requests

3 participants