[ Index ]

PHP Cross Reference of Joomla 1.5.26 DE

title

Body

[close]

/administrator/components/com_installer/models/ -> languages.php (source)

   1  <?php
   2  /**
   3   * @version        $Id: languages.php 14401 2010-01-26 14:10:00Z louis $
   4   * @package        Joomla
   5   * @subpackage    Menus
   6   * @copyright    Copyright (C) 2005 - 2010 Open Source Matters. All rights reserved.
   7   * @license        GNU/GPL, see LICENSE.php
   8   * Joomla! is free software. This version may have been modified pursuant to the
   9   * GNU General Public License, and as distributed it includes or is derivative
  10   * of works licensed under the GNU General Public License or other free or open
  11   * source software licenses. See COPYRIGHT.php for copyright notices and
  12   * details.
  13   */
  14  
  15  // no direct access
  16  defined( '_JEXEC' ) or die( 'Restricted access' );
  17  
  18  // Import library dependencies
  19  require_once(dirname(__FILE__).DS.'extension.php');
  20  jimport( 'joomla.filesystem.folder' );
  21  
  22  /**
  23   * Installer Languages Model
  24   *
  25   * @package        Joomla
  26   * @subpackage    Installer
  27   * @since        1.5
  28   */
  29  class InstallerModelLanguages extends InstallerModel
  30  {
  31      /**
  32       * Extension Type
  33       * @var    string
  34       */
  35      var $_type = 'language';
  36  
  37      /**
  38       * Overridden constructor
  39       * @access    protected
  40       */
  41  	function __construct()
  42      {
  43          global $mainframe;
  44  
  45          // Call the parent constructor
  46          parent::__construct();
  47  
  48          // Set state variables from the request
  49          $this->setState('filter.string', $mainframe->getUserStateFromRequest( "com_installer.languages.string", 'filter', '', 'string' ));
  50          $this->setState('filter.client', $mainframe->getUserStateFromRequest( "com_installer.languages.client", 'client', -1, 'int' ));
  51      }
  52  
  53  	function _loadItems()
  54      {
  55          global $mainframe, $option;
  56  
  57          $db = &JFactory::getDBO();
  58  
  59          if ($this->_state->get('filter.client') < 0) {
  60              $client = 'all';
  61              // Get the site languages
  62              $langBDir = JLanguage::getLanguagePath(JPATH_SITE);
  63              $langDirs = JFolder::folders($langBDir);
  64  
  65              for ($i=0; $i < count($langDirs); $i++)
  66              {
  67                  $lang = new stdClass();
  68                  $lang->folder = $langDirs[$i];
  69                  $lang->client = 0;
  70                  $lang->baseDir = $langBDir;
  71                  $languages[] = $lang;
  72              }
  73              // Get the admin languages
  74              $langBDir = JLanguage::getLanguagePath(JPATH_ADMINISTRATOR);
  75              $langDirs = JFolder::folders($langBDir);
  76  
  77              for ($i=0; $i < count($langDirs); $i++)
  78              {
  79                  $lang = new stdClass();
  80                  $lang->folder = $langDirs[$i];
  81                  $lang->client = 1;
  82                  $lang->baseDir = $langBDir;
  83                  $languages[] = $lang;
  84              }
  85          }
  86          else
  87          {
  88              $clientInfo =& JApplicationHelper::getClientInfo($this->_state->get('filter.client'));
  89              $client = $clientInfo->name;
  90              $langBDir = JLanguage::getLanguagePath($clientInfo->path);
  91              $langDirs = JFolder::folders($langBDir);
  92  
  93              for ($i=0, $n=count($langDirs); $i < $n; $i++)
  94              {
  95                  $lang = new stdClass();
  96                  $lang->folder = $langDirs[$i];
  97                  $lang->client = $clientInfo->id;
  98                  $lang->baseDir = $langBDir;
  99  
 100                  if ($this->_state->get('filter.string')) {
 101                      if (strpos($lang->folder, $this->_state->get('filter.string')) !== false) {
 102                          $languages[] = $lang;
 103                      }
 104                  } else {
 105                      $languages[] = $lang;
 106                  }
 107              }
 108          }
 109  
 110          $rows = array();
 111          $rowid = 0;
 112          foreach ($languages as $language)
 113          {
 114              $files = JFolder::files( $language->baseDir.DS.$language->folder, '^([-_A-Za-z]*)\.xml$' );
 115              foreach ($files as $file)
 116              {
 117                  $data = JApplicationHelper::parseXMLLangMetaFile($language->baseDir.DS.$language->folder.DS.$file);
 118  
 119                  $row             = new StdClass();
 120                  $row->id         = $rowid;
 121                  $row->client_id = $language->client;
 122                  $row->language     = $language->baseDir.DS.$language->folder;
 123  
 124                  // If we didn't get valid data from the xml file, move on...
 125                  if (!is_array($data)) {
 126                      continue;
 127                  }
 128  
 129                  // Populate the row from the xml meta file
 130                  foreach($data as $key => $value) {
 131                      $row->$key = $value;
 132                  }
 133  
 134                  // if current than set published
 135                  $clientVals =& JApplicationHelper::getClientInfo($row->client_id);
 136                  $lang = JComponentHelper::getParams('com_languages');
 137                  if ( $lang->get($clientVals->name, 'en-GB') == basename( $row->language ) ) {
 138                      $row->published    = 1;
 139                  } else {
 140                      $row->published = 0;
 141                  }
 142  
 143                  $row->checked_out = 0;
 144                  $row->jname = JString::strtolower( str_replace( " ", "_", $row->name ) );
 145                  $rows[] = $row;
 146                  $rowid++;
 147              }
 148          }
 149          $this->setState('pagination.total', count($rows));
 150          // if the offset is greater than the total, then can the offset
 151          if($this->_state->get('pagination.offset') > $this->_state->get('pagination.total')) {
 152              $this->setState('pagination.offset',0);
 153          }
 154  
 155          if($this->_state->get('pagination.limit') > 0) {
 156              $this->_items = array_slice( $rows, $this->_state->get('pagination.offset'), $this->_state->get('pagination.limit') );
 157          } else {
 158              $this->_items = $rows;
 159          }
 160      }
 161  
 162      /**
 163       * Remove (uninstall) an extension
 164       *
 165       * @static
 166       * @return boolean True on success
 167       * @since 1.0
 168       */
 169  	function remove($eid=array())
 170      {
 171          global $mainframe;
 172  
 173          $lang =& JFactory::getLanguage();
 174          $lang->load('com_installer');
 175  
 176          // Initialize variables
 177          $failed = array ();
 178  
 179          /*
 180           * Ensure eid is an array of extension ids
 181           * TODO: If it isn't an array do we want to set an error and fail?
 182           */
 183          if (!is_array($eid)) {
 184              $eid = array ($eid);
 185          }
 186          // construct the list of all language
 187          $this->_loadItems();
 188  
 189          // Get a database connector
 190          $db =& JFactory::getDBO();
 191  
 192          // Get an installer object for the extension type
 193          jimport('joomla.installer.installer');
 194          $installer    =& JInstaller::getInstance($db, $this->_type);
 195  
 196          // Uninstall the chosen extensions
 197          foreach ($eid as $id)
 198          {
 199              $item = $this->_items[$id];
 200  
 201              // Get client information
 202              $client    =& JApplicationHelper::getClientInfo($item->client_id);
 203  
 204              // Don't delete a default ( published language )
 205              $params = JComponentHelper::getParams('com_languages');
 206              $tag    = basename($item->language);
 207              if ( $params->get($client->name, 'en-GB') == $tag ) {
 208                  $failed[]    = $id;
 209                  JError::raiseWarning('', JText::_('UNINSTALLLANGPUBLISHEDALREADY'));
 210                  return;
 211              }
 212  
 213              $result = $installer->uninstall( 'language', $item->language );
 214  
 215              // Build an array of extensions that failed to uninstall
 216              if ($result === false) {
 217                  $failed[] = $id;
 218              }
 219          }
 220  
 221          if (count($failed)) {
 222              // There was an error in uninstalling the package
 223              $msg = JText::sprintf('UNINSTALLEXT', JText::_($this->_type), JText::_('Error'));
 224              $result = false;
 225          } else {
 226              // Package uninstalled sucessfully
 227              $msg = JText::sprintf('UNINSTALLEXT', JText::_($this->_type), JText::_('Success'));
 228              $result = true;
 229          }
 230  
 231          $mainframe->enqueueMessage($msg);
 232          $this->setState('action', 'remove');
 233          $this->setState('message', $installer->message);
 234          // re-construct the list of all language
 235          $this->_loadItems();
 236  
 237          return $result;
 238      }
 239  }


Generated: Wed Mar 28 15:54:07 2012 Cross-referenced by PHPXref 0.7.1