News:

Want to get involved in developing SMF, then why not lend a hand on our github!

Main Menu

integrating safelinking

Started by steve51184, August 02, 2010, 05:01:05 AM

Previous topic - Next topic

steve51184

i'm trying to get safelinking.net working with smf and i've added this bit of code in \Themes\default\Post.template.php

Code (before) Select
', $context['show_approval'] ? '<li><label for="approve"><input type="checkbox" name="approve" id="approve" value="2" class="input_check" ' . ($context['show_approval'] === 2 ? 'checked="checked"' : '') . ' /> ' . $txt['approve_this_post'] . '</label></li>' : '', '
</ul>


Code (add) Select
<!--Begin safelinking mod-->
<br/>
<label for="safelinking-links" style="width:auto;padding-bottom:10px;"><b>Secure your links</b></label><br/>
<textarea id="safelinking-links" rows="" cols="" style="width:100%;height:100px;"></textarea><br/><br/>
<input type="button" class="input_submit" value="Insert into post" onclick="safelinking_initialise();"/><br/><br/>
<script type="text/javascript" src="', $settings['default_theme_url'], '/scripts/sl.js"></script>
<!--End safelinking mod-->


and made the file \Themes\default\scripts\sl.js

var aObj;

function safelinking_initialise()
{
var links = document.getElementById("safelinking-links").value;
if(links === "")
{
alert("Please specify some links to protect");
}
else
{
        request = 'http://safelinking.net/api?output=json&enable-captcha=on&links-to-protect=' + links;
        aObj = new JSONscriptRequest(request);
        aObj.buildScriptTag();
        aObj.addScriptTag();
}
}

function callbackfunc(jsonData)
{
if(jsonData.p_links != null && jsonData.p_links != "")
{
document.getElementById("ed-0_iframe").contentWindow.document.getElementsByTagName("body")[0].innerHTML += "<br/><a href='" + jsonData.p_links + "'>" + jsonData.p_links + "</a>";
}
else
{
alert("There was an error protecting your links");
}
aObj.removeScriptTag();
}


//Thanks to http://www.xml.com/pub/a/2005/12/21/json-dynamic-script-tag.html
function JSONscriptRequest(fullUrl)
{
    this.fullUrl = fullUrl;
    this.noCacheIE = '&noCacheIE=' + (new Date()).getTime();
    this.headLoc = document.getElementsByTagName("head").item(0);
    this.scriptId = 'JscriptId' + JSONscriptRequest.scriptCounter++;
}

JSONscriptRequest.scriptCounter = 1;

JSONscriptRequest.prototype.buildScriptTag = function ()
{
        this.scriptObj = document.createElement("script");
        this.scriptObj.setAttribute("type", "text/javascript");
        this.scriptObj.setAttribute("charset", "utf-8");
        this.scriptObj.setAttribute("src", this.fullUrl + this.noCacheIE);
        this.scriptObj.setAttribute("id", this.scriptId);
}

JSONscriptRequest.prototype.removeScriptTag = function ()
{
this.headLoc.removeChild(this.scriptObj); 
}


JSONscriptRequest.prototype.addScriptTag = function ()
{
this.headLoc.appendChild(this.scriptObj);
}


but the code is from an IPB mod and there's something in the .js file that is stopping the mod from working but i don't know js that well

what the mod is for: adds a text area box and a submit button (within 'Additional Options...') so people can add links that will be 'cloaked' and then added to the post box automatically

what it's not doing: putting the links in the post box

steve51184


DoctorMalboro



DoctorMalboro

You would like it as an extra form or in the editor?

steve51184

Quote from: DoctorMalboro on August 19, 2010, 08:04:44 PM
You would like it as an extra form or in the editor?

well would it work in the editor? if so then that'd be the best option (and with a 'cloak links' button next to post/preview) but if it can't be done then an extra form :)


steve51184


Advertisement: