public function testOutputContent() { $obj = new _Json(); $json_data = ['first_element' => 'test', 'second_element' => ['a' => 'test a', 'b' => 'test b']]; $json_content = file_get_contents(TEST_FILES . 'test_output_pretty.json'); $json_output = $obj->outputContent($json_data, false, true); $this->string($json_output)->isEqualTo($json_content); $json_content = file_get_contents(TEST_FILES . 'test_output.json'); $json_output = $obj->outputContent($json_data, false, false); $this->string($json_output)->isEqualTo($json_content); }
use Bugzilla\Bugzilla; use Cache\Cache; $json = isset($_GET['json']); $locale = $_GET['locale']; // Include all data about our locales include __DIR__ . '/../data/locales.php'; // Check that this is a valid locale code called via GET if (!isset($_GET['locale']) || !in_array($_GET['locale'], $locales)) { $content = '<h2>Wrong locale code</h2>'; include __DIR__ . '/../views/error.php'; return; } else { $locale = $_GET['locale']; } // Get lang files status from langchecker $json_data = new Json(); $lang_files = $json_data->setURI(LANG_CHECKER . "?locale={$locale}&json")->fetchContent(); // Check if the locale is working on locamotion $cache_id = 'locamotion_locales'; if (!($locamotion = Cache::getKey($cache_id))) { $locamotion = $json_data->setURI(LANG_CHECKER . '?action=listlocales&project=locamotion&json')->fetchContent(); Cache::setKey($cache_id, $locamotion); } $locamotion = in_array($locale, $locamotion); // All open bugs for a locale in the mozilla.org/l10n component $bugzilla_query_mozillaorg = 'https://bugzilla.mozilla.org/buglist.cgi?' . 'f1=cf_locale' . '&o1=equals' . '&query_format=advanced' . '&v1=' . urlencode(Bugzilla::getBugzillaLocaleField($locale)) . '&o2=equals' . '&f2=component' . '&v2=L10N' . '&bug_status=UNCONFIRMED' . '&bug_status=NEW' . '&bug_status=ASSIGNED' . '&bug_status=REOPENED' . '&classification=Other' . '&product=www.mozilla.org'; // All open bugs for a locale in the Mozilla Localization/locale component, with "webdashboard" in the whiteboard $bugzilla_query_l10ncomponent = 'https://bugzilla.mozilla.org/buglist.cgi?' . '&query_format=advanced' . '&status_whiteboard_type=allwordssubstr' . '&status_whiteboard=webdashboard' . '&bug_status=UNCONFIRMED' . '&bug_status=NEW' . '&bug_status=ASSIGNED' . '&bug_status=REOPENED' . '&component=' . urlencode(Bugzilla::getBugzillaLocaleField($locale, 'l10n')) . '&classification=Client%20Software' . '&product=Mozilla%20Localizations'; /* Use cached requests if available, cache expires after 1 hour * Note: result can be empty, so I need to check strictly for false */
*/ namespace Webdashboard; use Bugzilla\Bugzilla; use Cache\Cache; require_once __DIR__ . '/../config/init.php'; // Include all data about our locales include __DIR__ . '/../data/locales.php'; $results = []; $results['types']["Webbugs"] = ["pluralLabel" => "Webbugs"]; $results['properties']["total_webbugs"] = ["valueType" => "number"]; $results['properties']["missing_webbugs"] = ["valueType" => "number"]; // All opened bugs for a locale in the mozilla.org/l10n component foreach ($locales as $locale) { $bugzilla_query = 'https://bugzilla.mozilla.org/buglist.cgi?' . 'f1=cf_locale' . '&o1=equals' . '&query_format=advanced' . '&v1=' . urlencode(Bugzilla::getBugzillaLocaleField($locale)) . '&o2=equals' . '&f2=component' . '&v2=L10N' . '&bug_status=UNCONFIRMED' . '&bug_status=NEW' . '&bug_status=ASSIGNED' . '&bug_status=REOPENED' . '&classification=Other' . '&product=www.mozilla.org'; /* Check if there is a cached request for this element. * For this request I use a ttl of 6 hours instead of default (15 minutes), * since it requires a lot of time. */ $cache_id = "bugs_mozillaorg_{$locale}"; $bugs = Cache::getKey($cache_id, 6 * 60 * 60); if ($bugs === false) { $csv = file($bugzilla_query . '&ctype=csv'); $bugs = Bugzilla::getBugsFromCSV($csv); Cache::setKey($cache_id, $bugs); } // Generate all the bugs $results['items'][] = ["type" => "Webbugs", "label" => $locale, "missing_webbugs" => count($bugs), "total_webbugs" => count($bugs)]; } $json_data = new Json(); print $json_data->outputContent($results, false, true);
<?php namespace Webdashboard; use Cache\Cache; // Check if the locale is working on locamotion $json_data = new Json(); $cache_id = 'locamotion_locales'; if (!($locamotion = Cache::getKey($cache_id))) { $locamotion = $json_data->setURI(LANG_CHECKER . '?action=listlocales&project=locamotion&json')->fetchContent(); Cache::setKey($cache_id, $locamotion); } // Base for the query to get external data $langchecker_query = LANG_CHECKER . '?locale=all&json'; $locale_done = []; // Include all data about project pages include __DIR__ . '/../data/project.php'; // Fall back to default if the project is not available $requested_project = array_key_exists($project, $projects) ? $project : 'default'; $project_data = $projects[$requested_project]; $pages = $project_data['pages']; $sum_pages = count($pages); // Get all locales from project pages list $locales = []; foreach ($pages as $page) { $filename = $page['file']; $json_string = $langchecker_query . '&file=' . $filename . '&website=' . $page['site']; $cache_id = 'page_' . $filename . '_' . $page['site']; if (!($data_page = Cache::getKey($cache_id))) { $data_page = $json_data->setURI($json_string)->fetchContent()[$filename]; Cache::setKey($cache_id, $data_page);