Location: PHPKode > projects > Joomla SEF / SEO - extending OpenSEF > includes/sef.backend.php
<?php
/**
 * JoomlaSEF for Joomla!
 * @copyright (c) 2006 The OpenSEF Project (www.opensef.org)
 * @copyright (c) 2004-2005 Xaneon Development (www.xaneon.com)
 * @license GPL http://www.gnu.org/copyleft/gpl.html
 *
 * TODO
 */

/** Ensure this file is being included by a parent file */
defined( '_VALID_MOS' ) or die( 'Direct access to this location is not allowed.' );

/**
 * Base class for producing a Joomla-compatible administrative
 * interface. Actual implementations are expected to subclass
 * this and override & implement their specific functionality.
 */
class xclBackendAdmin {


  /**
   * Backend Admin
   *
   * @param array $config
   * @param array $tables
   * @param array $classes
   * @return xclBackendAdmin
   */
  function xclBackendAdmin( &$config, &$tables, &$classes ) {
    $this->config =& $config;
    $this->tables =& $tables;
    $this->classes =& $classes;

    $this->mainframe =& $GLOBALS['mainframe'];
    $this->db =& $GLOBALS['database'];
    $this->option = mosGetParam( $_REQUEST, 'option', $GLOBALS['option'] );
    $this->method = strtolower( $_SERVER['REQUEST_METHOD'] );
    $this->act = trim( mosGetParam( $_REQUEST, 'act', null ) );
    $this->task = trim( mosGetParam( $_REQUEST, 'task', null ) );
    $this->taskParam = null;
    if (strpos( $this->task, ',' ) !== false)
    list($this->task, $this->taskParam) = explode( ',', $this->task, 2 );
    $this->cid = mosGetParam( $_REQUEST, 'cid', array( 0 ) );
    if (!is_array( $this->cid )) $this->cid = array ( 0 );

    $JoomlaPath = $GLOBALS['mosConfig_absolute_path'];
    $JoomlaSite = $GLOBALS['mosConfig_live_site'];
    $backendPath = "$JoomlaPath/administrator/components/{$this->option}";
    $frontendPath = "$JoomlaPath/components/{$this->option}";
    $imagePath = "$JoomlaSite/administrator/components/{$this->option}/admin/images";
    $this->JoomlaPath = $JoomlaPath;
    $this->JoomlaSite = $JoomlaSite;

    require_once( $this->mainframe->getPath( 'class' ) );
    require_once( 'sef.config.php' );
    require_once( 'sef.langs.php' );

    xclLoadLanguageConstants($this->config->backend_language);

    $xmlFile = $backendPath . '/' .
      str_replace( 'com_', '', $this->option ) . '.xml';
    $this->xml = new xclPackageInfo( $xmlFile );
    $this->version = $this->config->version;
    require_once( 'Savant2.php' );
    $tpl =& new Savant2();
    $tpl->assign( 'option', $this->option );
    $tpl->assign( 'act', $this->act );
    $tpl->assign( 'task', $this->task );
    $tpl->addPath( 'template', $backendPath . '/admin/' );
    $tpl->loadPlugin( 'dateformat', array( 'format' => '%Y-%m-%d H:i:s' ) );
    $tpl->loadPlugin( 'image', array( 'imageDir' => $JoomlaSite . "/administrator/components/{$this->option}/admin/images/" ) );
    $tpl->loadPlugin( 'Joomla', array() );
    $tpl->loadFilter( 'trimwhitespace' );
    $this->tpl =& $tpl;

    $tpl->assign( 'aboutLink', "index2.php?option={$this->option}&act=about" );
  }

  /**
   * Helper for including the correct File
   *
   * @param string $name
   */
  function include_file( $name ) {
    require_once( "sef.$name.php" );
  }

  /**
   * Generate the output
   *
   * @return $result
   */
  function output() {
    $this->header();
    $func1 = 'do_' . $this->act . '_' . $this->task;
    $func2 = 'do_' . $this->act;

    // echo $func1 . ' - ' . $func2;

    if (method_exists( $this, $func1 )) {
      $result = $this->$func1();
    }
    else if (method_exists( $this, $func2 )) {
      $result = $this->$func2();
    }
    else {
      $result = $this->request();
    }
    $this->footer();
    return $result;
  }

  /**
   * Redirection
   *
   * @param stringe $msg
   * @return unknown
   */
  function redirect( $msg = '' ) {
    $url = xclGetViewURL( $this->option, $this->act );
    return die(mosRedirect( $url, $msg ));
  }

  /**
   * Update call
   *
   * @param string $field
   * @param string $value
   * @param boole $checkin
   * @return unknown
   */
  function update( $field = 'published', $value, $checkin = true ) {
    $table = $this->tables[$this->act];
    $cid =& $this->cid;

    global $my;
    if (!is_array( $cid ) || count( $cid ) < 1) {
      exit;
    }
    $cids = implode( ',', $cid );
    $query = "UPDATE $table SET $field = '$value'" .
    "\nWHERE id IN ($cids)";
    if ($checkin)
    $query .= " AND (checked_out = 0 OR checked_out = '{$my->id}')";
    $this->db->setQuery( $query );
    return $this->db->query();
  }

  /**
   * Enter description here...
   *
   * @return unknown
   */
  function request() {
    if (method_exists( $this, 'do_about' )) {
      return $this->do_about();
    }
    else {
      echo( "Not implemented yet ('{$this->act}', '{$this->task}')." );
    }
  }

  /**
   * Enter description here...
   *
   */
  function dump() {
    // Dump ourselves, BUT temporarily unset XML object or Apache will
    // crash and burn.
    $xml =& $this->xml;
    $this->xml = null;
    var_dump( $this );
    $this->xml =& $xml;
  }

  /**
   * Enter description here...
   *
   */
  function header() {
    global $mosConfig_live_site;
    $info =& $this->xml;
    if (!is_object( $info ) || !$info->isAvailable()) {
      // TODO
    }
    $text = $info->getElementText( '/mosinstall/' . 'authorUrl' );
    // This is probably (well, hopefully!) unnecessary, but make sure we
    // pass on the text using UNIX line-endings only. The following takes
    // into account both Windows and Mac EOL characters:
    if (!empty( $text ))
    $text = str_replace( "\r", "\n", str_replace( "\r\n", "\n", $text ) );
    $this->tpl->assign( 'authorUrl', $text );
    $this->tpl->assign( 'version', $this->version );
    if (!empty( $this->config->backend_sidebar )) {
      $query = "SELECT * FROM #__components AS c" .
      "\nWHERE c.option = '{$this->option}' AND c.parent != '0'" .
      "\nORDER BY c.ordering ASC";
      $this->db->setQuery( $query );
      $this->tpl->assign( 'menu', $this->db->loadObjectList() );
    ?>
    <div class="com_sef">
      <link rel="stylesheet" type="text/css" href="<?php echo $mosConfig_live_site; ?>/administrator/components/com_sef/includes/css/opensef.css">
      <script type="text/javascript" src="<?php echo $mosConfig_live_site; ?>/administrator/components/com_sef/includes/js/prototype.lite.js"></script>
      <script type="text/javascript" src="<?php echo $mosConfig_live_site; ?>/administrator/components/com_sef/includes/js/moo.fx.js"></script>
      <script type="text/javascript" src="<?php echo $mosConfig_live_site; ?>/administrator/components/com_sef/includes/js/moo.fx.pack.js"></script>
      <script type="text/javascript" src="<?php echo $mosConfig_live_site; ?>/administrator/components/com_sef/includes/js/moo.fx.slide.js"></script>
      <script type="text/javascript" src="<?php echo $mosConfig_live_site; ?>/administrator/components/com_sef/includes/js/nifty.js"></script>
      <script type="text/javascript">
        window.onload=function(){
          if(!NiftyCheck()) alert("hello");
          Rounded("div.sidemenu-box","all","#fff","#f7f7f7","border #ccc");
          Rounded("div.element-box","all","#fff","#fff","border #ccc");
          Rounded("div.toolbar-box","all","#fff","#fbfbfb","border #ccc");
          Rounded("div.submenu-box","all","#fff","#f2f2f2","border #ccc");

        }
      </script>
      <table width="100%" cellspacing="0" cellpadding="3" border="0">
      <tr>
        <td align="left" valign="top" width="200">
          <?php $this->display( 'sidebar' ); ?>
        </td>
        <td align="left" valign="top" width="100%">
    <?php
    } // if !backend_sidebar
  }

  /**
   * Enter description here...
   *
   */
  function footer() {
    if (!empty( $this->config->backend_sidebar )) {
    ?>
          </td>
        </tr>
      </table>
      <script type="text/javascript">
        init_moofx();
      </script>
    </div>
    <?php
    } // if !backend_sidebar
  }

  /**
   * Enter description here...
   *
   */
  function do_about() {
    $info =& $this->xml;
    if (!is_object( $info ) || !$info->isAvailable()) {
      // TODO
    }

    $elements = array(
    'name', 'productName', 'creationDate', 'joomlaVersion',
    'author', 'authorName', 'authorEmail', 'authorUrl',
    'productPicture', 'productUrl', 'setupUrl', 'trackerUrl',
    'copyright', 'license', 'licenseText',
    'description', 'warning', 'credits',
    );
    foreach ($elements as $element) {
      $text = $info->getElementText( '/mosinstall/' . $element );
      // This is probably (well, hopefully!) unnecessary, but make sure we
      // pass on the text using UNIX line-endings only. The following takes
      // into account both Windows and Mac EOL characters:
      if (!empty( $text ))
      $text = str_replace( "\r", "\n", str_replace( "\r\n", "\n", $text ) );
      $this->tpl->assign( $element, $text );
    }
    $this->tpl->assign('version', $this->config->version);
    $this->display( 'about' );
  }

  /**
   * Enter description here...
   *
   */
  function do_config() {
    $row = $this->config; // copy
    //mosMakeHtmlSafe( $row, ENT_QUOTES );
    $this->tpl->assign( 'id', null );
    $this->tpl->assign( 'data', $row );
    if (method_exists( $this, 'config' ))
    $this->config( $row );
    $this->display( 'form' );
  }

  /**
   * Enter description here...
   *
   * @return unknown
   */
  function do_config_save() {
    if (!is_null( $this->config )) {
      foreach ($_POST as $field => $value) {
        if ($field[0] != '_' && $field != 'option' && $field != 'act'
        && $field != 'task' && $field != 'id') {
          if (isset( $this->config->$field )) {
            $this->config->$field = $value;
          }
        }
      }
      $this->config->store( true );
    }
    return $this->redirect( _T( 'CONFIGURATION_UPDATED' ) );
  }

  /**
   * Enter description here...
   *
   * @param unknown_type $template
   * @return unknown
   */
  function display( $template ) {
    $this->renderAlerts();
    return $this->tpl->display( $template . '.tpl.php' );
  }

  /**
   * Render (Output) Template Alerts
   */
  function renderAlerts(){
    if($this->tpl->notice_msg)
      echo '<h1 class="notice_msg">'.$this->tpl->notice_msg.'</h1>';
    if($this->tpl->alert_msg)
      echo '<h1 class="alert_msg">'.$this->tpl->alert_msg.'</h1>';
    if($this->tpl->error_msg)
      echo '<h1 class="error_msg">'.$this->tpl->error_msg.'</h1>';
  }

  /**
   * Enter description here...
   *
   * @param unknown_type $allowed
   * @return unknown
   */
  function _default( $allowed = null ) {
    $task = ($this->task ? $this->task : 'view');
    if (is_array( $allowed ) && !in_array( $task, $allowed ))
    return null;
    switch ($this->task) {
      case 'new':
      case 'edit':
        return $this->form();
      case 'save':
        $className = $this->classes[$this->act];
        $id = (!empty( $_POST['id'] ) ? $_POST['id'] : null);
        $row =& new $className( $this->db, $id );
        if (!is_null( $row )) {
          if (!$row->save( $_POST, null )) {
            die( $row->getError() );
          }
        }
        if ($this->act == 'aliases' ){
          $wbSEO =& new jsefPluginWBSEO( $this->db, $id );
          $wbSEO->save();
        }
        if ($this->act == 'sites' ) {
          $this->storeComponentAliases( $id );
        }
        return $this->redirect();
        break;
      case 'remove':
        if (array_key_exists( $this->act, $this->tables )) {
          xclRemove( $this->option, $this->db, $this->cid,
          str_replace( '#__', '', $this->tables[$this->act] ) );
        }
        return $this->redirect();
        break;
      case 'removeall':
        $this->db->setQuery( "DELETE FROM ".$this->tables[$this->act]." where locked !='1' " );
        if (!$this->db->query()) {
          die( xclErrorGoBack( $this->db->getErrorMsg() ) );
        }
        return $this->redirect();
      case 'removeunpublished':
        $this->db->setQuery( "DELETE FROM ".$this->tables[$this->act]." where published='0' and locked !='1'" );
        if (!$this->db->query()) {
          die( xclErrorGoBack( $this->db->getErrorMsg() ) );
        }
        return $this->redirect();
      case 'removeunvalid':
        $this->db->setQuery( "DELETE FROM ".$this->tables[$this->act]." where valid='0' and locked !='1'" );
        if (!$this->db->query()) {
          die( xclErrorGoBack( $this->db->getErrorMsg() ) );
        }
        return $this->redirect();
      case 'view':
      default:
        $this->tpl->assign( "rowTemplate", "view_{$this->act}.tpl.php" );
        $this->tpl->assign( $this->view() );
        $this->display( 'view' );
    }
  }

  /**
   * Enter description here...
   *
   */
  function form() {
    $id = ($this->task == 'new' ? '0' : $this->cid[0]);
    $className = $this->classes[$this->act];
    $row =& new $className( $this->db, $id );
    if ($row->id && $this->act == 'aliases' ){
      $wbSEO =& new jsefPluginWBSEO( $this->db );
      $wbSEO->loadAliasSEO( $row );
    }
    mosMakeHtmlSafe( $row, ENT_QUOTES );
    $this->tpl->assign( 'id', $id );
    $this->tpl->assign( 'data', $row );
    $func = 'form_' . $this->act;
    if (method_exists( $this, $func ))
    $this->$func( $row );
    $this->display( 'form' );
  }

  /**
   * Enter description here...
   *
   * @return unknown
   */
  function view() {

    include_once( $GLOBALS['mosConfig_absolute_path'] .
    '/administrator/components/com_sef/includes/pageNavigation.php' );

    $view =& new stdClass();
    $view->title = null;
    $view->icon = null;

    $view->limit = $this->mainframe->getUserStateFromRequest(
    "viewlistlimit", "limit", $GLOBALS['mosConfig_list_limit'] );
    $view->limitstart = $this->mainframe->getUserStateFromRequest(
    "view{$this->option}limitstart", "limitstart", 0 );
    $view->wheres = array();
    $view->orderBy = array();

    $view->className = $this->classes[$this->act];
    $view->table = null;
    if (!is_null( $this->tables )) {
      if (is_array( $this->tables )) {
        if (array_key_exists( $this->act, $this->tables ))
        $view->table = $this->tables[$this->act];
      }
      else {
        $view->table = $this->tables;
      }
    }

    $func = 'view_' . $this->act;
    if (method_exists( $this, $func ))
    $this->$func( $view );

    if (is_null( $view->table )) {
      $total = ($view->rowCount ? $view->rowCount : 0);
      $view->pageNav =& new mosPageNav(
      $total, $view->limitstart, $view->limit  );
    }
    else {
      $query = "SELECT COUNT(*) FROM {$view->table}";
      if (count( $view->wheres ) > 0) $query .= " WHERE " . implode( " AND ", $view->wheres );
      if (count( $view->orderBy ) > 0) $query .= " ORDER BY " . implode( ", ", $view->orderBy );
      $this->db->setQuery( $query );
      $total = $this->db->loadResult();

      $view->pageNav =& new mosPageNav(
      $total, $view->limitstart, $view->limit  );
      $query = "SELECT * FROM {$view->table}";
      if (count( $view->wheres ) > 0) $query .= "\nWHERE " . implode( " AND ", $view->wheres );
      if (count( $view->orderBy ) > 0) $query .= "\nORDER BY " . implode( ", ", $view->orderBy );
      $query .= "\nLIMIT {$view->pageNav->limitstart}, {$view->pageNav->limit}";
      $this->db->setQuery( $query );

      $rows = $this->db->loadObjectList();
      if ($this->db->getErrorNum()) {
        return array( "error" => $this->db->stderr() );
      }
      // This is inefficient but seemingly the only alternative at the moment.
      foreach ($rows as $row) {
        $data = get_object_vars( $row );
        $className = $view->className;
        $obj = new $className( $this->db );
          foreach ($data as $name => $value)
            $obj->$name = $value;
            $objs[] = $obj;

      }
      $view->rows =& $objs;
      $view->rowCount = count( $objs );
    }

    return $view;
  }
}

/**
 * Enter description here...
 *
 * @param unknown_type $msg
 */
function xclErrorGoBack( $msg ) {
?>
  <script language="JavaScript">alert('<?php echo( $msg ); ?>'); window.history.go(-1);</script>
<?php
}

/**
 * Enter description here...
 *
 * @param unknown_type $option
 * @param unknown_type $act
 * @return unknown
 */
function xclGetViewURL( $option, $act = '' ) {
  $url = "index2.php?option=$option";
  if ($act) $url .= "&act=$act";
  $limit = intval( mosGetParam( $_REQUEST, "limit", $GLOBALS['mosConfig_list_limit'] ) );
  $limitstart = intval( mosGetParam( $_REQUEST, "limitstart", 0 ) );
  $url .= "&limit=$limit&limitstart=$limitstart";
  return $url;
}

/**
 * Enter description here...
 *
 * @param unknown_type $option
 * @param unknown_type $database
 * @param unknown_type $cid
 * @param unknown_type $table
 * @param unknown_type $fieldName
 * @param unknown_type $publish
 */
function xclPublish( $option, &$database, &$cid, $table, $fieldName = "published", $publish = 1 ) {
  if (!is_array( $cid ) || count( $cid ) < 1) {
    $action = ($publish ? "publish" : "unpublish");
    die( xclErrorGoBack( "Select an item or items to $action." ) );
  }

  if (count( $cid )) {
    $cids = implode( ',', $cid );
    $database->setQuery( "UPDATE #__$table SET $fieldName = '$publish' WHERE id IN ($cids)" );
    if (!$database->query()) {
      die( xclErrorGoBack( $database->getErrorMsg() ) );
    }
  }
}

/**
 * Enter description here...
 *
 * @param unknown_type $option
 * @param unknown_type $database
 * @param unknown_type $cid
 * @param unknown_type $table
 */
function xclRemove( $option, &$database, &$cid, $table ) {
  if (!is_array( $cid ) || count( $cid ) < 1) {
    die( xclErrorGoBack( "Select an item or items to delete." ) );
  }

  if (count( $cid )) {
    $cids = implode( ',', $cid );
    $database->setQuery( "DELETE FROM #__$table WHERE id IN ($cids)" );
    if (!$database->query()) {
      die( xclErrorGoBack( $database->getErrorMsg() ) );
    }
  }
}

/**
 * Helpers for producing HTML output.
 *
 */
class xclHTML {

  var $name   = null;
  var $title  = null;
  var $html   = null;
  var $help   = null;
  var $type   = null;

  /**
   * Enter description here...
   *
   * @param unknown_type $section
   * @param unknown_type $name
   * @param unknown_type $html
   * @return xclHTML
   */
  function xclHTML( $section, $name, $html, $type=null ) {
    $this->name = $name;
    $this->title = _T( strtoupper( $section . '_' . $name ) );
    $this->html = $html;
    $this->help = _T( strtoupper( 'HELP_' . $section . '_' . $name ) );
    $this->type = $type;
  }

  /*
  * TODO
  */
  /**
   * Enter description here...
   *
   * @return unknown
   */
  function br() {
    return '<br />';
  }

  /**
   * Enter description here...
   *
   * @param unknown_type $tpl
   * @param unknown_type $section
   * @param unknown_type $name
   * @param unknown_type $params
   * @return unknown
   */
  function label( $tpl, $section, $name, $params = null ) {
    $html = "$title";
    return new xclHTML( $section, $name, $html, __FUNCTION__ );
  }

  /**
   * Hidden Input Field
   *
   * @param unknown_type $tpl
   * @param unknown_type $section
   * @param unknown_type $name
   * @param unknown_type $params
   * @return unknown
   */
  function hidden( $tpl, $section, $name, $params = null ) {
    $value = (is_object( $tpl ) ? $tpl->data->$name : strval( $tpl ));
    $html = '<input type="hidden"';
    $html .= ' name="' . $name . '"';
    $html .= ' value="' . $value . '"';
    $html .= ($params ? ' ' . $params : '') . ' />';
    return new xclHTML( $section, $name, $html, __FUNCTION__ );
  }

  /**
   * Enter description here...
   *
   * @param unknown_type $tpl
   * @param unknown_type $section
   * @param unknown_type $name
   * @param unknown_type $width
   * @param unknown_type $params
   * @return unknown
   */
  function textbox( $tpl, $section, $name, $width = 50, $params = null ) {
    $value = (is_object( $tpl ) ? $tpl->data->$name : strval( $tpl ));
    $html = '<input type="text"';
    $html .= ' name="' . $name . '"';
    //$html .= ' value="' . htmlspecialchars( $value ) . '"';
    $html .= ' value="' . $value . '"';
    $html .= ' class="text_area"';
    $html .= ' ' . (!is_string( $width ) ? 'size="' . $width . '"' :
    'style="width:' . $width . '"');
    $html .= ($params ? ' ' . $params : '') . ' />';
    return new xclHTML( $section, $name, $html, __FUNCTION__ );
  }

  /**
   * Enter description here...
   *
   * @param unknown_type $tpl
   * @param unknown_type $section
   * @param unknown_type $name
   * @param unknown_type $name2
   * @param unknown_type $width
   * @param unknown_type $params
   * @return unknown
   */
  function textbox2( $tpl, $section, $name, $name2, $width = 50, $params = null ) {
    $value = (is_object( $tpl ) ? $tpl->data->$name : strval( $tpl ));
    $html = '<input type="text"';
    $html .= ' name="' . $name . '"';
    //$html .= ' value="' . htmlspecialchars( $value ) . '"';
    $html .= ' value="' . $value . '"';
    $html .= ' class="text_area"';
    $html .= ' ' . (!is_string( $width ) ? 'size="' . $width . '"' :
    'style="width:' . $width . '"');
    $html .= ($params ? ' ' . $params : '') . ' />';

    $values = array();
    if (@$showGlobal) $values[null] = 'Use Global';
    $values['0'] = _T( strtoupper( '_NO'));
    $values['1'] = _T( strtoupper( '_YES'));

    $value = (is_object( $tpl ) ? $tpl->data->$name2 : strval( $tpl ));
    $html .= _T( 'USE_ALIAS' ).'&nbsp;<select name="use_' . $name . '" class="inputbox" size="1"' .
    ($params ? ' ' . $params : '') . '>';
    foreach ($values as $key => $text) {
      $selected = (strval( $key ) === $value);
      $selected = ($selected ? ' selected="1"' : '');
      //$html .= '<option value="' . htmlspecialchars( $key ) . '"' .
      //  $selected . '>' . $text . '</option>';
      $html .= '<option value="' . $key . '"' .
      $selected . '>' . $text . '</option>';
    }
    $html .= '</select>';
    return new xclHTML( $section, $name, $html, __FUNCTION__ );
  }
  /**
   * Enter description here...
   *
   * @param unknown_type $tpl
   * @param unknown_type $section
   * @param unknown_type $name
   * @param unknown_type $width
   * @param unknown_type $params
   * @return unknown
   */
  function textbox3( $tpl, $section, $name, $width = 50, $params = null ) {
    global $mosConfig_live_site;
    $value = (is_object( $tpl ) ? $tpl->data->$name : strval( $tpl ));
    $html = $mosConfig_live_site.'/<br />';
    $html .= '<input type="text"';
    $html .= ' name="' . $name . '"';
    //$html .= ' value="' . htmlspecialchars( $value ) . '"';
    $html .= ' value="' . $value . '"';
    $html .= ' class="text_area"';
    $html .= ' ' . (!is_string( $width ) ? 'size="' . $width . '"' :
    'style="width:' . $width . '"');
    $html .= ($params ? ' ' . $params : '') . ' />';
    return new xclHTML( $section, $name, $html, __FUNCTION__ );
  }

  /**
   * Enter description here...
   *
   * @param unknown_type $tpl
   * @param unknown_type $section
   * @param unknown_type $name
   * @param unknown_type $rows
   * @param unknown_type $cols
   * @param unknown_type $params
   * @return unknown
   */
  function textarea( $tpl, $section, $name, $rows = 2, $cols = 50, $params = null ) {
    $value = (is_object( $tpl ) ? $tpl->data->$name : strval( $tpl ));
    $html = '<textarea name="' . $name . '"';
    $html .= ' rows="' . $rows . '" cols="' . $cols . '"';
    $html .= ' class="text_area"';
    $html .= ($params ? ' ' . $params : '') . '>';
    //$html .= htmlspecialchars( $value ) . '</textarea>';
    $html .= $value . '</textarea>';
    return new xclHTML( $section, $name, $html, __FUNCTION__ );
  }

  /**
   * Enter description here...
   *
   * @param unknown_type $tpl
   * @param unknown_type $section
   * @param unknown_type $name
   * @param unknown_type $val
   * @param unknown_type $params
   * @return unknown
   */
  function checkbox( $tpl, $section, $name, $val = '1', $params = null ) {
    $value = (is_object( $tpl ) ? $tpl->data->$name : strval( $tpl ));
    $html = '<input type="checkbox"';
    $html .= ' name="' . $name . '"';
    $html .= ' value="' . $val . '"';
    if ($value == $val)
    $html .= ' checked="1"';
    $html .= ' class="text_area"';
    $html .= ($params ? ' ' . $params : '') . ' />';
    $title = _T( strtoupper( $section . '_' . $name ) );
    $html .= '&nbsp;' . $title . '&nbsp;';
    return new xclHTML( $section, $name, $html, __FUNCTION__ );
  }

  /**
   * Enter description here...
   *
   * @param unknown_type $tpl
   * @param unknown_type $section
   * @param unknown_type $name
   * @param unknown_type $values
   * @param unknown_type $params
   * @return unknown
   */
  function select( $tpl, $section, $name, $values, $params = null ) {
    $value = (is_object( $tpl ) ? $tpl->data->$name : strval( $tpl ));
    $html = '<select name="' . $name . '" class="inputbox" size="1"' .
    ($params ? ' ' . $params : '') . '>';
    foreach ($values as $key => $text) {
      $selected = (strval( $key ) === $value);
      $selected = ($selected ? ' selected="1"' : '');
      //$html .= '<option value="' . htmlspecialchars( $key ) . '"' .
      //  $selected . '>' . $text . '</option>';
      $html .= '<option value="' . $key . '"' .
      $selected . '>' . $text . '</option>';
    }
    $html .= '</select>';
    return new xclHTML( $section, $name, $html, __FUNCTION__ );
  }

  /**
   * Enter description here...
   *
   * @param unknown_type $tpl
   * @param unknown_type $section
   * @param unknown_type $name
   * @param unknown_type $values
   * @param unknown_type $selected
   * @return unknown
   */
  function selectLangs( $tpl, $section, $name, $values, $selected=NULL ) {
    reset( $values );
    $params = null;
    $value = (is_object( $tpl ) ? $tpl->data->$name : strval( $tpl ));
    $html = '<select name="' . $name . '" class="inputbox" size="1"' .($params ? ' ' . $params : '') . '>';
    for ($i=0, $n=count( $values ); $i < $n; $i++ ) {
      $k = $values[$i]->value;
      $t = $values[$i]->text;
      $id = ( isset($values[$i]->id) ? @$values[$i]->id : null);

      $extra = '';
      $extra .= $id ? " id=\"" . $values[$i]->id . "\"" : '';
      if (is_array( $selected )) {
        foreach ($selected as $obj) {
          $k2 = $obj->$key;
          if ($k == $k2) {
            $extra .= " selected=\"selected\"";
            break;
          }
        }
      } else {
        $extra .= ($k == $selected ? " selected=\"selected\"" : '');
      }
      $html .= "\n\t<option value=\"".$k."\"$extra>" . $t . "</option>";
    }
    $html .= "\n</select>\n";
    return new xclHTML( $section, $name, $html, __FUNCTION__ );

  }

  /**
   * Enter description here...
   *
   * @param unknown_type $tpl
   * @param unknown_type $section
   * @param unknown_type $name
   * @param unknown_type $showGlobal
   * @param unknown_type $params
   * @return unknown
   */
  function yesNoSelect( $tpl, $section, $name, $showGlobal = false, $params = null ) {
    $values = array();
    if ($showGlobal) $values[null] = 'Use Global';
    $values['0'] = _T( strtoupper( '_NO'));
    $values['1'] = _T( strtoupper( '_YES'));
    return xclHTML::select( $tpl, $section, $name, $values, $params );
  }

  /**
   * Enter description here...
   *
   * @param unknown_type $tpl
   * @param unknown_type $section
   * @param unknown_type $name
   * @param unknown_type $showGlobal
   * @param unknown_type $params
   */
  function yesNoRadio( $tpl, $section, $name, $showGlobal = false, $params = null ) {
    trigger_error( 'TODO: xclHTML::yesNoRadio not implemented yet.', E_USER_WARNING );
  }

  /**
   * Enter description here...
   *
   * @param unknown_type $tpl
   * @param unknown_type $section
   * @param unknown_type $name
   * @param unknown_type $start
   * @param unknown_type $end
   * @param unknown_type $showGlobal
   * @param unknown_type $params
   * @return unknown
   */
  function rangeSelect( $tpl, $section, $name, $start, $end, $showGlobal = false, $params = null ) {
    $values = array();
    if ($showGlobal) $values[null] = 'Use Global';
    for ($i = $start; $i <= $end; $i++)
    $values[$i] = $i;
    return xclHTML::select( $tpl, $section, $name, $values, $params );
  }
}

?>
Return current item: Joomla SEF / SEO - extending OpenSEF