Dr.CustUmz
03-25-2016, 04:03 PM
this should be my last request for help regarding this.
I am trying to show external link clicks next to links in post, like how twitter forums do:
I have everything ready, I just need help getting the count to show next to links in post through plugins.
plugin:
postbit_display_complete
$this->post['message'] = str_replace('href="', 'href="./out.php?link=', $this->post['message']);
$this->post['signature'] = str_replace('href="', 'href="./out.php?link=', $this->post['signature']);
this captures any link posted and sends it through out.php (which is effecting imgs if using highslide or w/e is built in currently which i also will need to fix)
out.php which captures the link to the database:
define('NO_REGISTER_GLOBALS', 1);
define('THIS_SCRIPT', 'drc-lf');
require_once('./global.php');
if (isset($_GET['link'])) {
// format passed url
$drc_url = $_GET['link'];
unset($_GET['link']);
if(count($_GET))
$drc_url = $drc_url . '&' . http_build_query($_GET);
// deals w/ the display if $drc_url is a valid URL
if (filter_var($drc_url, FILTER_VALIDATE_URL)) {
$site = parse_url($_SERVER['HTTP_HOST']);
$site = $site['path'];
$url = parse_url($drc_url);
// the passed url is not an external link
if ($site == $url['host']) {
Header( "Location: ". $drc_url);
}
// the passed url is an external link
else {
$query = $db->query_first("SELECT * FROM ". TABLE_PREFIX ."redirect WHERE url = '" . $drc_url . "'");
if (!$query){
$db->query_write("INSERT INTO ". TABLE_PREFIX ."redirect (url, hits) VALUES ('" . $drc_url . "', 1)");
} else {
$db->query_write("UPDATE ". TABLE_PREFIX ."redirect SET hits = hits + 1 WHERE url = '" . $drc_url . "'");
}
eval('print_output("' . fetch_template('drc_lf') . '");');
}
// open invalid link
} else {
Header( "Location: ". $drc_url);
}
}
So I have the data I need, I just don't know where to go from here.
Something like this should return the results:
$vbulletin->db->query_first("
SELECT SUM(hits) AS hits
FROM " . TABLE_PREFIX . "redirect
WHERE url = '$drc_url'
");
I used
$drclf = $vbulletin->db->query_first("
SELECT SUM(hits) AS hits
FROM " . TABLE_PREFIX . "redirect
WHERE url = 'http://google.com'
");in global
and placed $drclf[hits] in header and it worked properly (just to test)
I just don't know where to hook it without causing severe queries in every postbit, or maybe even a cron task, where it updates the count every so often, and how can I get it to show after every link without modifying core files. I just need some help getting the final result like the first IMG.
sorry for all the help needed, I'm better when it comes to design lol.
--------------- Added 1458967207 at 1458967207 ---------------
really really need some help.
I been working non stop on this I managed to get the location where i need the number i just cant get the result to display in it.
and i know this is going to cause massive queries when ever i do get it working, so i need help figuring out another way to do it.
in global_start i have:
$drc_url = $_GET['link'];
$drclf = $vbulletin->db->query_first("
SELECT SUM(hits) AS hits
FROM " . TABLE_PREFIX . "redirect
WHERE url = '$drc_url'
");
that doesnt feel right to me though.
then in postbit_display_complete is:
$post['message']=preg_replace ('</a>' , '</a>('.$drclf[hits].')' , $post['message']);
this isn't working though which im almost certain is because of the query in global. I think im off a little.
also my preg replace is f'd up and looks like <(this)> in posts <> shouldnt be in it but when i remove them i get an infinite load on showthread.
this is just driving me insane and i didnt think it would be this difficult.
all the data is ready, i just need to return it.
end goal:
154574
the table:
154575
I am trying to show external link clicks next to links in post, like how twitter forums do:
I have everything ready, I just need help getting the count to show next to links in post through plugins.
plugin:
postbit_display_complete
$this->post['message'] = str_replace('href="', 'href="./out.php?link=', $this->post['message']);
$this->post['signature'] = str_replace('href="', 'href="./out.php?link=', $this->post['signature']);
this captures any link posted and sends it through out.php (which is effecting imgs if using highslide or w/e is built in currently which i also will need to fix)
out.php which captures the link to the database:
define('NO_REGISTER_GLOBALS', 1);
define('THIS_SCRIPT', 'drc-lf');
require_once('./global.php');
if (isset($_GET['link'])) {
// format passed url
$drc_url = $_GET['link'];
unset($_GET['link']);
if(count($_GET))
$drc_url = $drc_url . '&' . http_build_query($_GET);
// deals w/ the display if $drc_url is a valid URL
if (filter_var($drc_url, FILTER_VALIDATE_URL)) {
$site = parse_url($_SERVER['HTTP_HOST']);
$site = $site['path'];
$url = parse_url($drc_url);
// the passed url is not an external link
if ($site == $url['host']) {
Header( "Location: ". $drc_url);
}
// the passed url is an external link
else {
$query = $db->query_first("SELECT * FROM ". TABLE_PREFIX ."redirect WHERE url = '" . $drc_url . "'");
if (!$query){
$db->query_write("INSERT INTO ". TABLE_PREFIX ."redirect (url, hits) VALUES ('" . $drc_url . "', 1)");
} else {
$db->query_write("UPDATE ". TABLE_PREFIX ."redirect SET hits = hits + 1 WHERE url = '" . $drc_url . "'");
}
eval('print_output("' . fetch_template('drc_lf') . '");');
}
// open invalid link
} else {
Header( "Location: ". $drc_url);
}
}
So I have the data I need, I just don't know where to go from here.
Something like this should return the results:
$vbulletin->db->query_first("
SELECT SUM(hits) AS hits
FROM " . TABLE_PREFIX . "redirect
WHERE url = '$drc_url'
");
I used
$drclf = $vbulletin->db->query_first("
SELECT SUM(hits) AS hits
FROM " . TABLE_PREFIX . "redirect
WHERE url = 'http://google.com'
");in global
and placed $drclf[hits] in header and it worked properly (just to test)
I just don't know where to hook it without causing severe queries in every postbit, or maybe even a cron task, where it updates the count every so often, and how can I get it to show after every link without modifying core files. I just need some help getting the final result like the first IMG.
sorry for all the help needed, I'm better when it comes to design lol.
--------------- Added 1458967207 at 1458967207 ---------------
really really need some help.
I been working non stop on this I managed to get the location where i need the number i just cant get the result to display in it.
and i know this is going to cause massive queries when ever i do get it working, so i need help figuring out another way to do it.
in global_start i have:
$drc_url = $_GET['link'];
$drclf = $vbulletin->db->query_first("
SELECT SUM(hits) AS hits
FROM " . TABLE_PREFIX . "redirect
WHERE url = '$drc_url'
");
that doesnt feel right to me though.
then in postbit_display_complete is:
$post['message']=preg_replace ('</a>' , '</a>('.$drclf[hits].')' , $post['message']);
this isn't working though which im almost certain is because of the query in global. I think im off a little.
also my preg replace is f'd up and looks like <(this)> in posts <> shouldnt be in it but when i remove them i get an infinite load on showthread.
this is just driving me insane and i didnt think it would be this difficult.
all the data is ready, i just need to return it.
end goal:
154574
the table:
154575