Annotation of /mambo/trunk/administrator/components/com_installer/component/component.class.php
Parent Directory
|
Revision Log
Revision 1 - (view) (download)
| 1 : | root | 1 | <?php |
| 2 : | /** | ||
| 3 : | * @version $Id: component.class.php,v 1.1 2005/07/22 01:52:30 eddieajau Exp $ | ||
| 4 : | * @package Mambo | ||
| 5 : | * @subpackage Installer | ||
| 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 : | /** | ||
| 15 : | * Component installer | ||
| 16 : | * @package Mambo | ||
| 17 : | * @subpackage Installer | ||
| 18 : | */ | ||
| 19 : | class mosInstallerComponent extends mosInstaller { | ||
| 20 : | var $i_componentadmindir = ""; | ||
| 21 : | var $i_hasinstallfile = false; | ||
| 22 : | var $i_installfile = ""; | ||
| 23 : | |||
| 24 : | function componentAdminDir($p_dirname = null) { | ||
| 25 : | if(!is_null($p_dirname)) { | ||
| 26 : | $this->i_componentadmindir = mosPathName($p_dirname); | ||
| 27 : | } | ||
| 28 : | return $this->i_componentadmindir; | ||
| 29 : | } | ||
| 30 : | |||
| 31 : | /** | ||
| 32 : | * Custom install method | ||
| 33 : | * @param boolean True if installing from directory | ||
| 34 : | */ | ||
| 35 : | function install($p_fromdir = null) { | ||
| 36 : | global $mosConfig_absolute_path,$database; | ||
| 37 : | |||
| 38 : | if (!$this->preInstallCheck( $p_fromdir, 'component' )) { | ||
| 39 : | return false; | ||
| 40 : | } | ||
| 41 : | |||
| 42 : | // aje moved down to here. ?? seemed to be some referencing problems | ||
| 43 : | $xml = $this->xmlDoc(); | ||
| 44 : | |||
| 45 : | // Set some vars | ||
| 46 : | $e = &$xml->getElementsByPath('name', 1); | ||
| 47 : | $this->elementName($e->getText()); | ||
| 48 : | $this->elementDir( mosPathName( $mosConfig_absolute_path . "/components/" | ||
| 49 : | . strtolower("com_" . str_replace(" ","",$this->elementName())) . "/" ) | ||
| 50 : | ); | ||
| 51 : | $this->componentAdminDir( mosPathName( $mosConfig_absolute_path . "/administrator/components/" | ||
| 52 : | . strtolower( "com_" . str_replace( " ","",$this->elementName() ) ) ) | ||
| 53 : | ); | ||
| 54 : | |||
| 55 : | if (file_exists($this->elementDir())) { | ||
| 56 : | $this->setError( 1, 'Another component is already using directory: "' . $this->elementDir() . '"' ); | ||
| 57 : | return false; | ||
| 58 : | } | ||
| 59 : | |||
| 60 : | if(!file_exists($this->elementDir()) && !mosMakePath($this->elementDir())) { | ||
| 61 : | $this->setError( 1, 'Failed to create directory "' . $this->elementDir() . '"' ); | ||
| 62 : | return false; | ||
| 63 : | } | ||
| 64 : | |||
| 65 : | if(!file_exists($this->componentAdminDir()) && !mosMakePath($this->componentAdminDir())) { | ||
| 66 : | $this->setError( 1, 'Failed to create directory "' . $this->componentAdminDir() . '"' ); | ||
| 67 : | return false; | ||
| 68 : | } | ||
| 69 : | |||
| 70 : | // Find files to copy | ||
| 71 : | if ($this->parseFiles( 'files' ) === false) { | ||
| 72 : | return false; | ||
| 73 : | } | ||
| 74 : | $this->parseFiles( 'images' ); | ||
| 75 : | $this->parseFiles( 'administration/files','','',1 ); | ||
| 76 : | $this->parseFiles( 'administration/images','','',1 ); | ||
| 77 : | |||
| 78 : | // Are there any SQL queries?? | ||
| 79 : | $query_element = &$xml->getElementsByPath('install/queries', 1); | ||
| 80 : | if (!is_null($query_element)) { | ||
| 81 : | $queries = $query_element->childNodes; | ||
| 82 : | foreach($queries as $query) | ||
| 83 : | { | ||
| 84 : | $database->setQuery( $query->getText()); | ||
| 85 : | if (!$database->query()) | ||
| 86 : | { | ||
| 87 : | $this->setError( 1, "SQL Error " . $database->stderr( true ) ); | ||
| 88 : | return false; | ||
| 89 : | } | ||
| 90 : | } | ||
| 91 : | } | ||
| 92 : | |||
| 93 : | // Is there an installfile | ||
| 94 : | $installfile_elemet = &$xml->getElementsByPath('installfile', 1); | ||
| 95 : | |||
| 96 : | if (!is_null($installfile_elemet)) { | ||
| 97 : | // check if parse files has already copied the install.component.php file (error in 3rd party xml's!) | ||
| 98 : | if (!file_exists($this->componentAdminDir().$installfile_elemet->getText())) { | ||
| 99 : | if(!$this->copyFiles($this->installDir(), $this->componentAdminDir(), array($installfile_elemet->getText()))) { | ||
| 100 : | $this->setError( 1, 'Could not copy PHP install file.' ); | ||
| 101 : | return false; | ||
| 102 : | } | ||
| 103 : | } | ||
| 104 : | $this->hasInstallfile(true); | ||
| 105 : | $this->installFile($installfile_elemet->getText()); | ||
| 106 : | } | ||
| 107 : | // Is there an uninstallfile | ||
| 108 : | $uninstallfile_elemet = &$xml->getElementsByPath('uninstallfile',1); | ||
| 109 : | if(!is_null($uninstallfile_elemet)) { | ||
| 110 : | if (!file_exists($this->componentAdminDir().$uninstallfile_elemet->getText())) { | ||
| 111 : | if(!$this->copyFiles($this->installDir(), $this->componentAdminDir(), array($uninstallfile_elemet->getText()))) { | ||
| 112 : | $this->setError( 1, 'Could not copy PHP uninstall file' ); | ||
| 113 : | return false; | ||
| 114 : | } | ||
| 115 : | } | ||
| 116 : | } | ||
| 117 : | |||
| 118 : | // Is the menues ? | ||
| 119 : | $adminmenu_element = &$xml->getElementsByPath('administration/menu',1); | ||
| 120 : | if(!is_null($adminmenu_element)) | ||
| 121 : | { | ||
| 122 : | $adminsubmenu_element = &$xml->getElementsByPath('administration/submenu',1); | ||
| 123 : | $com_name = strtolower("com_" . str_replace(" ","",$this->elementName())); | ||
| 124 : | $com_admin_menuname = $adminmenu_element->getText(); | ||
| 125 : | |||
| 126 : | if(!is_null($adminsubmenu_element)) | ||
| 127 : | { | ||
| 128 : | $com_admin_menu_id = $this->createParentMenu($com_admin_menuname,$com_name); | ||
| 129 : | if($com_admin_menu_id === false) | ||
| 130 : | { | ||
| 131 : | return false; | ||
| 132 : | } | ||
| 133 : | $com_admin_submenus = $adminsubmenu_element->childNodes; | ||
| 134 : | |||
| 135 : | $submenuordering = 0; | ||
| 136 : | foreach($com_admin_submenus as $admin_submenu) | ||
| 137 : | { | ||
| 138 : | $com = new mosComponent( $database ); | ||
| 139 : | $com->name = $admin_submenu->getText(); | ||
| 140 : | $com->link = ''; | ||
| 141 : | $com->menuid = 0; | ||
| 142 : | $com->parent = $com_admin_menu_id; | ||
| 143 : | $com->iscore = 0; | ||
| 144 : | |||
| 145 : | if ( $admin_submenu->getAttribute("act")) | ||
| 146 : | { | ||
| 147 : | $com->admin_menu_link = "option=$com_name&act=" . $admin_submenu->getAttribute("act"); | ||
| 148 : | } | ||
| 149 : | else if ($admin_submenu->getAttribute("task")) | ||
| 150 : | { | ||
| 151 : | $com->admin_menu_link = "option=$com_name&task=" . $admin_submenu->getAttribute("task"); | ||
| 152 : | } | ||
| 153 : | else if ($admin_submenu->getAttribute("link")) | ||
| 154 : | { | ||
| 155 : | $com->admin_menu_link = $admin_submenu->getAttribute("link"); | ||
| 156 : | } | ||
| 157 : | else | ||
| 158 : | { | ||
| 159 : | $com->admin_menu_link = "option=$com_name"; | ||
| 160 : | } | ||
| 161 : | $com->admin_menu_alt = $admin_submenu->getText(); | ||
| 162 : | $com->option = $com_name; | ||
| 163 : | $com->ordering = $submenuordering++; | ||
| 164 : | $com->admin_menu_img = "js/ThemeOffice/component.png"; | ||
| 165 : | |||
| 166 : | if (!$com->store()) | ||
| 167 : | { | ||
| 168 : | $this->setError( 1, $database->stderr( true ) ); | ||
| 169 : | return false; | ||
| 170 : | } | ||
| 171 : | } | ||
| 172 : | } | ||
| 173 : | else | ||
| 174 : | { | ||
| 175 : | $this->createParentMenu($com_admin_menuname,$com_name); | ||
| 176 : | } | ||
| 177 : | } | ||
| 178 : | |||
| 179 : | $desc= ''; | ||
| 180 : | if ($e = &$xml->getElementsByPath( 'description', 1 )) { | ||
| 181 : | $desc = $this->elementName() . '<p>' . $e->getText() . '</p>'; | ||
| 182 : | } | ||
| 183 : | $this->setError( 0, $desc ); | ||
| 184 : | |||
| 185 : | if ($this->hasInstallfile()) { | ||
| 186 : | if (is_file($this->componentAdminDir() . '/' . $this->installFile())) { | ||
| 187 : | require_once($this->componentAdminDir() . "/" . $this->installFile()); | ||
| 188 : | $ret = com_install(); | ||
| 189 : | if ($ret != '') { | ||
| 190 : | $this->setError( 0, $desc . $ret ); | ||
| 191 : | } | ||
| 192 : | } | ||
| 193 : | } | ||
| 194 : | return $this->copySetupFile(); | ||
| 195 : | } | ||
| 196 : | |||
| 197 : | function createParentMenu($_menuname,$_comname, $_image = "js/ThemeOffice/component.png") { | ||
| 198 : | global $database; | ||
| 199 : | $db_name = $_menuname; | ||
| 200 : | $db_link = "option=$_comname"; | ||
| 201 : | $db_menuid = 0; | ||
| 202 : | $db_parent = 0; | ||
| 203 : | $db_admin_menu_link = "option=$_comname"; | ||
| 204 : | $db_admin_menu_alt = $_menuname; | ||
| 205 : | $db_option = $_comname; | ||
| 206 : | $db_ordering = 0; | ||
| 207 : | $db_admin_menu_img = $_image; | ||
| 208 : | $db_iscore = 0; | ||
| 209 : | $db_params = ''; | ||
| 210 : | |||
| 211 : | $sql = "INSERT INTO #__components "; | ||
| 212 : | $sql .=" VALUES('','$db_name','$db_link','$db_menuid','$db_parent','$db_admin_menu_link','$db_admin_menu_alt','$db_option','$db_ordering','$db_admin_menu_img',$db_iscore,'')"; | ||
| 213 : | $database->setQuery($sql); | ||
| 214 : | if(!$database->query()) | ||
| 215 : | { | ||
| 216 : | $this->setError( 1, $database->stderr( true ) ); | ||
| 217 : | return false; | ||
| 218 : | } | ||
| 219 : | $menuid = $database->insertid(); | ||
| 220 : | return $menuid; | ||
| 221 : | } | ||
| 222 : | /** | ||
| 223 : | * Custom install method | ||
| 224 : | * @param int The id of the module | ||
| 225 : | * @param string The URL option | ||
| 226 : | * @param int The client id | ||
| 227 : | */ | ||
| 228 : | function uninstall( $cid, $option, $client=0 ) { | ||
| 229 : | global $database,$mosConfig_absolute_path; | ||
| 230 : | |||
| 231 : | $uninstallret = ""; | ||
| 232 : | |||
| 233 : | $sql = "SELECT * FROM #__components WHERE id=$cid"; | ||
| 234 : | $database->setQuery($sql); | ||
| 235 : | |||
| 236 : | $row = null; | ||
| 237 : | if (!$database->loadObject( $row )) { | ||
| 238 : | HTML_installer::showInstallMessage($database->stderr(true),'Uninstall - error', | ||
| 239 : | $this->returnTo( $option, 'component', $client ) ); | ||
| 240 : | exit(); | ||
| 241 : | } | ||
| 242 : | |||
| 243 : | if ($row->iscore) { | ||
| 244 : | HTML_installer::showInstallMessage("Component $row->name is a core component, and can not be uninstalled.<br />You need to unpublish it if you don't want to use it", 'Uninstall - error', | ||
| 245 : | $this->returnTo( $option, 'component', $client ) ); | ||
| 246 : | exit(); | ||
| 247 : | } | ||
| 248 : | |||
| 249 : | // Delete entries in the DB | ||
| 250 : | $sql = "DELETE FROM #__components WHERE parent=$row->id"; | ||
| 251 : | $database->setQuery($sql); | ||
| 252 : | if (!$database->query()) { | ||
| 253 : | HTML_installer::showInstallMessage($database->stderr(true),'Uninstall - error', | ||
| 254 : | $this->returnTo( $option, 'component', $client ) ); | ||
| 255 : | exit(); | ||
| 256 : | } | ||
| 257 : | |||
| 258 : | $sql = "DELETE FROM #__components WHERE id=$row->id"; | ||
| 259 : | $database->setQuery($sql); | ||
| 260 : | if (!$database->query()) { | ||
| 261 : | HTML_installer::showInstallMessage($database->stderr(true),'Uninstall - error', | ||
| 262 : | $this->returnTo( $option, 'component', $client ) ); | ||
| 263 : | exit(); | ||
| 264 : | } | ||
| 265 : | |||
| 266 : | // Try to find the uninstall file | ||
| 267 : | $filesindir = mosReadDirectory( $mosConfig_absolute_path.'/administrator/components/'.$row->option, 'uninstall' ); | ||
| 268 : | if (count( $filesindir ) > 0) { | ||
| 269 : | $uninstall_file = $filesindir[0]; | ||
| 270 : | if(file_exists($mosConfig_absolute_path.'/administrator/components/'.$row->option .'/'.$uninstall_file)) | ||
| 271 : | { | ||
| 272 : | require_once($mosConfig_absolute_path.'/administrator/components/'.$row->option .'/'.$uninstall_file ); | ||
| 273 : | $uninstallret = com_uninstall(); | ||
| 274 : | } | ||
| 275 : | } | ||
| 276 : | |||
| 277 : | // Try to find the XML file | ||
| 278 : | $filesindir = mosReadDirectory( mosPathName( $mosConfig_absolute_path.'/administrator/components/'.$row->option ), '.xml$'); | ||
| 279 : | if (count($filesindir) > 0) { | ||
| 280 : | $ismosinstall = false; | ||
| 281 : | foreach ($filesindir as $file) { | ||
| 282 : | $xmlDoc =& new DOMIT_Lite_Document(); | ||
| 283 : | $xmlDoc->resolveErrors( true ); | ||
| 284 : | if (!$xmlDoc->loadXML( $mosConfig_absolute_path."/administrator/components/".$row->option . "/" . $file, false, true )) { | ||
| 285 : | return false; | ||
| 286 : | } | ||
| 287 : | $element = &$xmlDoc->documentElement; | ||
| 288 : | |||
| 289 : | if ($element->getTagName() != 'mosinstall') { | ||
| 290 : | HTML_installer::showInstallMessage('XML File invalid','Uninstall - error', | ||
| 291 : | $this->returnTo( $option, 'component', $client ) ); | ||
| 292 : | exit(); | ||
| 293 : | } | ||
| 294 : | |||
| 295 : | $query_element = &$xmlDoc->getElementsbyPath( 'uninstall/queries', 1 ); | ||
| 296 : | if(!is_null($query_element)) | ||
| 297 : | { | ||
| 298 : | $queries = $query_element->childNodes; | ||
| 299 : | foreach($queries as $query) | ||
| 300 : | { | ||
| 301 : | $database->setQuery( $query->getText()); | ||
| 302 : | if (!$database->query()) | ||
| 303 : | { | ||
| 304 : | HTML_installer::showInstallMessage($database->stderr(true),'Uninstall - error', | ||
| 305 : | $this->returnTo( $option, 'component', $client ) ); | ||
| 306 : | exit(); | ||
| 307 : | } | ||
| 308 : | } | ||
| 309 : | } | ||
| 310 : | } | ||
| 311 : | } else { | ||
| 312 : | /* | ||
| 313 : | HTML_installer::showInstallMessage( 'Could not find XML Setup file in '.$mosConfig_absolute_path.'/administrator/components/'.$row->option, | ||
| 314 : | 'Uninstall - error', $option, 'component' ); | ||
| 315 : | exit(); | ||
| 316 : | */ | ||
| 317 : | } | ||
| 318 : | |||
| 319 : | // Delete directories | ||
| 320 : | |||
| 321 : | if (trim( $row->option )) { | ||
| 322 : | $result = 0; | ||
| 323 : | $path = mosPathName( $mosConfig_absolute_path.'/administrator/components/' . $row->option ); | ||
| 324 : | if (is_dir( $path )) { | ||
| 325 : | $result |= deldir( $path ); | ||
| 326 : | } | ||
| 327 : | $path = mosPathName( $mosConfig_absolute_path.'/components/'.$row->option ); | ||
| 328 : | if (is_dir( $path )) { | ||
| 329 : | $result |= deldir( $path ); | ||
| 330 : | } | ||
| 331 : | return $result; | ||
| 332 : | } else { | ||
| 333 : | HTML_installer::showInstallMessage( 'Option field empty, cannot remove files', 'Uninstall - error', $option,'component'); | ||
| 334 : | exit(); | ||
| 335 : | } | ||
| 336 : | |||
| 337 : | return $uninstallret; | ||
| 338 : | } | ||
| 339 : | } | ||
| 340 : | ?> |
| ViewVC Help | |
| Powered by ViewVC 1.0.0 |
Web Hosting provided by Network Redux.

