Jump to content


PHP and JavaScript Help


  • You cannot reply to this topic
No replies to this topic

#1 Saffleur

    Young Padawan

  • Members
  • Pip
  • 6 posts

Posted 06 August 2008 - 08:09 AM

I've been working on a modification that is for phpBB and other softwares of it's ilk.

What it does is stores the data in the database as this...

ALTER TABLE phpbb_users ADD user_xfire varchar( 255 ) NOT NULL DEFAULT '';

This stores and even returns a value on the editing of a profile so that part works.

This is what is used on the template side...

<!-- IF postrow.U_XFIRE --><li class="xfire-icon"><a href="xfire:add_friend?user={postrow.U_XFIRE}" onclick="return xfireCheck();"><img src="http://icon.alanedwardes.com/xfire/{postrow.U_XFIRE}" title="{L_XFIRE} {user_xfire}" border="0" /></a></li><!-- ENDIF -->

As you can see I am using a third party script for that but I have something done up I think may work but isn't.

<?php
error_reporting(0); 
function xfire_online($user){
$target_url = ('http://www.xfire.com/profile/'.$user.'/');
$ch = curl_init();
curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);
curl_setopt($ch, CURLOPT_URL,$target_url);
curl_setopt($ch, CURLOPT_FAILONERROR, true);
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
$do = curl_exec($ch);
if (!$do) echo('Error');

$replace = str_replace("\n", "", $do);
$replace = str_replace("	", "", $replace);
$replace = str_replace("<strong>Status</strong><br />Online</p><p><strong>", "wooitsonline", $replace);

preg_match("/wooitsonline/", $replace, $matches);

	if($matches[0] == 'wooitsonline'){
	return 'online';
	}else{
	return 'offline';
	}
	
}

$username = $_GET["username"];

$image = xfire_online("$username");

if ($image == 'online') echo('Online');

if ($image == 'offline') echo('Offline');

?>


The JavaScript part is this...the php script generates a query to check xfires user page for online status which returns an image. I want it so when they click the image it uses the url to add a person, if they do not have xfire installed and it returns an error I want a popup box to open xfires download page. I've tried this and this is what I have...

var activex = ((navigator.userAgent.indexOf('Win')  != -1) && (navigator.userAgent.indexOf('MSIE') != -1) && (parseInt(navigator.appVersion) >= 4 ));
var CantDetect = ((navigator.userAgent.indexOf('Safari')  != -1) || (navigator.userAgent.indexOf('Opera')  != -1));

function oopsPopup() {
    if((navigator.language && navigator.language.indexOf("ja") != -1) || (navigator.systemLanguage && navigator.systemLanguage.indexOf("ja") != -1) || (navigator.userLanguage && navigator.userLanguage.indexOf("ja") != -1)) {
        var URLtoOpen = "http://www.xfire.com/downloads/";
    } else {
        var URLtoOpen = "http://www.xfire.com/download/now/";
    }
	var windowName = "oops";
	var popW = 540, popH = 305;
	var scrollB = 'no';
	w = screen.availWidth;
	h = screen.availHeight;
	var leftPos = (w-popW)/2, topPos = (h-popH)/2;
	oopswindow = window.open(URLtoOpen, windowName,'width=' + popW + ',height=' + popH + ',scrollbars=' + scrollB + ',screenx=' +leftPos +',screeny=' +topPos +',top=' +topPos +',left=' +leftPos);
	return false;
}

if(typeof(detected) == "undefined" && activex) {
    document.write(
        ['<script language="VBscript">',
        'Function isXfireInstalled()',
        'on error resume next',
        'Set oXfire = CreateObject("Xfire.Detection")',
        'isXfireInstalled = IsObject(oXfire)',
        'Set oXfire = nothing',
        'End Function',
        '</script>'].join("\n")
    );
}

function xfireCheck() {
    if(CantDetect) {
        return true;
    } else if(!activex) {
        var xfireMime = navigator.mimeTypes["application/x-xfire"];
        detected = true;
        if(typeof(xfireMime) == "object") {
            return true;
        } else {
            return oopsPopup();
        }
    } else {
        if(isXfireInstalled()) {
            detected = true;
            return true;
        }
    }
    
    detected = true;
    return oopsPopup();
}

function loadDetection() {
    if(document.getElementById && document.getElementsByTagName) {
        if (window.addEventListener) window.addEventListener('load', addDetection, false);
        else if (window.attachEvent) window.attachEvent('onload', addDetection);
    }
}

function addDetection() {
    var pageLinks = document.getElementsByTagName("a");
    for (var i=0; i < pageLinks.length; i++) {
        if(pageLinks[i].childNodes[0] && pageLinks[i].childNodes[0].src) {
{
                pageLinks[i].onclick = function sChk() { return xfireCheck(); }
            }
        }
    }
}

loadDetection();

It's like I am "almost" done but can't finish it for some reason. Any help would really be appreciated.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users