phpwind民间论坛wap风格正式发布~20141219更新

sundianjing
45楼sundianjing高级会员 2014-12-19 19:02
哈哈,不客气啊,我就喜欢和大家一起互相学习!


还有个问题,就是手机端选择访问PC端,会跳转到WAP端,我觉得这不是BUG吧,只是功能有缺陷


我现在实现了WAP端手动访问PC端首页不再跳转到WAP端,原理是在URL中增加一个来自WAP端的参数,
但是除了这个带参数的页面外,其它PC页面仍然会自动跳转到WAP端,我在想的最佳方案应该是增加一个cookie,记忆用户选择,在cookie有效期内都访问一个版本,唉,不太懂cookie,我赶紧去恶补一下!………………
admin
46楼admin社区管理 2014-12-19 19:48
之前是可以跳转到电脑版本的?~
我这边再看看~
韬光晦影
47楼韬光晦影新手上路 2014-12-19 20:31
不是吧,我是沙发?admin你要感谢我,我回一帖就引来这么多人盖楼。
admin
48楼admin社区管理 2014-12-19 20:32
确实应该感谢啊~
韬光晦影
49楼韬光晦影新手上路 2014-12-19 20:33
先从最基本的登录、看帖、发帖(发图片)开始。手机很重要的功能就是贴图。慢慢要考虑开发app允许共享图片和文件。
admin
50楼admin社区管理 2014-12-19 20:36
发图这一块得延后了。
我们先 看看官方论坛的移动端怎么样~
sundianjing
51楼sundianjing高级会员 2014-12-19 23:51
累死了,搞了几个小时,终于把手机访问PC端自动跳转到WAP端的问题解决了!像我这种php初学者就是菜啊,恨!
故障现象:WAP端手动访问PC端,仍会跳至WAP端
解决方案:增加一个URL参数,并设置cookie
最终结果:WAP端手动访问这个带特定参数的URL后会产生一个cookie,在cookie有效期内,都不会再自动跳转至WAP端
已知缺陷:如果手动访问PC端后,在cookie有效期内PC端就不能再自动跳转至WAP端了,需要手动清除cookie才会自动跳转到WAP,这个问题其实可以在PC端增加一个WAP链接,设置个URL参数清除掉cookie就行了,但我认为不必了。
详细代码如下:\src\extensions\Medz3gUrlSkip\service\srv\App_Medz3gUrlSkip_ConfigDo.php
<?php
defined('WEKIT_VERSION') or exit(403);
/**
 * 后台菜单添加
 *
 * @author <lovevipdsw@vip.qq.com>
 * @copyright http://www.medz.cn
 * @license http://www.medz.cn
 */
class App_Medz3gUrlSkip_ConfigDo {
 
    public function getHead() {
        $global = wekit::getGlobal();
        $url = $this->getUrl($global['request']);
        $this->goToUrl($url['wap'], $url['pc'], $url['state']);
    }
     
    public function getFooter() {
        $global = wekit::getGlobal();
        $url = $this->getUrl($global['request']);
        $this->echoJavaScript($url['wap'], $url['pc']);
    }
     
    public function goToUrl($wapUrl, $pcUrl, $state) {
        $is = $_GET['is'];
        if(empty($is)) {
            if($this->is_wap() != $state) {
                $html = "";
                if($this->is_wap() == "wapTopc") {
                    $html = '
                        <script type="text/javascript">
                            var exdate=new Date();
                            exdate.setTime(exdate.getTime() + 86400000);
                            document.cookie="from = 2;expires=" + exdate.toGMTString();
                        </script>
                    ';//写入cookie,有效时间24小时
                } else if($this->is_wap() == "wap") {
                    $html = '
                        <script type="text/javascript">
                            window.location.href="' . $wapUrl . '";
                        </script>
                    ';
                } else if($this->is_wap() == "pc") {
                    $html = '
                        <script type="text/javascript">
                            window.location.href="' . $pcUrl . '";
                        </script>
                    ';
                }
                if(!empty($wapUrl) && !empty($pcUrl)) {
                    echo $html;
                }
            }
        }
    }
     
    public function getUrl($s) {
        if($s['m'] == 'bbs' || $s['m'] == "message" || $s['m'] == "u") {
            $pc = WindUrlHelper::createUrl($s['mca'] . $this->_get());
            $wap = WindUrlHelper::createUrl("3g/" . $s['c'] . "/" . $s['a'] . $this->_get());
        }
        if($s['m'] == "space") {
            if($s['c'] == "index" || $s['c'] == "profile") {
                $pc = WindUrlHelper::createUrl($s['mca'] . $this->_get());
                $wap = WindUrlHelper::createUrl("3g/profile/" . $s['a'] . $this->_get());
            }
        }
        if($s['m'] == "profile") {
            $pc = WindUrlHelper::createUrl($s['mca'] . $this->_get());
            if($s['c'] == "index") {
                $wap = WindUrlHelper::createUrl("3g/userinfo/" . $s['a'] . $this->_get());
            }
            if($s['c'] == "education" || $s['c'] == "work" || $s['c'] == "secret" || $s['c'] == "password") {
                $wap = WindUrlHelper::createUrl("3g/" . $s['c'] . "/" . $s['a'] . $this->_get());
            }
        }
        $state = "pc";
        /* -----------------------分割线------------------------- */
        if($s['m'] == '3g') {
            $wap = WindUrlHelper::createUrl($s['mca'] . $this->_get());
            if($s['c'] == "forumlist" || $s['c'] == "index" || $s['c'] == "thread" || $s['c'] == "read" || $s['c'] == "post") {
                $pc = WindUrlHelper::createUrl("bbs/" . $s['c'] . "/" . $s['a'] . $this->_get());
            }
            if($s['c'] == "message" || $s['c'] == "notice") {
                $pc = WindUrlHelper::createUrl("message/" . $s['c'] . "/" . $s['a'] . $this->_get());
            }
            if($s['c'] == "profile") {
                $pc = WindUrlHelper::createUrl("space/index/" . $s['a'] . $this->_get());
            }
            if($s['c'] == "login" || $s['c'] == "findPwd" || $s['c'] == "register") {
                $pc = WindUrlHelper::createUrl("u/" . $s['c'] . "/" . $s['a'] . $this->_get());
            }
            if($s['c'] == "userinfo") {
                $pc = WindUrlHelper::createUrl("profile/index/" . $s['a'] . $this->_get());
            }
            if($s['c'] == "education" || $s['c'] == "work" || $s['c'] == "secret" || $s['c'] == "password") {
                $pc = WindUrlHelper::createUrl("profile/" . $s['c'] . "/" . $s['a'] . $this->_get());
            }
            $state = "wap";
        }
        return array('pc' => $pc, 'wap' => $wap, 'state' => $state);
    }
     
    public function echoJavaScript($wapUrl, $pcUrl) {
        if(strstr($wapUrl, "?")) {
            $wapUrl .= "&is=1";
        } else {
            $wapUrl .= "?is=1";
        }
        if(strstr($pcUrl, "?")) {
            $pcUrl .= "&is=1";
        } else {
            $pcUrl .= "?is=1";
        }
        $html = '
        <script type="text/javascript">
            wap = document.getElementById("a_wap");
            pc = document.getElementById("a_pc");
            wap.href = "' . $wapUrl . '";
            pc.href = "' . $pcUrl . '";
        </script>
        ';
        echo $html;
    }
     
    public function _get() {
        $get = array();
        foreach($_GET as $k => $v) {
            if($k != "c" && $k != "m" && $k != "a" && $k != "is") {
                $get[$k] = $v;
            }
        }
        $ar = "?";
        $i = 1;
        foreach($get as $k => $v) {
            $ar .= $k . "=" . $v;
            if($i < count($get)) {
                $ar .= "&";
                $i++;
            }
        }
        return $ar;
    }
     
        public function is_wap(){
        $urlget = $_SERVER["QUERY_STRING"];//获取URL参数
        $from = preg_match('/from=mobile/i',$urlget);//正则匹配特定参数
        if( $_COOKIE["from"] == "2" ){//先判断cookie是否存在
            return 'pc';
        }else if($from == 1){
            return 'wapTopc';//特定参数存在,返回值
        }else if(stristr($_SERVER['HTTP_VIA'],"wap")) {// 先检查是否为wap代理,准确度高.
            return 'wap';
        }else if(strpos(strtoupper($_SERVER['HTTP_ACCEPT']),"VND.WAP.WML") > 0) {// 检查浏览器是否接受 WML.
            return 'wap';
        }else if(preg_match('/(blackberry|configuration\/cldc|hp |hp-|htc |htc_|htc-|iemobile|kindle|midp|mmp|motorola|mobile|nokia|opera mini|opera |Googlebot-Mobile|YahooSeeker\/M1A1-R2D2|android|iphone|ipod|mobi|palm|palmos|pocket|portalmmm|ppc;|smartphone|sonyericsson|sqh|spv|symbian|treo|up.browser|up.link|vodafone|windows ce|xda |xda_)/i', $_SERVER['HTTP_USER_AGENT'])) {//检查USER_AGENT
            return 'wap';
        }else{
            return 'pc';
        }
    }
     
}
 
?>
然后修改\template\3g\footer.htm文件底部链接修改为:
<a href="index.php?m=bbs&c=forumlist&from=mobile">直接访问电脑版</a>
此人不存在
52楼此人不存在初级会员 2014-12-20 00:27
好多高手
我是东西
53楼我是东西初级会员 2014-12-20 09:07
@sundianjing   内容页文字大小改哪里呀?还有行距能大些吗?
韬光晦影
54楼韬光晦影新手上路 2014-12-20 10:45
能这样分析代码,你已经很强大了。
韬光晦影
55楼韬光晦影新手上路 2014-12-20 10:48
其实你应该和官方联系一下,搞合作。既然这个风格已经这么好了,官方如果还没怎么开始,倒不如合作把这一个搞好。
其实应该把方向搞清楚。当时PHPwind要搞客户端也是个挺好的方向。毕竟现在手机用户都是认客户端,而很多客户端也就是个浏览器而已。
sundianjing
56楼sundianjing高级会员 2014-12-20 12:19
你在3g.css文件内增加以下CSS代码就能设置内容的字体大小和行距了

.editer_content{
font-size:14px;
line-height:25px;
color:#333333;
}
font-size:字体大小
line-height:行距
color:字体颜色
孤独之虎
57楼孤独之虎超级版主 2014-12-20 12:58
这个要支持,用ipad访问,就是这个效果。
yfyn
58楼yfyn初级会员 2014-12-20 14:42
政好需要
littleyang
59楼littleyang初级会员 2014-12-20 17:24
感谢元芳分享
weixin
小谷派

每一天,发现生活之美!

微信号:sdhy2006