| Current Path : /home/sunflowe/www2/j15/administrator/components/com_easycaptcha/libraries/ |
| Current File : /home/sunflowe/www2/j15/administrator/components/com_easycaptcha/libraries/captchaadapter.php |
<?php
/**
* @version $Id: captchaadapter.php 636 2008-03-18 09:01:06Z snipersister $
* @package EasyCaptcha
* @link http://www.easy-joomla.org
* @license GNU/GPL
*/
// Check to ensure this file is within the rest of the framework
defined('JPATH_BASE') or die();
class CaptchaAdapter extends JObject
{
/**
* Core language pack flag
* @access private
* @var boolean
*/
var $_core = false;
/**
* Constructor
*
* @access protected
* @param object $parent Parent object [JInstaller instance]
* @return void
* @since 1.5
*/
function __construct(&$parent)
{
$this->parent =& $parent;
}
/**
* Custom install method for EasyCaptcha Captcha
*
* @access public
* @return boolean True on success
*/
function install()
{
$db =& $this->parent->getDBO();
$manifest =& $this->parent->getManifest();
$this->manifest =& $manifest->document;
$root =& $manifest->document;
$basePath = JPATH_SITE.DS.'components'.DS.'com_easycaptcha'.DS.'captchas';
// Get the Plugin name
$name =& $this->manifest->getElementByPath('name');
$name = JFilterInput::clean($name->data(), 'cmd');
$this->set('name', $name);
// get the plugin folder name
$element =& $root->getElementByPath('name');
$folder = $element->_data;
// Set the plugin installation paths
$this->parent->setPath('extension_site', $basePath.DS.$folder);
/* If the component site or admin directory already exists, then we will assume that the component is already
* installed or another component is using that directory.
*/
if ((file_exists($this->parent->getPath('extension_site')) || file_exists($this->parent->getPath('extension_administrator'))) && !$this->parent->getOverwrite()) {
JError::raiseWarning(1, JText::_('Captcha').' '.JText::_('Install').': '.JText::_('Another captcha is already using directory').': "'.$this->parent->getPath('extension_site').'"');
return false;
}
// If the directory does not exist, lets create it
$created = false;
if (!file_exists($this->parent->getPath('extension_site'))) {
if (!$created = JFolder::create($this->parent->getPath('extension_site'))) {
$this->parent->abort(JText::_('Captcha').' '.JText::_('Install').': '.JText::_('Failed to create directory').' "'.$this->parent->getPath('extension_site').'"');
return false;
}
}
/*
* If we created the directory and will want to remove it if we
* have to roll back the installation, lets add it to the installation
* step stack
*/
if ($created) {
$this->parent->pushStep(array ('type' => 'folder', 'path' => $this->parent->getPath('extension_site')));
}
/* Let's run the install queries for the component
* If backward compatibility is required - run queries in xml file
* If Joomla 1.5 compatible, with discreet sql files - execute appropriate
* file for utf-8 support or non-utf-8 support
*/
$result = $this->parent->parseQueries($this->manifest->getElementByPath('install/queries'));
if ($result === false) {
// Install failed, rollback changes
$this->parent->abort(JText::_('Captcha').' '.JText::_('Install').': '.JText::_('SQL Error')." ".$db->stderr(true));
return false;
} elseif ($result === 0) {
// no backward compatibility queries found - try for Joomla 1.5 type queries
// second argument is the utf compatible version attribute
$utfresult = $this->parent->parseSQLFiles($this->manifest->getElementByPath('install/sql'));
if ($utfresult === false) {
// Install failed, rollback changes
$this->parent->abort(JText::_('Captcha').' '.JText::_('Install').': '.JText::_('SQLERRORORFILE')." ".$db->stderr(true));
return false;
}
}
$element =& $root->getElementByPath('files');
/*
* // Copy all the necessary files
* PLUGIN
*/
if ($this->parent->parseFiles($element) === false)
{
// Install failed, rollback changes
$this->parent->abort();
return false;
}
$element =& $root->getElementByPath('description');
$row =& JTable::getInstance('Captcha', 'Table');
$row->name = $this->get('name');
$row->description = $element->_data;
$row->published = 0;
$row->params = $this->parent->getParams();
if (!$row->store()) {
// Install failed, roll back changes
$this->parent->abort(JText::_('Captcha').' '.JText::_('Install').': '.$db->stderr(true));
return false;
}
// Since we have created a plugin item, we add it to the installation step stack
// so that if we have to rollback the changes we can undo it.
$this->parent->pushStep(array ('type' => 'plugin', 'id' => $row->id));
// Lastly, we will copy the manifest file to its appropriate place.
if (!$this->parent->copyManifest(0)) {
// Install failed, rollback changes
$this->parent->abort(JText::_('Captcha').' '.JText::_('Install').': '.JText::_('Could not copy setup file'));
return false;
}
return true;
}
/**
* Custom uninstall method
*
* @access public
* @param int $Id The id of the captcha
* @return mixed Return value for uninstall method in component uninstall file
*/
function uninstall($id)
{
// Initialize variables
$db =& $this->parent->getDBO();
$row = null;
$retval = true;
// First order of business will be to load the component object table from the database.
// This should give us the necessary information to proceed.
$row = & JTable::getInstance('Captcha', 'Table');
if ( !$row->load((int) $id) ) {
JError::raiseWarning(100, JText::_('ERRORUNKOWNEXTENSION'));
return false;
}
if ($row->published == 1) {
JError::raiseWarning(100, JText::_('Captcha').' '.JText::_('Uninstall').': '.JText::_('Can not remove captcha which is in use'));
return false;
}
$basePath = JPATH_SITE.DS.'components'.DS.'com_easycaptcha'.DS.'captchas';
// Set the plugin installation paths
$this->parent->setPath('extension_site', $basePath.DS.$row->name);
/**
* ---------------------------------------------------------------------------------------------
* Manifest Document Setup Section
* ---------------------------------------------------------------------------------------------
*/
// Find and load the XML install file for the component
$this->parent->setPath('source', $this->parent->getPath('extension_site'));
// Get the package manifest objecct
$manifest =& $this->parent->getManifest();
if (!is_a($manifest, 'JSimpleXML')) {
// Make sure we delete the folders if no manifest exists
JFolder::delete($this->parent->getPath('extension_site'));
// Raise a warning
JError::raiseWarning(100, JText::_('ERRORREMOVEMANUALLY'));
// Return
return false;
}
// Get the root node of the manifest document
$this->manifest =& $manifest->document;
/**
* ---------------------------------------------------------------------------------------------
* Database Processing Section
* ---------------------------------------------------------------------------------------------
*/
/*
* Let's run the uninstall queries for the component
* If backward compatibility is required - run queries in xml file
* If Joomla 1.5 compatible, with discreet sql files - execute appropriate
* file for utf-8 support or non-utf support
*/
$result = $this->parent->parseQueries($this->manifest->getElementByPath('uninstall/queries'));
if ($result === false) {
// Install failed, rollback changes
JError::raiseWarning(100, JText::_('Component').' '.JText::_('Uninstall').': '.JText::_('SQL Error')." ".$db->stderr(true));
return false;
} elseif ($result === 0) {
// no backward compatibility queries found - try for Joomla 1.5 type queries
// second argument is the utf compatible version attribute
$utfresult = $this->parent->parseSQLFiles($this->manifest->getElementByPath('uninstall/sql'));
if ($utfresult === false) {
// Install failed, rollback changes
JError::raiseWarning(100, JText::_('Captcha').' '.JText::_('Uninstall').': '.JText::_('SQLERRORORFILE')." ".$db->stderr(true));
return false;
}
}
/**
* ---------------------------------------------------------------------------------------------
* Filesystem Processing Section
* ---------------------------------------------------------------------------------------------
*/
// Delete the plugin site directory
if (is_dir($this->parent->getPath('extension_site'))) {
if (!JFolder::delete($this->parent->getPath('extension_site'))) {
JError::raiseWarning(100, JText::_('Captcha').' '.JText::_('Uninstall').': '.JText::_('Unable to remove the capcha directory'));
return false;
}
}
// Now we will no longer need the plugin object, so lets delete it
$row->delete($row->id);
unset ($row);
return true;
}// function
}// class