Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Q
question2answer
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
outils
question2answer
Commits
9b171a91
Commit
9b171a91
authored
Oct 17, 2016
by
pupi1985
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add ability to disable plugins
parent
cdee121e
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
198 additions
and
32 deletions
+198
-32
qa-admin.js
qa-content/qa-admin.js
+12
-0
PluginManager.php
qa-include/Q2A/Plugin/PluginManager.php
+94
-0
admin.php
qa-include/app/admin.php
+4
-1
qa-lang-admin.php
qa-include/lang/qa-lang-admin.php
+1
-0
admin-plugins.php
qa-include/pages/admin/admin-plugins.php
+72
-23
qa-base.php
qa-include/qa-base.php
+15
-8
No files found.
qa-content/qa-admin.js
View file @
9b171a91
...
...
@@ -145,3 +145,15 @@ function qa_version_check(uri, version, elem)
}
);
}
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
(
';'
));
}
qa-include/Q2A/Plugin/PluginManager.php
0 → 100644
View file @
9b171a91
<?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
);
}
}
qa-include/app/admin.php
View file @
9b171a91
...
...
@@ -608,7 +608,10 @@
*/
function
qa_admin_plugin_directory_hash
(
$directory
)
{
return
md5
(
$directory
);
$pluginManager
=
new
Q2A_Plugin_PluginManager
();
$hashes
=
$pluginManager
->
getHashesForPlugins
(
array
(
$directory
));
return
reset
(
$hashes
);
}
...
...
qa-include/lang/qa-lang-admin.php
View file @
9b171a91
...
...
@@ -105,6 +105,7 @@
'edit_title'
=>
' - ^1edit title^2'
,
'emails_per_minute'
=>
'emails per minute'
,
'emails_title'
=>
'Emails'
,
'enabled'
=>
'Enabled'
,
'feed_link'
=>
'Feed'
,
'feed_link_example'
=>
'Example feed'
,
'feeds_title'
=>
'RSS feeds'
,
...
...
qa-include/pages/admin/admin-plugins.php
View file @
9b171a91
...
...
@@ -69,7 +69,14 @@ $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'
);
$pluginManager
=
new
Q2A_Plugin_PluginManager
();
$pluginManager
->
cleanRemovedPlugins
();
$enabledPlugins
=
$pluginManager
->
getEnabledPlugins
();
$fileSystemPlugins
=
$pluginManager
->
getFilesystemPlugins
();
$pluginHashes
=
$pluginManager
->
getHashesForPlugins
(
$fileSystemPlugins
);
foreach
(
$moduletypes
as
$type
)
{
$modules
=
qa_load_modules_with
(
$type
,
'init_queries'
);
...
...
@@ -77,6 +84,7 @@ foreach ($moduletypes as $type) {
foreach
(
$modules
as
$name
=>
$module
)
{
$queries
=
$module
->
init_queries
(
$tables
);
if
(
!
empty
(
$queries
))
{
if
(
qa_is_http_post
())
qa_redirect
(
'install'
);
...
...
@@ -93,19 +101,32 @@ 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
;
$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'
);
}
}
}
if
(
!
empty
(
$
pluginfile
s
))
{
if
(
!
empty
(
$
fileSystemPlugin
s
))
{
$metadataUtil
=
new
Q2A_Util_Metadata
();
$sortedPluginFiles
=
array
();
foreach
(
$
pluginfiles
as
$pluginFile
)
{
$metadata
=
$metadataUtil
->
fetchFromAddonPath
(
dirname
(
$pluginFile
)
);
foreach
(
$
fileSystemPlugins
as
$pluginDirectory
)
{
$metadata
=
$metadataUtil
->
fetchFromAddonPath
(
$pluginDirectory
);
if
(
empty
(
$metadata
))
{
$pluginFile
=
QA_PLUGIN_DIR
.
$pluginDirectory
.
'/qa-plugin.php'
;
// limit plugin parsing to first 8kB
$contents
=
file_get_contents
(
$pluginFile
,
false
,
null
,
-
1
,
8192
);
$metadata
=
qa_addon_metadata
(
$contents
,
'Plugin'
);
...
...
@@ -113,16 +134,17 @@ if (!empty($pluginfiles)) {
$metadata
[
'name'
]
=
isset
(
$metadata
[
'name'
])
&&
!
empty
(
$metadata
[
'name'
])
?
qa_html
(
$metadata
[
'name'
])
:
qa_lang_html
(
'admin/unnamed_plugin'
);
$sortedPluginFiles
[
$plugin
File
]
=
$metadata
;
$sortedPluginFiles
[
$plugin
Directory
]
=
$metadata
;
}
qa_sort_by
(
$sortedPluginFiles
,
'name'
);
$pluginIndex
=
-
1
;
foreach
(
$sortedPluginFiles
as
$plugin
File
=>
$metadata
)
{
foreach
(
$sortedPluginFiles
as
$plugin
Directory
=>
$metadata
)
{
$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
);
$namehtml
=
$metadata
[
'name'
];
...
...
@@ -148,7 +170,7 @@ if (!empty($pluginfiles)) {
$authorhtml
=
''
;
if
(
$metaver
&&
isset
(
$metadata
[
'update_uri'
])
&&
strlen
(
$metadata
[
'update_uri'
]))
{
$elementid
=
'version_check_'
.
md5
(
$plugin
d
irectory
);
$elementid
=
'version_check_'
.
md5
(
$plugin
D
irectory
);
$updatehtml
=
'(<span id="'
.
$elementid
.
'">...</span>)'
;
...
...
@@ -164,12 +186,15 @@ if (!empty($pluginfiles)) {
else
$deschtml
=
''
;
if
(
isset
(
$pluginoptionmodules
[
$plugindirectory
])
&&
!
$showthisform
)
$deschtml
.=
(
strlen
(
$deschtml
)
?
' - '
:
''
)
.
'<a href="'
.
qa_admin_plugin_options_path
(
$plugindirectory
)
.
'">'
.
qa_lang_html
(
'admin/options'
)
.
'</a>'
;
if
(
isset
(
$pluginoptionmodules
[
$pluginDirectoryPath
])
&&
!
$showthisform
)
{
$deschtml
.=
(
strlen
(
$deschtml
)
?
' - '
:
''
)
.
'<a href="'
.
qa_admin_plugin_options_path
(
$pluginDirectory
)
.
'">'
.
qa_lang_html
(
'admin/options'
)
.
'</a>'
;
}
$pluginhtml
=
$namehtml
.
' '
.
$authorhtml
.
' '
.
$updatehtml
.
'<br>'
.
$deschtml
.
(
strlen
(
$deschtml
)
?
'<br>'
:
''
)
.
'<small style="color:#666">'
.
qa_html
(
$plugindirectory
)
.
'/</small>'
;
$enabled
=
in_array
(
$pluginDirectory
,
$enabledPlugins
);
$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'
]))
$pluginhtml
=
'<s style="color:#999">'
.
$pluginhtml
.
'</s><br><span style="color:#f00">'
.
...
...
@@ -184,14 +209,20 @@ if (!empty($pluginfiles)) {
'style'
=>
'tall'
,
'fields'
=>
array
(
array
(
'type'
=>
'checkbox'
,
'label'
=>
qa_lang_html
(
'admin/enabled'
),
'value'
=>
$enabled
,
'tags'
=>
sprintf
(
'id="plugin_enabled_%s"'
,
$hash
),
),
array
(
'type'
=>
'custom'
,
'html'
=>
$pluginhtml
,
)
)
,
),
);
if
(
$showthisform
&&
isset
(
$pluginoptionmodules
[
$plugin
directory
]))
{
foreach
(
$pluginoptionmodules
[
$plugin
directory
]
as
$pluginoptionmodule
)
{
if
(
$showthisform
&&
isset
(
$pluginoptionmodules
[
$plugin
DirectoryPath
]))
{
foreach
(
$pluginoptionmodules
[
$plugin
DirectoryPath
]
as
$pluginoptionmodule
)
{
$type
=
$pluginoptionmodule
[
'type'
];
$name
=
$pluginoptionmodule
[
'name'
];
...
...
@@ -200,7 +231,7 @@ if (!empty($pluginfiles)) {
$form
=
$module
->
admin_form
(
$qa_content
);
if
(
!
isset
(
$form
[
'tags'
]))
$form
[
'tags'
]
=
'method="post" action="'
.
qa_admin_plugin_options_path
(
$plugin
d
irectory
)
.
'"'
;
$form
[
'tags'
]
=
'method="post" action="'
.
qa_admin_plugin_options_path
(
$plugin
D
irectory
)
.
'"'
;
if
(
!
isset
(
$form
[
'style'
]))
$form
[
'style'
]
=
'tall'
;
...
...
@@ -217,5 +248,23 @@ if (!empty($pluginfiles)) {
$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
;
qa-include/qa-base.php
View file @
9b171a91
...
...
@@ -58,16 +58,19 @@
require_once
QA_JOOMLA_LOAD_FILE
;
}
qa_initialize_constants_2
();
qa_initialize_modularity
();
qa_register_core_modules
();
qa_load_plugin_files
();
qa_load_override_files
();
require_once
QA_INCLUDE_DIR
.
'qa-db.php'
;
qa_db_allow_connect
();
qa_load_plugin_files
();
// Version comparison functions
...
...
@@ -399,16 +402,20 @@
{
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
();
foreach
(
$pluginfiles
as
$pluginfile
)
{
$pluginDirectory
=
dirname
(
$pluginfile
);
foreach
(
$pluginDirectories
as
$pluginDirectory
)
{
$pluginFile
=
$pluginDirectory
.
'qa-plugin.php'
;
if
(
!
file_exists
(
$pluginFile
))
continue
;
$metadata
=
$metadataUtil
->
fetchFromAddonPath
(
$
pluginD
irectory
);
$metadata
=
$metadataUtil
->
fetchFromAddonPath
(
$
qa_plugin_d
irectory
);
if
(
empty
(
$metadata
))
{
// limit plugin parsing to first 8kB
$contents
=
file_get_contents
(
$plugin
f
ile
,
false
,
null
,
-
1
,
8192
);
$contents
=
file_get_contents
(
$plugin
F
ile
,
false
,
null
,
-
1
,
8192
);
$metadata
=
qa_addon_metadata
(
$contents
,
'Plugin'
,
true
);
}
...
...
@@ -420,10 +427,10 @@
continue
;
// 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
));
require_once
$plugin
f
ile
;
require_once
$plugin
F
ile
;
}
$qa_plugin_directory
=
null
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment