Feature suggestion - marking posts containing images (General)

by erikp, Saturday, March 08, 2008, 02:47 (5892 days ago)

Hello!

People often post images in forums and it would be nice if these posts were easy to spot. One way to solve this is if the subject somehow were marked if the text contained images.

An easy way to implement this is to just add a string at the end of the subject when an img-tag is found in the text.

Thus, if the post contains an image, a string, for example " [pic]", will be added to the end of the subject. If the post does not contain an image "[pic]" will be removed from the end of the subject (if is ending with [pic] ofcourse).

Implementation:
When replying to a message, with a subject marked with the string, the string is removed. This is to make it easy for the user to change the subject whithout having to think of the mark string.
To avoid the risk of getting two such string markings the mark string is removed from the ending of the subject before checking if the text contains an image.
This makes the process transparent.

Thus:
1) Remove the mark string from the end of the subject on the reply pages
2) Remove the mark string from the end of the subject before checking the reply for images and before storing the reply.
3) If the reply contains images, add the mark string to the end of the subject before storing the reply.

This is a small change to the code, and I have a patch that does the above. It stores the mark string in the settings database table, and the string is thus changable by any admin. If the string is "" there is no change to the function of the forum compared with the unpatched version. Because of the implementation, the mark string should however not be changed to often, since when changed it will not remove the old marks from subject in replies, will not change the string on already marked subjects etc.

Comments?
Is this a feature that you would like? If so, you can post me and I will send you the patch!
Is this a feature that should be included in the main release?

Regards,
Erik

locked
3964 views

Feature suggestion - marking posts containing images

by Name:, Saturday, March 08, 2008, 08:09 (5892 days ago) @ erikp

ok

locked
3758 views

Feature suggestion - marking posts containing images

by CindyLuWho, Monday, March 10, 2008, 05:13 (5890 days ago) @ erikp

Nice suggestion, please send the patch.
-CindyLuWho

locked
3953 views

kudos, nice feature to have

by Bogie @, Tuesday, March 11, 2008, 08:25 (5889 days ago) @ erikp

want the patch too
thank you

locked
3785 views

Feature suggestion - marking posts containing images

by erikp, Wednesday, March 12, 2008, 00:43 (5888 days ago) @ erikp
edited by erikp, Wednesday, March 12, 2008, 00:50

I'll post the patch here.

It prints the number of images (eg img-tags) in the post, and there are 3 settings, which are stored in the settings table in the database, and thus can be changed.

It works like before and adds a mark at the end of the subject. When you reply to a post with such mark, the mark is removed from the subject on the "post reply" page. This is to make it less likely that someone adds something after the mark etc. If you put text with the same format as the mark last in the subject, it is removed, thus there will not be 2 marks of the same "kind". And it, ofcourse, adds marks if there is pictures in the postings.

The settings are stored in the settings table in the database and the settings can be changed from admin->forum settings->advanced settings.

The settings are:
1. picstring_add : set to any non php false value (ex 1) to activate the function, and to a false php value to inactivate it (for example 0)
2. picstring : The string to use if there is only one picture in the posting.
3. picstring_plural : The string to use if there is more than one picture in the posting.

You need to add those settings to the database (using for example the php script referenced below).

For example, I'm from Sweden and use the settings "bild" for picstring and "bilder" for picstring_plural. If there is one picture in the posting, the mark will be "[1 bild]" and if there is more than one picture in the posting the mark will be, for example "[10 bilder]". Thus if I post something with the subject "My little subject" and it contains 10 pictures, the subject will be changed to "My little subject [10 bilder]". When someone replies to this, the subject on the "Post reply" page will be "My little subject", and if they add pictures in their posts, the appropriate mark will be added.

There is not much use in changing the picstring and picstring_plural once you have started using it, since after changing it, it will not remove old marks. For example if you use "pics" in the start and there are postings marked with for example "[10 pics]" and you then change it to "pictures", the old marks will not be removed automatic on the "post reply" page as described above.

To install the patch, either run:
patch < patchfile
in the forum/includes directory
or download the patch here:

http://www.djingis.se/~ep/patch4.tar.gz
(it contains the patchfile, a prepatched version of postings.inc.php, the original postings.inc.php, a "do what you want, no guarantee"-statement, and a small installation description)

and extract the contents of the file. Save the old postings.inc.php and add the one from the extraced archive. Check that you are using the same version as me [2.0 beta 25 (2008-02-27)] (though it may work with other 2-versions if you use the "patch < patchfile" way to install it, but there is no guarantee).

You need to add the name-value pairs to the settings database. You can of course do this anyway you want. However there is a "add-to-db.php" in the tar-file and you can put this in your forum-directory and *RUN IT ONCE* and then *REMOVE IT*. Do NOT run it more than once, and make SURE to delete it afterwards! Check that the settings table is updated afterwards [if not, you can try to run it once more :-) ] The same file is also here:
http://www.djingis.se/~ep/add-to-db.phps
so you can use cut and paste if you want.

As always, there is no guarantee about function and you use it on your own risk.

locked
3807 views

The patch file

by erikp, Wednesday, March 12, 2008, 11:14 (5888 days ago) @ erikp

As I wrote in my post, you can get the patch, together with a "prepatched" posting.inc.php, and install instructions from
http://www.djingis.se/~ep/patch4.tar.gz

For you who don't want to download it, I'll post the patch and the php-script that adds some settings to the settings table in the database (se my former post).

The patch (I don't know if it will survive the forum processing):

 
/*===================== START - CUT HERE ===================================*/
--- posting.inc.php.ORG 2008-03-06 23:05:19.000000000 +0100
+++ posting.inc.php     2008-03-09 17:48:21.000000000 +0100
@@ -237,7 +237,21 @@
           }
          else
           {
+
+// Added - removes ending
+if ( isset($settings['picstring_add']) && $settings['picstring_add'] 
+  && isset($settings['picstring']) && isset($settings['picstring_plural']) ) {
+       $headline = htmlspecialchars(stripslashes($field['subject']));
+       $picstring[0] = $settings['picstring'];
+       $picstring[1] = $settings['picstring_plural'];
+       $pic_pattern = "/s*[s*d*s*(" . escapeshellcmd($picstring[0]) . "|" . escapeshellcmd($picstring[1]) . ")s*]s*$/i";
+       $headline = preg_replace($pic_pattern, "", $headline);
+       $smarty->assign('subject', $headline);
+}
+else {
            $smarty->assign('subject',htmlspecialchars(stripslashes($field['subject'])));
+}
+
            $smarty->assign('p_category',$field['category']);
            $text = stripslashes($field['text']);
            $text = quote_reply($text);
@@ -331,6 +345,19 @@
    if(isset($_POST['email_notification'])) $email_notification = intval($_POST['email_notification']); else $email_notification=0;;
    if(isset($_POST['subject'])) $subject = trim($_POST['subject']);
    if(isset($_POST['text'])) $text = trim($_POST['text']);
+   
+// Ok lets add stuff to the subject in case of img tag in posting...
+if ( isset($subject) && isset($text) && isset($settings['picstring_add']) && $settings['picstring_add'] 
+        && isset($settings['picstring']) && isset($settings['picstring_plural']) ) {
+       $picstring[0] = $settings['picstring'];
+       $picstring[1] = $settings['picstring_plural'];
+       $pic_pattern = "/s*[s*d*s*(" . escapeshellcmd($picstring[0]) . "|" . escapeshellcmd($picstring[1]) . ")s*]s*$/i";
+       $subject = preg_replace($pic_pattern, "", $subject);
+       if ( $nbr = preg_match_all("/[img]/i", $text, $foo) ) $subject = $subject . " [$nbr " . $picstring[$nbr > 1] . "]";
+}
+   
+   
+   
    if(isset($_POST['setcookie'])) $setcookie = trim($_POST['setcookie']); else $setcookie=0;
    if(isset($_POST['sticky']) && $_POST['sticky']==1 && isset($_SESSION[$settings['session_prefix'].'user_type']) && ($_SESSION[$settings['session_prefix'].'use
r_type']>0)) $sticky=1; else $sticky=0;
    if(isset($_POST['terms_of_use_agree']) && $_POST['terms_of_use_agree']==1) $terms_of_use_agree=1; else $terms_of_use_agree=0;
=========================== END - CUT HERE ===============================
 
 
And the php script that adds some settings to the database:
=========================== START ========================
<html>
<head></head>
<body>
 
<?php
define('IN_INDEX', TRUE);
 
include('config/db_settings.php');
include('includes/functions.inc.php');
 
$connid = connect_db($db_settings['host'], $db_settings['user'], $db_settings['password'], $db_settings['database']);
mysql_query('insert into ' . $db_settings['settings_table'] . ' values("picstring", "picture")', $connid);
mysql_query('insert into ' . $db_settings['settings_table'] . ' values("picstring_plural", "pictures")', $connid);
mysql_query('insert into ' . $db_settings['settings_table'] . ' values("picstring_add", "1")', $connid);
 
mysql_close($connid);
?>
 
The database has been updated.<br/><br/>
But check it.<br/><br/>
Log in as admin<br/>
On Admin -> Forum settings -> Advanced settings there should be:<br/>
<ol>
<li>picstring - the mark if there is only one picture. This is set to "picture" as default</li>
<li>picstring_plural - the mark if there is more than one picture in the post. Default is "pictures"</li>
<li>picstring_add - If the function is activated or not. Set to 1, that is activated, as default. Set to 0 to deactivate. </li>
</ol>
Important: Run this file ONLY ONCE and the REMOVE THE FILE from the server.
 
</body>
</html>
/*====================== STOP ============================*/
 

/erik

locked
4028 views

RSS Feed of thread