Commit d0ea4a77 by Scott

Merge branch 'pr/453' into 1.8

parents cbb831cf aec53ab6
...@@ -145,3 +145,15 @@ function qa_version_check(uri, version, elem, isCore) ...@@ -145,3 +145,15 @@ function qa_version_check(uri, version, elem, isCore)
} }
); );
} }
function qa_get_enabled_plugins_hashes()
{
var hashes = [];
$('[id^=plugin_enabled]:checked').each(
function (idx, elem) {
hashes.push(elem.id.replace("plugin_enabled_", ""));
}
);
$('[name=enabled_plugins_hashes]').val(hashes.join(';'));
}
<?php
/*
Question2Answer by Gideon Greenspan and contributors
http://www.question2answer.org/
File: qa-include/Q2A/Plugin/PluginManager.php
Description: Keeps track of the installed plugins
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
More about this license: http://www.question2answer.org/license.php
*/
class Q2A_Plugin_PluginManager
{
const PLUGIN_DELIMITER = ';';
const OPT_ENABLED_PLUGINS = 'enabled_plugins';
public function getEnabledPlugins($fullPath = false)
{
$pluginDirectories = $this->getEnabledPluginsOption();
if ($fullPath) {
foreach ($pluginDirectories as $key => &$pluginDirectory)
$pluginDirectory = QA_PLUGIN_DIR . $pluginDirectory . '/';
}
return $pluginDirectories;
}
public function setEnabledPlugins($array)
{
$this->setEnabledPluginsOption($array);
}
public function getFilesystemPlugins($fullPath = false)
{
$result = array();
$fileSystemPluginFiles = glob(QA_PLUGIN_DIR . '*/qa-plugin.php');
foreach ($fileSystemPluginFiles as $pluginFile) {
$directory = dirname($pluginFile);
if (!$fullPath) {
$directory = basename($directory);
}
$result[] = $directory;
}
return $result;
}
public function getHashesForPlugins($pluginDirectories)
{
$result = array();
foreach ($pluginDirectories as $pluginDirectory) {
$result[$pluginDirectory] = md5($pluginDirectory);
}
return $result;
}
private function getEnabledPluginsOption()
{
return explode(self::PLUGIN_DELIMITER, qa_opt(self::OPT_ENABLED_PLUGINS));
}
private function setEnabledPluginsOption($array)
{
qa_opt(self::OPT_ENABLED_PLUGINS, implode(self::PLUGIN_DELIMITER, $array));
}
public function cleanRemovedPlugins()
{
$finalEnabledPlugins = array_intersect(
$this->getFilesystemPlugins(),
$this->getEnabledPlugins()
);
$this->setEnabledPluginsOption($finalEnabledPlugins);
}
}
...@@ -608,7 +608,10 @@ ...@@ -608,7 +608,10 @@
*/ */
function qa_admin_plugin_directory_hash($directory) function qa_admin_plugin_directory_hash($directory)
{ {
return md5($directory); $pluginManager = new Q2A_Plugin_PluginManager();
$hashes = $pluginManager->getHashesForPlugins(array($directory));
return reset($hashes);
} }
......
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
exit; exit;
} }
define('QA_DB_VERSION_CURRENT', 63); define('QA_DB_VERSION_CURRENT', 64);
function qa_db_user_column_type_verify() function qa_db_user_column_type_verify()
...@@ -1517,6 +1517,13 @@ ...@@ -1517,6 +1517,13 @@
qa_db_upgrade_query($locktablesquery); qa_db_upgrade_query($locktablesquery);
break; break;
case 64:
$pluginManager = new Q2A_Plugin_PluginManager();
$allPlugins = $pluginManager->getFilesystemPlugins();
$pluginManager->setEnabledPlugins($allPlugins);
break;
// Up to here: Version 1.8 alpha // Up to here: Version 1.8 alpha
} }
......
...@@ -105,6 +105,7 @@ ...@@ -105,6 +105,7 @@
'edit_title' => ' - ^1edit title^2', 'edit_title' => ' - ^1edit title^2',
'emails_per_minute' => 'emails per minute', 'emails_per_minute' => 'emails per minute',
'emails_title' => 'Emails', 'emails_title' => 'Emails',
'enabled' => 'Enabled',
'feed_link' => 'Feed', 'feed_link' => 'Feed',
'feed_link_example' => 'Example feed', 'feed_link_example' => 'Example feed',
'feeds_title' => 'RSS feeds', 'feeds_title' => 'RSS feeds',
......
...@@ -33,6 +33,41 @@ require_once QA_INCLUDE_DIR . 'app/admin.php'; ...@@ -33,6 +33,41 @@ require_once QA_INCLUDE_DIR . 'app/admin.php';
if (!qa_admin_check_privileges($qa_content)) if (!qa_admin_check_privileges($qa_content))
return $qa_content; return $qa_content;
// Prepare content for theme
$qa_content = qa_content_prepare();
$qa_content['title'] = qa_lang_html('admin/admin_title') . ' - ' . qa_lang_html('admin/plugins_title');
$qa_content['error'] = qa_admin_page_error();
$qa_content['script_rel'][] = 'qa-content/qa-admin.js?' . QA_VERSION;
$pluginManager = new Q2A_Plugin_PluginManager();
$pluginManager->cleanRemovedPlugins();
$enabledPlugins = $pluginManager->getEnabledPlugins();
$fileSystemPlugins = $pluginManager->getFilesystemPlugins();
$pluginHashes = $pluginManager->getHashesForPlugins($fileSystemPlugins);
$showpluginforms = true;
if (qa_is_http_post()) {
if (!qa_check_form_security_code('admin/plugins', qa_post_text('qa_form_security_code'))) {
$qa_content['error'] = qa_lang_html('misc/form_security_reload');
$showpluginforms = false;
} else {
if (qa_clicked('dosave')) {
$enabledPluginHashes = qa_post_text('enabled_plugins_hashes');
$enabledPluginHashesArray = explode(';', $enabledPluginHashes);
$pluginDirectories = array_keys(array_intersect($pluginHashes, $enabledPluginHashesArray));
$pluginManager->setEnabledPlugins($pluginDirectories);
qa_redirect('admin/plugins');
}
}
}
// Map modules with options to their containing plugins // Map modules with options to their containing plugins
...@@ -58,19 +93,6 @@ foreach ($moduletypes as $type) { ...@@ -58,19 +93,6 @@ foreach ($moduletypes as $type) {
} }
} }
// Prepare content for theme
$qa_content = qa_content_prepare();
$qa_content['title'] = qa_lang_html('admin/admin_title') . ' - ' . qa_lang_html('admin/plugins_title');
$qa_content['error'] = qa_admin_page_error();
$qa_content['script_rel'][] = 'qa-content/qa-admin.js?' . QA_VERSION;
$pluginfiles = glob(QA_PLUGIN_DIR . '*/qa-plugin.php');
foreach ($moduletypes as $type) { foreach ($moduletypes as $type) {
$modules = qa_load_modules_with($type, 'init_queries'); $modules = qa_load_modules_with($type, 'init_queries');
...@@ -93,19 +115,16 @@ foreach ($moduletypes as $type) { ...@@ -93,19 +115,16 @@ foreach ($moduletypes as $type) {
} }
} }
if (qa_is_http_post() && !qa_check_form_security_code('admin/plugins', qa_post_text('qa_form_security_code'))) {
$qa_content['error'] = qa_lang_html('misc/form_security_reload');
$showpluginforms = false;
} else
$showpluginforms = true;
if (!empty($pluginfiles)) { if (!empty($fileSystemPlugins)) {
$metadataUtil = new Q2A_Util_Metadata(); $metadataUtil = new Q2A_Util_Metadata();
$sortedPluginFiles = array(); $sortedPluginFiles = array();
foreach ($pluginfiles as $pluginFile) { foreach ($fileSystemPlugins as $pluginDirectory) {
$metadata = $metadataUtil->fetchFromAddonPath(dirname($pluginFile)); $metadata = $metadataUtil->fetchFromAddonPath($pluginDirectory);
if (empty($metadata)) { if (empty($metadata)) {
$pluginFile = QA_PLUGIN_DIR . $pluginDirectory . '/qa-plugin.php';
// limit plugin parsing to first 8kB // limit plugin parsing to first 8kB
$contents = file_get_contents($pluginFile, false, null, -1, 8192); $contents = file_get_contents($pluginFile, false, null, -1, 8192);
$metadata = qa_addon_metadata($contents, 'Plugin'); $metadata = qa_addon_metadata($contents, 'Plugin');
...@@ -113,16 +132,17 @@ if (!empty($pluginfiles)) { ...@@ -113,16 +132,17 @@ if (!empty($pluginfiles)) {
$metadata['name'] = isset($metadata['name']) && !empty($metadata['name']) $metadata['name'] = isset($metadata['name']) && !empty($metadata['name'])
? qa_html($metadata['name']) ? qa_html($metadata['name'])
: qa_lang_html('admin/unnamed_plugin'); : qa_lang_html('admin/unnamed_plugin');
$sortedPluginFiles[$pluginFile] = $metadata; $sortedPluginFiles[$pluginDirectory] = $metadata;
} }
qa_sort_by($sortedPluginFiles, 'name'); qa_sort_by($sortedPluginFiles, 'name');
$pluginIndex = -1; $pluginIndex = -1;
foreach ($sortedPluginFiles as $pluginFile => $metadata) { foreach ($sortedPluginFiles as $pluginDirectory => $metadata) {
$pluginIndex++; $pluginIndex++;
$plugindirectory = dirname($pluginFile);
$hash = qa_admin_plugin_directory_hash($plugindirectory); $pluginDirectoryPath = QA_PLUGIN_DIR . $pluginDirectory;
$hash = $pluginHashes[$pluginDirectory];
$showthisform = $showpluginforms && (qa_get('show') == $hash); $showthisform = $showpluginforms && (qa_get('show') == $hash);
$namehtml = $metadata['name']; $namehtml = $metadata['name'];
...@@ -148,7 +168,7 @@ if (!empty($pluginfiles)) { ...@@ -148,7 +168,7 @@ if (!empty($pluginfiles)) {
$authorhtml = ''; $authorhtml = '';
if ($metaver && isset($metadata['update_uri']) && strlen($metadata['update_uri'])) { if ($metaver && isset($metadata['update_uri']) && strlen($metadata['update_uri'])) {
$elementid = 'version_check_' . md5($plugindirectory); $elementid = 'version_check_' . md5($pluginDirectory);
$updatehtml = '(<span id="' . $elementid . '">...</span>)'; $updatehtml = '(<span id="' . $elementid . '">...</span>)';
...@@ -164,12 +184,15 @@ if (!empty($pluginfiles)) { ...@@ -164,12 +184,15 @@ if (!empty($pluginfiles)) {
else else
$deschtml = ''; $deschtml = '';
if (isset($pluginoptionmodules[$plugindirectory]) && !$showthisform) if (isset($pluginoptionmodules[$pluginDirectoryPath]) && !$showthisform) {
$deschtml .= (strlen($deschtml) ? ' - ' : '').'<a href="'. $deschtml .= (strlen($deschtml) ? ' - ' : '') . '<a href="' . qa_admin_plugin_options_path($pluginDirectory) . '">' .
qa_admin_plugin_options_path($plugindirectory).'">'.qa_lang_html('admin/options').'</a>'; qa_lang_html('admin/options') . '</a>';
}
$pluginhtml = $namehtml.' '.$authorhtml.' '.$updatehtml.'<br>'.$deschtml.(strlen($deschtml) ? '<br>' : ''). $enabled = in_array($pluginDirectory, $enabledPlugins);
'<small style="color:#666">'.qa_html($plugindirectory).'/</small>'; $pluginhtml = $namehtml . ' ' . $authorhtml . ' ' . $updatehtml . '<br>';
$pluginhtml .= $deschtml . (strlen($deschtml) > 0 ? '<br>' : '');
$pluginhtml .= '<small style="color:#666">' . qa_html($pluginDirectoryPath) . '/</small>';
if (qa_qa_version_below(@$metadata['min_q2a'])) if (qa_qa_version_below(@$metadata['min_q2a']))
$pluginhtml = '<s style="color:#999">'.$pluginhtml.'</s><br><span style="color:#f00">'. $pluginhtml = '<s style="color:#999">'.$pluginhtml.'</s><br><span style="color:#f00">'.
...@@ -184,14 +207,20 @@ if (!empty($pluginfiles)) { ...@@ -184,14 +207,20 @@ if (!empty($pluginfiles)) {
'style' => 'tall', 'style' => 'tall',
'fields' => array( 'fields' => array(
array( array(
'type' => 'checkbox',
'label' => qa_lang_html('admin/enabled'),
'value' => $enabled,
'tags' => sprintf('id="plugin_enabled_%s"', $hash),
),
array(
'type' => 'custom', 'type' => 'custom',
'html' => $pluginhtml, 'html' => $pluginhtml,
) ),
), ),
); );
if ($showthisform && isset($pluginoptionmodules[$plugindirectory])) { if ($showthisform && isset($pluginoptionmodules[$pluginDirectoryPath])) {
foreach ($pluginoptionmodules[$plugindirectory] as $pluginoptionmodule) { foreach ($pluginoptionmodules[$pluginDirectoryPath] as $pluginoptionmodule) {
$type = $pluginoptionmodule['type']; $type = $pluginoptionmodule['type'];
$name = $pluginoptionmodule['name']; $name = $pluginoptionmodule['name'];
...@@ -200,7 +229,7 @@ if (!empty($pluginfiles)) { ...@@ -200,7 +229,7 @@ if (!empty($pluginfiles)) {
$form = $module->admin_form($qa_content); $form = $module->admin_form($qa_content);
if (!isset($form['tags'])) if (!isset($form['tags']))
$form['tags'] = 'method="post" action="' . qa_admin_plugin_options_path($plugindirectory) . '"'; $form['tags'] = 'method="post" action="' . qa_admin_plugin_options_path($pluginDirectory) . '"';
if (!isset($form['style'])) if (!isset($form['style']))
$form['style'] = 'tall'; $form['style'] = 'tall';
...@@ -217,5 +246,23 @@ if (!empty($pluginfiles)) { ...@@ -217,5 +246,23 @@ if (!empty($pluginfiles)) {
$qa_content['navigation']['sub'] = qa_admin_sub_navigation(); $qa_content['navigation']['sub'] = qa_admin_sub_navigation();
$qa_content['form'] = array(
'tags' => 'method="post" action="' . qa_self_html() . '" name="plugins_form" onsubmit="qa_get_enabled_plugins_hashes(); return true;"',
'style' => 'wide',
'buttons' => array(
'dosave' => array(
'tags' => 'name="dosave"',
'label' => qa_lang_html('admin/save_options_button'),
),
),
'hidden' => array(
'qa_form_security_code' => qa_get_form_security_code('admin/plugins'),
'enabled_plugins_hashes' => '',
),
);
return $qa_content; return $qa_content;
...@@ -58,16 +58,19 @@ ...@@ -58,16 +58,19 @@
require_once QA_JOOMLA_LOAD_FILE; require_once QA_JOOMLA_LOAD_FILE;
} }
qa_initialize_constants_2(); qa_initialize_constants_2();
qa_initialize_modularity(); qa_initialize_modularity();
qa_register_core_modules(); qa_register_core_modules();
qa_load_plugin_files();
qa_load_override_files(); qa_load_override_files();
require_once QA_INCLUDE_DIR.'qa-db.php'; require_once QA_INCLUDE_DIR.'qa-db.php';
qa_db_allow_connect(); qa_db_allow_connect();
qa_load_plugin_files();
// Version comparison functions // Version comparison functions
...@@ -401,16 +404,20 @@ ...@@ -401,16 +404,20 @@
{ {
global $qa_plugin_directory, $qa_plugin_urltoroot; global $qa_plugin_directory, $qa_plugin_urltoroot;
$pluginfiles = glob(QA_PLUGIN_DIR.'*/qa-plugin.php'); $pluginManager = new Q2A_Plugin_PluginManager();
$pluginDirectories = $pluginManager->getEnabledPlugins(true);
$metadataUtil = new Q2A_Util_Metadata(); $metadataUtil = new Q2A_Util_Metadata();
foreach ($pluginfiles as $pluginfile) { foreach ($pluginDirectories as $pluginDirectory) {
$pluginDirectory = dirname($pluginfile); $pluginFile = $pluginDirectory . 'qa-plugin.php';
if (!file_exists($pluginFile))
continue;
$metadata = $metadataUtil->fetchFromAddonPath($pluginDirectory); $metadata = $metadataUtil->fetchFromAddonPath($qa_plugin_directory);
if (empty($metadata)) { if (empty($metadata)) {
// limit plugin parsing to first 8kB // limit plugin parsing to first 8kB
$contents = file_get_contents($pluginfile, false, null, -1, 8192); $contents = file_get_contents($pluginFile, false, null, -1, 8192);
$metadata = qa_addon_metadata($contents, 'Plugin', true); $metadata = qa_addon_metadata($contents, 'Plugin', true);
} }
...@@ -422,10 +429,10 @@ ...@@ -422,10 +429,10 @@
continue; continue;
// these variables are utilized in the qa_register_plugin_* functions // these variables are utilized in the qa_register_plugin_* functions
$qa_plugin_directory = $pluginDirectory . '/'; $qa_plugin_directory = $pluginDirectory;
$qa_plugin_urltoroot = substr($qa_plugin_directory, strlen(QA_BASE_DIR)); $qa_plugin_urltoroot = substr($qa_plugin_directory, strlen(QA_BASE_DIR));
require_once $pluginfile; require_once $pluginFile;
} }
$qa_plugin_directory = null; $qa_plugin_directory = null;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment