Announcement

#16 2012-07-26 23:50:59

geoffschultz
Member
Marlborough, MA, USA
2012-07-01
148

Re: [resolved] How to use plugin "Add <head> Element"?

I need to ask a stupid PHP question, but I'm a retired programmer who has just recently picked up PHP.

If I try to access a IPTC field which isn't set (for example)

Code:

$country_code = $jpegMD->getTag('iptc.Country/Primary Location Code')->getValue()

I get:

Fatal Error: Call to a member function getValue() on a non-object

How do I check to see if 'iptc.Country/Primary Location Code' exists before calling getValue?

-- Geoff

Last edited by geoffschultz (2012-07-26 23:52:33)

Offline

 

#17 2012-07-27 00:05:23

mistic100
Former Piwigo Team
Lyon (FR)
2008-09-27
3271

Re: [resolved] How to use plugin "Add <head> Element"?

depends on how getTag() method is defined but you can try

Code:

if ($jpegMD->getTag('iptc.Country/Primary Location Code'))
{
    $country_code = $jpegMD->getTag('iptc.Country/Primary Location Code')->getValue()
}
else
{
    $country_code = null;
}

Offline

 

#18 2012-07-27 00:29:30

geoffschultz
Member
Marlborough, MA, USA
2012-07-01
148

Re: [resolved] How to use plugin "Add <head> Element"?

That worked!  Thank you very much.  I could swear that I tried that or isset(), but it didn't work.  Anyhow, I'm off and running.  Thanks again.

-- Geoff

Offline

 

#19 2012-07-27 00:34:16

mistic100
Former Piwigo Team
Lyon (FR)
2008-09-27
3271

Re: [resolved] How to use plugin "Add <head> Element"?

yeah isset() is for variables, not function returned values

Offline

 

#20 2012-07-28 19:41:29

ddtddt
Piwigo Team
Quetigny - France
2007-07-27
6803

Re: [resolved] How to use plugin "Add <head> Element"?

Hi :-)

geoffschultz wrote:

I want to add information to the <head> section of image pages.  For example, in my current (non-piwigo) web site, I output information like:

<meta name="geo.position" content="-112.093667; 27.188833"/>

I see in a other topic

geoffschultz wrote:

<meta name="keywords" content="BCS, Isla San Marcos, MEX, Mexico"/>
<meta name="description" content="Gypsum Mine, Mexico, BCS, Isla San Marcos, MEX, "/>

You want additional what is, or in place

geoffschultz wrote:

<meta name="geo.region" content="MEX-BCS"/>
<meta name="geo.placename" content="Isla San Marcos, BCS, Mexico"/>

by FTP in folder PersonalPlugin create file metaperso.tpl with

<meta name="geo.region" content="{$metadata.1.lines.country_code}"/>
<meta name="geo.placename" content="{$metadata.1.lines.country_name}"/>

go to Administration -> plugins -> localFile Editor -> tap personalplugin
paste

define('PIPTC_DIR' , basename(dirname(__FILE__)));
define('PIPTC_PATH' , PHPWG_PLUGINS_PATH . PIPTC_DIR . '/');

global $template,$conf;

add_event_handler('loc_begin_page_header', 'AHEgeoffschultz',20 );

function AHEgeoffschultz()
{
global $template, $page;
    if ( !empty($page['image_id']) )   
  {
    $template->set_filename('META_PERSO', realpath(PIPTC_PATH.'metaperso.tpl'));   
    $template->append('head_elements', $template->parse('META_PERSO', true));
   }
}

active personal plugin

(this works if IPTC is good on local config)


You love Piwigo so don't hesitate to participate, learn more on the "Contribute to Piwigo" page. If you don't have much time for contribution, you can also help the project with a donation.

Offline

 

#21 2012-07-29 00:17:39

geoffschultz
Member
Marlborough, MA, USA
2012-07-01
148

Re: [resolved] How to use plugin "Add <head> Element"?

ddtddt,

Thank for yet another solution to this problem.  I really didn't want to have multiple threads about the same thing, but both threads ended up discussing the same thing.

Anyhow, at this point I have a rather lengthy PersonalPlugin which generates the headers that I need.  I'm generating the meta tags via code like:

Code:

$template->append('head_elements', '<meta name="geo.region" content="' . $place .'">' );

where $place is the string that I generated in other code.

-- Geoff

Offline

 

#22 2012-07-29 08:34:09

ddtddt
Piwigo Team
Quetigny - France
2007-07-27
6803

Re: [resolved] How to use plugin "Add <head> Element"?

Hi :-)

ok perfect ;-)

This topic is resolved ?


You love Piwigo so don't hesitate to participate, learn more on the "Contribute to Piwigo" page. If you don't have much time for contribution, you can also help the project with a donation.

Offline

 

Board footer

Powered by FluxBB

github twitter facebook google+ newsletter Donate Piwigo.org © 2002-2019 · Contact