Skip to content

Instantly share code, notes, and snippets.

@bradhintze
Created December 14, 2010 21:20
Show Gist options
  • Save bradhintze/741117 to your computer and use it in GitHub Desktop.
Save bradhintze/741117 to your computer and use it in GitHub Desktop.
rule build_div {
select when pageview ".*"
pre {
url = page:env("caller");
parent = <<
<div class = "kynetx_ui">
<div id = "what_links_here" style = "display:none">
</div>
</div>
>>;
}
{
append("body", parent);
jquery_ui:dialog("#what_links_here") with position = ["left", "top"] and title = "What Links Here";
}
fired {
raise explicit event "get_links" with url = url;
raise explicit event "get_total_links" with url = url;
}
}
meta {
name "YQL=>siteexplorer table"
description <<
YQL=>siteexplorer table
>>
author "AKO"
logging on
use javascript resource jquery_ui_js
use css resource jquery_ui_redmond_css
}
global {
datasource yql:JSON <- "http://query.yahooapis.com/v1/public/yql?format=json&callback="
css <<
.kynetx_ui {
font-size: 12px;
line-height: normal;
}
.kynetx_ui a {
text-decoration: none;
}
.kynetx_ui h3 {
margin: 0;
padding: 0;
font-family: "Arial", Helvitica, sans-serif;
font-size: 13px;
}
.kynetx_ui .link-data {
border-bottom: 1px solid #A6C9E2;
}
>>;
emit <|
// function that takes an unformatted number and puts commas in appropriate places
function addCommas(nStr)
{
nStr += '';
x = nStr.split('.');
x1 = x[0];
x2 = x.length > 1 ? '.' + x[1] : '';
var rgx = /(\d+)(\d{3})/;
while (rgx.test(x1)) {
x1 = x1.replace(rgx, '$1' + ',' + '$2');
}
return x1 + x2;
}
|>;
}
rule build_div {
select when pageview ".*"
pre {
url = page:env("caller");
parent = <<
<div class = "kynetx_ui">
<div id = "what_links_here" style = "display:none">
</div>
</div>
>>;
}
{
append("body", parent);
jquery_ui:dialog("#what_links_here") with position = ["left", "top"] and title = "What Links Here";
}
fired {
raise explicit event "get_links" with url = url;
raise explicit event "get_total_links" with url = url;
}
}
rule get_links {
select when explicit get_links
foreach datasource:yql({"q":"select%20*%20from%20search.siteexplorer.inlinks%20where%20query%3D%22#{event:param('url')}%22"}).pick("$.query.results.Result") setting (linkInfo)
pre {
url = event:param("url");
website = linkInfo.pick("$.Title");
page = linkInfo.pick("$.ClickUrl");
toAppend = <<
<div class = "link-data">
<a href = "#{page}" target = "_blank" title = "#{page}"><h3>#{website}</h3></a>
</div>
>>;
}
{
append("#what_links_here", toAppend);
}
}
rule get_total_links {
select when explicit get_total_links
pre {
totalLinks = datasource:yql({"q":"select%20*%20from%20search.siteexplorer.inlinks%20where%20query%3D%22#{event:param('url')}%22"}).pick("$.query.meta.data.totalResultsAvailable");
totalLinksInfo = <<
<div id = "total_links">
<p>Total links to this page: #{addCommas(totalLinks)}</p>
</div>
>>;
}
{
append("#what_links_here", totalLinksInfo);
}
}
global {
datasource yql:JSON <- "http://query.yahooapis.com/v1/public/yql?format=json&callback="
css <<
.kynetx_ui {
font-size: 12px;
line-height: normal;
}
.kynetx_ui a {
text-decoration: none;
}
.kynetx_ui h3 {
margin: 0;
padding: 0;
font-family: "Arial", Helvitica, sans-serif;
font-size: 13px;
}
.kynetx_ui .link-data {
border-bottom: 1px solid #A6C9E2;
}
>>;
emit <|
// function that takes an unformatted number and puts commas in appropriate places
function addCommas(nStr)
{
nStr += '';
x = nStr.split('.');
x1 = x[0];
x2 = x.length > 1 ? '.' + x[1] : '';
var rgx = /(\d+)(\d{3})/;
while (rgx.test(x1)) {
x1 = x1.replace(rgx, '$1' + ',' + '$2');
}
return x1 + x2;
}
|>;
}
meta {
name "YQL=>siteexplorer table"
description <<
YQL=>siteexplorer table
>>
author "AKO"
logging on
use javascript resource jquery_ui_js
use css resource jquery_ui_redmond_css
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment