4images Forum & Community

4images Modifications / Modifikationen => Mods & Plugins (Requests & Discussions) => Topic started by: artmedia on October 28, 2008, 11:30:48 PM

Title: [PRE-MOD] Top Categories by votes, rating and hits
Post by: artmedia on October 28, 2008, 11:30:48 PM
In order to this request: http://www.4homepages.de/forum/index.php?topic=5789.0 I have started this mod, but, this is my first attempt, i need some help, can someone help me:

The first Step would be:

Add in includes/functions.php

this code:

Code: [Select]
// Top Categories
function get_top_categories() {
  global $site_db, $cat_cache, $total_images;
  $categories_top = array();
  $cat_id_sql = get_auth_cat_sql("auth_viewcat", "NOTIN");

  $sql = "SELECT c.cat_name AS NAME, sum( `i.image_votes` ) AS VOTES
  FROM (".IMAGES_TABLE." i,  ".CATEGORIES_TABLE." c)
            WHERE i.image_active = 1 AND i.cat_id NOT IN ($cat_id_sql) AND c.cat_id = i.cat_id
            GROUP BY cat_id
HAVING sum( `i.image_votes` ) > 100 //MINIMAL VOTES FOR THE TOP LIST
ORDER BY VOTES DESC
LIMIT 0 , 15";  // IN THIS CASE FOR MY TOP 15 LIST
   
  $result = $site_db->query($sql);
  while ($row = $site_db->fetch_array($result)) {
     // $categories_top[$row['cat_id']] = $row;
echo $row['NAME']. " - ". $row['VOTES'];
echo "<br />";
  }
  return $categories_top;


Second Step:
(I'm lost here, i don't know how to call a function from other page, for example, how to associate let's say {top_categories} to this function)

Someone knows how?

Thanks
Sorry if i posted this topic in the wrong section, i hope this be finished soon like a real MOD
Title: Re: [PRE-MOD] Top Categories by votes, rating and hits
Post by: V@no on October 29, 2008, 01:39:18 AM
1) I'm not sure how this topic got into the mods publishing forum, its not even near a complete mod, so it moved to requests and discussion forum.
2) since these tops will not be printed on every page, and actually it will have it's own separate page (just like top.php), you don't need anything in the includes/functions.php
3) never use echo or print() in 4images, unless you are "capturing" the output or your code is inside a template (or the code is in ACP).


Sorry, not much of a help for now, maybe someone else?
Title: Re: [PRE-MOD] Top Categories by votes, rating and hits
Post by: artmedia on October 29, 2008, 09:59:04 PM
You are right V@no, I have made it different, maybe later someone can improve it.

Here we go:

STEP #1:
Create a new custom page
http://www.4homepages.de/forum/index.php?topic=4996.0


STEP #2:
On this new page, on content part, add (You must modify "yourdatabasehost","youruser","yourpassword" for your data):

Code: [Select]
//Optional styles
<style type="text/css">
<!--
.top {
width:auto;
padding:10px;
float:left;
margin-right:40px;;
}
.top h2{
line-height:150%;
font-size:16px;
}
-->
</style>                     
                      <?php
                       
function Connect()
                      {
                           if (!(
$link=mysql_connect("yourdatabasehost","youruser","yourpassword")))
                          {
                                  echo 
"Error connecting to database";
                                  exit();
                           }
                           if (!
mysql_select_db("yourdatabasename",$link))
                          {
                                  echo 
"Error selecting database.";
                                  exit();
                           }
                           return 
$link;
                        }
                                          
$link=Connect();
?>



<div class="top"></div>
<div class="top">
<h2>Top 15 - Votes </h2>
<p>
<?php 
  
$sql "SELECT 4images_categories.cat_id AS CAT_ID, sum( `image_votes` ) AS VOTES, 4images_categories.cat_name AS NAME
FROM `4images_images` , `4images_categories`
WHERE 4images_images.cat_id = 4images_categories.cat_id
AND cat_parent_id =125  
GROUP BY 4images_images.cat_id
HAVING sum( `image_votes` ) >100 
ORDER BY VOTES DESC
LIMIT 0 , 15 "
;

 
//* AND cat_parent_id =125               --> This line is exclusive for selected subcategories, in this case, all subcategories of category 125
//*  HAVING sum( `image_votes` ) > 100    --> Minimal votes quantity
//*  LIMIT 0 , 15 ";                      --> In this case it will display a top 15 list, change this number for your preferred.

$result mysql_query($sql,$link);
$i=0;
  
while ($row mysql_fetch_array($resultMYSQL_ASSOC)) {
     
  $i++;
echo "<a href=categories.php?cat_id={$row['CAT_ID']}>#".$i."</a> {$row['VOTES']} "." <a href=categories.php?cat_id={$row['CAT_ID']}>{$row['NAME']}</a><br>";  
}
?>

</p>
</div>
<div class="top">
<h2>Top 15 - Visits </h2>
<p>
<?php 
  
$sql "SELECT 4images_categories.cat_id AS CAT_ID, sum( `image_hits` ) AS HITS, 4images_categories.cat_name AS NAME
FROM `4images_images` , `4images_categories`
WHERE 4images_images.cat_id = 4images_categories.cat_id
AND cat_parent_id =125
GROUP BY 4images_images.cat_id
HAVING sum( `image_votes` ) >100
ORDER BY HITS DESC
LIMIT 0 , 15 "


$result mysql_query($sql,$link);
$i=0;
  
while ($row mysql_fetch_array($resultMYSQL_ASSOC)) {
     
  $i++;
echo "<a href=categories.php?cat_id={$row['CAT_ID']}>#".$i."</a> {$row['VOTES']} "." <a href=categories.php?cat_id={$row['CAT_ID']}>{$row['NAME']}</a><br>";   
}
?>

</p>
</div>
<div class="top" style="margin:0px;">
<h2>Top 15 - Rating </h2>
<p>
<?php 
  
$sql "SELECT 4images_categories.cat_id AS CAT_ID, avg( `image_RATING` ) AS VOTOS, 4images_categories.cat_name AS NAME
FROM `4images_images` , `4images_categories`
WHERE 4images_images.cat_id = 4images_categories.cat_id
AND cat_parent_id =125
GROUP BY 4images_images.cat_id
HAVING sum( `image_votes` ) >100
ORDER BY VOTOS DESC
LIMIT 0 , 15 "


$result mysql_query($sql,$link);
$i=0;
  
while ($row mysql_fetch_array($resultMYSQL_ASSOC)) {
     
  $i++;
echo "<a href=categories.php?cat_id={$row['CAT_ID']}>#".$i."</a> {$row['VOTES']} "." <a href=categories.php?cat_id={$row['CAT_ID']}>{$row['NAME']}</a><br>";    
}
                        
mysql_close($link);
?>

</p>
</div>

You can see the final result here Hi5 Girls Contest (http://www.ticas.cr/fotos_chicas/top.php)
That's it, let me know if you have some problems.
Title: Re: [PRE-MOD] Top Categories by votes, rating and hits
Post by: V@no on October 30, 2008, 12:34:17 AM
Nice and "not standard" method around here...

Also I have a few issue to comment:
1) your code have no filter regarding visitor's permissions, which mean visitors might see categories they are not supposed to see.
2) since you don't use 4images built-in database class, its not compatible with integrated 4images or if someone uses non-mysql database.
3) the code doesn't use template class for links, this will create problem for people using SEO mod
4) all data for each category is already loaded into $cat_cache array, you don't need query database for that. Because of that each of your database query can be simplified to query 4images_images table only.


P.S.
{$row['CAT_ID']} - today I've learned something new, thank you  ;)
Title: Re: [PRE-MOD] Top Categories by votes, rating and hits
Post by: artmedia on October 31, 2008, 08:19:33 PM
Thanks V@no, i never thought teaching something to you, i have follow many of your MODs, and yes, this MOD have many issues:

Also I have a few issue to comment:
1) your code have no filter regarding visitor's permissions, which mean visitors might see categories they are not supposed to see.
2) since you don't use 4images built-in database class, its not compatible with integrated 4images or if someone uses non-mysql database.
That's because on my site everyone can see any photo, maybe finishing my first attempt  this can be fixed, someone want to help with code?

3) the code doesn't use template class for links, this will create problem for people using SEO mod
Actually I'm using the SEO mod, people just need to change

Example
<a href=categories.php?cat_id={$row['CAT_ID']}>
for
"<a href=modelos_mujeres_{$row['CAT_ID']}.htm>#" -with correspondig keywords-

This is not the best way, but it works


4) All data for each category is already loaded into $cat_cache array, you don't need query database for that. Because of that each of your database query can be simplified to query 4images_images table only.

Let me research about it

Thanks!
Title: Re: [PRE-MOD] Top Categories by votes, rating and hits
Post by: V@nо on October 31, 2008, 09:03:35 PM
3) ops, I ment to say session class, whitch ensures that the link will not break the session.
Title: Re: [PRE-MOD] Top Categories by votes, rating and hits
Post by: Sunny C. on September 28, 2009, 07:58:17 PM
Gibt es dafür eine bessetre Lödung?
Eventuell sowas: http://www.4homepages.de/forum/index.php?topic=5789.msg141504#msg141504 ??