Author Topic: [MOD] Most Popular, Most Votes and Most Recent  (Read 19329 times)

0 Members and 1 Guest are viewing this topic.

Offline scubaguy

  • Pre-Newbie
  • Posts: 8
    • View Profile
[MOD] Most Popular, Most Votes and Most Recent
« on: October 21, 2005, 11:35:08 PM »
I am working on a site that needed three seperate modules showing the Most Recent, the Most Popular and Top Votes.

Here is the code for the Most Recent:

Code: [Select]
<?php // PATH to your 4images Gallery / PFAD zu Ihrer 4images Gallerie
define('ROOT_PATH''../');
  global 
$site_db$cat_cache$total_images;


// NUMBER OF THUMBNAILS TO DISPLAY / NUMMER DER GEWÜNSCHTEN THUMBNAILS
$num_images 5;

$sql "SELECT a.image_id, a.cat_id, a.image_name, a.image_date, a.image_active, a.image_thumb_file, a.image_comments
        FROM "
.IMAGES_TABLE." a, ".CATEGORIES_TABLE." b
        WHERE a.image_active=1
        AND a.cat_id = b.cat_id
AND a.cat_id != 23
        AND b.auth_viewcat="
.AUTH_ALL."
        AND b.auth_viewimage="
.AUTH_ALL."
        ORDER BY a.image_date DESC
        LIMIT 
$num_images";
$result $site_db->query($sql);

if (
$result) {
while (
$row $site_db->fetch_array($result)) {
  
$image_id $row['image_id'];
  
$cat_id $row['cat_id'];
  
$image_name $row['image_name'];
  
$image_comments $row['image_comments'];
  
$thumb_src = (is_remote($row['image_thumb_file'])) ? $row['image_thumb_file'] : ROOT_PATH.THUMB_DIR."/".$cat_id."/".$row['image_thumb_file'];

  echo 
"<div style='float:left;width:66px;height:68px;margin:3px;padding-bottom:4px;'><div style='border:2px solid #ffffff;width:64px;height:64px;'><a href=\"".ROOT_PATH."details.php?image_id=$image_id\"><img src=\"".$thumb_src."\" border=\"0\" alt=\"$image_name\" width=\"64\" height=\"64\"></div>\n";
  echo 
ShortenText($image_name)."\n";
echo "</div>\n";
}
}
?>

Here is the code for Most Popular:

Code: [Select]
<?php // PATH to your 4images Gallery / PFAD zu Ihrer 4images Gallerie
define('ROOT_PATH''../');
  global 
$site_db$cat_cache$total_images;

// NUMBER OF THUMBNAILS TO DISPLAY / NUMMER DER GEWÜNSCHTEN THUMBNAILS
$num_images 12;

$sql "SELECT a.image_id, a.cat_id, a.image_name, a.image_hits, a.image_active, a.image_thumb_file, a.image_comments
        FROM "
.IMAGES_TABLE." a, ".CATEGORIES_TABLE." b
        WHERE a.image_active=1
        AND a.cat_id = b.cat_id
AND a.cat_id != '23'
        AND b.auth_viewcat="
.AUTH_ALL."
        AND b.auth_viewimage="
.AUTH_ALL."
        ORDER BY a.image_hits DESC
        LIMIT 
$num_images";
$result $site_db->query($sql);

if (
$result) {
while (
$row $site_db->fetch_array($result)) {
  
$image_id $row['image_id'];
  
$cat_id $row['cat_id'];
  
$image_name $row['image_name'];
  
$image_comments $row['image_comments'];
  
$thumb_src = (is_remote($row['image_thumb_file'])) ? $row['image_thumb_file'] : ROOT_PATH.THUMB_DIR."/".$cat_id."/".$row['image_thumb_file'];

  echo 
"<div style='float:left;width:66px;height:68px;margin:3px;'><div style='border:2px solid #f2f2f2;width:64px;height:64px;'><a href=\"".ROOT_PATH."details.php?image_id=$image_id\" title=\"$image_name\"><img src=\"".$thumb_src."\" border=\"0\" alt=\"$image_name\"  width='64' height='64'><br>\n";
echo "</div></div>\n";
}
}
?>

Here is the code for the Top Votes:

Code: [Select]
<?php // PATH to your 4images Gallery / PFAD zu Ihrer 4images Gallerie
define('ROOT_PATH''../');
  global 
$site_db$cat_cache$total_images;

// NUMBER OF THUMBNAILS TO DISPLAY / NUMMER DER GEWÜNSCHTEN THUMBNAILS
$num_images 8;

$sql "SELECT DISTINCT a.image_id, a.cat_id, a.image_name, a.image_votes, a.image_active, a.image_thumb_file, a.image_comments, a.image_description, a.image_date
        FROM "
.IMAGES_TABLE." a, ".CATEGORIES_TABLE." b
        WHERE a.image_active=1
AND a.cat_id = '23'
        ORDER BY a.image_date DESC
        LIMIT 
$num_images";
$result $site_db->query($sql);
if (
$result) {
while (
$row $site_db->fetch_array($result)) {
  
$image_id $row['image_id'];
  
$cat_id $row['cat_id'];
$image_description $row['image_description'];
  
$image_name $row['image_name'];
  
$image_comments $row['image_comments'];
  
$thumb_src = (is_remote($row['image_thumb_file'])) ? $row['image_thumb_file'] : ROOT_PATH.THUMB_DIR."/".$cat_id."/".$row['image_thumb_file'];

  echo 
"<div style='float:left;width:66px;height:68px;margin:3px;'><div style='border:2px solid #f2f2f2;width:64px;height:64px;'><a href=\"$image_description\" title=\"$image_name\" target=\"_blank\"><img src=\"".$thumb_src."\" border=\"0\" alt=\"$image_name\" width='64' height='64'><br>\n";
echo "</div></div>\n";
}
}
?>

Offline scubaguy

  • Pre-Newbie
  • Posts: 8
    • View Profile
Re: [MOD] Most Popular, Most Votes and Most Recent
« Reply #1 on: October 21, 2005, 11:36:51 PM »
I also need to add a function to shorten the length of the image name in functions.php

Code: [Select]
    function ShortenText($text) {

        // Change to the number of characters you want to display
        $chars = 10;

        $text = $text." ";
        $text = substr($text,0,$chars);
        $text = substr($text,0,strrpos($text,' '));
        $text = $text."";

        return $text;

    }

Offline scubaguy

  • Pre-Newbie
  • Posts: 8
    • View Profile
Re: [MOD] Most Popular, Most Votes and Most Recent
« Reply #2 on: January 12, 2006, 08:11:44 AM »
This code was working, but now that I've tried it with 1.7.1 with the security patches it has stopped working.  Absolutely nothing is displayed, not even error messages.  Does anyone know what might be the problem?

I also noticed that when I try to create SEO urls with $site_sess->url they are no longer being converted.  Did something change that I am not aware of.  It all used to work.   :(

Offline botakedan

  • Pre-Newbie
  • Posts: 3
    • View Profile
Re: [MOD] Most Popular, Most Votes and Most Recent
« Reply #3 on: October 13, 2006, 01:57:20 PM »
i am using 4images 1.7.2
can you teach me where i should put that scripts ???

Offline quartz

  • Newbie
  • *
  • Posts: 18
    • View Profile
Re: [MOD] Most Popular, Most Votes and Most Recent
« Reply #4 on: February 23, 2007, 05:19:49 PM »
change this
Code: [Select]
define('ROOT_PATH', '../');
I replace with this
Code: [Select]
define('ROOT_PATH', './');
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);
function is_remote($file_name) {
  return (preg_match('#^https?\\:\\/\\/[a-z0-9\-]+\.([a-z0-9\-]+\.)?[a-z]+#i', $file_name)) ? 1 : 0;
}

that worked for me

Offline a1367h

  • Pre-Newbie
  • Posts: 5
    • View Profile
Re: [MOD] Most Popular, Most Votes and Most Recent
« Reply #5 on: December 20, 2012, 02:24:22 AM »
Hi.
I'm using 1.7.11 . I want to know where i have to put these code to show in home page.
please help. I need this mod.
Hossein Rad

Offline wallward

  • Jr. Member
  • **
  • Posts: 54
    • View Profile
Re: [MOD] Most Popular, Most Votes and Most Recent
« Reply #6 on: February 18, 2014, 01:50:59 PM »
Where do I put this code?
how to Show result in Home page?  :?:

 

Post your comments here