/** * Export PHP variables to JS through a script tag * * @param array $export Associative aray where keys are the desired JS variable names * @throws \Exception * * @return string */ static function exportVars(array $export) : string { if (empty($export)) { return ''; } /** @noinspection ES6ConvertVarToLetConst */ $HTML = '<script>var '; foreach ($export as $name => $value) { $type = gettype($value); switch ($type) { case "boolean": $value = $value ? 'true' : 'false'; break; case "array": $value = JSON::encode($value); break; case "string": // regex test if (preg_match(new RegExp('^/(.*)/([a-z]*)$', 'u'), $value, $regex_parts)) { $value = (new RegExp($regex_parts[1], $regex_parts[2]))->jsExport(); } else { $value = JSON::encode($value); } break; case "integer": case "float": case "null": $value = strval($value); break; default: if ($value instanceof RegExp) { $value = $value->jsExport(); break; } throw new \Exception("Exporting unsupported variable {$name} of type {$type}"); } $HTML .= "{$name}={$value},"; } return rtrim($HTML, ',') . '</script>'; }
/** * Redirection * * @param string $url Redirection target URL * @param int $http HTTP status code */ public static function redirect($url = '/', $http = 301) { header("Location: {$url}", true, $http); $urlenc = CoreUtils::aposEncode($url); die("Click <a href='{$urlenc}'>here</a> if you aren't redirected.<script>location.replace(" . JSON::encode($url) . ")</script>"); }
} } Logs::action('appearances', array('action' => 'add', 'id' => $data['id'], 'order' => $data['order'], 'label' => $data['label'], 'notes' => $data['notes'], 'cm_favme' => $data['cm_favme'] ?? null, 'ishuman' => $data['ishuman'], 'cm_preview' => $data['cm_preview'], 'cm_dir' => $data['cm_dir'], 'usetemplate' => $usetemplate ? 1 : 0, 'private' => $data['private'] ? 1 : 0)); Response::done($response); } CGUtils::clearRenderedImages($Appearance['id'], array(CGUtils::CLEAR_PALETTE, CGUtils::CLEAR_PREVIEW)); $response = array(); $diff = array(); foreach (array('label', 'notes', 'cm_favme', 'cm_dir', 'cm_preview', 'private') as $key) { if ($EditedAppearance[$key] !== $Appearance[$key]) { $diff["old{$key}"] = $Appearance[$key]; $diff["new{$key}"] = $EditedAppearance[$key]; } } if (!empty($diff)) { Logs::action('appearance_modify', array('ponyid' => $Appearance['id'], 'changes' => JSON::encode($diff))); } if (!$AppearancePage) { $response['label'] = $EditedAppearance['label']; if ($data['label'] !== $Appearance['label']) { $response['newurl'] = $Appearance['id'] . '-' . Appearances::getSafeLabel($EditedAppearance); } $response['notes'] = Appearances::getNotesHTML($EditedAppearance, NOWRAP); } Response::done($response); break; case "delete": if ($Appearance['id'] === 0) { Response::fail('This appearance cannot be deleted'); } $Tagged = Tags::getFor($Appearance['id'], null, true, false);
<link rel="icon" type="image/png" href="/img/favicons-v1/favicon-16x16.png" sizes="16x16"> <link rel="manifest" href="/img/favicons-v1/manifest.json"> <link rel="mask-icon" href="/img/favicons-v1/safari-pinned-tab.svg" color="#2c73b1"> <meta name="apple-mobile-web-app-title" content="MLP-VectorClub"> <meta name="application-name" content="MLP-VectorClub"> <meta name="msapplication-TileColor" content="#2c73b1"> <meta name="msapplication-TileImage" content="/img/favicons-v1/mstile-144x144.png"> <meta name="msapplication-config" content="/img/favicons-v1/browserconfig.xml"> <link rel="shortcut icon" href="/favicon.ico"> <?php if (isset($norobots)) { echo '<meta name="robots" content="noindex, nofollow">'; } if (isset($redirectto)) { echo '<script>history.replaceState&&history.replaceState(history.state,"",' . JSON::encode($redirectto) . ')</script>' . "\n"; } if (isset($customCSS)) { foreach ($customCSS as $css) { echo "<link rel='stylesheet' href='{$css}'>\n"; } } if (!empty(GA_TRACKING_CODE) && Permission::insufficient('developer')) { ?> <script> (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) })(window,document,'script','https://www.google-analytics.com/analytics.js','ga'); ga('create','<?php
static function send($to, $type, $data) { global $Database; if (empty(self::$_notifTypes[$type])) { throw new \Exception("Invalid notification type: {$type}"); } switch ($type) { case 'post-finished': case 'post-approved': $Database->rawQuery("UPDATE notifications SET read_at = NOW() WHERE \"user\" = ? && type = ? && data->>'id' = ? && data->>'type' = ?", array($to, $type, $data['id'], $data['type'])); } $Database->insert('notifications', array('user' => $to, 'type' => $type, 'data' => JSON::encode($data))); try { CoreUtils::socketEvent('notify-pls', array('user' => $to)); } catch (ServerConnectionFailureException $e) { error_log("Error while notifying {$to} with type {$type} (data:" . JSON::encode($data) . ")\nError message: {$e->getMessage()}"); return 'Notification server is down! Please <a class="send-feedback">let us know</a>.'; } return 0; }
Statistics::processUsageData($RequestData, $Dataset); $Data['datasets'][] = $Dataset; } $ReservationData = $Database->rawQuery(str_replace('table_name', 'reservations', $query)); if (!empty($ReservationData)) { $Dataset = array('label' => 'Reservations', 'clrkey' => 1); Statistics::processUsageData($ReservationData, $Dataset); $Data['datasets'][] = $Dataset; } break; case 'approvals': $Labels = $Database->rawQuery("SELECT to_char(timestamp,'{$LabelFormat}') AS key\n\t\t\t\t\tFROM log\n\t\t\t\t\tWHERE timestamp > NOW() - INTERVAL '2 MONTHS' AND reftype = 'post_lock'\n\t\t\t\t\tGROUP BY key\n\t\t\t\t\tORDER BY MIN(timestamp)"); Statistics::processLabels($Labels, $Data); $Approvals = $Database->rawQuery("SELECT\n\t\t\t\t\t\tto_char(MIN(timestamp),'{$LabelFormat}') AS key,\n\t\t\t\t\t\tCOUNT(*)::INT AS cnt\n\t\t\t\t\tFROM log\n\t\t\t\t\tWHERE timestamp > NOW() - INTERVAL '2 MONTHS' AND reftype = 'post_lock'\n\t\t\t\t\tGROUP BY to_char(timestamp,'{$LabelFormat}')\n\t\t\t\t\tORDER BY MIN(timestamp)"); if (!empty($Approvals)) { $Dataset = array('label' => 'Approved posts'); Statistics::processUsageData($Approvals, $Dataset); $Data['datasets'][] = $Dataset; } break; } Statistics::postprocessTimedData($Data); CoreUtils::createUploadFolder($CachePath); file_put_contents($CachePath, JSON::encode($Data)); Response::done(array('data' => $Data)); } CoreUtils::notFound(); } HTTP::pushResource('/about/stats-posts'); HTTP::pushResource('/about/stats-approvals'); CoreUtils::loadPage(array('title' => 'About', 'do-css', 'js' => array('Chart', $do)));