[ Index ]

PHP Cross Reference of MyBB 1.8.38

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(empty($inherit[$usergroup['gid']]))
 270          {
 271              if(!empty($canview[$usergroup['gid']]))
 272              {
 273                  $pview = 1;
 274              }
 275              else
 276              {
 277                  $pview = 0;
 278              }
 279  
 280              if(!empty($canpostthreads[$usergroup['gid']]))
 281              {
 282                  $pthreads = 1;
 283              }
 284              else
 285              {
 286                  $pthreads = 0;
 287              }
 288  
 289              if(!empty($canpostreplies[$usergroup['gid']]))
 290              {
 291                  $preplies = 1;
 292              }
 293              else
 294              {
 295                  $preplies = 0;
 296              }
 297  
 298              if(!empty($canpostpolls[$usergroup['gid']]))
 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)] = isset($existing_permissions[$field]) ? (int)$existing_permissions[$field] : 0;
 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(
 363              !empty($permissions['permissions'][$action['action']]) &&
 364              empty($mybb->admin['permissions'][$action['module']][$action['action']])
 365          )
 366          {
 367              if($error)
 368              {
 369                  $page->output_header($lang->access_denied);
 370                  $page->add_breadcrumb_item($lang->access_denied, "index.php?module=home-index");
 371                  $page->output_error("<b>{$lang->access_denied}</b><ul><li style=\"list-style-type: none;\">{$lang->access_denied_desc}</li></ul>");
 372                  $page->output_footer();
 373                  exit;
 374              }
 375              else
 376              {
 377                  return false;
 378              }
 379          }
 380      }
 381  
 382      return true;
 383  }
 384  
 385  /**
 386   * Fetches the list of administrator permissions for a particular user or group
 387   *
 388   * @param int $get_uid The user ID to fetch permissions for
 389   * @param int $get_gid The (optional) group ID to fetch permissions for
 390   * @return array Array of permissions for specified user or group
 391   */
 392  function get_admin_permissions($get_uid=0, $get_gid=0)
 393  {
 394      global $db, $mybb;
 395  
 396      // Set UID and GID if none
 397      $uid = $get_uid;
 398      $gid = $get_gid;
 399  
 400      $gid_array = array();
 401  
 402      if($uid === 0)
 403      {
 404          $uid = $mybb->user['uid'];
 405      }
 406  
 407      if(!$gid)
 408      {
 409          // Prepare user's groups since the group isn't specified
 410          $gid_array[] = (-1) * (int)$mybb->user['usergroup'];
 411  
 412          if($mybb->user['additionalgroups'])
 413          {
 414              $additional_groups = explode(',', $mybb->user['additionalgroups']);
 415  
 416              if(!empty($additional_groups))
 417              {
 418                  // Make sure gids are negative
 419                  foreach($additional_groups as $g)
 420                  {
 421                      $gid_array[] = (-1) * abs($g);
 422                  }
 423              }
 424          }
 425      }
 426      else
 427      {
 428          // Group is specified
 429          // Make sure gid is negative
 430          $gid_array[] = (-1) * abs($gid);
 431      }
 432  
 433      // What are we trying to find?
 434      if($get_gid && !$get_uid)
 435      {
 436          // A group only
 437  
 438          $options = array(
 439              "order_by" => "uid",
 440              "order_dir" => "ASC",
 441              "limit" => "1"
 442          );
 443          $query = $db->simple_select("adminoptions", "permissions", "(uid='-{$get_gid}' OR uid='0') AND permissions != ''", $options);
 444          return my_unserialize($db->fetch_field($query, "permissions"));
 445      }
 446      else
 447      {
 448          // A user and/or group
 449  
 450          $options = array(
 451              "order_by" => "uid",
 452              "order_dir" => "DESC"
 453          );
 454  
 455          // Prepare user's groups into SQL format
 456          $group_sql = '';
 457          foreach($gid_array as $gid)
 458          {
 459              $group_sql .= " OR uid='{$gid}'";
 460          }
 461  
 462          $perms_group = array();
 463          $query = $db->simple_select("adminoptions", "permissions, uid", "(uid='{$uid}'{$group_sql}) AND permissions != ''", $options);
 464          while($perm = $db->fetch_array($query))
 465          {
 466              $perm['permissions'] = my_unserialize($perm['permissions']);
 467  
 468              // Sorting out which permission is which
 469              if($perm['uid'] > 0)
 470              {
 471                  $perms_user = $perm;
 472                  return $perms_user['permissions'];
 473              }
 474              elseif($perm['uid'] < 0)
 475              {
 476                  $perms_group[] = $perm['permissions'];
 477              }
 478              else
 479              {
 480                  $perms_def = $perm['permissions'];
 481              }
 482          }
 483  
 484          // Figure out group permissions...ugh.
 485          foreach($perms_group as $gperms)
 486          {
 487              if(!isset($final_group_perms))
 488              {
 489                  // Use this group as the base for admin group permissions
 490                  $final_group_perms = $gperms;
 491                  continue;
 492              }
 493  
 494              // Loop through each specific permission to find the highest permission
 495              foreach($gperms as $perm_name => $perm_value)
 496              {
 497                  if($final_group_perms[$perm_name] != '1' && $perm_value == '1')
 498                  {
 499                      $final_group_perms[$perm_name] = '1';
 500                  }
 501              }
 502          }
 503  
 504          // Send specific user, or group permissions before default.
 505          // If user's permission are explicitly set, they've already been returned above.
 506          if(isset($final_group_perms))
 507          {
 508              return $final_group_perms;
 509          }
 510          elseif(isset($perms_def))
 511          {
 512              return $perms_def;
 513          }
 514  
 515          return array();
 516      }
 517  }
 518  
 519  /**
 520   * Fetch the iconv/mb encoding for a particular MySQL encoding
 521   *
 522   * @param string $mysql_encoding The MySQL encoding
 523   * @return string The iconv/mb encoding
 524   */
 525  function fetch_iconv_encoding($mysql_encoding)
 526  {
 527      $mysql_encoding = explode("_", $mysql_encoding);
 528      switch($mysql_encoding[0])
 529      {
 530          case "utf8":
 531              return "utf-8";
 532              break;
 533          case "latin1":
 534              return "iso-8859-1";
 535              break;
 536          default:
 537              return $mysql_encoding[0];
 538      }
 539  }
 540  
 541  /**
 542   * Adds/Updates a Page/Tab to the permissions array in the adminoptions table
 543   *
 544   * @param string $tab The name of the tab that is being affected
 545   * @param string $page The name of the page being affected (optional - if not specified, will affect everything under the specified tab)
 546   * @param integer $default Default permissions for the page (1 for allowed - 0 for disallowed - -1 to remove)
 547   */
 548  function change_admin_permission($tab, $page="", $default=1)
 549  {
 550      global $db;
 551  
 552      $query = $db->simple_select("adminoptions", "uid, permissions", "permissions != ''");
 553      while($adminoption = $db->fetch_array($query))
 554      {
 555          $adminoption['permissions'] = my_unserialize($adminoption['permissions']);
 556  
 557          if($default == -1)
 558          {
 559              if(!empty($page))
 560              {
 561                  unset($adminoption['permissions'][$tab][$page]);
 562              }
 563              else
 564              {
 565                  unset($adminoption['permissions'][$tab]);
 566              }
 567          }
 568          else
 569          {
 570              if(!empty($page))
 571              {
 572                  if($adminoption['uid'] == 0)
 573                  {
 574                      $adminoption['permissions'][$tab][$page] = 0;
 575                  }
 576                  else
 577                  {
 578                      $adminoption['permissions'][$tab][$page] = $default;
 579                  }
 580              }
 581              else
 582              {
 583                  if($adminoption['uid'] == 0)
 584                  {
 585                      $adminoption['permissions'][$tab]['tab'] = 0;
 586                  }
 587                  else
 588                  {
 589                      $adminoption['permissions'][$tab]['tab'] = $default;
 590                  }
 591              }
 592          }
 593  
 594          $db->update_query("adminoptions", array('permissions' => $db->escape_string(my_serialize($adminoption['permissions']))), "uid='{$adminoption['uid']}'");
 595      }
 596  }
 597  
 598  /**
 599   * Checks if we have had too many attempts at logging into the ACP
 600   *
 601   * @param integer $uid The uid of the admin to check
 602   * @param boolean $return_num Return an array of the number of attempts and expiry time? (default false)
 603   * @return mixed Return an array if the second parameter is true, boolean otherwise.
 604   */
 605  function login_attempt_check_acp($uid=0, $return_num=false)
 606  {
 607      global $db, $mybb;
 608  
 609      $attempts['loginattempts'] = 0;
 610  
 611      if($uid > 0)
 612      {
 613          $query = $db->simple_select("adminoptions", "loginattempts, loginlockoutexpiry", "uid='".(int)$uid."'", 1);
 614          $attempts = $db->fetch_array($query);
 615  
 616          if(!$attempts)
 617          {
 618              return false;
 619          }
 620      }
 621  
 622      if($attempts['loginattempts'] <= 0)
 623      {
 624          return false;
 625      }
 626  
 627      if($mybb->settings['maxloginattempts'] > 0 && $attempts['loginattempts'] >= $mybb->settings['maxloginattempts'])
 628      {
 629          // Has the expiry dateline been set yet?
 630          if($attempts['loginlockoutexpiry'] == 0 && $return_num == false)
 631          {
 632              $db->update_query("adminoptions", array("loginlockoutexpiry" => TIME_NOW+((int)$mybb->settings['loginattemptstimeout']*60)), "uid='".(int)$uid."'");
 633          }
 634  
 635          // Are we returning the # of login attempts?
 636          if($return_num == true)
 637          {
 638              return $attempts;
 639          }
 640          // Otherwise are we still locked out?
 641          else if($attempts['loginlockoutexpiry'] > TIME_NOW)
 642          {
 643              return true;
 644          }
 645      }
 646  
 647      return false;
 648  }
 649  
 650  /**
 651   * Checks whether the administrator is on a mobile device
 652   *
 653   * @param string $useragent The useragent to be checked
 654   * @return boolean A true/false depending on if the administrator is on a mobile
 655   */
 656  function is_mobile($useragent)
 657  {
 658      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);
 659  }
 660  
 661  /**
 662   * Checks whether there are any 'security' issues in templates via complex syntax
 663   *
 664   * @param string $template The template to be scanned
 665   * @return boolean A true/false depending on if an issue was detected
 666   */
 667  function check_template($template)
 668  {
 669      // Check to see if our database password is in the template
 670      if(preg_match('#\$config\[(([\'|"]database[\'|"])|([^\'"].*?))\]\[(([\'|"](database|hostname|password|table_prefix|username)[\'|"])|([^\'"].*?))\]#i', $template) !== 0)
 671      {
 672          return true;
 673      }
 674  
 675      // System calls via backtick
 676      if(preg_match('#\$\s*\{#', $template) !== 0)
 677      {
 678          return true;
 679      }
 680  
 681      // Any other malicious acts?
 682      // Courtesy of ZiNgA BuRgA
 683      $allowed = 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);
 684      if($allowed === null || preg_match("~\\{\\$.+?\\}~s", $allowed) !== 0)
 685      {
 686          return true;
 687      }
 688  
 689      return false;
 690  }
 691  
 692  /**
 693   * Provides a function to entirely delete a user's posts, and find the threads attached to them
 694   *
 695   * @param integer $uid The uid of the user
 696   * @param int $date A UNIX timestamp to delete posts that are older
 697   * @return array An array of threads to delete, threads/forums to recount
 698   */
 699  function delete_user_posts($uid, $date)
 700  {
 701      global $db;
 702      $uid = (int)$uid;
 703  
 704      // Build an array of posts to delete
 705      $postcache = array();
 706      $query = $db->simple_select("posts", "pid", "uid = '".$uid."' AND dateline < '".$date."'");
 707      while($post = $db->fetch_array($query))
 708      {
 709          $postcache[] = $post['pid'];
 710      }
 711  
 712      if(!$db->num_rows($query))
 713      {
 714          return false;
 715      }
 716      elseif(!empty($postcache))
 717      {
 718          // Let's start deleting posts
 719          $user_posts = implode(",", $postcache);
 720          $query = $db->query("
 721              SELECT p.pid, p.visible, f.usepostcounts, t.tid AS thread, t.firstpost, t.fid AS forum
 722              FROM ".TABLE_PREFIX."posts p
 723              LEFT JOIN ".TABLE_PREFIX."forums f ON (f.fid=p.fid)
 724              LEFT JOIN ".TABLE_PREFIX."threads t ON (t.tid=p.tid)
 725              WHERE p.pid IN ({$user_posts})
 726          ");
 727  
 728          $post_count = 0; // Collect the post number to deduct from the user's postcount
 729          $thread_list = array();
 730          $forum_list = array();
 731          $delete_thread_list = array();
 732          if(!$db->num_rows($query))
 733          {
 734              return false;
 735          }
 736          else
 737          {
 738              while($post = $db->fetch_array($query))
 739              {
 740                  if($post['usepostcounts'] != 0 && $post['visible'] == 1)
 741                  {
 742                      ++$post_count;
 743                  }
 744  
 745                  if($post['pid'] == $post['firstpost'])
 746                  {
 747                      $delete_thread_list[] = $post['thread'];
 748                  }
 749  
 750                  if(!in_array($post['thread'], $thread_list) && !in_array($post['thread'], $delete_thread_list))
 751                  {
 752                      $thread_list[] = $post['thread']; // Threads that have been affected by this action, that aren't marked to be deleted
 753                  }
 754                  if(!in_array($post['forum'], $forum_list))
 755                  {
 756                      $forum_list[] = $post['forum']; // Forums that have been affected, too
 757                  }
 758  
 759                  // Remove the attachments to this post, then delete the post
 760                  remove_attachments($post['pid']);
 761                  $db->delete_query("posts", "pid = '".$post['pid']."'");
 762                  $db->delete_query("pollvotes", "pid = '".$post['pid']."'"); // Delete pollvotes attached to this post
 763              }
 764  
 765              $db->update_query("users", array("postnum" => "postnum-".$post_count.""), "uid='".$uid."'", 1, true);
 766  
 767              $to_return = array(
 768                  'to_delete' => $delete_thread_list,
 769                  'thread_update' => $thread_list,
 770                  'forum_update' => $forum_list
 771              );
 772  
 773              return $to_return;
 774          }
 775      }
 776  }
 777  
 778  /**
 779   * Prints a selection JavaScript code for selectable groups/forums fields.
 780   */
 781  function print_selection_javascript()
 782  {
 783      static $already_printed = false;
 784  
 785      if($already_printed)
 786      {
 787          return;
 788      }
 789  
 790      $already_printed = true;
 791  
 792      echo "<script type=\"text/javascript\">
 793  	function checkAction(id)
 794      {
 795          var checked = '';
 796  
 797          $('.'+id+'_forums_groups_check').each(function(e, val)
 798          {
 799              if($(this).prop('checked') == true)
 800              {
 801                  checked = $(this).val();
 802              }
 803          });
 804  
 805          $('.'+id+'_forums_groups').each(function(e)
 806          {
 807              $(this).hide();
 808          });
 809  
 810          if($('#'+id+'_forums_groups_'+checked))
 811          {
 812              $('#'+id+'_forums_groups_'+checked).show();
 813          }
 814      }
 815  </script>";
 816  }
 817  
 818  if(!function_exists('array_column'))
 819  {
 820  	function array_column($input, $column_key)
 821      {
 822          $values = array();
 823  
 824          if(!is_array($input))
 825          {
 826              $input = array($input);
 827          }
 828  
 829          foreach($input as $val)
 830          {
 831              if(is_array($val) && isset($val[$column_key]))
 832              {
 833                  $values[] = $val[$column_key];
 834              }
 835              elseif(is_object($val) && isset($val->$column_key))
 836              {
 837                  $values[] = $val->$column_key;
 838              }
 839          }
 840  
 841          return $values;
 842      }
 843  }
 844  
 845  /**
 846   * Output the auto redirect block.
 847   *
 848   * @param \Form $form An existing form instance to wrap the redirect within.
 849   * @param string $prompt The prompt to show.
 850   */
 851  function output_auto_redirect($form, $prompt)
 852  {
 853      global $lang;
 854  
 855      echo <<<HTML
 856  <div class="confirm_action">
 857      <p>{$prompt}</p>
 858      <br />
 859      <script type="text/javascript">
 860          $(function() { 
 861              var button = $("#proceed_button"); 
 862              if (button.length > 0) {
 863                  // create a temporary div element to render the text within, un-escaping HTML entities
 864                  var textElement = $('<div/>').html('{$lang->automatically_redirecting}');
 865              
 866                  button.val(textElement.text());
 867                  button.attr("disabled", true);
 868                  button.css("color", "#aaa");
 869                  button.css("borderColor", "#aaa");
 870                  
 871                  var parent_form = button.closest('form');
 872  
 873                  if (parent_form.length > 0) {
 874                      parent_form.submit();
 875                  }
 876              }
 877          });
 878      </script>
 879      <p class="buttons">
 880          {$form->generate_submit_button($lang->proceed, array('class' => 'button_yes', 'id' => 'proceed_button'))}
 881      </p>
 882  </div>
 883  HTML;
 884  }


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