View Single Post
(#1)
c0rrupt Offline
Administrator
 
Posts: 193
Join Date: Mar 2010
Location: Canada
Show site Downloads/Rank [module] - 11-07-2010, 10:19 AM

by jomasaco on Mon Oct 11, 2010

By request of many families here goes.

First this module.
Code:
<?php
    /*BEGIN_INFO
    Show the downloads for an specific site.
    Show the sitename
    Show the arrowup
    END_INFO*/
    if(!defined("WCDDL_GUTS"))
        exit;
            $modEnabled = true; //Change to false if don't use
        if($modEnabled) {    
                 if(isset($_GET['site'])) {
                $core->site = $_GET['site'];
                if (preg_match('#^[A-Z0-9.-]+\.[A-Z]{2,4}$#i', $core->site)) {
                $core->siteSQL = mysql_real_escape_string($core->site);
            }
              $core->siteSURL = $core->processURL($core->site);
              $core->sqlOrder = "views DESC"; //order the downloads list by views, comment if want to show by date
            }
    function siteDownloads($where) {
        global $core;     
            $sid = mysql_query("SELECT id FROM wcddl_sites WHERE url = '".$core->siteSQL."'");
            if(!mysql_num_rows($sid)) {
            unset($core->siteSURL); //if no site on db this will be uset can be used to... msgs or something 
            return $where;
            } else { 
            $sid = mysql_result($sid,0);
            if(empty($where))
                $where = " WHERE sid = ".$sid;
            else
                $where = " AND sid = ".$sid;
        return $where;
    }
    }
    $core->attachDataHook("fetchDownloadsSQLWhere","siteDownloads");
    /*Show the sitename
    if doubled replace by arrowup
    show the rank
    */
    $lastSiteData = "";
    function lastSiteData($download) {
        global $lastSiteData,$core;
        if(empty($download) || !isset($download['title']) || !isset($download['sname']) || !isset($download['surl']))
            return $download;
        if($download['surl'] == $lastSiteData)
        $download['siteLink'] = '<center>[img]./images/arrowup.gif[/img]</center>';
        else
            $download['siteLink'] = '<center>'.$download['sname'].'[img]./images/rank/'.$download['rate'].'.gif[/img]</center>';
        $lastSiteData = $download['surl'];
        return $download;
    }
    $core->attachDataHook("fetchDownloadsRow","lastSiteData");
    }
    ?>
Now on index.php
replace,

Code:
    $downloads = $core->fetchDownloads();
with
Code:
    $downloads = $core->fetchDownloads(true,false);
where to show the site on table
add


Code:
    <td><?=$dl['siteLink']?></td>
images, copy this image to your images folder rename to arrowup.gif

inside images folder create an new rename to rank
place there your rank images name them from 0 to 5.gif (0.gif,1.gif....)

to rank the sites
first sql
Code:
    ALTER TABLE `wcddl_sites` ADD `rating` INT( 1 ) NOT NULL DEFAULT '0' AFTER `email`
open funcs.php
find

Code:
    $downloadSite = mysql_query("SELECT name as sname, url as surl FROM wcddl_sites WHERE id = '".$row['sid']."'");
Replace by
Code:
    $downloadSite = mysql_query("SELECT name as sname, url as surl, rating as rate FROM wcddl_sites WHERE id = '".$row['sid']."'");
To rate the site the easy way.
open funcs.php
find
function admin_maintenance() {
echo 'Use this panel carefully to take out maintenance on your database.


one line before the </form>';
add

Code:
    
<input type="submit" value="Rate Sites" name="Rsites">
find
if(isset($_POST['ort']))
$ort = $_POST['ort'];
after add

Code:
    if(isset($_POST['Rsites']))
                $rsites = $_POST['Rsites'];
find
Code:
echo '<div align="center" style="color:green;">Tables Optimized & Repaired</div>';
}
after add

Code:
    if(isset($rsites)) {
         mysql_query("UPDATE wcddl_sites SET rating=1");
         $get300 = mysql_query("SELECT COUNT(title) AS 'number' , sid FROM wcddl_downloads GROUP BY sid ORDER BY number DESC LIMIT 0,300");
    while ($row = mysql_fetch_array($get300)) {
    mysql_query("UPDATE wcddl_sites SET rating= rating+1 where id = '".$row['sid']."'"); }
         $get200 = mysql_query("SELECT COUNT(title) AS 'number' , sid FROM wcddl_downloads GROUP BY sid ORDER BY number DESC LIMIT 0,200");
    while ($row = mysql_fetch_array($get200)) {
    mysql_query("UPDATE wcddl_sites SET rating= rating+1 where id = '".$row['sid']."'"); }
    $get100 = mysql_query("SELECT COUNT(title) AS 'number' , sid FROM wcddl_downloads GROUP BY sid ORDER BY number DESC LIMIT 0,100");
    while ($row = mysql_fetch_array($get100)) {
    mysql_query("UPDATE wcddl_sites SET rating= rating+1 where id = '".$row['sid']."'"); }
    $getwhite = mysql_query("SELECT url FROM wcddl_whitelist");
    while ($row = mysql_fetch_array($getwhite)) {
    mysql_query("UPDATE wcddl_sites SET rating= rating+1 where url = '".$row['url']."'"); }
    echo '<div align="center" style="color:green;">Sites Rated</div>';
    }

missing here the pagination the queue listing the sites administration but that will be other lesson for today are enough.
------------EDIT 26-10 -------------
changed, the query will be only executed if the url are ok, bad urls are ignored to query but can be used to echo or something.
$core->siteSQL = mysql_real_escape_string($core->site);
if (preg_match('#^[A-Z0-9.-]+\.[A-Z]{2,4}$#i', $core->site)) {
$core->siteSQL = mysql_real_escape_string($core->site);
}
changed the function siteDownloads()
added an option who will unset the siteSURL so if no site on db that doesn't exist can use to show error msg.


Before doing any edits to your DDL Site always make a BACKUP first.