tipask 修改,临时的(暂没进行很好的全面考虑,为上线用)
此問吧程序基本上是
通過index.php來傳遞操作信息;
在control(起了設置參數=功能)中對應的名字的php調用model(用于實現功能)對應名字的php;
再調用對應的html來顯示;
html是保存在view中;
2011-2-21 by qidizi
增加功能:
分類中增加一個屬性,用于控制是否在前臺主頁分類中顯示此分類;
1 ask_category表中增加一個字段:index_show boolean 默認是0;
alter table ask_category add `index_show` boolean not null default 0;
2 修改view目錄中editcategory.html文件加上開關
?在分類目錄后插入以下代碼
<tr>
<th colspan="2">首頁顯示:</th>
</tr>
<tr>
<td><input name="index_show" type="checkbox"? {eval echo ($category['index_show']?"checked":''); }></td>
<td>在首頁左邊的分類中是否顯示。</td>
</tr>
3 修改control文件夾中admin_category.php加上傳入參數代碼
?????????? 在onedit()中
??????????? $index_show = $this->post['index_show'];
??????????? if (isset($index_show) && ($index_show == 'on'))$index_show=1;
??????????? else $index_show = 0;
前插入上面代碼,并為下面增加參數$index_show,
??????????? $_ENV['category']->update_by_id($id,$name,$categorydir,$cid,$index_show);
4 model文件夾中category.class.php增加接收參數
? function update_by_id($id,$name,$categorydir,$pid,$index_show) {
?
? $this->db->query("UPDATE `".DB_TABLEPRE."category` SET? `index_show`=$index_show,`pid`=$pid ,`grade`=$grade , `name`='$name', `dir`='$categorydir' WHERE `id`=$id");//add by qidizi `index_show`=$index_show,
增加一參數,$index_show;
5 model中category.class.php修改
/*用于在首頁左側顯示*/
??? function list_by_grade($grade=1) {
成判斷是否屬于首頁顯示的分類再加入首頁調用的數組;
$query=$this->db->query("select id,name,questions,grade,index_show from ".DB_TABLEPRE."category where grade=1 order by displayorder asc,id asc");
加入查詢index_show的字段;
while($category1=$this->db->fetch_array($query)) {
??????????? if (!$category1['index_show']) continue;//不屬于首頁分類不加入數組;
加入只有首頁顯示的分類才顯示;
修改完成;
?
?
----------------------------------------
2011 2 22 屏閉掉回答問題的論證碼檢查功能
model中base.class.php
/*檢查驗證碼*/
??? function checkcode() {
??? return true;//add by qidizi,no code;
中中斷為直接返回true;
--------------------------------
2011 2 22
增加寫入緩存權限判斷,否則移動到新服務器時因為緩存文件不存在,寫入失敗而導致錯誤錯誤
lib中tem...func.php
??? $fp = @fopen($objfile, 'w') or die("Directory './data/view/' not found or have no access!");
??? $template = preg_replace("//"(http)?[/w/.//:]+/?[^/"]+?&[^/"]+?/"/e", "transamp('//0')", $template);
??? $template = preg_replace("//<script[^/>]*?src=/"(.+?)/".*?/>/s*/<//script/>/ise", "stripscriptamp('//1')", $template);
??? flock($fp, 2);
??? @fwrite($fp, $template) or die("Directory './data/view/'? no access for write!");
??? fclose($fp);
}
--------------
去掉端口號,如何使用有端口登錄時
根目錄下的index.php中,改寫site_url定義
define('SITE_URL','http://'.preg_replace('///:/d+/','',$_SERVER['HTTP_HOST']).substr($_SERVER['PHP_SELF'],0,-9) );//add by qidizi
----------------------
緩存功能導致發貼不及時顯示優化,暫不用,發現動態解釋時,用到model=模式,會出錯
view文件夾中的tip.html文件
修改成以下代碼,主要是用js加上時間,讓服務器及時更新
??????????????????????? 頁面將在6秒后自動跳轉到下一頁,你也可以直接點 <a href="$redirect" >立即跳轉</a>。
??????????????????????? <script type="text/javascript">
??????????????????????????? function redirect(url, time) {
??????????????????????????????? if (!//?/.test(url)) url = url + "?time=" + new Date().getTime();
??????????????????????????????? else if (//?.+/.test(url)) url = url + "&time=" + new Date().getTime();
??????????????????????????????? else url = url + "time=" + new Date().getTime();
??????????????????????????????? setTimeout("window.location='" + url + "'", time * 1000);
??????????????????????????? }
??????????????????????????? redirect('$redirect', 6);
??????????????????????? </script>
???????????????????????
???????????????????????
--------------------------
在view default下面的nosole.html list.html close.html sole.html== 包含有 賞金求答案 的都是用于對應頁面:問題關閉,待解決,已解決,列表;可以使用動態地址方式看到實時修改模板效果;
----------
解決js跨域問題:
注意下面代碼不能直接放到html中,因為tipask的模板解釋script,導致頁面出錯;
所以只能使用js調用方式js_reset_domain(js_path)
qidizi.js
function js_reset_domain(js_path)
{//解決跨域問題,替換成當前域
? js_path = js_path.replace(/^ *http/:[^//]+/i,"http://" + location.hostname);
? js_path = '<script type="text/javascript" ' + ' src="' + js_path;
? js_path = js_path + '" ' + '></script' + '>';
? document.writeln( js_path );
}
<script type="text/javascript" src="{SITE_URL}js/qidizi.js"></script>
<script type="text/javascript">
?js_reset_domain("{SITE_URL}js/jquery.js");
?js_reset_domain("{SITE_URL}js/dialog.js");
?js_reset_domain("{SITE_URL}js/common.js");
</script>
-------------
解決動態頁面使用www有緩存地址問題
首頁index.php
有聲明SITE_URL下行
修改
define('SITE_URL_WWW','http://www.'.preg_replace('///:/d+/','',preg_replace('/^ *www//./','',$_SERVER['HTTP_HOST'])).substr($_SERVER['PHP_SELF'],0,-9) );//有www,去掉端口
define('SITE_URL',preg_replace("/^ *http//:// *www//./i",'http://',SITE_URL_WWW));//無www,
在lib
template.func.php中加入一個func
function no_www($url)
{//去掉www,只使用父域
? return preg_replace("/^ *http//:// *www//./i",'http://',$url);
}
上面修改用于直接調用
在lib
template.func.php
??? $template = preg_replace("//{url/s+(.+?)/}/ies", "url('//1')", $template);//這行插入下面二句
??? $template = preg_replace("//{url_www/s+(.+?)/}/ies", "url_www('//1')", $template);//無www
并在global.func.php加入以下二個func
/* 返回無緩存頁面地址 */
function url_www($var, $url='') {
??? global $setting;
??? $location = '?' . $var . $setting['seo_suffix'];
??? if ($setting['static_on'] && $url) {
??????? return SITE_URL_WWW . $url; //主要是程序動態獲取的,給question的model使用
??? }
??? if ($setting['seo_on']) {
??????? $rewritearray = array('question/view/', 'category/view/', 'category/list/', 'category/recommend/', 'user/space/', 'user/scorelist/');
??????? foreach ($rewritearray as $item) {
??????????? if (false !== strpos($var, $item)) {
??????????????? $location = $var . $setting['seo_suffix'];
??????????? }
??????? }
??? }
??? $location = urlmap($location, 2);
??? if ($url)
??????? return SITE_UR_WWW . $location; //程序動態獲取的,給question的model使用
?else
??????? return '<?=SITE_URL_WWW?>' . $location; //模板編譯時候生成使用
}
在調用時對應調用即可;
靜態直接使用{$sss['url']},不要使用{url xxx}
---------
修改cookie域
數據庫中setting表中cookie_domain修改;
--------
修改headter.html模板的site_url重設,解決跨域問題;
js/qidizi.js中
function reset_domain(js_path)
{//解決跨域問題,替換成當前域
? js_path = js_path.replace(/^ *http/:[^//]+/i,"http://" + location.hostname);
? return js_path;
}
?
js/qidizi.js中
function reset_domain_no_www(js_path)
{//替換成無www.
? js_path = js_path.replace(/^ *http/:www/./i,"http://");
? return js_path;
}
---------------------
解決生成靜態,也把用戶生成了;
在header.html中替換掉用戶條那里.
<div class="top">
?<iframe src="{SITE_URL_WWW}index.php?user/login_show.html" style="width:100%;height:23px;border:0px;" FRAMEBORDER=0></iframe>要替換成這個,在上面和下面之間
?<div class="top2">
?
?
?保存login_show.html到viw default
?{eval global $starttime,$querynum;$mtime = explode(' ', microtime());$runtime=number_format($mtime[1] + $mtime[0] - $starttime,6); $setting=$this->setting;$user=$this->user;$headernavlist=$this->nav;$regular=$this->regular;}
<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset={TIPASK_CHARSET}"/>
<title>{$navtitle} {$setting['site_name']} {$setting['seo_title']}</title>
<meta name="keywords" content="{$metakeywords}{$setting['seo_keywords']}" />
<meta name="description" content="$metadescription {$setting['site_name']} {$setting['seo_description']}" />
<meta name="generator" content="Tipask {TIPASK_VERSION} {TIPASK_RELEASE}" />
<meta name="author" content="Tipask Team" />
<meta name="copyright" content="2011 Tipask.com." />
<meta name="robots" content="index, follow">
<meta name="googlebot" content="index, follow">
<link href="{SITE_URL}css/default/ask.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="{SITE_URL}js/qidizi.js"></script>
<script type="text/javascript">
g_site_url=reset_domain('{SITE_URL}');g_prefix='{$setting['seo_prefix']}';g_suffix='{$setting['seo_suffix']}';editor_items='{$setting['editor_items']}';
</script>
<script type="text/javascript">
?js_reset_domain("{SITE_URL}js/jquery.js");
?js_reset_domain("{SITE_URL}js/dialog.js");
?js_reset_domain("{SITE_URL}js/common.js");
</script>
{$setting['seo_headers']}
</head>
<body>
<div class="top1 blake">
??<div class="top1right">
??????????? <a href="{SITE_URL}" target="_blank">問答首頁</a><span>︱</span>
??????????? <a href="{url user/ask}" target="_blank">我的提問</a><span>︱</span>
??????????? <a href="javascript:void(0)" οnclick="SetHomepage()">設為首頁</a><span>︱</span>
??????????? <a href="javascript:void(0)" οnclick="addfavorite()">收藏夾</a><span>︱</span>
??????????? <a href="{url index/help}" target="_blank">幫助</a>
??</div>
??<span class="rit padding-r">
??<!--{if 0!=$user['uid']}-->
???您好,<a href="{url_www user/default}" target="_blank"><strong>{$user['username']}</strong></a>
???<!--{if $user['newmsg']>0}-->
???| <a id="TopLink_MessageBox" href="{url_no_www message/new}" target="_blank">您有<span id="MessagesCount" style="color: rgb(255, 0, 0);">{$user['newmsg']}</span>條新信息</a>
??? <!--{/if}-->
???| <a href="{url_no_www user/default}"? target="_blank">個人中心</a>
???<!--{if $user['groupid']<=3}-->
???| <a href="{SITE_URL_NO_WWW}index.php?admin_main"? target="_blank">系統設置</a>
???<!--{/if}-->
???| <a href="{url_no_www user/logout}" target="_top">退出</a>
??<!--{else}-->
????? 您好,歡迎來{$setting['site_name']}![<a? href="{url_no_www user/login}"? target="_top">請登錄</a>]
?????? [<a? href="{url_no_www user/register}" target="_top">免費注冊</a>]
??<!--{/if}-->
??</span>
?</div>
?
</body>
</html>
?
base.class.php
??? /*權限檢測*/
??? function checkable($url) {
??????? $this->regular=$url;
??????? if(1==$this->user['groupid']) return true;
??????? $regulars = explode(',', 'user/login,user/logout,user/code,user/getpass,user/resetpass,index/help,js/view,user/login_show,'.$this->user['regulars']);//加上user/login_show,注意最后是,
???????
???????
??????? user.php
??????? 中加入
???????
??????? func
???????
???????
??? function onlogin_show() {
??????? $this->load('setting');
??????? $wordslist = unserialize($this->setting['hot_words']);
??????? $linklist=$this->cache->load('link','id','displayorder');
??????? include template('login_show');
??? }
???
???
???
??? -------------
???
??? 解決靜態化沒登錄跳到不正確的地址
???
??? user.php中改成
??? $this->message('用戶名或密碼錯誤!', 'index.php?user/login');
???
??? ------------------
??? 原參數改成帶www nowww就是無
??? index.php中改
define('SITE_URL','http://www.'.preg_replace('///:/d+/','',preg_replace('/^ *www//./','',$_SERVER['HTTP_HOST'])).substr($_SERVER['PHP_SELF'],0,-9) );
------------------------
使用了框架,需要改退出鏈接成 target="_self" 和user.php onloginut中messge這里加上'BACK';讓在框架內運行
---------------
在lib/global.func.php中加入一func
function domain_www($url='') {//把絕對地址轉成有www
??????? if ( preg_match("/^/s*http/:/i",$url)? && (!preg_match("/^/s*http/:www/./i",$url)) )
????????????? $url= preg_replace("/^/s*http/:/i",'http://www.',$url);
??????? return $url;
}
在模板中使用
href="{= domain_www($nosolve['url']);}"
---------------
lib/temp...func.php
??? $template = preg_replace("//{///=/s*([a-zA-Z0-9_/[/]/'/"/$/./x7f-/xff]+)/}/s", "<? echo //1?>", $template);//{= domain_www($nosolve['url']);} 增加解釋此格式標簽
???
???
??? -------------------
??? lib/template.func .php
??? 存在一個不存在的func
??? texit,已修改成exit;
??? 是在緩存文件夾不可用時使用;
???
??? --------------
??? 錄入站把模板header.html中的框架中的地址改成http://47389.com/ask/.....
??? 然后在base.class.php
??? 中修改,加入復制中的內容
???
???? /*生成一個問題的靜態頁面*/
??? function write_question($question) {
??????? global $setting,$db;
??????? include_once TIPASK_ROOT.'/control/question.php';
??????? $this->get[2]=$question['id'];
??????? $control = new questioncontrol($this->get,$this->post);
??????? ob_start();
??????? $control->onview();
??????? $html=ob_get_contents();
??????? ob_end_clean();
??????? $staticurl=getstaticurl($question);
??????? if($question['url'] && file_exists($question['url'])) {
??????????? unlink($question['url']);
??????? }
??????? $this->db->query("UPDATE `".DB_TABLEPRE."question`? SET url='$staticurl'? WHERE id =".$question['id']);
??????? forcemkdir(dirname($staticurl));
??????? writetofile($staticurl,$html);
??????? //復制
??????? $ask_html = preg_replace("/http:(www/.)?47389/.com//ask_admin/i", 'http://www.47389.com/ask', $html);
??????? $ask_q_dir = '/var/www/html/ask/question/' . preg_replace('/^.*///','',$staticurl);
??????? qidizi($ask_q_dir. chr(10).$ask_html);
??????? writetofile($ask_q_dir,$ask_html);
??????? //復制
???????
??????? return $staticurl;
??? }
??? 就可以達到錄入時把內容生成到www的站中.
???
???
???
???
???
???
???
???
???
??? ----------------
??? 首頁==網友在問這些,
??? 因為在base中用到查詢數據庫中最新數據,在分類代碼寫法上可能有問題,導致最后分類不是所有最新,而是某一個類,
??? 需要到base.clas中改 ''成null
??? 因為判斷中用到
??? (type ) && (sql .= '')這樣的寫,就是如果分類設置了就拼接上.
???
??? -----------
???
??? 把首頁的網友正在問,改成無分類區別,要求所有的分類
???
???
??????????? case 'indexnosolvelist': //首頁待解決問題,網友正在問,這個無分類限制,全部分類
??????????????? $this->load('question');
??????????????? $cachedata=$_ENV['question']->list_by_cfield_cvalue_status(null,0,1,0,$this->setting['list_indexnosolve']);
??????????????? break;
???????????????
??????????????? 而需要在首頁的模板中用到indexno...這個,而不是原來的.
總結
以上是生活随笔為你收集整理的tipask 修改,临时的(暂没进行很好的全面考虑,为上线用)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: BAT 面试题:25匹马,5个跑道,每个
- 下一篇: 车载颚式移动破碎机让资源重生,刻不容缓