[ Index ]

PHP Cross Reference of MyBB 1.6.5

title

Body

[close]

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

   1  <?php
   2  /**
   3   * MyBB 1.6
   4   * Copyright 2010 MyBB Group, All Rights Reserved
   5   *
   6   * Website: http://mybb.com
   7   * License: http://mybb.com/about/license
   8   *
   9   * $Id: class_page.php 5620 2011-09-26 18:23:52Z ralgith $
  10   */
  11  
  12  /*
  13   * MyBB Admin CP Page Generation Class
  14   */
  15  class DefaultPage
  16  {
  17  
  18      /**
  19       * @var string The current style in use.
  20       */
  21      public $style;
  22  
  23      /**
  24       * @var array The primary menu items.
  25       */
  26      public $menu = array();
  27  
  28      /**
  29       * @var string The side bar menu items.
  30       */
  31      public $submenu = '';
  32  
  33      /**
  34       * @var string The module we're currently in.
  35       */
  36      public $active_module;
  37  
  38      /**
  39       * @var string The action we're currently performing.
  40       */
  41      public $active_action;
  42      
  43      /**
  44       * @var string Content for the side bar of the page if we have one.
  45       */
  46      public $sidebar;
  47  
  48      /**
  49       * @var array The breadcrumb trail leading up to this page.
  50       */
  51      public $_breadcrumb_trail = array();
  52      
  53      /**
  54       * @var string Any additional information to add between the <head> tags.
  55       */
  56      public $extra_header = "";
  57  
  58      /**
  59       * Output the page header.
  60       *
  61       * @param string The title of the page.
  62       */
  63  	function output_header($title="")
  64      {
  65          global $mybb, $admin_session, $lang, $plugins;
  66          
  67          $plugins->run_hooks("admin_page_output_header");
  68          
  69          if(!$title)
  70          {
  71              $title = $lang->mybb_admin_panel;
  72          }
  73          
  74          $rtl = "";
  75          if($lang->settings['rtl'] == 1)
  76          {
  77              $rtl = " dir=\"rtl\"";
  78          }
  79          
  80          echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n";
  81          echo "<html xmlns=\"http://www.w3.org/1999/xhtml\"{$rtl}>\n";
  82          echo "<head profile=\"http://gmpg.org/xfn/1\">\n";
  83          echo "    <title>".$title."</title>\n";
  84          echo "    <meta name=\"author\" content=\"MyBB Group\" />\n";
  85          echo "    <meta name=\"copyright\" content=\"Copyright ".COPY_YEAR." MyBB Group.\" />\n";
  86          echo "    <link rel=\"stylesheet\" href=\"styles/".$this->style."/main.css\" type=\"text/css\" />\n";
  87  
  88          // Load stylesheet for this module if it has one
  89          if(file_exists(MYBB_ADMIN_DIR."styles/{$this->style}/{$this->active_module}.css"))
  90          {
  91              echo "    <link rel=\"stylesheet\" href=\"styles/{$this->style}/{$this->active_module}.css\" type=\"text/css\" />\n";
  92          }
  93  
  94          echo "    <script type=\"text/javascript\" src=\"../jscripts/prototype.js\"></script>\n";
  95          echo "    <script type=\"text/javascript\" src=\"../jscripts/general.js\"></script>\n";
  96          echo "    <script type=\"text/javascript\" src=\"../jscripts/popup_menu.js\"></script>\n";
  97          echo "    <script type=\"text/javascript\" src=\"./jscripts/admincp.js\"></script>\n";
  98          echo "    <script type=\"text/javascript\" src=\"./jscripts/tabs.js\"></script>\n";
  99  
 100          // Stop JS elements showing while page is loading (JS supported browsers only)
 101          echo "  <style type=\"text/css\">.popup_button { display: none; } </style>\n";
 102          echo "  <script type=\"text/javascript\">\n".
 103                  "//<![CDATA[\n".
 104                  "    document.write('<style type=\"text/css\">.popup_button { display: inline; } .popup_menu { display: none; }<\/style>');\n".
 105                  "//]]>\n".
 106                  "</script>\n";
 107  
 108          echo "    <script type=\"text/javascript\">
 109  //<![CDATA[
 110  var loading_text = '{$lang->loading_text}';
 111  var cookieDomain = '{$mybb->settings['cookiedomain']}';
 112  var cookiePath = '{$mybb->settings['cookiepath']}';
 113  var cookiePrefix = '{$mybb->settings['cookieprefix']}';
 114  var imagepath = '../images';
 115  //]]>
 116  </script>\n";
 117          echo $this->extra_header;
 118          echo "</head>\n";
 119          echo "<body>\n";
 120          echo "<div id=\"container\">\n";
 121          echo "    <div id=\"logo\"><h1><span class=\"invisible\">{$lang->mybb_admin_cp}</span></h1></div>\n";
 122          echo "    <div id=\"welcome\"><span class=\"logged_in_as\">{$lang->logged_in_as} <a href=\"index.php?module=user-users&amp;action=edit&amp;uid={$mybb->user['uid']}\" class=\"username\">{$mybb->user['username']}</a></span> | <a href=\"{$mybb->settings['bburl']}\" target=\"_blank\" class=\"forum\">{$lang->view_board}</a> | <a href=\"index.php?action=logout\" class=\"logout\">{$lang->logout}</a></div>\n";
 123          echo $this->_build_menu();
 124          echo "    <div id=\"page\">\n";
 125          echo "        <div id=\"left_menu\">\n";
 126          echo $this->submenu;
 127          echo $this->sidebar;
 128          echo "        </div>\n";
 129          echo "        <div id=\"content\">\n";
 130          echo "            <div class=\"breadcrumb\">\n";
 131          echo $this->_generate_breadcrumb();
 132          echo "            </div>\n";
 133          echo "           <div id=\"inner\">\n";
 134          if($admin_session['data']['flash_message'])
 135          {
 136              $message = $admin_session['data']['flash_message']['message'];
 137              $type = $admin_session['data']['flash_message']['type'];
 138              echo "<div id=\"flash_message\" class=\"{$type}\">\n";
 139              echo "{$message}\n";
 140              echo "</div>\n";
 141              update_admin_session('flash_message', '');
 142          }
 143          if($this->show_post_verify_error == true)
 144          {
 145              $this->output_error($lang->invalid_post_verify_key);
 146          }
 147      }
 148  
 149      /**
 150       * Output the page footer.
 151       */
 152  	function output_footer($quit=true)
 153      {
 154          global $mybb, $maintimer, $db, $lang, $plugins;
 155          
 156          $plugins->run_hooks("admin_page_output_footer");
 157          
 158          $memory_usage = $lang->na;
 159          if(function_exists("memory_get_usage"))
 160          {
 161              $memory_usage = get_friendly_size(memory_get_peak_usage(true));
 162          }
 163          
 164          $totaltime = $maintimer->stop();
 165          $querycount = $db->query_count;
 166          echo "            </div>\n";
 167          echo "        </div>\n";
 168          echo "    <br style=\"clear: both;\" />";
 169          echo "    <br style=\"clear: both;\" />";
 170          echo "    </div>\n";
 171          echo "<div id=\"footer\"><p class=\"generation\">".$lang->sprintf($lang->generated_in, $totaltime, $querycount, $memory_usage)."</p><p class=\"powered\">Powered By MyBB. &copy; ".COPY_YEAR." MyBB Group. All Rights Reserved.</p></div>\n";
 172          if($mybb->debug_mode)
 173          {
 174              echo $db->explain;
 175          }
 176          echo "</div>\n";
 177          echo "</body>\n";
 178          echo "</html>\n";
 179          
 180          if($quit != false)
 181          {
 182              exit;
 183          }
 184      }
 185      
 186      /**
 187       * Add an item to the page breadcrumb trail.
 188       *
 189       * @param string The name of the item to add.
 190       * @param string The URL to the item we're adding (if there is one)
 191       */
 192  	function add_breadcrumb_item($name, $url="")
 193      {
 194          $this->_breadcrumb_trail[] = array("name" => $name, "url" => $url);
 195      }
 196      
 197      /**
 198       * Generate a breadcrumb trail.
 199       */
 200  	function _generate_breadcrumb()
 201      {
 202          if(!is_array($this->_breadcrumb_trail))
 203          {
 204              return false;
 205          }
 206          $trail = "";
 207          foreach($this->_breadcrumb_trail as $key => $crumb)
 208          {
 209              if($this->_breadcrumb_trail[$key+1])
 210              {
 211                  $trail .= "<a href=\"".$crumb['url']."\">".$crumb['name']."</a>";
 212                  if($this->_breadcrumb_trail[$key+2])
 213                  {
 214                      $trail .= " &raquo; ";
 215                  }
 216              }
 217              else
 218              {
 219                  $trail .= "<span class=\"active\">".$crumb['name']."</span>";
 220              }
 221          }
 222          return $trail;
 223      }    
 224      
 225      /**
 226       * Output an introductory message.
 227       *
 228       * @param string The title of the introductory message.
 229       * @param string The introductory message.
 230       * @param string An additional class name to add to the message if there is one.
 231       */
 232  	function output_intro($title, $description, $class="")
 233      {
 234          echo "        <div class=\"intro_description\">\n";
 235          echo "    <div class=\"{$class}\">\n";
 236          echo "    <h2>{$title}</h2>\n";
 237          echo "    <p>{$description}</p>\n";
 238          echo "</div>\n";
 239          echo "</div>\n";    
 240      }
 241      
 242      /**
 243       * Output a success message.
 244       *
 245       * @param string The message to output.
 246       */
 247  	function output_success($message)
 248      {
 249          echo "<div class=\"success\">{$message}</div>\n";
 250      }
 251  
 252      /**
 253       * Output an alert/warning message.
 254       *
 255       * @param string The message to output.
 256       * @param string The ID of the alert/warning (optional)
 257       */
 258  	function output_alert($message, $id="")
 259      {
 260          if($id)
 261          {
 262              $id = " id=\"{$id}\"";
 263          }
 264          echo "<div class=\"alert\"{$id}>{$message}</div>\n";
 265      }
 266      
 267      /**
 268       * Output an inline message.
 269       *
 270       * @param string The message to output.
 271       */
 272  	function output_inline_message($message)
 273      {
 274          echo "<div class=\"inline_message\">{$message}</div>\n";
 275      }
 276      
 277      /**
 278       * Output a single error message.
 279       *
 280       * @param string The message to output.
 281       */
 282  	function output_error($error)
 283      {
 284          echo "<div class=\"error\">\n";
 285          echo "{$error}\n";
 286          echo "</div>\n";
 287      }
 288  
 289      /**
 290       * Output one or more inline error messages.
 291       *
 292       * @param array Array of error messages to output.
 293       */
 294  	function output_inline_error($errors)
 295      {
 296          global $lang;
 297          
 298          if(!is_array($errors))
 299          {
 300              $errors = array($errors);
 301          }
 302          echo "<div class=\"error\">\n";
 303          echo "<p><em>{$lang->encountered_errors}</em></p>\n";
 304          echo "<ul>\n";
 305          foreach($errors as $error)
 306          {
 307              echo "<li>{$error}</li>\n";
 308          }
 309          echo "</ul>\n";
 310          echo "</div>\n";
 311      }
 312  
 313  
 314      /**
 315       * Generate the login page.
 316       *
 317       * @param string The any message to output on the page if there is one.
 318       * @param string The class name of the message (defaults to success)
 319       */
 320  	function show_login($message="", $class="success")
 321      {
 322          global $lang, $cp_style;
 323  
 324          $copy_year = COPY_YEAR;
 325          
 326          $login_container_width = "";
 327          $login_label_width = "";
 328           
 329          // If the language string for "Username" is too cramped then use this to define how much larger you want the gap to be (in px)
 330          if($lang->login_field_width)
 331          {
 332              $login_label_width = " style=\"width: ".(intval($lang->login_field_width)+100)."px;\"";
 333              $login_container_width = " style=\"width: ".(410+(intval($lang->login_field_width)))."px;\"";
 334          }
 335  
 336          print <<<EOF
 337  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 338  <html xmlns="http://www.w3.org/1999/xhtml" lang="en">
 339  <head profile="http://gmpg.org/xfn/1">
 340  <title>{$lang->mybb_admin_login}</title>
 341  <meta name="author" content="MyBB Group" />
 342  <meta name="copyright" content="Copyright {$copy_year} MyBB Group." />
 343  <link rel="stylesheet" href="./styles/{$cp_style}/login.css" type="text/css" />
 344  <script type="text/javascript" src="../jscripts/prototype.js"></script>
 345  <script type="text/javascript" src="../jscripts/general.js"></script>
 346  <script type="text/javascript" src="./jscripts/admincp.js"></script>
 347  <script type="text/javascript">
 348  //<![CDATA[
 349      loading_text = '{$lang->loading_text}';
 350  //]]>
 351  </script>
 352  </head>
 353  <body>
 354  <div id="container"{$login_container_width}>
 355      <div id="header">
 356          <div id="logo">
 357              <h1><a href="../" title="{$lang->return_to_forum}"><span class="invisible">{$lang->mybb_acp}</span></a></h1>
 358  
 359          </div>
 360      </div>
 361      <div id="content">
 362          <h2>{$lang->please_login}</h2>
 363  EOF;
 364          if($message)
 365          {
 366              echo "<p id=\"message\" class=\"{$class}\"><span class=\"text\">{$message}</span></p>";
 367          }
 368          // Make query string nice and pretty so that user can go to his/her preferred destination
 369          $query_string = '';
 370          if($_SERVER['QUERY_STRING'])
 371          {
 372              $query_string = '?'.preg_replace('#adminsid=(.{32})#i', '', $_SERVER['QUERY_STRING']);
 373              $query_string = str_replace('action=logout', '', $query_string);
 374              $query_string = preg_replace('#&+#', '&', $query_string);
 375              $query_string = str_replace('?&', '?', $query_string);
 376              $query_string = htmlspecialchars_uni($query_string);
 377          }
 378          
 379          // TODO: Better Fix?
 380             $_SERVER['PHP_SELF'] = htmlspecialchars_uni($_SERVER['PHP_SELF']);
 381  print <<<EOF
 382          <p>{$lang->enter_username_and_password}</p>
 383          <form method="post" action="{$_SERVER['PHP_SELF']}{$query_string}">
 384          <div class="form_container">
 385  
 386              <div class="label"{$login_label_width}><label for="username">{$lang->username}</label></div>
 387  
 388              <div class="field"><input type="text" name="username" id="username" class="text_input initial_focus" /></div>
 389  
 390              <div class="label"{$login_label_width}><label for="password">{$lang->password}</label></div>
 391              <div class="field"><input type="password" name="password" id="password" class="text_input" /></div>
 392          </div>
 393          <p class="submit">
 394              <span class="forgot_password">
 395                  <a href="../member.php?action=lostpw">{$lang->lost_password}</a>
 396              </span>
 397  
 398              <input type="submit" value="{$lang->login}" />
 399              <input type="hidden" name="do" value="login" />
 400          </p>
 401          </form>
 402      </div>
 403  </div>
 404  </body>
 405  </html>
 406  EOF;
 407      exit;
 408      }
 409      
 410      /**
 411       * Generate the lockout page
 412       *
 413       */
 414  	function show_lockedout()
 415      {
 416          global $lang, $mybb, $cp_style;
 417  
 418          $copy_year = COPY_YEAR;
 419          $allowed_attempts = intval($mybb->settings['maxloginattempts']);
 420          $lockedout_message = $lang->sprintf($lang->error_mybb_admin_lockedout_message, $allowed_attempts);
 421  
 422          print <<<EOF
 423  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 424  <html xmlns="http://www.w3.org/1999/xhtml" lang="en">
 425  <head profile="http://gmpg.org/xfn/1">
 426  <title>{$lang->mybb_admin_cp} - {$lang->error_mybb_admin_lockedout}</title>
 427  <meta name="author" content="MyBB Group" />
 428  <meta name="copyright" content="Copyright {$copy_year} MyBB Group." />
 429  <link rel="stylesheet" href="./styles/{$cp_style}/login.css" type="text/css" />
 430  </head>
 431  <body>
 432  <div id="container">
 433      <div id="header">
 434          <div id="logo">
 435              <h1><a href="../" title="{$lang->return_to_forum}"><span class="invisible">{$lang->mybb_acp}</span></a></h1>
 436  
 437          </div>
 438      </div>
 439      <div id="content">
 440          <h2>{$lang->error_mybb_admin_lockedout}</h2>
 441          <div class="alert">{$lockedout_message}</div>
 442      </div>
 443  </div>
 444  </body>
 445  </html>
 446  EOF;
 447      exit;
 448      }
 449      
 450      /**
 451       * Generate the lockout unlock page
 452       *
 453       */
 454  	function show_lockout_unlock()
 455      {
 456          global $lang, $mybb, $cp_style;
 457  
 458          $copy_year = COPY_YEAR;
 459  
 460          print <<<EOF
 461  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 462  <html xmlns="http://www.w3.org/1999/xhtml" lang="en">
 463  <head profile="http://gmpg.org/xfn/1">
 464  <title>{$lang->mybb_admin_cp} - {$lang->lockout_unlock}</title>
 465  <meta name="author" content="MyBB Group" />
 466  <meta name="copyright" content="Copyright {$copy_year} MyBB Group." />
 467  <link rel="stylesheet" href="./styles/{$cp_style}/login.css" type="text/css" />
 468  </head>
 469  <body>
 470  <div id="container">
 471      <div id="header">
 472          <div id="logo">
 473              <h1><a href="../" title="{$lang->return_to_forum}"><span class="invisible">{$lang->mybb_acp}</span></a></h1>
 474  
 475          </div>
 476      </div>
 477      <div id="content">
 478          <h2>{$lang->lockout_unlock}</h2>
 479          <p>{$lang->enter_username_and_token}</p>
 480          <form method="post" action="index.php">
 481          <div class="form_container">
 482  
 483              <div class="label"{$login_label_width}><label for="username">{$lang->username}</label></div>
 484  
 485              <div class="field"><input type="text" name="username" id="username" class="text_input initial_focus" /></div>
 486  
 487              <div class="label"{$login_label_width}><label for="token">{$lang->unlock_token}</label></div>
 488              <div class="field"><input type="text" name="token" id="token" class="text_input" /></div>
 489          </div>
 490          <p class="submit">
 491              <span class="forgot_password">
 492                  <a href="../member.php?action=lostpw">{$lang->lost_password}</a>
 493              </span>
 494  
 495              <input type="submit" value="{$lang->unlock_account}" />
 496              <input type="hidden" name="action" value="unlock" />
 497          </p>
 498          </form>
 499      </div>
 500  </div>
 501  </body>
 502  </html>
 503  EOF;
 504      exit;
 505      }
 506  
 507      /**
 508       * Add an item to the primary navigation menu.
 509       *
 510       * @param string The title of the menu item.
 511       * @param string The ID of the menu item. This should correspond with the module the menu will run.
 512       * @param string The link to follow when the menu item is clicked.
 513       * @param int The display order of the menu item. Lower display order means closer to start of the menu.
 514       * @param array Array of sub menu items if there are any.
 515       */
 516  	function add_menu_item($title, $id, $link, $order=10, $submenu=array())
 517      {
 518          $this->_menu[$order][] = array(
 519              "title" => $title,
 520              "id" => $id,
 521              "link" => $link,
 522              "submenu" => $submenu
 523          );
 524      }
 525  
 526      /**
 527       * Build the actual navigation menu.
 528       */
 529  	function _build_menu()
 530      {
 531          if(!is_array($this->_menu))
 532          {
 533              return false;
 534          }
 535          $build_menu = "<div id=\"menu\">\n<ul>\n";
 536          ksort($this->_menu);
 537          foreach($this->_menu as $items)
 538          {
 539              foreach($items as $menu_item)
 540              {
 541                  $menu_item['link'] = htmlspecialchars($menu_item['link']);
 542                  if($menu_item['id'] == $this->active_module)
 543                  {
 544                      $sub_menu = $menu_item['submenu'];
 545                      $sub_menu_title = $menu_item['title'];
 546                      $build_menu .= "<li><a href=\"{$menu_item['link']}\" class=\"active\">{$menu_item['title']}</a></li>\n";
 547  
 548                  }
 549                  else
 550                  {
 551                      $build_menu .= "<li><a href=\"{$menu_item['link']}\">{$menu_item['title']}</a></li>\n";
 552                  }
 553              }
 554          }
 555          $build_menu .= "</ul>\n</div>";
 556  
 557          if($sub_menu)
 558          {
 559              $this->_build_submenu($sub_menu_title, $sub_menu);
 560          }
 561          return $build_menu;
 562      }
 563      
 564  
 565      /**
 566       * Build a navigation sub menu if we have one.
 567       *
 568       * @param string A title for the sub menu.
 569       * @param array Array of items for the sub menu.
 570       */
 571  	function _build_submenu($title, $items)
 572      {
 573          if(is_array($items))
 574          {
 575              $sidebar = new sideBarItem($title);
 576              $sidebar->add_menu_items($items, $this->active_action);
 577              $this->submenu .= $sidebar->get_markup();
 578          }
 579      }
 580  
 581      /**
 582       * Switch between two different alternating background colours.
 583       */
 584  	function get_alt_bg()
 585      {
 586          static $alt_bg;
 587          if($alt_bg == "alt1")
 588          {
 589              $alt_bg = "alt2";
 590              return "alt1";
 591          }
 592          else
 593          {
 594              $alt_bg = "alt1";
 595              return $alt_bg;
 596          }
 597      }
 598  
 599      /**
 600       * Output a Javascript based tab control on to the page.
 601       *
 602       * @param array Array of tabs in name => title format. Name should correspond to the name of a DIV containing the tab content.
 603       * @param boolean Whether or not to run the event onload or instantly
 604       * @param string The ID to use for the tabs for if you run multiple instances of the tabbing control in one html page
 605       */
 606  	function output_tab_control($tabs=array(), $observe_onload=true, $id="tabs")
 607      {
 608          global $plugins;
 609          $tabs = $plugins->run_hooks("admin_page_output_tab_control_start", $tabs);
 610          echo "<script type=\"text/javascript\">\n";
 611          if($observe_onload)
 612          {
 613              echo "Event.observe(window,'load',function(){\n";
 614          }
 615          echo "    \$\$('#{$id}').each(function(tabs)\n";
 616          echo "    {\n";
 617          echo "        new Control.Tabs(tabs);\n";
 618          echo "    });\n";
 619          if($observe_onload)
 620          {
 621              echo "});\n";
 622          }
 623          echo "</script>\n";
 624          echo "<ul class=\"tabs\" id=\"{$id}\">\n";
 625          $tab_count = count($tabs);
 626          $done = 1;
 627          foreach($tabs as $anchor => $title)
 628          {
 629              $class = "";
 630              if($tab_count == $done)
 631              {
 632                  $class .= " last";
 633              }
 634              if($done == 1)
 635              {
 636                  $class .= " first";
 637              }
 638              ++$done;
 639              echo "<li class=\"{$class}\"><a href=\"#tab_{$anchor}\">{$title}</a></li>\n";
 640          }
 641          echo "</ul>\n";
 642          $plugins->run_hooks("admin_page_output_tab_control_end", $tabs);
 643      }
 644  
 645      /**
 646       * Output a series of primary navigation tabs for swithcing between items within a particular module/action.
 647       *
 648       * @param array Nested array of tabs containing possible keys of align, link_target, link, title.
 649       * @param string The name of the active tab. Corresponds with the key of each tab item.
 650       */
 651  	function output_nav_tabs($tabs=array(), $active='')
 652      {
 653          global $plugins;
 654          $tabs = $plugins->run_hooks("admin_page_output_nav_tabs_start", $tabs);
 655          echo "<div class=\"nav_tabs\">";
 656          echo "\t<ul>\n";
 657          foreach($tabs as $id => $tab)
 658          {
 659              $class = '';
 660              if($id == $active)
 661              {
 662                  $class = ' active';
 663              }
 664              if($tab['align'] == "right")
 665              {
 666                  $class .= " right";
 667              }
 668              if($tab['link_target'])
 669              {
 670                  $target = " target=\"{$tab['link_target']}\"";
 671              }
 672              echo "\t\t<li class=\"{$class}\"><a href=\"{$tab['link']}\"{$target}>{$tab['title']}</a></li>\n";
 673              $target = '';
 674          }
 675          echo "\t</ul>\n";
 676          if($tabs[$active]['description'])
 677          {
 678              echo "\t<div class=\"tab_description\">{$tabs[$active]['description']}</div>\n";
 679          }
 680          echo "</div>";
 681          $arguments = array('tabs' => $tabs, 'active' => $active);
 682          $plugins->run_hooks("admin_page_output_nav_tabs_end", $arguments);
 683      }
 684  
 685      /**
 686       * Output a page asking if a user wishes to continue performing a specific action.
 687       *
 688       * @param string The URL to be forwarded to.
 689       * @param string The confirmation message to output.
 690       * @param string The title to use in the output header
 691       */
 692  	function output_confirm_action($url, $message="", $title="")
 693      {
 694          global $lang;
 695          
 696          if(!$message)
 697          {
 698              $message = $lang->confirm_action;
 699          }
 700          $this->output_header($title);
 701          $form = new Form($url, 'post');
 702          echo "<div class=\"confirm_action\">\n";
 703          echo "<p>{$message}</p>\n";
 704          echo "<br />\n";
 705          echo "<p class=\"buttons\">\n";
 706          echo $form->generate_submit_button($lang->yes, array('class' => 'button_yes'));
 707          echo $form->generate_submit_button($lang->no, array("name" => "no", 'class' => 'button_no'));
 708          echo "</p>\n";
 709          echo "</div>\n";
 710          $form->end();
 711          $this->output_footer();
 712      }
 713  
 714      /**
 715       * Build a clickable MyCode editor for the Admin CP.
 716       *
 717       * @param string The ID of the textarea to bind the editor to.
 718       * @param string The language string for the editor.
 719       * @return string The build MyCode editor Javascript.
 720       */
 721  	function build_codebuttons_editor($bind, $editor_language)
 722      {
 723          global $lang;
 724          if($bind == "signature")
 725          {
 726              $tabs_js = "Control.Tabs.observe('afterChange', function(instance, new_tab) { if(new_tab.id == \"tab_signature\") { initEditor() }});";
 727          }
 728          return "<script type=\"text/javascript\" src=\"../jscripts/editor.js\"></script>\n".
 729                  "<script type=\"text/javascript\">\n".
 730                  "//<![CDATA[\n".
 731                  "    {$editor_language}".
 732                  "    {$tabs_js}".
 733                  "    var clickableEditor = ''; function initEditor() { if(!clickableEditor) { clickableEditor = new messageEditor(\"{$bind}\", {lang: editor_language, rtl: {$lang->settings['rtl']}})}; };\n".
 734                  "//]]>".
 735                  "</script>";
 736      }
 737  }
 738  
 739  /**
 740   * A class for generating side bar blocks.
 741   */
 742  class DefaultSidebarItem
 743  {
 744      /**
 745       * @var The title of the side bar block.
 746       */
 747      private $_title;
 748  
 749      /**
 750       * @var string The contents of the side bar block.
 751       */
 752      private $_contents;
 753      
 754      /**
 755       * Constructor. Set the title of the side bar block.
 756       *
 757       * @param string The title of the side bar block.
 758       */
 759  	function __construct($title="")
 760      {
 761          $this->_title = $title;
 762      }
 763      
 764      /**
 765       * Add menus item to the side bar block.
 766       *
 767       * @param array Array of menu items to add. Each menu item should be a nested array of id, link and title.
 768       * @param string The ID of the active menu item if there is one.
 769       */
 770  	function add_menu_items($items, $active)
 771      {
 772          global $run_module;
 773          
 774          $this->_contents = "<ul class=\"menu\">";
 775          foreach($items as $item)
 776          {
 777              if(!check_admin_permissions(array("module" => $run_module, "action" => $item['id']), false))
 778              {
 779                  continue;
 780              }
 781              
 782              $class = "";
 783              if($item['id'] == $active)
 784              {
 785                  $class = "active";
 786              }
 787              $item['link'] = htmlspecialchars($item['link']);
 788              $this->_contents .= "<li class=\"{$class}\"><a href=\"{$item['link']}\">{$item['title']}</a></li>\n";
 789          }
 790          $this->_contents .= "</ul>";
 791      }
 792      
 793      /**
 794       * Sets custom html to the contents variable
 795       *
 796       * @param string The custom html to set
 797       */
 798  	function set_contents($html)
 799      {
 800          $this->_contents = $html;
 801      }
 802      
 803      /**
 804       * Fetch the HTML markup for the side bar box.
 805       */
 806  	function get_markup()
 807      {
 808          $markup = "<div class=\"left_menu_box\">\n";
 809          $markup .= "<div class=\"title\">{$this->_title}</div>\n";
 810          if($this->_contents)
 811          {
 812              $markup .= $this->_contents;
 813          }
 814          $markup .= "</div>\n";
 815          return $markup;
 816      }
 817  }
 818  
 819  /**
 820   * Generate a Javascript based popup menu.
 821   */
 822  class DefaultPopupMenu
 823  {
 824      /**
 825       * @var string The title of the popup menu to be shown on the button.
 826       */
 827      private $_title;
 828  
 829      /**
 830       * @var string The ID of this popup menu. Must be unique.
 831       */
 832      private $_id;
 833  
 834      /**
 835       * @var string Built HTML for the items in the popup menu.
 836       */
 837      private $_items;
 838  
 839      /**
 840       * Initialise a new popup menu.
 841       *
 842       * @var string The ID of the popup menu.
 843       * @var string The title of the popup menu.
 844       */
 845  	function __construct($id, $title='')
 846      {
 847          $this->_id = $id;
 848          $this->_title = $title;
 849      }
 850  
 851      /**
 852       * Add an item to the popup menu.
 853       *
 854       * @param string The title of this item.
 855       * @param string The page this item should link to.
 856       * @param string The onclick event handler if we have one.
 857       */
 858  	function add_item($text, $link, $onclick='')
 859      {
 860          if($onclick)
 861          {
 862              $onclick = " onclick=\"{$onclick}\"";
 863          }
 864          $this->_items .= "<div class=\"popup_item_container\"><a href=\"{$link}\"{$onclick} class=\"popup_item\">{$text}</a></div>\n";
 865      }
 866  
 867      /**
 868       * Fetch the contents of the popup menu.
 869       *
 870       * @return string The popup menu.
 871       */
 872  	function fetch()
 873      {
 874          $popup = "<div class=\"popup_menu\" id=\"{$this->_id}_popup\">\n{$this->_items}</div>\n";
 875          if($this->_title)
 876          {
 877              $popup .= "<a href=\"javascript:;\" id=\"{$this->_id}\" class=\"popup_button\">{$this->_title}</a>\n";
 878          }
 879          $popup .= "<script type=\"text/javascript\">\n";
 880          $popup .= "new PopupMenu('{$this->_id}');\n";
 881          $popup .= "</script>\n";
 882          return $popup;
 883      }
 884  
 885      /**
 886       * Outputs a popup menu to the browser.
 887       */
 888  	function output()
 889      {
 890          echo $this->fetch();
 891      }
 892  }
 893  ?>


Generated: Sun Dec 11 14:16:27 2011 Cross-referenced by PHPXref 0.7.1