Author Topic: Auto generate keywords if keywords field left emty by users  (Read 37969 times)

0 Members and 1 Guest are viewing this topic.

Offline egoplawi

  • Newbie
  • *
  • Posts: 15
  • Punksy möchte die Welt erobern.
    • View Profile
    • Punksy.com
Hallo!

D: Ich habe mir mal ein kleines Script geschrieben, welches das Feld "image_keywords" in der Datenbank mit Schlüsselwörtern füllt, falls der User keine eingetragen hat. Ich nehme dazu den Bildernamen, und die Beschreibung, falls diese vom User eingetragen wurden.

Erstelle eine Datei mit dem Namen "autokeywords.php"

Füge folgenden Code ein:

Code: [Select]
<?php



define
('ROOT_PATH''./gallery/');

include(
ROOT_PATH.'config.php');
include(
ROOT_PATH.'includes/db_mysql.php');
include(
ROOT_PATH.'includes/constants.php');

$site_db = new Db($db_host$db_user$db_password$db_name) OR die("Keine Verbindung zum Datenbankserver.");



$sql "SELECT image_id, image_name, image_description, image_keywords, image_media_file 
        FROM "
.IMAGES_TABLE.
        WHERE image_keywords=''"
;

$result $site_db->query($sql);

while (
$row $site_db->fetch_array($result)){
  
$new_keywords "";
  
$image_id $row['image_id'];
  
$image_name $row['image_name'];
  
$image_description $row['image_description'];
  
$image_keywords $row['image_keywords'];
  
$image_media_file $row['image_media_file'];

  
$image_media_file_name explode(".",$image_media_file);
  
  if(
$image_name != $image_media_file_name[0])
  {
$new_keywords .= $image_name;
  if(
$image_description != "")
  {
$new_keywords .= " ".$image_description;}
  echo 
"Bild ID: ".$image_id."<br>\n";
  echo 
"Bildname: ".$image_name."<br>\n";
  echo 
"Beschreibung: ".$image_description."<br>\n";
  echo 
"Keywords: ".$new_keywords."<br>\n";
  echo 
"Filename: ".$image_media_file."<br>\n";
  echo 
"<br><hr>\n";
  
$sql "UPDATE ".IMAGES_TABLE." SET image_keywords = '$new_keywords' WHERE image_id = '$image_id'";
  
$result mysql_query($sql) OR die("Fehler beim Schreiben in Tabelle.");


  }


  }
  @
mysql_close($site_db); 

?>

Achtung: Das Script schreibt in die Datenbank! Unbedingt Backup der Datenbank anlegen!

Vieleicht findet sich ja jemand, der das Script verbessern kann. Möglicherweise als Plugin im Admin Bereich.
Das kriege ich leider nicht so einfach hin.


E: This script auto generate keywords if keywords field left emty by users. For keywords i use picture name and picture description.
This script write data to the database! Make backup of your database!


Schönen Tag
Egoplawi

Jacob

  • Guest
Re: Auto generate keywords if keywords field left emty by users
« Reply #1 on: July 30, 2007, 08:26:05 PM »
Can you please explain it a little bit, where to place this file and how to use it??

Thanks for your hard work  :)

Offline thunderstrike

  • 4images Guru
  • *******
  • Posts: 2.327
    • View Profile
Re: Auto generate keywords if keywords field left emty by users
« Reply #2 on: July 30, 2007, 10:12:55 PM »
Further expand this MOD for additional image fields (all extra images fields):

Quote
$site_db = new Db($db_host, $db_user, $db_password, $db_name) OR die("Keine Verbindung zum Datenbankserver.");

below add:

Quote
$additional_sql = "";
if (!empty($additional_image_fields)) {
  foreach ($additional_image_fields as $key => $val) {
    $additional_sql .= ", ".$key;
  }
}

Quote
$sql = "SELECT image_id, image_name, image_description, image_keywords, image_media_file
        FROM ".IMAGES_TABLE."
        WHERE image_keywords=''";

replace by:

Quote
$sql = "SELECT image_id, image_name, image_description, image_keywords, image_media_file" . $additional_sql . "
        FROM ".IMAGES_TABLE."
        WHERE image_keywords=''";

You can use all your image extra fields now. :)

Would replace this too:

Quote
$result = mysql_query($sql) OR die("Fehler beim Schreiben in Tabelle.");

for:

Quote
$result = $site_db->query($sql) OR die("Fehler beim Schreiben in Tabelle.");
8 steps need when ask question -

- PHP version (ACP - > phpinfo())
- mySQL version (ACP - > phpinfo())
- 4images version
- Post screenshot / URL
- Post code in BB Code (no need full file for code) or post attach file
- It doesn't work. What is say - what is do for no work
- Install MOD ? If so - please say (troubleshooting)
- Read FAQ ? Install Bug fixes ?

Offline egoplawi

  • Newbie
  • *
  • Posts: 15
  • Punksy möchte die Welt erobern.
    • View Profile
    • Punksy.com
Re: Auto generate keywords if keywords field left emty by users
« Reply #3 on: July 30, 2007, 10:25:36 PM »
Hi Jacob!

If some users uploade pictures but do not enter keywords for this pictures the script generate keywords from the 'picture name' and 'picture description' fields.

w.b.r.
Egoplawi

Jacob

  • Guest
Re: Auto generate keywords if keywords field left emty by users
« Reply #4 on: July 31, 2007, 05:19:37 AM »
Ok, thanks a TON egoplawi for this wonderful mod   :D

and thanks a lot thunderstrike for optimizing it :D


Test it and its adding keywords :) but in the footer its showing this error (in red):

Bild ID: 40
Bildname: cameron-diaz-diaz175
Beschreibung:
Keywords: cameron-diaz-diaz175
Filename: 1_115-cameron-diaz-diaz1751024x768.jpg
________________________________________________________________________________________________________________________________
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/myurlin/public_html/xxxxxxxx/wip/includes/db_mysql.php on line 92


and one thing more, is there anyway to make it automated .. maybe with a cron job?? as i have over 15000 images on the gallery.. it gona take lots of time to do above thing ;)

Thanks again guys :D

Offline thunderstrike

  • 4images Guru
  • *******
  • Posts: 2.327
    • View Profile
Re: Auto generate keywords if keywords field left emty by users
« Reply #5 on: July 31, 2007, 05:41:57 AM »
Quote
$sql = "SELECT image_id, image_name, image_description, image_keywords, image_media_file" . $additional_sql . "
        FROM ".IMAGES_TABLE."
        WHERE image_keywords=''";

$result = $site_db->query($sql);

below add:

Quote
$num_rows = $site_db->get_numrows($result);

if ($num_rows > 0) {

Then,

Quote
$result = $site_db->query($sql) OR die("Fehler beim Schreiben in Tabelle.");


  }

below add:

Quote
}
8 steps need when ask question -

- PHP version (ACP - > phpinfo())
- mySQL version (ACP - > phpinfo())
- 4images version
- Post screenshot / URL
- Post code in BB Code (no need full file for code) or post attach file
- It doesn't work. What is say - what is do for no work
- Install MOD ? If so - please say (troubleshooting)
- Read FAQ ? Install Bug fixes ?

Jacob

  • Guest
Re: Auto generate keywords if keywords field left emty by users
« Reply #6 on: July 31, 2007, 08:08:05 AM »
thunderstrike error still there  :!:
But script adding keywords ;)

Already added keywords to 7801 images with the help of this script along with a Firefox addon: https://addons.mozilla.org/en-US/firefox/addon/115

Jacob

  • Guest
Re: Auto generate keywords if keywords field left emty by users
« Reply #7 on: July 31, 2007, 12:55:43 PM »
update:

Added keywords to all images :D

But script skipped some categories while adding keywords in bulk. How can i add keywords to the left images.?? I tried executing the file again, but its showing blank page now

Thanks for your help guys :)

Offline thunderstrike

  • 4images Guru
  • *******
  • Posts: 2.327
    • View Profile
Re: Auto generate keywords if keywords field left emty by users
« Reply #8 on: July 31, 2007, 01:09:13 PM »
Quote
But script skipped some categories while adding keywords in bulk.

It skips because cats are not selected from this MOD. Only images are.
8 steps need when ask question -

- PHP version (ACP - > phpinfo())
- mySQL version (ACP - > phpinfo())
- 4images version
- Post screenshot / URL
- Post code in BB Code (no need full file for code) or post attach file
- It doesn't work. What is say - what is do for no work
- Install MOD ? If so - please say (troubleshooting)
- Read FAQ ? Install Bug fixes ?

Jacob

  • Guest
Re: Auto generate keywords if keywords field left emty by users
« Reply #9 on: July 31, 2007, 03:35:59 PM »
Nope bro, i mean to say:

It skipped some images from some categories :)
Like in some categories, not a single image have keywords!

Thanks for your help :)

Offline egoplawi

  • Newbie
  • *
  • Posts: 15
  • Punksy möchte die Welt erobern.
    • View Profile
    • Punksy.com
Re: Auto generate keywords if keywords field left emty by users
« Reply #10 on: July 31, 2007, 04:27:11 PM »
Hi Jacob!

If you uploade pictures by ftp and did not enter picturename and/or picturedescription the default picturename is the same as the name of the mediafile like "CIMG1234" and this is not a good keyword.

As soon you or someone else enter a picturename and/or picturedescription you can run my script again and get new keywords.

w.b.r.
Egoplawi

Offline egoplawi

  • Newbie
  • *
  • Posts: 15
  • Punksy möchte die Welt erobern.
    • View Profile
    • Punksy.com
Re: Auto generate keywords if keywords field left emty by users
« Reply #11 on: August 03, 2007, 07:20:07 PM »
Hallo!

habe gerade entdeckt, dass 4images, wenn es im Namen der Bilddatei einen Unterstrich findet, diesen durch ein Leerzeichen ersetzt und als Bildernamen verwendet. Mein Skript verwendet dann diesen Bildernamen um ein Keyword zu erzeugen.

Beispiel:

Dateiname: 444_333.jpg
Bildername: 444 333
Neues Keyword: 444 333

Wer das nicht will findet
Code: [Select]
$image_media_file = $row['image_media_file'];und fügt direkt darunter ein
Code: [Select]
$image_media_file = str_replace("_", " " ,$image_media_file);
Bis bald
Egoplawi

Offline navyseal

  • Newbie
  • *
  • Posts: 43
    • View Profile
Re: Auto generate keywords if keywords field left emty by users
« Reply #12 on: October 16, 2007, 02:08:58 PM »
This doesnt work on 1.7.1 or doest it? I tried it out and its not working for me :(

Offline thunderstrike

  • 4images Guru
  • *******
  • Posts: 2.327
    • View Profile
Re: Auto generate keywords if keywords field left emty by users
« Reply #13 on: October 17, 2007, 12:52:35 AM »
Quote
I tried it out and its not working for me

Please read step 6 of my signature.
8 steps need when ask question -

- PHP version (ACP - > phpinfo())
- mySQL version (ACP - > phpinfo())
- 4images version
- Post screenshot / URL
- Post code in BB Code (no need full file for code) or post attach file
- It doesn't work. What is say - what is do for no work
- Install MOD ? If so - please say (troubleshooting)
- Read FAQ ? Install Bug fixes ?

Offline son_gokou

  • Full Member
  • ***
  • Posts: 199
    • View Profile
Re: Auto generate keywords if keywords field left emty by users
« Reply #14 on: January 08, 2008, 11:52:19 PM »
This isn´t working for me on all images...