コード例 #1
0
ファイル: raxan.webpage.php プロジェクト: enriqueism/raxan
/**
 * Creates a reference to the client-side event callback wrapper function. Used to trigger an event callback to the server from the client.
 * @return RaxanClientVariable
 */
function _event($type, $value = null, $target = 'page')
{
    // get value from first argument. If first argument is an event then pass event to trigger
    $code = 'var e,v=arguments[0],data=arguments[1]; if (v && v.stopPropagation) {e=v;v=null};';
    $code .= '$trigger("' . Raxan::escapeText($target) . '",' . ($type !== null ? '"' . Raxan::escapeText($type) . '"' : '""') . ',' . ($value !== null ? '"' . Raxan::escapeText($value) . '"' : 'v') . ',null,{event:e,data:data}' . ')';
    return _fn($code);
}
コード例 #2
0
/**
 * Smarty modifier to format datetimes in a more Human Readable form 
 * (like tomorow, 4 days from now, 6 hours ago)
 *
 * Example
 * <!--[$futuredate|dateformatHuman:'%x':'2']-->
 *
 * @author   Erik Spaan
 * @since    05/03/09
 * @param    string   $string   input datetime string
 * @param    string   $format   The format of the regular date output (default %x)
 * @param    string   $niceval  [1|2|3|4] Choose the nice value of the output (default 2)
 *                                    1 = full human readable
 *                                    2 = past date > 1 day with dateformat, otherwise human readable
 *                                    3 = within 1 day human readable, otherwise dateformat
 *                                    4 = only use the specified format
 * @return   string   the modified output
 */
function smarty_modifier_dateformatHuman($string, $format = '%x', $niceval = 2)
{
    $dom = ZLanguage::getModuleDomain('News');
    if (empty($format)) {
        $format = '%x';
    }
    // store the current datetime in a variable
    $now = DateUtil::getDatetime();
    if (empty($string)) {
        return DateUtil::formatDatetime($now, $format);
    }
    if (empty($niceval)) {
        $niceval = 2;
    }
    // now format the date with respect to the current datetime
    $res = '';
    $diff = DateUtil::getDatetimeDiff($now, $string);
    if ($diff['d'] < 0) {
        if ($niceval == 1) {
            $res = _fn('%s day ago', '%s days ago', abs($diff['d']), abs($diff['d']), $dom);
        } elseif ($niceval < 4 && $diff['d'] == -1) {
            $res = __('yesterday', $dom);
        } else {
            $res = DateUtil::formatDatetime($string, $format);
        }
    } elseif ($diff['d'] > 0) {
        if ($niceval > 2) {
            $res = DateUtil::formatDatetime($string, $format);
        } elseif ($diff['d'] == 1) {
            $res = __('tomorrow', $dom);
        } else {
            $res = _fn('%s day from now', '%s days from now', $diff['d'], $diff['d'], $dom);
        }
    } else {
        // no day difference
        if ($diff['h'] < 0) {
            $res = _fn('%s hour ago', '%s hours ago', abs($diff['h']), abs($diff['h']), $dom);
        } elseif ($diff['h'] > 0) {
            $res = _fn('%s hour from now', '%s hours from now', $diff['h'], $diff['h'], $dom);
        } else {
            // no hour difference
            if ($diff['m'] < 0) {
                $res = _fn('%s minute ago', '%s minutes ago', abs($diff['m']), abs($diff['m']), $dom);
            } elseif ($diff['m'] > 0) {
                $res = _fn('%s minute from now', '%s minutes from now', $diff['m'], $diff['m'], $dom);
            } else {
                // no min difference
                if ($diff['s'] < 0) {
                    $res = _fn('%s second ago', '%s seconds ago', abs($diff['s']), abs($diff['s']), $dom);
                } else {
                    $res = _fn('%s second from now', '%s seconds from now', $diff['s'], $diff['s'], $dom);
                }
            }
        }
    }
    return $res;
}
コード例 #3
0
/**
 * Zikula_View function to use the _dgettext() function
 *
 * This function takes a identifier and returns the corresponding language constant.
 *
 * Available parameters:
 *   - text:     (required) string to translate
 *   - plural:   (optional) plural version of the string
 *   - count:    (optional) if we have plural we need to specify the count
 *   - tagN:     (optional) replace for sprintf() e.g. %s or %1$s
 *   - domain:   (optional) textdomain to be used (not required, the system will fill this out automatically
 *   - comment:  (optional) comment to the translator (this is not processed by this code)
 *   - assign:   If set, the results are assigned to the corresponding variable instead of printed out
 *
 * Examples
 * {gt text="Hello world"}
 * {gt text="Hello %s" tag1=$name}
 * {gt text="You want one cup" plural="You want two cups" count=2}
 * {gt text='Hello %1$s, welcome to %2$s' tag1=$city tag2=$country comment="%1 is a name %2 is the place"}
 * ## WARNING! When using %1$s in a template, smarty compiles this to PHP so the string must be in single quotes or
 * ## the $s will be evaluated as variable $s
 *
 *
 * String replacement follows the rules at http://php.net/sprintf but please note Smarty seems to pass
 * all variables as strings so %s and %n$s are mostly used.
 *
 * @param array       $params All attributes passed to this function from the template.
 * @param Zikula_View $view   Reference to the Zikula_View object.
 *
 * @return string Translation if it was available.
 */
function smarty_function_gt($params, Zikula_View $view)
{
    // the check order here is important because:
    // if we are calling from a theme both $view->themeDomain and $view->renderDomain are set.
    // if the call was from a template only $view->renderDomain is set.
    if (isset($params['domain'])) {
        $domain = (strtolower($params['domain']) == 'zikula' ? null : $params['domain']);
    } else {
        $domain = $view->getDomain(); // default domain
    }

    if (!isset($params['text'])) {
        $view->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified.', array('smarty_function_gt', 'text')));
        return false;
    }
    $text = $params['text'];

    // validate plural settings if applicable
    if ((!isset($params['count']) && isset($params['plural'])) || (isset($params['count']) && !isset($params['plural']))) {
        $view->trigger_error(__('Error! If you use a plural or count in gettext, you must use both parameters together.'));
        return false;
    }

    $count = (isset($params['count']) ? (int)$params['count'] : 0);
    $plural = (isset($params['plural']) ? $params['plural'] : false);

    // build array for tags (for %s, %1$s etc) if applicable
    ksort($params);
    $tags = array();
    foreach ($params as $key => $value) {
        if (preg_match('#^tag([0-9]{1,2})$#', $key)) {
            $tags[] = $value;
        }
    }
    $tags = (count($tags) == 0 ? null : $tags);

    // perform gettext
    if ($plural) {
        $result = (isset($tags) ? _fn($text, $plural, $count, $tags, $domain) : _n($text, $plural, $count, $domain));
    } else {
        $result = (isset($tags) ? __f($text, $tags, $domain) : __($text, $domain));
    }

    // assign or return
    if (isset($params['assign'])) {
        $view->assign($params['assign'], $result);
    } else {
        return $result;
    }
}
コード例 #4
0
ファイル: function.gt.php プロジェクト: projectesIF/Sirius
/**
 * Copyright Zikula Foundation 2009 - Zikula Application Framework
 *
 * This work is contributed to the Zikula Foundation under one or more
 * Contributor Agreements and licensed to You under the following license:
 *
 * @license GNU/LGPLv3 (or at your option, any later version).
 * @package Zikula
 *
 * Please see the NOTICE file distributed with this source code for further
 * information regarding copyright and licensing.
 */
function smarty_function_gt($params, &$smarty)
{
    if (isset($params['domain'])) {
        $domain = $params['domain'] == strtolower('zikula') ? null : $params['domain'];
    } else {
        $domain = null;
        // default domain
    }
    if (!isset($params['text'])) {
        $smarty->trigger_error(__("Error! Gettext 'gt' requires an attribute text."));
        return false;
    }
    $text = $params['text'];
    // validate plural settings if applicable
    if (!isset($params['count']) && isset($params['plural']) || isset($params['count']) && !isset($params['plural'])) {
        $smarty->trigger_error(__('Error! If you use a plural or count in gettext, you must use both parameters together.'));
        return false;
    }
    $count = isset($params['count']) ? (int) $params['count'] : 0;
    $plural = isset($params['plural']) ? $params['plural'] : false;
    // build array for tags (for %s, %1$s etc) if applicable
    ksort($params);
    $tags = array();
    foreach ($params as $key => $value) {
        if (preg_match('#^tag([0-9]{1,2})$#', $key)) {
            $tags[] = $value;
        }
    }
    $tags = count($tags) == 0 ? null : $tags;
    // perform gettext
    if ($plural) {
        $result = isset($tags) ? _fn($text, $plural, $count, $tags, $domain) : _n($text, $plural, $count, $domain);
    } else {
        $result = isset($tags) ? __f($text, $tags, $domain) : __($text, $domain);
    }
    // assign or return
    if (isset($params['assign'])) {
        $smarty->assign($params['assign'], $result);
    } else {
        return $result;
    }
}
コード例 #5
0
 /**
  * Translate plural string with sprintf().
  *
  * @param string       $sin    Singular instance.
  * @param string       $plu    Plural instance.
  * @param string       $n      Object count.
  * @param string|array $params Sprintf() arguments.
  *
  * @return string
  */
 public function _fn($sin, $plu, $n, $params)
 {
     return _fn($sin, $plu, $n, $params, $this->domain);
 }
コード例 #6
0
ファイル: ZL10n.php プロジェクト: rmaiwald/core
 /**
  * Format pural translations for modules.
  *
  * @param string       $m1    Singular.
  * @param string       $m2    Plural.
  * @param integer      $n     Count.
  * @param string|array $param Format parameters.
  *
  * @return string
  */
 public function _fn($m1, $m2, $n, $param)
 {
     return _fn($m1, $m2, $n, $param, $this->domain);
 }
コード例 #7
0
ファイル: AdminApi.php プロジェクト: rtznprmpftl/Zikulacore
 /**
  * Send an e-mail message to one or more users.
  *
  * Parameters passed in the $args array:
  * -------------------------------------
  * numeric|array $args['uid']                         A single (numeric integer) uid or an array of uids to which the e-mail should be sent.
  * array         $args['sendmail']                    An array containing the information necessary to send an e-mail.
  * string        $args['sendmail']['from']            The name of the e-mail message's sender.
  * string        $args['sendmail']['rpemail']         The e-mail address of the e-mail message's sender.
  * string        $args['sendmail']['subject']         The e-mail message's subject.
  * string        $args['sendmail']['message']         The e-mail message's body (the message itself).
  * array         $args['sendmail']['recipientsname']  An array indexed by uid of each recipient's name.
  * array         $args['sendmail']['recipientsemail'] An array indexed by uid of each recipient's e-mail address.
  *
  * @param array $args All arguments passed to this function.
  *
  * @return bool True on success; otherwise false
  *
  * @throws \Zikula\Framework\Exception\ForbiddenException Thrown if the current user does not have sufficient access to send mail.
  */
 public function sendmail($args)
 {
     if (!SecurityUtil::checkPermission("{$this->name}::MailUsers", '::', ACCESS_COMMENT)) {
         throw new \Zikula\Framework\Exception\ForbiddenException();
     }
     if (isset($args['uid']) && !empty($args['uid'])) {
         if (is_array($args['uid'])) {
             $recipientUidList = $args['uid'];
         } else {
             $recipientUidList = array($args['uid']);
         }
     } else {
         $this->registerError(__('Error! No users selected to receive e-mail, or invalid uid list.'));
         return false;
     }
     if (isset($args['sendmail']) && !empty($args['sendmail']) && is_array($args['sendmail'])) {
         $sendmail = $args['sendmail'];
     } else {
         $this->registerError(__('Error! E-mail message to be sent not specified or invalid.'));
         return false;
     }
     $missingFields = array();
     if (empty($sendmail['from'])) {
         $missingFields[] = 'from';
     }
     if (empty($sendmail['rpemail'])) {
         $missingFields[] = 'reply-to e-mail address';
     }
     if (empty($sendmail['subject'])) {
         $missingFields[] = 'subject';
     }
     if (empty($sendmail['message'])) {
         $missingFields[] = 'message';
     }
     if (!empty($missingFields)) {
         $count = count($missingFields);
         $msg = _fn('Error! The required field \'%2$s\' was blank or missing', 'Error! %1$d required fields were blank or missing: \'%2$s\'.', $count, array($count, implode("', '", $missingFields)));
         $this->registerError($msg);
         return false;
     }
     unset($missingFields);
     $bcclist = array();
     $recipientlist = array();
     $recipientscount = 0;
     foreach ($sendmail['recipientsemail'] as $uid => $recipient) {
         if (in_array($uid, $recipientUidList)) {
             $bcclist[] = array('name' => $sendmail['recipientsname'][$uid], 'address' => $recipient);
             $recipientlist[] = $recipient;
         }
         if (count($bcclist) == $sendmail['batchsize']) {
             if (ModUtil::apiFunc('MailerModule', 'user', 'sendmessage', array('fromname' => $sendmail['from'], 'fromaddress' => $sendmail['rpemail'], 'toname' => UserUtil::getVar('uname'), 'toaddress' => UserUtil::getVar('email'), 'replytoname' => UserUtil::getVar('uname'), 'replytoaddress' => $sendmail['rpemail'], 'subject' => $sendmail['subject'], 'body' => $sendmail['message'], 'bcc' => $bcclist)) == true) {
                 $recipientscount += count($bcclist);
                 $bcclist = array();
             } else {
                 $this->registerError($this->__('Error! Could not send the e-mail message.'));
                 return false;
             }
         }
     }
     if (count($bcclist) != 0) {
         $sendMessageArgs = array('fromname' => $sendmail['from'], 'fromaddress' => $sendmail['rpemail'], 'toname' => UserUtil::getVar('uname'), 'toaddress' => UserUtil::getVar('email'), 'replytoname' => UserUtil::getVar('uname'), 'replytoaddress' => $sendmail['rpemail'], 'subject' => $sendmail['subject'], 'body' => $sendmail['message'], 'bcc' => $bcclist);
         if (ModUtil::apiFunc('MailerModule', 'user', 'sendMessage', $sendMessageArgs)) {
             $recipientscount += count($bcclist);
         } else {
             $this->registerError($this->__('Error! Could not send the e-mail message.'));
             return false;
         }
     }
     if ($recipientscount > 0) {
         $this->registerStatus($this->_fn('Done! E-mail message has been sent to %1$d user. ', 'Done! E-mail message has been sent to %1$d users. ', $recipientscount, array($recipientscount)));
     }
     return true;
 }
コード例 #8
0
ファイル: zrc.php プロジェクト: Silwereth/core
 public function getUtilityInputsTempdir()
 {
     if ($this->tempdirexists == false) {
         $form = __('Your temporary directory does not seem to exist. It will be built from scratch') . "\n";
     } else {
         $form = __('Your temporary directory seems to exist. The status of the subdirectories is as follows:') . "\n";
         $form .= "<br /><br />\n";
         foreach ($this->tempdirsubs as $dir => $status) {
             if ($status == 1) {
                 $icon = 'button_ok.png';
             } else {
                 $icon = 'button_cancel.png';
             }
             $form .= '<img src="images/icons/extrasmall/' . $icon . '" alt="' . __('directory status') . '" /> ' . $dir . "\n";
             $form .= "<br />\n";
         }
         $form .= "<br />\n";
         $form .= _fn('%s directory was not found. Please use the utility to create the deleted directory', '%s directories were not found. Please use the utility to create the deleted directories', $this->tempdirsubsfailed, $this->tempdirsubsfailed);
     }
     $form .= "<br /><br />\n";
     return $form;
 }