4images Forum & Community
4images Modifications / Modifikationen => Mods & Plugins (Requests & Discussions) => Topic started 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:
<?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
-
Can you please explain it a little bit, where to place this file and how to use it??
Thanks for your hard work :)
-
Further expand this MOD for additional image fields (all extra images fields):
$site_db = new Db($db_host, $db_user, $db_password, $db_name) OR die("Keine Verbindung zum Datenbankserver.");
below add:
$additional_sql = "";
if (!empty($additional_image_fields)) {
foreach ($additional_image_fields as $key => $val) {
$additional_sql .= ", ".$key;
}
}
$sql = "SELECT image_id, image_name, image_description, image_keywords, image_media_file
FROM ".IMAGES_TABLE."
WHERE image_keywords=''";
replace by:
$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:
$result = mysql_query($sql) OR die("Fehler beim Schreiben in Tabelle.");
for:
$result = $site_db->query($sql) OR die("Fehler beim Schreiben in Tabelle.");
-
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
-
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
-
$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:
$num_rows = $site_db->get_numrows($result);
if ($num_rows > 0) {
Then,
$result = $site_db->query($sql) OR die("Fehler beim Schreiben in Tabelle.");
}
below add:
}
-
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)
-
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 :)
-
But script skipped some categories while adding keywords in bulk.
It skips because cats are not selected from this MOD. Only images are.
-
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 :)
-
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
-
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
$image_media_file = $row['image_media_file'];
und fügt direkt darunter ein
$image_media_file = str_replace("_", " " ,$image_media_file);
Bis bald
Egoplawi
-
This doesnt work on 1.7.1 or doest it? I tried it out and its not working for me :(
-
I tried it out and its not working for me
Please read step 6 of my signature.
-
This isn´t working for me on all images...
-
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
Bild ID: 794
Bildname: 01. Michelle's Theme
Beschreibung:
Keywords: 01. Michelle's Theme
Filename: 01._Michelles_Theme.mp3
Fehler beim Schreiben in Tabelle.
-
Hello :)
I have a error :
An unexpected error occured. Please try again later.
Fehler beim Schreiben in Tabelle.
Thanks :)
-
thanks for this wonderful mod :)
:( :( :( :( :(
error there
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
-
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.
-
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)
-
I am seeing blank page, I am using 4images v1.7.6
I have changed my path but no use
Any help, appreciated
Regards
-
Hello,
I have a problem with this script, where a _ or, in the title or description, the script does not work
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 ?
-
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.
-
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?
-
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
-
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.
-
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:
<?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);
?>
-
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
-
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
-
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
-
Aber gerne doch :wink:
-
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. :)