From e9b26ffbb331f841886236beb745e7511228adbf Mon Sep 17 00:00:00 2001 From: Zach Prezkuta Date: Thu, 1 Nov 2012 17:14:42 -0600 Subject: [PATCH 1/4] prevent double posting of status updates and comments --- boot.php | 7 ++++++ include/conversation.php | 3 ++- mod/content.php | 3 ++- mod/editpost.php | 3 ++- mod/item.php | 27 ++++++++++++++++++------ mod/photos.php | 9 +++++--- object/Item.php | 3 ++- view/comment_item.tpl | 1 + view/jot.tpl | 1 + view/theme/comix-plain/comment_item.tpl | 1 + view/theme/comix/comment_item.tpl | 1 + view/theme/diabook/comment_item.tpl | 1 + view/theme/diabook/jot.tpl | 1 + view/theme/dispy/comment_item.tpl | 1 + view/theme/dispy/jot.tpl | 1 + view/theme/duepuntozero/comment_item.tpl | 1 + view/theme/facepark/comment_item.tpl | 1 + view/theme/facepark/jot.tpl | 1 + view/theme/frost-mobile/comment_item.tpl | 1 + view/theme/frost-mobile/jot.tpl | 1 + view/theme/frost/comment_item.tpl | 1 + view/theme/frost/jot.tpl | 1 + view/theme/quattro/comment_item.tpl | 1 + view/theme/quattro/jot.tpl | 1 + view/theme/smoothly/jot.tpl | 1 + view/theme/testbubble/comment_item.tpl | 1 + view/theme/testbubble/jot.tpl | 1 + 27 files changed, 62 insertions(+), 13 deletions(-) diff --git a/boot.php b/boot.php index a96d223a0..d231d87d1 100644 --- 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; +} diff --git a/include/conversation.php b/include/conversation.php index 5f44cde7f..45736051d 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -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) )); diff --git a/mod/content.php b/mod/content.php index d827b5b57..e0634b3e8 100644 --- a/mod/content.php +++ b/mod/content.php @@ -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) )); } } diff --git a/mod/editpost.php b/mod/editpost.php index 75b686bcd..1dc6aea21 100644 --- a/mod/editpost.php +++ b/mod/editpost.php @@ -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; diff --git a/mod/item.php b/mod/item.php index de6bce972..6dbe99dfd 100644 --- a/mod/item.php +++ b/mod/item.php @@ -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())) diff --git a/mod/photos.php b/mod/photos.php index 63b093dc3..fa4ca3fc0 100644 --- a/mod/photos.php +++ b/mod/photos.php @@ -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) )); } } diff --git a/object/Item.php b/object/Item.php index 035255466..b5837b6b6 100644 --- a/object/Item.php +++ b/object/Item.php @@ -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) )); } diff --git a/view/comment_item.tpl b/view/comment_item.tpl index 3de24ca8d..5783a409c 100644 --- a/view/comment_item.tpl +++ b/view/comment_item.tpl @@ -10,6 +10,7 @@ +
$mytitle diff --git a/view/jot.tpl b/view/jot.tpl index 91de628ac..0f2176681 100644 --- a/view/jot.tpl +++ b/view/jot.tpl @@ -14,6 +14,7 @@ +
diff --git a/view/theme/comix-plain/comment_item.tpl b/view/theme/comix-plain/comment_item.tpl index 9c3facaff..e3c686f05 100644 --- a/view/theme/comix-plain/comment_item.tpl +++ b/view/theme/comix-plain/comment_item.tpl @@ -6,6 +6,7 @@ +
$mytitle diff --git a/view/theme/comix/comment_item.tpl b/view/theme/comix/comment_item.tpl index 9c3facaff..e3c686f05 100644 --- a/view/theme/comix/comment_item.tpl +++ b/view/theme/comix/comment_item.tpl @@ -6,6 +6,7 @@ +
$mytitle diff --git a/view/theme/diabook/comment_item.tpl b/view/theme/diabook/comment_item.tpl index fc3594fdc..c5a24ec48 100644 --- a/view/theme/diabook/comment_item.tpl +++ b/view/theme/diabook/comment_item.tpl @@ -6,6 +6,7 @@ +
$mytitle diff --git a/view/theme/diabook/jot.tpl b/view/theme/diabook/jot.tpl index 1d94cb6d3..a9c0a3740 100644 --- a/view/theme/diabook/jot.tpl +++ b/view/theme/diabook/jot.tpl @@ -13,6 +13,7 @@ +
diff --git a/view/theme/dispy/comment_item.tpl b/view/theme/dispy/comment_item.tpl index aa63a03ed..765b41437 100644 --- a/view/theme/dispy/comment_item.tpl +++ b/view/theme/dispy/comment_item.tpl @@ -6,6 +6,7 @@ +
$mytitle diff --git a/view/theme/dispy/jot.tpl b/view/theme/dispy/jot.tpl index 12969dd03..580904485 100644 --- a/view/theme/dispy/jot.tpl +++ b/view/theme/dispy/jot.tpl @@ -9,6 +9,7 @@ +
diff --git a/view/theme/duepuntozero/comment_item.tpl b/view/theme/duepuntozero/comment_item.tpl index 87e060571..0f655ba43 100755 --- a/view/theme/duepuntozero/comment_item.tpl +++ b/view/theme/duepuntozero/comment_item.tpl @@ -10,6 +10,7 @@ +
$mytitle diff --git a/view/theme/facepark/comment_item.tpl b/view/theme/facepark/comment_item.tpl index 3503c3843..7e71aa380 100644 --- a/view/theme/facepark/comment_item.tpl +++ b/view/theme/facepark/comment_item.tpl @@ -6,6 +6,7 @@ +
$mytitle diff --git a/view/theme/facepark/jot.tpl b/view/theme/facepark/jot.tpl index 5fe1f954e..6b24045ef 100644 --- a/view/theme/facepark/jot.tpl +++ b/view/theme/facepark/jot.tpl @@ -14,6 +14,7 @@ +
diff --git a/view/theme/frost-mobile/comment_item.tpl b/view/theme/frost-mobile/comment_item.tpl index 570db6842..adcd5d75e 100755 --- a/view/theme/frost-mobile/comment_item.tpl +++ b/view/theme/frost-mobile/comment_item.tpl @@ -21,6 +21,7 @@ + $mytitle diff --git a/view/theme/frost-mobile/jot.tpl b/view/theme/frost-mobile/jot.tpl index b491f448d..7dd689378 100644 --- a/view/theme/frost-mobile/jot.tpl +++ b/view/theme/frost-mobile/jot.tpl @@ -15,6 +15,7 @@ +
diff --git a/view/theme/frost/comment_item.tpl b/view/theme/frost/comment_item.tpl index 32d4d78ef..380803807 100755 --- a/view/theme/frost/comment_item.tpl +++ b/view/theme/frost/comment_item.tpl @@ -20,6 +20,7 @@ + $mytitle diff --git a/view/theme/frost/jot.tpl b/view/theme/frost/jot.tpl index e7a89d8e0..9f7b71c53 100644 --- a/view/theme/frost/jot.tpl +++ b/view/theme/frost/jot.tpl @@ -14,6 +14,7 @@ +
diff --git a/view/theme/quattro/comment_item.tpl b/view/theme/quattro/comment_item.tpl index 7d1d7550b..3fbde1631 100644 --- a/view/theme/quattro/comment_item.tpl +++ b/view/theme/quattro/comment_item.tpl @@ -6,6 +6,7 @@ +
$mytitle diff --git a/view/theme/quattro/jot.tpl b/view/theme/quattro/jot.tpl index 7f9f9bbaf..55fc322d7 100644 --- a/view/theme/quattro/jot.tpl +++ b/view/theme/quattro/jot.tpl @@ -13,6 +13,7 @@ + diff --git a/view/theme/smoothly/jot.tpl b/view/theme/smoothly/jot.tpl index 437eec437..f990c95e1 100644 --- a/view/theme/smoothly/jot.tpl +++ b/view/theme/smoothly/jot.tpl @@ -14,6 +14,7 @@ +
diff --git a/view/theme/testbubble/comment_item.tpl b/view/theme/testbubble/comment_item.tpl index 6d9230dbf..1054b23e2 100644 --- a/view/theme/testbubble/comment_item.tpl +++ b/view/theme/testbubble/comment_item.tpl @@ -6,6 +6,7 @@ +
$mytitle diff --git a/view/theme/testbubble/jot.tpl b/view/theme/testbubble/jot.tpl index 89150534c..12f60b29c 100644 --- a/view/theme/testbubble/jot.tpl +++ b/view/theme/testbubble/jot.tpl @@ -16,6 +16,7 @@ +
From 6effdd570c4905d3921859c0780a093e544defcb Mon Sep 17 00:00:00 2001 From: Zach Prezkuta Date: Thu, 1 Nov 2012 17:42:40 -0600 Subject: [PATCH 2/4] add a confirm dialog and a busy rotator for delete selected --- include/conversation.php | 3 +- include/items.php | 4 +-- view/jot-header.tpl | 33 ++++++++++-------- view/theme/frost/jot-header.tpl | 1 + view/theme/frost/js/theme.js | 34 ++++++++++--------- view/theme/frost/threaded_conversation.tpl | 6 ++-- view/theme/quattro/threaded_conversation.tpl | 3 +- view/theme/smoothly/jot-header.tpl | 35 +++++++++++--------- view/theme/testbubble/jot-header.tpl | 33 ++++++++++-------- view/theme/vier/threaded_conversation.tpl | 3 +- view/threaded_conversation.tpl | 1 + 11 files changed, 91 insertions(+), 65 deletions(-) diff --git a/include/conversation.php b/include/conversation.php index 45736051d..56d34f3d8 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -896,7 +896,8 @@ function status_editor($a,$x, $notes_cid = 0, $popup=false) { '$audurl' => t("Please enter an audio link/URL:"), '$term' => t('Tag term:'), '$fileas' => t('Save to Folder:'), - '$whereareu' => t('Where are you right now?') + '$whereareu' => t('Where are you right now?'), + '$delitems' => t('Delete item(s)?') )); diff --git a/include/items.php b/include/items.php index 9203f663c..939cefc3d 100755 --- a/include/items.php +++ b/include/items.php @@ -3901,10 +3901,10 @@ function drop_item($id,$interactive = true) { // send the notification upstream/downstream as the case may be + proc_run('php',"include/notifier.php","drop","$drop_id"); + if(! $interactive) return $owner; - - proc_run('php',"include/notifier.php","drop","$drop_id"); goaway($a->get_baseurl() . '/' . $_SESSION['return_url']); //NOTREACHED } diff --git a/view/jot-header.tpl b/view/jot-header.tpl index 64bcf27ca..d6f39d6c4 100644 --- a/view/jot-header.tpl +++ b/view/jot-header.tpl @@ -158,21 +158,26 @@ function enableOnUser(){ }); function deleteCheckedItems() { - var checkedstr = ''; + if(confirm('$delitems')) { + var checkedstr = ''; - $('.item-select').each( function() { - if($(this).is(':checked')) { - if(checkedstr.length != 0) { - checkedstr = checkedstr + ',' + $(this).val(); - } - else { - checkedstr = $(this).val(); - } - } - }); - $.post('item', { dropitems: checkedstr }, function(data) { - window.location.reload(); - }); + $("#item-delete-selected").hide(); + $('#item-delete-selected-rotator').show(); + + $('.item-select').each( function() { + if($(this).is(':checked')) { + if(checkedstr.length != 0) { + checkedstr = checkedstr + ',' + $(this).val(); + } + else { + checkedstr = $(this).val(); + } + } + }); + $.post('item', { dropitems: checkedstr }, function(data) { + window.location.reload(); + }); + } } function jotGetLink() { diff --git a/view/theme/frost/jot-header.tpl b/view/theme/frost/jot-header.tpl index 16fd47317..04169beb5 100644 --- a/view/theme/frost/jot-header.tpl +++ b/view/theme/frost/jot-header.tpl @@ -12,5 +12,6 @@ window.baseURL = "$baseurl"; window.geoTag = function () { $geotag } window.ajaxType = 'jot-header'; + window.delItems = '$delitems'; diff --git a/view/theme/frost/js/theme.js b/view/theme/frost/js/theme.js index 37d06c80c..801b94e07 100644 --- a/view/theme/frost/js/theme.js +++ b/view/theme/frost/js/theme.js @@ -900,22 +900,26 @@ function wallInitEditor() { $j("#prvmail-text").contact_autocomplete(baseurl+"/acl"); } -function deleteCheckedItems() { - var checkedstr = ''; +function deleteCheckedItems(delID) { + if(confirm(window.delItems)) { + var checkedstr = ''; - $j('.item-select').each( function() { - if($j(this).is(':checked')) { - if(checkedstr.length != 0) { - checkedstr = checkedstr + ',' + $j(this).val(); - } - else { - checkedstr = $j(this).val(); - } - } - }); - $j.post('item', { dropitems: checkedstr }, function(data) { - window.location.reload(); - }); + $j(delID).hide(); + $j(delID + '-rotator').show(); + $j('.item-select').each( function() { + if($j(this).is(':checked')) { + if(checkedstr.length != 0) { + checkedstr = checkedstr + ',' + $j(this).val(); + } + else { + checkedstr = $j(this).val(); + } + } + }); + $j.post('item', { dropitems: checkedstr }, function(data) { + window.location.reload(); + }); + } } diff --git a/view/theme/frost/threaded_conversation.tpl b/view/theme/frost/threaded_conversation.tpl index 1e77f91c2..0f7f9a986 100644 --- a/view/theme/frost/threaded_conversation.tpl +++ b/view/theme/frost/threaded_conversation.tpl @@ -1,8 +1,9 @@ {{ if $dropping }} -