Discuz! Research on accessing and displaying pictures by Wap in 7.0

Source: Internet
Author: User

Http://www.oldjun.com/blog/index.php/archives/46/

Because I manage my own forums and have some functional defects in the forums, I will try to improve them. So I have this article. The idea of playing black is very important, and the idea of writing a program is equally important. Since there are few technical articles on the wap display images of the Discuz forum on the Internet, the official version of wap is delayed, so you can only rely on yourself.

I searched the official forum for a long time and checked the handling methods of Version 5.5 and version 6.0. After modification, I got the corresponding Discuz! 7.0 The following figure shows the wap image display method. Use the wapcode function to replace some strings. The Code is as follows (modify the wapcode function in global. func. php ):

Function wapcode ($ string ){
Global $ lang;
$ String = str_replace (array ([attach], [/attach]), array (), $ string );
$ String = str_replace (array ([img], [/img]), array (), $ string );
$ String = preg_replace ("/[url = (http: //. *?)] (.*?) [/Url]/is "," <a href = "\ 2 \ 1"> \ 2 </a> ", $ string );
$ String = preg_replace ("/[url] (. *?) [/Url]/is "," <a href = "\ 1 \ 1"> \ 1 </a> ", $ string );
$ String = str_replace (array (&, ", <,>), array (&,", & lt;, & gt;), $ string );
$ String = str_replace (array (& lt; img src1 = ", & lt; img src2 =", "alt =" p "/& gt ;), array (
), $ String );
$ String = str_replace (array (& lt; a href = "," & gt;, & lt;/a & gt;), array (<a href = ", ">,</a>), $ string );
$ String = preg_replace ("/[hide] (. + ?) [/Hide]/is ", $ lang [post_hide_reply_hidden], $ string );
$ String = preg_replace ("/[hide = (d +)] s * (. + ?) S * [/hide]/ies ", $ lang [post_hide_reply_hidden], $ string );
For ($ I = 0; $ I <1; $ I ++ ){
$ String = preg_replace ("/[(w +) [^] *?] (.*?) [/\ 1]/is "," \ 2 ", $ string );
}

Return $ string;
}
After the test, the image is displayed successfully. No exception was found for one or two images. However, when there were too many images, an error was reported on the mobile phone. I checked the code carefully and found that this method only changed the wapcode ($ string) function, however, the wapcutstr ($ string, & $ length) method is not adjusted accordingly. Therefore, when you flip pages, the page may fail to be displayed due to the disconnection of the img tag, in this case, it is not only an img tag. If wapcutstr is not processed and you want to use html tags, It is impossible because the tags are processed as strings during string truncation. So I want to change the wapcutstr function, I also found the corresponding modified version on the Internet, but I did not continue, because later I found that the pictures looked uncomfortable on the mobile phone, so I had a second idea of displaying images.

There are only two types of images in the post: one is a remote image, which is called using [img] [/img]; the other is a local image, which can be read directly from the database. In this case, why bother replacing strings and simply displaying all the images on the first page of the post. Implementation Code (Add the following code to $ post [author] = in thread. inc. php! $ Post [anonymous]? $ Post [author]: $ lang [anonymous]; Front ):

If (! $ Offset | $ offset =-1 ){
If (preg_match_all ("/[img (. *?)] (.*?) [/Img]/is ", $ strpost, $ imgout, PREG_PATTERN_ORDER )){
$ Imgnum = count ($ imgout [2]);
$ Img = "";
For ($ I = 0; $ I <$ imgnum; $ I ++ ){
If ($ imgout [1] [$ I] & strpos ($ imgout [1] [$ I], ",") {
$ Imgwidth = explode (",", str_replace ("=", "", $ imgout [1] [$ I]);
$ Newwidth = $ imgwidth [0]> 100? 100: $ imgwidth [0];
} Else {
$ Newwidth = 100;
}
$ Img. =
;
}
$ Threadposts. = $ img;
}
If ($ post [attachment]) {
$ Attquery = $ db-> query ("SELECT * FROM {$ tablepre} attachments WHERE pid = $ post [pid]");
While ($ attach = $ db-> fetch_array ($ attquery )){
If ($ attach [isimage]) {
$ Attachimg. =
;
}
}
$ Threadposts. = $ attachimg;
}
}
At this point, the basic problem of image display is perfectly solved. As for the problem of image size thumbnails, I did not continue to study it. In addition, I did not consider reading permission issues (if I want to consider it, I just need to change the code slightly)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.