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)
$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
depends on how getTag() method is defined but you can try
if ($jpegMD->getTag('iptc.Country/Primary Location Code')) { $country_code = $jpegMD->getTag('iptc.Country/Primary Location Code')->getValue() } else { $country_code = null; }
Offline
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
yeah isset() is for variables, not function returned values
Offline
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)
Offline
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:
$template->append('head_elements', '<meta name="geo.region" content="' . $place .'">' );
where $place is the string that I generated in other code.
-- Geoff
Offline
Hi :-)
ok perfect ;-)
This topic is resolved ?
Offline