Forums / Cotonti / Extensions / Support / Sidepanel plugin always redirects to itself at login

foxhound
#1 2013-10-22 16:26

Working on a new plugin, pretty simple probably but its actually the first one I ever got to work. :)
However, the plugin seems to have the nasty habit to redirect a users login to itself. With that I mean if a user is browsing the website and wishes to login after doing so the site will direct him to the plugin page "index.php?e=sidepanel".
The plugin itself is really simple, with the default setup file (sidepanel.setup.php), which is empty except the minimal requirements and in my sidepanel.php I have the following: 

<?php

/* ====================
  [BEGIN_COT_EXT]
  Hooks=standalone
  [END_COT_EXT]
  ==================== */

/**
 * Contact Plugin for Cotonti CMF
 *
 * @package contact
 * @version 2.1.0
 * @author Cotonti Team
 * @copyright (c) Cotonti Team 2008-2013
 * @license BSD
 */
defined('COT_CODE') or die('Wrong URL');

$tplfile = cot_import('tpl', 'G', 'TXT');
$mskin = cot_tplfile(array('sidepanel', $tplfile), 'plug');
$t = new XTemplate($mskin);

?>

 

The sidepanel is created in my footer with the following code: 

<div id="extruderRight" class="{title:'User Control Panel', url:'index.php?e=sidepanel'}"></div>

Yes, I am using "redirect back on login" and I made 100% sure I am not actually on the plugin page.
Is there also a way to prevent from people accessing that "index.php?e=sidepanel"? Cause I have to make it standalone else it does not work, but than you can access it in a standalone page (obviously) which will than show the contents of my tpl in a page.

 

I am trying to make a plugin for this sitepanel: http://pupunzi.com/#mb.components/mb.extruder/extruder.htm

<img src="http://www.armaholic.com/datas/thumbs/green-sea-battalion-uniforms-version-03-preview_4.jpg" alt="green-sea-battalion-uniforms-version-03-" />
Twiebie
#2 2013-10-22 16:48

If I correctly understand what your goal is, I don't think you need a plugin for this.

Simply code it as explained in the documentation on their website.

If you want to use a seperate TPL for it you could include it with: {FILE "{PHP.cfg.themes_dir}/{PHP.usr.theme}/tpl/foobar.tpl"}

foxhound
#3 2013-10-22 17:05

I need this to work with xtemplate as I plan to use this as the user control panel, for his PM's, his profile and a lot more. I only want to show the content the member has access to in that panel. Thats why I figured I had to make it a plugin with its own tpl so I can use if, else statements etc ;)

<img src="http://www.armaholic.com/datas/thumbs/green-sea-battalion-uniforms-version-03-preview_4.jpg" alt="green-sea-battalion-uniforms-version-03-" />
Twiebie
#4 2013-10-22 17:36

You can do that in the TPL aswell.

<!-- IF {PHP.usr.id} > 0 -->
Show something
<!-- ENDIF -->

Have a look at: http://www.cotonti.com/docs/ext/themes/

foxhound
#5 2013-10-22 18:08

Uhm, yes. That is why I made it a tpl. It needs to be a tpl to work with the xtemplate.
The issue is not with that.

 

The issue is with the fact this plugin causes a user to be (re)directed to "index.php?e=sidepanel" after succesfull login. And of course it should not do that. I would like to know how to prevent that.
sidepanel is the plugin I created for this.
I tried to make the plugin global instead of standalone but than it wont work at all.

 

<img src="http://www.armaholic.com/datas/thumbs/green-sea-battalion-uniforms-version-03-preview_4.jpg" alt="green-sea-battalion-uniforms-version-03-" />
Twiebie
#6 2013-10-22 18:26

Can you show the rest of your code, because at the moment I'm a bit confused.

foxhound
#7 2013-10-22 18:46

In my first post I linked you to the source, you can use that in case you need more. I can only paste here my edits I have made but posting all js files is not needed I guess?

In the footer I have the following: 

<!-- sidebar stuff -->
	<!-- <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.js"></script> -->
	<script type="text/javascript" src="inc/jquery.hoverIntent.min.js"></script>
	<script type="text/javascript" src="inc/jquery.mb.flipText.js"></script>
	<script type="text/javascript" src="inc/mbExtruder.js"></script>
	<script type="text/javascript">

		$(function(){
			if (self.location.href == top.location.href){}
			$("#extruderRight").buildMbExtruder({
				position:"right",
				width:300,
				extruderOpacity:.8,
				textOrientation:"tb",
				onExtOpen:function(){},
				onExtContentLoad:function(){},
				onExtClose:function(){}
			});
		});
	</script>
<!-- <div id="extruderRight" class="{title:'User Control Panel ', url:'parts/extruderRight.html'}"></div> -->
<div id="extruderRight" class="{title:'User Control Panel', url:'index.php?e=sidepanel'}"></div>

 

Than I have my sidepanel setup php file: 

<?php
/* ====================
[BEGIN_COT_EXT]
Code=sidepanel
Name=sidepanel
Category=User control panel
Description= A sidepanel you can use as a user control area.
Version=1.0
Date=2013-10-22
Author=
Copyright=
Notes=
Auth_guests=RW
Lock_guests=12345A
Auth_members=RW
Lock_members=12345A
[END_COT_EXT]
==================== */

/**
 * Sidepanel Plugin for Cotonti CMF
 *
 * @package sidepanel
 * @version 1.0
 * @author
 * @copyright (c)
 * @license BSD
 */
?>

 

Than my sidepanel.php: 

<?php

/* ====================
  [BEGIN_COT_EXT]
  Hooks=standalone
  [END_COT_EXT]
  ==================== */

/**
 * Sidepanel Plugin for Cotonti CMF
 *
 * @package sidepanel
 * @version 1.0
 * 
 * @copyright (c)
 * @license BSD
 */
defined('COT_CODE') or die('Wrong URL');

$tplfile = cot_import('tpl', 'G', 'TXT');
$mskin = cot_tplfile(array('sidepanel', $tplfile), 'plug');
$t = new XTemplate($mskin);

?>

 

And I have this is my sidepanel.tpl 

<!-- BEGIN: MAIN -->
<!--
  ~ /*******************************************************************************
  ~  jquery.mb.components
  ~  file: extruderRight.html
  ~
  ~  Copyright (c) 2001-2013. Matteo Bicocchi (Pupunzi);
  ~  Open lab srl, Firenze - Italy
  ~  email: matteo@open-lab.com
  ~  site: 	http://pupunzi.com
  ~  blog:	http://pupunzi.open-lab.com
  ~ 	http://open-lab.com
  ~
  ~  Licences: MIT, GPL
  ~  http://www.opensource.org/licenses/mit-license.php
  ~  http://www.gnu.org/licenses/gpl.html
  ~
  ~  last modified: 04/01/13 17.13
  ~  ******************************************************************************/
  -->

<div class="voice {}"><span class="label"><a class="label" href="http://www.open-lab.com">Open Lab</a></span></div>
<div id="tw" class="voice {panel:'parts/extr.tw.html'}"><a class="label" href="http://twproject.com" target="_blank">teamwork</a></div>
<div class="voice {panel:'parts/extr.mti.html'}"><span class="label">Morethanicons</span></div>
<!-- IF {PHP.usr.isadmin} -->
	<div class="voice {panel:'parts/extr.network.html'}"><span class="label">Only admins can see this</span></div>
<!-- ENDIF -->
<div class="voice {disabled:true}"><span class="label">Microsoft Internet Explorer</span></div>
<div class="voice {}"><a class="label" href="http://firefox.com" target="_blank">get FireFox</a></div>
<div class="voice {}"><a class="label" href="http://www.google.com/chrome" target="_blank">get Chrome</a></div>
<div class="voice {}"><a class="label" href="http://www.apple.com/safari/" target="_blank">get Safari</a></div>
<div class="voice {}"><a class="label" href="http://www.opera.com/" target="_blank">get Opera</a></div>

<script type="text/javascript"></script>

<!-- END: MAIN -->


In the tpl I made one if statement purely for testing. Since it works my plugin actually works, except for tht redirect to its standalone page after succesfull login.
Please bare in mind, I do not really understand so much about making plugins, I am always reading and trying till I drop ;)

<img src="http://www.armaholic.com/datas/thumbs/green-sea-battalion-uniforms-version-03-preview_4.jpg" alt="green-sea-battalion-uniforms-version-03-" />
Twiebie
#8 2013-10-22 22:04

If you want to do it with a plugin you should set the hook to ajax.

Call it like this:

<?php defined('COT_CODE') or die('Wrong URL');
/* ====================
  [BEGIN_COT_EXT]
  Hooks=ajax
  [END_COT_EXT]
  ==================== */

$t = new XTemplate(cot_tplfile('sidepanel', 'plug'));

$t->parse();
$t->out();
<!-- sidebar stuff -->
<div id="extruderRight" class="{title:'User Control Panel', url:'index.php?r=sidepanel'}"></div>

Note the index.php?r=sidepanel

foxhound
#9 2013-10-23 01:06

It is almost working right, I will get to that at the end.

First, thank you very much for pointing me in the right direction!!
If it is not to much asked, why does the hook have to be ajax? And yes indeed, why is the "e" replaced with an "r"? I gues both things are connected?


Now, about this almost working right.
I have applied the changes you wrote above and it is working correctly, no more redirects after login. However, the output from the tpl is now done twice, it is looping 2x so to say. That means I see the same menu 2 times underneath eachother.
Could this have to be cause it is now ajax? Should I put it in an ajx block and add the ajax class to the url?
As described here: http://www.cotonti.com/docs/devel/ajax_helpers

<img src="http://www.armaholic.com/datas/thumbs/green-sea-battalion-uniforms-version-03-preview_4.jpg" alt="green-sea-battalion-uniforms-version-03-" />
Twiebie
#10 2013-10-23 01:22

Remove:

<div class="content"> </div>

The 'r' is so that it doesn't include header.php and footer.php.

foxhound
#11 2013-10-23 02:10
#38222 Twiebie:

Remove:

<div class="content"> </div>

 

Sorry, it must be cause its late but that class is not present as far as I can tell. Not in the sidepanel tpl at least and also not in the php. I am not sure where you want me to remove it from?


Thanks for the info on the "r", thats very usefull and I will try to remember that :)

<img src="http://www.armaholic.com/datas/thumbs/green-sea-battalion-uniforms-version-03-preview_4.jpg" alt="green-sea-battalion-uniforms-version-03-" />
Twiebie
#12 2013-10-23 02:47

Try to build up your sidepanel.tpl file from scratch, I think it's in there.

I've never used this Extruder thing before, so I can't be of much more assistence.

foxhound
#13 2013-10-28 16:00

I had to comment out the following line in sidepanel.php
 

// $t->parse(); disabled otherwise the contents of tpl shows 2x


 

Now it properly works and allows me to use the conditions etc. Thanks for all the help!!

<img src="http://www.armaholic.com/datas/thumbs/green-sea-battalion-uniforms-version-03-preview_4.jpg" alt="green-sea-battalion-uniforms-version-03-" />
Twiebie
#14 2013-10-28 16:07

Ah, sorry. Overlooked that.

foxhound
#15 2013-10-28 17:57

No problem at all, you really helped me  lot getting this done.
I knew we were close to getting it to work so spending some time looking at the code is good for my expereince. After doing all possible changes to the tpl I soon figured the issue was elsewhere ;)

<img src="http://www.armaholic.com/datas/thumbs/green-sea-battalion-uniforms-version-03-preview_4.jpg" alt="green-sea-battalion-uniforms-version-03-" />