4images Forum & Community

4images Modifications / Modifikationen => Mods & Plugins (Requests & Discussions) => Topic started by: egoplawi on July 19, 2007, 08:54:08 PM

Title: Auto generate keywords if keywords field left emty by users
Post by: egoplawi on July 19, 2007, 08:54:08 PM
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
Title: Re: Auto generate keywords if keywords field left emty by users
Post by: Jacob 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  :)
Title: Re: Auto generate keywords if keywords field left emty by users
Post by: thunderstrike 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.");
Title: Re: Auto generate keywords if keywords field left emty by users
Post by: egoplawi 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
Title: Re: Auto generate keywords if keywords field left emty by users
Post by: Jacob 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
Title: Re: Auto generate keywords if keywords field left emty by users
Post by: thunderstrike 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
}
Title: Re: Auto generate keywords if keywords field left emty by users
Post by: Jacob 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 (https://addons.mozilla.org/en-US/firefox/addon/115)
Title: Re: Auto generate keywords if keywords field left emty by users
Post by: Jacob 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 :)
Title: Re: Auto generate keywords if keywords field left emty by users
Post by: thunderstrike 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.
Title: Re: Auto generate keywords if keywords field left emty by users
Post by: Jacob 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 :)
Title: Re: Auto generate keywords if keywords field left emty by users
Post by: egoplawi 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
Title: Re: Auto generate keywords if keywords field left emty by users
Post by: egoplawi 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
Title: Re: Auto generate keywords if keywords field left emty by users
Post by: navyseal 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 :(
Title: Re: Auto generate keywords if keywords field left emty by users
Post by: thunderstrike 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.
Title: Re: Auto generate keywords if keywords field left emty by users
Post by: son_gokou on January 08, 2008, 11:52:19 PM
This isn´t working for me on all images...
Title: Re: Auto generate keywords if keywords field left emty by users
Post by: navyseal on April 03, 2008, 05:16:36 PM
sorry..it justsnt wanst parsing due to server issues...coming back to the issue

when I execute this script all I get is

"Fehler beim Schreiben in Tabelle."
This is after displaying one file ID...output is something like this

Quote
Bild ID: 794
Bildname: 01. Michelle's Theme
Beschreibung:
Keywords: 01. Michelle's Theme
Filename: 01._Michelles_Theme.mp3

Fehler beim Schreiben in Tabelle.
Title: Re: Auto generate keywords if keywords field left emty by users
Post by: satine88 on April 28, 2008, 04:07:00 PM
Hello :)

I have a error :


Quote
An unexpected error occured. Please try again later.
Fehler beim Schreiben in Tabelle.

Thanks :)
Title: Re: Auto generate keywords if keywords field left emty by users
Post by: KamelN on May 01, 2008, 12:18:45 AM


thanks for this wonderful mod  :)

 :( :( :( :( :(
error there



Quote
Warning: include(./gallery/config.php) [function.include]: failed to open stream: No such file or directory in /home/*****/public_html/*******/autokeywords.php on line 7

Warning: include() [function.include]: Failed opening './gallery/config.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/*****/public_html/*****/autokeywords.php on line 7

Warning: include(./gallery/includes/db_mysql.php) [function.include]: failed to open stream: No such file or directory in /home/*****/public_html/*****/autokeywords.php on line 8

Warning: include() [function.include]: Failed opening './gallery/includes/db_mysql.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/*****/public_html/********/autokeywords.php on line 8

Warning: include(./gallery/includes/constants.php) [function.include]: failed to open stream: No such file or directory in /home/******/public_html/*******/autokeywords.php on line 9

Warning: include() [function.include]: Failed opening './gallery/includes/constants.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/**********/public_html/***********/autokeywords.php on line 9

Fatal error: Class 'Db' not found in /home/********/public_html/*******/autokeywords.php on line 11
Title: Re: Auto generate keywords if keywords field left emty by users
Post by: navyseal on May 21, 2008, 06:01:26 AM
well having an apostrophe in the image name will cause an error. This is for my problem though...the script is working fine after removing all apostrophes.
Title: Re: Auto generate keywords if keywords field left emty by users
Post by: SunnyUK on May 30, 2008, 04:55:24 PM
Thank you for this script. It's very close to what I was looking for, but not exactly. Maybe someone can explain to me how I can make it suit my purposes completely?

1) instead of generating the keywords from all sorts of fields, I would like to generate them from the ITPC keywords (the intention is that if people have already tagged their photos, these tags should become 4images keywords) - and only from the ITPC keywords.

2) instead of having a script that runs on request, I would like it integrated in the upload process so it does its magic each and every time somebody uploads a new image.

Is this possible? Any hints about how to go about it would be greatly appreciated.

(I'm using 4images 1.7.6 and am not a php programmer)
Title: Re: Auto generate keywords if keywords field left emty by users
Post by: lona_jasty on January 08, 2009, 02:29:34 PM
I am seeing blank page, I am using 4images v1.7.6
I have changed my path but no use

Any help, appreciated

Regards
Title: Re: Auto generate keywords if keywords field left emty by users
Post by: satine88 on December 24, 2009, 12:15:14 AM
Hello,

I have a problem with this script, where a _ or, in the title or description, the script does not work

Code: [Select]
ID: 7727
Nom de l image : Buzzards' Roost, Fall Creek Falls State Park, Tennessee
Description :
Mots cles: Buzzards' Roost, Fall Creek Falls State Park, Tennessee
Nom du fichier: Buzzards_Roost_Fall_Creek_Falls_State_Park_Tennessee.jpg


An unexpected error occured. Please try again later.
Fehler beim Schreiben in Tabelle.

Can you help-me ?
Title: Re: Auto generate keywords if keywords field left emty by users
Post by: V@no on December 24, 2009, 02:12:59 AM
How exactly doesn't work?
just in case you didn't know, 4images uses space to separate keywords and does not support sentences as one keyword.
Title: Re: Auto generate keywords if keywords field left emty by users
Post by: satine88 on December 24, 2009, 12:09:13 PM
The error here is this:
http://www.fond-ecran-gratuit.biz/autokeywords.php

In fact, I do not know, is that there is a way for those _ be automatically replaced by spaces?
Title: Re: Auto generate keywords if keywords field left emty by users
Post by: alsunna on March 10, 2010, 12:12:48 AM
So how do I use this script?
I added the file with the updates, but how do I use it?


And I keep getting an error, after I added those changes by thunderstrike..

Parse error: syntax error, unexpected '}' in */*/public_html/gallery/autokeywords.php on line 34
Title: Re: Auto generate keywords if keywords field left emty by users
Post by: zhono on November 08, 2010, 03:33:10 AM
I changed the root path, uploaded, and ran it. The first time I ran it, it did some images, from maybe 2 categories. But after that, when I click it to do more, all I get is a blank page.
Title: Re: Auto generate keywords if keywords field left emty by users
Post by: zhono on November 14, 2010, 01:11:06 AM
Well, i edited it a bit, and it works. But now I'm trying to pull the category name of each image, and insert that as the keyword, instead of the image name. I got it to the point where it worked, but only for 1 image at a time. I have over 200,000 images, so that just won't work.

Here's what I'm using:

Code: [Select]
<?php



define
('ROOT_PATH''/home/*********/public_html/');

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, cat_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)){
  
$image_id $row['image_id'];
  
$cat_id $row['cat_id'];
  
$image_name $row['image_name'];
  
$image_description $row['image_description'];
  
$image_keywords $row['image_keywords'];
  
$image_media_file $row['image_media_file'];

  
  
$sql2 "SELECT cat_id, cat_name 
        FROM "
.CATEGORIES_TABLE.
        WHERE cat_id = 
$cat_id";

$result2 $site_db->query($sql2);

while (
$row $site_db->fetch_array($result2)){
  
$new_keywords $row['cat_name'];
}
  echo 
"Image ID: ".$image_id."<br>\n";
  echo 
"Image Name: ".$image_name."<br>\n";
  echo 
"Description: ".$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); 

?>
Title: Re: Auto generate keywords if keywords field left emty by users
Post by: Jan-Lukas on May 26, 2011, 11:03:40 PM
ist es möglich dies ein wenig an die neue Version anzupassen, am besten im Admin, und auswählbar ob mit oder ohne Beschreibung (mir reicht der Bildname  :wink:)
Und wenn es geht, die alten Keywörter belassen, nur ergänzen.
habe es mal in einer Testversion ausprobiert, läuft kurz an (so ca. 50 Bilder) danach wird es abgebrochen (Fehler beim Schreiben in Tabelle.)

LG
Title: Re: Auto generate keywords if keywords field left emty by users
Post by: Jan-Lukas on June 02, 2011, 07:52:40 PM
Habe raus gefunden warum das Programm stehen bleibt, und zwar wenn der Bildname ein `drin hat, wird es nicht unter Keywords gespeichert.
z.B. Let`s go

Kann man das in diesem Script ändern? denn unter Bildname wird es ja auch gespeichert.

LG
Title: Re: Auto generate keywords if keywords field left emty by users
Post by: Rembrandt on June 04, 2011, 05:44:49 PM
Hi!

ist es möglich dies ein wenig an die neue Version anzupassen, am besten im Admin, und auswählbar ob mit oder ohne Beschreibung (mir reicht der Bildname  :wink:)
Und wenn es geht, die alten Keywörter belassen, nur ergänzen......

ich habe eine neue Version gemacht, schau es dir mal an:
http://www.4homepages.de/forum/index.php?topic=29651.msg157630#msg157630

mfg Andi

Title: Re: Auto generate keywords if keywords field left emty by users
Post by: Jan-Lukas on June 04, 2011, 10:08:21 PM
Aber gerne doch  :wink:
Title: Re: Auto generate keywords if keywords field left emty by users
Post by: Rembrandt on September 05, 2011, 07:27:21 AM
Habe raus gefunden warum das Programm stehen bleibt, und zwar wenn der Bildname ein `drin hat, wird es nicht unter Keywords gespeichert.
z.B. Let`s go

Kann man das in diesem Script ändern? denn unter Bildname wird es ja auch gespeichert.

LG
ist zwar schon etwas länger her,aber versuche mal das:
http://www.4homepages.de/forum/index.php?topic=29950.msg158671#msg158671

mfg Andi

P.S: @Jan-Lukas , zu dem anderen (PM) bin ich noch nicht gekommen, aber ich habe schon mal eine idee das um zusetzen. :)