Beehive PHP Cross Reference Discussion Forums

Source: /ajax.php - 615 lines - 15281 bytes - Summary - Text - Print

   1  <?php
   2  
   3  /*======================================================================
   4  Copyright Project Beehive Forum 2002
   5  
   6  This file is part of Beehive Forum.
   7  
   8  Beehive Forum is free software; you can redistribute it and/or modify
   9  it under the terms of the GNU General Public License as published by
  10  the Free Software Foundation; either version 3 of the License, or
  11  (at your option) any later version.
  12  
  13  Beehive Forum is distributed in the hope that it will be useful,
  14  but WITHOUT ANY WARRANTY; without even the implied warranty of
  15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16  GNU General Public License for more details.
  17  
  18  You should have received a copy of the GNU General Public License
  19  along with Beehive; if not, write to the Free Software
  20  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
  21  USA
  22  ======================================================================*/
  23  
  24  // Bootstrap
  25  require_once  'boot.php';
  26  
  27  // Required includes
  28  require_once  BH_INCLUDE_PATH . 'attachments.inc.php';
  29  require_once  BH_INCLUDE_PATH . 'cache.inc.php';
  30  require_once  BH_INCLUDE_PATH . 'constants.inc.php';
  31  require_once  BH_INCLUDE_PATH . 'header.inc.php';
  32  require_once  BH_INCLUDE_PATH . 'light.inc.php';
  33  require_once  BH_INCLUDE_PATH . 'messages.inc.php';
  34  require_once  BH_INCLUDE_PATH . 'pm.inc.php';
  35  require_once  BH_INCLUDE_PATH . 'poll.inc.php';
  36  require_once  BH_INCLUDE_PATH . 'post.inc.php';
  37  require_once  BH_INCLUDE_PATH . 'session.inc.php';
  38  require_once  BH_INCLUDE_PATH . 'stats.inc.php';
  39  require_once  BH_INCLUDE_PATH . 'text_captcha.inc.php';
  40  require_once  BH_INCLUDE_PATH . 'user.inc.php';
  41  // End Required includes
  42  
  43  if (!isset($_GET['ajax']) || !isset($_GET['action'])) {
  44  
  45      header_status(500, 'Internal Server Error');
  46      exit;
  47  }
  48  
  49  $content = '';
  50  
  51  switch ($_GET['action']) {
  52  
  53      case 'user_autocomplete':
  54  
  55          if (!session::logged_in()) break;
  56  
  57          cache_disable();
  58  
  59          if (!isset($_GET['term']) || strlen(trim($_GET['term'])) == 0) {
  60  
  61              header_status(500, 'Internal Server Error');
  62              exit;
  63          }
  64  
  65          $term = trim($_GET['term']);
  66  
  67          if (!($search_results_array = user_search($term))) {
  68  
  69              $content = '';
  70              break;
  71          }
  72  
  73          header('Content-type: application/json; charset=UTF-8');
  74  
  75          $content = json_encode($search_results_array);
  76  
  77          break;
  78  
  79      case 'sig_toggle':
  80  
  81          if (!session::logged_in()) break;
  82  
  83          cache_disable();
  84  
  85          $page_prefs = session::get_post_page_prefs();
  86  
  87          if (!isset($_GET['display']) || !in_array($_GET['display'], array('true', 'false'))) {
  88  
  89              header_status(500, 'Internal Server Error');
  90              exit;
  91          }
  92  
  93          if ($_GET['display'] === 'true') {
  94              $page_prefs = (double)$page_prefs | POST_SIGNATURE_DISPLAY;
  95          } else {
  96              $page_prefs = (double)$page_prefs & ~POST_SIGNATURE_DISPLAY;
  97          }
  98  
  99          $user_prefs = array(
 100              'POST_PAGE' => $page_prefs
 101          );
 102  
 103          if (!user_update_prefs($_SESSION['UID'], $user_prefs)) {
 104  
 105              header_status(500, 'Internal Server Error');
 106              exit;
 107          }
 108  
 109          break;
 110  
 111      case 'attachment_toggle':
 112  
 113          if (!session::logged_in()) break;
 114  
 115          cache_disable();
 116  
 117          $page_prefs = session::get_post_page_prefs();
 118  
 119          if (!isset($_GET['display']) || !in_array($_GET['display'], array('true', 'false'))) {
 120  
 121              header_status(500, 'Internal Server Error');
 122              exit;
 123          }
 124  
 125          if ($_GET['display'] === 'true') {
 126              $page_prefs = (double)$page_prefs | POST_ATTACHMENT_DISPLAY;
 127          } else {
 128              $page_prefs = (double)$page_prefs & ~POST_ATTACHMENT_DISPLAY;
 129          }
 130  
 131          $user_prefs = array(
 132              'POST_PAGE' => $page_prefs
 133          );
 134  
 135          if (!user_update_prefs($_SESSION['UID'], $user_prefs)) {
 136  
 137              header_status(500, 'Internal Server Error');
 138              exit;
 139          }
 140  
 141          break;
 142  
 143      case 'emots_toggle':
 144  
 145          if (!session::logged_in()) break;
 146  
 147          cache_disable();
 148  
 149          $page_prefs = session::get_post_page_prefs();
 150  
 151          if (!isset($_GET['display']) || !in_array($_GET['display'], array('true', 'false'))) {
 152  
 153              header_status(500, 'Internal Server Error');
 154              exit;
 155          }
 156  
 157          if ($_GET['display'] === 'true') {
 158              $page_prefs = (double)$page_prefs | POST_EMOTICONS_DISPLAY;
 159          } else {
 160              $page_prefs = (double)$page_prefs & ~POST_EMOTICONS_DISPLAY;
 161          }
 162  
 163          $user_prefs = array(
 164              'POST_PAGE' => $page_prefs
 165          );
 166  
 167          if (!user_update_prefs($_SESSION['UID'], $user_prefs)) {
 168  
 169              header_status(500, 'Internal Server Error');
 170              exit;
 171          }
 172  
 173          break;
 174  
 175      case 'poll_advanced_toggle':
 176  
 177          if (!session::logged_in()) break;
 178  
 179          cache_disable();
 180  
 181          $page_prefs = session::get_post_page_prefs();
 182  
 183          if (!isset($_GET['display']) || !in_array($_GET['display'], array('true', 'false'))) {
 184  
 185              header_status(500, 'Internal Server Error');
 186              exit;
 187          }
 188  
 189          if ($_GET['display'] === 'true') {
 190              $page_prefs = (double)$page_prefs | POLL_ADVANCED_DISPLAY;
 191          } else {
 192              $page_prefs = (double)$page_prefs & ~POLL_ADVANCED_DISPLAY;
 193          }
 194  
 195          $user_prefs = array(
 196              'POST_PAGE' => $page_prefs
 197          );
 198  
 199          if (!user_update_prefs($_SESSION['UID'], $user_prefs)) {
 200  
 201              header_status(500, 'Internal Server Error');
 202              exit;
 203          }
 204  
 205          break;
 206  
 207      case 'poll_additional_message_toggle':
 208  
 209          if (!session::logged_in()) break;
 210  
 211          cache_disable();
 212  
 213          $page_prefs = session::get_post_page_prefs();
 214  
 215          if (!isset($_GET['display']) || !in_array($_GET['display'], array('true', 'false'))) {
 216  
 217              header_status(500, 'Internal Server Error');
 218              exit;
 219          }
 220  
 221          if ($_GET['display'] === 'true') {
 222              $page_prefs = (double)$page_prefs | POLL_ADDITIONAL_MESSAGE_DISPLAY;
 223          } else {
 224              $page_prefs = (double)$page_prefs & ~POLL_ADDITIONAL_MESSAGE_DISPLAY;
 225          }
 226  
 227          $user_prefs = array(
 228              'POST_PAGE' => $page_prefs
 229          );
 230  
 231          if (!user_update_prefs($_SESSION['UID'], $user_prefs)) {
 232  
 233              header_status(500, 'Internal Server Error');
 234              exit;
 235          }
 236  
 237          break;
 238  
 239      case 'poll_soft_edit_toggle':
 240  
 241          if (!session::logged_in()) break;
 242  
 243          cache_disable();
 244  
 245          $page_prefs = session::get_post_page_prefs();
 246  
 247          if (!isset($_GET['display']) || !in_array($_GET['display'], array('true', 'false'))) {
 248  
 249              header_status(500, 'Internal Server Error');
 250              exit;
 251          }
 252  
 253          if ($_GET['display'] === 'true') {
 254              $page_prefs = (double)$page_prefs | POLL_EDIT_SOFT_DISPLAY;
 255          } else {
 256              $page_prefs = (double)$page_prefs & ~POLL_EDIT_SOFT_DISPLAY;
 257          }
 258  
 259          $user_prefs = array(
 260              'POST_PAGE' => $page_prefs
 261          );
 262  
 263          if (!user_update_prefs($_SESSION['UID'], $user_prefs)) {
 264  
 265              header_status(500, 'Internal Server Error');
 266              exit;
 267          }
 268  
 269          break;
 270  
 271      case 'forum_stats_toggle':
 272  
 273          if (!session::logged_in()) break;
 274  
 275          cache_disable();
 276  
 277          if (!isset($_GET['display']) || !in_array($_GET['display'], array('true', 'false'))) {
 278  
 279              header_status(500, 'Internal Server Error');
 280              exit;
 281          }
 282  
 283          if ($_GET['display'] === 'true') {
 284  
 285              $user_prefs = array(
 286                  'SHOW_STATS' => 'Y'
 287              );
 288  
 289          } else {
 290  
 291              $user_prefs = array(
 292                  'SHOW_STATS' => 'N'
 293              );
 294          }
 295  
 296          if (!user_update_prefs($_SESSION['UID'], $user_prefs)) {
 297  
 298              header_status(500, 'Internal Server Error');
 299              exit;
 300          }
 301  
 302          break;
 303  
 304      case 'frame_resize':
 305  
 306          if (!session::logged_in()) break;
 307  
 308          cache_disable();
 309  
 310          if (!isset($_GET['size']) || !is_numeric($_GET['size'])) {
 311  
 312              header_status(500, 'Internal Server Error');
 313              exit;
 314          }
 315  
 316          $left_frame_width = max(100, abs($_GET['size']));
 317  
 318          $user_prefs = array(
 319              'LEFT_FRAME_WIDTH' => $left_frame_width,
 320          );
 321  
 322          if (!user_update_prefs($_SESSION['UID'], $user_prefs)) {
 323  
 324              header_status(500, 'Internal Server Error');
 325              exit;
 326          }
 327  
 328          break;
 329  
 330      case 'pm_check_messages':
 331  
 332          if (!session::logged_in()) break;
 333  
 334          cache_disable();
 335  
 336          if (($pm_notification_data = pm_check_messages()) === false) {
 337  
 338              header_status(500, 'Internal Server Error');
 339              exit;
 340          }
 341  
 342          header('Content-type: application/json; charset=UTF-8');
 343  
 344          $content = json_encode($pm_notification_data);
 345  
 346          break;
 347  
 348      case 'get_forum_stats':
 349  
 350          cache_check_request_throttle(300);
 351  
 352          if (!($content = stats_get_html())) {
 353  
 354              header_status(500, 'Internal Server Error');
 355              exit;
 356          }
 357  
 358          break;
 359  
 360      case 'reload_captcha':
 361  
 362          $text_captcha = new captcha(6, 15, 25, 9, 30);
 363  
 364          if (!$text_captcha->generate_keys()) {
 365  
 366              header_status(500, 'Internal Server Error');
 367              exit;
 368          }
 369  
 370          if (!($text_captcha_image = $text_captcha->make_image())) {
 371  
 372              header_status(500, 'Internal Server Error');
 373              exit;
 374          }
 375  
 376          cache_disable();
 377  
 378          header('Content-type: application/json; charset=UTF-8');
 379  
 380          $content = json_encode(array(
 381              'image' => sprintf(
 382                  "data:image/jpeg;base64,%s",
 383                  base64_encode(file_get_contents($text_captcha_image))
 384              ),
 385              'chars' => $text_captcha->get_num_chars(),
 386              'key' => $text_captcha->get_public_key()
 387          ));
 388  
 389          break;
 390  
 391      case 'font_size_larger':
 392      case 'font_size_smaller':
 393  
 394          if (!session::logged_in()) break;
 395  
 396          cache_disable();
 397  
 398          if (!isset($_GET['msg']) || !validate_msg($_GET['msg'])) {
 399  
 400              header_status(500, 'Internal Server Error');
 401              exit;
 402          }
 403  
 404          list($tid, $pid) = explode('.', $_GET['msg']);
 405  
 406          $user_prefs = user_get_prefs($_SESSION['UID']);
 407  
 408          switch ($_GET['action']) {
 409  
 410              case 'font_size_smaller':
 411  
 412                  $user_prefs = array(
 413                      'FONT_SIZE' => $user_prefs['FONT_SIZE'] - 1
 414                  );
 415  
 416                  break;
 417  
 418              case 'font_size_larger':
 419  
 420                  $user_prefs = array(
 421                      'FONT_SIZE' => $user_prefs['FONT_SIZE'] + 1
 422                  );
 423  
 424                  break;
 425          }
 426  
 427          if ($user_prefs['FONT_SIZE'] < 5) $user_prefs['FONT_SIZE'] = 5;
 428  
 429          if ($user_prefs['FONT_SIZE'] > 15) $user_prefs['FONT_SIZE'] = 15;
 430  
 431          if (!user_update_prefs($_SESSION['UID'], $user_prefs)) {
 432  
 433              header_status(500, 'Internal Server Error');
 434              exit;
 435          }
 436  
 437          header('Content-type: application/json; charset=UTF-8');
 438  
 439          $content = json_encode(array(
 440              'success' => true,
 441              'font_size' => $user_prefs['FONT_SIZE'],
 442              'html' => messages_fontsize_form($tid, $pid, true, $user_prefs['FONT_SIZE'])
 443          ));
 444  
 445          break;
 446  
 447      case 'post_options':
 448  
 449          cache_disable();
 450  
 451          if (!isset($_GET['msg']) || !validate_msg($_GET['msg'])) {
 452  
 453              header_status(500, 'Internal Server Error');
 454              exit;
 455          }
 456  
 457          list($tid, $pid) = explode('.', $_GET['msg']);
 458  
 459          if (!isset($_GET['pid']) || !is_numeric($_GET['pid'])) {
 460  
 461              header_status(500, 'Internal Server Error');
 462              exit;
 463          }
 464  
 465          if (!($message = messages_get($tid, $_GET['pid'], 1))) {
 466  
 467              header_status(500, 'Internal Server Error');
 468              exit;
 469          }
 470  
 471          if (!($content = message_get_post_options_html($tid, $pid, $message))) {
 472  
 473              header_status(500, 'Internal Server Error');
 474              exit;
 475          }
 476  
 477          break;
 478  
 479      case 'post_vote':
 480  
 481          if (!session::logged_in()) break;
 482  
 483          cache_disable();
 484  
 485          if (!isset($_GET['msg']) || !validate_msg($_GET['msg'])) {
 486  
 487              header_status(500, 'Internal Server Error');
 488              exit;
 489          }
 490  
 491          list($tid, $pid) = explode('.', $_GET['msg']);
 492  
 493          if (!isset($_GET['post_rating']) || !in_array($_GET['post_rating'], array(-1, 1))) {
 494  
 495              header_status(500, 'Internal Server Error');
 496              exit;
 497          }
 498  
 499          $post_rating = $_GET['post_rating'];
 500  
 501          if (!post_set_user_rating($tid, $pid, $_SESSION['UID'], $post_rating)) {
 502  
 503              header_status(500, 'Internal Server Error');
 504              exit;
 505          }
 506  
 507          if (!($message = messages_get($tid, $pid, 1))) {
 508  
 509              header_status(500, 'Internal Server Error');
 510              exit;
 511          }
 512  
 513          if (isset($_GET['mobile'])) {
 514  
 515              if (!($content = light_message_get_vote_form_html($message))) {
 516  
 517                  header_status(500, 'Internal Server Error');
 518                  exit;
 519              }
 520  
 521          } else {
 522  
 523              if (!($content = message_get_vote_form_html($message))) {
 524  
 525                  header_status(500, 'Internal Server Error');
 526                  exit;
 527              }
 528          }
 529  
 530          break;
 531  
 532      case 'poll_add_question':
 533  
 534          if (!session::logged_in()) break;
 535  
 536          cache_disable();
 537  
 538          if (!isset($_GET['question_number']) || !is_numeric($_GET['question_number'])) {
 539  
 540              header_status(500, 'Internal Server Error');
 541              exit;
 542          }
 543  
 544          if (!($content = poll_get_question_html($_GET['question_number']))) {
 545  
 546              header_status(500, 'Internal Server Error');
 547              exit;
 548          }
 549  
 550          break;
 551  
 552      case 'poll_add_option':
 553  
 554          if (!session::logged_in()) break;
 555  
 556          cache_disable();
 557  
 558          if (!isset($_GET['question_number']) || !is_numeric($_GET['question_number'])) {
 559  
 560              header_status(500, 'Internal Server Error');
 561              exit;
 562          }
 563  
 564          if (!isset($_GET['option_number']) || !is_numeric($_GET['option_number'])) {
 565  
 566              header_status(500, 'Internal Server Error');
 567              exit;
 568          }
 569  
 570          if (!($content = poll_get_option_html($_GET['question_number'], $_GET['option_number']))) {
 571  
 572              header_status(500, 'Internal Server Error');
 573              exit;
 574          }
 575  
 576          break;
 577  
 578      case 'pref_attachment':
 579  
 580          if (!session::logged_in()) break;
 581  
 582          cache_disable();
 583  
 584          if (!isset($_GET['type']) || !in_array($_GET['type'], array('pic_aid', 'avatar_aid'))) {
 585  
 586              header_status(500, 'Internal Server Error');
 587              exit;
 588          }
 589  
 590          $attachments_array = attachments_get_all($_SESSION['UID']);
 591  
 592          header('Content-type: application/json; charset=UTF-8');
 593  
 594          switch ($_GET['type']) {
 595  
 596              case 'pic_aid':
 597  
 598                  $content = json_encode(user_prefs_filter_attachments($attachments_array, 95, 95));
 599                  break;
 600  
 601              case 'avatar_aid':
 602  
 603                  $content = json_encode(user_prefs_filter_attachments($attachments_array, 16, 16));
 604                  break;
 605          }
 606  
 607          break;
 608  
 609      default:
 610  
 611          header_status(500, 'Internal Server Error');
 612          exit;
 613  }
 614  
 615  echo $content;

title

Description

title

Description

title

Description

title

title

Body