Passing user ID and other variables to a wrapper

Your code modifications and patches you want to share with others.
Locked
jrmathis
Joomla! Fledgling
Joomla! Fledgling
Posts: 3
Joined: Sat Jun 20, 2009 1:31 am

Passing user ID and other variables to a wrapper

Post by jrmathis » Sat Jun 20, 2009 1:40 am

Hey everyone, I've been scratching my head over this for a few days..

I've found and tried a couple of solutions to this problem, but none of them are working:

What I need is to have the user ID of the currently logged in user to my iframe.

I have attempted to modify the default.php for com_wrapper (both in the core components as well as in the template) as such:

Code: Select all

<iframe <?php echo $this->wrapper->load; ?>
	id="blockrandom"
	name="iframe"
	src="<?php echo $this->wrapper->url."?userid=".$user->id; ?>"
Of course, I placed this at the top of the file:

Code: Select all

$user =& JFactory::getUser();
However, the iframe url is not changed at all when I view the source of the loaded page.

I even placed a comment in each file I file I modified to see which file was actually being used to load the wrapper, ie:

Code: Select all

<!-- comment specifying which file is being loaded -->
<iframe ...
But when I load the page and view source, there is no comment before the iframe element.

Can anyone help with this? If you need any more details, just ask.

Thanks in advance!

User avatar
ooffick
Joomla! Master
Joomla! Master
Posts: 11393
Joined: Thu Jul 17, 2008 3:10 pm
Location: Ireland
Contact:

Re: Passing user ID and other variables to a wrapper

Post by ooffick » Sat Jun 20, 2009 10:29 am

You might want to delete the Joomla Cache.
Moreover, you don't need to hack the Joomla Core file for that, you can use a template overwrite as well:
  1. create a folder in your template folder called "html" (if it doesn't exists)
  2. create a folder in that html folder called "com_wrapper" (if it doesn't exists)
  3. create a folder in that com_wrapper folder called "wrapper" (if it doesn't exists)
  4. copy the file .../components/com_wrapper/views/wrapper/tmpl/default.php in this .../templates/[your-template]/html/com_wrapper/wrapper/ folder
  5. open that file and change it instead of the original
  6. save the file
Olaf
Olaf Offick - Global Moderator
learnskills.org

jrmathis
Joomla! Fledgling
Joomla! Fledgling
Posts: 3
Joined: Sat Jun 20, 2009 1:31 am

Re: Passing user ID and other variables to a wrapper

Post by jrmathis » Sat Jun 20, 2009 4:16 pm

Hmm, the template override is what I tried first, but I'm sure you're right about the cache being the problem. So I've changed all files back to their originals except the template's default.php.

However, I've tried to clean the cache but Tools -> Clean Cache comes up empty with nothing to clean. I've deleted all the files in /cache/ and cleared my browser's cache, as well.

Still having the same problem.. :(

User avatar
ooffick
Joomla! Master
Joomla! Master
Posts: 11393
Joined: Thu Jul 17, 2008 3:10 pm
Location: Ireland
Contact:

Re: Passing user ID and other variables to a wrapper

Post by ooffick » Sat Jun 20, 2009 4:25 pm

Do you have a URL so I can have a look at it?

Olaf
Olaf Offick - Global Moderator
learnskills.org

jrmathis
Joomla! Fledgling
Joomla! Fledgling
Posts: 3
Joined: Sat Jun 20, 2009 1:31 am

Re: Passing user ID and other variables to a wrapper

Post by jrmathis » Sat Jun 20, 2009 4:41 pm

Yes, here you go:

http://swemsar.com/index.php?option=com ... d=35:forms

The only important thing is that the current user ID is appended to the iframe src url.
Here is the code I have in the template override:

Code: Select all

<!-- html/com_wrapper/wrapper/default.php -->
<iframe <?php echo $this->wrapper->load; ?>
	id="blockrandom"
	name="iframe"
	src="<?php echo $this->wrapper->url."?jid=$user->id"; ?>"
	width="<?php echo $this->params->get( 'width' ); ?>"
	height="<?php echo $this->params->get( 'height' ); ?>"
	scrolling="<?php echo $this->params->get( 'scrolling' ); ?>"
	align="top"
	frameborder="0"
	class="wrapper<?php echo $this->params->get( 'pageclass_sfx' ); ?>">
	<?php echo JText::_( 'NO_IFRAMES' ); ?>
</iframe>

User avatar
ooffick
Joomla! Master
Joomla! Master
Posts: 11393
Joined: Thu Jul 17, 2008 3:10 pm
Location: Ireland
Contact:

Re: Passing user ID and other variables to a wrapper

Post by ooffick » Sat Jun 20, 2009 4:50 pm

Well, your link is an article not the wrapper, you can see your changes here:
http://swemsar.com/index.php?option=com ... ew=wrapper

I don't have the proper ItemID so that's why the URL is missing.

Olaf
Olaf Offick - Global Moderator
learnskills.org

to-me
Joomla! Fledgling
Joomla! Fledgling
Posts: 2
Joined: Tue Oct 06, 2009 1:27 pm

Re: Passing user ID and other variables to a wrapper

Post by to-me » Tue Oct 06, 2009 1:32 pm

Hi everyone!

I did what you said. In my application index.php i put those lines :
echo " username: ".$app_user;
echo "session ".$sessioncookie;

Results: nothing
I've got empty fields but no php errors.

Could you help me please?

User avatar
ooffick
Joomla! Master
Joomla! Master
Posts: 11393
Joined: Thu Jul 17, 2008 3:10 pm
Location: Ireland
Contact:

Re: Passing user ID and other variables to a wrapper

Post by ooffick » Tue Oct 06, 2009 2:22 pm

to-me wrote:I did what you said. In my application index.php i put those lines :
echo " username: ".$app_user;
echo "session ".$sessioncookie;

Results: nothing
I've got empty fields but no php errors.
And how did you declare the $app_user or $sessioncookie variable?

Olaf
Olaf Offick - Global Moderator
learnskills.org

to-me
Joomla! Fledgling
Joomla! Fledgling
Posts: 2
Joined: Tue Oct 06, 2009 1:27 pm

Re: Passing user ID and other variables to a wrapper

Post by to-me » Wed Oct 07, 2009 4:33 am

Thanks for answer.

I declared them in my index.php like this:
defined( '_JosAppG' ) or die( 'Restricted access' );


// DB login information
$jos_username = 'C266071_standard'; // restrict user to read just this table if possible
$jos_password = '****';
$jos_database = 'C266071_maneva';
$jos_host = '****';

/****** Connect to MySQL ******/
if(!extension_loaded('mysql')){
echo "
ERROR: PHP is not configured to connect to MySQL on this machine. Please see this page for help on how to configure MySQL.
";
exit;}

if(!mysql_connect($jos_host, $jos_username, $jos_password)){
echo "
ERROR: can not connect to server.
";
exit;}

/****** Connection Charset ********/
@mysql_query("SET NAMES 'utf8'");
/****** Select DB ********/
if(!mysql_select_db($jos_database)){
echo "
ERROR: can not access database.
";
exit;
exit;}

if(!$result = @mysql_query("select * from jos_session where session_id='".$sessioncookie."'")){
echo "
ERROR: can not find session in database.
";
$app_user='';
}else{
$row = mysql_fetch_assoc($result);
$app_user=$row['username']; }

I followed this tuto:
http://www.kratvej28c.dk/joomla/index.p ... n-php-code
Last edited by ooffick on Wed Oct 07, 2009 7:43 am, edited 1 time in total.
Reason: Mod Note: Deleted passwords

User avatar
ooffick
Joomla! Master
Joomla! Master
Posts: 11393
Joined: Thu Jul 17, 2008 3:10 pm
Location: Ireland
Contact:

Re: Passing user ID and other variables to a wrapper

Post by ooffick » Wed Oct 07, 2009 7:59 am

ok, you will need to use define $sessioncookie in your php script:

Since you probably don't use the Joomla in your script, try to add this to the beginning of your script:

Code: Select all

$sessioncookie = $_GET['sessioncookie']
Olaf
Olaf Offick - Global Moderator
learnskills.org


Locked

Return to “Core Hacks and Patches”