Annotation of /mambo/branches/4.6/administrator/components/com_languages/admin.languages.php
Parent Directory
|
Revision Log
Revision 1 -
(view)
(download)
Original Path: mambo/trunk/administrator/components/com_languages/admin.languages.php
| 1 : | root | 1 | <?php |
| 2 : | /** | ||
| 3 : | * @version $Id: admin.languages.php,v 1.1 2005/07/22 01:52:34 eddieajau Exp $ | ||
| 4 : | * @package Mambo | ||
| 5 : | * @subpackage Languages | ||
| 6 : | * @copyright (C) 2000 - 2005 Miro International Pty Ltd | ||
| 7 : | * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL | ||
| 8 : | * Mambo is Free Software | ||
| 9 : | */ | ||
| 10 : | |||
| 11 : | /** ensure this file is being included by a parent file */ | ||
| 12 : | defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' ); | ||
| 13 : | |||
| 14 : | // ensure user has access to this function | ||
| 15 : | if (!$acl->acl_check( 'administration', 'config', 'users', $my->usertype )) { | ||
| 16 : | mosRedirect( 'index2.php', _NOT_AUTH ); | ||
| 17 : | } | ||
| 18 : | |||
| 19 : | |||
| 20 : | require_once( $mainframe->getPath( 'admin_html' ) ); | ||
| 21 : | // XML library | ||
| 22 : | require_once( "$mosConfig_absolute_path/includes/domit/xml_domit_lite_include.php" ); | ||
| 23 : | |||
| 24 : | $task = trim( strtolower( mosGetParam( $_REQUEST, "task", "" ) ) ); | ||
| 25 : | $cid = mosGetParam( $_REQUEST, "cid", array(0) ); | ||
| 26 : | |||
| 27 : | if (!is_array( $cid )) { | ||
| 28 : | $cid = array(0); | ||
| 29 : | } | ||
| 30 : | |||
| 31 : | switch ($task) { | ||
| 32 : | case "new": | ||
| 33 : | mosRedirect( "index2.php?option=com_installer&element=language" ); | ||
| 34 : | break; | ||
| 35 : | |||
| 36 : | case "edit_source": | ||
| 37 : | editLanguageSource( $cid[0], $option ); | ||
| 38 : | break; | ||
| 39 : | |||
| 40 : | case "save_source": | ||
| 41 : | saveLanguageSource( $option ); | ||
| 42 : | break; | ||
| 43 : | |||
| 44 : | case "remove": | ||
| 45 : | removeLanguage( $cid[0], $option ); | ||
| 46 : | break; | ||
| 47 : | |||
| 48 : | case "publish": | ||
| 49 : | publishLanguage( $cid[0], $option ); | ||
| 50 : | break; | ||
| 51 : | |||
| 52 : | case "cancel": | ||
| 53 : | mosRedirect( "index2.php?option=$option" ); | ||
| 54 : | break; | ||
| 55 : | |||
| 56 : | default: | ||
| 57 : | viewLanguages( $option ); | ||
| 58 : | break; | ||
| 59 : | } | ||
| 60 : | |||
| 61 : | /** | ||
| 62 : | * Compiles a list of installed languages | ||
| 63 : | */ | ||
| 64 : | function viewLanguages( $option ) { | ||
| 65 : | global $languages; | ||
| 66 : | global $mainframe; | ||
| 67 : | global $mosConfig_lang, $mosConfig_absolute_path, $mosConfig_list_limit; | ||
| 68 : | |||
| 69 : | $limit = $mainframe->getUserStateFromRequest( "viewlistlimit", 'limit', $mosConfig_list_limit ); | ||
| 70 : | $limitstart = $mainframe->getUserStateFromRequest( "view{$option}limitstart", 'limitstart', 0 ); | ||
| 71 : | |||
| 72 : | // get current languages | ||
| 73 : | $cur_language = $mosConfig_lang; | ||
| 74 : | |||
| 75 : | $rows = array(); | ||
| 76 : | // Read the template dir to find templates | ||
| 77 : | $languageBaseDir = mosPathName(mosPathName($mosConfig_absolute_path) . "language"); | ||
| 78 : | |||
| 79 : | $rowid = 0; | ||
| 80 : | |||
| 81 : | $xmlFilesInDir = mosReadDirectory($languageBaseDir,'.xml$'); | ||
| 82 : | |||
| 83 : | $dirName = $languageBaseDir; | ||
| 84 : | foreach($xmlFilesInDir as $xmlfile) { | ||
| 85 : | // Read the file to see if it's a valid template XML file | ||
| 86 : | $xmlDoc =& new DOMIT_Lite_Document(); | ||
| 87 : | $xmlDoc->resolveErrors( true ); | ||
| 88 : | if (!$xmlDoc->loadXML( $dirName . $xmlfile, false, true )) { | ||
| 89 : | continue; | ||
| 90 : | } | ||
| 91 : | |||
| 92 : | $element = &$xmlDoc->documentElement; | ||
| 93 : | |||
| 94 : | if ($element->getTagName() != 'mosinstall') { | ||
| 95 : | continue; | ||
| 96 : | } | ||
| 97 : | if ($element->getAttribute( "type" ) != "language") { | ||
| 98 : | continue; | ||
| 99 : | } | ||
| 100 : | |||
| 101 : | $row = new StdClass(); | ||
| 102 : | $row->id = $rowid; | ||
| 103 : | $row->language = substr($xmlfile,0,-4); | ||
| 104 : | $element = &$xmlDoc->getElementsByPath('name', 1 ); | ||
| 105 : | $row->name = $element->getText(); | ||
| 106 : | |||
| 107 : | $element = &$xmlDoc->getElementsByPath('creationDate', 1); | ||
| 108 : | $row->creationdate = $element ? $element->getText() : 'Unknown'; | ||
| 109 : | |||
| 110 : | $element = &$xmlDoc->getElementsByPath('author', 1); | ||
| 111 : | $row->author = $element ? $element->getText() : 'Unknown'; | ||
| 112 : | |||
| 113 : | $element = &$xmlDoc->getElementsByPath('copyright', 1); | ||
| 114 : | $row->copyright = $element ? $element->getText() : ''; | ||
| 115 : | |||
| 116 : | $element = &$xmlDoc->getElementsByPath('authorEmail', 1); | ||
| 117 : | $row->authorEmail = $element ? $element->getText() : ''; | ||
| 118 : | |||
| 119 : | $element = &$xmlDoc->getElementsByPath('authorUrl', 1); | ||
| 120 : | $row->authorUrl = $element ? $element->getText() : ''; | ||
| 121 : | |||
| 122 : | $element = &$xmlDoc->getElementsByPath('version', 1); | ||
| 123 : | $row->version = $element ? $element->getText() : ''; | ||
| 124 : | |||
| 125 : | // if current than set published | ||
| 126 : | if ($cur_language == $row->language) { | ||
| 127 : | $row->published = 1; | ||
| 128 : | } else { | ||
| 129 : | $row->published = 0; | ||
| 130 : | } | ||
| 131 : | |||
| 132 : | $row->checked_out = 0; | ||
| 133 : | $row->mosname = strtolower( str_replace( " ", "_", $row->name ) ); | ||
| 134 : | $rows[] = $row; | ||
| 135 : | $rowid++; | ||
| 136 : | } | ||
| 137 : | |||
| 138 : | require_once( $GLOBALS['mosConfig_absolute_path'] . '/administrator/includes/pageNavigation.php' ); | ||
| 139 : | $pageNav = new mosPageNav( count( $rows ), $limitstart, $limit ); | ||
| 140 : | |||
| 141 : | $rows = array_slice( $rows, $pageNav->limitstart, $pageNav->limit ); | ||
| 142 : | |||
| 143 : | HTML_languages::showLanguages( $cur_language, $rows, $pageNav, $option ); | ||
| 144 : | } | ||
| 145 : | |||
| 146 : | /** | ||
| 147 : | * Publish, or make current, the selected language | ||
| 148 : | */ | ||
| 149 : | function publishLanguage( $p_lname, $option ) { | ||
| 150 : | global $mosConfig_lang; | ||
| 151 : | |||
| 152 : | $config = ""; | ||
| 153 : | |||
| 154 : | $fp = fopen("../configuration.php","r"); | ||
| 155 : | while(!feof($fp)){ | ||
| 156 : | $buffer = fgets($fp,4096); | ||
| 157 : | if (strstr($buffer,"\$mosConfig_lang")){ | ||
| 158 : | $config .= "\$mosConfig_lang = \"$p_lname\";\n"; | ||
| 159 : | } else { | ||
| 160 : | $config .= $buffer; | ||
| 161 : | } | ||
| 162 : | } | ||
| 163 : | fclose($fp); | ||
| 164 : | |||
| 165 : | if ($fp = fopen("../configuration.php","w")){ | ||
| 166 : | fputs($fp, $config, strlen($config)); | ||
| 167 : | fclose($fp); | ||
| 168 : | mosRedirect("index2.php","Configuration succesfully updated!"); | ||
| 169 : | } else { | ||
| 170 : | mosRedirect("index2.php","Error! Make sure that configuration.php is writeable."); | ||
| 171 : | } | ||
| 172 : | |||
| 173 : | } | ||
| 174 : | |||
| 175 : | /** | ||
| 176 : | * Remove the selected language | ||
| 177 : | */ | ||
| 178 : | function removeLanguage( $cid, $option, $client ) { | ||
| 179 : | global $mosConfig_lang; | ||
| 180 : | |||
| 181 : | $client_id = $client=='admin' ? 1 : 0; | ||
| 182 : | |||
| 183 : | $cur_language = $mosConfig_lang; | ||
| 184 : | |||
| 185 : | if ($cur_language == $cid) { | ||
| 186 : | echo "<script>alert(\"You can not delete language in use.\"); window.history.go(-1); </script>\n"; | ||
| 187 : | exit(); | ||
| 188 : | } | ||
| 189 : | |||
| 190 : | /*$lang_path = "../language/$cid.php"; | ||
| 191 : | $lang_ignore_path = "../language/$cid.ignore.php"; | ||
| 192 : | $xml_path = "../language/$cid.xml"; | ||
| 193 : | |||
| 194 : | unlink($lang_path); | ||
| 195 : | unlink($lang_ignore_path); | ||
| 196 : | unlink($xml_path); | ||
| 197 : | */ | ||
| 198 : | |||
| 199 : | mosRedirect( 'index2.php?option=com_installer&element=language&client='. $client .'&task=remove&cid[]='. $cid ); | ||
| 200 : | |||
| 201 : | } | ||
| 202 : | |||
| 203 : | function editLanguageSource( $p_lname, $option) { | ||
| 204 : | $file = stripslashes( "../language/$p_lname.php" ); | ||
| 205 : | |||
| 206 : | if ($fp = fopen( $file, "r" )) { | ||
| 207 : | $content = fread( $fp, filesize( $file ) ); | ||
| 208 : | $content = htmlspecialchars( $content ); | ||
| 209 : | |||
| 210 : | HTML_languages::editLanguageSource( $p_lname, $content, $option ); | ||
| 211 : | } else { | ||
| 212 : | mosRedirect( "index2.php?option=$option&mosmsg=Operation Failed: Could not open $file" ); | ||
| 213 : | } | ||
| 214 : | } | ||
| 215 : | |||
| 216 : | function saveLanguageSource( $option ) { | ||
| 217 : | $language = trim( mosGetParam( $_POST, 'language', '' ) ); | ||
| 218 : | $filecontent = mosGetParam( $_POST, 'filecontent', '', _MOS_ALLOWHTML ); | ||
| 219 : | |||
| 220 : | if (!$language) { | ||
| 221 : | mosRedirect( "index2.php?option=$option&mosmsg=Operation failed: No language specified." ); | ||
| 222 : | } | ||
| 223 : | if (!$filecontent) { | ||
| 224 : | mosRedirect( "index2.php?option=$option&mosmsg=Operation failed: Content empty." ); | ||
| 225 : | } | ||
| 226 : | |||
| 227 : | $file = "../language/$language.php"; | ||
| 228 : | $enable_write = mosGetParam($_POST,'enable_write',0); | ||
| 229 : | $oldperms = fileperms($file); | ||
| 230 : | if ($enable_write) @chmod($file, $oldperms | 0222); | ||
| 231 : | |||
| 232 : | clearstatcache(); | ||
| 233 : | if (is_writable( $file ) == false) { | ||
| 234 : | mosRedirect( "index2.php?option=$option&mosmsg=Operation failed: The file is not writable." ); | ||
| 235 : | } | ||
| 236 : | |||
| 237 : | if ($fp = fopen ($file, "w")) { | ||
| 238 : | fputs( $fp, stripslashes( $filecontent ) ); | ||
| 239 : | fclose( $fp ); | ||
| 240 : | if ($enable_write) { | ||
| 241 : | @chmod($file, $oldperms); | ||
| 242 : | } else { | ||
| 243 : | if (mosGetParam($_POST,'disable_write',0)) | ||
| 244 : | @chmod($file, $oldperms & 0777555); | ||
| 245 : | } // if | ||
| 246 : | mosRedirect( "index2.php?option=$option" ); | ||
| 247 : | } else { | ||
| 248 : | if ($enable_write) @chmod($file, $oldperms); | ||
| 249 : | mosRedirect( "index2.php?option=$option&mosmsg=Operation failed: Failed to open file for writing." ); | ||
| 250 : | } | ||
| 251 : | |||
| 252 : | } | ||
| 253 : | |||
| 254 : | ?> |
| ViewVC Help | |
| Powered by ViewVC 1.0.0 |
Web Hosting provided by Network Redux.

