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
b5aca36a
Commit
b5aca36a
authored
Nov 27, 2014
by
pupi1985
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added backwards compatible support to handle local metadata.json files in plugins and themes
parent
a6277bc8
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
89 additions
and
18 deletions
+89
-18
Metadata.php
qa-include/Q2A/Util/Metadata.php
+56
-0
admin-default.php
qa-include/pages/admin/admin-default.php
+8
-3
admin-plugins.php
qa-include/pages/admin/admin-plugins.php
+7
-3
qa-base.php
qa-include/qa-base.php
+18
-12
No files found.
qa-include/Q2A/Util/Metadata.php
0 → 100644
View file @
b5aca36a
<?php
/*
Question2Answer by Gideon Greenspan and contributors
http://www.question2answer.org/
File: qa-include/Q2A/Util/Metadata.php
Description: Some useful metadata handling stuff
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_Util_Metadata
{
const
METADATA_FILE_JSON
=
'metadata.json'
;
/**
* Return an array from a JSON string
* @param mixed $json The JSON string to turn into an array
* @return array Always return an array containing the decoded JSON or an empty array in case the
* $json parameter is not a valid JSON string
*/
private
function
getArrayFromJson
(
$json
)
{
$result
=
json_decode
(
$json
,
true
);
return
is_array
(
$result
)
?
$result
:
array
();
}
/**
* Fetch metadata information from an addon path
* @param string $path Path to the addon
* @return array The metadata fetched from the metadata.json file in the addon path
*/
public
function
fetchFromAddonPath
(
$path
)
{
$metadataFile
=
$path
.
self
::
METADATA_FILE_JSON
;
if
(
is_file
(
$metadataFile
))
{
$content
=
file_get_contents
(
$metadataFile
);
return
$this
->
getArrayFromJson
(
$content
);
}
return
array
();
}
}
\ No newline at end of file
qa-include/pages/admin/admin-default.php
View file @
b5aca36a
...
...
@@ -1006,9 +1006,14 @@
qa_optionfield_make_select
(
$optionfield
,
$themeoptions
,
$value
,
'Classic'
);
// limit theme parsing to first 8kB
$contents
=
file_get_contents
(
QA_THEME_DIR
.
$value
.
'/qa-styles.css'
,
false
,
NULL
,
-
1
,
8192
);
$metadata
=
qa_addon_metadata
(
$contents
,
'Theme'
);
$metadataUtil
=
new
Q2A_Util_Metadata
();
$themedirectory
=
QA_THEME_DIR
.
$value
.
'/'
;
$metadata
=
$metadataUtil
->
fetchFromAddonPath
(
$themedirectory
);
if
(
empty
(
$metadata
))
{
// limit theme parsing to first 8kB
$contents
=
file_get_contents
(
$themedirectory
.
'qa-styles.css'
,
false
,
NULL
,
-
1
,
8192
);
$metadata
=
qa_addon_metadata
(
$contents
,
'Theme'
);
}
if
(
strlen
(
@
$metadata
[
'version'
]))
$namehtml
=
'v'
.
qa_html
(
$metadata
[
'version'
]);
...
...
qa-include/pages/admin/admin-plugins.php
View file @
b5aca36a
...
...
@@ -100,14 +100,18 @@
$showpluginforms
=
true
;
if
(
count
(
$pluginfiles
))
{
$metadataUtil
=
new
Q2A_Util_Metadata
();
foreach
(
$pluginfiles
as
$pluginindex
=>
$pluginfile
)
{
$plugindirectory
=
dirname
(
$pluginfile
)
.
'/'
;
$hash
=
qa_admin_plugin_directory_hash
(
$plugindirectory
);
$showthisform
=
$showpluginforms
&&
(
qa_get
(
'show'
)
==
$hash
);
// limit plugin parsing to first 8kB
$contents
=
file_get_contents
(
$pluginfile
,
false
,
NULL
,
-
1
,
8192
);
$metadata
=
qa_addon_metadata
(
$contents
,
'Plugin'
);
$metadata
=
$metadataUtil
->
fetchFromAddonPath
(
$plugindirectory
);
if
(
empty
(
$metadata
))
{
// limit plugin parsing to first 8kB
$contents
=
file_get_contents
(
$pluginfile
,
false
,
NULL
,
-
1
,
8192
);
$metadata
=
qa_addon_metadata
(
$contents
,
'Plugin'
);
}
if
(
isset
(
$metadata
[
'name'
])
&&
strlen
(
$metadata
[
'name'
]))
$namehtml
=
qa_html
(
$metadata
[
'name'
]);
...
...
qa-include/qa-base.php
View file @
b5aca36a
...
...
@@ -288,12 +288,14 @@
}
/**
* Retrieve metadata information from the $contents of a qa-theme.php or qa-plugin.php file, specified by $type ('Plugin' or 'Theme').
* If $versiononly is true, only min version metadata is parsed.
* Name, Description, Min Q2A & Min PHP are not currently used by themes.
*
* @deprecated Deprecated from 1.7; Q2A_Util_Metadata class and metadata.json files should be used instead
*/
function
qa_addon_metadata
(
$contents
,
$type
,
$versiononly
=
false
)
/*
Retrieve metadata information from the $contents of a qa-theme.php or qa-plugin.php file, specified by $type ('Plugin' or 'Theme').
If $versiononly is true, only min version metadata is parsed.
Name, Description, Min Q2A & Min PHP are not currently used by themes.
*/
{
$fields
=
array
(
'min_q2a'
=>
'Minimum Question2Answer Version'
,
...
...
@@ -334,10 +336,18 @@
$pluginfiles
=
glob
(
QA_PLUGIN_DIR
.
'*/qa-plugin.php'
);
$metadataUtil
=
new
Q2A_Util_Metadata
();
foreach
(
$pluginfiles
as
$pluginfile
)
{
// limit plugin parsing to first 8kB
$contents
=
file_get_contents
(
$pluginfile
,
false
,
NULL
,
-
1
,
8192
);
$metadata
=
qa_addon_metadata
(
$contents
,
'Plugin'
,
true
);
// these variables are utilized in the qa_register_plugin_* functions
$qa_plugin_directory
=
dirname
(
$pluginfile
)
.
'/'
;
$qa_plugin_urltoroot
=
substr
(
$qa_plugin_directory
,
strlen
(
QA_BASE_DIR
));
$metadata
=
$metadataUtil
->
fetchFromAddonPath
(
$qa_plugin_directory
);
if
(
empty
(
$metadata
))
{
// limit plugin parsing to first 8kB
$contents
=
file_get_contents
(
$pluginfile
,
false
,
NULL
,
-
1
,
8192
);
$metadata
=
qa_addon_metadata
(
$contents
,
'Plugin'
,
true
);
}
// skip plugin which requires a later version of Q2A
if
(
isset
(
$metadata
[
'min_q2a'
])
&&
qa_qa_version_below
(
$metadata
[
'min_q2a'
]))
...
...
@@ -346,10 +356,6 @@
if
(
isset
(
$metadata
[
'min_php'
])
&&
qa_php_version_below
(
$metadata
[
'min_php'
]))
continue
;
// these variables are utilized in the qa_register_plugin_* functions
$qa_plugin_directory
=
dirname
(
$pluginfile
)
.
'/'
;
$qa_plugin_urltoroot
=
substr
(
$qa_plugin_directory
,
strlen
(
QA_BASE_DIR
));
require_once
$pluginfile
;
}
...
...
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