Ejemplo n.º 1
0
 /**
  * Fetch metadata information from an URL
  * @param string $url URL linking to a metadata.json file
  * @return array The metadata fetched from the file
  */
 public function fetchFromUrl($url, $type = 'Plugin')
 {
     $contents = qa_retrieve_url($url);
     $metadata = $this->getArrayFromJson($contents);
     // fall back to old metadata format
     if (empty($metadata)) {
         $metadata = qa_addon_metadata($contents, $type);
     }
     return $metadata;
 }
Ejemplo n.º 2
0
     break;
 case 'site_theme':
 case 'site_theme_mobile':
     $themeoptions = qa_admin_theme_options();
     if (!isset($themeoptions[$value])) {
         $value = 'Classic';
     }
     // check here because we also need $value for qa_addon_metadata()
     qa_optionfield_make_select($optionfield, $themeoptions, $value, 'Classic');
     $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']);
     } else {
         $namehtml = '';
     }
     if (strlen(@$metadata['uri'])) {
         if (!strlen($namehtml)) {
             $namehtml = qa_html($value);
         }
         $namehtml = '<a href="' . qa_html($metadata['uri']) . '">' . $namehtml . '</a>';
     }
     $authorhtml = '';
     if (strlen(@$metadata['author'])) {
         $authorhtml = qa_html($metadata['author']);
Ejemplo n.º 3
0
/**
 * Return a sorted array of available themes, [theme name] => [theme name]
 */
function qa_admin_theme_options()
{
    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_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);
            $metadata = qa_addon_metadata($contents, 'Theme');
        }
        $options[$theme] = isset($metadata['name']) ? $metadata['name'] : $theme;
    }
    asort($options, SORT_STRING);
    return $options;
}
Ejemplo n.º 4
0
}
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)) {
    $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);
            $metadata = qa_addon_metadata($contents, 'Plugin');
        }
        $metadata['name'] = isset($metadata['name']) && !empty($metadata['name']) ? qa_html($metadata['name']) : qa_lang_html('admin/unnamed_plugin');
        $sortedPluginFiles[$pluginFile] = $metadata;
    }
    qa_sort_by($sortedPluginFiles, 'name');
    $pluginIndex = -1;
    foreach ($sortedPluginFiles as $pluginFile => $metadata) {
        $pluginIndex++;
        $plugindirectory = dirname($pluginFile);
        $hash = qa_admin_plugin_directory_hash($plugindirectory);
        $showthisform = $showpluginforms && qa_get('show') == $hash;
        $namehtml = $metadata['name'];
        if (isset($metadata['uri']) && strlen($metadata['uri'])) {
            $namehtml = '<a href="' . qa_html($metadata['uri']) . '">' . $namehtml . '</a>';
        }
Ejemplo n.º 5
0
function qa_load_plugin_files()
{
    global $qa_plugin_directory, $qa_plugin_urltoroot;
    $pluginfiles = glob(QA_PLUGIN_DIR . '*/qa-plugin.php');
    $metadataUtil = new Q2A_Util_Metadata();
    foreach ($pluginfiles as $pluginfile) {
        $pluginDirectory = dirname($pluginfile);
        $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', true);
        }
        // skip plugin which requires a later version of Q2A
        if (isset($metadata['min_q2a']) && qa_qa_version_below($metadata['min_q2a'])) {
            continue;
        }
        // skip plugin which requires a later version of PHP
        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 = $pluginDirectory . '/';
        $qa_plugin_urltoroot = substr($qa_plugin_directory, strlen(QA_BASE_DIR));
        require_once $pluginfile;
    }
    $qa_plugin_directory = null;
    $qa_plugin_urltoroot = null;
}