| 1 | <?php |
|---|
| 2 | /* |
|---|
| 3 | WPListCal Utility functions |
|---|
| 4 | |
|---|
| 5 | Permission is hereby granted, free of charge, to any person or organization |
|---|
| 6 | obtaining a copy of the software and accompanying documentation covered by |
|---|
| 7 | this license (the "Software") to use, reproduce, display, distribute, |
|---|
| 8 | execute, and transmit the Software, and to prepare derivative works of the |
|---|
| 9 | Software, and to permit third-parties to whom the Software is furnished to |
|---|
| 10 | do so, all subject to the following: |
|---|
| 11 | |
|---|
| 12 | The copyright notices in the Software and this entire statement, including |
|---|
| 13 | the above license grant and author attributions, this restriction, and the |
|---|
| 14 | following disclaimer, must be included in all copies of the Software, in |
|---|
| 15 | whole or in part, and all derivative works of the Software, unless such |
|---|
| 16 | copies or derivative works are solely in the form of machine-executable |
|---|
| 17 | object code generated by a source language processor. |
|---|
| 18 | |
|---|
| 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|---|
| 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|---|
| 21 | FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT |
|---|
| 22 | SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE |
|---|
| 23 | FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, |
|---|
| 24 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
|---|
| 25 | DEALINGS IN THE SOFTWARE. |
|---|
| 26 | */ |
|---|
| 27 | function wplc_set_if_null(&$var, $option_id) { |
|---|
| 28 | if(is_null($var)) |
|---|
| 29 | $var = get_option($option_id); |
|---|
| 30 | } |
|---|
| 31 | |
|---|
| 32 | function wplc_br2nl($string) |
|---|
| 33 | { |
|---|
| 34 | return preg_replace('/\<br(\s*)?\/?\>/i', "\n", $string); |
|---|
| 35 | } |
|---|
| 36 | |
|---|
| 37 | add_action('admin_print_scripts', 'wplc_js_admin_header'); |
|---|
| 38 | function wplc_js_admin_header() { |
|---|
| 39 | wp_print_scripts(array('sack')); |
|---|
| 40 | ?> |
|---|
| 41 | <script type="text/javascript" charset="utf-8"> |
|---|
| 42 | //<![CDATA[ |
|---|
| 43 | function wplcDeleteEvent(id, msg) { |
|---|
| 44 | if(confirm(msg)) { |
|---|
| 45 | var mysack = new sack("<?php bloginfo( 'wpurl' ); ?>/wp-admin/admin-ajax.php" ); |
|---|
| 46 | mysack.execute = 1; |
|---|
| 47 | mysack.method = 'POST'; |
|---|
| 48 | mysack.setVar("action", "wplc_delete_event"); |
|---|
| 49 | mysack.setVar("id", id); |
|---|
| 50 | mysack.encVar("cookie", document.cookie, false); |
|---|
| 51 | mysack.onError = function() { alert('AJAX error in deleting event'); }; |
|---|
| 52 | mysack.onCompletion = function() { |
|---|
| 53 | if(mysack.responseStatus[0] == 200) { |
|---|
| 54 | var row = document.getElementById('event-'+id); |
|---|
| 55 | if(row != null && row.parentNode != null) |
|---|
| 56 | row.parentNode.removeChild(row); |
|---|
| 57 | } |
|---|
| 58 | } |
|---|
| 59 | mysack.runAJAX(); |
|---|
| 60 | |
|---|
| 61 | return true; |
|---|
| 62 | } |
|---|
| 63 | } |
|---|
| 64 | |
|---|
| 65 | function wplc_changeDisabled(id, disabled) { |
|---|
| 66 | var elm = document.getElementById(id); |
|---|
| 67 | if(elm != null && elm.disabled != disabled) |
|---|
| 68 | elm.disabled = disabled; |
|---|
| 69 | } |
|---|
| 70 | |
|---|
| 71 | var fieldsDirty = false; |
|---|
| 72 | var editable = false; |
|---|
| 73 | function wplc_matchValue(myid, matchid, isselect) { |
|---|
| 74 | if(fieldsDirty) |
|---|
| 75 | return; |
|---|
| 76 | |
|---|
| 77 | var me = document.getElementById(myid); |
|---|
| 78 | var you = document.getElementById(matchid); |
|---|
| 79 | |
|---|
| 80 | if(isselect) { |
|---|
| 81 | you.selectedIndex = me.selectedIndex; |
|---|
| 82 | } |
|---|
| 83 | else { |
|---|
| 84 | you.value = me.value; |
|---|
| 85 | } |
|---|
| 86 | } |
|---|
| 87 | |
|---|
| 88 | function wplc_doallday(checked) { |
|---|
| 89 | var visibility = checked ? "hidden" : "visible"; |
|---|
| 90 | |
|---|
| 91 | var starttime = document.getElementById("start-time-cont"); |
|---|
| 92 | var endtime = document.getElementById("end-time-cont"); |
|---|
| 93 | |
|---|
| 94 | if(starttime && typeof(starttime) != 'undefined') { |
|---|
| 95 | starttime.style.visibility = visibility; |
|---|
| 96 | } |
|---|
| 97 | if(endtime && typeof(endtime) != 'undefined') { |
|---|
| 98 | endtime.style.visibility = visibility; |
|---|
| 99 | } |
|---|
| 100 | } |
|---|
| 101 | //]]> |
|---|
| 102 | </script> |
|---|
| 103 | <?php |
|---|
| 104 | } |
|---|
| 105 | |
|---|
| 106 | add_action("admin_head", "wplc_admin_css"); |
|---|
| 107 | function wplc_admin_css() { |
|---|
| 108 | wp_enqueue_style( 'thickbox' ); |
|---|
| 109 | ?> |
|---|
| 110 | |
|---|
| 111 | <style type="text/css" media="screen"> |
|---|
| 112 | .wplc_eventformfield { |
|---|
| 113 | margin: 10px 8px 20px 20px; |
|---|
| 114 | padding: 0px; |
|---|
| 115 | border-color: rgb(235, 235, 235); |
|---|
| 116 | } |
|---|
| 117 | .wplc_date_label { |
|---|
| 118 | float:left; |
|---|
| 119 | display:block; |
|---|
| 120 | width:50px; |
|---|
| 121 | font-weight:bold; |
|---|
| 122 | padding-top:7px; |
|---|
| 123 | } |
|---|
| 124 | .wplc_date_body { |
|---|
| 125 | float:left; |
|---|
| 126 | clear:right; |
|---|
| 127 | } |
|---|
| 128 | #link, #title-noformat, #location { |
|---|
| 129 | margin: 1px; |
|---|
| 130 | padding: 0; |
|---|
| 131 | border: 0; |
|---|
| 132 | width: 100%; |
|---|
| 133 | font-size: 1.7em; |
|---|
| 134 | outline: none; |
|---|
| 135 | } |
|---|
| 136 | #linkwrap, #titlewrap-noformat, #locwrap { |
|---|
| 137 | border: 1px solid rgb(204, 204, 204); |
|---|
| 138 | padding: 2px 3px; |
|---|
| 139 | } |
|---|
| 140 | .wplc_delete:hover { |
|---|
| 141 | background-color: red; |
|---|
| 142 | border-bottom: 1px solid red; |
|---|
| 143 | color: white; |
|---|
| 144 | } |
|---|
| 145 | .wplc_link { |
|---|
| 146 | border-bottom:1px solid; |
|---|
| 147 | padding:1px 2px; |
|---|
| 148 | text-decoration:none; |
|---|
| 149 | } |
|---|
| 150 | .wplc_baseline { |
|---|
| 151 | vertical-align:baseline; |
|---|
| 152 | } |
|---|
| 153 | .wplc_plaincursor { |
|---|
| 154 | cursor:default !important; |
|---|
| 155 | } |
|---|
| 156 | </style> |
|---|
| 157 | <?php |
|---|
| 158 | } |
|---|
| 159 | |
|---|
| 160 | function wplc_is_wplc_page() { |
|---|
| 161 | global $wplc_plugin; |
|---|
| 162 | |
|---|
| 163 | switch($_GET['page']) { |
|---|
| 164 | case $wplc_plugin: |
|---|
| 165 | case "wplc-edit": |
|---|
| 166 | case "wplc-options": |
|---|
| 167 | case "wplc-import": |
|---|
| 168 | case "wplc-export": |
|---|
| 169 | case "wplc-delete-event": |
|---|
| 170 | case "wplc_cleanup": |
|---|
| 171 | return true; |
|---|
| 172 | default: |
|---|
| 173 | return false; |
|---|
| 174 | } |
|---|
| 175 | } |
|---|
| 176 | |
|---|
| 177 | function wplc_dbg_print_array(&$array) { |
|---|
| 178 | echo "<pre>"; |
|---|
| 179 | print_r($array); |
|---|
| 180 | echo "</pre>"; |
|---|
| 181 | } |
|---|
| 182 | |
|---|
| 183 | // Returns the server time converted to the wordpress timezone time |
|---|
| 184 | function wplc_time() { |
|---|
| 185 | $time = time(); |
|---|
| 186 | $gmt_time = $time - intval(date('Z', $time)); |
|---|
| 187 | $wp_offset = get_option("gmt_offset"); |
|---|
| 188 | return $gmt_time + ($wp_offset * 3600); |
|---|
| 189 | } |
|---|
| 190 | |
|---|
| 191 | class FormatToken { |
|---|
| 192 | var $string; |
|---|
| 193 | var $dependent; |
|---|
| 194 | |
|---|
| 195 | function FormatToken($_string, $_dependent=null) { |
|---|
| 196 | $this->string = $_string; |
|---|
| 197 | $this->dependent = $_dependent; |
|---|
| 198 | } |
|---|
| 199 | } |
|---|
| 200 | ?> |
|---|