Source for file plugin.php

Documentation is available at plugin.php

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

Documentation generated on Tue, 19 Nov 2013 15:10:48 +0100 by phpDocumentor 1.4.3