suggestion for hack 'organized keyword list' suggestion for hack 'organized keyword list'
 

News:

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

Main Menu

suggestion for hack 'organized keyword list'

Started by krakelis, November 20, 2008, 09:32:43 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

krakelis

First things first: I'm completely new to this forum, to CPG and to PHP. As green as possible so to say. I'm smashed by everything that's possible with this great piece of software and try to integrate it in my static HTML website in a nice way to store my pictures and make them searchable.
http://basdekker.eu/beeldbank/index.php

The hack by Stramm wich turns the flat keywordlist in an orginized one did fullfill my dreams.... well, almost  ;D
http://forum.coppermine-gallery.net/index.php/topic,30900.0.html

There are two things in this hack I'm trying to change, but since I don't know that much (= nothing) about PHP I'm just swimming in the air. I will keep struggling to understand how PHP works because I like to learn about it, but I will put my suggestions here at the same time.

One: The suggestion of kad75 to get only the field of one letter shown in the lower part of the page seems very usefull to me.
Two: I like the use of <br> as suggested by Nibbler very much but it would be great (if possible in an easy way) to have the alphabeth on top of the page not broken in such a list. I thought to be keen and make a second defenition for 'delimiter-2' to get used in that part, but as I told PHP is not my specialty so after the idea everything got blocked since I really have no idea how to make changings. I'm reading and studying and struggling in the meanwhile, but If anyone has some simple solutions it would be great ofcourse.

krakelis

As I said, I will keep trying myself too at least  ;D

It seems like I did change Stramms nice hack with a working result to get the index letters not showed as list but as line.

Below are the changes I made in Stramms hacked 'keyword.inc.php'. I did add a second definition called DELIMITERAZ and replaced DELIMITER by it three times in the code. Be warned though, this is my first 'coding' in PHP so there will be better methods for sure but for the moment I'm happy with the result. The attachement shows the result on my coppermine testsite at http://basdekker.eu/beeldbank/search.php

Old code:
//mod indexed keaywords
define("DELIMITER", "&nbsp;|&nbsp;");

function spacer($w, $n)
{
for ($i = 1; $i <= $n; $i++)
{
$index .= DELIMITER . chr((ord($w)) + $i);
}
return $index;
}

// ADDED QUICK KEYWORDS FUNCTIONALITY 8/6/2004

$result = cpg_db_query("select keywords FROM {$CONFIG['TABLE_PICTURES']} WHERE keywords <> '' $ALBUM_SET");
if (mysql_num_rows($result)) {

  // Grab all keywords
  print '<br />';
  starttable("100%", $lang_search_php['keyword_list_title']);


  // Find unique keywords
  $keywords_array = array();

  while (list($keywords) = mysql_fetch_row($result)) {
      $array = explode(" ",$keywords);

      foreach($array as $word)
      {
       if (!in_array($word = strtolower($word),$keywords_array)) $keywords_array[] = $word;;
      }
  }

  // Sort selected keywords
  sort($keywords_array);
  $count = count($keywords_array);
  // Result to table
  echo '<tr><td class="tableb">' ;
 
//mod indexed keywords
$oldword = "";
$html="";
$special_html="";
$index_list="";
$special="FALSE";
foreach($keywords_array as $key)
{
$word = strtoupper(substr($key, 0, 1));
if (($word < "A" or $word >"Z")) {

if ($special=="FALSE") { //if we do not have it in the index and special exits
$index_list .=  "<b><u><a href=\"#1-9\">1-9</a></u></b>";
$special_html .= "<br><br><a name=\"1-9\"></a><b>1-9</b><br>"; //container for 1-9 and special chars
}
$special="TRUE"; //we have special now in the index
$special_html .= "<a href=\"thumbnails.php?album=search&search=".$key."\">$key</a> ";
$special_html .= DELIMITER;
} else { // index and keywords a-z
$next = strncasecmp($word, $oldword, 1); //compare this first letter with the first letter of the next keyword
if ($next > 0) //next keaywords first letter <> this keywords first letter
{
$index_list .= spacer($oldword, --$next); // add the non linked 'spacer' letters

if (strlen($html) >= strlen(DELIMITER)) $html = substr($html,0,(strlen($html)-strlen(DELIMITER))); // remove trailing delimiter

$html .= "<br><br><a name=\"{$word}\"></a><b>{$word}</b><br>"; //add the first letter as header to the html
$index_list .=  DELIMITER . "<b><u><a href=\"#{$word}\">{$word}</a></u></b>";
$oldword = $word;

}
$html .= "<a href=\"thumbnails.php?album=search&search=".$key."\">{$key}</a>" . DELIMITER;
}

}
if (strlen($html) >= strlen(DELIMITER)) $html = substr($html,0,(strlen($html)-strlen(DELIMITER)));


My changings:
//mod indexed keywords
// define("DELIMITER", "&nbsp;|&nbsp;");  //removed by Krakelis
define("DELIMITER", "<br>"); //changed by Krakelis, suggested by Nibbler
define("DELIMITERAZ", "&nbsp;&nbsp;"); //added by Krakelis

function spacer($w, $n)
{
for ($i = 1; $i <= $n; $i++)
{
$index .= DELIMITERAZ . chr((ord($w)) + $i); //changed by krakelis
}
return $index;
}

// ADDED QUICK KEYWORDS FUNCTIONALITY 8/6/2004

$result = cpg_db_query("select keywords FROM {$CONFIG['TABLE_PICTURES']} WHERE keywords <> '' $ALBUM_SET");
if (mysql_num_rows($result)) {

  // Grab all keywords
  print '<br />';
  starttable("100%", $lang_search_php['keyword_list_title']);


  // Find unique keywords
  $keywords_array = array();

  while (list($keywords) = mysql_fetch_row($result)) {
      $array = explode(" ",$keywords);

      foreach($array as $word)
      {
       if (!in_array($word = strtolower($word),$keywords_array)) $keywords_array[] = $word;;
      }
  }

  // Sort selected keywords
  sort($keywords_array);
  $count = count($keywords_array);
  // Result to table
  echo '<tr><td class="tableb">' ;
 
//mod indexed keywords
$oldword = "";
$html="";
$special_html="";
$index_list="";
$special="FALSE";
foreach($keywords_array as $key)
{
$word = strtoupper(substr($key, 0, 1));
if (($word < "A" or $word >"Z")) {

if ($special=="FALSE") { //if we do not have it in the index and special exits
$index_list .=  "<b><u><a href=\"#1-9\">1-9</a></u></b>";
$special_html .= "<br><br><a name=\"1-9\"></a><b>1-9</b><br>"; //container for 1-9 and special chars
}
$special="TRUE"; //we have special now in the index
$special_html .= "<a href=\"thumbnails.php?album=search&search=".$key."\">$key</a> ";
$special_html .= DELIMITERAZ; //changed by krakelis
} else { // index and keywords a-z
$next = strncasecmp($word, $oldword, 1); //compare this first letter with the first letter of the next keyword
if ($next > 0) //next keywords first letter <> this keywords first letter
{
$index_list .= spacer($oldword, --$next); // add the non linked 'spacer' letters

if (strlen($html) >= strlen(DELIMITER)) $html = substr($html,0,(strlen($html)-strlen(DELIMITER))); // remove trailing delimiter

$html .= "<br><br><a name=\"{$word}\"></a><b>{$word}</b><br>"; //add the first letter as header to the html
$index_list .=  DELIMITERAZ . "<b><u><a href=\"#{$word}\">{$word}</a></u></b>"; //changed by krakelis
$oldword = $word;

}
$html .= "<a href=\"thumbnails.php?album=search&search=".$key."\">{$key}</a>" . DELIMITER;
}

}
if (strlen($html) >= strlen(DELIMITER)) $html = substr($html,0,(strlen($html)-strlen(DELIMITER)));


It would be great if someone with PHP knowledge does check my beginnerscode.