[ Index ]

PHP Cross Reference of MyBB 1.8.38

title

Body

[close]

/admin/modules/config/ -> spiders.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  // Disallow direct access to this file for security reasons
  12  if(!defined("IN_MYBB"))
  13  {
  14      die("Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined.");
  15  }
  16  
  17  $page->add_breadcrumb_item($lang->spiders_bots, "index.php?module=config-spiders");
  18  
  19  $plugins->run_hooks("admin_config_spiders_begin");
  20  
  21  if($mybb->input['action'] == "add")
  22  {
  23      $plugins->run_hooks("admin_config_spiders_add");
  24  
  25      if($mybb->request_method == "post")
  26      {
  27          if(!trim($mybb->input['name']))
  28          {
  29              $errors[] = $lang->error_missing_name;
  30          }
  31  
  32          if(!trim($mybb->input['useragent']))
  33          {
  34              $errors[] = $lang->error_missing_agent;
  35          }
  36  
  37          if(!$errors)
  38          {
  39              $new_spider = array(
  40                  "name" => $db->escape_string($mybb->input['name']),
  41                  "theme" => $mybb->get_input('theme', MyBB::INPUT_INT),
  42                  "language" => $db->escape_string($mybb->input['language']),
  43                  "usergroup" => $mybb->get_input('usergroup', MyBB::INPUT_INT),
  44                  "useragent" => $db->escape_string($mybb->input['useragent']),
  45                  "lastvisit" => 0
  46              );
  47              $sid = $db->insert_query("spiders", $new_spider);
  48  
  49              $plugins->run_hooks("admin_config_spiders_add_commit");
  50  
  51              $cache->update_spiders();
  52  
  53              // Log admin action
  54              log_admin_action($sid, $mybb->input['name']);
  55  
  56              flash_message($lang->success_bot_created, 'success');
  57              admin_redirect("index.php?module=config-spiders");
  58          }
  59      }
  60  
  61      $page->add_breadcrumb_item($lang->add_new_bot);
  62      $page->output_header($lang->spiders_bots." - ".$lang->add_new_bot);
  63  
  64      $sub_tabs['spiders'] = array(
  65          'title' => $lang->spiders_bots,
  66          'link' => "index.php?module=config-spiders",
  67      );
  68      $sub_tabs['add_spider'] = array(
  69          'title' => $lang->add_new_bot,
  70          'link' => "index.php?module=config-spiders&amp;action=add",
  71          'description' => $lang->add_new_bot_desc
  72      );
  73  
  74      $page->output_nav_tabs($sub_tabs, "add_spider");
  75  
  76      $form = new Form("index.php?module=config-spiders&amp;action=add", "post");
  77  
  78      if($errors)
  79      {
  80          $page->output_inline_error($errors);
  81      }
  82  
  83      $form_container = new FormContainer($lang->add_new_bot);
  84      $form_container->output_row($lang->name." <em>*</em>", $lang->name_desc, $form->generate_text_box('name', $mybb->get_input('name'), array('id' => 'name')), 'name');
  85      $form_container->output_row($lang->user_agent." <em>*</em>", $lang->user_agent_desc, $form->generate_text_box('useragent', $mybb->get_input('useragent'), array('id' => 'useragent')), 'useragent');
  86  
  87      $languages = array('' => $lang->use_board_default);
  88      $languages = array_merge($languages, $lang->get_languages());
  89      $form_container->output_row($lang->language_str, $lang->language_desc, $form->generate_select_box("language", $languages, $mybb->get_input('language'), array("id" => "language")), 'language');
  90  
  91      $form_container->output_row($lang->theme, $lang->theme_desc, build_theme_select("theme", $mybb->get_input('theme'), 0, "", true, false, true));
  92  
  93      $query = $db->simple_select("usergroups", "*", "", array("order_by" => "title", "order_dir" => "asc"));
  94  
  95      $usergroups = array();
  96      while($usergroup = $db->fetch_array($query))
  97      {
  98          $usergroups[$usergroup['gid']] = $usergroup['title'];
  99      }
 100      if(!$mybb->get_input('usergroup'))
 101      {
 102          $mybb->input['usergroup'] = 1;
 103      }
 104      $form_container->output_row($lang->user_group, $lang->user_group_desc, $form->generate_select_box("usergroup", $usergroups, $mybb->input['usergroup'], array("id" => "usergroup")), 'usergroup');
 105  
 106  
 107      $form_container->end();
 108      $buttons[] = $form->generate_submit_button($lang->save_bot);
 109      $form->output_submit_wrapper($buttons);
 110      $form->end();
 111  
 112      $page->output_footer();
 113  }
 114  
 115  if($mybb->input['action'] == "delete")
 116  {
 117      $query = $db->simple_select("spiders", "*", "sid='".$mybb->get_input('sid', MyBB::INPUT_INT)."'");
 118      $spider = $db->fetch_array($query);
 119  
 120      // Does the spider not exist?
 121      if(!$spider)
 122      {
 123          flash_message($lang->error_invalid_bot, 'error');
 124          admin_redirect("index.php?module=config-spiders");
 125      }
 126  
 127      // User clicked no
 128      if($mybb->get_input('no'))
 129      {
 130          admin_redirect("index.php?module=config-spiders");
 131      }
 132  
 133      $plugins->run_hooks("admin_config_spiders_delete");
 134  
 135      if($mybb->request_method == "post")
 136      {
 137          // Delete the spider
 138          $db->delete_query("spiders", "sid='{$spider['sid']}'");
 139  
 140          $plugins->run_hooks("admin_config_spiders_delete_commit");
 141  
 142          $cache->update_spiders();
 143  
 144          // Log admin action
 145          log_admin_action($spider['sid'], $spider['name']);
 146  
 147          flash_message($lang->success_bot_deleted, 'success');
 148          admin_redirect("index.php?module=config-spiders");
 149      }
 150      else
 151      {
 152          $page->output_confirm_action("index.php?module=config-spiders&action=delete&sid={$spider['sid']}", $lang->confirm_bot_deletion);
 153      }
 154  }
 155  
 156  if($mybb->input['action'] == "edit")
 157  {
 158      $query = $db->simple_select("spiders", "*", "sid='".$mybb->get_input('sid', MyBB::INPUT_INT)."'");
 159      $spider = $db->fetch_array($query);
 160  
 161      // Does the spider not exist?
 162      if(!$spider)
 163      {
 164          flash_message($lang->error_invalid_bot, 'error');
 165          admin_redirect("index.php?module=config-spiders");
 166      }
 167  
 168      $plugins->run_hooks("admin_config_spiders_edit");
 169  
 170      if($mybb->request_method == "post")
 171      {
 172          if(!trim($mybb->input['name']))
 173          {
 174              $errors[] = $lang->error_missing_name;
 175          }
 176  
 177          if(!trim($mybb->input['useragent']))
 178          {
 179              $errors[] = $lang->error_missing_agent;
 180          }
 181  
 182          if(!$errors)
 183          {
 184              $updated_spider = array(
 185                  "name" => $db->escape_string($mybb->input['name']),
 186                  "theme" => $mybb->get_input('theme', MyBB::INPUT_INT),
 187                  "language" => $db->escape_string($mybb->input['language']),
 188                  "usergroup" => $mybb->get_input('usergroup', MyBB::INPUT_INT),
 189                  "useragent" => $db->escape_string($mybb->input['useragent'])
 190              );
 191  
 192              $plugins->run_hooks("admin_config_spiders_edit_commit");
 193  
 194              $db->update_query("spiders", $updated_spider, "sid='{$spider['sid']}'");
 195  
 196              $cache->update_spiders();
 197  
 198              // Log admin action
 199              log_admin_action($spider['sid'], $mybb->input['name']);
 200  
 201              flash_message($lang->success_bot_updated, 'success');
 202              admin_redirect("index.php?module=config-spiders");
 203          }
 204      }
 205  
 206      $page->add_breadcrumb_item($lang->edit_bot);
 207      $page->output_header($lang->spiders_bots." - ".$lang->edit_bot);
 208  
 209      $sub_tabs['edit_spider'] = array(
 210          'title' => $lang->edit_bot,
 211          'link' => "index.php?module=config-spiders&amp;action=edit&amp;sid={$spider['sid']}",
 212          'description' => $lang->edit_bot_desc
 213      );
 214  
 215      $page->output_nav_tabs($sub_tabs, "edit_spider");
 216  
 217      $form = new Form("index.php?module=config-spiders&amp;action=edit&amp;sid={$spider['sid']}", "post");
 218  
 219      if($errors)
 220      {
 221          $page->output_inline_error($errors);
 222          $spider_data = $mybb->input;
 223      }
 224      else
 225      {
 226          $spider_data = $spider;
 227      }
 228  
 229      $form_container = new FormContainer($lang->edit_bot);
 230      $form_container->output_row($lang->name." <em>*</em>", $lang->name_desc, $form->generate_text_box('name', $spider_data['name'], array('id' => 'name')), 'name');
 231      $form_container->output_row($lang->user_agent." <em>*</em>", $lang->user_agent_desc, $form->generate_text_box('useragent', $spider_data['useragent'], array('id' => 'useragent')), 'useragent');
 232  
 233      $languages = array('' => $lang->use_board_default);
 234      $languages = array_merge($languages, $lang->get_languages());
 235      $form_container->output_row($lang->language_str, $lang->language_desc, $form->generate_select_box("language", $languages, $spider_data['language'], array("id" => "language")), 'language');
 236  
 237      $form_container->output_row($lang->theme, $lang->theme_desc, build_theme_select("theme", $spider_data['theme'], 0, "", true, false, true));
 238  
 239      $query = $db->simple_select("usergroups", "*", "", array("order_by" => "title", "order_dir" => "asc"));
 240      while($usergroup = $db->fetch_array($query))
 241      {
 242          $usergroups[$usergroup['gid']] = $usergroup['title'];
 243      }
 244      if(!$spider_data['usergroup'])
 245      {
 246          $spider_data['usergroup'] = 1;
 247      }
 248      $form_container->output_row($lang->user_group, $lang->user_group_desc, $form->generate_select_box("usergroup", $usergroups, $spider_data['usergroup'], array("id" => "usergroup")), 'usergroup');
 249  
 250      $form_container->end();
 251      $buttons[] = $form->generate_submit_button($lang->save_bot);
 252      $form->output_submit_wrapper($buttons);
 253      $form->end();
 254  
 255      $page->output_footer();
 256  }
 257  
 258  if(!$mybb->input['action'])
 259  {
 260      $plugins->run_hooks("admin_config_spiders_start");
 261  
 262      $page->output_header($lang->spiders_bots);
 263  
 264      $sub_tabs['spiders'] = array(
 265          'title' => $lang->spiders_bots,
 266          'link' => "index.php?module=config-spiders",
 267          'description' => $lang->spiders_bots_desc
 268      );
 269      $sub_tabs['add_spider'] = array(
 270          'title' => $lang->add_new_bot,
 271          'link' => "index.php?module=config-spiders&amp;action=add"
 272      );
 273  
 274      $page->output_nav_tabs($sub_tabs, "spiders");
 275  
 276      $query = $db->simple_select("spiders", "COUNT(sid) AS spiders");
 277      $total_rows = $db->fetch_field($query, "spiders");
 278  
 279      $pagenum = $mybb->get_input('page', MyBB::INPUT_INT);
 280      if($pagenum)
 281      {
 282          $start = ($pagenum - 1) * 20;
 283          $pages = ceil($total_rows / 20);
 284          if($pagenum > $pages)
 285          {
 286              $start = 0;
 287              $pagenum = 1;
 288          }
 289      }
 290      else
 291      {
 292          $start = 0;
 293          $pagenum = 1;
 294      }
 295  
 296      $table = new Table;
 297      $table->construct_header($lang->bot);
 298      $table->construct_header($lang->last_visit, array("class" => "align_center", "width" => 200));
 299      $table->construct_header($lang->controls, array("class" => "align_center", "width" => 150, "colspan" => 2));
 300  
 301      $query = $db->simple_select("spiders", "*", "", array('limit_start' => $start, 'limit' => 20, "order_by" => "lastvisit", "order_dir" => "desc"));
 302      while($spider = $db->fetch_array($query))
 303      {
 304          $lastvisit = $lang->never;
 305          $spider['name'] = htmlspecialchars_uni($spider['name']);
 306  
 307          if($spider['lastvisit'])
 308          {
 309              $lastvisit = my_date('relative', $spider['lastvisit']);
 310          }
 311  
 312          $table->construct_cell("<a href=\"index.php?module=config-spiders&amp;action=edit&amp;sid={$spider['sid']}\"><strong>{$spider['name']}</strong></a>");
 313          $table->construct_cell($lastvisit, array("class" => "align_center", "width" => 200));
 314          $table->construct_cell("<a href=\"index.php?module=config-spiders&amp;action=edit&amp;sid={$spider['sid']}\">{$lang->edit}</a>", array("class" => "align_center", "width" => 75));
 315          $table->construct_cell("<a href=\"index.php?module=config-spiders&amp;action=delete&amp;sid={$spider['sid']}&amp;my_post_key={$mybb->post_code}\" onclick=\"return AdminCP.deleteConfirmation(this, '{$lang->confirm_bot_deletion}');\">{$lang->delete}</a>", array("class" => "align_center", "width" => 75));
 316          $table->construct_row();
 317      }
 318  
 319      if($table->num_rows() == 0)
 320      {
 321          $table->construct_cell($lang->no_bots, array("colspan" => 4));
 322          $table->construct_row();
 323      }
 324  
 325      $table->output($lang->spiders_bots);
 326  
 327      echo "<br />".draw_admin_pagination($pagenum, "20", $total_rows, "index.php?module=config-spiders&amp;page={page}");
 328  
 329      $page->output_footer();
 330  }


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