]> git.mxchange.org Git - friendica.git/commitdiff
prevent double posting of status updates and comments
authorZach Prezkuta <fermion@gmx.com>
Thu, 1 Nov 2012 23:14:42 +0000 (17:14 -0600)
committerZach Prezkuta <fermion@gmx.com>
Thu, 1 Nov 2012 23:14:42 +0000 (17:14 -0600)
27 files changed:
boot.php
include/conversation.php
mod/content.php
mod/editpost.php
mod/item.php
mod/photos.php
object/Item.php
view/comment_item.tpl
view/jot.tpl
view/theme/comix-plain/comment_item.tpl
view/theme/comix/comment_item.tpl
view/theme/diabook/comment_item.tpl
view/theme/diabook/jot.tpl
view/theme/dispy/comment_item.tpl
view/theme/dispy/jot.tpl
view/theme/duepuntozero/comment_item.tpl
view/theme/facepark/comment_item.tpl
view/theme/facepark/jot.tpl
view/theme/frost-mobile/comment_item.tpl
view/theme/frost-mobile/jot.tpl
view/theme/frost/comment_item.tpl
view/theme/frost/jot.tpl
view/theme/quattro/comment_item.tpl
view/theme/quattro/jot.tpl
view/theme/smoothly/jot.tpl
view/theme/testbubble/comment_item.tpl
view/theme/testbubble/jot.tpl

index a96d223a0e628635bb14fcd57373152ab42803d7..d231d87d1c129faabb0af29e0cba610f126f82b1 100644 (file)
--- a/boot.php
+++ b/boot.php
@@ -1796,3 +1796,10 @@ function curPageURL() {
        return $pageURL;
 }
 
+function random_digits($digits) {
+       $rn = '';
+       for($i = 0; $i < $digits; $i++) {
+               $rn .= rand(0,9);
+       }
+       return $rn;
+}
index 5f44cde7fbdb911bf76d5c79553e227927700ba7..45736051d046313113aaf85e4f331009cb19d93a 100644 (file)
@@ -993,7 +993,8 @@ function status_editor($a,$x, $notes_cid = 0, $popup=false) {
                '$profile_uid' => $x['profile_uid'],
                '$preview' => t('Preview'),
                '$sourceapp' => t($a->sourcename),
-               '$cancel' => t('Cancel')
+               '$cancel' => t('Cancel'),
+               '$rand_num' => random_digits(12)
        ));
 
 
index d827b5b57b4cf79ff08a6cf1434685701d15b454..e0634b3e841f1f1a5e710b9f73eb7f209e753693 100644 (file)
@@ -701,7 +701,8 @@ function render_content(&$a, $items, $mode, $update, $preview = false) {
                                                        '$edvideo' => t('Video'),
                                                        '$preview' => t('Preview'),
                                                        '$sourceapp' => t($a->sourcename),
-                                                       '$ww' => (($mode === 'network') ? $commentww : '')
+                                                       '$ww' => (($mode === 'network') ? $commentww : ''),
+                                                       '$rand_num' => random_digits(12)
                                                ));
                                        }
                                }
index 75b686bcd9c25d0ae46469368e9c2c5e14a828ff..1dc6aea21e054a3af159ebbda149cab5414a7538 100644 (file)
@@ -139,7 +139,8 @@ function editpost_content(&$a) {
                '$preview' => t('Preview'),
                '$jotplugins' => $jotplugins,
                '$sourceapp' => t($a->sourcename),
-               '$cancel' => t('Cancel')
+               '$cancel' => t('Cancel'),
+               '$rand_num' => random_digits(12)
        ));
 
        return $o;
index de6bce972ce2d08ad9dfad63caca8bcf4fff1039..6dbe99dfd0fd0918a23b9b9e307876b1084a593a 100644 (file)
@@ -46,6 +46,19 @@ function item_post(&$a) {
        $return_path = ((x($_REQUEST,'return')) ? $_REQUEST['return'] : '');
        $preview = ((x($_REQUEST,'preview')) ? intval($_REQUEST['preview']) : 0);
 
+
+       // Check for doubly-submitted posts, and reject duplicates
+       // Note that we have to ignore previews, otherwise nothing will post
+       // after it's been previewed
+       if(!$preview && x($_REQUEST['post_id_random'])) {
+               if(x($_SESSION['post-random']) && $_SESSION['post-random'] == $_REQUEST['post_id_random']) {
+                       logger("item post: duplicate post", LOGGER_DEBUG);
+                       item_post_return($a->get_baseurl(), $api_source, $return_path);
+               }
+               else
+                       $_SESSION['post-random'] = $_REQUEST['post_id_random'];
+       }
+
        /**
         * Is this a reply to something?
         */
@@ -98,7 +111,7 @@ function item_post(&$a) {
 
                // multi-level threading - preserve the info but re-parent to our single level threading
                //if(($parid) && ($parid != $parent))
-                       $thr_parent = $parent_uri;
+               $thr_parent = $parent_uri;
 
                if($parent_item['contact-id'] && $uid) {
                        $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
@@ -873,30 +886,32 @@ function item_post(&$a) {
 
        logger('post_complete');
 
+       item_post_return($a->get_baseurl(), $api_source, $return_path);
+       // NOTREACHED
+}
+
+function item_post_return($baseurl, $api_source, $return_path) {
        // figure out how to return, depending on from whence we came
 
        if($api_source)
                return;
 
        if($return_path) {
-               goaway($a->get_baseurl() . "/" . $return_path);
+               goaway($baseurl . "/" . $return_path);
        }
 
        $json = array('success' => 1);
        if(x($_REQUEST,'jsreload') && strlen($_REQUEST['jsreload']))
-               $json['reload'] = $a->get_baseurl() . '/' . $_REQUEST['jsreload'];
+               $json['reload'] = $baseurl . '/' . $_REQUEST['jsreload'];
 
        logger('post_json: ' . print_r($json,true), LOGGER_DEBUG);
 
        echo json_encode($json);
        killme();
-       // NOTREACHED
 }
 
 
 
-
-
 function item_content(&$a) {
 
        if((! local_user()) && (! remote_user()))
index 63b093dc376fdb49d86103e361b58b98d05d8d63..fa4ca3fc0c8baafc13e5997583a9749c6e6a3271 100644 (file)
@@ -1406,7 +1406,8 @@ function photos_content(&$a) {
                                                        '$submit' => t('Submit'),
                                                        '$preview' => t('Preview'),
                                                        '$sourceapp' => t($a->sourcename),
-                                                       '$ww' => ''
+                                                       '$ww' => '',
+                                                       '$rand_num' => random_digits(12)
                                                ));
                                        }
                                }
@@ -1449,7 +1450,8 @@ function photos_content(&$a) {
                                                        '$submit' => t('Submit'),
                                                        '$preview' => t('Preview'),
                                                        '$sourceapp' => t($a->sourcename),
-                                                       '$ww' => ''
+                                                       '$ww' => '',
+                                                       '$rand_num' => random_digits(12)
                                                ));
                                        }
                                }
@@ -1520,7 +1522,8 @@ function photos_content(&$a) {
                                                                '$submit' => t('Submit'),
                                                                '$preview' => t('Preview'),
                                                                '$sourceapp' => t($a->sourcename),
-                                                               '$ww' => ''
+                                                               '$ww' => '',
+                                                               '$rand_num' => random_digits(12)
                                                        ));
                                                }
                                        }
index 035255466a04159bac127213ceda206f98ff5216..b5837b6b661ee49bce4d84f544a11b37d36270e8 100644 (file)
@@ -567,7 +567,8 @@ class Item extends BaseObject {
                                '$preview' => t('Preview'),
                                '$indent' => $indent,
                                '$sourceapp' => t($a->sourcename),
-                               '$ww' => (($conv->get_mode() === 'network') ? $ww : '')
+                               '$ww' => (($conv->get_mode() === 'network') ? $ww : ''),
+                               '$rand_num' => random_digits(12)
                        ));
                }
 
index 3de24ca8d25948b4492a5262f0352ccd21f22079..5783a409c5a8a794d371a03e0aaf9a6ef84a1539 100644 (file)
@@ -10,6 +10,7 @@
                                <input type="hidden" name="return" value="$return_path" />
                                <input type="hidden" name="jsreload" value="$jsreload" />
                                <input type="hidden" name="preview" id="comment-preview-inp-$id" value="0" />
+                               <input type="hidden" name="post_id_random" value="$rand_num" />
 
                                <div class="comment-edit-photo" id="comment-edit-photo-$id" >
                                        <a class="comment-edit-photo-link" href="$mylink" title="$mytitle"><img class="my-comment-photo" src="$myphoto" alt="$mytitle" title="$mytitle" /></a>
index 91de628ac6c665a9debf4cbdf634326a2db3bef3..0f21766812f95a6976064d9f322cfa78cfdb7165 100644 (file)
@@ -14,6 +14,7 @@
                <input type="hidden" name="coord" id="jot-coord" value="" />
                <input type="hidden" name="post_id" value="$post_id" />
                <input type="hidden" name="preview" id="jot-preview" value="0" />
+               <input type="hidden" name="post_id_random" value="$rand_num" />
                <div id="jot-title-wrap"><input name="title" id="jot-title" type="text" placeholder="$placeholdertitle" value="$title" class="jothidden" style="display:none"></div>
                <div id="jot-category-wrap"><input name="category" id="jot-category" type="text" placeholder="$placeholdercategory" value="$category" class="jothidden" style="display:none" /></div>
                <div id="jot-text-wrap">
index 9c3facaff0f977b6b6fdeeb4d552c584421ab593..e3c686f052dcab94a21f31699bcb834315c346f9 100644 (file)
@@ -6,6 +6,7 @@
                                <input type="hidden" name="return" value="$return_path" />
                                <input type="hidden" name="jsreload" value="$jsreload" />
                                <input type="hidden" name="preview" id="comment-preview-inp-$id" value="0" />
+                               <input type="hidden" name="post_id_random" value="$rand_num" />
 
                                <div class="comment-edit-photo" id="comment-edit-photo-$id" >
                                        <a class="comment-edit-photo-link" href="$mylink" title="$mytitle"><img class="my-comment-photo" src="$myphoto" alt="$mytitle" title="$mytitle" /></a>
index 9c3facaff0f977b6b6fdeeb4d552c584421ab593..e3c686f052dcab94a21f31699bcb834315c346f9 100644 (file)
@@ -6,6 +6,7 @@
                                <input type="hidden" name="return" value="$return_path" />
                                <input type="hidden" name="jsreload" value="$jsreload" />
                                <input type="hidden" name="preview" id="comment-preview-inp-$id" value="0" />
+                               <input type="hidden" name="post_id_random" value="$rand_num" />
 
                                <div class="comment-edit-photo" id="comment-edit-photo-$id" >
                                        <a class="comment-edit-photo-link" href="$mylink" title="$mytitle"><img class="my-comment-photo" src="$myphoto" alt="$mytitle" title="$mytitle" /></a>
index fc3594fdc9841e87072034018190344255fff171..c5a24ec48e224e90e8ae3966fd42286930effca4 100644 (file)
@@ -6,6 +6,7 @@
                                <input type="hidden" name="return" value="$return_path" />
                                <input type="hidden" name="jsreload" value="$jsreload" />
                                <input type="hidden" name="preview" id="comment-preview-inp-$id" value="0" />
+                               <input type="hidden" name="post_id_random" value="$rand_num" />
 
                                <div class="comment-edit-photo" id="comment-edit-photo-$id" >
                                        <a class="comment-edit-photo-link" href="$mylink" title="$mytitle"><img class="my-comment-photo" src="$myphoto" alt="$mytitle" title="$mytitle" /></a>
index 1d94cb6d3c05752da8b856a4bad13386413ab6a3..a9c0a3740be797faae5ddb2f67ce7b1fed4e8c5d 100644 (file)
@@ -13,6 +13,7 @@
                <input type="hidden" name="coord" id="jot-coord" value="" />
                <input type="hidden" name="post_id" value="$post_id" />
                <input type="hidden" name="preview" id="jot-preview" value="0" />
+               <input type="hidden" name="post_id_random" value="$rand_num" />
                <input name="title" id="jot-title" type="text" placeholder="$placeholdertitle" value="$title" class="jothidden" style="display:none">
                <div id="jot-category-wrap"><input name="category" id="jot-category" type="text" placeholder="$placeholdercategory" value="$category" class="jothidden" style="display:none" /></div>           
                <div id="character-counter" class="grey"></div>         
index aa63a03ed2300b0a37a0c628f13be3cf92ec7fa0..765b41437de65685f8da3ec095479dd69f29b7aa 100644 (file)
@@ -6,6 +6,7 @@
                                <input type="hidden" name="return" value="$return_path" />
                                <input type="hidden" name="jsreload" value="$jsreload" />
                                <input type="hidden" name="preview" id="comment-preview-inp-$id" value="0" />
+                               <input type="hidden" name="post_id_random" value="$rand_num" />
 
                                <div class="comment-edit-photo" id="comment-edit-photo-$id" >
                                        <a class="comment-edit-photo-link" href="$mylink" title="$mytitle"><img class="my-comment-photo" src="$myphoto" alt="$mytitle" title="$mytitle" /></a>
index 12969dd031861e227d7ed3117209d6cace9dd474..58090448590f19f8847f7c7bec9cbf48203052eb 100644 (file)
@@ -9,6 +9,7 @@
                <input type="hidden" name="coord" id="jot-coord" value="" />
                <input type="hidden" name="post_id" value="$post_id" />
                <input type="hidden" name="preview" id="jot-preview" value="0" />
+               <input type="hidden" name="post_id_random" value="$rand_num" />
                <div id="jot-title-wrap"><input name="title" id="jot-title" type="text" placeholder="$placeholdertitle" value="$title" class="jothidden" style="display:none" /></div>
                <div id="character-counter" class="grey jothidden"></div>
                <div id="jot-category-wrap"><input name="category" id="jot-category" type="text" placeholder="$placeholdercategory" value="$category" class="jothidden" style="display:none" /></div>
index 87e0605712f138f0d4ffb22d24ff90b9fc79651c..0f655ba43cf017b5d8abc34b9caaaf567616bef3 100755 (executable)
@@ -10,6 +10,7 @@
                                <input type="hidden" name="return" value="$return_path" />
                                <input type="hidden" name="jsreload" value="$jsreload" />
                                <input type="hidden" name="preview" id="comment-preview-inp-$id" value="0" />
+                               <input type="hidden" name="post_id_random" value="$rand_num" />
 
                                <div class="comment-edit-photo" id="comment-edit-photo-$id" >
                                        <a class="comment-edit-photo-link" href="$mylink" title="$mytitle"><img class="my-comment-photo" src="$myphoto" alt="$mytitle" title="$mytitle" /></a>
index 3503c3843eea13e93a8d9b73b8fe6f7b5df45489..7e71aa380bce966c305e278a589bfca66e10421b 100644 (file)
@@ -6,6 +6,7 @@
                                <input type="hidden" name="return" value="$return_path" />
                                <input type="hidden" name="jsreload" value="$jsreload" />
                                <input type="hidden" name="preview" id="comment-preview-inp-$id" value="0" />
+                               <input type="hidden" name="post_id_random" value="$rand_num" />
 
                                <div class="comment-edit-photo" id="comment-edit-photo-$id" >
                                        <a class="comment-edit-photo-link" href="$mylink" title="$mytitle"><img class="my-comment-photo" src="$myphoto" alt="$mytitle" title="$mytitle" /></a>
index 5fe1f954ee24eb9f82ac17840fa0579f04be7f26..6b24045ef3fee4aa4c485cfc62b46fc5951a15c1 100644 (file)
@@ -14,6 +14,7 @@
                <input type="hidden" name="coord" id="jot-coord" value="" />
                <input type="hidden" name="post_id" value="$post_id" />
                <input type="hidden" name="preview" id="jot-preview" value="0" />
+               <input type="hidden" name="post_id_random" value="$rand_num" />
                <div id="jot-title-wrap"><input name="title" id="jot-title" type="text" placeholder="$placeholdertitle" value="$title" class="jothidden" style="display:none"></div>
                <div id="jot-text-wrap">
                <img id="profile-jot-text-loading" src="images/rotator.gif" alt="$wait" title="$wait" style="display: none;" />
index 570db6842652d6b5dfadb7ba5061f8c3a6fb8ded..adcd5d75ed630be06b2ff538bfaef41911bc7dba 100755 (executable)
@@ -21,6 +21,7 @@
                                <input type="hidden" name="return" value="$return_path" />
                                <input type="hidden" name="jsreload" value="$jsreload" />
                                <input type="hidden" name="preview" id="comment-preview-inp-$id" value="0" />
+                               <input type="hidden" name="post_id_random" value="$rand_num" />
 
                                <!--<div class="comment-edit-photo" id="comment-edit-photo-$id" >-->
                                        <a class="comment-edit-photo comment-edit-photo-link" id="comment-edit-photo-$id" href="$mylink" title="$mytitle"><img class="my-comment-photo" src="$myphoto" alt="$mytitle" title="$mytitle" /></a>
index b491f448d739497535721fbd2e2569580c2485dc..7dd68937837b432d16080b7e1771ca13ead970c3 100644 (file)
@@ -15,6 +15,7 @@
                <input type="hidden" name="post_id" value="$post_id" />
                <input type="hidden" name="source" value="$sourceapp" />
                <input type="hidden" name="preview" id="jot-preview" value="0" />
+               <input type="hidden" name="post_id_random" value="$rand_num" />
                <div id="jot-title-wrap"><input name="title" id="jot-title" type="text" placeholder="$placeholdertitle" value="$title" class="jothidden" style="display:none"></div>
                <div id="jot-category-wrap"><input name="category" id="jot-category" type="text" placeholder="$placeholdercategory" value="$category" class="jothidden" style="display:none" /></div>
                <div id="jot-text-wrap">
index 32d4d78ef9698b6250dc6a06f72d5e61c890875e..380803807973b1ab1397498202bd69182b64fae5 100755 (executable)
@@ -20,6 +20,7 @@
                                <input type="hidden" name="return" value="$return_path" />
                                <input type="hidden" name="jsreload" value="$jsreload" />
                                <input type="hidden" name="preview" id="comment-preview-inp-$id" value="0" />
+                               <input type="hidden" name="post_id_random" value="$rand_num" />
 
 <!--                           <div class="comment-edit-photo" id="comment-edit-photo-$id" >-->
                                        <a class="comment-edit-photo comment-edit-photo-link" id="comment-edit-photo-$id" href="$mylink" title="$mytitle"><img class="my-comment-photo" src="$myphoto" alt="$mytitle" title="$mytitle" /></a>
index e7a89d8e074619cdfbef8a16b35c5bb522794930..9f7b71c531ef172ca4a4eaeb348a420442c817f8 100644 (file)
@@ -14,6 +14,7 @@
                <input type="hidden" name="coord" id="jot-coord" value="" />
                <input type="hidden" name="post_id" value="$post_id" />
                <input type="hidden" name="preview" id="jot-preview" value="0" />
+               <input type="hidden" name="post_id_random" value="$rand_num" />
                <div id="jot-title-wrap"><input name="title" id="jot-title" type="text" placeholder="$placeholdertitle" value="$title" class="jothidden" style="display:none"></div>
                <div id="jot-category-wrap"><input name="category" id="jot-category" type="text" placeholder="$placeholdercategory" value="$category" class="jothidden" style="display:none" /></div>
                <div id="jot-text-wrap">
index 7d1d7550b2f2b10e7835e297f2f901542d5ac80c..3fbde16318b33715404964d119d6af9866ac8dc0 100644 (file)
@@ -6,6 +6,7 @@
                                <input type="hidden" name="return" value="$return_path" />
                                <input type="hidden" name="jsreload" value="$jsreload" />
                                <input type="hidden" name="preview" id="comment-preview-inp-$id" value="0" />
+                               <input type="hidden" name="post_id_random" value="$rand_num" />
 
                                <div class="comment-edit-photo" id="comment-edit-photo-$id" >
                                        <a class="comment-edit-photo-link" href="$mylink" title="$mytitle"><img class="my-comment-photo" src="$myphoto" alt="$mytitle" title="$mytitle" /></a>
index 7f9f9bbaf177cf38d7656b5c68daba166fadce58..55fc322d741776783bc42d0f340646aa9b44dd29 100644 (file)
@@ -13,6 +13,7 @@
                <input type="hidden" name="coord" id="jot-coord" value="" />
                <input type="hidden" name="post_id" value="$post_id" />
                <input type="hidden" name="preview" id="jot-preview" value="0" />
+               <input type="hidden" name="post_id_random" value="$rand_num" />
 
                <textarea rows="5" cols="64" class="profile-jot-text" id="profile-jot-text" name="body" >{{ if $content }}$content{{ else }}$share{{ endif }}</textarea>
 
index 437eec43735d089bbb89c9caa80aba49c6e23b8f..f990c95e115e9dedabaecca20b961b289afe3ebb 100644 (file)
@@ -14,6 +14,7 @@
                <input type="hidden" name="coord" id="jot-coord" value="" />
                <input type="hidden" name="post_id" value="$post_id" />
                <input type="hidden" name="preview" id="jot-preview" value="0" />
+               <input type="hidden" name="post_id_random" value="$rand_num" />
                <div id="jot-title-wrap">
                        <input name="title" id="jot-title" type="text" placeholder="$placeholdertitle" value="$title" class="jothidden" style="display:none">
                </div>
index 6d9230dbf8fbe0ebc5b9d6f0b246b9ce6e961322..1054b23e2425d9c0956205f4d05c42c7270992fb 100644 (file)
@@ -6,6 +6,7 @@
                                <input type="hidden" name="return" value="$return_path" />
                                <input type="hidden" name="jsreload" value="$jsreload" />
                                <input type="hidden" name="preview" id="comment-preview-inp-$id" value="0" />
+                               <input type="hidden" name="post_id_random" value="$rand_num" />
 
                                <div class="comment-edit-photo" id="comment-edit-photo-$id" >
                                        <a class="comment-edit-photo-link" href="$mylink" title="$mytitle"><img class="my-comment-photo" src="$myphoto" alt="$mytitle" title="$mytitle" /></a>
index 89150534c362f620c5fef2ba1311728441906004..12f60b29c0dc2e4fdb546e8431d018c0e34bdbf5 100644 (file)
@@ -16,6 +16,7 @@
                <input type="hidden" name="coord" id="jot-coord" value="" />
                <input type="hidden" name="post_id" value="$post_id" />
                <input type="hidden" name="preview" id="jot-preview" value="0" />
+               <input type="hidden" name="post_id_random" value="$rand_num" />
                <div id="jot-title-wrap"><input name="title" id="jot-title" type="text" placeholder="$placeholdertitle" value="$title" class="jothidden" style="display:none"></div>
                <div id="jot-text-wrap">
                 <img id="profile-jot-text-loading" src="images/rotator.gif" alt="$wait" title="$wait" style="display: none;" />