<?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/                                        *
************************************************************************************/

/*** Likes Info Importer ***/
include 'vbseo/includes/functions_vbseo.php';
$db = vbseo_get_db();
$stepsize = 1000;
$step_no = intval($_GET['step']);
vbseo_extra_inc('ui');
$cnt1 = $db->vbseodb_query_first("select count(*) as cnt from ".vbseo_tbl_prefix('reputation'));
$cnt2 = $db->vbseodb_query_first("select count(*) as cnt from ".vbseo_tbl_prefix('post_thanks'));
$cnt3 = $db->vbseodb_query_first("select count(*) as cnt from ".vbseo_tbl_prefix('dbtech_thanks_entry')." where contenttype='post'");
$cnt4 = $db->vbseodb_query_first("select count(*) as cnt from ".vbseo_tbl_prefix('helpfulanswer')." where yesno=1");
?>
<ol>
<li>vBulletin's built-in reputation system: <?php echo $cnt1['cnt'];?> entries found, <a href="vbseo_import_likes.php?imp=1">click here to import</a>
<li>[AJAX] Post Thank You"'s mod: <?php echo $cnt2['cnt'];?> entries found, <a href="vbseo_import_likes.php?imp=2">click here to import</a>
<li>DBTech Post Thanks"'s mod: <?php echo $cnt3['cnt'];?> entries found, <a href="vbseo_import_likes.php?imp=3">click here to import</a>
<li>Helpful Answers mod: <?php echo $cnt4['cnt'];?> entries found, <a href="vbseo_import_likes.php?imp=4">click here to import</a>
</ol>
<?php
flush();
if(isset($_GET['imp']))
{
switch($_GET['imp'])
{
case 1:
echo "<h2>Importing entries from vBulletin's reputation system</h2>";flush();
$q = "select r.postid,r.whoadded,r.dateline,r.userid,p.threadid,u.username,l.l_contentid from ".vbseo_tbl_prefix('reputation')." r ".
"left join ".vbseo_tbl_prefix('user')." u on u.userid=r.whoadded ".
"left join ".vbseo_tbl_prefix('vbseo_likes')." l on l_ctype=1 and l_contentid=r.postid and l_from_userid=whoadded ".
"left join ".vbseo_tbl_prefix('post')." p on p.postid=r.postid ";
break;
case 2:
echo "<h2>Importing entries from [AJAX] Post Thank You mod</h2>";flush();
$q = "select r.postid,p.userid,r.date,r.userid as whoadded,p.threadid,u.username,l.l_contentid from ".vbseo_tbl_prefix('post_thanks')." r ".
"left join ".vbseo_tbl_prefix('user')." u on u.userid=r.userid ".
"left join ".vbseo_tbl_prefix('vbseo_likes')." l on l_ctype=1 and l_contentid=r.postid and l_from_userid=r.userid ".
"left join ".vbseo_tbl_prefix('post')." p on p.postid=r.postid " ;
break;
case 3:
echo "<h2>Importing entries from DBTech Post Thanks mod</h2>";flush();
$q=
"select p.postid,p.userid,r.dateline as date,r.userid as whoadded,p.threadid,u.username,l.l_contentid from ".vbseo_tbl_prefix('dbtech_thanks_entry')." r ".
"left join ".vbseo_tbl_prefix('user')." u on u.userid=r.userid ".
"left join ".vbseo_tbl_prefix('vbseo_likes')." l on l_ctype=1 and l_contentid=r.contentid and l_from_userid=r.userid ".
"left join ".vbseo_tbl_prefix('post')." p on p.postid=r.contentid ".
" where r.contenttype='post'";
break;
case 4:
echo "<h2>Importing entries from Helpful Answers mod</h2>";flush();
$q=
"select p.postid,p.userid,ha.dateline as date,ha.userid as whoadded,hp.threadid,u.username,l.l_contentid ".
"from ".vbseo_tbl_prefix('helpfulanswer')." ha inner join ".vbseo_tbl_prefix('post')." p on (ha.postid = p.postid) ".
"inner join ".vbseo_tbl_prefix('helpfulpost')." hp on (ha.postid = hp.postid) ".
"inner join ".vbseo_tbl_prefix('user')." u on (ha.userid = u.userid) ".
"left join ".vbseo_tbl_prefix('vbseo_likes')." l on l_ctype=1 and l_contentid=p.postid and l_from_userid=ha.userid ".
"where ha.yesno = 1";
break;
}
$impno = $fimpno = 0;
$sql_limit = " LIMIT ".($step_no*$stepsize).",".$stepsize;
$mq = $db->vbseodb_query($q . $sql_limit);
while($pinf = $db->vbseodb_fetch_assoc($mq))
{
$fimpno++;
if($pinf['threadid'] && !$pinf['l_contentid'] && $pinf['username'])
{
$impno++;
vBSEO_UI::add_like($pinf['postid'], 1, $pinf['threadid'], $pinf['whoadded'], 
$pinf['userid'], $pinf['dateline'], $pinf['username']);
}
}
$timpno = intval($_GET['timpno'])+$impno;
echo "Imported likes: $timpno<hr>";
if($fimpno==$stepsize)
{
echo 'redirecting... <script type="text/javascript">document.location="vbseo_import_likes.php?imp='.$_GET['imp'].'&step='.($step_no+1).'&timpno='.$timpno.'"</script>';
}
}
