plegall / Piwigo-write_metadata

3 stars 4 forks source link

Unable to Write metadata to files from Piwigo database problem When HTML code in PTC:Caption-Abstract #17

Open RStoroy opened 1 year ago

RStoroy commented 1 year ago

NO IPTC TAGS at all is written to the file. [code] <?php / Plugin Name: Write Metadata Description: Write Piwigo photo properties (title, description, author, tags) into IPTC fields Author: plg Plugin URI: http://piwigo.org/ext/extension_view.php?eid=769 Version: 12.a /

// +-----------------------------------------------------------------------+ // | Define plugin constants | // +-----------------------------------------------------------------------+

defined('WRITE_METADATA_ID') or define('WRITE_METADATA_ID', basename(dirname(FILE))); define('WRITE_METADATA_PATH' , PHPWG_PLUGINS_PATH.basename(dirname(FILE)).'/');

// +-----------------------------------------------------------------------+ // | Edit Photo | // +-----------------------------------------------------------------------+

add_event_handler('loc_begin_admin_page', 'wm_add_link', 60); function wm_add_link() { global $template, $page;

$template->set_prefilter('picture_modify', 'wm_add_link_prefilter');

if (isset($page['page']) and 'photo' == $page['page']) { $template->assign( 'U_WRITEMETADATA', get_root_url().'admin.php?page=photo-'.$_GET['image_id'].'-properties&write_metadata=1' ); } }

function wm_add_link_prefilter($content) { $search = '{if !url_is_remote($PATH)}';

$replacement = '{if !url_is_remote($PATH)} ';

return str_replace($search, $replacement, $content); }

add_event_handler('loc_begin_admin_page', 'wm_picture_write_metadata'); function wm_picture_write_metadata() { global $page, $conf;

load_language('plugin.lang', dirname(FILE).'/');

if (isset($page['page']) and 'photo' == $page['page'] and isset($_GET['write_metadata'])) { check_input_parameter('image_id', $_GET, false, PATTERN_ID); list($rc, $output) = wm_write_metadata($_GET['image_id']);

if (count($output) == 0)
{
  $_SESSION['page_infos'][] = l10n('Metadata written into file');
  redirect(get_root_url().'admin.php?page=photo-'.$_GET['image_id'].'-properties');
}
else
{
  $page['errors'] = array_merge($page['errors'], $output);
}

} }

// +-----------------------------------------------------------------------+ // | Batch Manager | // +-----------------------------------------------------------------------+

add_event_handler('loc_begin_element_set_global', 'wm_element_set_global_add_action'); function wm_element_set_global_add_action() { global $template, $page;

$template->set_filename('writeMetadata', realpath(WRITE_METADATA_PATH.'element_set_global_action.tpl'));

if (isset($_POST['submit']) and $_POST['selectAction'] == 'writeMetadata') { $page['infos'][] = l10n('Metadata written into file'); }

$template->assign( array( 'WM_PWG_TOKEN' => get_pwg_token(), ) );

$template->append( 'element_set_global_plugins_actions', array( 'ID' => 'writeMetadata', 'NAME' => l10n('Write metadata'), 'CONTENT' => $template->parse('writeMetadata', true), ) ); }

add_event_handler('ws_add_methods', 'wm_add_methods'); function wm_add_methods($arr) { include_once(WRITE_METADATA_PATH.'ws_functions.inc.php'); }

// +-----------------------------------------------------------------------+ // | Common functions | // +-----------------------------------------------------------------------+

/**

function wm_prepare_string($string, $maxLen) { return wm_cutString( wm_explode_description( wm_decode_html_string_to_unicode($string) ), $maxLen ); }

function wm_cutString($description, $maxLen) { if (strlen($description) > $maxLen) { $description = substr($description, 0, $maxLen); } return $description; }

function wm_explode_description($description) { return str_replace( array('
', '
', "\n", "\r"), array('', '', '', ''), $description ); }

function wm_decode_html_string_to_unicode($string) { if (isset($string) and strlen($string) > 0) { $string = html_entity_decode(trim($string), ENT_QUOTES, 'UTF8'); $string = stripslashes($string); } else { $string = ''; }

return($string); } ?> [/code]