3 { |
3 { |
4 "Plugin Name" : "Gorilla Paste", |
4 "Plugin Name" : "Gorilla Paste", |
5 "Plugin URI" : "http://enanocms.org/plugin/gorilla", |
5 "Plugin URI" : "http://enanocms.org/plugin/gorilla", |
6 "Description" : "For The Toughest Pasting Jobs On Earth.™ The pastebin, Enano style. <a href=\"http://enanocms.org/plugin/geshi\" onclick=\"window.open(this.href); return false;\">GeSHi plugin</a> highly recommended.", |
6 "Description" : "For The Toughest Pasting Jobs On Earth.™ The pastebin, Enano style. <a href=\"http://enanocms.org/plugin/geshi\" onclick=\"window.open(this.href); return false;\">GeSHi plugin</a> highly recommended.", |
7 "Author" : "Dan Fuhry", |
7 "Author" : "Dan Fuhry", |
8 "Version" : "0.1", |
8 "Version" : "0.1.1", |
9 "Author URI" : "http://enanocms.org/" |
9 "Author URI" : "http://enanocms.org/", |
|
10 "Version list" : ['0.1', '0.1.1'] |
10 } |
11 } |
11 **!*/ |
12 **!*/ |
12 |
13 |
13 // Register namespace and ACLs |
14 // Register namespace and ACLs |
14 $plugins->attachHook('acl_rule_init', 'gorilla_setupcore($this, $session);'); |
15 $plugins->attachHook('acl_rule_init', 'gorilla_setupcore($this, $session);'); |
105 load_component(['jquery', 'jquery-ui']); |
114 load_component(['jquery', 'jquery-ui']); |
106 $('#gorilla_submit_result').empty().hide(); |
115 $('#gorilla_submit_result').empty().hide(); |
107 |
116 |
108 var whitey = whiteOutElement(document.forms['gorilla_create']); |
117 var whitey = whiteOutElement(document.forms['gorilla_create']); |
109 |
118 |
|
119 var parent = parseInt($('#gorilla_parent').val()); |
|
120 if ( isNaN(parent) ) |
|
121 parent = 0; |
|
122 |
110 var json_packet = { |
123 var json_packet = { |
111 highlight: $('#gorilla_highlight').val(), |
124 highlight: $('#gorilla_highlight').val(), |
112 text: $('#gorilla_create_text').val(), |
125 text: $('#gorilla_create_text').val(), |
113 is_private: $('#gorilla_private:checked').val() ? true : false, |
126 is_private: $('#gorilla_private:checked').val() ? true : false, |
114 nick: $('#gorilla_nick').val(), |
127 nick: $('#gorilla_nick').val(), |
115 title: $('#gorilla_title').val(), |
128 title: $('#gorilla_title').val(), |
116 ttl: parseInt($('.gorilla_ttl:checked').val()) |
129 ttl: parseInt($('.gorilla_ttl:checked').val()), |
|
130 parent: parent, |
|
131 hash: $('#gorilla_hash').val(); |
117 }; |
132 }; |
118 json_packet = ajaxEscape(toJSONString(json_packet)); |
133 json_packet = ajaxEscape(toJSONString(json_packet)); |
119 ajaxPost(makeUrlNS('Special', 'NewPaste/ajaxsubmit'), 'r=' + json_packet, function(ajax) |
134 ajaxPost(makeUrlNS('Special', 'NewPaste/ajaxsubmit'), 'r=' + json_packet, function(ajax) |
120 { |
135 { |
121 if ( ajax.readyState == 4 && ajax.status == 200 ) |
136 if ( ajax.readyState == 4 && ajax.status == 200 ) |
246 <label><input<?php if ( $ttl == 2592000 ) echo ' checked="checked"'; ?> class="gorilla_ttl" type="radio" name="ttl" value="2592000" /> <?php echo $lang->get('gorilla_lbl_ttl_month'); ?></label> |
261 <label><input<?php if ( $ttl == 2592000 ) echo ' checked="checked"'; ?> class="gorilla_ttl" type="radio" name="ttl" value="2592000" /> <?php echo $lang->get('gorilla_lbl_ttl_month'); ?></label> |
247 <label><input<?php if ( $ttl == 0 ) echo ' checked="checked"'; ?> class="gorilla_ttl" type="radio" name="ttl" value="0" /> <?php echo $lang->get('gorilla_lbl_ttl_forever'); ?></label> |
262 <label><input<?php if ( $ttl == 0 ) echo ' checked="checked"'; ?> class="gorilla_ttl" type="radio" name="ttl" value="0" /> <?php echo $lang->get('gorilla_lbl_ttl_forever'); ?></label> |
248 </em> |
263 </em> |
249 </p> |
264 </p> |
250 |
265 |
|
266 <!-- reply --> |
|
267 <p> |
|
268 <?php echo $lang->get('gorilla_lbl_reply'); ?><input id="gorilla_parent" name="parent" size="8" value="<?php echo $copy_from ? strval($copy_from) : ''; ?>" /> |
|
269 </p> |
|
270 |
251 </div> |
271 </div> |
252 </fieldset> |
272 </fieldset> |
|
273 |
|
274 <!-- hash --> |
|
275 <?php if ( $private && $copy_from ): ?> |
|
276 <input type="hidden" name="hash" id="gorilla_hash" value="<?php echo gorilla_sign($paste_id, $text); ?>" /> |
|
277 <?php else: ?> |
|
278 <input type="hidden" name="hash" id="gorilla_hash" value="" /> |
|
279 <?php endif; ?> |
253 |
280 |
254 <!-- login notice --> |
281 <!-- login notice --> |
255 |
282 |
256 <?php if ( !$have_permission && !$session->user_logged_in ): ?> |
283 <?php if ( !$have_permission && !$session->user_logged_in ): ?> |
257 <div class="info-box-mini"> |
284 <div class="info-box-mini"> |
316 'highlight' => $_POST['highlight'], |
345 'highlight' => $_POST['highlight'], |
317 'text' => $_POST['text'], |
346 'text' => $_POST['text'], |
318 'is_private' => isset($_POST['is_private']), |
347 'is_private' => isset($_POST['is_private']), |
319 'nick' => $_POST['nick'], |
348 'nick' => $_POST['nick'], |
320 'title' => $_POST['title'], |
349 'title' => $_POST['title'], |
321 'ttl' => intval($_POST['ttl']) |
350 'ttl' => intval($_POST['ttl']), |
|
351 'parent' => intval($_POST['parent']), |
|
352 'hash' => $_POST['hash'] |
322 ); |
353 ); |
|
354 } |
|
355 |
|
356 if ( $info['parent'] ) |
|
357 { |
|
358 // make sure we have the right hash |
|
359 $q = $db->sql_query('SELECT paste_text FROM ' . table_prefix . "pastes WHERE paste_id = {$info['parent']};"); |
|
360 if ( !$q ) |
|
361 $db->_die(); |
|
362 |
|
363 if ( $db->numrows() > 0 ) |
|
364 { |
|
365 list($old_text) = $db->fetchrow_num(); |
|
366 if ( $info['hash'] !== gorilla_sign($info['parent'], $old_text) ) |
|
367 { |
|
368 $info['parent'] = 0; |
|
369 } |
|
370 } |
|
371 else |
|
372 { |
|
373 $info['parent'] = 0; |
|
374 } |
323 } |
375 } |
324 |
376 |
325 if ( !$have_permission ) |
377 if ( !$have_permission ) |
326 { |
378 { |
327 return '1;<div class="error-box-mini">' . $lang->get('etc_access_denied') . '</div>'; |
379 return '1;<div class="error-box-mini">' . $lang->get('etc_access_denied') . '</div>'; |
357 $now = time(); |
409 $now = time(); |
358 $flags = 0; |
410 $flags = 0; |
359 if ( $info['is_private'] ) |
411 if ( $info['is_private'] ) |
360 $flags |= PASTE_PRIVATE; |
412 $flags |= PASTE_PRIVATE; |
361 |
413 |
362 $sql = 'INSERT INTO ' . table_prefix . "pastes( paste_title, paste_text, paste_author, paste_author_name, paste_author_ip, paste_language, paste_timestamp, paste_ttl, paste_flags ) VALUES\n" |
414 $sql = 'INSERT INTO ' . table_prefix . "pastes( paste_title, paste_text, paste_author, paste_author_name, paste_author_ip, paste_language, paste_timestamp, paste_ttl, paste_flags, paste_parent ) VALUES\n" |
363 . " ( {$info_db['title']}, {$info_db['text']}, $session->user_id, {$info_db['nick']}, '{$_SERVER['REMOTE_ADDR']}', {$info_db['highlight']}, $now, {$info_db['ttl']}, $flags );"; |
415 . " ( {$info_db['title']}, {$info_db['text']}, $session->user_id, {$info_db['nick']}, '{$_SERVER['REMOTE_ADDR']}', {$info_db['highlight']}, $now, {$info_db['ttl']}, $flags, {$info_db['parent']} );"; |
364 |
416 |
365 if ( !$db->sql_query($sql) ) |
417 if ( !$db->sql_query($sql) ) |
366 ( $is_ajax ) ? $db->die_json() : $db->_die(); |
418 ( $is_ajax ) ? $db->die_json() : $db->_die(); |
367 |
419 |
368 // avoid insert_id |
420 // avoid insert_id |
570 $date = enano_date('D, j M Y H:i:s', $paste_timestamp); |
632 $date = enano_date('D, j M Y H:i:s', $paste_timestamp); |
571 $pasteinfo = $lang->get('gorilla_msg_paste_info', array('user_link' => $user_link, 'date' => $date)); |
633 $pasteinfo = $lang->get('gorilla_msg_paste_info', array('user_link' => $user_link, 'date' => $date)); |
572 |
634 |
573 echo '<div class="mdg-infobox" style="margin: 10px 0;">'; |
635 echo '<div class="mdg-infobox" style="margin: 10px 0;">'; |
574 echo '<div style="float: right;"> |
636 echo '<div style="float: right;"> |
575 ' . $lang->get('gorilla_msg_other_formats', array('plain_link' => makeUrlNS('Paste', $paste_id, 'format=text', true), 'download_link' => makeUrlNS('Paste', $paste_id, 'format=download', true))) . ' |
637 ' . $lang->get('gorilla_msg_other_formats', array('plain_link' => makeUrlNS('Paste', $paste_id, 'format=text' . ( $localhash ? "&hash=$localhash" : '' ), true), 'download_link' => makeUrlNS('Paste', $paste_id, 'format=download' . ( $localhash ? "&hash=$localhash" : '' ), true))) . ' |
576 / |
638 / |
577 <a title="' . $lang->get('gorilla_tip_new_paste') . '" href="' . makeUrlNS('Special', 'NewPaste') . '">' . $lang->get('gorilla_btn_new_paste') . '</a> |
639 <a title="' . $lang->get('gorilla_tip_new_paste') . '" href="' . makeUrlNS('Special', 'NewPaste') . '">' . $lang->get('gorilla_btn_new_paste') . '</a> |
578 / |
640 / |
579 <a title="' . $lang->get('gorilla_tip_copy_from_this') . '" href="' . makeUrlNS('Special', 'NewPaste/Copy=' . $paste_id) . '">' . $lang->get('gorilla_btn_copy_from_this') . '</a>'; |
641 <a title="' . $lang->get('gorilla_tip_copy_from_this') . '" href="' . makeUrlNS('Special', 'NewPaste/Copy=' . $paste_id, ( $paste_flags & PASTE_PRIVATE ? 'hash=' . gorilla_sign($paste_id, $paste_text) : false ), true) . '">' . $lang->get('gorilla_btn_copy_from_this') . '</a>'; |
|
642 |
|
643 if ( $paste_parent ) |
|
644 { |
|
645 // pull flags of parent |
|
646 $q = $db->sql_query('SELECT paste_text, paste_flags FROM ' . table_prefix . "pastes WHERE paste_id = $paste_parent;"); |
|
647 if ( !$q ) |
|
648 $db->_die(); |
|
649 |
|
650 if ( $db->numrows() > 0 ) |
|
651 { |
|
652 list($parent_text, $parent_flags) = $db->fetchrow_num(); |
|
653 $parenthash = false; |
|
654 if ( $parent_flags & PASTE_PRIVATE ) |
|
655 { |
|
656 $parenthash = gorilla_sign($paste_parent, $parent_text); |
|
657 } |
|
658 |
|
659 echo ' / ' . $lang->get('gorilla_msg_reply_to', array( |
|
660 'parent_link' => makeUrlNS('Paste', $paste_parent, ( $parenthash ? "hash=$parenthash" : '' ), true), |
|
661 'diff_link' => makeUrlNS('Paste', $paste_id, 'diff_parent' . ( $localhash ? "&hash=$localhash" : '' ), true), |
|
662 'parent_id' => $paste_parent |
|
663 )); |
|
664 } |
|
665 $db->free_result($q); |
|
666 } |
580 |
667 |
581 if ( $perms->get_permissions($perm) && $session->user_logged_in ) |
668 if ( $perms->get_permissions($perm) && $session->user_logged_in ) |
582 { |
669 { |
583 echo ' / <a title="' . $lang->get('gorilla_tip_delete') . '" href="' . makeUrlNS('Paste', $paste_id, 'delete&hash=' . hmac_sha1($paste_id, sha1($paste_text)), true) . '">' . $lang->get('gorilla_btn_delete') . '</a>'; |
670 echo ' / <a title="' . $lang->get('gorilla_tip_delete') . '" href="' . makeUrlNS('Paste', $paste_id, 'delete&hash=' . gorilla_sign($paste_id, $paste_text), true) . '">' . $lang->get('gorilla_btn_delete') . '</a>'; |
584 } |
671 } |
585 if ( $perms->get_permissions('mod_misc') ) |
672 if ( $perms->get_permissions('mod_misc') ) |
586 { |
673 { |
587 echo ' / <span title="' . $lang->get('gorilla_tip_paste_ip') . '">' . $paste_author_ip . '</span>'; |
674 echo ' / <span title="' . $lang->get('gorilla_tip_paste_ip') . '">' . $paste_author_ip . '</span>'; |
588 } |
675 } |
589 |
676 |
590 echo '</div>'; |
677 echo '</div>'; |
591 echo $pasteinfo; |
678 echo $pasteinfo; |
592 echo '</div>'; |
679 echo '</div>'; |
|
680 |
|
681 if ( isset($_GET['diff_parent']) && isset($parent_text) ) |
|
682 { |
|
683 echo '<p>' . $lang->get('gorilla_btn_view_normal', array('orig_url' => makeUrlNS('Paste', $paste_id, ( $localhash ? "hash=$localhash" : '' ), true))) . '</p>'; |
|
684 // convert to unix newlines to avoid confusing the diff engine (seen on Chromium on Linux) |
|
685 echo RenderMan::diff(str_replace("\r\n", "\n", $parent_text), str_replace("\r\n", "\n", $paste_text)); |
|
686 $output->footer(); |
|
687 return; |
|
688 } |
593 |
689 |
594 if ( preg_match('/^## /m', $paste_text) ) |
690 if ( preg_match('/^## /m', $paste_text) ) |
595 { |
691 { |
596 gorilla_show_text_multi($paste_text, $paste_language); |
692 gorilla_show_text_multi($paste_text, $paste_language); |
597 } |
693 } |
633 } |
729 } |
634 |
730 |
635 function gorilla_show_text_multi($text, $lang) |
731 function gorilla_show_text_multi($text, $lang) |
636 { |
732 { |
637 $sections = preg_split('/^## .*$/m', $text); |
733 $sections = preg_split('/^## .*$/m', $text); |
638 $headingcount = preg_match_all('/^## (.+?)(?: \[([a-z_-]+)\])? *$/m', $text, $matches); |
734 $headingcount = preg_match_all('/^## (.+?)(?: \[([a-z_-]+)\])? *\r?$/m', $text, $matches); |
639 |
735 |
640 // if we have one heading less than the number of sections, print the first section |
736 // if we have one heading less than the number of sections, print the first section |
641 while ( count($sections) > $headingcount ) |
737 while ( count($sections) > $headingcount ) |
642 { |
738 { |
643 gorilla_show_text(trim($sections[0], "\r\n"), $lang); |
739 gorilla_show_text(trim($sections[0], "\r\n"), $lang); |
675 paste_author_ip varchar(39) NOT NULL, |
776 paste_author_ip varchar(39) NOT NULL, |
676 paste_language varchar(32) NOT NULL DEFAULT 'plaintext', |
777 paste_language varchar(32) NOT NULL DEFAULT 'plaintext', |
677 paste_timestamp int(12) NOT NULL DEFAULT 0, |
778 paste_timestamp int(12) NOT NULL DEFAULT 0, |
678 paste_ttl int(12) NOT NULL DEFAULT 86400, |
779 paste_ttl int(12) NOT NULL DEFAULT 86400, |
679 paste_flags int(8) NOT NULL DEFAULT 0, |
780 paste_flags int(8) NOT NULL DEFAULT 0, |
|
781 paste_parent int(18) NOT NULL DEFAULT 0, |
680 PRIMARY KEY ( paste_id ) |
782 PRIMARY KEY ( paste_id ) |
681 ) ENGINE=`MyISAM` CHARSET=`UTF8` COLLATE=`utf8_bin`; |
783 ) ENGINE=`MyISAM` CHARSET=`UTF8` COLLATE=`utf8_bin`; |
682 |
784 |
|
785 **!*/ |
|
786 |
|
787 /**!upgrade from="0.1"; to="0.1.1"; dbms="mysql"; ** |
|
788 ALTER TABLE {{TABLE_PREFIX}}pastes ADD COLUMN paste_parent int(18) NOT NULL DEFAULT 0; |
683 **!*/ |
789 **!*/ |
684 |
790 |
685 /**!uninstall ** |
791 /**!uninstall ** |
686 DROP TABLE {{TABLE_PREFIX}}pastes; |
792 DROP TABLE {{TABLE_PREFIX}}pastes; |
687 **!*/ |
793 **!*/ |
714 lbl_ttl: 'Keep it for:', |
820 lbl_ttl: 'Keep it for:', |
715 lbl_ttl_hour: '1 hour', |
821 lbl_ttl_hour: '1 hour', |
716 lbl_ttl_day: '1 day', |
822 lbl_ttl_day: '1 day', |
717 lbl_ttl_month: '1 month', |
823 lbl_ttl_month: '1 month', |
718 lbl_ttl_forever: 'forever', |
824 lbl_ttl_forever: 'forever', |
|
825 lbl_reply: 'Reply to paste: #', |
719 msg_will_prompt_for_login: 'You are not logged in. You will be asked to log in when you click the submit button below.', |
826 msg_will_prompt_for_login: 'You are not logged in. You will be asked to log in when you click the submit button below.', |
720 btn_submit: 'Paste it!', |
827 btn_submit: 'Paste it!', |
721 |
828 |
722 msg_created: 'Paste created.', |
829 msg_created: 'Paste created.', |
723 msg_paste_url: 'Share this paste using the following URL:', |
830 msg_paste_url: 'Share this paste using the following URL:', |
734 btn_copy_from_this: 'cp', |
841 btn_copy_from_this: 'cp', |
735 tip_copy_from_this: 'Create a new paste, copying this one into the form', |
842 tip_copy_from_this: 'Create a new paste, copying this one into the form', |
736 btn_delete: 'rm', |
843 btn_delete: 'rm', |
737 tip_delete: 'Delete this paste', |
844 tip_delete: 'Delete this paste', |
738 tip_paste_ip: 'IP address of paste author', |
845 tip_paste_ip: 'IP address of paste author', |
|
846 msg_reply_to: 'parent: <a href="%parent_link%">#%parent_id%</a> (<a href="%diff_link%">diff</a>)', |
|
847 btn_view_normal: '<b>Difference from parent</b> (<a href="%orig_url%">back to paste</a>)', |
739 template_ns_string: 'paste', |
848 template_ns_string: 'paste', |
740 |
849 |
741 msg_paste_deleted: 'Paste deleted.', |
850 msg_paste_deleted: 'Paste deleted.', |
742 msg_delete_confirm: 'Really delete this paste?', |
851 msg_delete_confirm: 'Really delete this paste?', |
743 btn_delete_confirm: 'Delete', |
852 btn_delete_confirm: 'Delete', |