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
1d92c67e
Commit
1d92c67e
authored
Dec 02, 2014
by
Scott
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
More minor improvements to metadata system
Allowed glob() to sort results
parent
89b717fa
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
33 additions
and
32 deletions
+33
-32
Metadata.php
qa-include/Q2A/Util/Metadata.php
+19
-21
admin.php
qa-include/app/admin.php
+7
-7
admin-default.php
qa-include/pages/admin/admin-default.php
+1
-1
admin-plugins.php
qa-include/pages/admin/admin-plugins.php
+4
-1
qa-base.php
qa-include/qa-base.php
+1
-1
metadata.json
qa-theme/SnowFlat/metadata.json
+1
-1
No files found.
qa-include/Q2A/Util/Metadata.php
View file @
1d92c67e
...
...
@@ -22,34 +22,22 @@
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
* @param string $path
Directory the addon is in (without trailing slash)
* @return array The metadata fetched from the
JSON file, or an empty array otherwise
*/
public
function
fetchFromAddonPath
(
$path
)
{
$metadataFile
=
$path
.
'/'
.
self
::
METADATA_FILE_JSON
;
if
(
is_file
(
$metadataFile
))
{
$content
=
file_get_contents
(
$metadataFile
);
return
$this
->
getArrayFromJson
(
$content
);
if
(
!
is_file
(
$metadataFile
))
{
return
array
();
}
return
array
();
$content
=
file_get_contents
(
$metadataFile
);
return
$this
->
getArrayFromJson
(
$content
);
}
/**
...
...
@@ -63,4 +51,15 @@ class Q2A_Util_Metadata
return
$this
->
getArrayFromJson
(
$content
);
}
}
\ No newline at end of file
/**
* 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
();
}
}
qa-include/app/admin.php
View file @
1d92c67e
...
...
@@ -55,14 +55,14 @@
}
/**
* Return a sorted array of available languages, [short code] => [long name]
*/
function
qa_admin_language_options
()
/*
Return a sorted array of available languages, [short code] => [long name]
*/
{
if
(
qa_to_override
(
__FUNCTION__
))
{
$args
=
func_get_args
();
return
qa_call_override
(
__FUNCTION__
,
$args
);
}
/*
/*
*
* @deprecated The hardcoded language ids will be removed in favor of language metadata files.
* See qa-lang/en-GB directory for a clear example of how to use them.
*/
...
...
@@ -121,7 +121,7 @@
// find all language folders
$metadataUtil
=
new
Q2A_Util_Metadata
();
foreach
(
glob
(
QA_LANG_DIR
.
'*'
,
GLOB_
NOSORT
|
GLOB_
ONLYDIR
)
as
$directory
)
{
foreach
(
glob
(
QA_LANG_DIR
.
'*'
,
GLOB_ONLYDIR
)
as
$directory
)
{
$code
=
basename
(
$directory
);
$metadata
=
$metadataUtil
->
fetchFromAddonPath
(
$directory
);
if
(
isset
(
$metadata
[
'display_name'
]))
...
...
@@ -143,12 +143,12 @@
if
(
qa_to_override
(
__FUNCTION__
))
{
$args
=
func_get_args
();
return
qa_call_override
(
__FUNCTION__
,
$args
);
}
$metadataUtil
=
new
Q2A_Util_Metadata
();
foreach
(
glob
(
QA_THEME_DIR
.
'*'
,
GLOB_
NOSORT
|
GLOB_
ONLYDIR
)
as
$directory
)
{
foreach
(
glob
(
QA_THEME_DIR
.
'*'
,
GLOB_ONLYDIR
)
as
$directory
)
{
$theme
=
basename
(
$directory
);
$metadata
=
$metadataUtil
->
fetchFromAddonPath
(
$directory
);
if
(
empty
(
$metadata
))
{
// limit theme parsing to first 8kB
$contents
=
file_get_contents
(
$directory
.
'/qa-styles.css'
,
false
,
NULL
,
-
1
,
8192
);
$contents
=
file_get_contents
(
$directory
.
'/qa-styles.css'
,
false
,
null
,
-
1
,
8192
);
$metadata
=
qa_addon_metadata
(
$contents
,
'Theme'
);
}
$options
[
$theme
]
=
isset
(
$metadata
[
'name'
])
?
$metadata
[
'name'
]
:
$theme
;
...
...
qa-include/pages/admin/admin-default.php
View file @
1d92c67e
...
...
@@ -1011,7 +1011,7 @@
$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
);
$contents
=
file_get_contents
(
$themedirectory
.
'/qa-styles.css'
,
false
,
null
,
-
1
,
8192
);
$metadata
=
qa_addon_metadata
(
$contents
,
'Theme'
);
}
...
...
qa-include/pages/admin/admin-plugins.php
View file @
1d92c67e
...
...
@@ -102,11 +102,12 @@
if
(
!
empty
(
$pluginfiles
))
{
$metadataUtil
=
new
Q2A_Util_Metadata
();
$sortedPluginFiles
=
array
();
foreach
(
$pluginfiles
as
$pluginFile
)
{
$metadata
=
$metadataUtil
->
fetchFromAddonPath
(
dirname
(
$pluginFile
));
if
(
empty
(
$metadata
))
{
// 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
[
'name'
]
=
isset
(
$metadata
[
'name'
])
&&
!
empty
(
$metadata
[
'name'
])
...
...
@@ -115,7 +116,9 @@
;
$sortedPluginFiles
[
$pluginFile
]
=
$metadata
;
}
qa_sort_by
(
$sortedPluginFiles
,
'name'
);
$pluginIndex
=
-
1
;
foreach
(
$sortedPluginFiles
as
$pluginFile
=>
$metadata
)
{
$pluginIndex
++
;
...
...
qa-include/qa-base.php
View file @
1d92c67e
...
...
@@ -343,7 +343,7 @@
$metadata
=
$metadataUtil
->
fetchFromAddonPath
(
$pluginDirectory
);
if
(
empty
(
$metadata
))
{
// 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
);
}
...
...
qa-theme/SnowFlat/metadata.json
View file @
1d92c67e
{
"name"
:
"SnowFlat"
,
"uri"
:
""
,
"description"
:
"S
h
owFlat responsive theme with RTL support"
,
"description"
:
"S
n
owFlat responsive theme with RTL support"
,
"version"
:
"1.4"
,
"date"
:
"2014-03-11"
,
"author"
:
"Q2A Market"
,
...
...
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