| [ Index ] |
PHP Cross Reference of Joomla 2.5.4 DE |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * @package Joomla.Platform 4 * @subpackage Installer 5 * 6 * @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved. 7 * @license GNU General Public License version 2 or later; see LICENSE 8 */ 9 10 defined('JPATH_PLATFORM') or die; 11 12 jimport('joomla.base.adapterinstance'); 13 14 /** 15 * Plugin installer 16 * 17 * @package Joomla.Platform 18 * @subpackage Installer 19 * @since 11.1 20 */ 21 class JInstallerPlugin extends JAdapterInstance 22 { 23 /** 24 * Install function routing 25 * 26 * @var string 27 * @since 11.1 28 * */ 29 protected $route = 'install'; 30 31 /** 32 * The installation manifest XML object 33 * 34 * @var 35 * @since 11.1 36 * */ 37 protected $manifest = null; 38 39 /** 40 * 41 * 42 * @var 43 * @since 11.1 44 * */ 45 protected $manifest_script = null; 46 47 /** 48 * 49 * 50 * @var 51 * @since 11.1 52 * */ 53 protected $name = null; 54 55 /** 56 * 57 * 58 * @var 59 * @since 11.1 60 * */ 61 protected $scriptElement = null; 62 63 /** 64 * @var 65 * @since 11.1 66 */ 67 protected $oldFiles = null; 68 69 /** 70 * Custom loadLanguage method 71 * 72 * @param string $path The path where to find language files. 73 * 74 * @return void 75 * 76 * @since 11.1 77 */ 78 public function loadLanguage($path = null) 79 { 80 $source = $this->parent->getPath('source'); 81 if (!$source) 82 { 83 $this->parent->setPath('source', JPATH_PLUGINS . '/' . $this->parent->extension->folder . '/' . $this->parent->extension->element); 84 } 85 $this->manifest = $this->parent->getManifest(); 86 $element = $this->manifest->files; 87 if ($element) 88 { 89 $group = strtolower((string) $this->manifest->attributes()->group); 90 $name = ''; 91 if (count($element->children())) 92 { 93 foreach ($element->children() as $file) 94 { 95 if ((string) $file->attributes()->plugin) 96 { 97 $name = strtolower((string) $file->attributes()->plugin); 98 break; 99 } 100 } 101 } 102 if ($name) 103 { 104 $extension = "plg_$group}_$name}"; 105 $lang = JFactory::getLanguage(); 106 $source = $path ? $path : JPATH_PLUGINS . "/$group/$name"; 107 $folder = (string) $element->attributes()->folder; 108 if ($folder && file_exists("$path/$folder")) 109 { 110 $source = "$path/$folder"; 111 } 112 $lang->load($extension . '.sys', $source, null, false, false) 113 || $lang->load($extension . '.sys', JPATH_ADMINISTRATOR, null, false, false) 114 || $lang->load($extension . '.sys', $source, $lang->getDefault(), false, false) 115 || $lang->load($extension . '.sys', JPATH_ADMINISTRATOR, $lang->getDefault(), false, false); 116 } 117 } 118 } 119 120 /** 121 * Custom install method 122 * 123 * @return boolean True on success 124 * 125 * @since 11.1 126 */ 127 public function install() 128 { 129 // Get a database connector object 130 $db = $this->parent->getDbo(); 131 132 // Get the extension manifest object 133 $this->manifest = $this->parent->getManifest(); 134 135 $xml = $this->manifest; 136 137 // Manifest Document Setup Section 138 139 // Set the extension name 140 $name = (string) $xml->name; 141 $name = JFilterInput::getInstance()->clean($name, 'string'); 142 $this->set('name', $name); 143 144 // Get the component description 145 $description = (string) $xml->description; 146 if ($description) 147 { 148 $this->parent->set('message', JText::_($description)); 149 } 150 else 151 { 152 $this->parent->set('message', ''); 153 } 154 155 /* 156 * Backward Compatibility 157 * @todo Deprecate in future version 158 */ 159 $type = (string) $xml->attributes()->type; 160 161 // Set the installation path 162 if (count($xml->files->children())) 163 { 164 foreach ($xml->files->children() as $file) 165 { 166 if ((string) $file->attributes()->$type) 167 { 168 $element = (string) $file->attributes()->$type; 169 break; 170 } 171 } 172 } 173 $group = (string) $xml->attributes()->group; 174 if (!empty($element) && !empty($group)) 175 { 176 $this->parent->setPath('extension_root', JPATH_PLUGINS . '/' . $group . '/' . $element); 177 } 178 else 179 { 180 $this->parent->abort(JText::sprintf('JLIB_INSTALLER_ABORT_PLG_INSTALL_NO_FILE', JText::_('JLIB_INSTALLER_' . $this->route))); 181 return false; 182 } 183 184 // Check if we should enable overwrite settings 185 186 // Check to see if a plugin by the same name is already installed. 187 $query = $db->getQuery(true); 188 $query->select($query->qn('extension_id'))->from($query->qn('#__extensions')); 189 $query->where($query->qn('folder') . ' = ' . $query->q($group)); 190 $query->where($query->qn('element') . ' = ' . $query->q($element)); 191 $db->setQuery($query); 192 try 193 { 194 $db->Query(); 195 } 196 catch (JException $e) 197 { 198 // Install failed, roll back changes 199 $this->parent 200 ->abort(JText::sprintf('JLIB_INSTALLER_ABORT_PLG_INSTALL_ROLLBACK', JText::_('JLIB_INSTALLER_' . $this->route), $db->stderr(true))); 201 return false; 202 } 203 $id = $db->loadResult(); 204 205 // If it's on the fs... 206 if (file_exists($this->parent->getPath('extension_root')) && (!$this->parent->getOverwrite() || $this->parent->getUpgrade())) 207 { 208 $updateElement = $xml->update; 209 // Upgrade manually set or 210 // Update function available or 211 // Update tag detected 212 if ($this->parent->getUpgrade() || ($this->parent->manifestClass && method_exists($this->parent->manifestClass, 'update')) 213 || $updateElement) 214 { 215 // Force this one 216 $this->parent->setOverwrite(true); 217 $this->parent->setUpgrade(true); 218 if ($id) 219 { 220 // If there is a matching extension mark this as an update; semantics really 221 $this->route = 'update'; 222 } 223 } 224 elseif (!$this->parent->getOverwrite()) 225 { 226 // Overwrite is set 227 // We didn't have overwrite set, find an update function or find an update tag so lets call it safe 228 $this->parent 229 ->abort( 230 JText::sprintf( 231 'JLIB_INSTALLER_ABORT_PLG_INSTALL_DIRECTORY', JText::_('JLIB_INSTALLER_' . $this->route), 232 $this->parent->getPath('extension_root') 233 ) 234 ); 235 return false; 236 } 237 } 238 239 // Installer Trigger Loading 240 241 // If there is an manifest class file, let's load it; we'll copy it later (don't have destination yet). 242 243 if ((string) $xml->scriptfile) 244 { 245 $manifestScript = (string) $xml->scriptfile; 246 $manifestScriptFile = $this->parent->getPath('source') . '/' . $manifestScript; 247 if (is_file($manifestScriptFile)) 248 { 249 // Load the file 250 include_once $manifestScriptFile; 251 } 252 // If a dash is present in the group name, remove it 253 $groupClass = str_replace('-', '', $group); 254 // Set the class name 255 $classname = 'plg' . $groupClass . $element . 'InstallerScript'; 256 if (class_exists($classname)) 257 { 258 // Create a new instance 259 $this->parent->manifestClass = new $classname($this); 260 // And set this so we can copy it later 261 $this->set('manifest_script', $manifestScript); 262 263 // Note: if we don't find the class, don't bother to copy the file 264 } 265 } 266 267 // Run preflight if possible (since we know we're not an update) 268 ob_start(); 269 ob_implicit_flush(false); 270 if ($this->parent->manifestClass && method_exists($this->parent->manifestClass, 'preflight')) 271 { 272 if ($this->parent->manifestClass->preflight($this->route, $this) === false) 273 { 274 // Install failed, rollback changes 275 $this->parent->abort(JText::_('JLIB_INSTALLER_ABORT_PLG_INSTALL_CUSTOM_INSTALL_FAILURE')); 276 return false; 277 } 278 } 279 $msg = ob_get_contents(); // create msg object; first use here 280 ob_end_clean(); 281 282 // Filesystem Processing Section 283 284 // If the plugin directory does not exist, lets create it 285 $created = false; 286 if (!file_exists($this->parent->getPath('extension_root'))) 287 { 288 if (!$created = JFolder::create($this->parent->getPath('extension_root'))) 289 { 290 $this->parent 291 ->abort( 292 JText::sprintf( 293 'JLIB_INSTALLER_ABORT_PLG_INSTALL_CREATE_DIRECTORY', JText::_('JLIB_INSTALLER_' . $this->route), 294 $this->parent->getPath('extension_root') 295 ) 296 ); 297 return false; 298 } 299 } 300 301 // If we're updating at this point when there is always going to be an extension_root find the old XML files 302 if ($this->route == 'update') 303 { 304 // Hunt for the original XML file 305 $old_manifest = null; 306 $tmpInstaller = new JInstaller; // create a new installer because findManifest sets stuff; side effects! 307 // Look in the extension root 308 $tmpInstaller->setPath('source', $this->parent->getPath('extension_root')); 309 if ($tmpInstaller->findManifest()) 310 { 311 $old_manifest = $tmpInstaller->getManifest(); 312 $this->oldFiles = $old_manifest->files; 313 } 314 } 315 316 // If we created the plugin directory and will want to remove it if we 317 // have to roll back the installation, let's add it to the installation 318 // step stack 319 320 if ($created) 321 { 322 $this->parent->pushStep(array('type' => 'folder', 'path' => $this->parent->getPath('extension_root'))); 323 } 324 325 // Copy all necessary files 326 if ($this->parent->parseFiles($xml->files, -1, $this->oldFiles) === false) 327 { 328 // Install failed, roll back changes 329 $this->parent->abort(); 330 return false; 331 } 332 333 // Parse optional tags -- media and language files for plugins go in admin app 334 $this->parent->parseMedia($xml->media, 1); 335 $this->parent->parseLanguages($xml->languages, 1); 336 337 // If there is a manifest script, lets copy it. 338 if ($this->get('manifest_script')) 339 { 340 $path['src'] = $this->parent->getPath('source') . '/' . $this->get('manifest_script'); 341 $path['dest'] = $this->parent->getPath('extension_root') . '/' . $this->get('manifest_script'); 342 343 if (!file_exists($path['dest'])) 344 { 345 if (!$this->parent->copyFiles(array($path))) 346 { 347 // Install failed, rollback changes 348 $this->parent 349 ->abort(JText::sprintf('JLIB_INSTALLER_ABORT_PLG_INSTALL_MANIFEST', JText::_('JLIB_INSTALLER_' . $this->route))); 350 return false; 351 } 352 } 353 } 354 355 // Database Processing Section 356 357 $row = JTable::getInstance('extension'); 358 // Was there a plugin with the same name already installed? 359 if ($id) 360 { 361 if (!$this->parent->getOverwrite()) 362 { 363 // Install failed, roll back changes 364 $this->parent 365 ->abort( 366 JText::sprintf( 367 'JLIB_INSTALLER_ABORT_PLG_INSTALL_ALLREADY_EXISTS', JText::_('JLIB_INSTALLER_' . $this->route), 368 $this->get('name') 369 ) 370 ); 371 return false; 372 } 373 $row->load($id); 374 $row->name = $this->get('name'); 375 $row->manifest_cache = $this->parent->generateManifestCache(); 376 $row->store(); // update the manifest cache and name 377 } 378 else 379 { 380 // Store in the extensions table (1.6) 381 $row->name = $this->get('name'); 382 $row->type = 'plugin'; 383 $row->ordering = 0; 384 $row->element = $element; 385 $row->folder = $group; 386 $row->enabled = 0; 387 $row->protected = 0; 388 $row->access = 1; 389 $row->client_id = 0; 390 $row->params = $this->parent->getParams(); 391 // Custom data 392 $row->custom_data = ''; 393 // System data 394 $row->system_data = ''; 395 $row->manifest_cache = $this->parent->generateManifestCache(); 396 397 // Editor plugins are published by default 398 if ($group == 'editors') 399 { 400 $row->enabled = 1; 401 } 402 403 if (!$row->store()) 404 { 405 // Install failed, roll back changes 406 $this->parent 407 ->abort( 408 JText::sprintf('JLIB_INSTALLER_ABORT_PLG_INSTALL_ROLLBACK', JText::_('JLIB_INSTALLER_' . $this->route), $db->stderr(true)) 409 ); 410 return false; 411 } 412 413 // Since we have created a plugin item, we add it to the installation step stack 414 // so that if we have to rollback the changes we can undo it. 415 $this->parent->pushStep(array('type' => 'extension', 'id' => $row->extension_id)); 416 $id = $row->extension_id; 417 } 418 419 // Let's run the queries for the module 420 // If Joomla 1.5 compatible, with discreet sql files - execute appropriate 421 // file for utf-8 support or non-utf-8 support 422 423 // Try for Joomla 1.5 type queries 424 // Second argument is the utf compatible version attribute 425 if (strtolower($this->route) == 'install') 426 { 427 $utfresult = $this->parent->parseSQLFiles($this->manifest->install->sql); 428 if ($utfresult === false) 429 { 430 // Install failed, rollback changes 431 $this->parent 432 ->abort( 433 JText::sprintf('JLIB_INSTALLER_ABORT_PLG_INSTALL_SQL_ERROR', JText::_('JLIB_INSTALLER_' . $this->route), $db->stderr(true)) 434 ); 435 return false; 436 } 437 438 // Set the schema version to be the latest update version 439 if ($this->manifest->update) 440 { 441 $this->parent->setSchemaVersion($this->manifest->update->schemas, $row->extension_id); 442 } 443 } 444 elseif (strtolower($this->route) == 'update') 445 { 446 if ($this->manifest->update) 447 { 448 $result = $this->parent->parseSchemaUpdates($this->manifest->update->schemas, $row->extension_id); 449 if ($result === false) 450 { 451 // Install failed, rollback changes 452 $this->parent->abort(JText::sprintf('JLIB_INSTALLER_ABORT_PLG_UPDATE_SQL_ERROR', $db->stderr(true))); 453 return false; 454 } 455 } 456 } 457 458 // Start Joomla! 1.6 459 ob_start(); 460 ob_implicit_flush(false); 461 if ($this->parent->manifestClass && method_exists($this->parent->manifestClass, $this->route)) 462 { 463 if ($this->parent->manifestClass->{$this->route}($this) === false) 464 { 465 // Install failed, rollback changes 466 $this->parent->abort(JText::_('JLIB_INSTALLER_ABORT_PLG_INSTALL_CUSTOM_INSTALL_FAILURE')); 467 return false; 468 } 469 } 470 // Append messages 471 $msg .= ob_get_contents(); 472 ob_end_clean(); 473 474 // Finalization and Cleanup Section 475 476 // Lastly, we will copy the manifest file to its appropriate place. 477 if (!$this->parent->copyManifest(-1)) 478 { 479 // Install failed, rollback changes 480 $this->parent->abort(JText::sprintf('JLIB_INSTALLER_ABORT_PLG_INSTALL_COPY_SETUP', JText::_('JLIB_INSTALLER_' . $this->route))); 481 return false; 482 } 483 // And now we run the postflight 484 ob_start(); 485 ob_implicit_flush(false); 486 if ($this->parent->manifestClass && method_exists($this->parent->manifestClass, 'postflight')) 487 { 488 $this->parent->manifestClass->postflight($this->route, $this); 489 } 490 // Append messages 491 $msg .= ob_get_contents(); 492 ob_end_clean(); 493 if ($msg != '') 494 { 495 $this->parent->set('extension_message', $msg); 496 } 497 return $id; 498 } 499 500 /** 501 * Custom update method 502 * 503 * @return boolean True on success 504 * 505 * @since 11.1 506 */ 507 public function update() 508 { 509 // Set the overwrite setting 510 $this->parent->setOverwrite(true); 511 $this->parent->setUpgrade(true); 512 // Set the route for the install 513 $this->route = 'update'; 514 // Go to install which handles updates properly 515 return $this->install(); 516 } 517 518 /** 519 * Custom uninstall method 520 * 521 * @param integer $id The id of the plugin to uninstall 522 * 523 * @return boolean True on success 524 * 525 * @since 11.1 526 */ 527 public function uninstall($id) 528 { 529 $this->route = 'uninstall'; 530 531 // Initialise variables. 532 $row = null; 533 $retval = true; 534 $db = $this->parent->getDbo(); 535 536 // First order of business will be to load the plugin object table from the database. 537 // This should give us the necessary information to proceed. 538 $row = JTable::getInstance('extension'); 539 if (!$row->load((int) $id)) 540 { 541 JError::raiseWarning(100, JText::_('JLIB_INSTALLER_ERROR_PLG_UNINSTALL_ERRORUNKOWNEXTENSION')); 542 return false; 543 } 544 545 // Is the plugin we are trying to uninstall a core one? 546 // Because that is not a good idea... 547 if ($row->protected) 548 { 549 JError::raiseWarning(100, JText::sprintf('JLIB_INSTALLER_ERROR_PLG_UNINSTALL_WARNCOREPLUGIN', $row->name)); 550 return false; 551 } 552 553 // Get the plugin folder so we can properly build the plugin path 554 if (trim($row->folder) == '') 555 { 556 JError::raiseWarning(100, JText::_('JLIB_INSTALLER_ERROR_PLG_UNINSTALL_FOLDER_FIELD_EMPTY')); 557 return false; 558 } 559 560 // Set the plugin root path 561 if (is_dir(JPATH_PLUGINS . '/' . $row->folder . '/' . $row->element)) 562 { 563 // Use 1.6 plugins 564 $this->parent->setPath('extension_root', JPATH_PLUGINS . '/' . $row->folder . '/' . $row->element); 565 } 566 else 567 { 568 // Use Legacy 1.5 plugins 569 $this->parent->setPath('extension_root', JPATH_PLUGINS . '/' . $row->folder); 570 } 571 572 // Because 1.5 plugins don't have their own folders we cannot use the standard method of finding an installation manifest 573 // Since 1.6 they do, however until we move to 1.7 and remove 1.6 legacy we still need to use this method. 574 // When we get there it'll be something like "$this->parent->findManifest();$manifest = $this->parent->getManifest();" 575 $manifestFile = $this->parent->getPath('extension_root') . '/' . $row->element . '.xml'; 576 577 if (!file_exists($manifestFile)) 578 { 579 JError::raiseWarning(100, JText::_('JLIB_INSTALLER_ERROR_PLG_UNINSTALL_INVALID_NOTFOUND_MANIFEST')); 580 return false; 581 } 582 583 $xml = JFactory::getXML($manifestFile); 584 585 $this->manifest = $xml; 586 587 // If we cannot load the XML file return null 588 if (!$xml) 589 { 590 JError::raiseWarning(100, JText::_('JLIB_INSTALLER_ERROR_PLG_UNINSTALL_LOAD_MANIFEST')); 591 return false; 592 } 593 594 /* 595 * Check for a valid XML root tag. 596 * @todo: Remove backwards compatibility in a future version 597 * Should be 'extension', but for backward compatibility we will accept 'install'. 598 */ 599 if ($xml->getName() != 'install' && $xml->getName() != 'extension') 600 { 601 JError::raiseWarning(100, JText::_('JLIB_INSTALLER_ERROR_PLG_UNINSTALL_INVALID_MANIFEST')); 602 return false; 603 } 604 605 // Attempt to load the language file; might have uninstall strings 606 $this->parent->setPath('source', JPATH_PLUGINS . '/' . $row->folder . '/' . $row->element); 607 $this->loadLanguage(JPATH_PLUGINS . '/' . $row->folder . '/' . $row->element); 608 609 // Installer Trigger Loading 610 611 // If there is an manifest class file, let's load it; we'll copy it later (don't have dest yet) 612 $manifestScript = (string) $xml->scriptfile; 613 if ($manifestScript) 614 { 615 $manifestScriptFile = $this->parent->getPath('source') . '/' . $manifestScript; 616 if (is_file($manifestScriptFile)) 617 { 618 // Load the file 619 include_once $manifestScriptFile; 620 } 621 // If a dash is present in the folder, remove it 622 $folderClass = str_replace('-', '', $row->folder); 623 // Set the class name 624 $classname = 'plg' . $folderClass . $row->element . 'InstallerScript'; 625 if (class_exists($classname)) 626 { 627 // Create a new instance 628 $this->parent->manifestClass = new $classname($this); 629 // And set this so we can copy it later 630 $this->set('manifest_script', $manifestScript); 631 632 // Note: if we don't find the class, don't bother to copy the file 633 } 634 } 635 636 // Run preflight if possible (since we know we're not an update) 637 ob_start(); 638 ob_implicit_flush(false); 639 if ($this->parent->manifestClass && method_exists($this->parent->manifestClass, 'preflight')) 640 { 641 if ($this->parent->manifestClass->preflight($this->route, $this) === false) 642 { 643 // Install failed, rollback changes 644 $this->parent->abort(JText::_('JLIB_INSTALLER_ABORT_PLG_INSTALL_CUSTOM_INSTALL_FAILURE')); 645 return false; 646 } 647 } 648 // Create msg object; first use here 649 $msg = ob_get_contents(); 650 ob_end_clean(); 651 652 // Let's run the queries for the module 653 // If Joomla 1.5 compatible, with discreet sql files - execute appropriate 654 // file for utf-8 support or non-utf-8 support 655 656 // Try for Joomla 1.5 type queries 657 // Second argument is the utf compatible version attribute 658 $utfresult = $this->parent->parseSQLFiles($xml->{strtolower($this->route)}->sql); 659 if ($utfresult === false) 660 { 661 // Install failed, rollback changes 662 $this->parent->abort(JText::sprintf('JLIB_INSTALLER_ABORT_PLG_UNINSTALL_SQL_ERROR', $db->stderr(true))); 663 return false; 664 } 665 666 // Start Joomla! 1.6 667 ob_start(); 668 ob_implicit_flush(false); 669 if ($this->parent->manifestClass && method_exists($this->parent->manifestClass, 'uninstall')) 670 { 671 $this->parent->manifestClass->uninstall($this); 672 } 673 // Append messages 674 $msg = ob_get_contents(); 675 ob_end_clean(); 676 677 // Remove the plugin files 678 $this->parent->removeFiles($xml->images, -1); 679 $this->parent->removeFiles($xml->files, -1); 680 JFile::delete($manifestFile); 681 682 // Remove all media and languages as well 683 $this->parent->removeFiles($xml->media); 684 $this->parent->removeFiles($xml->languages, 1); 685 686 // Remove the schema version 687 $query = $db->getQuery(true); 688 $query->delete()->from('#__schemas')->where('extension_id = ' . $row->extension_id); 689 $db->setQuery($query); 690 $db->Query(); 691 692 // Now we will no longer need the plugin object, so let's delete it 693 $row->delete($row->extension_id); 694 unset($row); 695 696 // If the folder is empty, let's delete it 697 $files = JFolder::files($this->parent->getPath('extension_root')); 698 699 JFolder::delete($this->parent->getPath('extension_root')); 700 701 if ($msg) 702 { 703 $this->parent->set('extension_message', $msg); 704 } 705 706 return $retval; 707 } 708 709 /** 710 * Custom discover method 711 * 712 * @return array JExtension) list of extensions available 713 * 714 * @since 11.1 715 */ 716 public function discover() 717 { 718 $results = array(); 719 $folder_list = JFolder::folders(JPATH_SITE . '/plugins'); 720 721 foreach ($folder_list as $folder) 722 { 723 $file_list = JFolder::files(JPATH_SITE . '/plugins/' . $folder, '\.xml$'); 724 foreach ($file_list as $file) 725 { 726 $manifest_details = JApplicationHelper::parseXMLInstallFile(JPATH_SITE . '/plugins/' . $folder . '/' . $file); 727 $file = JFile::stripExt($file); 728 // Ignore example plugins 729 if ($file == 'example') 730 { 731 continue; 732 } 733 734 $extension = JTable::getInstance('extension'); 735 $extension->set('type', 'plugin'); 736 $extension->set('client_id', 0); 737 $extension->set('element', $file); 738 $extension->set('folder', $folder); 739 $extension->set('name', $file); 740 $extension->set('state', -1); 741 $extension->set('manifest_cache', json_encode($manifest_details)); 742 $results[] = $extension; 743 } 744 $folder_list = JFolder::folders(JPATH_SITE . '/plugins/' . $folder); 745 foreach ($folder_list as $plugin_folder) 746 { 747 $file_list = JFolder::files(JPATH_SITE . '/plugins/' . $folder . '/' . $plugin_folder, '\.xml$'); 748 foreach ($file_list as $file) 749 { 750 $manifest_details = JApplicationHelper::parseXMLInstallFile( 751 JPATH_SITE . '/plugins/' . $folder . '/' . $plugin_folder . '/' . $file 752 ); 753 $file = JFile::stripExt($file); 754 755 if ($file == 'example') 756 { 757 continue; 758 } 759 760 // ignore example plugins 761 $extension = JTable::getInstance('extension'); 762 $extension->set('type', 'plugin'); 763 $extension->set('client_id', 0); 764 $extension->set('element', $file); 765 $extension->set('folder', $folder); 766 $extension->set('name', $file); 767 $extension->set('state', -1); 768 $extension->set('manifest_cache', json_encode($manifest_details)); 769 $results[] = $extension; 770 } 771 } 772 } 773 return $results; 774 } 775 776 /** 777 * Custom discover_install method. 778 * 779 * @return mixed 780 * 781 * @since 11.1 782 */ 783 public function discover_install() 784 { 785 // Plugins use the extensions table as their primary store 786 // Similar to modules and templates, rather easy 787 // If it's not in the extensions table we just add it 788 $client = JApplicationHelper::getClientInfo($this->parent->extension->client_id); 789 if (is_dir($client->path . '/plugins/' . $this->parent->extension->folder . '/' . $this->parent->extension->element)) 790 { 791 $manifestPath = $client->path . '/plugins/' . $this->parent->extension->folder . '/' . $this->parent->extension->element . '/' 792 . $this->parent->extension->element . '.xml'; 793 } 794 else 795 { 796 $manifestPath = $client->path . '/plugins/' . $this->parent->extension->folder . '/' . $this->parent->extension->element . '.xml'; 797 } 798 $this->parent->manifest = $this->parent->isManifest($manifestPath); 799 $description = (string) $this->parent->manifest->description; 800 if ($description) 801 { 802 $this->parent->set('message', JText::_($description)); 803 } 804 else 805 { 806 $this->parent->set('message', ''); 807 } 808 $this->parent->setPath('manifest', $manifestPath); 809 $manifest_details = JApplicationHelper::parseXMLInstallFile($manifestPath); 810 $this->parent->extension->manifest_cache = json_encode($manifest_details); 811 $this->parent->extension->state = 0; 812 $this->parent->extension->name = $manifest_details['name']; 813 $this->parent->extension->enabled = ('editors' == $this->parent->extension->folder) ? 1 : 0; 814 $this->parent->extension->params = $this->parent->getParams(); 815 if ($this->parent->extension->store()) 816 { 817 return $this->parent->extension->get('extension_id'); 818 } 819 else 820 { 821 JError::raiseWarning(101, JText::_('JLIB_INSTALLER_ERROR_PLG_DISCOVER_STORE_DETAILS')); 822 return false; 823 } 824 } 825 826 /** 827 * Refreshes the extension table cache. 828 * 829 * @return boolean Result of operation, true if updated, false on failure. 830 * 831 * @since 11.1 832 */ 833 public function refreshManifestCache() 834 { 835 // Plugins use the extensions table as their primary store 836 // Similar to modules and templates, rather easy 837 // If it's not in the extensions table we just add it 838 $client = JApplicationHelper::getClientInfo($this->parent->extension->client_id); 839 $manifestPath = $client->path . '/plugins/' . $this->parent->extension->folder . '/' . $this->parent->extension->element . '/' 840 . $this->parent->extension->element . '.xml'; 841 $this->parent->manifest = $this->parent->isManifest($manifestPath); 842 $this->parent->setPath('manifest', $manifestPath); 843 $manifest_details = JApplicationHelper::parseXMLInstallFile($this->parent->getPath('manifest')); 844 $this->parent->extension->manifest_cache = json_encode($manifest_details); 845 846 $this->parent->extension->name = $manifest_details['name']; 847 if ($this->parent->extension->store()) 848 { 849 return true; 850 } 851 else 852 { 853 JError::raiseWarning(101, JText::_('JLIB_INSTALLER_ERROR_PLG_REFRESH_MANIFEST_CACHE')); 854 return false; 855 } 856 } 857 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Tue Apr 3 11:40:28 2012 | Cross-referenced by PHPXref 0.7.1 |