'MySQL',
'mysqli' => 'MySQLi',
'pdomysql' => 'PDO MySql',
'postgresql' => 'PostgreSQL',
'sqlsrv' => 'MS SQL Server',
'sqlazure' => 'MS SQL Azure');
/**
* An array of supported database types
*
* @var array
*/
protected $dbSupported = array('mysql', 'mysqli', 'pdomysql');
/**
* name of moved attachments directory (if present)
*/
var $moved_attachments_dir = null;
/**
* List of the plugins
*/
var $plugins = Array('plg_content_attachments',
'plg_search_attachments',
'plg_attachments_plugin_framework',
'plg_attachments_for_content',
'plg_editors-xtd_add_attachment_btn',
'plg_editors-xtd_insert_attachments_token_btn',
'plg_system_show_attachments_in_editor',
'plg_quickicon_attachments'
);
/**
* Attachments component install function
*
* @param $parent : the installer parent
*/
public function install($parent)
{
global $attachments_install_verbose, $attachments_install_last_method;
$attachments_install_verbose = true;
$attachments_install_last_method = 'install';
$app = JFactory::getApplication();
$app->enqueueMessage(JText::sprintf('ATTACH_ATTACHMENTS_COMPONENT_SUCCESSFULLY_INSTALLED'), 'message');
com_AttachmentsInstallerScript::installPermissions();
}
/**
* Attachments component update function
*
* @param $parent : the installer parent
*/
public function update($parent)
{
global $attachments_install_verbose, $attachments_install_last_method;
$attachments_install_last_method = 'update';
if ( $attachments_install_verbose ) {
$app = JFactory::getApplication();
$app->enqueueMessage(JText::sprintf('ATTACH_ATTACHMENTS_COMPONENT_SUCCESSFULLY_UPGRADED'), 'message');
}
com_AttachmentsInstallerScript::installPermissions();
}
/**
* Attachments component uninstall function
*
* @param $parent : the installer parent
*/
public function uninstall($parent)
{
// disable all the plugins
foreach ($this->plugins as $plugin_name)
{
// Make the query to enable the plugin
$db = JFactory::getDBO();
$query = $db->getQuery(true);
$query->update('#__extensions')
->set("enabled = 0")
->where('type=' . $db->quote('plugin') . ' AND name=' . $db->quote($plugin_name));
$db->setQuery($query);
$db->query();
// NOTE: Do NOT complain if there was an error
// (in case any plugin is already uninstalled and this query fails)
}
}
/**
* Attachments component preflight function
*
* @param $type : type of installation
* @param $parent : the installer parent
*/
public function preflight($type, $parent)
{
global $attachments_install_verbose, $attachments_install_last_method;
$app = JFactory::getApplication();
if ( $attachments_install_last_method == 'update' ) {
$attachments_install_verbose = false;
}
if ( $attachments_install_last_method == null ) {
$attachments_install_verbose = true;
}
// Load the installation language
$lang = JFactory::getLanguage();
// First load the English version
$lang->load('com_attachments.sys', dirname(__FILE__), 'en-GB');
$lang->load('pkg_attachments.sys', dirname(__FILE__), 'en-GB');
// Now load the current language (if not English)
if ( $lang->getTag() != 'en-GB' ) {
// (Double-loading to fall back to Engish if a new term is missing)
$lang->load('com_attachments.sys', dirname(__FILE__), null, true);
$lang->load('pkg_attachments.sys', dirname(__FILE__), null, true);
}
$app->enqueueMessage('
', 'message');
// Check to see if the database type is supported
if (!in_array(JFactory::getDbo()->name, $this->dbSupported))
{
$db_name = $this->dbKnown[JFactory::getDbo()->name];
if (empty($db_name)) {
$db_name = JFactory::getDbo()->name;
}
$errmsg = JText::sprintf('ATTACH_ATTACHMENTS_ERROR_UNSUPPORTED_DB_S', $db_name);
$app->enqueueMessage($errmsg, 'error');
return false;
}
// Verify that the Joomla version is adequate for this version of the Attachments extension
$this->minimum_joomla_release = $parent->get( 'manifest' )->attributes()->version;
if ( version_compare(JVERSION, $this->minimum_joomla_release, 'lt') ) {
$msg = JText::sprintf('ATTACH_ATTACHMENTS_ONLY_WORKS_FOR_VERSION_S_UP', $this->minimum_joomla_release);
if ( $msg == 'ATTACH_ATTACHMENTS_ONLY_WORKS_FOR_VERSION_S_UP' ) {
// Handle unupdated languages
$msg = JText::_('ATTACH_ATTACHMENTS_ONLY_WORKS_FOR_VERSION_16UP');
$msg = str_replace('1.6', $this->minimum_joomla_release, $msg);
}
$app->enqueueMessage($msg, 'error');
return false;
}
// If there is debris from a previous failed attempt to install Attachments, delete it
// NOTE: Creating custom query because using JComponentHelper::isEnabled insists on
// printing a warning if the component is not installed
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select('extension_id AS id, enabled');
$query->from('#__extensions');
$query->where($query->qn('type') . ' = ' . $db->quote('component'));
$query->where($query->qn('element') . ' = ' . $db->quote('com_attachments'));
$db->setQuery($query);
if ( $db->loadResult() == 0 )
{
if (JFolder::exists(JPATH_ROOT . '/components/com_attachments') OR
JFolder::exists(JPATH_ROOT . '/administrator/components/com_attachments'))
{
$msg = JText::_('ATTACH_ERROR_UINSTALL_OLD_VERSION');
$app->enqueueMessage($msg, 'error');
return false;
}
}
// Temporarily move the attachments directory out of the way to avoid conflicts
$attachdir = JPATH_ROOT.'/attachments';
if ( JFolder::exists($attachdir) ) {
// Move the attachments directory out of the way temporarily
$this->moved_attachments_dir = JPATH_ROOT.'/temporarily_renamed_attachments_folder';
if ( JFolder::move($attachdir, $this->moved_attachments_dir) !== true ) {
$msg = JText::sprintf('ATTACH_ERROR_MOVING_ATTACHMENTS_DIR');
$app->enqueueMessage($msg, 'error');
return false;
}
if ( $attachments_install_verbose ) {
$msg = JText::sprintf('ATTACH_TEMPORARILY_RENAMED_ATTACHMENTS_DIR_TO_S', $this->moved_attachments_dir);
$app->enqueueMessage($msg, 'message');
}
}
// ??? Joomla! 2.5x+ bugfix for "Can not build admin menus"
if(in_array($type, array('install','discover_install'))) {
$this->_bugfixDBFunctionReturnedNoError('com_attachments');
}
else {
$this->_bugfixCantBuildAdminMenus('com_attachments');
}
}
/**
* Attachments component postflight function
*
* @param $type : type of installation
* @param $parent : the installer parent
*/
public function postflight($type, $parent)
{
global $attachments_install_verbose, $attachments_install_last_method;
$app = JFactory::getApplication();
$db = JFactory::getDBO();
// Make sure the translations are available
$lang = JFactory::getLanguage();
$lang->load('com_attachments', JPATH_ADMINISTRATOR);
// Enable all the plugins
foreach ($this->plugins as $plugin_name)
{
// Make the query to enable the plugin
$plugin_title = JText::_($plugin_name);
$query = $db->getQuery(true);
$query->update('#__extensions');
$query->set("enabled = 1");
$query->where('type=' . $db->quote('plugin') . ' AND name=' . $db->quote($plugin_name));
$db->setQuery($query);
$db->query();
// Complain if there was an error
if ( $db->getErrorNum() ) {
$errmsg = JText::sprintf('ATTACH_WARNING_FAILED_ENABLING_PLUGIN_S', $plugin_title);
$errmsg .= $db->getErrorMsg();
$app->enqueueMessage($errmsg, 'error');
return false;
}
if ( $attachments_install_verbose ) {
$app->enqueueMessage(JText::sprintf('ATTACH_ENABLED_ATTACHMENTS_PLUGIN_S', $plugin_title), 'message');
}
}
if ( $attachments_install_verbose ) {
$app->enqueueMessage(JText::_('ATTACH_ALL_ATTACHMENTS_PLUGINS_ENABLED'), 'message');
}
// Restore the attachments directory (if renamed)
$attachdir = JPATH_ROOT.'/attachments';
if ( $this->moved_attachments_dir && JFolder::exists($this->moved_attachments_dir) ) {
JFolder::move($this->moved_attachments_dir, $attachdir);
if ( $attachments_install_verbose ) {
$app->enqueueMessage(JText::sprintf('ATTACH_RESTORED_ATTACHMENTS_DIR_TO_S', $attachdir), 'message');
}
}
// If needed, add the 'url_verify' column (may be needed because of SQL update issues)
$attachments_table = '#__attachments';
$cols = $db->getTableColumns($attachments_table);
if ( !array_key_exists('url_verify', $cols))
{
$query = "ALTER TABLE " . $db->quoteName($attachments_table);
$query .= " ADD COLUMN " . $db->quoteName('url_verify');
$query .= " TINYINT(1) UNSIGNED NOT NULL DEFAULT '1'";
$query .= " AFTER " . $db->quoteName('url_relative');
$db->setQuery($query);
if ( !$db->query() ) {
// Ignore any DB errors (may require manual DB mods)
// ??? $errmsg = $db->stderr();
}
}
// Check to see if we should be in secure mode
jimport('joomla.filesystem.file');
$htaccess_file = $attachdir . '/.htaccess';
if ( JFile::exists($htaccess_file) ) {
if ( com_AttachmentsInstallerScript::setSecureMode() ) {
if ( $attachments_install_verbose ) {
$app->enqueueMessage(JText::_('ATTACH_RESTORED_SECURE_MODE'), 'message');
}
}
}
// Add warning message about how to uninstall properly
$emphasis = 'font-size: 125%; font-weight: bold;';
$padding = 'padding: 0.5em 0;';
$pkg_name = JText::_('ATTACH_PACKAGE_ATTACHMENTS_FOR_JOOMLA_16PLUS');
$pkg_uninstall = JText::sprintf('ATTACH_PACKAGE_NOTICE_UNINSTALL_PACKAGE_S', $pkg_name);
$app->enqueueMessage("