smarty.addons.php

来自「通达OA2007SE源代码 非常好的」· PHP 代码 · 共 1,011 行 · 第 1/2 页

PHP
1,011
字号
<?
  function smarty_mod_escape ($string, $esc_type = 'html')
  {
    switch ($esc_type)
    {
      case 'html':
      {
        return htmlspecialchars ($string, ENT_QUOTES);
      }
      case 'url':
      {
        return urlencode ($string);
      }
      case 'quotes':
      {
        return preg_replace ('%(?<!\\\\)\'%', '\\\'', $string);
      }
      default:
      {
        return $string;
      }
    }
  }
  function smarty_mod_truncate ($string, $length = 80, $etc = '...', $break_words = false)
  {
    if (($length == 0))
    {
      return '';
    }
    if (($length < strlen ($string)))
    {
      ($length -= strlen ($etc));
      $fragment = substr ($string, 0, ($length + 1));
      if ($break_words)
      {
        $fragment = substr ($fragment, 0, -1);
      }
      else
      {
        $fragment = preg_replace ('/\\s+(\\S+)?$/', '', $fragment);
      }
      return ($fragment.$etc);
    }
    else
    {
      return $string;
    }
  }
  function smarty_mod_spacify ($string, $spacify_char = ' ')
  {
    return implode ($spacify_char, preg_split ('//', $string, -1, PREG_SPLIT_NO_EMPTY));
  }
  function smarty_mod_date_format ($string, $format = '%b %e, %Y')
  {
    return strftime ($format, smarty_make_timestamp ($string));
  }
  function smarty_make_timestamp ($string)
  {
    if (empty ($string))
    {
      $string = 'now';
    }
    $time = strtotime ($string);
    if ((is_numeric ($time) AND ($time != -1)))
    {
      return $time;
    }
    if ((is_numeric ($string) AND (strlen ($string) == 14)))
    {
      $time = mktime (substr ($string, 8, 2), substr ($string, 10, 2), substr ($string, 12, 2), substr ($string, 4, 2), substr ($string, 6, 2), substr ($string, 0, 4));
      return $time;
    }
    return $string;
  }
  function smarty_mod_string_format ($string, $format)
  {
    return sprintf ($format, $string);
  }
  function smarty_mod_replace ($string, $search, $replace)
  {
    return str_replace ($search, $replace, $string);
  }
  function smarty_mod_regex_replace ($string, $search, $replace)
  {
    return preg_replace ($search, $replace, $string);
  }
  function smarty_mod_strip_tags ($string, $replace_with_space = true)
  {
    if ($replace_with_space)
    {
      return preg_replace ('!<[^>]*?>!', ' ', $string);
    }
    else
    {
      return strip_tags ($string);
    }
  }
  function smarty_mod_default ($string, $default = '')
  {
    if (empty ($string))
    {
      return $default;
    }
    else
    {
      return $string;
    }
  }
  function smarty_func_um_welcome_message ($args, &$smarty_obj)
  {
    extract ($args);
    $config_vars = $smarty_obj->_config[0]['vars'];
    $array_keys = array_keys ($args);
    if (empty ($var))
    {
      $smarty_obj->_trigger_error_msg ('um_welcome_message: missing \'var\' parameter');
      return null;
    }
    if (!in_array ('messages', $array_keys))
    {
      $smarty_obj->_trigger_error_msg ('um_welcome_message: missing \'messages\' parameter');
      return null;
    }
    if (!in_array ('unread', $array_keys))
    {
      $smarty_obj->_trigger_error_msg ('um_welcome_message: missing \'unread\' parameter');
      return null;
    }
    if (!in_array ('var', $array_keys))
    {
      $smarty_obj->_trigger_error_msg ('um_welcome_message: missing \'var\' parameter');
      return null;
    }
    if (!in_array ('boxname', $array_keys))
    {
      $smarty_obj->_trigger_error_msg ('um_welcome_message: missing \'boxname\' parameter');
      return null;
    }
    $wlcmessage = ($config_vars['msg_you_have'].(((''.' <b>').$messages).'</b> '));
    if (($messages == 1))
    {
      ($wlcmessage .= ($config_vars['msg_message'].', '));
    }
    else
    {
      ($wlcmessage .= ($config_vars['msg_messages'].', '));
    }
    if (($unread == 0))
    {
      ($wlcmessage .= ($config_vars['msg_none_unread'].' '));
    }
    else
    {
      if (($unread == 1))
      {
        ($wlcmessage .= (((((''.'<b>').$unread).'</b> ').$config_vars['msg_one_unread']).' '));
      }
      else
      {
        ($wlcmessage .= (((((''.'<b>').$unread).'</b> ').$config_vars['msg_more_unread']).' '));
      }
    }
    ($wlcmessage .= ($config_vars['msg_in_the_folder'].(((''.' <b>').$boxname).'</b>')));
    $smarty_obj->assign ($var, $wlcmessage);
    return true;
  }
  function smarty_func_um_translatebox ($args, &$smarty_obj)
  {
    extract ($args);
    $config_vars = $smarty_obj->_config[0]['vars'];
    if (empty ($var))
    {
      $smarty_obj->_trigger_error_msg ('um_translatebox: missing \'var\' parameter');
      return null;
    }
    if (!in_array ('value', array_keys ($args)))
    {
      $smarty_obj->_trigger_error_msg ('um_translatebox: missing \'value\' parameter');
      return null;
    }
    switch (strtolower ($value))
    {
      case 'inbox':
      {
        $value = $config_vars['inbox_extended'];
        break;
      }
      case 'sent':
      {
        $value = $config_vars['sent_extended'];
        break;
      }
      case 'trash':
      {
        $value = $config_vars['trash_extended'];
        break;
      }
    }
    $smarty_obj->assign ($var, $value);
    return true;
  }
  function smarty_func_assign ($args, &$smarty_obj)
  {
    extract ($args);
    if (empty ($var))
    {
      $smarty_obj->_trigger_error_msg ('assign: missing \'var\' parameter');
      return null;
    }
    if (!in_array ('value', array_keys ($args)))
    {
      $smarty_obj->_trigger_error_msg ('assign: missing \'value\' parameter');
      return null;
    }
    $smarty_obj->assign ($var, $value);
    return true;
  }
  function smarty_func_html_options ()
  {
    $print_result = true;
    extract (func_get_arg (0));
    $html_result = '';
    settype ($selected, 'array');
    if (isset ($options))
    {
      settype ($options, 'array');
      foreach ($options as $key => $value)
      {
        ($html_result .= (((''.'<option value="').$key).'"'));
        if (in_array ($key, $selected))
        {
          ($html_result .= ' selected="selected"');
        }
        ($html_result .= (((''.'>').$value).'</option>
'));
      }
    }
    else
    {
      settype ($output, 'array');
      settype ($values, 'array');
      for ($i = 0; ($i < count ($output)); ++$i)
      {
        $sel_check = $values[$i];
        ($html_result .= '<option');
        if (($i < count ($values)))
        {
          ($html_result .= ((' value="'.$values[$i]).'"'));
        }
        else
        {
          $sel_check = $output[$i];
        }
        if (in_array ($sel_check, $selected))
        {
          ($html_result .= ' selected');
        }
        ($html_result .= (('>'.$output[$i]).'</option>
'));
      }
    }
    if ($print_result)
    {
      print $html_result;
    }
    else
    {
      return $html_result;
    }
  }
  function smarty_func_html_select_date ()
  {
    $prefix = 'Date_';
    $time = time ();
    $start_year = strftime ('%Y');
    $end_year = $start_year;
    $display_days = true;
    $display_months = true;
    $display_years = true;
    $month_format = '%B';
    $day_format = '%02d';
    $year_as_text = false;
    $reverse_years = false;
    $field_array = null;
    $day_size = null;
    $month_size = null;
    $year_size = null;
    $all_extra = null;
    $day_extra = null;
    $month_extra = null;
    $year_extra = null;
    $field_order = 'MDY';
    $field_separator = '
';
    extract (func_get_arg (0));
    $time = smarty_make_timestamp ($time);
    $field_order = strtoupper ($field_order);
    $html_result = $month_result = $day_result = $year_result = '';
    if ($display_months)
    {
      $month_names = array ();
      for ($i = 1; ($i <= 12); ++$i)
      {
        $month_names[] = strftime ($month_format, mktime (0, 0, 0, $i, 1, 2000));
      }
      ($month_result .= '<select name=');
      if ((null !== $field_array))
      {
        ($month_result .= (((('"'.$field_array).'[').$prefix).'Month]"'));
      }
      else
      {
        ($month_result .= (('"'.$prefix).'Month"'));
      }
      if ((null !== $month_size))
      {
        ($month_result .= ((' size="'.$month_size).'"'));
      }
      if ((null !== $month_extra))
      {
        ($month_result .= (' '.$month_extra));
      }
      if ((null !== $all_extra))
      {
        ($month_result .= (' '.$all_extra));
      }
      ($month_result .= '>
');
      ($month_result .= smarty_func_html_options (array ('output' => $month_names, 'values' => range (1, 12), 'selected' => strftime ('%m', $time), 'print_result' => false)));
      ($month_result .= '</select>');
    }
    if ($display_days)
    {
      $days = range (1, 31);
      for ($i = 0; ($i < count ($days)); ++$i)
      {
        $days[$i] = sprintf ($day_format, $days[$i]);
      }
      ($day_result .= '<select name=');
      if ((null !== $field_array))
      {
        ($day_result .= (((('"'.$field_array).'[').$prefix).'Day]"'));
      }
      else
      {
        ($day_result .= (('"'.$prefix).'Day"'));
      }
      if ((null !== $day_size))
      {
        ($day_result .= ((' size="'.$day_size).'"'));
      }
      if ((null !== $all_extra))
      {
        ($day_result .= (' '.$all_extra));
      }
      if ((null !== $day_extra))
      {
        ($day_result .= (' '.$day_extra));
      }
      ($day_result .= '>
');
      ($day_result .= smarty_func_html_options (array ('output' => $days, 'values' => range (1, 31), 'selected' => strftime ('%d', $time), 'print_result' => false)));
      ($day_result .= '</select>');
    }
    if ($display_years)
    {
      if ((null !== $field_array))
      {
        $year_name = ((($field_array.'[').$prefix).'Year]');
      }
      else
      {
        $year_name = ($prefix.'Year');
      }
      if ($year_as_text)
      {
        ($year_result .= (((('<input type="text" name="'.$year_name).'" value="').strftime ('%Y', $time)).'" size="4" maxlength="4"'));
        if ((null !== $all_extra))
        {
          ($year_result .= (' '.$all_extra));
        }
        if ((null !== $year_extra))
        {
          ($year_result .= (' '.$year_extra));
        }
        ($year_result .= '>');
      }
      else
      {
        $years = range ((int)$start_year, (int)$end_year);
        if ($reverse_years)
        {
          rsort ($years, SORT_NUMERIC);
        }
        ($year_result .= (('<select name="'.$year_name).'"'));
        if ((null !== $year_size))
        {
          ($year_result .= ((' size="'.$year_size).'"'));
        }
        if ((null !== $all_extra))
        {
          ($year_result .= (' '.$all_extra));
        }
        if ((null !== $year_extra))
        {
          ($year_result .= (' '.$year_extra));
        }
        ($year_result .= '>
');
        ($year_result .= smarty_func_html_options (array ('output' => $years, 'values' => $years, 'selected' => strftime ('%Y', $time), 'print_result' => false)));
        ($year_result .= '</select>');
      }
    }
    for ($i = 0; ($i <= 2); ++$i)
    {
      $c = substr ($field_order, $i, 1);
      switch ($c)
      {
        case 'D':
        {
          ($html_result .= $day_result);
          break;
        }
        case 'M':
        {
          ($html_result .= $month_result);
          break;
        }
        case 'Y':
        {
          ($html_result .= $year_result);
          break;
        }
      }
      ($html_result .= $field_separator);
    }
    print $html_result;
  }
  function smarty_func_html_select_time ()
  {
    $prefix = 'Time_';
    $time = time ();
    $display_hours = true;
    $display_minutes = true;
    $display_seconds = true;
    $display_meridian = true;
    $use_24_hours = true;
    $minute_interval = 1;
    $second_interval = 1;
    $field_array = null;
    extract (func_get_arg (0));
    $time = smarty_make_timestamp ($time);
    $html_result = '';
    if ($display_hours)
    {
      $hours = ($use_24_hours ? range (0, 23) : range (1, 12));
      $hour_fmt = ($use_24_hours ? '%H' : '%I');
      for ($i = 0; ($i < count ($hours)); ++$i)
      {
        $hours[$i] = sprintf ('%02d', $hours[$i]);
      }
      ($html_result .= '<select name=');
      if ((null !== $field_array))
      {
        ($html_result .= ((((('"'.$field_array).'[').$prefix).'Hour]">').'
'));
      }
      else
      {
        ($html_result .= ((('"'.$prefix).'Hour">').'
'));
      }
      ($html_result .= smarty_func_html_options (array ('output' => $hours, 'values' => $hours, 'selected' => strftime ($hour_fmt, $time), 'print_result' => false)));
      ($html_result .= '</select>
');
    }
    if ($display_minutes)
    {
      $all_minutes = range (0, 59);
      for ($i = 0; ($i < count ($all_minutes)); ($i += $minute_interval))
      {
        $minutes[] = sprintf ('%02d', $all_minutes[$i]);
      }
      $selected = intval ((floor ((strftime ('%M', $time) / $minute_interval)) * $minute_interval));
      ($html_result .= '<select name=');
      if ((null !== $field_array))
      {
        ($html_result .= ((((('"'.$field_array).'[').$prefix).'Minute]">').'
'));
      }
      else
      {
        ($html_result .= ((('"'.$prefix).'Minute">').'
'));
      }
      ($html_result .= smarty_func_html_options (array ('output' => $minutes, 'values' => $minutes, 'selected' => $selected, 'print_result' => false)));
      ($html_result .= '</select>
');
    }
    if ($display_seconds)
    {
      $all_seconds = range (0, 59);
      for ($i = 0; ($i < count ($all_seconds)); ($i += $second_interval))
      {
        $seconds[] = sprintf ('%02d', $all_seconds[$i]);
      }

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?