Advanced search  

News:

cpg1.5.46 Security release - upgrade mandatory!
The Coppermine development team is releasing a security update for Coppermine in order to counter recently discovered vulnerabilities. It is important that all users who run version cpg1.5.44 or older update to this latest version as soon as possible.
[more]

Pages: 1 [2]   Go Down

Author Topic: Open Graph meta data for coppermine  (Read 9971 times)

0 Members and 1 Guest are viewing this topic.

Αndré

  • Administrator
  • Coppermine addict
  • *****
  • Country: de
  • Offline Offline
  • Gender: Male
  • Posts: 15415
Re: Open Graph meta data for coppermine
« Reply #20 on: January 28, 2015, 09:41:53 pm »

Updated code:
Code: [Select]
    global $CPG_PHP_SELF, $LINEBREAK, $CURRENT_PIC_DATA, $CURRENT_ALBUM_DATA;
    if ($CPG_PHP_SELF == 'displayimage.php') {
        $meta .= '<meta property="og:url" content="' . $CONFIG['ecards_more_pic_target'] . 'displayimage.php?pid=' . $CURRENT_PIC_DATA['pid'] . '" />' . $LINEBREAK;
        $meta .= '<meta property="og:image" content="' . $CONFIG['ecards_more_pic_target'] . $CONFIG['fullpath'] . $CURRENT_PIC_DATA['filepath'] . $CURRENT_PIC_DATA['filename'] . '" />';
    } elseif ($CPG_PHP_SELF == 'thumbnails.php') {
        $thumb = mysql_fetch_assoc(cpg_db_query("SELECT filepath, filename FROM {$CONFIG['TABLE_PICTURES']} WHERE aid = {$CURRENT_ALBUM_DATA['aid']} ORDER BY pid DESC LIMIT 1"));
        $meta .= '<meta property="og:url" content="' . $CONFIG['ecards_more_pic_target'] . 'thumbnails.php?album=' . $CURRENT_ALBUM_DATA['aid'] . '" />' . $LINEBREAK;
        $meta .= '<meta property="og:image" content="' . $CONFIG['ecards_more_pic_target'] . $CONFIG['fullpath'] . $thumb['filepath'] . $thumb['filename'] . '" />';
    }
Logged

netb

  • Coppermine regular visitor
  • **
  • Offline Offline
  • Posts: 81
Re: Open Graph meta data for coppermine
« Reply #21 on: February 05, 2015, 11:54:47 pm »

Thank you, Αndré!
This does the job. I was lurking around the forum almost every day and reading other topics but didn't notice you replied here until now, silly me.

There is a minor issue though, when I open the lastup meta album of a category for example, it gives an error. The elseif seems to make it because when I leave only the function for displayimage it works normally. Here's an example of what's happening: http://www.greatmusclebodies.com/thumbnails.php?album=lastup&cat=3

Code: [Select]
Template error
Failed to find block 'file_line' (#<!-- BEGIN file_line -->(.*?)<!-- END file_line -->#s) in :
                    <div class="{CSS_CLASS}">
                        <h2>{HEADER_TXT}</h2>
                        <span class="cpg_user_message">{MESSAGE}</span>


                        <br /><br />
                    </div>
Logged

netb

  • Coppermine regular visitor
  • **
  • Offline Offline
  • Posts: 81
Re: Open Graph meta data for coppermine
« Reply #22 on: February 06, 2015, 12:56:57 am »

Forgot to mention that it also happens for the others like "toprated", "topn" and "lastcom" if relevant.
Logged

netb

  • Coppermine regular visitor
  • **
  • Offline Offline
  • Posts: 81
Re: Open Graph meta data for coppermine
« Reply #23 on: February 06, 2015, 02:41:21 am »

I think it's related to the negative/positive ID of the albums/categories and I was just looking at the codebase.php of the cpg1.5.x_plugin_social-sharing_v1.5 plugin which seems to address the same issue when generating the meta tags but my understanding of the code is very limited.
Logged

Αndré

  • Administrator
  • Coppermine addict
  • *****
  • Country: de
  • Offline Offline
  • Gender: Male
  • Posts: 15415
Re: Open Graph meta data for coppermine
« Reply #24 on: February 06, 2015, 07:34:19 am »

Do you also need the open graph meta data in the header for Coppermine meta albums (lastup, etc.) or can it be ommitted?
Logged

netb

  • Coppermine regular visitor
  • **
  • Offline Offline
  • Posts: 81
Re: Open Graph meta data for coppermine
« Reply #25 on: February 06, 2015, 09:31:48 am »

Well, if it's not hard to show meta data also for the meta albums' header - yes. But if involves much headbanging and it's not trivial you can just shield it in some way, so that it doesn't give the error at least.
Logged

netb

  • Coppermine regular visitor
  • **
  • Offline Offline
  • Posts: 81
Re: Open Graph meta data for coppermine
« Reply #26 on: February 06, 2015, 11:49:11 pm »

I also noticed that the search also gets broken by this so I guess it's not going to be trivial.
Logged

Αndré

  • Administrator
  • Coppermine addict
  • *****
  • Country: de
  • Offline Offline
  • Gender: Male
  • Posts: 15415
Re: Open Graph meta data for coppermine
« Reply #27 on: February 08, 2015, 08:00:29 pm »

The search is also just a meta album (in the Coppermine world). For almost all meta albums it should be possible to choose a picture from its content. If it's "not possible" (e.g. for meta album "search"), I'll select a random picture from the database. Of course it would also be possible to choose a static picture for all meta albums. Just let me know what's your preferred behavior.
Logged

netb

  • Coppermine regular visitor
  • **
  • Offline Offline
  • Posts: 81
Re: Open Graph meta data for coppermine
« Reply #28 on: February 08, 2015, 10:42:47 pm »

For the meta albums - choose a picture from its content and if it's "not possible, no results for the album, meta album search, etc." just select a random picture from the database.
Logged

Αndré

  • Administrator
  • Coppermine addict
  • *****
  • Country: de
  • Offline Offline
  • Gender: Male
  • Posts: 15415
Re: Open Graph meta data for coppermine
« Reply #29 on: February 09, 2015, 08:06:11 pm »

I decided to always use a random picture for meta albums:

Code: [Select]
    global $CPG_PHP_SELF, $LINEBREAK, $CURRENT_PIC_DATA, $CURRENT_ALBUM_DATA;
    if ($CPG_PHP_SELF == 'displayimage.php') {
        $meta .= $LINEBREAK . '<meta property="og:url" content="' . $CONFIG['ecards_more_pic_target'] . 'displayimage.php?pid=' . $CURRENT_PIC_DATA['pid'] . '" />';
        $meta .= $LINEBREAK . '<meta property="og:image" content="' . $CONFIG['ecards_more_pic_target'] . $CONFIG['fullpath'] . $CURRENT_PIC_DATA['filepath'] . $CURRENT_PIC_DATA['filename'] . '" />';
    } elseif ($CPG_PHP_SELF == 'thumbnails.php') {
        if ($CURRENT_ALBUM_DATA['aid']) {
            $album = $CURRENT_ALBUM_DATA['aid'];
            $sql = "SELECT filepath, filename FROM {$CONFIG['TABLE_PICTURES']} WHERE approved = 'YES' AND aid = '{$CURRENT_ALBUM_DATA['aid']}' ORDER BY pid DESC LIMIT 1";
        } else {
            $superCage = Inspekt::makeSuperCage();
            $album = $superCage->get->getAlpha('album');
            $sql = "SELECT filepath, filename FROM {$CONFIG['TABLE_PICTURES']} WHERE approved = 'YES' ORDER BY RAND() LIMIT 1";
        }
        $thumb = mysql_fetch_assoc(cpg_db_query($sql));
        $meta .= $LINEBREAK . '<meta property="og:url" content="' . $CONFIG['ecards_more_pic_target'] . 'thumbnails.php?album=' . $album . '" />';
        $meta .= $LINEBREAK . '<meta property="og:image" content="' . $CONFIG['ecards_more_pic_target'] . $CONFIG['fullpath'] . $thumb['filepath'] . $thumb['filename'] . '" />';
    }
Logged

netb

  • Coppermine regular visitor
  • **
  • Offline Offline
  • Posts: 81
Re: Open Graph meta data for coppermine
« Reply #30 on: February 09, 2015, 09:44:29 pm »

That's great! Thanks, Αndré! :)
Logged

zorbas2

  • Coppermine novice
  • *
  • Country: gr
  • Offline Offline
  • Gender: Male
  • Posts: 43
  • not bridged yet :(
    • Zorbas Travel Stoupa - Greece
Re: Open Graph meta data for coppermine
« Reply #31 on: February 18, 2015, 04:19:36 pm »

I'd like to add the open graph meta tags also to my cpg 1.5.34 installation.
I am using the 'rainy day' theme but can't find the
Code: [Select]
/******************************************************************************
** Section <<<pageheader>>> - START
******************************************************************************/
in the theme.php
However, it is found in the sample theme.php so I guess this is used... ?
Where exactly would I have to paste the code for the open graph meta tags?
Logged

netb

  • Coppermine regular visitor
  • **
  • Offline Offline
  • Posts: 81
Re: Open Graph meta data for coppermine
« Reply #32 on: February 18, 2015, 07:50:43 pm »

Yes, you have to copy this function from sample theme.php if you don't have it in yours and paste the additional code inside it.

Logged

zorbas2

  • Coppermine novice
  • *
  • Country: gr
  • Offline Offline
  • Gender: Male
  • Posts: 43
  • not bridged yet :(
    • Zorbas Travel Stoupa - Greece
Re: Open Graph meta data for coppermine
« Reply #33 on: February 19, 2015, 02:30:59 pm »

Probably I made a mistake - thats why I asked where exaclty to paste it...

My page header section now looks like this:
Code: [Select]
/******************************************************************************
** Section <<<pageheader>>> - START
******************************************************************************/
function pageheader($section, $meta = '')


{
    global $CPG_PHP_SELF, $LINEBREAK, $CURRENT_PIC_DATA, $CURRENT_ALBUM_DATA;
    if ($CPG_PHP_SELF == 'displayimage.php') {
        $meta .= $LINEBREAK . '<meta property="og:url" content="' . $CONFIG['ecards_more_pic_target'] . 'displayimage.php?pid=' . $CURRENT_PIC_DATA['pid'] . '" />';
        $meta .= $LINEBREAK . '<meta property="og:image" content="' . $CONFIG['ecards_more_pic_target'] . $CONFIG['fullpath'] . $CURRENT_PIC_DATA['filepath'] . $CURRENT_PIC_DATA['filename'] . '" />';
    } elseif ($CPG_PHP_SELF == 'thumbnails.php') {
        if ($CURRENT_ALBUM_DATA['aid']) {
            $album = $CURRENT_ALBUM_DATA['aid'];
            $sql = "SELECT filepath, filename FROM {$CONFIG['TABLE_PICTURES']} WHERE approved = 'YES' AND aid = '{$CURRENT_ALBUM_DATA['aid']}' ORDER BY pid DESC LIMIT 1";
        } else {
            $superCage = Inspekt::makeSuperCage();
            $album = $superCage->get->getAlpha('album');
            $sql = "SELECT filepath, filename FROM {$CONFIG['TABLE_PICTURES']} WHERE approved = 'YES' ORDER BY RAND() LIMIT 1";
        }
        $thumb = mysql_fetch_assoc(cpg_db_query($sql));
        $meta .= $LINEBREAK . '<meta property="og:url" content="' . $CONFIG['ecards_more_pic_target'] . 'thumbnails.php?album=' . $album . '" />';
        $meta .= $LINEBREAK . '<meta property="og:image" content="' . $CONFIG['ecards_more_pic_target'] . $CONFIG['fullpath'] . $thumb['filepath'] . $thumb['filename'] . '" />';
    }

    global $CONFIG, $THEME_DIR;
    global $template_header, $lang_charset, $lang_text_dir;

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

    $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
******************************************************************************/

But I get the following error:

Quote
Template error
Failed to find block 'file_line' (#<!-- BEGIN file_line -->(.*?)<!-- END file_line -->#s) in :
                    <div class="{CSS_CLASS}">
                        <h2>{HEADER_TXT}</h2>
                        <span class="cpg_user_message">{MESSAGE}</span>


                        <br /><br />
                    </div>
Logged

netb

  • Coppermine regular visitor
  • **
  • Offline Offline
  • Posts: 81
Re: Open Graph meta data for coppermine
« Reply #34 on: February 20, 2015, 02:25:26 pm »

Here's how I've put the code and my first part of the section looks like:

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

global $CPG_PHP_SELF, $LINEBREAK, $CURRENT_PIC_DATA, $CURRENT_ALBUM_DATA;
    if ($CPG_PHP_SELF == 'displayimage.php') {
        $meta .= '<meta property="og:url" content="' . $CONFIG['ecards_more_pic_target'] . 'displayimage.php?pid=' . $CURRENT_PIC_DATA['pid'] . '" />' . $LINEBREAK;
        $meta .= '<meta property="og:image" content="' . $CONFIG['ecards_more_pic_target'] . $CONFIG['fullpath'] . $CURRENT_PIC_DATA['filepath'] . $CURRENT_PIC_DATA['filename'] . '" />';
    } elseif ($CPG_PHP_SELF == 'thumbnails.php') {
        $thumb = mysql_fetch_assoc(cpg_db_query("SELECT filepath, filename FROM {$CONFIG['TABLE_PICTURES']} WHERE aid = {$CURRENT_ALBUM_DATA['aid']} ORDER BY pid DESC LIMIT 1"));
        $meta .= '<meta property="og:url" content="' . $CONFIG['ecards_more_pic_target'] . 'thumbnails.php?album=' . $CURRENT_ALBUM_DATA['aid'] . '" />' . $LINEBREAK;
        $meta .= '<meta property="og:image" content="' . $CONFIG['ecards_more_pic_target'] . $CONFIG['fullpath'] . $thumb['filepath'] . $thumb['filename'] . '" />';
    }

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

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

micropalla

  • Coppermine newbie
  • Offline Offline
  • Posts: 12
Re: Open Graph meta data for coppermine
« Reply #35 on: November 16, 2017, 09:54:20 am »

Hello!

I added the code and now it shows the image in FB but now I receive and error while trying to see all the images of an author.

Here the code i applied to theme.php

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

global $CPG_PHP_SELF, $LINEBREAK, $CURRENT_PIC_DATA, $CURRENT_ALBUM_DATA;
    if ($CPG_PHP_SELF == 'displayimage.php') {
        $meta .= '<meta property="og:url" content="' . $CONFIG['ecards_more_pic_target'] . 'displayimage.php?pid=' . $CURRENT_PIC_DATA['pid'] . '" />' . $LINEBREAK;
        $meta .= '<meta property="og:image" content="' . $CONFIG['ecards_more_pic_target'] . $CONFIG['fullpath'] . $CURRENT_PIC_DATA['filepath'] . $CURRENT_PIC_DATA['filename'] . '" />';
    } elseif ($CPG_PHP_SELF == 'thumbnails.php') {
        $thumb = mysql_fetch_assoc(cpg_db_query("SELECT filepath, filename FROM {$CONFIG['TABLE_PICTURES']} WHERE aid = {$CURRENT_ALBUM_DATA['aid']} ORDER BY pid DESC LIMIT 1"));
        $meta .= '<meta property="og:url" content="' . $CONFIG['ecards_more_pic_target'] . 'thumbnails.php?album=' . $CURRENT_ALBUM_DATA['aid'] . '" />' . $LINEBREAK;
        $meta .= '<meta property="og:image" content="' . $CONFIG['ecards_more_pic_target'] . $CONFIG['fullpath'] . $thumb['filepath'] . $thumb['filename'] . '" />';
    }

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

    $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
******************************************************************************/

Here the error I receive:

Quote
Template error
Failed to find block 'output_buffer' (#<!-- BEGIN output_buffer -->(.*?)<!-- END output_buffer -->#s) in :
                    <div class="{CSS_CLASS}">
                        <h2>{HEADER_TXT}</h2>
                        <span class="cpg_user_message">{MESSAGE}</span>
<!-- BEGIN file_line -->
                        <br />
                        <br />
                        {FILE_TXT}{FILE} - {LINE_TXT}{LINE}
<!-- END file_line -->

                        <br /><br />
                    </div>

What do I wrong?
Thx in advance
Logged

Αndré

  • Administrator
  • Coppermine addict
  • *****
  • Country: de
  • Offline Offline
  • Gender: Male
  • Posts: 15415
Re: Open Graph meta data for coppermine
« Reply #36 on: November 21, 2017, 12:28:39 pm »

Cannot confirm. Please post a link to your gallery and a link where we can see the error "in action". I assume it'll look like http://planepix.nl/thumbnails.php?album=lastupby&uid=4 (i.e. the "lastupby" meta album). That's at least what I tested and as you can see, the mod works as expected in that gallery.
Logged
Pages: 1 [2]   Go Up
 

Page created in 0.023 seconds with 22 queries.