Commit 1d92c67e by Scott

More minor improvements to metadata system

Allowed glob() to sort results
parent 89b717fa
......@@ -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();
}
}
......@@ -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;
......
......@@ -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');
}
......
......@@ -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++;
......
......@@ -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);
}
......
{
"name": "SnowFlat",
"uri": "",
"description": "ShowFlat responsive theme with RTL support",
"description": "SnowFlat responsive theme with RTL support",
"version": "1.4",
"date": "2014-03-11",
"author": "Q2A Market",
......
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