Announcement

  •  » Your Piwigo
  •  » Just up and running, have some contributions...

#1 2018-09-30 23:16:13

ajuniper
Member
2018-09-30
3

Just up and running, have some contributions...

Hi

Thanks for providing Piwigo.

I just got 2.9.4 up and running after finally switching from Gallery2 and have a couple of patches for things which I found lacking in PWG.

First, I found the long standing issue with not being able to use commas in tags.  I tag with Geosetter which uses commas as a keyword separator.  First, I made the hard coded comma symbol a config value (defaults to comma, so no change to existing behaviour unless configured), then in my environment changed the configured value to be chr(127) - a character that is highly unlikely to appear in any tags.  In my case, I also then removed the value for metadata_keyword_separator_regex in my local config since the chr(127) that is used to implode the separate values provided by the library is enough.

Code:

diff --exclude=language --exclude='*rej' --exclude=_data --exclude='galleries*' --exclude='*orig' -ur piwigo-2.9.2-clean/admin/include/functions_metadata.php piwigo/admin/include/functions_metadata.php
--- piwigo-2.9.2-clean/admin/include/functions_metadata.php  2017-10-06 09:19:54.000000000 +0100
+++ piwigo/admin/include/functions_metadata.php  2017-12-06 22:55:48.412038585 +0000
@@ -42,7 +42,7 @@
 
   $map = $conf['use_iptc_mapping'];
 
-  $iptc = get_iptc_data($file, $map);
+  $iptc = get_iptc_data($file, $map, $conf['metadata_keyword_separator_char']);
 
   foreach ($iptc as $pwg_key => $value)
   {
@@ -270,7 +270,7 @@
           $tags_of[$id] = array();
         }
 
-        foreach (explode(',', $data[$key]) as $tag_name)
+        foreach (explode($conf['metadata_keyword_separator_char'], $data[$key]) as $tag_name)
         {
           $tags_of[$id][] = tag_id_from_tag_name($tag_name);
         }
@@ -380,16 +380,19 @@
 function metadata_normalize_keywords_string($keywords_string)
 {
   global $conf;
+  $sep = $conf['metadata_keyword_separator_char'];
   
-  $keywords_string = preg_replace($conf['metadata_keyword_separator_regex'], ',', $keywords_string);
-  $keywords_string = preg_replace('/,+/', ',', $keywords_string);
-  $keywords_string = preg_replace('/^,+|,+$/', '', $keywords_string);
+  if ($conf['metadata_keyword_separator_regex'] != "") {
+      $keywords_string = preg_replace($conf['metadata_keyword_separator_regex'], $sep, $keywords_string);
+  }
+  $keywords_string = preg_replace('/'.preg_quote($sep).'+/', $sep, $keywords_string);
+  $keywords_string = preg_replace('/^'.preg_quote($sep).'+|'.preg_quote($sep).'+$/', '', $keywords_string);
       
   $keywords_string = implode(
-    ',',
+    $sep,
     array_unique(
       explode(
-        ',',
+        $sep,
         $keywords_string
         )
       )
@@ -397,4 +400,4 @@
 
   return $keywords_string;
 }
-?>
\ No newline at end of file
+?>
diff --exclude=language --exclude='*rej' --exclude=_data --exclude='galleries*' --exclude='*orig' -ur piwigo-2.9.2-clean/admin/site_update.php piwigo/admin/site_update.php
--- piwigo-2.9.2-clean/admin/site_update.php  2017-10-06 09:19:54.000000000 +0100
+++ piwigo/admin/site_update.php  2017-12-10 17:17:53.105178561 +0000
@@ -875,7 +875,7 @@
             $tags_of[$id] = array();
           }
 
-          foreach (explode(',', $data[$key]) as $tag_name)
+          foreach (explode($conf['metadata_keyword_separator_char'], $data[$key]) as $tag_name)
           {
             $tags_of[$id][] = tag_id_from_tag_name($tag_name);
           }
diff --exclude=language --exclude='*rej' --exclude=_data --exclude='galleries*' --exclude='*orig' -ur piwigo-2.9.2-clean/include/config_default.inc.php piwigo/include/config_default.inc.php
--- piwigo-2.9.2-clean/include/config_default.inc.php  2017-10-06 09:19:54.000000000 +0100
+++ piwigo/include/config_default.inc.php  2017-12-06 22:56:42.913277771 +0000
@@ -399,6 +399,9 @@
 // and IPTC). Coma "," cannot be removed from this list.
 $conf['metadata_keyword_separator_regex'] = '/[.,;]/';
 
+// character to split keyword list on
+$conf['metadata_keyword_separator_char'] = ',';
+
 // +-----------------------------------------------------------------------+
 // |                               sessions                                |
 // +-----------------------------------------------------------------------+
Only in piwigo/include: config.inc.php
diff --exclude=language --exclude='*rej' --exclude=_data --exclude='galleries*' --exclude='*orig' -ur piwigo-2.9.2-clean/include/picture_metadata.inc.php piwigo/include/picture_metadata.inc.php
--- piwigo-2.9.2-clean/include/picture_metadata.inc.php  2017-10-06 09:19:54.000000000 +0100
+++ piwigo/include/picture_metadata.inc.php  2017-12-06 22:55:48.413038571 +0000
@@ -79,7 +79,7 @@
 
 if ($conf['show_iptc'])
 {
-  $iptc = get_iptc_data($picture['current']['src_image']->get_path(), $conf['show_iptc_mapping'], ', ');
+  $iptc = get_iptc_data($picture['current']['src_image']->get_path(), $conf['show_iptc_mapping'], $conf['metadata_keyword_separator_char'].' ');
 
   if (count($iptc) > 0)
   {
@@ -102,4 +102,4 @@
 }
 
 
-?>
\ No newline at end of file
+?>
Only in piwigo/local/config: config.inc.php
diff --exclude=language --exclude='*rej' --exclude=_data --exclude='galleries*' --exclude='*orig' -ur piwigo-2.9.2-clean/plugins/read_metadata/admin.php piwigo/plugins/read_metadata/admin.php
--- piwigo-2.9.2-clean/plugins/read_metadata/admin.php  2017-03-07 13:22:42.000000000 +0000
+++ piwigo/plugins/read_metadata/admin.php  2017-12-06 22:55:48.414038557 +0000
@@ -21,6 +21,7 @@
 
 if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
 global $template;
+global $conf;
 include_once(PHPWG_ROOT_PATH .'admin/include/tabsheet.class.php');
 
 // +-----------------------------------------------------------------------+
@@ -112,7 +113,7 @@
     foreach (array_keys($iptc) as $iptc_key){
           if (isset($iptc[$iptc_key][0])){
            if ($iptc_key == '2#025'){
-             $value = implode(',',
+             $value = implode($conf['metadata_keyword_separator_char'],
                array_map(
                  'clean_iptc_value',
                  $iptc[$iptc_key]
@@ -191,4 +192,4 @@
 $template->set_filenames(array('plugin_admin_content' => dirname(__FILE__) . '/admin.tpl')); 
 $template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');
 }
-?>
\ No newline at end of file
+?>

Next, on the tags page, I wanted to make it easier to find tags.  All of my tags are prefixed with "prefix/" - e.g. "people/persons name" or "places/uk, someplace".  Repeating the "prefix/" part for each tag on the tags page caused a lot of unnecessary words, so I tweaked the tags page to have a new mode "words" which aggregates tags by the "prefix/" part, and strips that off for each linked tag.  The "prefix/" part is then what is used as a group, like the initial letters are in the existing "letters" mode.  It's a bit difficult to explain so I've added a screenshot of what it looks like.  The only thing lacking here is a good icon, I've reused the existing icon for letter indexing.  The character used between the prefix and value is configurable "tags_words_split_characters".

Code:

diff --exclude=language --exclude='*rej' --exclude=_data --exclude='galleries*' --exclude='*orig' -ur piwigo-2.9.2-clean/tags.php piwigo/tags.php
--- piwigo-2.9.2-clean/tags.php  2017-10-06 09:19:54.000000000 +0100
+++ piwigo/tags.php  2017-12-31 19:28:40.868367505 +0000
@@ -63,13 +63,13 @@
 $page['display_mode'] = $conf['tags_default_display_mode'];
 if (isset($_GET['display_mode']))
 {
-  if (in_array($_GET['display_mode'], array('cloud', 'letters')))
+  if (in_array($_GET['display_mode'], array('cloud', 'letters', 'words')))
   {
     $page['display_mode'] = $_GET['display_mode'];
   }
 }
 
-foreach (array('cloud', 'letters') as $mode)
+foreach (array('cloud', 'letters', 'words') as $mode)
 {
   $template->assign(
     'U_'.strtoupper($mode),
@@ -86,7 +86,85 @@
 // |                       letter groups construction                      |
 // +-----------------------------------------------------------------------+
 
-if ($page['display_mode'] == 'letters') {
+if ($page['display_mode'] == 'words') {
+  // we want tags diplayed in alphabetic order
+  usort($tags, 'tag_alpha_compare');
+
+  $current_word = null;
+  $nb_tags = count($tags);
+  $current_column = 1;
+  $current_tag_idx = 0;
+
+  $word = array(
+    'tags' => array()
+    );
+
+  if ($conf['tags_words_split_chars'] != '')
+  {
+      $spliton = '['.$conf['tags_words_split_chars'].']';
+  } else {
+      $spliton = '[,/]';
+  }
+
+  foreach ($tags as $tag)
+  {
+    $tag_word = mb_split($spliton,$tag['name'],2)[0];
+
+    if ($current_tag_idx==0) {
+      $current_word = $tag_word;
+      $word['TITLE'] = $tag_word;
+    }
+
+    if ($tag_word !== $tag['name'])
+    {
+      # strip the tag prefix from the tag name
+      $tag['name'] = mb_substr($tag['name'],mb_strlen($tag_word)+1);
+    }
+
+    //lettre precedente differente de la lettre suivante
+    if ($tag_word !== $current_word)
+    {
+      if ($current_column<$conf['tag_letters_column_number']
+          and $current_tag_idx > $current_column*$nb_tags/$conf['tag_letters_column_number'] )
+      {
+        $word['CHANGE_COLUMN'] = true;
+        $current_column++;
+      }
+
+      $word['TITLE'] = $current_word;
+
+      $template->append(
+        'letters',
+        $word
+        );
+
+      $current_word = $tag_word;
+      $word = array(
+        'tags' => array()
+        );
+    }
+
+    $word['tags'][] = array_merge(
+      $tag,
+      array(
+        'URL' => make_index_url(array('tags' => array($tag))),
+        )
+      );
+
+    $current_tag_idx++;
+  }
+
+  // flush last word
+  if (count($word['tags']) > 0)
+  {
+    unset($word['CHANGE_COLUMN']);
+    $word['TITLE'] = $current_word;
+    $template->append(
+      'letters',
+      $word
+      );
+  }
+} else if ($page['display_mode'] == 'letters') {
   // we want tags diplayed in alphabetic order
   usort($tags, 'tag_alpha_compare');
 
@@ -199,4 +277,4 @@
 flush_page_messages();
 $template->pparse('tags');
 include(PHPWG_ROOT_PATH.'include/page_tail.php');
-?>
\ No newline at end of file
+?>
diff --exclude=language --exclude='*rej' --exclude=_data --exclude='galleries*' --exclude='*orig' -ur piwigo-2.9.2-clean/themes/default/template/tags.tpl piwigo/themes/default/template/tags.tpl
--- piwigo-2.9.2-clean/themes/default/template/tags.tpl  2017-10-06 09:19:54.000000000 +0100
+++ piwigo/themes/default/template/tags.tpl  2017-12-31 19:23:09.296435329 +0000
@@ -3,12 +3,17 @@
 
 <div class="titrePage">
   <ul class="categoryActions">
-{if $display_mode == 'letters'}
+{if $display_mode != 'cloud'}
     <li><a href="{$U_CLOUD}" title="{'show tag cloud'|@translate}" class="pwg-state-default pwg-button">
       <span class="pwg-icon pwg-icon-cloud"></span><span class="pwg-button-text">{'cloud'|@translate}</span>
     </a></li>
 {/if}
-{if $display_mode == 'cloud'}
+{if $display_mode != 'words'}
+    <li><a href="{$U_WORDS}" title="{'group by word'|@translate}" class="pwg-state-default pwg-button">
+      <span class="pwg-icon pwg-icon-letters"></span><span class="pwg-button-text">{'words'|@translate}</span>
+    </a></li>
+{/if}
+{if $display_mode != 'letters'}
     <li><a href="{$U_LETTERS}" title="{'group by letters'|@translate}" class="pwg-state-default pwg-button" rel="nofollow">
       <span class="pwg-icon pwg-icon-letters"></span><span class="pwg-button-text">{'letters'|@translate}</span>
     </a></li>
@@ -28,7 +33,7 @@
 </div>
 {/if}
 
-{if $display_mode == 'letters' and isset($letters)}
+{if ($display_mode == 'words' || $display_mode == 'letters') and isset($letters)}
 <table>
   <tr>
     <td valign="top">

So in my local config I now have the following, since I like using my patches.  I also use the IPTC headline value in my tagging so I also map that in the config:

Code:

<?php
$conf['show_iptc'] = true;
$conf['use_iptc'] = true;

$conf['metadata_keyword_separator_regex'] = '';
$conf['metadata_keyword_separator_char'] = chr(127);
# IPTC Headline = 2#105
$conf['show_iptc_mapping']['iptc_heaadline']='2#105';
$conf['use_iptc_mapping']['name']='2#105';

$conf['tags_default_display_mode'] = 'words';
$conf['tags_words_split_chars'] = '/,';
?>

Hope someone can benefit from these patches (it would be great if they were merged into the main code so that I don't have hassles each time things update).

Thanks for providiing Piwigo!


Uploaded Images

Last edited by ajuniper (2018-09-30 23:17:04)

Offline

 

#2 2018-10-01 10:25:03

plg
Piwigo Team
Nantes, France, Europe
2002-04-05
13173

Re: Just up and running, have some contributions...

Hi ajuniper,

Did you try [extension by plg] Tag Groups ?


Latest blog post (May 3rd 2018) New subscription form

Offline

 

#3 2018-10-01 22:26:48

ajuniper
Member
2018-09-30
3

Re: Just up and running, have some contributions...

Hi,

No, I had not seen that plugin.  I just gave it a quick try, had to tweak it to use '/' as a separator (and suitably escape it in the regex).  The grouped page then works as expected (same result as the patch I gave), but it does mean that the groups are not shown on the other tag pages.  Not sure if that is what I was expecting or not...

Here's the change I had to make, I guess that the separator should be made a proper config item instead of hard coded in the plugin.

Code:

--- plugins/tag_groups/main.inc.php.orig  2016-03-16 17:18:06.000000000 +0000
+++ plugins/tag_groups/main.inc.php  2018-10-01 21:21:55.147264600 +0100
@@ -8,6 +8,9 @@
 Author URI: http://piwigo.org
 */
 
+global $tag_group_sep;
+$tag_group_sep="/";
+
 if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
 
 $render_tag_names = true;
@@ -42,7 +45,10 @@
 
 function tg_clean_tag_name($tag_name)
 {
-  return preg_replace('/^[^:]*:/', '', $tag_name);
+  global $tag_group_sep;
+  $pattern='/^[^'.preg_quote($tag_group_sep,'/').']*'.preg_quote($tag_group_sep,'/').'/';
+  #echo "sep =$tag_group_sep= pattern $pattern\n";
+  return preg_replace($pattern, '', $tag_name);
 }
 
 // file_get_contents('tags.tpl')
@@ -55,6 +61,7 @@
 function tg_groups_display()
 {
   global $conf, $template, $user, $tags, $page;
+  global $tag_group_sep;
 
   load_language('plugin.lang', PHPWG_PLUGINS_PATH . basename(dirname(__FILE__)) . '/');
   load_language('lang', PHPWG_ROOT_PATH.PWG_LOCAL_DIR, array('no_fallback'=>true, 'local'=>true) );
@@ -86,13 +93,13 @@
     {
       // if the tag belongs to no group, we don't show it on the "tag by
       // group" display mode
-      if (strpos($tag['name'], ':') === false)
+      if (strpos($tag['name'], $tag_group_sep) === false)
       {
         continue;
       }
       else
       {
-        list($tag['group'], $tag['name']) = explode(':', $tag['name'], 2);
+        list($tag['group'], $tag['name']) = explode($tag_group_sep, $tag['name'], 2);
         $tag['group'] = preg_replace('/^[^=]*=/', '', $tag['group']);
       }

Offline

 

#4 2018-10-05 17:09:10

plg
Piwigo Team
Nantes, France, Europe
2002-04-05
13173

Re: Just up and running, have some contributions...

If possible, please make a pull-request on https://github.com/plegall/piwigo-tag_groups (if you can't, tell me and I'll include your change in the code).


Latest blog post (May 3rd 2018) New subscription form

Offline

 

#5 2018-10-10 23:05:17

ajuniper
Member
2018-09-30
3

Re: Just up and running, have some contributions...

I'm just trying to sort out pull requests for each of my changes but notice that the keyword separator fix would need to be synchronised with the read_metadata plugin.

How does that work, with respect to a plugin version requiring a particular core version?

Also, what is the best practise with regards a plugin requiring a config value?  The separator is obviously best defaulted to the colon you use today but the kind of thing that everyone had a different opinion on.

Offline

 
  •  » Your Piwigo
  •  » Just up and running, have some contributions...

Board footer

Powered by FluxBB

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