dev-util/idea-* minor fixes
[anomen-overlay.git] / www-apps / pmwiki / cookbook / SortPageLines / sortpagelines.php
blobd9ed5033c7337a0e28e56c4d255e770920de4269
1 <?php if (!defined('PmWiki')) exit();
3 /*
4 SortPage
6 Adds two sort buttons to edit form.
7 Lines in page can be sorted in ascending or descending order.
8 Duplicate and empty lines are removed.
11 Copyright 2011 Anomen (ludek_h@seznam.cz)
12 This program is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published
14 by the Free Software Foundation; either version 2 of the License, or
15 (at your option) any later version.
18 $RecipeInfo['SortPageLines']['Version'] = '2013-01-24';
20 if ($action == 'edit') {
22 $HTMLHeaderFmt['sortpage'] = '
23 <script type="text/javascript">
24 // <![CDATA[
27 function sortPage(order) {
29 var sortPage_fnc = function (a, b) {
30 a = a.toLowerCase();
31 b = b.toLowerCase();
32 return ((a < b) ? -1 : ((a > b) ? 1 : 0));
35 var textField = document.getElementById("text");
36 var value = textField.value;
38 var mySplitResult = value.split("\n");
39 mySplitResult.sort(sortPage_fnc);
40 if (order == 1) {
41 mySplitResult.reverse();
43 var value = "";
44 var lastval = "";
45 for(i = 0; i < mySplitResult.length; i++) {
46 var curr = mySplitResult[i];
47 if ((lastval != curr) && (curr != "")) {
48 value = value + curr + "\n";
50 lastval = curr;
52 textField.value = value;
54 // ]]>
55 </script>
58 if (IsEnabled($EnableGUIButtons)) {
59 $GUIButtons['sortpageAsc'] = array(1250, '', '', '',
60 '<input type=\"button\" name=\"sortPageButtonAsc\" value=\"$[Sort lines ASC]\" onClick=\"sortPage(0);\" />');
61 $GUIButtons['sortpageDesc'] = array(1251, '', '', '',
62 '<input type=\"button\" name=\"sortPageButtonDesc\" value=\"$[Sort lines DESC]\" onClick=\"sortPage(1);\" />');
63 } else {
64 $MessagesFmt[] = "<input type='button' name='sortPageButtonAsc' value='$[Sort lines ASC]' onClick='sortPage(0);'/>";
65 $MessagesFmt[] = "<input type='button' name='sortPageButtonDesc' value='$[Sort lines DESC]' onClick='sortPage(1);'/>";