[ Index ]

PHP Cross Reference of MyBB 1.8.27

title

Body

[close]

/admin/inc/ -> functions.php (source)

   1  <?php
   2  /**
   3   * MyBB 1.8
   4   * Copyright 2014 MyBB Group, All Rights Reserved
   5   *
   6   * Website: http://www.mybb.com
   7   * License: http://www.mybb.com/about/license
   8   *
   9   */
  10  
  11  /**
  12   * Logs an administrator action taking any arguments as log data.
  13   */
  14  function log_admin_action()
  15  {
  16      global $db, $mybb;
  17  
  18      $data = func_get_args();
  19  
  20      if(count($data) == 1 && is_array($data[0]))
  21      {
  22          $data = $data[0];
  23      }
  24  
  25      if(!is_array($data))
  26      {
  27          $data = array($data);
  28      }
  29  
  30      $log_entry = array(
  31          "uid" => (int)$mybb->user['uid'],
  32          "ipaddress" => $db->escape_binary(my_inet_pton(get_ip())),
  33          "dateline" => TIME_NOW,
  34          "module" => $db->escape_string($mybb->get_input('module')),
  35          "action" => $db->escape_string($mybb->get_input('action')),
  36          "data" => $db->escape_string(@my_serialize($data))
  37      );
  38  
  39      $db->insert_query("adminlog", $log_entry);
  40  }
  41  
  42  /**
  43   * Redirects the current user to a specified URL.
  44   *
  45   * @param string $url The URL to redirect to
  46   */
  47  function admin_redirect($url)
  48  {
  49      if(!headers_sent())
  50      {
  51          $url = str_replace("&amp;", "&", $url);
  52          header("Location: $url");
  53      }
  54      else
  55      {
  56          echo "<meta http-equiv=\"refresh\" content=\"0; url={$url}\">";
  57      }
  58      exit;
  59  }
  60  
  61  /**
  62   * Updates an administration session data array.
  63   *
  64   * @param string $name The name of the item in the data session to update
  65   * @param mixed $value The value
  66   */
  67  function update_admin_session($name, $value)
  68  {
  69      global $db, $admin_session;
  70  
  71      $admin_session['data'][$name] = $value;
  72      $updated_session = array(
  73          "data" => $db->escape_string(@my_serialize($admin_session['data']))
  74      );
  75      $db->update_query("adminsessions", $updated_session, "sid='{$admin_session['sid']}'");
  76  }
  77  
  78  /**
  79   * Saves a "flash message" for the current user to be shown on their next page visit.
  80   *
  81   * @param string $message The message to show
  82   * @param string $type The type of message to be shown (success|error)
  83   */
  84  function flash_message($message, $type='')
  85  {
  86      $flash = array('message' => $message, 'type' => $type);
  87      update_admin_session('flash_message', $flash);
  88  }
  89  
  90  /**
  91   * Draw pagination for pages in the Admin CP.
  92   *
  93   * @param int $page The current page we're on
  94   * @param int $per_page The number of items per page
  95   * @param int $total_items The total number of items in this collection
  96   * @param string $url The URL for pagination of this collection
  97   * @return string The built pagination
  98   */
  99  function draw_admin_pagination($page, $per_page, $total_items, $url)
 100  {
 101      global $mybb, $lang;
 102  
 103      if($total_items <= $per_page)
 104      {
 105          return '';
 106      }
 107  
 108      $pages = ceil($total_items / $per_page);
 109  
 110      $pagination = "<div class=\"pagination\"><span class=\"pages\">{$lang->pages}: </span>\n";
 111  
 112      if($page > 1)
 113      {
 114          $prev = $page-1;
 115          $prev_page = fetch_page_url($url, $prev);
 116          $pagination .= "<a href=\"{$prev_page}\" class=\"pagination_previous\">&laquo; {$lang->previous}</a> \n";
 117      }
 118  
 119      // Maximum number of "page bits" to show
 120      if(!$mybb->settings['maxmultipagelinks'])
 121      {
 122          $mybb->settings['maxmultipagelinks'] = 5;
 123      }
 124  
 125      $max_links = $mybb->settings['maxmultipagelinks'];
 126  
 127      $from = $page-floor($mybb->settings['maxmultipagelinks']/2);
 128      $to = $page+floor($mybb->settings['maxmultipagelinks']/2);
 129  
 130      if($from <= 0)
 131      {
 132          $from = 1;
 133          $to = $from+$max_links-1;
 134      }
 135  
 136      if($to > $pages)
 137      {
 138          $to = $pages;
 139          $from = $pages-$max_links+1;
 140          if($from <= 0)
 141          {
 142              $from = 1;
 143          }
 144      }
 145  
 146      if($to == 0)
 147      {
 148          $to = $pages;
 149      }
 150  
 151      if($from > 2)
 152      {
 153          $first = fetch_page_url($url, 1);
 154          $pagination .= "<a href=\"{$first}\" title=\"{$lang->page} 1\" class=\"pagination_first\">1</a> ... ";
 155      }
 156  
 157      for($i = $from; $i <= $to; ++$i)
 158      {
 159          $page_url = fetch_page_url($url, $i);
 160          if($page == $i)
 161          {
 162              $pagination .= "<span class=\"pagination_current\">{$i}</span> \n";
 163          }
 164          else
 165          {
 166              $pagination .= "<a href=\"{$page_url}\" title=\"{$lang->page} {$i}\">{$i}</a> \n";
 167          }
 168      }
 169  
 170      if($to < $pages)
 171      {
 172          $last = fetch_page_url($url, $pages);
 173          $pagination .= "... <a href=\"{$last}\" title=\"{$lang->page} {$pages}\" class=\"pagination_last\">{$pages}</a>";
 174      }
 175  
 176      if($page < $pages)
 177      {
 178          $next = $page+1;
 179          $next_page = fetch_page_url($url, $next);
 180          $pagination .= " <a href=\"{$next_page}\" class=\"pagination_next\">{$lang->next} &raquo;</a>\n";
 181      }
 182      $pagination .= "</div>\n";
 183      return $pagination;
 184  }
 185  
 186  /**
 187   * Builds a CSV parent list for a particular forum.
 188   *
 189   * @param int $fid The forum ID
 190   * @param string $navsep Optional separator - defaults to comma for CSV list
 191   * @return string The built parent list
 192   */
 193  function make_parent_list($fid, $navsep=",")
 194  {
 195      global $pforumcache, $db;
 196  
 197      if(!$pforumcache)
 198      {
 199          $query = $db->simple_select("forums", "name, fid, pid", "", array("order_by" => "disporder, pid"));
 200          while($forum = $db->fetch_array($query))
 201          {
 202              $pforumcache[$forum['fid']][$forum['pid']] = $forum;
 203          }
 204      }
 205  
 206      reset($pforumcache);
 207      reset($pforumcache[$fid]);
 208  
 209      $navigation = '';
 210  
 211      foreach($pforumcache[$fid] as $key => $forum)
 212      {
 213          if($fid == $forum['fid'])
 214          {
 215              if(!empty($pforumcache[$forum['pid']]))
 216              {
 217                  $navigation = make_parent_list($forum['pid'], $navsep).$navigation;
 218              }
 219  
 220              if($navigation)
 221              {
 222                  $navigation .= $navsep;
 223              }
 224              $navigation .= $forum['fid'];
 225          }
 226      }
 227      return $navigation;
 228  }
 229  
 230  /**
 231   * @param int $fid
 232   */
 233  function save_quick_perms($fid)
 234  {
 235      global $db, $inherit, $canview, $canpostthreads, $canpostreplies, $canpostpolls, $canpostattachments, $cache;
 236  
 237      $permission_fields = array();
 238  
 239      $field_list = $db->show_fields_from("forumpermissions");
 240      foreach($field_list as $field)
 241      {
 242          if(strpos($field['Field'], 'can') !== false || strpos($field['Field'], 'mod') !== false)
 243          {
 244              $permission_fields[$field['Field']] = 1;
 245          }
 246      }
 247  
 248      // "Can Only View Own Threads" and "Can Only Reply Own Threads" permissions are forum permission only options
 249      $usergroup_permission_fields = $permission_fields;
 250      unset($usergroup_permission_fields['canonlyviewownthreads']);
 251      unset($usergroup_permission_fields['canonlyreplyownthreads']);
 252  
 253      $query = $db->simple_select("usergroups", "gid");
 254      while($usergroup = $db->fetch_array($query))
 255      {
 256          $query2 = $db->simple_select("forumpermissions", $db->escape_string(implode(',', array_keys($permission_fields))), "fid='{$fid}' AND gid='{$usergroup['gid']}'", array('limit' => 1));
 257          $existing_permissions = $db->fetch_array($query2);
 258  
 259          if(!$existing_permissions)
 260          {
 261              $query2 = $db->simple_select("usergroups", $db->escape_string(implode(',', array_keys($usergroup_permission_fields))), "gid='{$usergroup['gid']}'", array('limit' => 1));
 262              $existing_permissions = $db->fetch_array($query2);
 263          }
 264  
 265          // Delete existing permissions
 266          $db->delete_query("forumpermissions", "fid='{$fid}' AND gid='{$usergroup['gid']}'");
 267  
 268          // Only insert the new ones if we're using custom permissions
 269          if($inherit[$usergroup['gid']] != 1)
 270          {
 271              if($canview[$usergroup['gid']] == 1)
 272              {
 273                  $pview = 1;
 274              }
 275              else
 276              {
 277                  $pview = 0;
 278              }
 279  
 280              if($canpostthreads[$usergroup['gid']] == 1)
 281              {
 282                  $pthreads = 1;
 283              }
 284              else
 285              {
 286                  $pthreads = 0;
 287              }
 288  
 289              if($canpostreplies[$usergroup['gid']] == 1)
 290              {
 291                  $preplies = 1;
 292              }
 293              else
 294              {
 295                  $preplies = 0;
 296              }
 297  
 298              if($canpostpolls[$usergroup['gid']] == 1)
 299              {
 300                  $ppolls = 1;
 301              }
 302              else
 303              {
 304                  $ppolls = 0;
 305              }
 306  
 307              if(!$preplies && !$pthreads)
 308              {
 309                  $ppost = 0;
 310              }
 311              else
 312              {
 313                  $ppost = 1;
 314              }
 315  
 316              $insertquery = array(
 317                  "fid" => (int)$fid,
 318                  "gid" => (int)$usergroup['gid'],
 319                  "canview" => (int)$pview,
 320                  "canpostthreads" => (int)$pthreads,
 321                  "canpostreplys" => (int)$preplies,
 322                  "canpostpolls" => (int)$ppolls,
 323              );
 324  
 325              foreach($permission_fields as $field => $value)
 326              {
 327                  if(array_key_exists($field, $insertquery))
 328                  {
 329                      continue;
 330                  }
 331  
 332                  $insertquery[$db->escape_string($field)] = (int)$existing_permissions[$field];
 333              }
 334  
 335              $db->insert_query("forumpermissions", $insertquery);
 336          }
 337      }
 338      $cache->update_forumpermissions();
 339  }
 340  
 341  /**
 342   * Checks if a particular user has the necessary permissions to access a particular page.
 343   *
 344   * @param array $action Array containing module and action to check for
 345   * @param bool $error
 346   * @return bool
 347   */
 348  function check_admin_permissions($action, $error = true)
 349  {
 350      global $mybb, $page, $lang, $modules_dir;
 351  
 352      if(is_super_admin($mybb->user['uid']))
 353      {
 354          return true;
 355      }
 356  
 357      require_once $modules_dir."/".$action['module']."/module_meta.php";
 358      if(function_exists($action['module']."_admin_permissions"))
 359      {
 360          $func = $action['module']."_admin_permissions";
 361          $permissions = $func();
 362          if($permissions['permissions'][$action['action']] && $mybb->admin['permissions'][$action['module']][$action['action']] != 1)
 363          {
 364              if($error)
 365              {
 366                  $page->output_header($lang->access_denied);
 367                  $page->add_breadcrumb_item($lang->access_denied, "index.php?module=home-index");
 368                  $page->output_error("<b>{$lang->access_denied}</b><ul><li style=\"list-style-type: none;\">{$lang->access_denied_desc}</li></ul>");
 369                  $page->output_footer();
 370                  exit;
 371              }
 372              else
 373              {
 374                  return false;
 375              }
 376          }
 377      }
 378  
 379      return true;
 380  }
 381  
 382  /**
 383   * Fetches the list of administrator permissions for a particular user or group
 384   *
 385   * @param int $get_uid The user ID to fetch permissions for
 386   * @param int $get_gid The (optional) group ID to fetch permissions for
 387   * @return array Array of permissions for specified user or group
 388   */
 389  function get_admin_permissions($get_uid=0, $get_gid=0)
 390  {
 391      global $db, $mybb;
 392  
 393      // Set UID and GID if none
 394      $uid = $get_uid;
 395      $gid = $get_gid;
 396  
 397      $gid_array = array();
 398  
 399      if($uid === 0)
 400      {
 401          $uid = $mybb->user['uid'];
 402      }
 403  
 404      if(!$gid)
 405      {
 406          // Prepare user's groups since the group isn't specified
 407          $gid_array[] = (-1) * (int)$mybb->user['usergroup'];
 408  
 409          if($mybb->user['additionalgroups'])
 410          {
 411              $additional_groups = explode(',', $mybb->user['additionalgroups']);
 412  
 413              if(!empty($additional_groups))
 414              {
 415                  // Make sure gids are negative
 416                  foreach($additional_groups as $g)
 417                  {
 418                      $gid_array[] = (-1) * abs($g);
 419                  }
 420              }
 421          }
 422      }
 423      else
 424      {
 425          // Group is specified
 426          // Make sure gid is negative
 427          $gid_array[] = (-1) * abs($gid);
 428      }
 429  
 430      // What are we trying to find?
 431      if($get_gid && !$get_uid)
 432      {
 433          // A group only
 434  
 435          $options = array(
 436              "order_by" => "uid",
 437              "order_dir" => "ASC",
 438              "limit" => "1"
 439          );
 440          $query = $db->simple_select("adminoptions", "permissions", "(uid='-{$get_gid}' OR uid='0') AND permissions != ''", $options);
 441          return my_unserialize($db->fetch_field($query, "permissions"));
 442      }
 443      else
 444      {
 445          // A user and/or group
 446  
 447          $options = array(
 448              "order_by" => "uid",
 449              "order_dir" => "DESC"
 450          );
 451  
 452          // Prepare user's groups into SQL format
 453          $group_sql = '';
 454          foreach($gid_array as $gid)
 455          {
 456              $group_sql .= " OR uid='{$gid}'";
 457          }
 458  
 459          $perms_group = array();
 460          $query = $db->simple_select("adminoptions", "permissions, uid", "(uid='{$uid}'{$group_sql}) AND permissions != ''", $options);
 461          while($perm = $db->fetch_array($query))
 462          {
 463              $perm['permissions'] = my_unserialize($perm['permissions']);
 464  
 465              // Sorting out which permission is which
 466              if($perm['uid'] > 0)
 467              {
 468                  $perms_user = $perm;
 469                  return $perms_user['permissions'];
 470              }
 471              elseif($perm['uid'] < 0)
 472              {
 473                  $perms_group[] = $perm['permissions'];
 474              }
 475              else
 476              {
 477                  $perms_def = $perm['permissions'];
 478              }
 479          }
 480  
 481          // Figure out group permissions...ugh.
 482          foreach($perms_group as $gperms)
 483          {
 484              if(!isset($final_group_perms))
 485              {
 486                  // Use this group as the base for admin group permissions
 487                  $final_group_perms = $gperms;
 488                  continue;
 489              }
 490  
 491              // Loop through each specific permission to find the highest permission
 492              foreach($gperms as $perm_name => $perm_value)
 493              {
 494                  if($final_group_perms[$perm_name] != '1' && $perm_value == '1')
 495                  {
 496                      $final_group_perms[$perm_name] = '1';
 497                  }
 498              }
 499          }
 500  
 501          // Send specific user, or group permissions before default.
 502          // If user's permission are explicitly set, they've already been returned above.
 503          if(isset($final_group_perms))
 504          {
 505              return $final_group_perms;
 506          }
 507          elseif(isset($perms_def))
 508          {
 509              return $perms_def;
 510          }
 511  
 512          return array();
 513      }
 514  }
 515  
 516  /**
 517   * Fetch the iconv/mb encoding for a particular MySQL encoding
 518   *
 519   * @param string $mysql_encoding The MySQL encoding
 520   * @return string The iconv/mb encoding
 521   */
 522  function fetch_iconv_encoding($mysql_encoding)
 523  {
 524      $mysql_encoding = explode("_", $mysql_encoding);
 525      switch($mysql_encoding[0])
 526      {
 527          case "utf8":
 528              return "utf-8";
 529              break;
 530          case "latin1":
 531              return "iso-8859-1";
 532              break;
 533          default:
 534              return $mysql_encoding[0];
 535      }
 536  }
 537  
 538  /**
 539   * Adds/Updates a Page/Tab to the permissions array in the adminoptions table
 540   *
 541   * @param string $tab The name of the tab that is being affected
 542   * @param string $page The name of the page being affected (optional - if not specified, will affect everything under the specified tab)
 543   * @param integer $default Default permissions for the page (1 for allowed - 0 for disallowed - -1 to remove)
 544   */
 545  function change_admin_permission($tab, $page="", $default=1)
 546  {
 547      global $db;
 548  
 549      $query = $db->simple_select("adminoptions", "uid, permissions", "permissions != ''");
 550      while($adminoption = $db->fetch_array($query))
 551      {
 552          $adminoption['permissions'] = my_unserialize($adminoption['permissions']);
 553  
 554          if($default == -1)
 555          {
 556              if(!empty($page))
 557              {
 558                  unset($adminoption['permissions'][$tab][$page]);
 559              }
 560              else
 561              {
 562                  unset($adminoption['permissions'][$tab]);
 563              }
 564          }
 565          else
 566          {
 567              if(!empty($page))
 568              {
 569                  if($adminoption['uid'] == 0)
 570                  {
 571                      $adminoption['permissions'][$tab][$page] = 0;
 572                  }
 573                  else
 574                  {
 575                      $adminoption['permissions'][$tab][$page] = $default;
 576                  }
 577              }
 578              else
 579              {
 580                  if($adminoption['uid'] == 0)
 581                  {
 582                      $adminoption['permissions'][$tab]['tab'] = 0;
 583                  }
 584                  else
 585                  {
 586                      $adminoption['permissions'][$tab]['tab'] = $default;
 587                  }
 588              }
 589          }
 590  
 591          $db->update_query("adminoptions", array('permissions' => $db->escape_string(my_serialize($adminoption['permissions']))), "uid='{$adminoption['uid']}'");
 592      }
 593  }
 594  
 595  /**
 596   * Checks if we have had too many attempts at logging into the ACP
 597   *
 598   * @param integer $uid The uid of the admin to check
 599   * @param boolean $return_num Return an array of the number of attempts and expiry time? (default false)
 600   * @return mixed Return an array if the second parameter is true, boolean otherwise.
 601   */
 602  function login_attempt_check_acp($uid=0, $return_num=false)
 603  {
 604      global $db, $mybb;
 605  
 606      $attempts['loginattempts'] = 0;
 607  
 608      if($uid > 0)
 609      {
 610          $query = $db->simple_select("adminoptions", "loginattempts, loginlockoutexpiry", "uid='".(int)$uid."'", 1);
 611          $attempts = $db->fetch_array($query);
 612  
 613          if(!$attempts)
 614          {
 615              return false;
 616          }
 617      }
 618  
 619      if($attempts['loginattempts'] <= 0)
 620      {
 621          return false;
 622      }
 623  
 624      if($mybb->settings['maxloginattempts'] > 0 && $attempts['loginattempts'] >= $mybb->settings['maxloginattempts'])
 625      {
 626          // Has the expiry dateline been set yet?
 627          if($attempts['loginlockoutexpiry'] == 0 && $return_num == false)
 628          {
 629              $db->update_query("adminoptions", array("loginlockoutexpiry" => TIME_NOW+((int)$mybb->settings['loginattemptstimeout']*60)), "uid='".(int)$uid."'");
 630          }
 631  
 632          // Are we returning the # of login attempts?
 633          if($return_num == true)
 634          {
 635              return $attempts;
 636          }
 637          // Otherwise are we still locked out?
 638          else if($attempts['loginlockoutexpiry'] > TIME_NOW)
 639          {
 640              return true;
 641          }
 642      }
 643  
 644      return false;
 645  }
 646  
 647  /**
 648   * Checks whether the administrator is on a mobile device
 649   *
 650   * @param string $useragent The useragent to be checked
 651   * @return boolean A true/false depending on if the administrator is on a mobile
 652   */
 653  function is_mobile($useragent)
 654  {
 655      return preg_match("/(android|avantgo|blackberry|bolt|boost|cricket|docomo|fone|hiptop|mini|mobi|palm|phone|pie|tablet|up\.browser|up\.link|webos|wos)/i", $useragent);
 656  }
 657  
 658  /**
 659   * Checks whether there are any 'security' issues in templates via complex syntax
 660   *
 661   * @param string $template The template to be scanned
 662   * @return boolean A true/false depending on if an issue was detected
 663   */
 664  function check_template($template)
 665  {
 666      // Check to see if our database password is in the template
 667      if(preg_match('#\$config\[(([\'|"]database[\'|"])|([^\'"].*?))\]\[(([\'|"](database|hostname|password|table_prefix|username)[\'|"])|([^\'"].*?))\]#i', $template)) 
 668      {
 669          return true;
 670      }
 671  
 672      // System calls via backtick
 673      if(preg_match('#\$\s*\{#', $template))
 674      {
 675          return true;
 676      }
 677  
 678      // Any other malicious acts?
 679      // Courtesy of ZiNgA BuRgA
 680      if(preg_match("~\\{\\$.+?\\}~s", preg_replace('~\\{\\$+[a-zA-Z_][a-zA-Z_0-9]*((?:-\\>|\\:\\:)\\$*[a-zA-Z_][a-zA-Z_0-9]*|\\[\s*\\$*([\'"]?)[a-zA-Z_ 0-9 ]+\\2\\]\s*)*\\}~', '', $template)))
 681      {
 682          return true;
 683      }
 684  
 685      return false;
 686  }
 687  
 688  /**
 689   * Provides a function to entirely delete a user's posts, and find the threads attached to them
 690   *
 691   * @param integer $uid The uid of the user
 692   * @param int $date A UNIX timestamp to delete posts that are older
 693   * @return array An array of threads to delete, threads/forums to recount
 694   */
 695  function delete_user_posts($uid, $date)
 696  {
 697      global $db;
 698      $uid = (int)$uid;
 699  
 700      // Build an array of posts to delete
 701      $postcache = array();
 702      $query = $db->simple_select("posts", "pid", "uid = '".$uid."' AND dateline < '".$date."'");
 703      while($post = $db->fetch_array($query))
 704      {
 705          $postcache[] = $post['pid'];
 706      }
 707  
 708      if(!$db->num_rows($query))
 709      {
 710          return false;
 711      }
 712      elseif(!empty($postcache))
 713      {
 714          // Let's start deleting posts
 715          $user_posts = implode(",", $postcache);
 716          $query = $db->query("
 717              SELECT p.pid, p.visible, f.usepostcounts, t.tid AS thread, t.firstpost, t.fid AS forum
 718              FROM ".TABLE_PREFIX."posts p
 719              LEFT JOIN ".TABLE_PREFIX."forums f ON (f.fid=p.fid)
 720              LEFT JOIN ".TABLE_PREFIX."threads t ON (t.tid=p.tid)
 721              WHERE p.pid IN ({$user_posts})
 722          ");
 723  
 724          $post_count = 0; // Collect the post number to deduct from the user's postcount
 725          $thread_list = array();
 726          $forum_list = array();
 727          $delete_thread_list = array();
 728          if(!$db->num_rows($query))
 729          {
 730              return false;
 731          }
 732          else
 733          {
 734              while($post = $db->fetch_array($query))
 735              {
 736                  if($post['usepostcounts'] != 0 && $post['visible'] == 1)
 737                  {
 738                      ++$post_count;
 739                  }
 740  
 741                  if($post['pid'] == $post['firstpost'])
 742                  {
 743                      $delete_thread_list[] = $post['thread'];
 744                  }
 745  
 746                  if(!in_array($post['thread'], $thread_list) && !in_array($post['thread'], $delete_thread_list))
 747                  {
 748                      $thread_list[] = $post['thread']; // Threads that have been affected by this action, that aren't marked to be deleted
 749                  }
 750                  if(!in_array($post['forum'], $forum_list))
 751                  {
 752                      $forum_list[] = $post['forum']; // Forums that have been affected, too
 753                  }
 754  
 755                  // Remove the attachments to this post, then delete the post
 756                  remove_attachments($post['pid']);
 757                  $db->delete_query("posts", "pid = '".$post['pid']."'");
 758                  $db->delete_query("pollvotes", "pid = '".$post['pid']."'"); // Delete pollvotes attached to this post
 759              }
 760  
 761              $db->update_query("users", array("postnum" => "postnum-".$post_count.""), "uid='".$uid."'", 1, true);
 762  
 763              $to_return = array(
 764                  'to_delete' => $delete_thread_list,
 765                  'thread_update' => $thread_list,
 766                  'forum_update' => $forum_list
 767              );
 768  
 769              return $to_return;
 770          }
 771      }
 772  }
 773  
 774  /**
 775   * Prints a selection JavaScript code for selectable groups/forums fields.
 776   */
 777  function print_selection_javascript()
 778  {
 779      static $already_printed = false;
 780  
 781      if($already_printed)
 782      {
 783          return;
 784      }
 785  
 786      $already_printed = true;
 787  
 788      echo "<script type=\"text/javascript\">
 789  	function checkAction(id)
 790      {
 791          var checked = '';
 792  
 793          $('.'+id+'_forums_groups_check').each(function(e, val)
 794          {
 795              if($(this).prop('checked') == true)
 796              {
 797                  checked = $(this).val();
 798              }
 799          });
 800  
 801          $('.'+id+'_forums_groups').each(function(e)
 802          {
 803              $(this).hide();
 804          });
 805  
 806          if($('#'+id+'_forums_groups_'+checked))
 807          {
 808              $('#'+id+'_forums_groups_'+checked).show();
 809          }
 810      }
 811  </script>";
 812  }
 813  
 814  if(!function_exists('array_column'))
 815  {
 816  	function array_column($input, $column_key)
 817      {
 818          $values = array();
 819  
 820          if(!is_array($input))
 821          {
 822              $input = array($input);
 823          }
 824  
 825          foreach($input as $val)
 826          {
 827              if(is_array($val) && isset($val[$column_key]))
 828              {
 829                  $values[] = $val[$column_key];
 830              }
 831              elseif(is_object($val) && isset($val->$column_key))
 832              {
 833                  $values[] = $val->$column_key;
 834              }
 835          }
 836  
 837          return $values;
 838      }
 839  }
 840  
 841  /**
 842   * Output the auto redirect block.
 843   *
 844   * @param \Form $form An existing form instance to wrap the redirect within.
 845   * @param string $prompt The prompt to show.
 846   */
 847  function output_auto_redirect($form, $prompt)
 848  {
 849      global $lang;
 850  
 851      echo <<<HTML
 852  <div class="confirm_action">
 853      <p>{$prompt}</p>
 854      <br />
 855      <script type="text/javascript">
 856          $(function() { 
 857              var button = $("#proceed_button"); 
 858              if (button.length > 0) {
 859                  // create a temporary div element to render the text within, un-escaping HTML entities
 860                  var textElement = $('<div/>').html('{$lang->automatically_redirecting}');
 861              
 862                  button.val(textElement.text());
 863                  button.attr("disabled", true);
 864                  button.css("color", "#aaa");
 865                  button.css("borderColor", "#aaa");
 866                  
 867                  var parent_form = button.closest('form');
 868  
 869                  if (parent_form.length > 0) {
 870                      parent_form.submit();
 871                  }
 872              }
 873          });
 874      </script>
 875      <p class="buttons">
 876          {$form->generate_submit_button($lang->proceed, array('class' => 'button_yes', 'id' => 'proceed_button'))}
 877      </p>
 878  </div>
 879  HTML;
 880  }


2005 - 2021 © MyBB.de | Alle Rechte vorbehalten! | Sponsor: netcup Cross-referenced by PHPXref