function ac_save() { global $cfg_soft_lang; $data[0]['pic'] = request('pic1', ''); $data[1]['pic'] = request('pic2', ''); $data[2]['pic'] = request('pic3', ''); $data[0]['url'] = request('url1', ''); $data[1]['url'] = request('url2', ''); $data[2]['url'] = request('url3', ''); $data[0]['description'] = request('description1', ''); $data[1]['description'] = request('description2', ''); $data[2]['description'] = request('description3', ''); $mpath = DEDEASK . "/data/cache/slide.inc"; if ($cfg_soft_lang == 'utf-8') { $data = AutoCharset($data, 'utf-8', 'gb2312'); $data = serialize($data); $data = gb2utf8($data); } else { $data = serialize($data); } $configstr = "<" . "?php\r\n\$data = '" . $data . "';"; file_put_contents($mpath, $configstr); ShowMsg('修改幻灯片成功', '?ct=slide'); exit; }
function ac_index() { global $cfg_soft_lang; $row = 8; //推荐问题 $digests = $this->question->get_digests(7); //待解决的问题 $notoks = $this->question->get_all('status=0', 'ORDER BY disorder DESC, dateline DESC', $row); //新解决的问题 $solutions = $this->question->get_all('status=1', 'ORDER BY solvetime DESC', $row); //高分悬赏问题 $rewards = $this->question->get_all('status=0', 'ORDER BY reward DESC', $row); //获取问题数 $solvenum = $this->question->get_total(); //首页幻灯片 if (file_exists(DEDEASK . "/data/cache/slide.inc")) { require_once DEDEASK . "/data/cache/slide.inc"; if ($cfg_soft_lang == 'utf-8') { $row = AutoCharset(unserialize(utf82gb($data))); } else { $row = unserialize($data); } } //处理链接地址 if ($GLOBALS['cfg_ask_rewrite'] == 'Y') { $digests = makerewurl($digests, 'id'); $notoks = makerewurl($notoks, 'id'); $solutions = makerewurl($solutions, 'id'); $rewards = makerewurl($rewards, 'id'); } else { $digests = makeurl($digests, 'id'); $notoks = makeurl($notoks, 'id'); $solutions = makeurl($solutions, 'id'); $rewards = makeurl($rewards, 'id'); } //设定变量值 $GLOBALS['row'] = $row; $GLOBALS['digests'] = $digests; $GLOBALS['notoks'] = $notoks; $GLOBALS['rewards'] = $rewards; $GLOBALS['solutions'] = $solutions; $GLOBALS['solvenum'] = $solvenum; //载入模板 $this->SetTemplate('index.htm'); $this->Display(); }
function lib_json(&$ctag, &$refObj) { global $dsql, $sqlCt, $cfg_soft_lang; $attlist = "url|"; FillAttsDefault($ctag->CAttribute->Items, $attlist); extract($ctag->CAttribute->Items, EXTR_SKIP); $Innertext = trim($ctag->GetInnerText()); if ($url == '' || $Innertext == '') { return ''; } $ctp = new DedeTagParse(); $ctp->SetNameSpace('field', '[', ']'); $ctp->LoadSource($Innertext); $mcache = new MiniCache(); $GLOBALS['autoindex'] = 0; $chash = md5($url); if (!($row = $mcache->Get($chash))) { $content = @file_get_contents($url); $json = new Services_JSON(SERVICES_JSON_LOOSE_TYPE); $row = $json->decode($content); if ($cfg_soft_lang != 'utf-8') { $row = AutoCharset($row, 'utf-8', 'gb2312'); } $mcache->Save($chash, $row, $cache); } $revalue = ""; foreach ($row as $key => $value) { $GLOBALS['autoindex']++; foreach ($ctp->CTags as $tagid => $ctag) { if ($ctag->GetName() == 'array') { $ctp->Assign($tagid, $value); } else { if (!empty($value[$ctag->GetName()])) { $ctp->Assign($tagid, $value[$ctag->GetName()]); } else { $ctp->Assign($tagid, ""); } } } $revalue .= $ctp->GetResult(); } return $revalue; }
exit; } else { if ($dopost == 'uninstall') { $row = $dsql->GetOne("SELECT * FROM `#@__payment` WHERE id='{$pid}'"); if ($cfg_soft_lang == 'utf-8') { $config = AutoCharset(unserialize(utf82gb($row['config']))); } else { if ($cfg_soft_lang == 'gb2312') { $config = unserialize($row['config']); } } foreach ($config as $key => $v) { $config[$key]['value'] = ""; } if ($cfg_soft_lang == 'utf-8') { $config = AutoCharset($config, 'utf-8', 'gb2312'); $config = serialize($config); $config = gb2utf8($config); } else { $config = serialize($config); } $query = "UPDATE `#@__payment` SET fee='',config='{$config}',enabled='0' WHERE id='{$pid}'"; $dsql->ExecuteNoneQuery($query); //同时需要删除对应的缓存 $m_file = DEDEDATA . "/payment/" . $row['code'] . ".php"; @unlink($m_file); ShowMsg("删除成功!", "sys_payment.php"); exit; } } }
function lib_sql(&$ctag, &$refObj) { global $dsql, $sqlCt, $cfg_soft_lang; $attlist = "sql|appname"; FillAttsDefault($ctag->CAttribute->Items, $attlist); extract($ctag->CAttribute->Items, EXTR_SKIP); //传递环境参数 preg_match_all("/~([A-Za-z0-9]+)~/s", $sql, $conditions); $appname = empty($appname) ? 'default' : $appname; if (is_array($conditions)) { foreach ($conditions[1] as $key => $value) { if (isset($refObj->Fields[$value])) { $sql = str_replace($conditions[0][$key], "'" . addslashes($refObj->Fields[$value]) . "'", $sql); } } } $revalue = ''; $Innertext = trim($ctag->GetInnerText()); if ($sql == '' || $Innertext == '') { return ''; } if (empty($sqlCt)) { $sqlCt = 0; } $ctp = new DedeTagParse(); $ctp->SetNameSpace('field', '[', ']'); $ctp->LoadSource($Innertext); $thisrs = 'sq' . $sqlCt; $GLOBALS['autoindex'] = 0; // 引入配置文件 if ($appname != 'default') { require_once DEDEDATA . '/tag/sql.inc.php'; global $sqltag; $config = $sqltag[$appname]; if (!isset($config['dbname'])) { return ''; } // 链接数据库 $linkid = @mysql_connect($config['dbhost'], $config['dbuser'], $config['dbpwd']); if (!$linkid) { return ''; } @mysql_select_db($config['dbname']); $mysqlver = explode('.', $dsql->GetVersion()); $mysqlver = $mysqlver[0] . '.' . $mysqlver[1]; // 设定数据库编码及长连接 if ($mysqlver > 4.0) { @mysql_query("SET NAMES '" . $config['dblanguage'] . "', character_set_client=binary, sql_mode='', interactive_timeout=3600 ;", $linkid); } $prefix = "#@__"; $sql = str_replace($prefix, $config['dbprefix'], $sql); // 校验SQL字符串并获取数组返回 $sql = CheckSql($sql); $rs = @mysql_query($sql, $linkid); while ($row = mysql_fetch_array($rs, MYSQL_ASSOC)) { $sqlCt++; $GLOBALS['autoindex']++; // 根据程序判断编码类型,并进行转码,这里主要就是gbk和utf-8 if (substr($cfg_soft_lang, 0, 2) != substr($config['dblanguage'], 0, 2)) { $row = AutoCharset($row, $config['dblanguage'], $cfg_soft_lang); } foreach ($ctp->CTags as $tagid => $ctag) { if ($ctag->GetName() == 'array') { $ctp->Assign($tagid, $row); } else { if (!empty($row[$ctag->GetName()])) { $ctp->Assign($tagid, $row[$ctag->GetName()]); } else { $ctp->Assign($tagid, ""); } } } $revalue .= $ctp->GetResult(); } @mysql_free_result($rs); } else { $dsql->Execute($thisrs, $sql); while ($row = $dsql->GetArray($thisrs)) { $sqlCt++; $GLOBALS['autoindex']++; foreach ($ctp->CTags as $tagid => $ctag) { if ($ctag->GetName() == 'array') { $ctp->Assign($tagid, $row); } else { if (!empty($row[$ctag->GetName()])) { $ctp->Assign($tagid, $row[$ctag->GetName()]); } else { $ctp->Assign($tagid, ""); } } } $revalue .= $ctp->GetResult(); } } return $revalue; }
function AutoCharset($fContents, $from = 'gbk', $to = 'utf-8') { $from = strtoupper($from) == 'UTF8' ? 'utf-8' : $from; $to = strtoupper($to) == 'UTF8' ? 'utf-8' : $to; if (strtoupper($from) === strtoupper($to) || empty($fContents) || is_scalar($fContents) && !is_string($fContents)) { //如果编码相同或者非字符串标量则不转换 return $fContents; } if (is_string($fContents)) { if (function_exists('mb_convert_encoding')) { return mb_convert_encoding($fContents, $to, $from); } elseif (function_exists('iconv')) { return iconv($from, $to, $fContents); } else { return $fContents; } } elseif (is_array($fContents)) { foreach ($fContents as $key => $val) { $_key = AutoCharset($key, $from, $to); $fContents[$_key] = AutoCharset($val, $from, $to); if ($key != $_key) { unset($fContents[$key]); } } return $fContents; } else { return $fContents; } }
/** * 获得文档列表 * * @access public * @param int $limitstart 限制开始 * @param int $row 行数 * @param int $col 列数 * @param int $titlelen 标题长度 * @param int $infolen 描述长度 * @param int $imgwidth 图片宽度 * @param int $imgheight 图片高度 * @param string $achanneltype 列表类型 * @param string $orderby 排列顺序 * @param string $innertext 底层模板 * @param string $tablewidth 表格宽度 * @return string */ function GetArcList($limitstart = 0, $row = 10, $col = 1, $titlelen = 30, $infolen = 250, $imgwidth = 120, $imgheight = 90, $achanneltype = "all", $orderby = "default", $innertext = "", $tablewidth = "100") { global $cfg_sphinx_article; $typeid = $this->TypeID; if ($row == '') { $row = 10; } if ($limitstart == '') { $limitstart = 0; } if ($titlelen == '') { $titlelen = 30; } if ($infolen == '') { $infolen = 250; } if ($imgwidth == '') { $imgwidth = 120; } if ($imgheight = '') { $imgheight = 120; } if ($achanneltype == '') { $achanneltype = '0'; } $orderby = $orderby == '' ? 'default' : strtolower($orderby); $tablewidth = str_replace("%", "", $tablewidth); if ($tablewidth == '') { $tablewidth = 100; } if ($col == '') { $col = 1; } $colWidth = ceil(100 / $col); $tablewidth = $tablewidth . "%"; $colWidth = $colWidth . "%"; $innertext = trim($innertext); if ($innertext == '') { $innertext = GetSysTemplets("search_list.htm"); } if ($cfg_sphinx_article == 'Y') { $ordersql = ''; if ($this->ChannelType < 0 || $this->ChannelTypeid < 0) { if ($orderby == "id") { $ordersql = "@id desc"; } else { $ordersql = "@senddate desc"; } } else { if ($orderby == "senddate") { $ordersql = "@senddate desc"; } else { if ($orderby == "pubdate") { $ordersql = "@pubdate desc"; } else { if ($orderby == "id") { $ordersql = "@id desc"; } else { $ordersql = "@sortrank desc"; } } } } $this->sphinx->SetLimits($limitstart, (int) $row, $row > 1000 ? $row : 1000); $res = array(); $res = AutoCharset($this->sphinx->Query($this->Keywords, 'mysql, delta'), 'utf-8', 'gbk'); foreach ($res['words'] as $k => $v) { $this->Keywords .= " {$k}"; } foreach ($res['matches'] as $_v) { $aids[] = $_v['id']; } $aids = @implode(',', $aids); //搜索 $query = "SELECT arc.*,act.typedir,act.typename,act.isdefault,act.defaultname,act.namerule,\n act.namerule2,act.ispart,act.moresite,act.siteurl,act.sitepath\n FROM `#@__archives` arc LEFT JOIN `#@__arctype` act ON arc.typeid=act.id\n WHERE arc.id IN ({$aids})"; } else { //排序方式 $ordersql = ''; if ($this->ChannelType < 0 || $this->ChannelTypeid < 0) { if ($orderby == "id") { $ordersql = "ORDER BY arc.aid desc"; } else { $ordersql = "ORDER BY arc.senddate desc"; } } else { if ($orderby == "senddate") { $ordersql = " ORDER BY arc.senddate desc"; } else { if ($orderby == "pubdate") { $ordersql = " ORDER BY arc.pubdate desc"; } else { if ($orderby == "id") { $ordersql = " ORDER BY arc.id desc"; } else { $ordersql = " ORDER BY arc.sortrank desc"; } } } } //搜索 $query = "SELECT arc.*,act.typedir,act.typename,act.isdefault,act.defaultname,act.namerule,\n act.namerule2,act.ispart,act.moresite,act.siteurl,act.sitepath\n FROM `{$this->AddTable}` arc LEFT JOIN `#@__arctype` act ON arc.typeid=act.id\n WHERE {$this->AddSql} {$ordersql} LIMIT {$limitstart},{$row}"; } $this->dsql->SetQuery($query); $this->dsql->Execute("al"); $artlist = ""; if ($col > 1) { $artlist = "<table width='{$tablewidth}' border='0' cellspacing='0' cellpadding='0'>\r\n"; } $this->dtp2->LoadSource($innertext); for ($i = 0; $i < $row; $i++) { if ($col > 1) { $artlist .= "<tr>\r\n"; } for ($j = 0; $j < $col; $j++) { if ($col > 1) { $artlist .= "<td width='{$colWidth}'>\r\n"; } if ($row = $this->dsql->GetArray("al")) { if ($this->ChannelType < 0 || $this->ChannelTypeid < 0) { $row["id"] = $row["aid"]; $row["ismake"] = empty($row["ismake"]) ? "" : $row["ismake"]; $row["filename"] = empty($row["filename"]) ? "" : $row["filename"]; $row["money"] = empty($row["money"]) ? "" : $row["money"]; $row["description"] = empty($row["description "]) ? "" : $row["description"]; $row["pubdate"] = empty($row["pubdate "]) ? $row["senddate"] : $row["pubdate"]; } //处理一些特殊字段 $row["arcurl"] = GetFileUrl($row["id"], $row["typeid"], $row["senddate"], $row["title"], $row["ismake"], $row["arcrank"], $row["namerule"], $row["typedir"], $row["money"], $row['filename'], $row["moresite"], $row["siteurl"], $row["sitepath"]); $row["description"] = $this->GetRedKeyWord(cn_substr($row["description"], $infolen)); $row["title"] = $this->GetRedKeyWord(cn_substr($row["title"], $titlelen)); $row["id"] = $row["id"]; if ($row['litpic'] == '-' || $row['litpic'] == '') { $row['litpic'] = $GLOBALS['cfg_cmspath'] . '/images/defaultpic.gif'; } if (!preg_match("/^http:\\/\\//", $row['litpic']) && $GLOBALS['cfg_multi_site'] == 'Y') { $row['litpic'] = $GLOBALS['cfg_mainsite'] . $row['litpic']; } $row['picname'] = $row['litpic']; $row["typeurl"] = GetTypeUrl($row["typeid"], $row["typedir"], $row["isdefault"], $row["defaultname"], $row["ispart"], $row["namerule2"], $row["moresite"], $row["siteurl"], $row["sitepath"]); $row["info"] = $row["description"]; $row["filename"] = $row["arcurl"]; $row["stime"] = GetDateMK($row["pubdate"]); $row["textlink"] = "<a href='" . $row["filename"] . "'>" . $row["title"] . "</a>"; $row["typelink"] = "[<a href='" . $row["typeurl"] . "'>" . $row["typename"] . "</a>]"; $row["imglink"] = "<a href='" . $row["filename"] . "'><img src='" . $row["picname"] . "' border='0' width='{$imgwidth}' height='{$imgheight}'></a>"; $row["image"] = "<img src='" . $row["picname"] . "' border='0' width='{$imgwidth}' height='{$imgheight}'>"; $row['plusurl'] = $row['phpurl'] = $GLOBALS['cfg_phpurl']; $row['memberurl'] = $GLOBALS['cfg_memberurl']; $row['templeturl'] = $GLOBALS['cfg_templeturl']; if (is_array($this->dtp2->CTags)) { foreach ($this->dtp2->CTags as $k => $ctag) { if ($ctag->GetName() == 'array') { //传递整个数组,在runphp模式中有特殊作用 $this->dtp2->Assign($k, $row); } else { if (isset($row[$ctag->GetName()])) { $this->dtp2->Assign($k, $row[$ctag->GetName()]); } else { $this->dtp2->Assign($k, ''); } } } } $artlist .= $this->dtp2->GetResult(); } else { $artlist .= ""; } if ($col > 1) { $artlist .= "</td>\r\n"; } } //Loop Col if ($col > 1) { $artlist .= "</tr>\r\n"; } } //Loop Line if ($col > 1) { $artlist .= "</table>\r\n"; } $this->dsql->FreeResult("al"); return $artlist; }
/** * 获取远程接口数据 * * @access public * @param string * @return string */ function GetAnalyticsDate($url) { global $cfg_bshare, $json, $cfg_soft_lang; $user = $cfg_bshare['user']; $pass = $cfg_bshare['pwd']; $results = DownHost($url, '', 'GET', NULL, NULL, $user, $pass); try { $result = $json->decode($results['results']); } catch (Exception $e) { trigger_error("Server Error:" . $result); } //if ($cfg_soft_lang == 'gb2312') //{ $result = AutoCharset($result, 'utf-8', 'gbk'); //} return $result; }