<?php

/************************************************************************************
* vBSEO 3.6.0 for vBulletin v3.x & v4.x by Crawlability, Inc.                       *
*                                                                                   *
* Copyright © 2011, Crawlability, Inc. All rights reserved.                         *
* You may not redistribute this file or its derivatives without written permission. *
*                                                                                   *
* Sales Email: sales@crawlability.com                                               *
*                                                                                   *
*----------------------------vBSEO IS NOT FREE SOFTWARE-----------------------------*
* http://www.crawlability.com/vbseo/license/                                        *
************************************************************************************/

/************************************************************************************
* vBSEO 3.6.0 for vBulletin v3.x & v4.x by Crawlability, Inc.                       *
* Likes info importer                                                               *
*                                                                                   *
* Copyright © 2010, Crawlability, Inc. All rights reserved.                         *
* You may not redistribute this file or its derivatives without written permission. *
*                                                                                   *
* Sales Email: sales@crawlability.com                                               *
*                                                                                   *
*----------------------------vBSEO IS NOT FREE SOFTWARE-----------------------------*
* http://www.crawlability.com/vbseo/license/                                        *
************************************************************************************/
include 'vbseo/includes/functions_vbseo.php';
$db = vbseo_get_db();
vbseo_extra_inc('ui');
if($_GET['run'])
{
$db->vbseodb_query("update ".vbseo_tbl_prefix('user')." set vbseo_likes_in=0,vbseo_likes_out=0");
$pinf = $db->vbseodb_query("select *,count(*) as cnt from ".vbseo_tbl_prefix('vbseo_likes')." group by l_from_userid,l_dest_userid");
while($d = $db->vbseodb_fetch_assoc($pinf))
{
echo $d['cnt'].' - '.$d['l_dest_userid'].' - '.$d['l_from_userid'].'<br>';
$db->vbseodb_query("update ".vbseo_tbl_prefix('user')." set vbseo_likes_in=vbseo_likes_in+".$d['cnt']." where userid=".$d['l_dest_userid']);
$db->vbseodb_query("update ".vbseo_tbl_prefix('user')." set vbseo_likes_out=vbseo_likes_out+".$d['cnt']." where userid=".$d['l_from_userid']);
}
$db->vbseodb_query("update ".vbseo_tbl_prefix('thread')." set vbseo_likes=0");
$db->vbseodb_query("update ".vbseo_tbl_prefix('blog')." set vbseo_likes=0");
$db->vbseodb_query("update ".vbseo_tbl_prefix('cms_nodeinfo')." set vbseo_likes=0");
$pinf = $db->vbseodb_query("select *,count(*) as cnt from ".vbseo_tbl_prefix('vbseo_likes')." group by l_ctype,l_cgroup");
$atbl = array(1=>'thread', 2=>'blog', 3 => 'cms_nodeinfo');
$ftbl = array(1=>'threadid', 2=>'blogid', 3 => 'nodeid');
while($d = $db->vbseodb_fetch_assoc($pinf))
{
if($tt=$atbl[$d['l_ctype']])
$db->vbseodb_query($q="update ".vbseo_tbl_prefix($tt)." set vbseo_likes=vbseo_likes+".$d['cnt']." where ".$ftbl[$d['l_ctype']]."=".$d['l_cgroup']);
}
}
$cnt1 = $db->vbseodb_query_first("select count(*) as cnt from ".vbseo_tbl_prefix('vbseo_likes'));
?>
<h2>A total of <?php echo $cnt1['cnt'];?> likes found in database</h2>
<p>Click <a href="vbseo_likes_calc.php?run=yes">here</a> to recalculate counters for users and threads/blogs</p>