| 1 | <?php |
|---|
| 2 | // Untersuchen ob alles eingegeben wurde |
|---|
| 3 | function check_input($form_input) { |
|---|
| 4 | global $l; |
|---|
| 5 | if(strlen(trim($form_input['topic'])) < 1) $errors[] = $l['admin']['no_headline']; |
|---|
| 6 | |
|---|
| 7 | // checking URL |
|---|
| 8 | if(strlen(trim($form_input['url'])) < 1) $errors[] = $l['admin']['no_url']; |
|---|
| 9 | elseif(!preg_match("/^[a-z0-9\-_\.\/,]+$/", $form_input['url'])) $errors[] = $l['admin']['false_url_letters']; |
|---|
| 10 | else { |
|---|
| 11 | $f = escape_for_mysql($form_input); |
|---|
| 12 | if(empty($f['date'])) $f['date'] = strftime("%Y-%m-%d %H:%M:%S"); |
|---|
| 13 | |
|---|
| 14 | list($date, $time) = explode(" ", $form_input["date"]); |
|---|
| 15 | list($year, $month, $day) = explode("-", $date); |
|---|
| 16 | list($hour, $minute, $second) = explode(":", $time); |
|---|
| 17 | |
|---|
| 18 | # TODO: (jeena) diese Abfrage scheint noch falsch zu sein |
|---|
| 19 | /* |
|---|
| 20 | if( |
|---|
| 21 | !checkdate((int)$month, (int)$day, (int)$year) OR |
|---|
| 22 | $hour < 0 OR $hour > 23 OR |
|---|
| 23 | $minute < 0 OR $minute > 59 OR |
|---|
| 24 | $second < 0 OR $second > 59 |
|---|
| 25 | ) $errors[] = $l['admin']['false_date']; |
|---|
| 26 | */ |
|---|
| 27 | if($form_input['section'] == 'page') { |
|---|
| 28 | $sql = "SELECT id FROM ".JLOG_DB_CONTENT." WHERE url = '".$f['url']."';"; |
|---|
| 29 | } |
|---|
| 30 | else { |
|---|
| 31 | $sql = "SELECT id FROM ".JLOG_DB_CONTENT." WHERE |
|---|
| 32 | YEAR(date) = ".date("Y", $f['date'])." AND |
|---|
| 33 | MONTH(date) = ".date("m", $f['date'])." AND |
|---|
| 34 | url = '".$f['url']."';"; |
|---|
| 35 | } |
|---|
| 36 | |
|---|
| 37 | $check_url = new Query($sql); |
|---|
| 38 | |
|---|
| 39 | if($check_url->error()) { |
|---|
| 40 | echo "<pre>\n"; |
|---|
| 41 | echo $check_url->getError(); |
|---|
| 42 | echo "</pre>\n"; |
|---|
| 43 | die(); |
|---|
| 44 | } |
|---|
| 45 | |
|---|
| 46 | if($check_url->numRows() > 0) { |
|---|
| 47 | $c = $check_url->fetch(); |
|---|
| 48 | if($c['id'] != $form_input['id'] AND $form_input['section'] != 'page') $errors[] = $l['admin']['url_duplicate']; |
|---|
| 49 | elseif($c['id'] != $form_input['id'] AND $form_input['section'] == 'page') $errors[] = $l['admin']['url_duplicate_page']; |
|---|
| 50 | } |
|---|
| 51 | } |
|---|
| 52 | |
|---|
| 53 | if(strlen(trim($form_input['teaserpic']) > 0) AND !is_file(JLOG_BASEPATH.'img'.DIRECTORY_SEPARATOR."t_".$form_input['teaserpic'])) { |
|---|
| 54 | $errors[] = $l['admin']['false_teaserpic']; |
|---|
| 55 | } |
|---|
| 56 | |
|---|
| 57 | if($form_input['teaserpiconblog'] == "1" AND strlen(trim($form_input['teaserpic'])) == 0) $errors[] = $l['admin']['no_teaserpic_uploaded']; |
|---|
| 58 | |
|---|
| 59 | if(strlen(trim($form_input['teaser'])) < 1) $errors[] = $l['admin']['no_teaser']; |
|---|
| 60 | if(strlen(trim($form_input['content'])) < 1) $errors[] = $l['admin']['no_content']; |
|---|
| 61 | |
|---|
| 62 | return $errors; |
|---|
| 63 | } |
|---|
| 64 | |
|---|
| 65 | // Eingabeformular |
|---|
| 66 | function form_output($form_input) { |
|---|
| 67 | $form_input = array_htmlspecialchars($form_input); |
|---|
| 68 | global $l, $categories, $plugins; |
|---|
| 69 | |
|---|
| 70 | if($form_input['teaserpiconblog'] == 1) $form_input['teaserpiconblog_check'] = "checked='checked'"; |
|---|
| 71 | if($form_input['section'] == 'page') $page = " checked='checked'"; |
|---|
| 72 | else $weblog = " checked='checked'"; |
|---|
| 73 | if($form_input['allowcomments'] === '0') $form_input['comments_check'] = "checked='checked'"; |
|---|
| 74 | if($form_input['allowpingback'] === '0') $form_input['pingback_check'] = "checked='checked'"; |
|---|
| 75 | |
|---|
| 76 | $o = " |
|---|
| 77 | <form method='post' id='entryform' action='".$_SERVER['SCRIPT_NAME']."' accept-charset='UTF-8'> |
|---|
| 78 | <fieldset><legend>".$l['admin']['metadata']."</legend> |
|---|
| 79 | <p><label>".$l['admin']['section']."</label><br /> |
|---|
| 80 | <input id='weblog' name='section' type='radio' value='weblog'".$weblog." /><label for='weblog' class='nobreak'>".$l['admin']['section_weblog']."</label> |
|---|
| 81 | <input id='page' name='section' type='radio' value='page'".$page." /><label for='page' class='nobreak'>".$l['admin']['section_page']."</label></p> |
|---|
| 82 | <p><label for='topic'>".$l['admin']['headline']."</label><br /> |
|---|
| 83 | <input id='topic' name='topic' class='long' type='text' maxlength='255' size='60' value='".$form_input['topic']."' /></p> |
|---|
| 84 | <p><label for='url'>".$l['admin']['url']."</label><br /> |
|---|
| 85 | <input id='url' name='url' class='long' type='text' maxlength='200' size='60' value='".$form_input['url']."' /></p> |
|---|
| 86 | <p><label for='teaser'>".$l['admin']['teaser']."</label><br /> |
|---|
| 87 | <textarea id='teaser' name='teaser' class='small' rows='2' cols='60' >".$form_input['teaser']."</textarea></p> |
|---|
| 88 | <p><label for='keywords'>".$l['admin']['keywords']."</label><br /> |
|---|
| 89 | <input id='keywords' name='keywords' class='long' type='text' maxlength='255' size='60' value='".$form_input['keywords']."' /></p> |
|---|
| 90 | ".$categories->output_select($form_input['categories'])." |
|---|
| 91 | <p id='jlogteaserpic' style='display: none;'><label for='teaserpic'>".$l['admin']['pic_for_teaser']."</label><br /> |
|---|
| 92 | <input id='teaserpic' name='teaserpic' class='short' type='text' size='6' value='".$form_input['teaserpic']."' /> |
|---|
| 93 | <input id='teaserpiconblog' name='teaserpiconblog' type='checkbox' value='1' ".$form_input['teaserpiconblog_check']." /> <label for='teaserpiconblog'>".$l['admin']['show_tpic_on_archive']."</label> |
|---|
| 94 | <script type='text/javascript'> |
|---|
| 95 | document.write(\"<br /><input type='button' name='teaserupload' value='".$l['admin']['pic_upload']."' onclick='jlog_wopen(\\\"".add_session_id_to_url("media/upload-teaser.php")."\\\");' /><input type='button' name='teaserchose' value='".$l['admin']['pic_choose']."' onclick='jlog_wopen(\\\"".add_session_id_to_url("media/select-teaser.php")."\\\");' />\"); |
|---|
| 96 | </script> |
|---|
| 97 | </p> |
|---|
| 98 | <p><input id='allowcomments' type='checkbox' name='allowcomments' value='0' ".$form_input['comments_check']." /><label for='allowcomments'>".$l['admin']['comments_closed']."</label><br /> |
|---|
| 99 | <input id='allowpingback' type='checkbox' name='allowpingback' value='0' ".$form_input['pingback_check']." /><label for='allowpingback'>".$l['admin']['pingback_closed']."</label></p> |
|---|
| 100 | |
|---|
| 101 | </fieldset> |
|---|
| 102 | |
|---|
| 103 | <fieldset><legend>".$l['admin']['contentdata']."</legend> |
|---|
| 104 | <script type='text/javascript'> |
|---|
| 105 | document.write(\"<br /><label for='content'>".$l['admin']['contentpic_choose']."</label><br /><input name='imgupload' type='button' value='".$l['admin']['pic_upload']."' onclick='jlog_wopen(\\\"".add_session_id_to_url("media/upload-picture.php")."\\\");' /><input name='imgselect' type='button' value='".$l['admin']['pic_choose']."' onclick='jlog_wopen(\\\"".add_session_id_to_url("media/select-picture.php")."\\\");' />\"); |
|---|
| 106 | </script> |
|---|
| 107 | <p><label for='content'>".$l['admin']['content']." (".$l['admin']['howto_bbcode'].")</label><br /><br id='bbcode' /> |
|---|
| 108 | <textarea id='content' name='content' rows='15' cols='60' class='big'>".$form_input['content']."</textarea></p> |
|---|
| 109 | |
|---|
| 110 | <p><input class='send' type='submit' name='form_submitted' value='".$l['admin']['preview']."' /> |
|---|
| 111 | <input class='send' type='submit' name='form_submitted' value='".$l['admin']['publish']."' /> |
|---|
| 112 | <input type='hidden' name='id' value='".$form_input['id']."' /> |
|---|
| 113 | <input type='hidden' name='date' value='".$form_input['date']."' /> |
|---|
| 114 | ".add_session_id_input_tag()." |
|---|
| 115 | </p> |
|---|
| 116 | </fieldset> |
|---|
| 117 | </form> |
|---|
| 118 | <script type='text/javascript'> |
|---|
| 119 | jlog_admin = true; |
|---|
| 120 | jlog_l_comments_bold = '".$l['admin']['content_bold']."'; |
|---|
| 121 | jlog_l_comments_italic = '".$l['admin']['content_italic']."'; |
|---|
| 122 | jlog_l_comments_quote = '".$l['admin']['content_quote']."'; |
|---|
| 123 | jlog_l_comments_url = '".$l['admin']['content_url']."'; |
|---|
| 124 | jlog_l_comments_plz_format_txt = '".$l['admin']['content_plz_format_txt']."'; |
|---|
| 125 | jlog_l_comments_input_on_pos = '".$l['admin']['content_input_on_pos']."'; |
|---|
| 126 | jlog_l_comments_url_href = '".$l['admin']['content_url_href']."'; |
|---|
| 127 | jlog_l_comments_url_node = '".$l['admin']['content_url_node']."'; |
|---|
| 128 | jlog_l_list = '".$l['admin']['content_list']."'; |
|---|
| 129 | jlog_l_headline = '".$l['admin']['content_headline']."'; |
|---|
| 130 | </script> |
|---|
| 131 | "; |
|---|
| 132 | |
|---|
| 133 | ### Plugin Hook |
|---|
| 134 | $o = $plugins->callHook('adminForm', $o, $form_input); |
|---|
| 135 | |
|---|
| 136 | return $o; |
|---|
| 137 | } |
|---|
| 138 | |
|---|
| 139 | function preview_output($form_input) { |
|---|
| 140 | global $l, $bbcode, $categories; |
|---|
| 141 | |
|---|
| 142 | // get data from _post |
|---|
| 143 | if(empty($form_input['date'])) $form_input['date'] = time(); |
|---|
| 144 | $output = "<h2 class='preview'>".$l['admin']['preview']."</h2>\n<div class='preview'>".do_entry($form_input, NULL, $section)."</div>"; |
|---|
| 145 | |
|---|
| 146 | return $output; |
|---|
| 147 | } |
|---|
| 148 | |
|---|
| 149 | function insert_blog($form_input) { |
|---|
| 150 | global $l, $plugins; |
|---|
| 151 | |
|---|
| 152 | if($form_input['allowcomments'] != "0") $form_input['allowcomments'] = "1"; |
|---|
| 153 | if($form_input['allowpingback'] != "0") $form_input['allowpingback'] = "1"; |
|---|
| 154 | |
|---|
| 155 | $form_input = escape_for_mysql($form_input); |
|---|
| 156 | $sql = "INSERT INTO ".JLOG_DB_CONTENT." ( |
|---|
| 157 | topic, |
|---|
| 158 | url, |
|---|
| 159 | section, |
|---|
| 160 | date, |
|---|
| 161 | teaser, |
|---|
| 162 | teaserpic, |
|---|
| 163 | teaserpiconblog, |
|---|
| 164 | keywords, |
|---|
| 165 | content, |
|---|
| 166 | comments, |
|---|
| 167 | allowpingback ) |
|---|
| 168 | VALUES ( |
|---|
| 169 | '".$form_input['topic']."', |
|---|
| 170 | '".$form_input['url']."', |
|---|
| 171 | '".$form_input['section']."', |
|---|
| 172 | NOW(), |
|---|
| 173 | '".$form_input['teaser']."', |
|---|
| 174 | '".$form_input['teaserpic']."', |
|---|
| 175 | '".$form_input['teaserpiconblog']."', |
|---|
| 176 | '".$form_input['keywords']."', |
|---|
| 177 | '".$form_input['content']."', |
|---|
| 178 | '".$form_input['allowcomments']."', |
|---|
| 179 | '".$form_input['allowpingback']."' );"; |
|---|
| 180 | |
|---|
| 181 | $writeblog = new Query($sql); |
|---|
| 182 | $id = mysql_insert_id(); |
|---|
| 183 | if($writeblog->error()) { |
|---|
| 184 | echo "<pre>\n"; |
|---|
| 185 | echo $writeblog->getError(); |
|---|
| 186 | echo "</pre>\n"; |
|---|
| 187 | die(); |
|---|
| 188 | } |
|---|
| 189 | |
|---|
| 190 | if(is_array($form_input['categories']) AND $form_input['categories']['0'] != 'no_categories') { |
|---|
| 191 | $sql = "INSERT INTO ".JLOG_DB_CATASSIGN." ( cat_id, content_id ) |
|---|
| 192 | VALUES \n"; |
|---|
| 193 | foreach($form_input['categories'] AS $category) { |
|---|
| 194 | if(++$i > 1) $sql .= ",\n"; |
|---|
| 195 | $sql .= "( '".$category."', '".$id."')"; |
|---|
| 196 | } |
|---|
| 197 | $sql .= ";"; |
|---|
| 198 | |
|---|
| 199 | $catassign = new Query($sql); |
|---|
| 200 | if($catassign->error()) { |
|---|
| 201 | echo "<pre>\n"; |
|---|
| 202 | echo $catassign->getError(); |
|---|
| 203 | echo "</pre>\n"; |
|---|
| 204 | die(); |
|---|
| 205 | } |
|---|
| 206 | } |
|---|
| 207 | |
|---|
| 208 | ### Plugin Hook |
|---|
| 209 | $plugins->callHook('insertEntry', $id, $form_input); |
|---|
| 210 | return $id; |
|---|
| 211 | } |
|---|
| 212 | |
|---|
| 213 | function get_blog($id) { |
|---|
| 214 | global $l, $categories; |
|---|
| 215 | |
|---|
| 216 | $sql = 'SELECT id, url, topic, UNIX_TIMESTAMP(date) AS date, ' . |
|---|
| 217 | 'teaser, teaserpic, teaserpiconblog, keywords, ' . |
|---|
| 218 | 'content, comments, allowpingback, section FROM ' . |
|---|
| 219 | JLOG_DB_CONTENT . ' WHERE id = \'' . $id . |
|---|
| 220 | '\' LIMIT 1;'; |
|---|
| 221 | |
|---|
| 222 | $blog = new Query($sql); |
|---|
| 223 | if($blog->error()) { |
|---|
| 224 | echo "<pre>\n"; |
|---|
| 225 | echo $blog->getError(); |
|---|
| 226 | echo "</pre>\n"; |
|---|
| 227 | die(); |
|---|
| 228 | } |
|---|
| 229 | $form_input = $blog->fetch(); |
|---|
| 230 | |
|---|
| 231 | $form_input['categories'] = $categories->get_assigned_categories($form_input['id']); |
|---|
| 232 | |
|---|
| 233 | return $form_input; |
|---|
| 234 | } |
|---|
| 235 | |
|---|
| 236 | function update_blog($form_input) { |
|---|
| 237 | global $l, $plugins; |
|---|
| 238 | |
|---|
| 239 | if($form_input['allowcomments'] != "0") $form_input['allowcomments'] = "1"; |
|---|
| 240 | if($form_input['allowpingback'] != "0") $form_input['allowpingback'] = "1"; |
|---|
| 241 | |
|---|
| 242 | $form_input = escape_for_mysql($form_input); |
|---|
| 243 | $sql = "UPDATE ".JLOG_DB_CONTENT." SET |
|---|
| 244 | topic = '".$form_input['topic']."', |
|---|
| 245 | url = '".$form_input['url']."', |
|---|
| 246 | section = '".$form_input['section']."', |
|---|
| 247 | teaser = '".$form_input['teaser']."', |
|---|
| 248 | teaserpic = '".$form_input['teaserpic']."', |
|---|
| 249 | teaserpiconblog = '".$form_input['teaserpiconblog']."', |
|---|
| 250 | keywords = '".$form_input['keywords']."', |
|---|
| 251 | content = '".$form_input['content']."', |
|---|
| 252 | comments = '".$form_input['allowcomments']."', |
|---|
| 253 | allowpingback = '".$form_input['allowpingback']."' |
|---|
| 254 | WHERE id = '".$form_input['id']."' LIMIT 1;"; |
|---|
| 255 | |
|---|
| 256 | |
|---|
| 257 | $updateblog = new Query($sql); |
|---|
| 258 | if($updateblog->error()) { |
|---|
| 259 | echo "<pre>\n"; |
|---|
| 260 | echo $updateblog->getError(); |
|---|
| 261 | echo "</pre>\n"; |
|---|
| 262 | die(); |
|---|
| 263 | } |
|---|
| 264 | |
|---|
| 265 | if(is_array($form_input['categories'])) { |
|---|
| 266 | $sql = "DELETE FROM ".JLOG_DB_CATASSIGN." WHERE content_id = '".$form_input['id']."';"; |
|---|
| 267 | $trashcatassign = new Query($sql); |
|---|
| 268 | if($trashcatassign->error()) { |
|---|
| 269 | echo "<pre>\n"; |
|---|
| 270 | echo $trashcatassign->getError(); |
|---|
| 271 | echo "</pre>\n"; |
|---|
| 272 | die(); |
|---|
| 273 | } |
|---|
| 274 | |
|---|
| 275 | if(is_array($form_input['categories']) AND $form_input['categories']['0'] != 'no_categories') { |
|---|
| 276 | $sql = "INSERT INTO ".JLOG_DB_CATASSIGN." ( cat_id, content_id ) |
|---|
| 277 | VALUES \n"; |
|---|
| 278 | foreach($form_input['categories'] AS $category) { |
|---|
| 279 | if(++$i > 1) $sql .= ",\n"; |
|---|
| 280 | $sql .= "( '".$category."', '".$form_input['id']."')"; |
|---|
| 281 | } |
|---|
| 282 | $sql .= ";"; |
|---|
| 283 | |
|---|
| 284 | $catassign = new Query($sql); |
|---|
| 285 | if($catassign->error()) { |
|---|
| 286 | echo "<pre>\n"; |
|---|
| 287 | echo $catassign->getError(); |
|---|
| 288 | echo "</pre>\n"; |
|---|
| 289 | die(); |
|---|
| 290 | } |
|---|
| 291 | } |
|---|
| 292 | } |
|---|
| 293 | |
|---|
| 294 | ### Plugin Hook |
|---|
| 295 | $plugins->callHook('updateEntry', $form_input['id'], $form_input); |
|---|
| 296 | |
|---|
| 297 | return $l['admin']['data_updated']; |
|---|
| 298 | } |
|---|
| 299 | |
|---|
| 300 | function trash_blog($id) { |
|---|
| 301 | global $l; |
|---|
| 302 | |
|---|
| 303 | $sql = "DELETE FROM ".JLOG_DB_CONTENT." WHERE id = '".escape_for_mysql($id)."' LIMIT 1"; |
|---|
| 304 | |
|---|
| 305 | $trashblog = new Query($sql); |
|---|
| 306 | if($trashblog->error()) { |
|---|
| 307 | echo "<pre>\n"; |
|---|
| 308 | echo $trashblog->getError(); |
|---|
| 309 | echo "</pre>\n"; |
|---|
| 310 | die(); |
|---|
| 311 | } |
|---|
| 312 | return $l['admin']['postleted']; |
|---|
| 313 | } |
|---|
| 314 | |
|---|
| 315 | /** |
|---|
| 316 | * add PHPSESSID GET parameter if cookies are not allowed |
|---|
| 317 | **/ |
|---|
| 318 | function add_session_id_to_url($url="") { |
|---|
| 319 | if(empty($_COOKIE[session_name()])) { |
|---|
| 320 | if(strpos($url, "?") === false) $url .= "?"; |
|---|
| 321 | else $url .= "&"; |
|---|
| 322 | $url .= session_name() . "=" . htmlspecialchars(session_id()); |
|---|
| 323 | } |
|---|
| 324 | return $url; |
|---|
| 325 | } |
|---|
| 326 | |
|---|
| 327 | /** |
|---|
| 328 | * add PHPSESSID <input>-Tag if cookies are not allowed |
|---|
| 329 | */ |
|---|
| 330 | function add_session_id_input_tag() { |
|---|
| 331 | if(empty($_COOKIE[session_name()])) { |
|---|
| 332 | return "<input type='hidden' name='" . session_name() . "' value='" . htmlspecialchars(session_id()) . "' />"; |
|---|
| 333 | } |
|---|
| 334 | } |
|---|
| 335 | |
|---|
| 336 | // output the administration menu |
|---|
| 337 | function output_admin_menu() { |
|---|
| 338 | global $l, $plugins; |
|---|
| 339 | $o = '<p id="admin-menu"> |
|---|
| 340 | <a href="'.add_session_id_to_url("./").'">'.$l['admin']['menu_home'].'</a> | |
|---|
| 341 | <a href="'.add_session_id_to_url("categories.php").'">'.$l['admin']['menu_categories'].'</a> | |
|---|
| 342 | <a href="'.add_session_id_to_url("comments.php").'">'.$l['admin']['menu_comments'].'</a> | |
|---|
| 343 | <a href="'.add_session_id_to_url("settings.php").'">'.$l['admin']['menu_settings'].'</a> | |
|---|
| 344 | <a href="'.add_session_id_to_url("plugin.php").'">'.$l['admin']['menu_plugins'].'</a> | |
|---|
| 345 | <a href="'.add_session_id_to_url("logout.php").'">'.$l['admin']['menu_logout'].'</a> |
|---|
| 346 | </p>'; |
|---|
| 347 | |
|---|
| 348 | ### Plugin Hook |
|---|
| 349 | $o = $plugins->callHook('adminMenu', $o); |
|---|
| 350 | |
|---|
| 351 | return $o; |
|---|
| 352 | } |
|---|
| 353 | |
|---|
| 354 | |
|---|
| 355 | // eof |
|---|