Discuz! Plug-in: Automatically hide the Post _ php instance

Source: Internet
Author: User
Tags php switch
Discuz! Plug-in: Automatically hide Post preface
At the request of a netizen, the open volume studio created the plug-in for automatically hiding posts. The main purpose is to automatically hide all posted posts without manually adding the [hide] code, the member can view the post only after replying. This idea is quite good, and it is not very difficult to implement this function, so I just made a try. The plug-in provides two automatic hiding modes: one is to hide posts on the first floor, and the other is to hide all posts including replies. Because the Green Plug-in style of the open-volume studio can not be changed without changing the database, so this plug-in does not add the background switch function, but only provides the config. inc. php switch settings.
This plugin applies to Discuz! For all versions of the forum, only the installation methods of DZ4.1/DZ5.0/DZ5.5 are provided. For other versions of the forum, please modify them as needed.
Update record:
Fixed the issue where posts that do not contain Forum code could not be hidden. added the settings for hiding all posts except the first floor. added the preview byte settings, after setting, you can preview some hidden post content, so that the posts with good content can attract more people to participate in the reply. you can also customize the setting of forums to enable the automatic hide function.
You can only read part of the content when visiting the website from. The effect is as follows:
Sorry, you are in the tourist status, so you can only read part of the content. To read the complete information, register or log on.
Correction of announcements and short messages will also be automatically hidden, and errors will be reported due to the lack of variables; added settings that allow or exclude the auto-hide function of the specified forum; two solutions are provided to solve the page code disorder after text truncation. you can choose to use them as needed.
Added the compatibility modification with the interference code on February 4.
Added Discuz in! 5.5 installation method, and the test is successful.
Name: The opening studio automatically hides the post [enhanced version] For Discuz! All Version
Difficulty: average
Applicable version: Discuz! All versions
Author: KaijuanStudio
Release date: 2006-11-07
Updated on: 2007-03-14
Release site: China Manufacturing Forum
Technical support: https://www.php1.cn/
The installation method is as follows:
Modify: viewthread. php
Open: viewthread. php
DZ4.1, find:
$ Post ['message'] = discuzcode ($ post ['message'], $ post ['smileyoff '], $ post ['bbcodeoff'], $ post ['htmlon'], $ forum ['allowsresults'], $ forum ['allowbucketcodes '], $ forum ['allowimgcode'], $ forum ['allowhtml'], ($ forum ['jammer'] & $ post ['authorid']! = $ Discuz_uid? 1: 0); Replace:
$ Post ['message'] = discuzcode ($ post ['message'], $ post ['smileyoff '], $ post ['bbcodeoff'], $ post ['htmlon'], $ forum ['allowsresults'], $ forum ['allowbucketcodes '], $ forum ['allowimgcode'], $ forum ['allowhtml'], ($ forum ['jammer'] & $ post ['authorid']! = $ Discuz_uid? 1: 0), $ post ['first']); DZ5.0, locate:
$ Post ['message'] = discuzcode ($ post ['message'], $ post ['smileyoff '], $ post ['bbcodeoff'], $ post ['htmlon'], $ forum ['allowscloud'], $ forum ['allowbucketcodes '], ($ forum ['allowimgcode'] & $ showimages? 1: 0), $ forum ['allowhtml '], ($ forum ['jammer'] & $ post ['authorid']! = $ Discuz_uid? 1: 0), $ pasetype, $ post ['authorid']); Replace:
$ Post ['message'] = discuzcode ($ post ['message'], $ post ['smileyoff '], $ post ['bbcodeoff'], $ post ['htmlon'], $ forum ['allowscloud'], $ forum ['allowbucketcodes '], ($ forum ['allowimgcode'] & $ showimages? 1: 0), $ forum ['allowhtml '], ($ forum ['jammer'] & $ post ['authorid']! = $ Discuz_uid? 1: 0), $ pasetype, $ post ['authorid'], $ post ['first']); DZ5.5, locate:
$ Post ['message'] = discuzcode ($ post ['message'], $ post ['smileyoff '], $ post ['bbcodeoff'], $ post ['htmlon'], $ forum ['allowscloud'], $ forum ['allowbucketcodes '], ($ forum ['allowimgcode'] & $ showimages? 1: 0), $ forum ['allowhtml '], ($ forum ['jammer'] & $ post ['authorid']! = $ Discuz_uid? 1: 0), 0, $ post ['authorid']); Replace:
$ Post ['message'] = discuzcode ($ post ['message'], $ post ['smileyoff '], $ post ['bbcodeoff'], $ post ['htmlon'], $ forum ['allowscloud'], $ forum ['allowbucketcodes '], ($ forum ['allowimgcode'] & $ showimages? 1: 0), $ forum ['allowhtml '], ($ forum ['jammer'] & $ post ['authorid']! = $ Discuz_uid? 1: 0), 0, $ post ['authorid'], $ post ['first']);
Modify: discuzcode. func. php
Open: include \ discuzcode. func. php
DZ4.1, find:
Function discuzcode ($ message, $ smileyoff, $ bbcodeoff, $ htmlon = 0, $ allowsmilies = 1, $ allowbbcode = 1, $ allowimgcode = 1, $ allowhtml = 0, $ jammer = 0) {Replace:
Function discuzcode ($ message, $ smileyoff, $ bbcodeoff, $ htmlon = 0, $ allowsmilies = 1, $ allowbbcode = 1, $ allowimgcode = 1, $ allowhtml = 0, $ jammer = 0, $ first = '0') {add the following row:
Global $ discuzcodes, $ credits, $ tid, $ discuz_uid, $ highlight, $ maxsmilies, $ db, $ tablepre; Replace:
Global $ discuzcodes, $ credits, $ fid, $ tid, $ discuz_uid, $ highlight, $ maxsmilies, $ db, $ tablepre, $ hidemsg, $ hidecut, $ leavemod, $ hidefids;
$ Bbcodeoff = $ hidemsg? '': $ Bbcodeoff; continue to find:
If (preg_match ("/\ [hide =? \ D * \]. +? \ [\/Hide \]/is ", $ message) {Replace:
// Hidemsg by KaijuanStudio
If ($ hidefids ){
Foreach ($ hidefids as $ hidefid ){
If ($ leavemod ){
If ($ fid = $ hidefid ){
$ Unallowed = 1;
} Else {
$ Allowhide = 1;
}
} Else {
If ($ fid = $ hidefid ){
$ Allowhide = 1;
}
}
}
} Elseif ($ fid ){
$ Allowhide = 1;
}
If ($ hidemsg & $ allowhide &&! $ Unallowed ){
Global $ language;
Include_once language ('Misc ');
$ Hidefirst = $ hidemsg = 1? $ First: ($ hidemsg = 2? 1: ($ hidemsg = 3? ($ First? '': 1 ):''));
If ($ hidefirst ){
If ($ hidecut <strlen ($ message )){
$ Query = $ db-> query ("SELECT pid FROM {$ tablepre} posts WHERE tid = '$ tid' AND authorid =' $ discuz_uid 'LIMIT 1 ");
If ($ GLOBALS ['forum'] ['isderator'] | $ db-> result ($ query, 0 )){
$ Message = ''. $ language ['post _ hide_reply '].'
'.
'====================================

'.
$ Message .'

'.
'=============================== ';
} Else {
$ Message = $ hidecut? ($ Hidecut> = strlen ($ message )? $ Message: dhtmlspecialchars (cutstr ($ message, $ hidecut )).'

'. $ Language ['post _ hide_reply_hidden'].''):' '. $ Language ['post _ hide_reply_hidden'].'';
}
}
} Elseif (! $ Discuz_uid & $ hidemsg = 4 & $ hidecut ){
$ Message = $ hidecut> = strlen ($ message )? $ Message: dhtmlspecialchars (cutstr ($ message, $ hidecut )).'

'. $ Language ['post _ hide_limit'];
}
} Elseif (preg_match ("/\ [hide =? \ D * \]. +? \ [\/Hide \]/is ", $ message) {DZ5.0/DZ5.5, locate:
Function discuzcode ($ message, $ smileyoff, $ bbcodeoff, $ htmlon = 0, $ allowsmilies = 1, $ allowbbcode = 1, $ allowimgcode = 1, $ allowhtml = 0, $ jammer = 0, $ parsetype = '0', $ authorid = '0') {Replace:
Function discuzcode ($ message, $ smileyoff, $ bbcodeoff, $ htmlon = 0, $ allowsmilies = 1, $ allowbbcode = 1, $ allowimgcode = 1, $ allowhtml = 0, $ jammer = 0, $ parsetype = '0', $ authorid = '0', $ first = '0') {DZ5.0:
Global $ discuzcodes, $ credits, $ tid, $ discuz_uid, $ highlight, $ maxsmilies, $ db, $ tablepre; Replace:
Global $ discuzcodes, $ credits, $ fid, $ tid, $ discuz_uid, $ highlight, $ maxsmilies, $ db, $ tablepre, $ hidemsg, $ hidecut, $ leavemod, $ hidefids;
$ Bbcodeoff = $ hidemsg? '': $ Bbcodeoff; DZ5.5:
Global $ discuzcodes, $ credits, $ tid, $ discuz_uid, $ highlight, $ maxsmilies, $ db, $ tablepre, $ hideattach; Replace:
Global $ discuzcodes, $ credits, $ fid, $ tid, $ discuz_uid, $ highlight, $ maxsmilies, $ db, $ tablepre, $ hideattach, $ hidemsg, $ hidecut, $ leavemod, $ hidefids;
$ Bbcodeoff = $ hidemsg? '': $ Bbcodeoff; DZ5.0 continue to find:
If (! In_array ($ parsetype, array (1, 2) & preg_match ("/\ [hide =? \ D * \]. +? \ [\/Hide \]/is ", $ message) {Replace:
// Hidemsg by KaijuanStudio
If ($ hidefids ){
Foreach ($ hidefids as $ hidefid ){
If ($ leavemod ){
If ($ fid = $ hidefid ){
$ Unallowed = 1;
} Else {
$ Allowhide = 1;
}
} Else {
If ($ fid = $ hidefid ){
$ Allowhide = 1;
}
}
}
} Elseif ($ fid ){
$ Allowhide = 1;
}
If ($ hidemsg & $ allowhide &&! $ Unallowed ){
Global $ language;
Include_once language ('Misc ');
$ Hidefirst = $ hidemsg = 1? $ First: ($ hidemsg = 2? 1: ($ hidemsg = 3? ($ First? '': 1 ):''));
If ($ hidefirst ){
If ($ hidecut <strlen ($ message )){
$ Query = $ db-> query ("SELECT pid FROM {$ tablepre} posts WHERE tid = '$ tid' AND authorid =' $ discuz_uid 'LIMIT 1 ");
If ($ GLOBALS ['forum'] ['isderator'] | $ db-> result ($ query, 0 )){
$ Message = ''. $ language ['post _ hide_reply '].'
'.
'====================================

'.
$ Message .'

'.
'=============================== ';
} Else {
$ Message = $ hidecut? ($ Hidecut> = strlen ($ message )? $ Message: dhtmlspecialchars (cutstr ($ message, $ hidecut )).'

'. $ Language ['post _ hide_reply_hidden'].''):' '. $ Language ['post _ hide_reply_hidden'].'';
}
}
} Elseif (! $ Discuz_uid & $ hidemsg = 4 & $ hidecut ){
$ Message = $ hidecut> = strlen ($ message )? $ Message: dhtmlspecialchars (cutstr ($ message, $ hidecut )).'

'. $ Language ['post _ hide_limit'];
}
} Elseif (! In_array ($ parsetype, array (1, 2) & preg_match ("/\ [hide =? \ D * \]. +? \ [\/Hide \]/is ", $ message) {DZ5.5 continue to find:
If ($ parsetype! = 1 & preg_match ("/\ [hide =? \ D * \]. +? \ [\/Hide \]/is ", $ message) {Replace:
// Hidemsg by KaijuanStudio
If ($ hidefids ){
Foreach ($ hidefids as $ hidefid ){
If ($ leavemod ){
If ($ fid = $ hidefid ){
$ Unallowed = 1;
} Else {
$ Allowhide = 1;
}
} Else {
If ($ fid = $ hidefid ){
$ Allowhide = 1;
}
}
}
} Elseif ($ fid ){
$ Allowhide = 1;
}
If ($ hidemsg & $ allowhide &&! $ Unallowed ){
Global $ language;
Include_once language ('Misc ');
$ Hidefirst = $ hidemsg = 1? $ First: ($ hidemsg = 2? 1: ($ hidemsg = 3? ($ First? '': 1 ):''));
If ($ hidefirst ){
If ($ hidecut <strlen ($ message )){
$ Query = $ db-> query ("SELECT pid FROM {$ tablepre} posts WHERE tid = '$ tid' AND authorid =' $ discuz_uid 'LIMIT 1 ");
If ($ GLOBALS ['forum'] ['isderator'] | $ db-> result ($ query, 0 )){
$ Message = ''. $ language ['post _ hide_reply '].'
'.
'====================================

'.
$ Message .'

'.
'=============================== ';
} Else {
$ Message = $ hidecut? ($ Hidecut> = strlen ($ message )? $ Message: dhtmlspecialchars (cutstr ($ message, $ hidecut )).'

'. $ Language ['post _ hide_reply_hidden'].''):' '. $ Language ['post _ hide_reply_hidden'].'';
}
}
} Elseif (! $ Discuz_uid & $ hidemsg = 4 & $ hidecut ){
$ Message = $ hidecut> = strlen ($ message )? $ Message: dhtmlspecialchars (cutstr ($ message, $ hidecut )).'

'. $ Language ['post _ hide_limit'];
}
} Elseif ($ parsetype! = 1 & preg_match ("/\ [hide =? \ D * \]. +? \ [\/Hide \]/is ", $ message )){
Solve code disorder after text truncation (same as DZ4.1/DZ5.0/DZ5.5)
Solution 1 (recommended ):
Select the modified code from:
// Start with hidemsg by KaijuanStudio:
$ Message = preg_replace ("/\ [hide = (\ d +) \] \ s * (. + ?) \ S * \ [\/hide \]/ies "," creditshide (\ 1, '\ 2') ", $ message );
} All the code at the end, and then move this large piece of code:
If (! $ Bbcodeoff & $ allowbbcode) {in the following line.
This method is the simplest and applicable to forums where HTML code is not enabled. code such as unclosed code appears at the end of text truncation, such as missing: the content of [/quote], [/url], and [/img] is displayed as code.

Solution 2:
First, replace dhtmlspecialchars with put_html.
And then at the end of the discuzcode. func. php file?> Add:
// Hidemsg by KaijuanStudio
Function put_html ($ message ){
If (preg_match ('/([^ \ f] +) <[^>] + $/', $ message, $ put1 )){
$ Message = $ put1 [1];
}
$ Tour1 = preg_replace ('/$ tour2 = explode (' <', trim ($ tour1 ));
Foreach ($ tour2 as $ tour3 ){
If (preg_match ('/^ ([a-z] {1,}). *>. */I', $ tour3, $ tour4 )){
$ Fronts [] = $ tour4 [1];
$ Kmsg [] = $ tour3;
}
If (preg_match ('/^ \/([a-z] {1,}). *>. */I', $ tour3, $ tour5 )){
$ Backs [] = $ tour5 [1];
}
}
$ Fronts = $ fronts? $ Fronts: array ();
$ Backs = $ backs? $ Backs: array ();
Foreach ($ fronts as $ i1 => $ front ){
Foreach ($ backs as $ i2 => $ back ){
If ($ fronts [$ i1]! = ''){
If ($ front = $ back ){
$ Fronts [$ i1] = '';
$ Backs [$ i2] = '';
}
}
}
If ($ fronts [$ i1]! = ''&&! $ Badcode ){
$ Badcode = $ kmsg [$ i1];
}
}
If ($ badcode ){
$ Badcode = '<'. str_replace ('/', '\/', $ badcode );
Preg_match ('/([^ \ f] *)'. $ badcode. '/I', $ message, $ put2 );
$ Message = $ put2 [1];
}
Return $ message;
}
// Hidemsg end is applicable to forums where HTML code is enabled. it mainly uses our own HTML troubleshooting function to filter incorrect HTML elements in the truncated text. This function may not be perfect. I hope that my friends can report the problem in time. The implementation of this method is basically the same as the above, but no code is truncated at the end of the text, but the disadvantage is that if all the post content is included in a quote reference, or table, The Post content cannot be previewed due to incomplete code after the post is truncated.
Interference Code compatibility modification (same as DZ4.1/DZ5.0/DZ5.5)
Note: if the interference code function is not enabled for your forum, you can skip this modification. This modification continues with the modification to the discuzcode. func. php file.
Find:
If (! $ Htmlon &&! $ Allowhtml ){
$ Message = $ jammer? Preg_replace ("/\ r \ n | \ r/e", "jammer ()", dhtmlspecialchars ($ message): dhtmlspecialchars ($ message );
} Replace:
If (! $ Htmlon &&! $ Allowhtml ){
$ Message = dhtmlspecialchars ($ message );
} Continue searching:
If ($ highlight) {add:
If (! $ Htmlon &&! $ Allowhtml ){
$ Message = $ jammer? Preg_replace ("/\ r \ n | \ r/e", "jammer ()", $ message): $ message;
} The interference code compatibility modification is complete.
Modify: misc. lang. php (same as DZ4.1/DZ5.0/DZ5.5)
Open templates \ default \ misc. lang. php and find:
'Post _ hide_reply_hidden '=>' ***** this content is replied with the post before you can browse ***** '. add it in the following line:
'Post _ hide_limit '=>'

Sorry, you are in the tourist status, so you can only read part of the content. To read the complete content, please:RegisterOrLogin.

',
Modify: config. inc. php (same as DZ4.1/DZ5.0)
Add:
$ Hidemsg = 4; // enable auto hide of studio posts, 0 = disable, 1 = automatically hide posts on the first floor, 2 = automatically hide all posts, 3 = automatically hide all posts except the first floor, 4 = only restrict visitors to read all the posts. Note: When this setting is enabled, you must set the following $ hidecut value, otherwise, this setting will be invalid.
$ Hidecut = 100; // set the number of bytes of the post content that can be previewed. The value 0 indicates that preview is disabled. The value 100 indicates that 100 bytes of content can be previewed. you can also set the value to another value, the larger the value, the more content you can preview.
$ Leavemod = 0; // Set whether to allow or exclude the fid of the Forum in $ hidefids. 0 = allow. the automatically hidden Forum will be enabled in the set Forum, except for the Forum in $ hidefids, hide is not enabled. 1 = exclude: enable auto hide for all forums other than $ hidefids. When the fid of the forum is not set in $ hidefids, this setting is also invalid, which means that automatic hiding is enabled for all forums.
$ Hidefids = array (); // sets the fid of an automatically hidden forum that is enabled or excluded. when multiple forums are set, they are separated by commas (,). when a forum is set, you do not need to add commas (,). For example, $ hidefid = array (2, 3, 5). The Auto hide function is enabled in the three forums where fid is 2, 3, and 5; $ hidefid = array (2); enable automatic hiding only in forums with fid 2. When array () is used by default, auto hide is enabled for all forums.
Complete. Upload the update file!
Finally, the attachment provides 55 icons before the prompt. you can select one of them and change it to warning.gif, and then upload it to the image directory of the Forum.

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.