PDA

View Full Version : Custom Header Extension :: Not showing for guests


AlexBrock
03-10-2015, 08:18 PM
I've hit a stumbling block when it comes to using a custom API Extension for vB5, I'm hoping someone else may have experienced this and have a solution.

I've developed an API Extension which pulls in an external header to make our forum more inline with our main site. This is all working perfectly for my admin account, however if I log out the header is no longer visible. I've check the user permissions in the Usergroup Manager tab and nothing stands out as being a problem.

Any advice would be greatly appreciated.

Lynne
03-11-2015, 01:26 AM
Perhaps post your code so we can see what you did. It's really impossible to tell what the problem is without know exactly what you did.

AlexBrock
03-12-2015, 03:20 PM
That would be helpful wouldn't it!

So in the template file I have:
{vb:data returnHead, options, mcheadfunction}
{vb:raw returnHead}

Which is calling my API:

<?php
class Mcheadd_Api_Options extends vB_Api_Extensions
{
public $product = 'mcheadd';

public $developer = 'Developer';
public $title = 'Pull in Domain Name header';
public $minver = '5.1.0';
// public $maxver = '5.9.99';// Use vB default.
// public $infourl = 'Domain Name';
// public $checkurl = 'Domain Name';

public $AutoInstall = 0;
public $extensionOrder = 10;

public function mcheadfunction(){
// create curl resource
$ch = curl_init();

// set url
curl_setopt($ch, CURLOPT_URL, "DomainName");

//return the transfer as a string
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

// $output contains the output string
$output = curl_exec($ch);

$page_parts = explode('<!-- Top navigtation -->', $output);
$page_parts = explode('<!-- DAB container -->', $page_parts[1]);

$header_html = '<div id="header-mc">' . $page_parts[0] ;

$header_html = str_replace("'", '"', $header_html);

$output = str_replace(array("\r\n", "\r"), "\n", $header_html);
$lines = explode("\n", $output);
$new_lines = array();

foreach ($lines as $i => $line) {
if(!empty($line))
$new_lines[] = trim($line);
}
$pageStuff = implode($new_lines);

echo '<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>';

echo "<script> $(document).ready(function(){ $('#outer-wrapper').prepend('" . $pageStuff . "'); $('.hamburger').click(function(){ $('#nav_top ul').toggleClass('mobile_show'); });}); </script>";

curl_close($ch);

}

}

AlexBrock
03-18-2015, 11:50 PM
Sorry to bug, Lynne. Do you have any idea what could be happening with this?

Lynne
03-20-2015, 03:56 PM
I really have not spent much time doing coding for vB5 which is why I didn't answer. I do wonder why do you have both these lines when the second one will replace the first one?
$page_parts = explode('<!-- Top navigtation -->', $output);
$page_parts = explode('<!-- DAB container -->', $page_parts[1]);

Also, echos aren't a good idea (unless it is debug code). I am pretty sure you want to do a return with the html and then spit it out into a template.

Other than that, there really isn't enough information for us to be able to 'install' it on our own test site and see what is going on.

AlexBrock
03-20-2015, 05:37 PM
Thanks for the reply.

I have both of those lines so that I'm only using the code in between those two comments to avoid unnecessary markup.

I've tried even doing a simple return of a string, which also doesn't appear when the user isn't logged in but is there if logged in.

<?php
class Mcheadd_Api_Options extends vB_Api_Extensions
{
public $product = 'mcheadd';

public $developer = '';
public $title = 'Pull in Site header';
public $minver = '5.1.0';
// public $maxver = '5.9.99';// Use vB default.
// public $infourl = '';
// public $checkurl = '';

public $AutoInstall = 0;
public $extensionOrder = 10;

public function mcheadfunction(){
return 'Test String';
}

}

these are stored in core/packages/mcheadd/api if that's any help

--------------- Added 1426877795 at 1426877795 ---------------

Lynne!

Changing the echo to return worked, not sure why but it did!

Thanks for all your help, you're my hero.