我积极解决 发表于 2018-12-22 08:47:28

Discuz!源代码分析系列:./include/global.func.php(4)

转自www.discuz.net 作者:郭鑫  复制内容到剪贴板代码:
  /**
  * 用来计算星星月亮太阳显示的
  * @para $num 等级数
  *
  */
  function showstars($num) {
  global $starthreshold;
  $alt = 'alt="Rank: '.$num.'"';
  if(empty($starthreshold)) {
  for($i = 0; $i < $num; $i++) {
  echo '';
  }
  } else {
  for($i = 3; $i > 0; $i--) {
  $numlevel = intval($num / pow($starthreshold, ($i - 1)));
  $num = ($num % pow($starthreshold, ($i - 1)));
  for($j = 0; $j < $numlevel; $j++) {
  echo '';
  }
  }
  }
  }
  复制内容到剪贴板代码:
  /**
  * 得到站点
  *
  * @return string 如: http://discuz.net
  */
  function site() {
  return $_SERVER['HTTP_HOST'];
  }
  复制内容到剪贴板代码:
  /**
  * 这个看成函数重载也无妨,功能就是查找$haystack是不是在$needle中存在
  * @para string $haystack
  * @para string $needle
  *
  * @return boolean
  */
  function strexists($haystack, $needle) {
  return !(strpos($haystack, $needle) === FALSE);
  }
  复制内容到剪贴板代码:
  /**
  * 验证码转换,具体功能用处还没研究
  * @para string $seccode 验证码
  *
  */
  function seccodeconvert(&$seccode) {
  $seccode = substr($seccode, -6);
  $s = sprintf('%04s', base_convert($seccode, 10, 24));
  $seccode = '';
  $seccodeunits = 'BCEFGHJKMPQRTVWXY2346789';
  for($i = 0; $i < 4; $i++) {
  $unit = ord($s{$i});
  $seccode .= ($unit >= 0x30 && $unit$tplrefresh)) {
  if(@filemtime($tplfile) > @filemtime($objfile)) {
  require_once DISCUZ_ROOT.'./include/template.func.php';
  parse_template($file, $templateid, $tpldir);
  }
  }
  return $objfile;
  }
  复制内容到剪贴板代码:
  /**
  * 得到url中的sid
  * @para string $url
  * @para string tag
  * @para int $wml
  *
  * @return string
  */
  function transsid($url, $tag = '', $wml = 0) {
  global $sid;
  $tag = stripslashes($tag);
  if(!$tag || (!preg_match("/^(http:\/\/|mailto:|#|javascript)/i", $url) && !strpos($url, 'sid='))) {
  if($pos = strpos($url, '#')) {
  $urlret = substr($url, $pos);
  $url = substr($url, 0, $pos);
  } else {
  $urlret = '';
  }
  $url .= (strpos($url, '?') ? ($wml ? '&amp;' : '&') : '?').'sid='.$sid.$urlret;
  }
  return $tag.$url;
  }
  复制内容到剪贴板代码:
  /**
  * 生成主题分类下拉列表
  * @para int $curtypeid 当前选择的id
  *
  * @return string
  */
  function typeselect($curtypeid = 0) {
  if($threadtypes = $GLOBALS['forum']['threadtypes']) {
  $html = '&nbsp;';
  foreach($threadtypes['types'] as $typeid => $name) {
  $html .= ''.strip_tags($name).'';
  }
  $html .= '';
  return $html;
  } else {
  return '';
  }
  }
  复制内容到剪贴板代码:
  /**
  * 更新积分用到的函数
  * @para string $uids 要更新的uid
  * @para array $creditsarray 要更新的积分
  * @para int $coef 单位
  * @para string $extrasql 附加的sql语句
  *
  */
  function updatecredits($uids, $creditsarray, $coef = 1, $extrasql = '') {
  if($uids && ((!empty($creditsarray) && is_array($creditsarray)) || $extrasql)) {
  global $db, $tablepre;
  $creditsadd = $comma = '';
  foreach($creditsarray as $id => $addcredits) {
  $creditsadd .= $comma.'extcredits'.$id.'=extcredits'.$id.'+('.intval($addcredits).')*('.$coef.')';
  $comma = ', ';
  }
  if($creditsadd || $extrasql) {
  $db->query("UPDATE {$tablepre}members SET $creditsadd ".($creditsadd && $extrasql ? ', ' : '')." $extrasql WHERE uid IN ('$uids')", 'UNBUFFERED');
  }
  }
  }
  复制内容到剪贴板代码:
  /**
  * 把session更新一下,更新了如下的表:onlinetime, members, sessions
  */
  function updatesession() {
  if(!empty($GLOBALS['sessionupdated'])) {
  return TRUE;
  }
  global $db, $tablepre, $sessionexists, $sessionupdated, $sid, $onlineip, $discuz_uid, $discuz_user, $timestamp, $lastactivity, $seccode,
  $pvfrequence, $spageviews, $lastolupdate, $oltimespan, $onlinehold, $groupid, $styleid, $invisible, $discuz_action, $fid, $tid, $bloguid;
  $fid = intval($fid);
  $tid = intval($tid);
  if($oltimespan && $discuz_uid && $lastactivity && $timestamp - ($lastolupdate ? $lastolupdate : $lastactivity) > $oltimespan * 60) {
  $lastolupdate = $timestamp;
  $db->query("UPDATE {$tablepre}onlinetime SET total=total+'$oltimespan', thismonth=thismonth+'$oltimespan', lastupdate='$timestamp' WHERE uid='$discuz_uid' AND lastupdate
页: [1]
查看完整版本: Discuz!源代码分析系列:./include/global.func.php(4)