custom shortcode help

e107 CMS » Forums » e107 Themes » Theme Developer Discussion << Previous thread | Next thread >>
Go to page  1 2
VR6Pete
Dec 12 2011, 09:02AM
Registered Member #2353
Joined: Jul 28 2003, 11:21AM
Location: Stoke-on-Trent
Posts: 1246
I've got this shotcode for a theme im tweaking for my website...

global $tp;global $sql;parse_str($parm);$pm_file1 = e_PLUGIN."pm/pm_func.php";include_once(is_readable($pm_file1) ? $pm_file1 : e_PLUGIN."pm/pm_func.php"); $pm_inbox = pm_getInfo("inbox"); $lan_file = e_PLUGIN."pm/languages/".e_LANGUAGE.".php";include_once(is_readable($lan_file) ? $lan_file : e_PLUGIN."pm/languages/English.php");$sql->db_Select_gen($qry);$sql -> db_Fetch();$new = $sql->db_Count("private_msg", "(*)", "WHERE pm_sent > '.USERLV.' AND pm_read = 0 AND pm_to = '".INTVAL(USERID)."' AND pm_read_del != 1"); if(intval($pm_inbox['inbox']['unread']) > 0){    $messageSpam = "".intval($pm_inbox['inbox']['unread'])." ".(intval($pm_inbox['inbox']['unread']) == 1 ? "New message" : "New messages"); } if (USER == TRUE && $new > 0){        $ret = "  <script language='JavaScript'>jQuery(document).ready(function()  {    jQuery.sticky('<a href=".e_PLUGIN_ABS."pm/pm.php?inbox><b>You have $messageSpam</b></a>');  });            </script><div class='topnav'>                          &nbsp;<a href='".e_PLUGIN_ABS."pm/pm.php?inbox'>$messageSpam</a>&nbsp; <a href='".e_BASE."usersettings.php'>".X_THEME_16."</a> <a href='".e_BASE."user.php?id.".USERID."'>".X_THEME_17."</a> <a href='".e_BASE."index.php?logout'>".X_THEME_18."</a>          </div>";   }  elseif (USER == TRUE || $new = 0){         $ret = " <div class='topnav'>        <a href='".e_PLUGIN_ABS."pm/pm.php?inbox'>Your Messages</a>&nbsp<a href='".e_BASE."usersettings.php'>".X_THEME_16."</a> <a href='".e_BASE."user.php?id.".USERID."'>".X_THEME_17."</a> <a href='".e_BASE."index.php?logout'>".X_THEME_18."</a> </div>"; }  else{ $ret = " <div class='topnav'> <a href='".e_BASE."signup.php'>".X_THEME_9."</a> <a href='".e_BASE."login.php'>".X_THEME_10."</a> </div>"; if (ADMIN){ $ret .= " <a href='".e_ADMIN."admin.php'>".X_THEME_19."</a> </div>";}}  if (!USER && defined("LOGINMESSAGE") && LOGINMESSAGE != "")  {    $ret = "                    <div class='topnav'>                        ".X_THEME_20." <a href='".e_BASE."login.php'>".X_THEME_21."</a> ".X_THEME_22." <a href='".e_BASE."fpw.php'>".X_THEME_23."</a>                    </div>        ";  }  return $ret;


for some reason the admin option doesnt display when logged in as an admin... any ideas?

I'd like to take this a step further too. and de-clutter how it displays by instead of having Inbox Outbox Send Message options, I want these as a dropdown menu called "Messages"...

Thanks.

Pete
[ Edited Jan 16 2012, 06:12AM ]
Go to top
Website
VR6Pete
Dec 15 2011, 09:24AM
Registered Member #2353
Joined: Jul 28 2003, 11:21AM
Location: Stoke-on-Trent
Posts: 1246
I still cant get my admin link to display if you are logged in with admin rights - can anyone offer any advice?
Go to top
Website
inebriated
Jan 08 2012, 07:18PM
  • e107 Support Team
  • e107 Documentation Team
Registered Member #33479
Joined: Jan 15 2007, 07:52PM
Location: East London, UK
Posts: 705
Try using the following if statement instead of the one you posted.

if (ADMIN == TRUE) {
[ Edited Jan 08 2012, 07:20PM ]
Go to top
Website
septor
Jan 14 2012, 03:06AM
  • e107 Site administrator
  • e107 Security Team
  • e107 Support Team
  • e107 Documentation Team
Registered Member #37
Joined: Aug 11 2002, 03:20AM
Location: United States
Posts: 2659
$new = $sql->db_Count("private_msg", "(*)", "WHERE pm_sent > '.USERLV.' AND pm_read = 0 AND pm_to = '".USERID."' AND pm_read_del != 1");


Should be:

 $new = $sql->db_Count("private_msg", "(*)", "WHERE pm_sent > '.USERLV.' AND pm_read = 0 AND pm_to = '".intval(USERID)."' AND pm_read_del != 1");


I'll have more when I get home from work.
Go to top
Website
VR6Pete
Jan 14 2012, 12:01PM
Registered Member #2353
Joined: Jul 28 2003, 11:21AM
Location: Stoke-on-Trent
Posts: 1246
cool, I've changed that now, that code is about 4 years old, but has been working ok, but I've changed it now
Go to top
Website
septor
Jan 14 2012, 05:04PM
  • e107 Site administrator
  • e107 Security Team
  • e107 Support Team
  • e107 Documentation Team
Registered Member #37
Joined: Aug 11 2002, 03:20AM
Location: United States
Posts: 2659
So apparently I fail at typing at 6AM.

On line 9, change the part that says '".USERID."' to '".intval(USERID)."'

Are you still wondering how to make it say "1 message" and "2 messages"?
Go to top
Website
VR6Pete
Jan 15 2012, 12:59PM
Registered Member #2353
Joined: Jul 28 2003, 11:21AM
Location: Stoke-on-Trent
Posts: 1246
Line 9 are you sure?

I want it to say:

Message: 1
And

Messages: 2 respectively.
Go to top
Website
nlstart
Jan 16 2012, 01:27AM
nlstart
  • e107 Site administrator
  • e107 Core developer
  • e107 Translation Team Leader
Registered Member #29855
Joined: Aug 18 2006, 01:12AM
Location: Utrecht, The Netherlands
Posts: 5493
I would like to suggest this: [-link-]
[ Edited Jan 16 2012, 01:27AM ]
Go to top
Website
VR6Pete
Jan 16 2012, 05:24AM
Registered Member #2353
Joined: Jul 28 2003, 11:21AM
Location: Stoke-on-Trent
Posts: 1246
Hi all,

Well its been a little while since I initially posted this, and have made a few changes, but essentially its still not working as it should be

below is my current .sc for this...

global $tp;
global $sql;
parse_str($parm);
$pm_file1 = e_PLUGIN."pm/pm_func.php";
include_once(is_readable($pm_file1) ? $pm_file1 : e_PLUGIN."pm/pm_func.php");

$pm_inbox = pm_getInfo("inbox");

$lan_file = e_PLUGIN."pm/languages/".e_LANGUAGE.".php";
include_once(is_readable($lan_file) ? $lan_file : e_PLUGIN."pm/languages/English.php");
$sql->db_Select_gen($qry);
$sql -> db_Fetch();
$new = $sql->db_Count("private_msg", "(*)", "WHERE pm_sent > '.USERLV.' AND pm_read = 0 AND pm_to = '".INTVAL(USERID)."' AND pm_read_del != 1");

if(intval($pm_inbox['inbox']['unread']) > 0){
    $messageSpam = "".intval($pm_inbox['inbox']['unread'])." ".(intval($pm_inbox['inbox']['unread']) == 1 ? "New message" : "New messages");

}

if (USER == TRUE && $new > 0){
        $ret = "  <script language='JavaScript'>
jQuery(document).ready(function()
  {
    jQuery.sticky('<a href=".e_PLUGIN_ABS."pm/pm.php?inbox><b>You have $messageSpam</b></a>');
  });            
</script>
<div class='topnav'>
						  &nbsp;<a href='".e_PLUGIN_ABS."pm/pm.php?inbox'>$messageSpam</a>&nbsp; <a href='".e_BASE."usersettings.php'>".X_THEME_16."</a> <a href='".e_BASE."user.php?id.".USERID."'>".X_THEME_17."</a> <a href='".e_BASE."index.php?logout'>".X_THEME_18."</a> 			</div>";
  
}  elseif (USER == TRUE || $new = 0)
{
        
$ret = "

<div class='topnav'>
        <a href='".e_PLUGIN_ABS."pm/pm.php?inbox'>Your Messages</a>&nbsp<a href='".e_BASE."usersettings.php'>".X_THEME_16."</a> <a href='".e_BASE."user.php?id.".USERID."'>".X_THEME_17."</a> <a href='".e_BASE."index.php?logout'>".X_THEME_18."</a> 
</div>
"; 
}  
else
{

$ret = "

<div class='topnav'>

<a href='".e_BASE."signup.php'>".X_THEME_9."</a> <a href='".e_BASE."login.php'>".X_THEME_10."</a>

</div>";

if (ADMIN)
{

$ret .= "

<a href='".e_ADMIN."admin.php'>".X_THEME_19."</a>

</div>";
}
}
  if (!USER && defined("LOGINMESSAGE") && LOGINMESSAGE != "")
  {
    $ret = "
    				<div class='topnav'>
						".X_THEME_20." <a href='".e_BASE."login.php'>".X_THEME_21."</a> ".X_THEME_22." <a href='".e_BASE."fpw.php'>".X_THEME_23."</a>
					</div>
    	";
  }
  return $ret;


I think there is a little overlap on using my old sql query and the pm functions.... in the interest of keeping DB queries at a minimum, can anyone offer more optimised code for the above?

Nlstart, I tweaked your code into my shortcode (see above) but still doesnt display the admin link when logged in as an admin

any suggestions apreciated..
Go to top
Website
steved
Jan 16 2012, 05:31AM
  • e107 Main site administrator
  • e107 Core developer
Registered Member #16181
Joined: Mar 28 2005, 01:18PM
Posts: 8942
What is the point of lines 11 and 12?
$sql->db_Select_gen($qry);
$sql -> db_Fetch();

$qry apparently isn't defined anywhere (unless its outwith what you posted)
And you need something like:
$row = $sql->db_Fetch();

to get the data from the DB into the array $row.
Go to top
Berckoff
Jan 16 2012, 06:07AM
  • e107 Core developer
  • e107 Support Team
Registered Member #52782
Joined: Sep 03 2009, 02:00AM
Posts: 16
The admin part is not showing due to improper curly brace placement. I'll give you the code in the next post (not checked if it is working - just optimized by the given one)

[Edit] I think you have something missing in this piece of code... It seems incomplete to me.
[ Edited Jan 16 2012, 06:27AM ]
Go to top
VR6Pete
Jan 16 2012, 06:10AM
Registered Member #2353
Joined: Jul 28 2003, 11:21AM
Location: Stoke-on-Trent
Posts: 1246
the code its self was written probably at least 4 years, not by myself and im just trying to mash it together i'm no developer by any means like I say, it needs some work as there is depreciated code and probably a certain amount of duplication in there...
Go to top
Website
Berckoff
Jan 16 2012, 06:28AM
  • e107 Core developer
  • e107 Support Team
Registered Member #52782
Joined: Sep 03 2009, 02:00AM
Posts: 16
What is the purpose of this shortcode? This is a very good idea to have in mind - to share the purpose in the beginning
Go to top
VR6Pete
Jan 16 2012, 06:47AM
Registered Member #2353
Joined: Jul 28 2003, 11:21AM
Location: Stoke-on-Trent
Posts: 1246
it basically is my login bar for my theme....

if the user has a new message, it initiates some jQuery that slides in a new message notification from the top of the screen as opposed to the horrible / obtrusive new notification in the PM system...

it also displays the number the unread messages in the users inbox.
Go to top
Website
nlstart
Jan 16 2012, 08:53AM
nlstart
  • e107 Site administrator
  • e107 Core developer
  • e107 Translation Team Leader
Registered Member #29855
Joined: Aug 18 2006, 01:12AM
Location: Utrecht, The Netherlands
Posts: 5493
Another attempt; better formatting as well... [-link-]
Go to top
Website
VR6Pete
Jan 16 2012, 01:05PM
Registered Member #2353
Joined: Jul 28 2003, 11:21AM
Location: Stoke-on-Trent
Posts: 1246
That didn't work I'm afraid.... when users are logged out, it's still displaying the links for a logged in user...
Go to top
Website
septor
Jan 16 2012, 01:31PM
  • e107 Site administrator
  • e107 Security Team
  • e107 Support Team
  • e107 Documentation Team
Registered Member #37
Joined: Aug 11 2002, 03:20AM
Location: United States
Posts: 2659
The problem is line 33. It's displaying those links if the viewer is a user OR if $new = 0 (which would be the case for a non-user).

Try this.
[ Edited Jan 16 2012, 01:35PM ]
Go to top
Website
VR6Pete
Jan 17 2012, 01:52AM
Registered Member #2353
Joined: Jul 28 2003, 11:21AM
Location: Stoke-on-Trent
Posts: 1246
Ok we have progress.... Admin link now displays for admin user, but. the "Your Messages" does not display when there is a new unread PM....

The strange thing is that it does work as I would expect to when on the pm.php?inbox pm.php?outbox pages etc...

any ideas?
Go to top
Website
Berckoff
Jan 17 2012, 03:47AM
  • e107 Core developer
  • e107 Support Team
Registered Member #52782
Joined: Sep 03 2009, 02:00AM
Posts: 16
This is my first shot - if i've got the things right, this should be a good solution

[Edit]
I've got troubles with pasting the code here (any kind of bad tag i guess),
so it is at paste2.org

[Edit 2]
I've forgotten to mention - you have some comments to follow: a path to be changed accfroding your installation and two LAN strings definitions at the theme lans (or whereever you like)
[ Edited Jan 17 2012, 03:49AM ]
Go to top
VR6Pete
Jan 17 2012, 02:53PM
Registered Member #2353
Joined: Jul 28 2003, 11:21AM
Location: Stoke-on-Trent
Posts: 1246
Ill try this tomorrow! I thought the one nlatart did would do the trick and seemed neat. No need declare LANs etc.... Can anyone see any issues why it only works when on a pm.php page?
Go to top
Website
Go to page  1 2  

Jump:     Back to top

Syndicate this thread: rss 0.92 Syndicate this thread: rss 2.0 Syndicate this thread: RDF
Powered by e107 Forum System