pokemons

pokemon.inc

  1. <?php
  2. // vim:filetype=php expandtab tabstop=2 softtabstop=2 shiftwidth=2 autoindent smartindent
  3.  
  4. function tribune_pokemon_info() {
  5.   return array(
  6.     'description' => t('Automatically gives a random username to anonymous users.'),
  7.     'weight' => 10,
  8.   );
  9. }
  10.  
  11. function tribune_pokemon_filter(&$post, &$help) {
  12.   global $user;
  13.  
  14.   if (!$user->uid and $post) {
  15.     if (!tribune_variable_get('tribune_pokemon_allow_custom_name', true) or !isset($_SESSION['tribune_nickname'])) {
  16.       if (!isset($_SESSION['tribune_pokemon'])) {
  17.         $_SESSION['tribune_pokemon'] = tribune_pokemon_random_pokemon();
  18.       }
  19.  
  20.       $post['info'] = $_SESSION['tribune_pokemon'];
  21.     }
  22.   }
  23. }
  24.  
  25. function tribune_pokemon_settings() {
  26.   global $tribune_pokemon_default_pokemons;
  27.   $form = array();
  28.  
  29.   $form['tribune_pokemon_allow_custom_name'] = array(
  30.     '#type' => "checkbox",
  31.     '#title' => t("Allow users to choose their name (with the \"nick\" filter)"),
  32.     '#default_value' => tribune_variable_get('tribune_pokemon_allow_custom_name', true),
  33.   );
  34.  
  35.   $form['tribune_pokemon_names'] = array(
  36.     '#type' => "textarea",
  37.     '#title' => t("Available names"),
  38.     '#default_value' => tribune_variable_get('tribune_pokemon_names', $tribune_pokemon_default_pokemons),
  39.     '#description' => t("One name per line"),
  40.   );
  41.  
  42.   return tribune_settings_form($form);
  43. }
  44.  
  45. function tribune_pokemon_random_pokemon() {
  46.   global $tribune_pokemon_default_pokemons;
  47.   $pokemons = explode("\n", trim(tribune_variable_get('tribune_pokemon_names', $tribune_pokemon_default_pokemons)));
  48.   $pokemon = $pokemons[rand(0, count($pokemons) - 1)];
  49.   return trim($pokemon);
  50. }
  51.  
  52. $tribune_pokemon_default_pokemons = <<<EOT
  53. <|!REG3XP0!>Blue
  54. Red
  55. Yellow
  56. Green
  57. Amber
  58. Azure
  59. Carmine
  60. Cerise
  61. Cyan
  62. Emerald
  63. Fuchsia
  64. Gray
  65. Indigo
  66. Ivory
  67. Jade
  68. Lavender
  69. Lilac
  70. Magenta
  71. Mauve
  72. Olive
  73. Orange
  74. Peach
  75. Purple
  76. Saffron
  77. Sepia
  78. Teal|>
  79. EOT;
  80.