Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Hacked popup function to block plugin

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Plugins
View previous topic :: View next topic  
Author Message
chris
Smarty n00b


Joined: 18 Apr 2003
Posts: 2

PostPosted: Thu Oct 16, 2003 2:11 pm    Post subject: Hacked popup function to block plugin Reply with quote

I wasn't able to use the popup function because I needed to generate the displayed content on the fly.

I have modified the smarty 'popup' function in a block fonction to be able to generate the popup content betwen the start en end block.

block.popup.php
Code:

<?php
/**
 * Smarty plugin
 * @package Smarty
 * @subpackage plugins
 */


/**
 * Smarty {popup} block plugin
 *
 * Type:     block<br>
 * Name:     popup<br>
 * Purpose:  make text pop up in windows via overlib
 * @link http://smarty.php.net/manual/en/language.function.popup.php {popup}
 *          (Smarty online manual, the block popup use the same option than the function popup)
 * @param array
 * @param Smarty
 * @return string
 */
function smarty_block_popup($params, $content, &$smarty)
{
   if ($content == null) {
       return true;        // Leave if we are in the starting block. All the work is done at the end
    }

    extract($params);

    if (empty($content) && !isset($inarray) && empty($function)) {
        $smarty->trigger_error("overlib: attribute 'text' or 'inarray' or 'function' required");
        return false;
    }

    if (empty($trigger)) { $trigger = "onmouseover"; }

    $retval = $trigger . '="return overlib(\''.preg_replace(array("!'!","![\r\n]!"),array("\'",'\r'),$content).'\'';
    if (!empty($sticky) && $sticky) { $retval .= ",STICKY"; }
    if (!empty($caption)) { $retval .= ",CAPTION,'".str_replace("'","\'",$caption)."'"; }
    if (!empty($fgcolor)) { $retval .= ",FGCOLOR,'$fgcolor'"; }
    if (!empty($bgcolor)) { $retval .= ",BGCOLOR,'$bgcolor'"; }
    if (!empty($textcolor)) { $retval .= ",TEXTCOLOR,'$textcolor'"; }
    if (!empty($capcolor)) { $retval .= ",CAPCOLOR,'$capcolor'"; }
    if (!empty($closecolor)) { $retval .= ",CLOSECOLOR,'$closecolor'"; }
    if (!empty($textfont)) { $retval .= ",TEXTFONT,'$textfont'"; }
    if (!empty($captionfont)) { $retval .= ",CAPTIONFONT,'$captionfont'"; }
    if (!empty($closefont)) { $retval .= ",CLOSEFONT,'$closefont'"; }
    if (!empty($textsize)) { $retval .= ",TEXTSIZE,$textsize"; }
    if (!empty($captionsize)) { $retval .= ",CAPTIONSIZE,$captionsize"; }
    if (!empty($closesize)) { $retval .= ",CLOSESIZE,$closesize"; }
    if (!empty($width)) { $retval .= ",WIDTH,$width"; }
    if (!empty($height)) { $retval .= ",HEIGHT,$height"; }
    if (!empty($left)) { $retval .= ",LEFT"; }
    if (!empty($right)) { $retval .= ",RIGHT"; }
    if (!empty($center)) { $retval .= ",CENTER"; }
    if (!empty($above)) { $retval .= ",ABOVE"; }
    if (!empty($below)) { $retval .= ",BELOW"; }
    if (isset($border)) { $retval .= ",BORDER,$border"; }
    if (isset($offsetx)) { $retval .= ",OFFSETX,$offsetx"; }
    if (isset($offsety)) { $retval .= ",OFFSETY,$offsety"; }
    if (!empty($fgbackground)) { $retval .= ",FGBACKGROUND,'$fgbackground'"; }
    if (!empty($bgbackground)) { $retval .= ",BGBACKGROUND,'$bgbackground'"; }
    if (!empty($closetext)) { $retval .= ",CLOSETEXT,'".str_replace("'","\'",$closetext)."'"; }
    if (!empty($noclose)) { $retval .= ",NOCLOSE"; }
    if (!empty($status)) { $retval .= ",STATUS,'".str_replace("'","\'",$status)."'"; }
    if (!empty($autostatus)) { $retval .= ",AUTOSTATUS"; }
    if (!empty($autostatuscap)) { $retval .= ",AUTOSTATUSCAP"; }
    if (isset($inarray)) { $retval .= ",INARRAY,'$inarray'"; }
    if (isset($caparray)) { $retval .= ",CAPARRAY,'$caparray'"; }
    if (!empty($capicon)) { $retval .= ",CAPICON,'$capicon'"; }
    if (!empty($snapx)) { $retval .= ",SNAPX,$snapx"; }
    if (!empty($snapy)) { $retval .= ",SNAPY,$snapy"; }
    if (isset($fixx)) { $retval .= ",FIXX,$fixx"; }
    if (isset($fixy)) { $retval .= ",FIXY,$fixy"; }
    if (!empty($background)) { $retval .= ",BACKGROUND,'$background'"; }
    if (!empty($padx)) { $retval .= ",PADX,$padx"; }
    if (!empty($pady)) { $retval .= ",PADY,$pady"; }
    if (!empty($fullhtml)) { $retval .= ",FULLHTML"; }
    if (!empty($frame)) { $retval .= ",FRAME,'$frame'"; }
    if (isset($timeout)) { $retval .= ",TIMEOUT,$timeout"; }
    if (!empty($function)) { $retval .= ",FUNCTION,'$function'"; }
    if (isset($delay)) { $retval .= ",DELAY,$delay"; }
    if (!empty($hauto)) { $retval .= ",HAUTO"; }
    if (!empty($vauto)) { $retval .= ",VAUTO"; }
    $retval .= ');" onmouseout="nd();"';

        return $retval;
}

/* vim: set expandtab: */

?>



exemple using it in a template :
Code:

<a href="#"
{popup caption="Description" fgcolor="yellow"}
Email : {$employe->getField('email')}<br>
tel : {$employe->getField('tel')}<br>
fax : {$employe->getField('fax')}<br>Commentaire :<br>
{$employe->getField('commentaire')}
{/popup}>
  {$employe->getField('name')}
</a>


The displayed content are auto-escaped (for the javascript call generated by the plugin).
Back to top
View user's profile Send private message
Adar
Smarty Regular


Joined: 27 May 2004
Posts: 58

PostPosted: Sun May 30, 2004 1:29 pm    Post subject: Reply with quote

Nice one, helped me very much, thx Smile
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Plugins All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP