function CreatePackageJson() { $extensionData = ExtensionData::get(); $count = 0; if ($extensionData && !empty($extensionData)) { $count = $extensionData->Count(); $filename = 'packages.json'; $repo = array('packages' => array()); foreach ($extensionData as $extension) { // Include only Approved extensions if ($extension->Accepted == '1') { $json = new JsonHandler($extension->Url); $jsonData = $json->cloneJson(); $packages = $jsonData['AllRelease']; $dumper = new ArrayDumper(); foreach ($packages as $package) { $repo['packages'][$package->getPrettyName()][$package->getPrettyVersion()] = $dumper->dump($package); } } } if (!empty($repo['packages'])) { $packagesJsonData = Convert::array2json($repo); $packageJsonFile = fopen(BASE_PATH . DIRECTORY_SEPARATOR . $filename, 'w'); fwrite($packageJsonFile, $packagesJsonData); fclose($packageJsonFile); echo "<br /><br /><strong> package.json file created successfully...</strong><br />"; } else { throw new InvalidArgumentException('package.json file could not be created'); } } }
function updateJson() { $extensionData = ExtensionData::get(); $count = 0; if ($extensionData && !empty($extensionData)) { $count = 0; foreach ($extensionData as $extension) { // Include only Approved extensions if ($extension->Accepted == '1') { $json = new JsonHandler($extension->Url); $jsonData = $json->cloneJson(); $updateJson = $json->UpdateJson(); if (array_key_exists('ExtensionID', $updateJson)) { $id = $updateJson['ExtensionID']; $deleteVersion = $json->deleteVersionData($id); if ($deleteVersion) { $saveVersion = $json->saveVersionData($id); if ($saveVersion) { echo "<br>{$extension->Name} is updated <br>"; } } } else { throw new InvalidArgumentException("{$extension->Name} could not updated <br />"); } $count++; } } echo "<br><br><strong>{$count} Repositories processed...</strong><br>"; } else { throw new InvalidArgumentException('No Extension found...'); } }
function testSaveJsonFunction() { $repoUrl = 'https://github.com/vikas-srivastava/extensionmanager.git'; $jsonHandler = new JsonHandler($repoUrl); $jsonHandler->repo = new MockVCSRepositoryWithRealValues(); $result = $jsonHandler->cloneJson(); $this->latestReleasePackage = $result['LatestRelease']; $result = $jsonHandler->saveJson(); $this->assertArrayNotHasKey('ErrorMsg', $result); $this->assertArrayHasKey('ExtensionID', $result); $extensionId = $result['ExtensionID']; $extensionData = ExtensionData::get()->byID($extensionId); list($vendorName, $extensionName) = explode("/", $this->latestReleasePackage->getPrettyName()); $this->assertEquals($extensionData->Name, $extensionName); }
function __construct($widget) { $this->id = $widget->widget; $this->templateTarget = $widget->templateTarget; $this->tags = $widget->tags; $theData = getFile("widgets/" . $this->id . "/widget.json", true); if ($theData == false) { throw new RuntimeException("JSON FILE couldn't be opened."); } try { $json = JsonHandler::decode($theData); $this->name = $json->name; $this->description = $json->description; $this->js = $json->js; $this->dependencies = $json->dependencies; $this->dependenciesCSS = $json->dependenciesCSS; $this->html = $json->html; $this->css = $json->css; } catch (Exception $e) { throw new RuntimeException("JSON FILE corrupted. " . $e); } }
public function setContent($content) { parent::setContent(JsonHandler::encode($content)); }
return; } $theData = getFile($filename); try { $json = JsonHandler::decode($theData); } catch (Exception $e) { echo "ERROR: JSON cant be decoded."; echo "Caught " . $e->getMessage(); return; } } else { echo "ERROR: parameter id is mandatory"; return; } if ($_GET['test'] != '' && $_GET['test'] == 'true') { array_push($json->widgets, JsonHandler::decode('{ "widget": "QUnitWidget", "parameters": { "id": "qunit"}, "templateTarget":"center"}')); } switch ($_GET['type']) { case "json": Header("content-type: application/json"); echo $theData; break; case "js": Header("content-type: application/x-javascript"); //Adding all the mandatory dependencies that are Web based foreach ($mandatoryWeb as $url) { echo "\n//" . $url . "\n" . getUrl($url) . "\n"; } //Adding all the mandatory dependencies that are local files foreach ($mandatoryLocal as $path) { echo "\n//" . $path . "\n" . getFile($path, true);
/** * The form handler. */ public function submitUrl($data, $form) { $url = $data['Url']; if (empty($url)) { $form->sessionMessage(_t('ExtensionHolderPage.BADURL', 'Please enter URL'), 'bad'); return $this->redirectBack(); } elseif (substr($url, 0, 4) != "http" && substr($url, 0, 3) != "git") { $form->sessionMessage(_t('ExtensionHolderPage.BADURL', "Please enter valid 'HTTP' or 'GIT Read-only' URL "), 'bad'); return $this->redirectBack(); } elseif (substr($url, 0, 4) == "git@") { $form->sessionMessage(_t('ExtensionHolderPage.BADURL', "'SSH' URL is not allowed, Please enter valid 'HTTP' or 'GIT Read-only' URL"), 'bad'); return $this->redirectBack(); } $json = new JsonHandler($url); $jsonData = $json->cloneJson(); if (!array_key_exists('ErrorMsg', $jsonData)) { $this->latestReleasePackage = $jsonData['LatestRelease']; if ($this->isNewExtension($url)) { $saveJson = $json->saveJson(); if (!array_key_exists('ErrorMsg', $saveJson)) { $id = $saveJson['ExtensionID']; $saveVersion = $json->saveVersionData($id); if ($saveVersion) { $this->extensionType = ExtensionData::get()->byID($id)->Type; $this->extensionName = ExtensionData::get()->byID($id)->Name; $this->mailData = array('ExtensionType' => $this->extensionType, 'ExtensionName' => $this->extensionName, 'SubmittedByName' => Member::currentUser()->Name, 'SubmittedByEmail' => Member::currentUser()->Email, 'ReviewAtUrl' => Director::absoluteBaseURL() . 'admin/extensions/ExtensionData/EditForm/field/ExtensionData/item/' . $id . '/edit', 'DetailPageLink' => Director::absoluteBaseURL() . strtolower($this->extensionType) . '/show/' . $id, 'Subject' => 'New ' . $this->extensionType . " '" . $this->extensionName . "' " . ' Submitted'); $this->sendMailtoAdmin(); $form->sessionMessage(_t('ExtensionHolderPage.THANKSFORSUBMITTING', 'Thank you for submitting "' . $this->extensionName . '" ' . $this->extensionType), 'good'); return $this->redirectBack(); } } else { $form->sessionMessage(_t('ExtensionHolderPage.PROBLEMINSAVING', "We are unable to save Extension info, the parser reports: {$saveJson['ErrorMsg']} Please Re-check format of you composer.json file."), 'bad'); return $this->redirectBack(); } } else { $updateJson = $json->updateJson(); if (!array_key_exists('ErrorMsg', $updateJson)) { $id = $updateJson['ExtensionID']; $deleteVersion = $json->deleteVersionData($id); if ($deleteVersion) { $saveVersion = $json->saveVersionData($id); if ($saveVersion) { $this->extensionType = ExtensionData::get()->byID($id)->Type; $this->extensionName = ExtensionData::get()->byID($id)->Name; $this->mailData = array('ExtensionType' => $this->extensionType, 'ExtensionName' => $this->extensionName, 'SubmittedByName' => Member::currentUser()->Name, 'SubmittedByEmail' => Member::currentUser()->Email, 'ReviewAtUrl' => Director::absoluteBaseURL() . 'admin/extensions/ExtensionData/EditForm/field/ExtensionData/item/' . $id . '/edit', 'DetailPageLink' => Director::absoluteBaseURL() . strtolower($this->extensionType) . '/show/' . $id, 'Subject' => $this->extensionType . " '" . $this->extensionName . "' " . ' Updated'); $this->sendMailtoAdmin(); $form->sessionMessage(_t('ExtensionHolderPageExtensionHolderPage.THANKSFORUPDATING', 'Thank you for Updating your "' . $this->extensionName . '" ' . $this->extensionType), 'good'); return $this->redirectBack(); } } else { $form->sessionMessage(_t('ExtensionHolderPage.PROBLEMINSAVING', 'Something went wrong we are not able to save versions of submitted extension '), 'bad'); return $this->redirectBack(); } } else { $form->sessionMessage(_t('ExtensionHolderPage.PROBLEMINUPDATING', "We had problems parsing your composer.json file, the parser reports: {$updateJson['ErrorMsg']} Please read our extension Submission Guide for more details and submit url again"), 'bad'); return $this->redirectBack(); } } } else { $form->sessionMessage(_t('ExtensionHolderPage.NOJSON', "We had problems parsing your composer.json file, the parser reports: {$jsonData['ErrorMsg']} Please read our extension Submission Guide for more details and submit url again"), 'bad'); return $this->redirectBack(); } }
<?php // hangreHandler.php require_once $_SERVER['DOCUMENT_ROOT'] . '/hangee/m/lib/__core.php'; $handler = new JsonHandler(); $request = $handler->getRequest(); if ($request == null) { $handler->sendError('Invalid Request!'); die; } $char = $request->character; $query = "select * from hangee_words where word like '{$char}%' and page < 500 order by word asc"; $db = new MySql(); $db->connect(); $res = $db->query($query); $words = array(); while ($row = mysql_fetch_array($res, MYSQL_ASSOC)) { $current = new WordRecord(); $current->wid = $row['id']; $current->page = $row['page']; $current->word = $row['word']; $current->sense = $row['sense']; $words[] = $current; } $db->close(); $handler->sendData($words);
<?php // initListHandler.php require_once $_SERVER['DOCUMENT_ROOT'] . '/hangee/m/lib/__core.php'; $handler = new JsonHandler(); $query = "select id from hangee_words order by id asc"; $db = new MySql(); $db->connect(); $res = $db->query($query); $wids = array(); while ($row = mysql_fetch_array($res, MYSQL_ASSOC)) { $wids[] = $row['id']; } $db->close(); $handler->sendData($wids);