Open Graph meta data for coppermine Open Graph meta data for coppermine
 

News:

CPG Release 1.6.26
Correct PHP8.2 issues with user and language managers.
Additional fixes for PHP 8.2
Correct PHP8 error with SMF 2.0 bridge.
Correct IPTC supplimental category parsing.
Download and info HERE

Main Menu

Open Graph meta data for coppermine

Started by Anturaju93, December 17, 2013, 12:46:13 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Anturaju93

I`m trying to add Open Graph meta data to coppermine gallery:
I manage to add the title and type:
<meta property="og:title" content="{TITLE}" />
<meta property="og:type" content="website" />

I want to add the og:url and og:image meta tags, but i need the correct code so that coppermine will generate the unique tags for every page.
What can i use for url and image so i can enable Open Graph meta information for social networks ?
<meta property="og:url" content="????????" />
<meta property="og:image" content="?????????" />

I`m editing template.html.

Αndré

If you need unique criteria, I suggest to use the picture ID (pid). Does Open Graph supports something like that, or can you "abuse" some existing field for that information?

Anturaju93

I`m not a coder, i don`t know how to do that :(
Don`t know what to code to insert to generate a unique image url and picture location to use with open graph.
As you can see if i use 
<meta property="og:title" content="{TITLE}" />
I get the real page title in the meta content, but what code to insert for
<meta property="og:url" content="????????" />
<meta property="og:image" content="?????????" />

so i can get unique url and image file location. How to generate them ?

Αndré

First of all, I don't know Open Graph nor support it. You need to tell us which data you need to insert. Then, we can tell you how to do that.

You said you're currently editing template.html. I assume you just need that meta data for intermediate-sized image pages? Regardless, we probably need to edit theme.php to add data dynamicly.

Anturaju93

I need a unique url for "og:url" and image location for "og:image" to be generated dynamic.
A custom header witch ads this information on every page...
A simple question is: How to dynamic generate a image url and image location for every page-view and show up on the page.
If open graph works with content="{TITLE}" and generates the page title, it will work with some other code that generates image URL and location.       

Anturaju93

I think i need to edit theme.php and add this function function pageheader($section, $meta = '') from sample theme but i don't know how to construct the $meta
I tried $meta = <meta property="og:url" content="link here" /> but is not working, my site is crashing.   
//meta open graph
    $meta = <<<EOT <meta property="og:url" content="link aici" /> EOT;

Some ideas ?

Anturaju93

I added this to theme.php :

/******************************************************************************
** Section <<<pageheader>>> - START
******************************************************************************/
function pageheader($section, $meta = '')
{
    global $CONFIG, $THEME_DIR;
    global $template_header, $lang_charset, $lang_text_dir;

    // Variabile pentru aflarea pid-ului unic START
    $superCage = Inspekt::makeSuperCage();
    $pid = $superCage->get->getInt('pid');
    // Variabile pentru aflarea pid-ului unic END

    $custom_header = cpg_get_custom_include($CONFIG['custom_header_path']);

    $meta = '<meta property="og:url" content="http://imagini.moinesti.biz/displayimage.php?pid=$pid" />';

    $charset = ($CONFIG['charset'] == 'language file') ? $lang_charset : $CONFIG['charset'];

    header('P3P: CP="CAO DSP COR CURa ADMa DEVa OUR IND PHY ONL UNI COM NAV INT DEM PRE"');
    header("Content-Type: text/html; charset=$charset");
    user_save_profile();

    $template_vars = array(
        '{LANG_DIR}' => $lang_text_dir,
        '{TITLE}' => theme_page_title($section),
        '{CHARSET}' => $charset,
        '{META}' => $meta,
        '{GAL_NAME}' => $CONFIG['gallery_name'],
        '{GAL_DESCRIPTION}' => $CONFIG['gallery_description'],
        '{SYS_MENU}' => theme_main_menu('sys_menu'),
        '{SUB_MENU}' => theme_main_menu('sub_menu'),
        '{ADMIN_MENU}' => theme_admin_mode_menu(),
        '{CUSTOM_HEADER}' => $custom_header,
        '{JAVASCRIPT}' => theme_javascript_head(),
        '{MESSAGE_BLOCK}' => theme_display_message_block(),
    );

    $template_vars = CPGPluginAPI::filter('theme_pageheader_params', $template_vars);
    echo template_eval($template_header, $template_vars);

    // Show various admin messages
    adminmessages();
}
/******************************************************************************
** Section <<<pageheader>>> - END
******************************************************************************/


You can see that i defined $meta = '<meta property="og:url" content="http://imagini.moinesti.biz/displayimage.php?pid=$pid" />'; witch displays <meta property="og:url" content="http://imagini.moinesti.biz/displayimage.php?pid=$pid" /> in browser meta data, but i can`t make the URL to by dynamic: imagini.moinesti.biz/displayimage.php?pid=$pid stays the same and does not change into imagini.moinesti.biz/displayimage.php?pid=140 etc. ...

E. William

Try replacing:
    $meta = '<meta property="og:url" content="http://imagini.moinesti.biz/displayimage.php?pid=$pid" />';

with:
    $meta = '<meta property="og:url" content="http://imagini.moinesti.biz/displayimage.php?pid=' . $pid . '" />';

so it doesn't read $pid as part of the url, but as a variable.

Not sure if it'll do the trick, that depends on other parts of the code as well, but it'll get you closer to where you want to be.

Anturaju93

Yes, is working now, thanks.   8)
This is only half fixed, i need now to display this custom meta data only on displayimage.php and i need to insert another meta data into $meta , the image file location for facebook to use with the share button to create a timeline story. <meta property="og:image" content="dynamic and direct path to file location" />
Facebook share looks very nice now with this new open graph data :)

E. William

That code would look something like:

    $meta = '<meta property="og:url" content="http://imagini.moinesti.biz/displayimage.php?pid=' . $pid . '" />';

    if ($CONFIG['make_intermediate'] && cpg_picture_dimension_exceeds_intermediate_limit($CURRENT_PIC_DATA['pwidth'], $CURRENT_PIC_DATA['pheight'])) {
        $meta .= '<meta property="og:image" content="http://imagini.moinesti.biz/' . "{$CURRENT_PIC_DATA['filepath']}" . 'normal_' . "{$CURRENT_PIC_DATA['filename']}" . '" />';
    } else {
        $meta .= '<meta property="og:image" content="http://imagini.moinesti.biz/' . "{$CURRENT_PIC_DATA['filepath']}" . "{$CURRENT_PIC_DATA['filename']}" . '" />';
    }


I must say I'm not a coder either, so I can't guarantee this will work. You may have to tweak the code here and there.

Anturaju93

The meta data is displayed only on displayimage.php but like this:
<meta property="og:url" content="http://imagini.moinesti.biz/displayimage.php?pid=71" /><meta property="og:image" content="http://imagini.moinesti.biz/" />
meta property="og:image"  must be a direct link to an intermediate file location and a <br> is needed to show <meta property="og:image" content="http://imagini.moinesti.biz/" /> down on a second line.

E. William

Like I said, I'm no coder, so it's gonna be hit and miss :)

Try this:
    $meta = '<meta property="og:url" content="http://imagini.moinesti.biz/displayimage.php?pid=' . $pid . '" />' . $LINEBREAK;

    if ($CONFIG['make_intermediate'] && cpg_picture_dimension_exceeds_intermediate_limit($CURRENT_PIC_DATA['pwidth'], $CURRENT_PIC_DATA['pheight'])) {
        $meta .= '<meta property="og:image" content="http://imagini.moinesti.biz/' . {$CURRENT_PIC_DATA['filepath']} . 'normal_' . {$CURRENT_PIC_DATA['filename']}" . ' />';
    } else {
        $meta .= '<meta property="og:image" content="http://imagini.moinesti.biz/' . {$CURRENT_PIC_DATA['filepath']} . {$CURRENT_PIC_DATA['filename']} . '" />';
    }


The "if" statement is there to link to the fullsize image in case no intermediate file has been generated (for instance if the file dimensions were smaller than those of the intermediate settings or the option has been turned off).

E. William

Sorry, left a double quote in there which will result in an empty page...
Here's the correct version (I hope):

    $meta = '<meta property="og:url" content="http://imagini.moinesti.biz/displayimage.php?pid=' . $pid . '" />' . $LINEBREAK;

    if ($CONFIG['make_intermediate'] && cpg_picture_dimension_exceeds_intermediate_limit($CURRENT_PIC_DATA['pwidth'], $CURRENT_PIC_DATA['pheight'])) {
        $meta .= '<meta property="og:image" content="http://imagini.moinesti.biz/' . {$CURRENT_PIC_DATA['filepath']} . 'normal_' . {$CURRENT_PIC_DATA['filename']} . ' />';
    } else {
        $meta .= '<meta property="og:image" content="http://imagini.moinesti.biz/' . {$CURRENT_PIC_DATA['filepath']} . {$CURRENT_PIC_DATA['filename']} . '" />';
    }

E. William

You may also want to try leaving the {} out like this:

    $meta = '<meta property="og:url" content="http://imagini.moinesti.biz/displayimage.php?pid=' . $pid . '" />' . $LINEBREAK;

    if ($CONFIG['make_intermediate'] && cpg_picture_dimension_exceeds_intermediate_limit($CURRENT_PIC_DATA['pwidth'], $CURRENT_PIC_DATA['pheight'])) {
        $meta .= '<meta property="og:image" content="http://imagini.moinesti.biz/' . $CURRENT_PIC_DATA['filepath'] . 'normal_' . $CURRENT_PIC_DATA['filename'] . ' />';
    } else {
        $meta .= '<meta property="og:image" content="http://imagini.moinesti.biz/' . $CURRENT_PIC_DATA['filepath'] . $CURRENT_PIC_DATA['filename'] . '" />';
    }


This is how I code: Trial and Error ;). See what works, and what doesn't.

Αndré

Quote from: Anturaju93 on December 18, 2013, 07:08:23 AM
The meta data is displayed only on displayimage.php
I cannot see any code that is responsible to display your additional meta data just on displayimage.php. Have you added anything different you haven't posted yet?

Anturaju93

Quote from: E. William on December 18, 2013, 08:58:41 AM
You may also want to try leaving the {} out like this:

    $meta = '<meta property="og:url" content="http://imagini.moinesti.biz/displayimage.php?pid=' . $pid . '" />' . $LINEBREAK;

    if ($CONFIG['make_intermediate'] && cpg_picture_dimension_exceeds_intermediate_limit($CURRENT_PIC_DATA['pwidth'], $CURRENT_PIC_DATA['pheight'])) {
        $meta .= '<meta property="og:image" content="http://imagini.moinesti.biz/' . $CURRENT_PIC_DATA['filepath'] . 'normal_' . $CURRENT_PIC_DATA['filename'] . ' />';
    } else {
        $meta .= '<meta property="og:image" content="http://imagini.moinesti.biz/' . $CURRENT_PIC_DATA['filepath'] . $CURRENT_PIC_DATA['filename'] . '" />';
    }


This is how I code: Trial and Error ;). See what works, and what doesn't.

Not working, now meta data is displayed on all pages, not only displayimage.php.
There is no line break between meta code, and image URL its not generated :
<meta property="og:url" content="http://imagini.moinesti.biz/displayimage.php?pid=250" /><meta property="og:image" content="http://imagini.moinesti.biz/" />
URL for "og:image" must be dynamic generated like this http://imagini.moinesti.biz/albums/userpics/10001/normal_Toamna_in_Parc_Moinesti_19.jpg , and only be prezent on displayimage.php

Anturaju93

Quote from: Αndré on December 18, 2013, 09:22:34 AM
I cannot see any code that is responsible to display your additional meta data just on displayimage.php. Have you added anything different you haven't posted yet?
The code is not working correctly , so i do not leave it on my site yet.

Αndré

Use this code:
    global $CPG_PHP_SELF, $LINEBREAK, $CURRENT_PIC_DATA;
    if ($CPG_PHP_SELF == 'displayimage.php') {
        $superCage = Inspekt::makeSuperCage();
        $meta .= '<meta property="og:url" content="' . $CONFIG['ecards_more_pic_target'] . 'displayimage.php?pid=' . $superCage->get->getInt('pid') . '" />' . $LINEBREAK;
        $meta .= '<meta property="og:image" content="' . $CONFIG['ecards_more_pic_target'] . $CONFIG['fullpath'] . $CURRENT_PIC_DATA['filepath'] . $CURRENT_PIC_DATA['filename'] . '" />';
    }


netb

Quote from: Αndré on December 18, 2013, 09:53:21 AM
Use this code:
    global $CPG_PHP_SELF, $LINEBREAK, $CURRENT_PIC_DATA;
    if ($CPG_PHP_SELF == 'displayimage.php') {
        $superCage = Inspekt::makeSuperCage();
        $meta .= '<meta property="og:url" content="' . $CONFIG['ecards_more_pic_target'] . 'displayimage.php?pid=' . $superCage->get->getInt('pid') . '" />' . $LINEBREAK;
        $meta .= '<meta property="og:image" content="' . $CONFIG['ecards_more_pic_target'] . $CONFIG['fullpath'] . $CURRENT_PIC_DATA['filepath'] . $CURRENT_PIC_DATA['filename'] . '" />';
    }


Hello,

I used this code and it works like a charm for which I thank you but now it seems that it doesn't quite fit my requirements.
Sharing services like addthis and also the generic facebook share use these meta tags and don't display any image when they are missing.
So could it be possible also to display the meta tags for og:url and og:image in the thumbnails.php also?

This can be debugged here for instance - https://developers.facebook.com/tools/debug/og/object/ to see what will be the share result and if you share from thumbnails.php there is no image.
For the test I share for example Last Additions from http://www.greatmusclebodies.com/thumbnails.php?album=lastup&cat=0 and I want the og:url tag to be in there with a og:image tag for an image (it doesn't matter which image as long as there is one).

I hope you understand what I mean.

Is it possible to also to display the