Author Topic: [MOD] - Top Friends - Referrers  (Read 4447 times)

0 Members and 1 Guest are viewing this topic.

Offline batu544

  • Sr. Member
  • ****
  • Posts: 336
    • View Profile
    • Free Celebrity wallpapers
[MOD] - Top Friends - Referrers
« on: January 04, 2011, 07:00:57 AM »
Hi All,

What is this MOD ?
        ....This mod will enable the users to list the top referrers to your website which are added in your friends list.
        ....This list also ordered based on the incoming traffic from your friends website.


Demo : http://www.bhwallpapers.com/

If you like this feature, then here is the steps..

Following files are required for this changes..

1. includes/sessions.php   - change
2. includes/page_header.php   - change
3. includes/constants.php     - change
4. top_friends.php    - New file
5. config.php   - change

Template files

5. top_friends.html   - new
6. top_friends_form.html  - new

Admin Plugin to manager friends

7. Friends.php  - new



Step 1 :

      Please download the attached installer and run it . This installer will create 2 new tables in database. ( 4images_friends and 4images_friends_referrals ). 
   
Step 2: includes/constants.php  changes

   search for
Code: [Select]
define('WORDMATCH_TABLE', $table_prefix.'wordmatch');

Insert after
Code: [Select]
define('FRIENDS_TABLE', $table_prefix.'friends');
define('FRIENDS_REF_TABLE', $table_prefix.'friends_referrals');

Step 3: includes/sessions.php changes

1. Search for
Code: [Select]
    //if (!$login_process) {
      $sql = "REPLACE INTO ".SESSIONS_TABLE."
              (session_id, session_user_id, session_lastaction, session_location, session_ip)
              VALUES
              ('".addslashes($this->session_id)."', ".$this->user_info['user_id'].", $this->current_time, '$this->user_location', '$this->user_ip')";
      $site_db->query($sql);
    //}

    $this->session_info['session_user_id'] = $this->user_info['user_id'];
    $this->session_info['session_lastaction'] = $this->current_time;
    $this->session_info['session_location'] = $this->user_location;
    $this->session_info['session_ip'] = $this->user_ip;

Insert AFTER
Code: [Select]
//**** added for recording friends referal ***************/
$hour = date('H');
if ($hour==0)
{
$sql = "UPDATE ".FRIENDS_TABLE." SET
`daily_visits`=0, `reset_flag`=0
WHERE `reset_flag`=1";
$site_db->query($sql);
}
if ($hour==1)
{
$sql = "UPDATE ".FRIENDS_TABLE." SET
`reset_flag`=1";
$site_db->query($sql);
}

$arr_dom = explode(".", $_SERVER['SERVER_NAME']);
if (count($arr_dom)>2)
{
if (strlen($arr_dom[count($arr_dom)-2])<=3 and strlen($arr_dom[count($arr_dom)-1])==2)
{
$domain_name = $arr_dom[count($arr_dom)-3].".".$arr_dom[count($arr_dom)-2].".".$arr_dom[count($arr_dom)-1];
}
else  {
$domain_name = $arr_dom[count($arr_dom)-2].".".$arr_dom[count($arr_dom)-1];
}
}
else {
$domain_name = $arr_dom[0].".".$arr_dom[1];
}
$ref_url = parse_url(urldecode($_SERVER['HTTP_REFERER'])) ;

if ($ref_url==false) return false;
$ref_domain = str_replace("www.", "", $ref_url['host']);
if ($ref_domain=='') $ref_domain = $ref_url ;
if (strpos($ref_domain, $domain_name)===false)
{
$sql = "SELECT * FROM ".FRIENDS_TABLE." WHERE `url` REGEXP 'http(s)*://(([^/\.])*(/|\.){0,1}){0,1}$ref_domain(/){0,1}.*' ";
$result = $site_db->query($sql);
$num_rows = $site_db->get_numrows($result);
$friend = array();
while ($row = $site_db->fetch_array($result)) {
if (preg_match("'http(s)*://(([^/\.])*([/|\.]){1}){0,1}".$ref_domain."(/){0,1}.*'i", $row['url'])==1)
{
$friend = $row;
}

}
if (count($friend)>0) {

$sql = "SELECT * FROM ".FRIENDS_REF_TABLE." WHERE
`ip`='".$_SERVER['REMOTE_ADDR']."'
AND `friend_id`='".$friend['id']."'
AND NOW()<DATE_ADD(`created`, INTERVAL 1 DAY) ";
$check_day = $site_db->query_firstrow($sql);

// if (count($check_day)==0)
if (!$check_day)
{
/*
* Add the ip to the referrer table
*/
$sql = "INSERT INTO ".FRIENDS_REF_TABLE." SET
`ip`='".$_SERVER['REMOTE_ADDR']."',
`host`='".gethostbyaddr($_SERVER['REMOTE_ADDR'])."',
`created`=NOW(),
`friend_id`='".$friend['id']."'
";
$site_db->query($sql);

$sql = "UPDATE ".FRIENDS_TABLE." SET
`total_visits`=`total_visits`+1,
`daily_visits`=`daily_visits`+1
WHERE `id`='".$friend['id']."'
";
$site_db->query($sql);
}
}
}


//**********************************************************


Step 4: top_friends.php

 1. Download the attached top_friends.php file and upload it in your root directory..

Here is the code for your reference
Code: [Select]
<?php 
/**************************************************************************
 *                                                                        *
 *    4images - A Web Based Image Gallery Management System               *
 *    ----------------------------------------------------------------    *
 *                                                                        *
 *             File: top_friends.php                                      *
 *        Copyright: (C) 2002 Jan Sorgalla                                *
 *            Email: jan@4homepages.de                                    *
 *              Web: http://www.4homepages.de                             *
 *    Scriptversion: 1.7.6                                                *
 *                                                                        *
 *    Never released without support from: Nicky (http://www.nicky.net)   *
 *                                                                        *
 **************************************************************************
 *                                                                        *
 *    Dieses Script ist KEINE Freeware. Bitte lesen Sie die Lizenz-       *
 *    bedingungen (Lizenz.txt) f&#252;r weitere Informationen.                 *
 *    ---------------------------------------------------------------     *
 *    This script is NOT freeware! Please read the Copyright Notice       *
 *    (Licence.txt) for further information.                              *
 *                                                                        *
 *************************************************************************/
$main_template 'top_friends';
define('GET_CACHES'1);
define('ROOT_PATH''./');
include(
ROOT_PATH.'global.php');
require(
ROOT_PATH.'includes/sessions.php');
$user_access get_permission();
include(
ROOT_PATH.'includes/page_header.php');


//-----------------------------------------------------
//--- Save New Friends --------------------------------
//-----------------------------------------------------
$error 0;

if (
$action == "add" && isset($HTTP_POST_VARS[URL_ID])) {
  
$id intval($HTTP_POST_VARS[URL_ID]);

    
$title un_htmlspecialchars(trim($HTTP_POST_VARS['title']));
    
$host un_htmlspecialchars(trim($HTTP_POST_VARS['host']));

$captcha = (isset($HTTP_POST_VARS['captcha'])) ? un_htmlspecialchars(trim($HTTP_POST_VARS['captcha'])) : "";

preg_match("/^(http:\/\/)?([^\/]+)/i","$host"$matches);
$dom $matches[2];
preg_match("/[^\.\/]+\.[^\.\/]+$/"$dom$matches);
$domain $matches[0] ; 

    
// Check already in the friends table..
//    $sql = "SELECT * FROM ".FRIENDS_TABLE." WHERE `url` REGEXP 'http(s)*://(([^/\.])*(/|\.){0,1}){0,1}$domain(/){0,1}.*' ";
    
$sql "SELECT * FROM ".FRIENDS_TABLE." WHERE `url` = '".$dom."' ";
    
$exist_row $site_db->query_firstrow($sql);



    if (
$exist_row)  {
      
$msg .= (($msg != "") ? "<br />" "")."Url already Exist";
      
$error 1;
    }

    if (
$title == "")  {
      
$msg .= (($msg != "") ? "<br />" "").$lang['name_required'];
      
$error 1;
    }
    if (
$captcha_enable_friends && !captcha_validate($captcha)) {
      
$msg .= (($msg != "") ? "<br />" "").$lang['captcha_required'];
      
$error 1;
    }

    if (!
$error)  {
    
if ($user_info['user_level'] != ADMIN) {

      
$sql "INSERT INTO ".FRIENDS_TABLE."
        (title, url, `created`, `modified`, `enabled`, `sort_order`, `display`, `daily_visits`, `reset_flag`, `total_visits`, `ip`, `hostname`)
        VALUES ( '"
.$title."','".$host."', NOW(),NOW(),'0', '1', '0', '0', '0', '0', '".$session_info['session_ip']."','".$dom."' )";
    

    
} else {

      
$sql "INSERT INTO ".FRIENDS_TABLE."
        (title, url, `created`, `modified`, `enabled`, `sort_order`, `display`, `daily_visits`, `reset_flag`, `total_visits`, `ip`, `hostname`)
        VALUES ( '"
.$title."','".$host."', NOW(),NOW(),'1', '1', '1', '0', '0', '0', '".$session_info['session_ip']."','".$dom."' )";

}

      
$site_db->query($sql);
      
$friendid $site_db->get_insert_id();
      
$msg "Your link will be activated after admin review" ;
/****     if ($user_info['user_level'] != ADMIN) {

include(ROOT_PATH.'includes/email.php');
$site_email = new Email();

$config['upload_emails'] = str_replace(" ", "", $config['upload_emails']);
$emails = explode(",", $config['upload_emails']);


$site_email->set_to($config['site_email']);
$site_email->set_subject($lang['new_upload_emailsubject']);
$site_email->register_vars(array(
  "image_name" => stripslashes($image_name),
  "file_name" => $new_name,
  "cat_name" => $cat_cache[$cat_id]['cat_name'],
  "validation_url" => $validation_url,
  "site_name" => $config['site_name']
));
$site_email->set_body("upload_notify", $config['language_dir_default']);
$site_email->set_bcc($emails);
$site_email->send_email();
     }   ***/

 }
  }



  
//-----------------------------------------------------
  //--- Form -----------------------------------
  //-----------------------------------------------------
    
$title = (isset($HTTP_POST_VARS['title']) && $error) ? format_text(trim(stripslashes($HTTP_POST_VARS['title'])), 2) : (($user_info['user_level'] != GUEST) ? format_text($user_info['title'], 2) : "");
    
$host = (isset($HTTP_POST_VARS['host']) && $error) ? format_text(trim(stripslashes($HTTP_POST_VARS['host'])), 2) : "";

    
$site_template->register_vars(array(
      
"title" => $title,
      
"host" => $host,
      
"url_form" => $site_sess->url(ROOT_PATH."top_friends.php"),
      
"lang_add_new_friend" => $lang['post_comment'],
      
"lang_captcha" => $lang['captcha'],
      
"lang_captcha_desc" => $lang['captcha_desc'],
      
"captcha_friends" => (bool)$captcha_enable_friends
    
));
    
$top_friends_form $site_template->parse_template("top_friends_form");
  
$site_template->register_vars("top_friends_form"$top_friends_form);
  unset(
$top_friends_form);

//---------------------------------------------------------
//----All the friends list---------------------------------
//---------------------------------------------------------
$sql "SELECT title, url, hostname,  `daily_visits` , `total_visits`
 FROM "
.FRIENDS_TABLE."
 WHERE `enabled` = '1' AND `display` = '1'  OR `total_visits` > 5
         ORDER BY `daily_visits` DESC, `total_visits` DESC "
;
$result $site_db->query($sql);
$friend_rows $site_db->get_numrows($result);

$top_friends "<tr class=\"row1\"><td>Description</td><td> Url</td><td>Daily Visit</td><td>Total Visit</td></tr><br />"
if (
$friend_rows)  {
  while (
$friend_rows $site_db->fetch_array($result)){
   
$top_friends .= "<tr class=\"row1\"><td>$friend_rows[title]</td><td><a href=\"$friend_rows[url]\" rel=\"nofollow\" target=\"_blank\" title=\"$friend_rows[title]\">".$friend_rows[hostname]."</a></td><td>".$friend_rows[daily_visits]."</td><td>".$friend_rows[total_visits]."</td></tr>\n"
  }
// end else


//-----------------------------------------------------
//--- Print Out ---------------------------------------
//-----------------------------------------------------
$site_template->register_vars(array(
  
"msg" => $msg,
  
"clickstream" => $clickstream,
  
"top_friends" => $top_friends

));

  
$site_template->print_template($site_template->parse_template($main_template));
include(
ROOT_PATH.'includes/page_footer.php');
?>


Step 5: - includes/page_header.php changes

1. Open page_header.php file and find
Code: [Select]
?>

Insert ABOVE
Code: [Select]
//*********************************************************
// top 20 friends
$sql = "SELECT title, url
FROM ".FRIENDS_TABLE."
WHERE `enabled` = '1' AND `display` = '1' 
         ORDER BY `daily_visits` DESC, `total_visits` DESC
         LIMIT 20 ";
$result = $site_db->query($sql);
$friend_rows = $site_db->get_numrows($result);

$top_20 ="<ul class=\"categories_nav\">\n";
$top_20 .="    <li class=\"categories_header_new\" >Top Friends </li>\n";
if ($friend_rows)  {
  while ($friend_rows = $site_db->fetch_array($result)){
   $top_20 .= "    <li><a href=\"$friend_rows[url]\" target=\"_blank\" rel=\"nofollow\" title=\"$friend_rows[title]\">".$friend_rows[title]."</a></li>\n";
  }
} // end else
$top_20 .= "    <li><strong><a href=\"top_friends.htm\" >All Friends</a></strong></li>\n";
$top_20 .= "</ul>\n";


$site_template->register_vars(array(
"top_20" => $top_20
));
unset($top_20);
unset($top_friends);
//*********************************************

Step 6: - New file   top_friends_form.html

Create a new file called top_friends_form.html in your templates/your directory and put below code inside it..
Code: [Select]
<table border="0" cellspacing="0" cellpadding="0" align="center">
  <tr>
    <td valign="top" class="head1" >
      <table  border="0" cellpadding="3" cellspacing="0">
        <tr>
          <td valign="top" class="head1">Add Your Link</td>
        </tr>
        <tr>
          <td valign="top" class="row1" >
            <form name="commentform" action="{url_form}" method="post" onsubmit="postbutton.disabled=true;">
                    <input type="hidden" name="id" value="{image_id}" />
                    <input type="hidden" name="action" value="add" />
              <table cellpadding="4" cellspacing="0" border="0">
                <tr>
                  <td ><b>Desc :</b></td>
                  <td><input type="text" name="title" size="30" value="{title}" class="commentinput" /></td>
                </tr>
                <tr>
                  <td ><b>Url :</b></td>
                  <td><input type="text" name="host" size="30" value="{host}" class="commentinput" /></td>
                </tr>
                 {if captcha_friends}
          <tr>
            <td class="row1" valign="top"><b>{lang_captcha}</b></td>
            <td class="row1">
  <a href="javascript:new_captcha_image();"><img src="{url_captcha_image}" border="0" alt="" id="captcha_image" /></a> <br />
              <input type="text" name="captcha" size="30" value="" class="captchainput" id="captcha_input" />
              <br />
              <table cellpadding="0" cellspacing="0" width="210">
                            <tr>
                                <td>{lang_captcha_desc}</td>
                            </tr>
                        </table>
</td>
          </tr>
                {endif captcha_friends}
               <tr>
                  <td  valign="top">&nbsp;</td>
                  <td><input type="submit" name="postbutton" value="Submit Link" class="button" /></td>
               </tr>
              </table>
            </form>
          </td>
        </tr>
      </table>
    </td>
  </tr>
</table>

Step 7: - top_friends.html

Create  a new file in your templates/your directory directory and name it as top_friends.html . Design is yours..You need to use below tags to get the list of top friends and top friends form
Code: [Select]
{top_friends_form}
<table width="100%">{top_friends}</table>

I have mentioned the complete top_friends.html file for reference
Code: [Select]
{header}
<table width="100%" border="0" cellspacing="0" cellpadding="0" align="center">
  <tr>
    <td>
      <table width="100%" border="0" cellspacing="0" cellpadding="0" class="tablehead">
        <tr>
          <td width="100%" colspan="4"><table cellpadding="0" cellspacing="0" width="100%">
    <tr>
        <td width="6"><img src="{template_url}/images/header_top_left.gif" width="6" height="6" alt="" /></td>
        <td width="100%"><img src="{template_url}/images/header_top.gif" width="100%" height="6" alt="" /></td>
<td width="6"><img src="{template_url}/images/header_top_right.gif" width="6" height="6" alt="" /></td>
    </tr>
</table>
</td>
        </tr>
        <tr>
          <td width="6"><img src="{template_url}/images/header_left.gif" width="6" height="60" alt="" /></td>
          <td width="100%"><img src="{template_url}/images/header_logo.gif" width="405" height="60" alt="" /></td>
          <td width="225" align="right">
            <form method="post" action="{url_search}">
              <table border="0" cellspacing="0" cellpadding="1">
                <tr>
                  <td>
                    <input type="text" name="search_keywords" size="15" class="searchinput" />
                  </td>
                  <td>
                    <input type="submit" value="{lang_search}" class="button" name="submit" />
                  </td>
                </tr>
                <tr valign="top">
                  <td colspan="2"><a href="{url_search}" class="smalltext">{lang_advanced_search}</a></td>
                </tr>
              </table>
            </form>
          </td>
          <td align="right" width="6"><img src="{template_url}/images/header_right.gif" width="6" height="60" alt="" /></td>
        </tr>
      </table>
    </td>
  </tr>
  <tr>
    <td class="bordercolor">
      <table width="100%" border="0" cellspacing="1" cellpadding="0">
        <tr>
          <td class="tablebgcolor">
            <table width="100%" border="0" cellspacing="1" cellpadding="0">
              <tr>
                <td class="navbar" height="23">
                  <table width="100%" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                      <td><img src="{template_url}/images/spacer.gif" width="4" height="4" alt="" />{clickstream}</td>
                      <td align="right">
<a href="{url_top_images}"><b>{lang_top_images}</b></a>&nbsp;
<a href="{url_new_images}"><b>{lang_new_images}</b></a>&nbsp;
  </td>
                    </tr>
                  </table>
                </td>
              </tr>
            </table>
            <table width="100%" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td width="150" valign="top" class="row2">
                  <table width="150" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                      <td class="head2" height="20"><img src="{template_url}/images/spacer.gif" alt="" width="4" height="4" />{lang_registered_user}</td>
                    </tr>
                    <tr>
                      <td class="tablebgcolor"><img src="{template_url}/images/spacer.gif" alt="" width="1" height="1" /></td>
                    </tr>
                    <tr>
                      <td align="center" class="row1">{user_box} </td>
                    </tr>
                    <tr>
                      <td class="tablebgcolor"><img src="{template_url}/images/spacer.gif" alt="" width="1" height="1" /></td>
                    </tr>
                  </table>
                  {if random_image}
                  <table width="150" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                      <td class="head2" height="20"> <img src="{template_url}/images/spacer.gif" alt="" width="4" height="4" />{lang_random_image}</td>
                    </tr>
                    <tr>
                      <td class="tablebgcolor"><img src="{template_url}/images/spacer.gif" alt="" width="1" height="1" /></td>
                    </tr>
                    <tr>
                      <td align="center" class="row1">
    <br />
                        {random_image}
<br />
                        <br />
                      </td>
                    </tr>
                    <tr>
                      <td class="tablebgcolor"><img src="{template_url}/images/spacer.gif" alt="" width="1" height="1" /></td>
                    </tr>
                  </table>
                  {endif random_image}
                </td>
                <td width="1" class="bordercolor" valign="top"><img src="{template_url}/images/spacer.gif" width="1" height="1" alt="" /></td>
                <td width="18" valign="top"><img src="{template_url}/images/spacer.gif" width="18" height="18" alt="" /></td>
                <td width="450" valign="top"><br />
                  <b class="title"><b>{msg}</b></b>
                  <hr size="1" />
{top_friends_form}
<table width="100%">{top_friends}</table>

                  <table width="100%" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                      <td>{category_dropdown_form}</td>
                      <td align="right">{setperpage_dropdown_form}</td>
                    </tr>
                  </table>
                  <p>&nbsp;</p>
                </td>
                <td width="20" valign="top"><img src="{template_url}/images/spacer.gif" width="19" height="19" alt="" /></td>
              </tr>
            </table>
          </td>
        </tr>
      </table>
    </td>
  </tr>
  <tr>
    <td>
      <table width="100%" border="0" cellspacing="0" cellpadding="0" class="tablebottom">
        <tr>
          <td width="6" nowrap><img src="{template_url}/images/footer_left.gif" width="6" height="19" alt="" /></td>
          <td width="100%"></td>
          <td width="6" nowrap><img src="{template_url}/images/footer_right.gif" width="6" height="19" alt="" /></td>
        </tr>
      </table>
    </td>
  </tr>
</table>
{footer}

Step 8:

  .. Now you can list your top 20 friends in any other pages by using {top_20} tag.


Step 9:
   Download the attached plugin and place it in your admin/plugins/ folder.

Step 10: config.php file changes
   
Open your config.php file and find for
Code: [Select]
?>
and insert above ..
Code: [Select]
$captcha_enable_friends=1;


I hope, I am done .. :)   For me email notification part is not working so, I have commented it in my code.. may be some PHP gurus can improve this code also ..

« Last Edit: February 14, 2011, 12:08:00 PM by batu544 »

Offline sunl

  • Newbie
  • *
  • Posts: 20
    • View Profile
Re: [MOD] - Top Friends - Referrers
« Reply #1 on: February 14, 2011, 09:53:41 AM »
Hello Batu544  :)

Your MOD is good for Traffic Exchange. I try this and found that Captcha integration not working.

If some one try to submit link then submission not worked. And If i remove capatcha part from

"top_friends_form.html" then submission worked but in this case it will be paradise for spammers.


Offline batu544

  • Sr. Member
  • ****
  • Posts: 336
    • View Profile
    • Free Celebrity wallpapers
Re: [MOD] - Top Friends - Referrers
« Reply #2 on: February 14, 2011, 12:02:26 PM »
Hello, I guess you did something wrong.. because this is the same code what I am running in my website. Also, I have tested this in my test server with a fresh copy of 4images script..

can you provide your link, so that I can see it ?...


I added one more file changes in my previous post .. please check it, may be it will help you...


Thank you
batu544