• [Mod] Random image / Zufallsbild 5 0 5 1
Currently:  

Author Topic: [Mod] Random image / Zufallsbild  (Read 874485 times)

0 Members and 1 Guest are viewing this topic.

Offline sorestar

  • Newbie
  • *
  • Posts: 17
    • View Profile
Re: [Mod] Random image / Zufallsbild
« Reply #150 on: January 16, 2003, 04:35:40 AM »
Quote
define('PIC_CATEGORIES_TABLE', '4images_categories');
define('PIC_IMAGES_TABLE', '4images_images');



which file is it under?

can you post the completed script here, please?
 :)
[/quote]

Offline SLL

  • Hero Member
  • *****
  • Posts: 585
    • View Profile
Re: [Mod] Random image / Zufallsbild
« Reply #151 on: January 16, 2003, 11:54:56 AM »
Quote from: sorestar
can you post the completed script here, please?


OK, to make our life easier, below are three scripts running on the homepage of my site:

    - one to show random image from 4images gallery;
    - one to fetch last few topics from phpBB board;
    - one to fetch some stats from phpBB board;
    [/list:u]
The code is not mine! I just modified it a bit and have managed scripts to work on the same page.

Save this one as random.php
Code: [Select]
<?php
define
&#40;'ROOT_PATH', './4images/'&#41;;
define&#40;'SITE_URL', 'http&#58;//faces.dalnet.ru/'&#41;;

include_once&#40;ROOT_PATH.'config.php'&#41;;
include_once&#40;ROOT_PATH.'includes/db_mysql.php'&#41;;

define&#40;'PIC_CATEGORIES_TABLE', '4images_categories'&#41;;
define&#40;'PIC_IMAGES_TABLE', '4images_images'&#41;;
define&#40;'THUMB_DIR', 'data/thumbnails'&#41;;
define&#40;'AUTH_ALL', 0&#41;;
define&#40;'AUTH_USER', 2&#41;;
define&#40;'AUTH_ACL', 3&#41;;
define&#40;'AUTH_ADMIN', 9&#41;;

$pics_db = new Db&#40;$db_host, $db_user, $db_password, $db_name&#41;;

function is_remote&#40;$file_name&#41; &#123;
  
return &#40;preg_match&#40;'#^https?\\&#58;\\/\\/[a-z0-9\-&#93;+\.&#40;[a-z0-9\-&#93;+\.&#41;?[a-z&#93;+#i', $file_name&#41;&#41; ? 1 &#58; 0;
&#125;

$sql "SELECT COUNT&#40;*&#41; as total_images FROM ".PIC_IMAGES_TABLE." a, ".PIC_CATEGORIES_TABLE." b WHERE a.image_active=1 AND a.cat_id = b.cat_id AND b.auth_viewcat=".AUTH_ALL." AND b.auth_viewimage=".AUTH_ALL."";
$row $pics_db->query_firstrow&#40;$sql&#41;;
$total_images $row['total_images'&#93;;

mt_srand&#40;&#40;double&#41;microtime&#40;&#41; * 1000000&#41;;
$number = &#40;$total_images > 1&#41; ? mt_rand&#40;0, $total_images - 1&#41; &#58; 0;

$sql "SELECT a.image_id, a.cat_id, a.image_name, a.image_active, a.image_thumb_file, a.image_comments FROM ".PIC_IMAGES_TABLE." a, ".PIC_CATEGORIES_TABLE." b WHERE a.image_active=1 AND a.cat_id = b.cat_id AND b.auth_viewcat=".AUTH_ALL." AND b.auth_viewimage=".AUTH_ALL." LIMIT $number, 1";
$row $pics_db->query_firstrow&#40;$sql&#41;;
$image_id $row['image_id'&#93;;
$cat_id $row['cat_id'&#93;;
$image_name $row['image_name'&#93;;
$image_comments $row['image_comments'&#93;;
$thumb_src = &#40;is_remote&#40;$row['image_thumb_file'&#93;&#41;&#41; ? $row['image_thumb_file'&#93; &#58; ROOT_PATH.THUMB_DIR."/".$cat_id."/".$row['image_thumb_file'&#93;;

echo "<a href=\"".SITE_URL."details.php?image_id=$image_id\"><img src=\"".$thumb_src."\" border=\"0\" vspace=\"2\" alt=\"$image_name\"></a><br>\n";
echo 
"<b><div class=\"ltgreytext\">$image_name</b></div>\n";
echo 
"&raquo; <a target=\"a\" href=\"".SITE_URL."\">âñåãî â àëüáîìå <b>$total_images</b> ôîòî</a><br>\n";
?>


Save this one as recent.php
Code: [Select]
<?php
define
&#40;'IN_PHPBB', true&#41;;

$limit "7"// how many topics to fetch?

$phpbb_root_path "./phpBB2/";
$phpbb_main_url "http&#58;//forum.dalnet.ru/";
include_once&
#40;$phpbb_root_path . 'extension.inc'&#41;;
include_once&#40;$phpbb_root_path . 'common.'.$phpEx&#41;;

$recent_sql "SELECT topic_id,topic_title,topic_last_post_id,forum_id FROM " TOPICS_TABLE " WHERE forum_id !='3' AND forum_id <'8' ORDER BY topic_last_post_id DESC LIMIT $limit";
$recent $db->sql_query&#40;$recent_sql&#41;;

echo "<table cellspacing=0 cellpadding=1 width=\"100%\">";

while &
#40;$line = mysql_fetch_array&#40;$recent&#41;&#41; &#123;
$security=FALSE;
if&
#40;$forum_auth == 2 && $userdata['user_level'&#93; == ADMIN&#41; &#123;
$security=TRUE;
&
#125;
if&#40;$forum_auth == 3 && &#40;$userdata['user_level'&#93; == ADMIN&#41; || &#40;$userdata['user_level'&#93; == 2&#41;&#41; &#123;
$security=TRUE;
&
#125;
if&#40;$forum_auth == 0&#41; &#123;
$security=TRUE;
&
#125;
if&#40;$security == TRUE&#41;
&#123;
  
$lastpost_array=$db->sql_query&#40;"SELECT post_time FROM " . POSTS_TABLE . " WHERE post_id =" . $line['topic_last_post_id'&#93;&#41;;
  
$lastpost=mysql_fetch_array&#40;$lastpost_array&#41;;
  
$lastpost=$lastpost['post_time'&#93;;
  
$lastpost=create_date&#40;"d M - H&#58;m", $lastpost, $board_config['board_timezone'&#93;&#41;;

  
$j stripslashes&#40;$line['topic_title'&#93;&#41;;
  
$k substr&#40;$j, 0, 35&#41; . "...";

  
echo "<tr><td class=\"menutext\" align=\"left\">&raquo; <a target=\"f\" href=\"$phpbb_main_url"viewtopic.php?t=" $line['topic_id'&#93; . "\" class=\"menutext\">" . $k . "</a></td>";
  
echo "<td class=\"ltgreytext\" align=\"right\">$lastpost</td></tr>";

&
#125;&#125;;
echo "</table>";
?>


Save this one as phpbb_fetch_info.php
Code: [Select]
<?php
$phpbb_root_path 
'./phpBB2/';
define &#40;'IN_PHPBB', true&#41;;

include&#40;$phpbb_root_path . 'extension.inc'&#41;;
include_once&#40;$phpbb_root_path.'config.'.$phpEx&#41;;
include_once&#40;$phpbb_root_path.'includes/db.'.$phpEx&#41;;
include_once&#40;$phpbb_root_path.'includes/constants.'.$phpEx&#41;;

function phpbb_fetch_stats&#40;&#41;
&#123;
    
global $db;

    
$result = array&#40;&#41;;
    
$result['total_posts'&#93; = get_db_stat&#40;'postcount'&#41;;
    
$result['total_users'&#93; = get_db_stat&#40;'usercount'&#41;;
    
$newest_user           get_db_stat&#40;'newestuser'&#41;;
    
$result['user_id'&#93;     = $newest_user['user_id'&#93;;
    
$result['username'&#93;    = $newest_user['username'&#93;;

    
$sql 'SELECT session_id FROM ' SESSIONS_TABLE ' WHERE session_time >= ' . &#40;time&#40;&#41; - 300&#41;;
$query $db->sql_query&#40;$sql&#41;;
$user_online $db->sql_fetchrow&#40;$query&#41;;

$result['user_online'&#93; = count&#40;$user_online&#41;;
echo "$table_prefix\n<br>";

    return 
$result;
&
#125;
?>


Then open your index.php and insert the following tags into the proper places:
Code: [Select]
<?php
include&#40;'phpbb_fetch_info.php'&#41;;
$stats phpbb_fetch_stats&#40;&#41;;
echo 'Total posts&#58; ' $stats['total_posts'&#93; . ', total users&#58; ' . $stats['total_users'&#93; . ', now online&#58; ' . $stats['user_online'&#93; . ', last registered&#58; ' . $stats['username'&#93;;
?>


<?php include&#40;"recent.php"&#41;; ?>
<?php include&#40;"random.php"&#41;; ?>


Demo: http://www.dalnet.ru/home.php

Offline sorestar

  • Newbie
  • *
  • Posts: 17
    • View Profile
Re: [Mod] Random image / Zufallsbild
« Reply #152 on: January 18, 2003, 12:11:27 AM »
wow  8)  is is working fantastic!!!!

ABOUT RANDOM.PHP....Can you show me how to set, so that it only randomize certain categories?


Thanks SLL

Offline SLL

  • Hero Member
  • *****
  • Posts: 585
    • View Profile
Re: [Mod] Random image / Zufallsbild
« Reply #153 on: January 18, 2003, 11:00:48 AM »
Quote from: sorestar
Can you show me how to set, so that it only randomize certain categories?

Try to play with this query:
Code: [Select]
$sql = "SELECT COUNT(*) as total_images FROM ".PIC_IMAGES_TABLE." a, ".PIC_CATEGORIES_TABLE." b WHERE a.image_active=1 AND a.cat_id = b.cat_id AND b.auth_viewcat=".AUTH_ALL." AND b.auth_viewimage=".AUTH_ALL."";

... adding something like AND b.cat_id !='2' AND b.cat_id <'4'

Offline sorestar

  • Newbie
  • *
  • Posts: 17
    • View Profile
Re: [Mod] Random image / Zufallsbild
« Reply #154 on: January 18, 2003, 08:59:23 PM »
Thanks SSL

 8) U R DA MAN 8)

Offline tradertt

  • Jr. Member
  • **
  • Posts: 61
    • View Profile
Re: [Mod] Random image / Zufallsbild
« Reply #155 on: January 23, 2003, 06:29:19 PM »
How can I post multiple THUMBNAILS in 1 page?

<?php
include("./random.php");
?>

I tried doing it in 2 tables .. but


Fatal error: Cannot redeclare class db in /home/ahahchen/public_html/tradertt/4images/includes/db_mysql.php on line 28


What can I do then?

Offline tradertt

  • Jr. Member
  • **
  • Posts: 61
    • View Profile
Re: [Mod] Random image / Zufallsbild
« Reply #156 on: January 23, 2003, 06:37:47 PM »
I want to put 2 different random thumbnails in 1 webpage ... but I keep getting that error cause they are querying the same database.. how can I overcome it?

Offline tradertt

  • Jr. Member
  • **
  • Posts: 61
    • View Profile
Re: [Mod] Random image / Zufallsbild
« Reply #157 on: January 23, 2003, 06:49:08 PM »
Even if I use 1 table ... I keep getting just a CROSS and not a picture and the link to it is


http://www.tipscheck.com/tradertt/4images/details.php?image_id=


WHy is there no image_id    number behind ?

Offline tradertt

  • Jr. Member
  • **
  • Posts: 61
    • View Profile
Re: [Mod] Random image / Zufallsbild
« Reply #158 on: January 23, 2003, 06:59:12 PM »
Quote from: tradertt
Even if I use 1 table ... I keep getting just a CROSS and not a picture and the link to it is


http://www.tipscheck.com/tradertt/4images/details.php?image_id=


WHy is there no image_id    number behind ?



THis happens when I keep refreshing the page ... I am using a FULL IMAGE random_full.php and if I chg my

AND a.cat_id = 3

the problem occurs

But when I chg it back to

AND a.cat_id = b.cat_id

it does not have this problem .. HELP !!

Offline irocracer

  • Newbie
  • *
  • Posts: 25
    • View Profile
Re: [Mod] Random image / Zufallsbild
« Reply #159 on: January 24, 2003, 05:52:48 AM »
any luck yet on having it work when you have IBF mod in 4images ?

Offline STCD

  • Pre-Newbie
  • Posts: 3
    • View Profile
Re: [Mod] Random image / Zufallsbild
« Reply #160 on: February 01, 2003, 11:26:18 PM »
Quote from: SLL
Quote from: sorestar
can you post the completed script here, please?


OK, to make our life easier, below are three scripts running on the homepage of my site:

    - one to show random image from 4images gallery;
    - one to fetch last few topics from phpBB board;
    - one to fetch some stats from phpBB board;
    [/list:u]
The code is not mine! I just modified it a bit and have managed scripts to work on the same page.

Save this one as random.php
Code: [Select]
<?php
define
&#40;'ROOT_PATH', './4images/'&#41;;
define&#40;'SITE_URL', 'http&#58;//faces.dalnet.ru/'&#41;;

include_once&#40;ROOT_PATH.'config.php'&#41;;
include_once&#40;ROOT_PATH.'includes/db_mysql.php'&#41;;

define&#40;'PIC_CATEGORIES_TABLE', '4images_categories'&#41;;
define&#40;'PIC_IMAGES_TABLE', '4images_images'&#41;;
define&#40;'THUMB_DIR', 'data/thumbnails'&#41;;
define&#40;'AUTH_ALL', 0&#41;;
define&#40;'AUTH_USER', 2&#41;;
define&#40;'AUTH_ACL', 3&#41;;
define&#40;'AUTH_ADMIN', 9&#41;;

$pics_db = new Db&#40;$db_host, $db_user, $db_password, $db_name&#41;;

function is_remote&#40;$file_name&#41; &#123;
  
return &#40;preg_match&#40;'#^https?\\&#58;\\/\\/[a-z0-9\-&#93;+\.&#40;[a-z0-9\-&#93;+\.&#41;?[a-z&#93;+#i', $file_name&#41;&#41; ? 1 &#58; 0;
&#125;

$sql "SELECT COUNT&#40;*&#41; as total_images FROM ".PIC_IMAGES_TABLE." a, ".PIC_CATEGORIES_TABLE." b WHERE a.image_active=1 AND a.cat_id = b.cat_id AND b.auth_viewcat=".AUTH_ALL." AND b.auth_viewimage=".AUTH_ALL."";
$row $pics_db->query_firstrow&#40;$sql&#41;;
$total_images $row['total_images'&#93;;

mt_srand&#40;&#40;double&#41;microtime&#40;&#41; * 1000000&#41;;
$number = &#40;$total_images > 1&#41; ? mt_rand&#40;0, $total_images - 1&#41; &#58; 0;

$sql "SELECT a.image_id, a.cat_id, a.image_name, a.image_active, a.image_thumb_file, a.image_comments FROM ".PIC_IMAGES_TABLE." a, ".PIC_CATEGORIES_TABLE." b WHERE a.image_active=1 AND a.cat_id = b.cat_id AND b.auth_viewcat=".AUTH_ALL." AND b.auth_viewimage=".AUTH_ALL." LIMIT $number, 1";
$row $pics_db->query_firstrow&#40;$sql&#41;;
$image_id $row['image_id'&#93;;
$cat_id $row['cat_id'&#93;;
$image_name $row['image_name'&#93;;
$image_comments $row['image_comments'&#93;;
$thumb_src = &#40;is_remote&#40;$row['image_thumb_file'&#93;&#41;&#41; ? $row['image_thumb_file'&#93; &#58; ROOT_PATH.THUMB_DIR."/".$cat_id."/".$row['image_thumb_file'&#93;;

echo "<a href=\"".SITE_URL."details.php?image_id=$image_id\"><img src=\"".$thumb_src."\" border=\"0\" vspace=\"2\" alt=\"$image_name\"></a><br>\n";
echo 
"<b><div class=\"ltgreytext\">$image_name</b></div>\n";
echo 
"&raquo; <a target=\"a\" href=\"".SITE_URL."\">âñåãî â àëüáîìå <b>$total_images</b> ôîòî</a><br>\n";
?>


Save this one as recent.php
Code: [Select]
<?php
define
&#40;'IN_PHPBB', true&#41;;

$limit "7"// how many topics to fetch?

$phpbb_root_path "./phpBB2/";
$phpbb_main_url "http&#58;//forum.dalnet.ru/";
include_once&
#40;$phpbb_root_path . 'extension.inc'&#41;;
include_once&#40;$phpbb_root_path . 'common.'.$phpEx&#41;;

$recent_sql "SELECT topic_id,topic_title,topic_last_post_id,forum_id FROM " TOPICS_TABLE " WHERE forum_id !='3' AND forum_id <'8' ORDER BY topic_last_post_id DESC LIMIT $limit";
$recent $db->sql_query&#40;$recent_sql&#41;;

echo "<table cellspacing=0 cellpadding=1 width=\"100%\">";

while &
#40;$line = mysql_fetch_array&#40;$recent&#41;&#41; &#123;
$security=FALSE;
if&
#40;$forum_auth == 2 && $userdata['user_level'&#93; == ADMIN&#41; &#123;
$security=TRUE;
&
#125;
if&#40;$forum_auth == 3 && &#40;$userdata['user_level'&#93; == ADMIN&#41; || &#40;$userdata['user_level'&#93; == 2&#41;&#41; &#123;
$security=TRUE;
&
#125;
if&#40;$forum_auth == 0&#41; &#123;
$security=TRUE;
&
#125;
if&#40;$security == TRUE&#41;
&#123;
  
$lastpost_array=$db->sql_query&#40;"SELECT post_time FROM " . POSTS_TABLE . " WHERE post_id =" . $line['topic_last_post_id'&#93;&#41;;
  
$lastpost=mysql_fetch_array&#40;$lastpost_array&#41;;
  
$lastpost=$lastpost['post_time'&#93;;
  
$lastpost=create_date&#40;"d M - H&#58;m", $lastpost, $board_config['board_timezone'&#93;&#41;;

  
$j stripslashes&#40;$line['topic_title'&#93;&#41;;
  
$k substr&#40;$j, 0, 35&#41; . "...";

  
echo "<tr><td class=\"menutext\" align=\"left\">&raquo; <a target=\"f\" href=\"$phpbb_main_url"viewtopic.php?t=" $line['topic_id'&#93; . "\" class=\"menutext\">" . $k . "</a></td>";
  
echo "<td class=\"ltgreytext\" align=\"right\">$lastpost</td></tr>";

&
#125;&#125;;
echo "</table>";
?>


Save this one as phpbb_fetch_info.php
Code: [Select]
<?php
$phpbb_root_path 
'./phpBB2/';
define &#40;'IN_PHPBB', true&#41;;

include&#40;$phpbb_root_path . 'extension.inc'&#41;;
include_once&#40;$phpbb_root_path.'config.'.$phpEx&#41;;
include_once&#40;$phpbb_root_path.'includes/db.'.$phpEx&#41;;
include_once&#40;$phpbb_root_path.'includes/constants.'.$phpEx&#41;;

function phpbb_fetch_stats&#40;&#41;
&#123;
    
global $db;

    
$result = array&#40;&#41;;
    
$result['total_posts'&#93; = get_db_stat&#40;'postcount'&#41;;
    
$result['total_users'&#93; = get_db_stat&#40;'usercount'&#41;;
    
$newest_user           get_db_stat&#40;'newestuser'&#41;;
    
$result['user_id'&#93;     = $newest_user['user_id'&#93;;
    
$result['username'&#93;    = $newest_user['username'&#93;;

    
$sql 'SELECT session_id FROM ' SESSIONS_TABLE ' WHERE session_time >= ' . &#40;time&#40;&#41; - 300&#41;;
$query $db->sql_query&#40;$sql&#41;;
$user_online $db->sql_fetchrow&#40;$query&#41;;

$result['user_online'&#93; = count&#40;$user_online&#41;;
echo "$table_prefix\n<br>";

    return 
$result;
&
#125;
?>


Then open your index.php and insert the following tags into the proper places:
Code: [Select]
<?php
include&#40;'phpbb_fetch_info.php'&#41;;
$stats phpbb_fetch_stats&#40;&#41;;
echo 'Total posts&#58; ' $stats['total_posts'&#93; . ', total users&#58; ' . $stats['total_users'&#93; . ', now online&#58; ' . $stats['user_online'&#93; . ', last registered&#58; ' . $stats['username'&#93;;
?>


<?php include&#40;"recent.php"&#41;; ?>
<?php include&#40;"random.php"&#41;; ?>


Demo: http://www.dalnet.ru/home.php


i am getting this error:
Fatal error: Cannot instantiate non-existent class: db in random.php on line 16
(i am only using the random image script)
HELP ME PLEEEASE! :cry:

Offline camo93

  • Newbie
  • *
  • Posts: 24
    • View Profile
    • http://central-galerie.com
Re: [Mod] Random image / Zufallsbild
« Reply #161 on: February 06, 2003, 12:13:38 PM »
Hi,

Good mod, he work 2 days and now it don't work :-(
he don't to find the image_id=

This is the javascript version : http://central-galerie.com/4images/random.php

a problem with my database ?

Quote from: Nicky
hi an alle, hi all,

D: hier ist der Zufallsbild MOD für extra seiten ausserhalb ihrer Gallerie:
E: here the Random image MOD for extra sites outside your Gallery:

http://www.nicky.net/4images/random.txt

D: speichere den inhalt als random.php
E: save the content as random.php

D: random.php wurde mit folgenden befehl in die random_mod.php inkludiert
E: random.php was included into the random_mod.php site

D: mit
E: with
Code: [Select]

<?php
 
include&#40;"./random.php"&#41;;
?>



D: viel spass
E: have fun

p.s.:
D: vielen dank an JAN der 99% der arbeit geleistet hat ;)
E: many thanks to JAN who maked 99% of this mod ;)

Offline rweoli

  • Pre-Newbie
  • Posts: 2
    • View Profile
Re: [Mod] Random image / Zufallsbild
« Reply #162 on: February 10, 2003, 01:39:04 PM »
Hallo,

ich bekomme beim Versuch das so einzubinden eine Fehlermeldung:

Quote
Warning: Failed opening './4images/config.php' for inclusion (include_path='.:/usr/share/php') in /var/home/rot-weiss-erfurt.com/www/pix/random.php on line 30

Warning: Failed opening './4images/includes/db_mysql.php' for inclusion (include_path='.:/usr/share/php') in /var/home/rot-weiss-erfurt.com/www/pix/random.php on line 31

Warning: Failed opening './4images/includes/constants.php' for inclusion (include_path='.:/usr/share/php') in /var/home/rot-weiss-erfurt.com/www/pix/random.php on line 32

Fatal error: Cannot instantiate non-existent class: db in /var/home/rot-weiss-erfurt.com/www/pix/random.php on line 34


Ich hoffe ich habe alles richitg verstanden, hier deshalb meine Vorgehensweise:

1. random.txt von oben als random.php in 4images Verzeichniss
2. Den Code von oben

Code: [Select]
<?php 
include&#40;"./random.php"&#41;; 
?>


in meine Seite eingefügt. Als das nicht funktionierte, habe ich die Pfadangabe von ./random.php zu http://www.meinedomain.com/ornder/random.php geändert.

Da nix ging poste ich nun hier... ;)

Gruß

Offline Maweryk

  • Sr. Member
  • ****
  • Posts: 253
    • View Profile
Re: [Mod] Random image / Zufallsbild
« Reply #163 on: February 12, 2003, 01:31:09 AM »
Erst einmal vielen Dank für diesen genialen Mod.

Die Thumbnails werden perfekt auf meiner anderen Website angezeigt.
Es gibt da allerdings noch ein kleines Problem.
Liegt das Thumbnail nicht auf dem 4images-Server, da es von einem User per URL hinzugefügt wurde, wird das Bild natürlich nicht angezeigt. Kann man da evtl. noch eine Abfrage einfügen, die den Ort der thumbnail-Datei bestimmt oder den Code so ändern, dass nur thumbnails angezeigt werden, die auf dem 4images-Server liegen???

Vielen Dank für Eure Hilfe!

Gruß

Markus

Offline rweoli

  • Pre-Newbie
  • Posts: 2
    • View Profile
Re: [Mod] Random image / Zufallsbild
« Reply #164 on: February 12, 2003, 04:51:08 PM »
Okay, wer hat eine funktionierende random.php für mich. Irgendwie akzeptier er den Pfad nicht, egal was ich tue. Wenn ich als root_path den kompletten Pfad nehme, dann funktioniert zwar das Script, aber das Bild wird nicht angezeigt! Kann ich das irgendwie ändern?

Gruß