MyBB Community Forums

Full Version: generate_submit_button(); Function
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3 4 5
I think you cannot:
  12  /**
  13   * Logs an administrator action taking any arguments as log data.
  14   */
  15  function log_admin_action()
  16  {
  17      global $db, $mybb;
  18  
  19      $data = func_get_args();
  20  
  21      if(count($data) == 1 && is_array($data[0]))
  22      {
  23          $data = $data[0];
  24      }
  25  
  26      if(!is_array($data))
  27      {
  28          $data = array($data);
  29      }
  30  
  31      $log_entry = array(
  32          "uid" => $mybb->user['uid'],
  33          "ipaddress" => $db->escape_string(get_ip()),
  34          "dateline" => TIME_NOW,
  35          "module" => $db->escape_string($mybb->input['module']),
  36          "action" => $db->escape_string($mybb->input['action']),
  37          "data" => $db->escape_string(@serialize($data))
  38      );
  39  
  40      $db->insert_query("adminlog", $log_entry);
  41  }

Unless you replicate what the function does but I'm not sure about that.
I'm fairly certain he can.

309  function get_admin_log_action($logitem)
 310  {
 311      global $lang, $plugins, $mybb;
 312      
 313      $logitem['module'] = str_replace('/', '-', $logitem['module']);
 314      list($module, $action) = explode('-', $logitem['module']);
 315      $lang_string = 'admin_log_'.$module.'_'.$action.'_'.$logitem['action'];
 316      
 317      // Specific page overrides
 318      switch($lang_string)
 319      {
 320          // == CONFIG ==
 321          case 'admin_log_config_banning_add': // Banning IP/Username/Email
 322          case 'admin_log_config_banning_delete': // Removing banned IP/username/emails
 323              switch($logitem['data'][2])
 324              {
 325                  case 1:
 326                      $lang_string = 'admin_log_config_banning_'.$logitem['action'].'_ip';
 327                      break;
 328                  case 2: 
 329                      $lang_string = 'admin_log_config_banning_'.$logitem['action'].'_username';
 330                      break;
 331                  case 3:
 332                      $lang_string = 'admin_log_config_banning_'.$logitem['action'].'_email';
 333                      break;
 334              }
 335              break;
 336          
 337          case 'admin_log_config_help_documents_add': // Help documents and sections
 338          case 'admin_log_config_help_documents_edit':
 339          case 'admin_log_config_help_documents_delete':
 340              $lang_string .= "_{$logitem['data'][2]}"; // adds _section or _document
 341              break;
 342              
 343          case 'admin_log_config_languages_edit': // Editing language variables
 344              $logitem['data'][1] = basename($logitem['data'][1]);
 345              if($logitem['data'][2] == 1)
 346              {
 347                  $lang_string = 'admin_log_config_languages_edit_admin';
 348              }
 349              break;
 350              
 351          case 'admin_log_config_mycode_toggle_status': // Custom MyCode toggle activation
 352              if($logitem['data'][2] == 1)
 353              {
 354                  $lang_string .= '_enabled';
 355              }
 356              else
 357              {
 358                  $lang_string .= '_disabled';
 359              }
 360              break;
 361          case 'admin_log_config_plugins_activate': // Installing plugin
 362              if($logitem['data'][1])
 363              {
 364                  $lang_string .= '_install';
 365              }
 366              break;
 367          case 'admin_log_config_plugins_deactivate': // Uninstalling plugin
 368              if($logitem['data'][1])
 369              {
 370                  $lang_string .= '_uninstall';
 371              }
 372              break;
 373          // == FORUM ==
 374          case 'admin_log_forum_attachments_delete': // Deleting attachments
 375              if($logitem['data'][2])
 376              {
 377                  $lang_string .= '_post';
 378              }
 379              break;
 380          case 'admin_log_forum_management_copy': // Forum copy
 381              if($logitem['data'][4])
 382              {
 383                  $lang_string .= '_with_permissions';
 384              }
 385              break;
 386          case 'admin_log_forum_management_': // add mod, permissions, forum orders
 387              // first parameter already set with action
 388              $lang_string .= $logitem['data'][0];
 389              if($logitem['data'][0] == 'orders' && $logitem['data'][1])
 390              {
 391                  $lang_string .= '_sub'; // updating forum orders in a subforum 
 392              }
 393              break;
 394          case 'admin_log_forum_moderation_queue_': //moderation queue
 395              // first parameter already set with action
 396              $lang_string .= $logitem['data'][0];
 397              break;
 398          // == HOME ==
 399          // == STYLE ==
 400          case 'admin_log_style_templates_delete_template': // deleting templates
 401              // global template set
 402              if($logitem['data'][2] == -1)
 403              {
 404                  $lang_string .= '_global';
 405              }
 406              break;
 407          case 'admin_log_style_templates_edit_template': // editing templates
 408              // global template set
 409              if($logitem['data'][2] == -1)
 410              {
 411                  $lang_string .= '_global';
 412              }
 413              break;
 414          // == TOOLS ==
 415          case 'admin_log_tools_adminlog_prune': // Admin Log Pruning
 416              if($logitem['data'][1] && !$logitem['data'][2])
 417              {
 418                  $lang_string = 'admin_log_tools_adminlog_prune_user';
 419              }
 420              elseif($logitem['data'][2] && !$logitem['data'][1])
 421              {
 422                  $lang_string = 'admin_log_tools_adminlog_prune_module';
 423              }
 424              elseif($logitem['data'][1] && $logitem['data'][2])
 425              {
 426                  $lang_string = 'admin_log_tools_adminlog_prune_user_module';
 427              }
 428              break;
 429          case 'admin_log_tools_modlog_prune': // Moderator Log Pruning
 430              if($logitem['data'][1] && !$logitem['data'][2])
 431              {
 432                  $lang_string = 'admin_log_tools_modlog_prune_user';
 433              }
 434              elseif($logitem['data'][2] && !$logitem['data'][1])
 435              {
 436                  $lang_string = 'admin_log_tools_modlog_prune_forum';
 437              }
 438              elseif($logitem['data'][1] && $logitem['data'][2])
 439              {
 440                  $lang_string = 'admin_log_tools_modlog_prune_user_forum';
 441              }
 442              break;
 443          case 'admin_log_tools_backupdb_backup': // Create backup
 444              if($logitem['data'][0] == 'download')
 445              {
 446                  $lang_string = 'admin_log_tools_backupdb_backup_download';
 447              }
 448              break;
 449          case 'admin_log_tools_optimizedb_': // Optimize DB
 450              $logitem['data'][0] = @implode(', ', unserialize($logitem['data'][0]));
 451              break;
 452          case 'admin_log_tools_recount_rebuild_': // Recount and rebuild
 453              $detail_lang_string = $lang_string.$logitem['data'][0];
 454              if(isset($lang->$detail_lang_string))
 455              {
 456                  $lang_string = $detail_lang_string;
 457              }
 458              break;
 459          // == USERS ==
 460          case 'admin_log_user_admin_permissions_edit': // default/group/user admin permissions
 461              if($logitem['data'][0] > 0)
 462              {
 463                  // User
 464                  $lang_string .= '_user';
 465              }
 466              elseif($logitem['data'][0] < 0)
 467              {
 468                  // Group
 469                  $logitem['data'][0] = abs($logitem['data'][0]);
 470                  $lang_string .= '_group';
 471              }
 472              break;
 473          case 'admin_log_user_banning_': // banning
 474              if($logitem['data'][2] == 0)
 475              {
 476                  $lang_string = 'admin_log_user_banning_add_permanent';
 477              }
 478              else
 479              {
 480                  $logitem['data'][2] = my_date($mybb->settings['dateformat'], $logitem['data'][2]);
 481                  $lang_string = 'admin_log_user_banning_add_temporary';
 482              }
 483              break;
 484          case 'admin_log_user_users_inline_banned':
 485              if($logitem['data'][1] == 0)
 486              {
 487                  $lang_string = 'admin_log_user_users_inline_banned_perm';
 488              }
 489              else
 490              {
 491                  $logitem['data'][1] = my_date($mybb->settings['dateformat'], $logitem['data'][1]);
 492                  $lang_string = 'admin_log_user_users_inline_banned_temp';
 493              }
 494              break;
 495      }
 496      
 497      $plugin_array = array('logitem' => &$logitem, 'lang_string' => &$lang_string);
 498      $plugins->run_hooks("admin_tools_get_admin_log_action", $plugin_array);
 499      
 500      if(isset($lang->$lang_string))
 501      {
 502          array_unshift($logitem['data'], $lang->$lang_string); // First parameter for sprintf is the format string
 503          $string = call_user_func_array(array($lang, 'sprintf'), $logitem['data']);
 504          if(!$string)
 505          {
 506              $string = $lang->$lang_string; // Fall back to the one in the language pack
 507          }
 508      }
 509      else
 510      {
 511          // Build a default string
 512          $string = $logitem['module'].' - '.$logitem['action'];
 513          if(is_array($logitem['data']) && count($logitem['data']) > 0)
 514          {
 515              $string .= '('.implode(', ', $logitem['data']).')';
 516          }
 517      }
 518      return $string;
 519  }

Look at the hook there, you'll need to use that.
Thanks guys! A little problem I ran into:

The code Jammer provided worked perfectly: (preg_match('/^\d+$/', $negative_rec_post))

However when I try to enter 0 for only ONE text field, how can I do that?

Thanks Smile
What do you mean, entering 0 should work.
I'm using:

						if((!empty($mybb->input['positive_rec_uid'])) && (!empty($mybb->input['positive_from_uid'])) && (!empty($mybb->input['positive_rec_post'])) && (!empty($mybb->input['positive_rec_amount'])) && (!empty($mybb->input['positive_unix_time'])) && (!empty($mybb->input['positive_rec_comment'])) && (preg_match('/^\d+$/', $positive_rec_uid)) && (preg_match('/^\d+$/', $positive_from_uid)) && (preg_match('/^\d+$/', $positive_rec_post)) && (preg_match('/^\d+$/', $positive_rec_amount)) && (preg_match('/^\d+$/', $positive_unix_time)) && ($mybb->request_method == "post")){
				$db->query("INSERT INTO `".TABLE_PREFIX."reputation` VALUES (NULL, '$positive_rec_uid', '$positive_from_uid', '$positive_rec_post', '$positive_rec_amount', '$positive_unix_time', '$positive_rec_comment')");
			    flash_message("Positive Reputation has been successfully added.", 'success');
			    admin_redirect('index.php?module=tools-easyrep');
			}
			elseif($mybb->request_method == "post"){
				flash_message("You've missed a field or entered text in an interger field. Please correct these before attempting to add reputation.", 'error');
				admin_redirect('index.php?module=tools-easyrep&amp;action=addpositive');
				die();
			}

When I enter just 0, it gives the error.

Cheers Smile
Oh, IIRC empty(); returns true if the value is "0". Try something like:
if(!empty($strign) || $strign == '0')
{
// good
}
else
{
//error
}
Thanks Omar, works perfectly now! Smile

(2012-07-23, 06:01 PM)Jammerx2 Wrote: [ -> ]I'm fairly certain he can.

309  function get_admin_log_action($logitem)
 310  {
 311      global $lang, $plugins, $mybb;
 312      
 313      $logitem['module'] = str_replace('/', '-', $logitem['module']);
 314      list($module, $action) = explode('-', $logitem['module']);
 315      $lang_string = 'admin_log_'.$module.'_'.$action.'_'.$logitem['action'];
 316      
 317      // Specific page overrides
 318      switch($lang_string)
 319      {
 320          // == CONFIG ==
 321          case 'admin_log_config_banning_add': // Banning IP/Username/Email
 322          case 'admin_log_config_banning_delete': // Removing banned IP/username/emails
 323              switch($logitem['data'][2])
 324              {
 325                  case 1:
 326                      $lang_string = 'admin_log_config_banning_'.$logitem['action'].'_ip';
 327                      break;
 328                  case 2: 
 329                      $lang_string = 'admin_log_config_banning_'.$logitem['action'].'_username';
 330                      break;
 331                  case 3:
 332                      $lang_string = 'admin_log_config_banning_'.$logitem['action'].'_email';
 333                      break;
 334              }
 335              break;
 336          
 337          case 'admin_log_config_help_documents_add': // Help documents and sections
 338          case 'admin_log_config_help_documents_edit':
 339          case 'admin_log_config_help_documents_delete':
 340              $lang_string .= "_{$logitem['data'][2]}"; // adds _section or _document
 341              break;
 342              
 343          case 'admin_log_config_languages_edit': // Editing language variables
 344              $logitem['data'][1] = basename($logitem['data'][1]);
 345              if($logitem['data'][2] == 1)
 346              {
 347                  $lang_string = 'admin_log_config_languages_edit_admin';
 348              }
 349              break;
 350              
 351          case 'admin_log_config_mycode_toggle_status': // Custom MyCode toggle activation
 352              if($logitem['data'][2] == 1)
 353              {
 354                  $lang_string .= '_enabled';
 355              }
 356              else
 357              {
 358                  $lang_string .= '_disabled';
 359              }
 360              break;
 361          case 'admin_log_config_plugins_activate': // Installing plugin
 362              if($logitem['data'][1])
 363              {
 364                  $lang_string .= '_install';
 365              }
 366              break;
 367          case 'admin_log_config_plugins_deactivate': // Uninstalling plugin
 368              if($logitem['data'][1])
 369              {
 370                  $lang_string .= '_uninstall';
 371              }
 372              break;
 373          // == FORUM ==
 374          case 'admin_log_forum_attachments_delete': // Deleting attachments
 375              if($logitem['data'][2])
 376              {
 377                  $lang_string .= '_post';
 378              }
 379              break;
 380          case 'admin_log_forum_management_copy': // Forum copy
 381              if($logitem['data'][4])
 382              {
 383                  $lang_string .= '_with_permissions';
 384              }
 385              break;
 386          case 'admin_log_forum_management_': // add mod, permissions, forum orders
 387              // first parameter already set with action
 388              $lang_string .= $logitem['data'][0];
 389              if($logitem['data'][0] == 'orders' && $logitem['data'][1])
 390              {
 391                  $lang_string .= '_sub'; // updating forum orders in a subforum 
 392              }
 393              break;
 394          case 'admin_log_forum_moderation_queue_': //moderation queue
 395              // first parameter already set with action
 396              $lang_string .= $logitem['data'][0];
 397              break;
 398          // == HOME ==
 399          // == STYLE ==
 400          case 'admin_log_style_templates_delete_template': // deleting templates
 401              // global template set
 402              if($logitem['data'][2] == -1)
 403              {
 404                  $lang_string .= '_global';
 405              }
 406              break;
 407          case 'admin_log_style_templates_edit_template': // editing templates
 408              // global template set
 409              if($logitem['data'][2] == -1)
 410              {
 411                  $lang_string .= '_global';
 412              }
 413              break;
 414          // == TOOLS ==
 415          case 'admin_log_tools_adminlog_prune': // Admin Log Pruning
 416              if($logitem['data'][1] && !$logitem['data'][2])
 417              {
 418                  $lang_string = 'admin_log_tools_adminlog_prune_user';
 419              }
 420              elseif($logitem['data'][2] && !$logitem['data'][1])
 421              {
 422                  $lang_string = 'admin_log_tools_adminlog_prune_module';
 423              }
 424              elseif($logitem['data'][1] && $logitem['data'][2])
 425              {
 426                  $lang_string = 'admin_log_tools_adminlog_prune_user_module';
 427              }
 428              break;
 429          case 'admin_log_tools_modlog_prune': // Moderator Log Pruning
 430              if($logitem['data'][1] && !$logitem['data'][2])
 431              {
 432                  $lang_string = 'admin_log_tools_modlog_prune_user';
 433              }
 434              elseif($logitem['data'][2] && !$logitem['data'][1])
 435              {
 436                  $lang_string = 'admin_log_tools_modlog_prune_forum';
 437              }
 438              elseif($logitem['data'][1] && $logitem['data'][2])
 439              {
 440                  $lang_string = 'admin_log_tools_modlog_prune_user_forum';
 441              }
 442              break;
 443          case 'admin_log_tools_backupdb_backup': // Create backup
 444              if($logitem['data'][0] == 'download')
 445              {
 446                  $lang_string = 'admin_log_tools_backupdb_backup_download';
 447              }
 448              break;
 449          case 'admin_log_tools_optimizedb_': // Optimize DB
 450              $logitem['data'][0] = @implode(', ', unserialize($logitem['data'][0]));
 451              break;
 452          case 'admin_log_tools_recount_rebuild_': // Recount and rebuild
 453              $detail_lang_string = $lang_string.$logitem['data'][0];
 454              if(isset($lang->$detail_lang_string))
 455              {
 456                  $lang_string = $detail_lang_string;
 457              }
 458              break;
 459          // == USERS ==
 460          case 'admin_log_user_admin_permissions_edit': // default/group/user admin permissions
 461              if($logitem['data'][0] > 0)
 462              {
 463                  // User
 464                  $lang_string .= '_user';
 465              }
 466              elseif($logitem['data'][0] < 0)
 467              {
 468                  // Group
 469                  $logitem['data'][0] = abs($logitem['data'][0]);
 470                  $lang_string .= '_group';
 471              }
 472              break;
 473          case 'admin_log_user_banning_': // banning
 474              if($logitem['data'][2] == 0)
 475              {
 476                  $lang_string = 'admin_log_user_banning_add_permanent';
 477              }
 478              else
 479              {
 480                  $logitem['data'][2] = my_date($mybb->settings['dateformat'], $logitem['data'][2]);
 481                  $lang_string = 'admin_log_user_banning_add_temporary';
 482              }
 483              break;
 484          case 'admin_log_user_users_inline_banned':
 485              if($logitem['data'][1] == 0)
 486              {
 487                  $lang_string = 'admin_log_user_users_inline_banned_perm';
 488              }
 489              else
 490              {
 491                  $logitem['data'][1] = my_date($mybb->settings['dateformat'], $logitem['data'][1]);
 492                  $lang_string = 'admin_log_user_users_inline_banned_temp';
 493              }
 494              break;
 495      }
 496      
 497      $plugin_array = array('logitem' => &$logitem, 'lang_string' => &$lang_string);
 498      $plugins->run_hooks("admin_tools_get_admin_log_action", $plugin_array);
 499      
 500      if(isset($lang->$lang_string))
 501      {
 502          array_unshift($logitem['data'], $lang->$lang_string); // First parameter for sprintf is the format string
 503          $string = call_user_func_array(array($lang, 'sprintf'), $logitem['data']);
 504          if(!$string)
 505          {
 506              $string = $lang->$lang_string; // Fall back to the one in the language pack
 507          }
 508      }
 509      else
 510      {
 511          // Build a default string
 512          $string = $logitem['module'].' - '.$logitem['action'];
 513          if(is_array($logitem['data']) && count($logitem['data']) > 0)
 514          {
 515              $string .= '('.implode(', ', $logitem['data']).')';
 516          }
 517      }
 518      return $string;
 519  }

Look at the hook there, you'll need to use that.

How would I edit this so that it shows as the plugin name, not tools-easyrep ?

Thanks Smile
Pages: 1 2 3 4 5