/** * Registers the editor javascript file and code to initialize the editor. */ protected function registerEditorClientScript($writer) { $this->loadJavascriptLibrary(); $scripts = $this->getPage()->getClientScript(); $options = array('EditorOptions' => $this->getEditorOptions()); $options = TJavaScript::encode($options, true, true); $script = "new {$this->getClientClassName()}({$options})"; $scripts->registerEndScript('prado:THtmlArea4' . $this->ClientID, $script); }
/** * @return array list of callback options. */ protected function getPostBackOptions() { //disallow page state update ? //$this->getActiveControl()->getClientSide()->setEnablePageStateUpdate(false); $options = array(); if (strlen($string = $this->getSeparator())) { $string = strtr($string, array('\\t' => "\t", '\\n' => "\n", '\\r' => "\r")); $token = preg_split('//', $string, -1, PREG_SPLIT_NO_EMPTY); $options['tokens'] = TJavaScript::encode($token, false); } if ($this->getAutoPostBack()) { $options = array_merge($options, parent::getPostBackOptions()); $options['AutoPostBack'] = true; } if (strlen($select = $this->getTextCssClass())) { $options['select'] = $select; } $options['ResultPanel'] = $this->getResultPanel()->getClientID(); $options['ID'] = $this->getClientID(); $options['EventTarget'] = $this->getUniqueID(); if (($minchars = $this->getMinChars()) !== '') { $options['minChars'] = $minchars; } if (($frequency = $this->getFrequency()) !== '') { $options['frequency'] = $frequency; } $options['CausesValidation'] = $this->getCausesValidation(); $options['ValidationGroup'] = $this->getValidationGroup(); return $options; }
/** * @param string callback requestion options as javascript code. */ public function getJsCallbackOptions() { return TJavaScript::encode($this->getClientSideOptions()); }
/** * Registers the relevant JavaScript. */ protected function registerClientScript() { $id = $this->getClientID(); $options = TJavaScript::encode($this->getClientOptions()); $className = $this->getClientClassName(); $page = $this->getPage(); $cs = $page->getClientScript(); $cs->registerPradoScript('accordion'); $code = "new {$className}({$options});"; $cs->registerEndScript("prado:{$id}", $code); // ensure an item is always active and visible $index = $this->getActiveViewIndex(); if (!$this->getViews()->itemAt($index)->Visible) { $index = 0; } $cs->registerHiddenField($id . '_1', $index); $page->registerRequiresPostData($this); $page->registerRequiresPostData($id . "_1"); }
/** * Registers the relevant JavaScript. */ protected function registerClientScript() { $options = TJavaScript::encode($this->getClientOptions()); $className = $this->getClientClassName(); $cs = $this->getPage()->getClientScript(); $cs->registerPradoScript('keyboard'); $cs->registerEndScript('prado:' . $this->getClientID(), "new {$className}({$options});"); }
/** * Adds on client-side event handler by wrapping the code within a * javascript function block. If the code begins with "javascript:", the * code is assumed to be a javascript function block rather than arbiturary * javascript statements. * @param string option name * @param string javascript statements. */ protected function setFunction($name, $code) { if (!TJavaScript::isFunction($code)) { $code = TJavaScript::quoteFunction($this->ensureFunction($code)); } $this->setOption($name, $code); }
/** * Registers the editor javascript file and code to initialize the editor. */ protected function registerEditorClientScript($writer) { $this->loadJavascriptLibrary(); $scripts = $this->getPage()->getClientScript(); $options = array('EditorOptions' => $this->getEditorOptions()); if ($this->getEnableCompression()) { $options['CompressionOptions'] = $this->getCompressionOptions(); } $options = TJavaScript::encode($options, true, true); $script = "new Prado.WebUI.THtmlArea({$options})"; $scripts->registerEndScript('prado:THtmlArea' . $this->ClientID, $script); }
public function renderContents($writer) { $readyscript = 'jQuery(document).trigger(' . TJavaScript::quoteString('captchaready:' . $this->getClientID()) . ')'; $cs = $this->Page->ClientScript; $id = $this->getClientID(); $divid = $id . '_1_recaptchadiv'; $writer->write('<div id="' . htmlspecialchars($divid) . '">'); if (!$this->Page->IsCallback) { $writer->write(TJavaScript::renderScriptBlock('var RecaptchaOptions = ' . TJavaScript::jsonEncode($this->getClientSideOptions()) . ';')); $html = recaptcha_get_html($this->getPublicKey()); /* reCAPTCHA currently does not support multiple validations per page $html = str_replace( array(self::ChallengeFieldName,self::ResponseFieldName), array($this->getChallengeFieldName(),$this->getResponseFieldName()), $html ); */ $writer->write($html); $cs->registerEndScript('ReCaptcha::EventScript', 'jQuery(document).ready(function() { ' . $readyscript . '; } );'); } else { $options = $this->getClientSideOptions(); $options['callback'] = new TJavaScriptLiteral('function() { ' . $readyscript . '; ' . $this->getCallbackScript() . '; }'); $cs->registerScriptFile('ReCaptcha::AjaxScript', 'http://www.google.com/recaptcha/api/js/recaptcha_ajax.js'); $cs->registerEndScript('ReCaptcha::CreateScript::' . $id, implode(' ', array('if (!jQuery(' . TJavaScript::quoteString('#' . $this->getResponseFieldName()) . '))', '{', 'Recaptcha.destroy();', 'Recaptcha.create(', TJavaScript::quoteString($this->getPublicKey()) . ', ', TJavaScript::quoteString($divid) . ', ', TJavaScript::encode($options), ');', '}'))); } $writer->write('</div>'); }
/** * Registers the individual validator client-side javascript code. */ protected function registerClientScriptValidator() { $key = 'prado:' . $this->getClientID(); if (!$this->getPage()->getClientScript()->isEndScriptRegistered($key)) { $options = TJavaScript::encode($this->getClientScriptOptions()); $script = 'new ' . $this->getClientClassName() . '(' . $options . ');'; $this->getPage()->getClientScript()->registerEndScript($key, $script); } }
/** * Get javascript sliderr options. * @return array slider client-side options */ protected function getSliderOptions() { // PostBack Options : $options['ID'] = $this->getClientID(); $options['EventTarget'] = $this->getUniqueID(); $options['AutoPostBack'] = $this->getAutoPostBack(); // Slider Control options $minValue = $this->getMinValue(); $maxValue = $this->getMaxValue(); $options['axis'] = strtolower($this->getDirection()); $options['maximum'] = $maxValue; $options['minimum'] = $minValue; $options['range'] = 'javascript:$R(' . $minValue . "," . $maxValue . ")"; $options['sliderValue'] = $this->getValue(); $options['disabled'] = !$this->getEnabled(); $values = $this->getValues(); if (!empty($values)) { // Values are provided. Check if min/max are present in them if (!in_array($minValue, $values)) { $values[] = $minValue; } if (!in_array($maxValue, $values)) { $values[] = $maxValue; } // Remove all values outsize the range [min..max] foreach ($values as $idx => $value) { if ($value < $minValue) { unset($values[$idx]); } if ($value > $maxValue) { unset($values[$idx]); } } } else { // Values are not provided, generate automatically using stepsize $step = $this->getStepSize(); // We want at most self::MAX_STEPS values, so, change the step if necessary if (($maxValue - $minValue) / $step > self::MAX_STEPS) { $step = ($maxValue - $minValue) / self::MAX_STEPS; } $values = array(); for ($i = $minValue; $i <= $maxValue; $i += $step) { $values[] = $i; } // Add max if it's not in the array because of step if (!in_array($maxValue, $values)) { $values[] = $maxValue; } } $options['values'] = TJavaScript::Encode($values, false); if ($this->_clientScript !== null) { $options = array_merge($options, $this->_clientScript->getOptions()->toArray()); } return $options; }
public function toJavaScriptLiteral() { return TJavaScript::jsonEncode((string) $this->_s, JSON_HEX_QUOT | JSON_HEX_APOS | JSON_HEX_TAG); }
/** * Registers the relevant JavaScript. */ protected function registerClientScript() { $id = $this->getClientID(); $options = TJavaScript::encode($this->getClientOptions()); $className = $this->getClientClassName(); $page = $this->getPage(); $cs = $page->getClientScript(); $cs->registerPradoScript('tabpanel'); $code = "new {$className}({$options});"; $cs->registerEndScript("prado:{$id}", $code); $cs->registerHiddenField($id . '_1', $this->getActiveViewIndex()); $page->registerRequiresPostData($this); $page->registerRequiresPostData($id . "_1"); }
/** * Registers the editor javascript file and code to initialize the editor. */ protected function registerEditorClientScript($writer) { $scripts = $this->getPage()->getClientScript(); $options = TJavaScript::encode($this->getEditorOptions()); $script = "new CSHtmlArea({$options});"; $scripts->registerEndScript('CSHtmlArea:' . $this->getClientID(), $script); }
/** * Renders content provided by TJsonResponse::getJsonContent() as * javascript in JSON format. */ protected function createJsonResponse($service, $properties, $config) { // init service properties foreach ($properties as $name => $value) { $service->setSubproperty($name, $value); } $service->init($config); //send content if not null if (($content = $service->getJsonContent()) !== null) { $response = $this->getResponse(); $response->setContentType('application/json'); $response->setCharset('UTF-8'); //send content $response->write(TJavaScript::jsonEncode($content)); } }
/** * Displays the exceptions to the client-side TJavascriptLogger. * A HTTP 500 status code is sent and the stack trace is sent as JSON encoded. * @param Exception exception details. */ protected function displayException($exception) { if ($this->getApplication()->getMode() === TApplication::STATE_DEBUG) { $response = $this->getApplication()->getResponse(); $trace = $this->getExceptionStackTrace($exception); // avoid error on non-utf8 strings try { $trace = TJavaScript::jsonEncode($trace); } catch (Exception $e) { // strip everythin not 7bit ascii $trace = preg_replace('/[^(\\x20-\\x7F)]*/', '', serialize($trace)); } // avoid exception loop if headers have already been sent try { $response->setStatusCode(500, 'Internal Server Error'); } catch (Exception $e) { } $content = $response->createHtmlWriter(); $content->getWriter()->setBoundary(TActivePageAdapter::CALLBACK_ERROR_HEADER); $content->write($trace); } else { error_log("Error happened while processing an existing error:\n" . $exception->__toString()); header('HTTP/1.0 500 Internal Server Error', true, 500); } $this->getApplication()->getResponse()->flush(); }
public function onPreRender($param) { parent::onPreRender($param); $cs = $this->Page->getClientScript(); $cs->registerPradoScript('validator'); // communicate validation status to the client side $value = $this->_isvalid === false ? '0' : '1'; $cs->registerHiddenField($this->getClientID() . '_1', $value); // update validator display if ($control = $this->getValidationTarget()) { $fn = 'captchaUpdateValidatorStatus_' . $this->getClientID(); // check if we need to request a new captcha too if ($this->Page->IsCallback) { if ($control->getVisible(true)) { if (!is_null($this->_isvalid)) { // if the response has been tested and we reach the pre-render phase // then we need to regenerate the token, because it won't test positive // anymore, even if solves correctly $control->regenerateToken(); } } } $cs->registerEndScript($this->getClientID() . '::validate', implode(' ', array('function ' . $fn . '(valid)', '{', ' jQuery(' . TJavaScript::quoteString('#' . $this->getClientID() . '_1') . ').val(valid);', ' Prado.Validation.validateControl(' . TJavaScript::quoteString($control->ClientID) . '); ', '}', '', $this->Page->IsCallback ? $fn . '(' . $value . ');' : '', '', 'jQuery("#' . $control->getClientID() . '").on("keyup", ' . TJavaScript::quoteString('#' . $control->getResponseFieldName()) . ', function() { ', $fn . '("1");', '});'))); } }
/** * Decodes a javascript string into PHP variable. * This method invokes {@TJSON} utility class to perform the decoding. * @param string string to be decoded * @return mixed decoded variable */ public static function jsonDecode($value) { if (self::$_json === null) { self::$_json = Prado::createComponent('System.Web.Javascripts.TJSON'); } return self::$_json->decode($value); }
/** * Render the javascript for validation summary. * @param array list of options for validation summary. */ protected function renderJsSummary() { if (!$this->getEnabled(true) || !$this->getEnableClientScript()) { return; } $cs = $this->getPage()->getClientScript(); $cs->registerPradoScript('validator'); //need to register the validation manager is validation summary is alone. $formID = $this->getPage()->getForm()->getClientID(); $scriptKey = "TBaseValidator:{$formID}"; if ($this->getEnableClientScript() && !$cs->isEndScriptRegistered($scriptKey)) { $manager['FormID'] = $formID; $options = TJavaScript::encode($manager); $cs->registerPradoScript('validator'); $cs->registerEndScript($scriptKey, "new Prado.ValidationManager({$options});"); } $options = TJavaScript::encode($this->getClientScriptOptions()); $script = "new Prado.WebUI.TValidationSummary({$options});"; $cs->registerEndScript($this->getClientID(), $script); }
/** * Register the callback clientscripts and sets the post loader IDs. */ protected function renderCallbackClientScripts() { $cs = $this->getPage()->getClientScript(); $key = 'Prado.CallbackRequest.addPostLoaders'; if (!$cs->isEndScriptRegistered($key)) { $data = $this->getPage()->getPostDataLoaders(); if (count($data) > 0) { $options = TJavaScript::encode($data, false); $script = "Prado.CallbackRequest.addPostLoaders({$options});"; $cs->registerEndScript($key, $script); } } }
/** * Displays the exceptions to the client-side TJavascriptLogger. * A HTTP 500 status code is sent and the stack trace is sent as JSON encoded. * @param Exception exception details. */ protected function displayException($exception) { if ($this->getApplication()->getMode() === TApplication::STATE_DEBUG) { $response = $this->getApplication()->getResponse(); $trace = TJavaScript::jsonEncode($this->getExceptionStackTrace($exception)); $response->setStatusCode(500, 'Internal Server Error'); $response->appendHeader(TActivePageAdapter::CALLBACK_ERROR_HEADER . ': ' . $trace); } else { error_log("Error happened while processing an existing error:\n" . $exception->__toString()); header('HTTP/1.0 500 Internal Server Error', true, 500); } $this->getApplication()->getResponse()->flush(); }
protected function renderClientControlScript($writer) { if ($this->getShowCalendar()) { $cs = $this->getPage()->getClientScript(); if (!$cs->isEndScriptRegistered('TDatePicker.spacer')) { $spacer = $this->getAssetUrl('spacer.gif'); $code = "Prado.WebUI.TDatePicker.spacer = '{$spacer}';"; $cs->registerEndScript('TDatePicker.spacer', $code); } $options = TJavaScript::encode($this->getDatePickerOptions()); $code = "new Prado.WebUI.TDatePicker({$options});"; $cs->registerEndScript("prado:" . $this->getClientID(), $code); } }
/** * @return string header template with "Copy code" link. */ protected function getHeaderTemplate() { $id = $this->getClientID(); return TJavaScript::renderScriptBlock("new Prado.WebUI.TTextHighlighter('{$id}');"); }
protected function processCallbackRequest($writer) { Prado::using('System.Web.UI.ActiveControls.TActivePageAdapter'); $this->setAdapter(new TActivePageAdapter($this)); $callbackEventParameter = $this->getRequest()->itemAt(TPage::FIELD_CALLBACK_PARAMETER); if (strlen($callbackEventParameter) > 0) { $this->_postData[TPage::FIELD_CALLBACK_PARAMETER] = TJavaScript::jsonDecode((string) $callbackEventParameter); } if (($g = $this->getApplication()->getGlobalization(false)) !== null && strtoupper($enc = $g->getCharset()) != 'UTF-8') { foreach ($this->_postData as $k => $v) { $this->_postData[$k] = self::decodeUTF8($v, $enc); } } $this->onPreInit(null); $this->initRecursive(); $this->onInitComplete(null); $this->_restPostData = new TMap(); $this->loadPageState(); $this->processPostData($this->_postData, true); $this->onPreLoad(null); $this->loadRecursive(); $this->processPostData($this->_restPostData, false); $this->raiseChangedEvents(); $this->getAdapter()->processCallbackEvent($writer); $this->onLoadComplete(null); $this->preRenderRecursive(); $this->onPreRenderComplete(null); $this->savePageState(); $this->onSaveStateComplete(null); $this->getAdapter()->renderCallbackResponse($writer); $this->unloadRecursive(); }
/** * Registers the editor javascript file and code to initialize the editor. */ protected function registerEditorClientScript($writer) { $scripts = $this->getPage()->getClientScript(); $options = TJavaScript::encode($this->getEditorOptions(), true, true); // Force encoding of empty strings $script = "if(typeof(tinyMCE)!='undefined'){ tinyMCE.init({$options}); }"; $scripts->registerEndScript('prado:THtmlArea' . $this->ClientID, $script); }
/** * Publish the color picker assets. */ protected function publishColorPickerAssets() { $cs = $this->getPage()->getClientScript(); $key = "prado:" . get_class($this); $imgs['button.gif'] = $this->getAssetUrl('button.gif'); $imgs['background.png'] = $this->getAssetUrl('background.png'); $options = TJavaScript::encode($imgs); $code = "Prado.WebUI.TColorPicker.UIImages = {$options};"; $cs->registerEndScript($key, $code); $cs->registerPradoScript("colorpicker"); $url = $this->getAssetUrl($this->getColorPickerStyle() . '.css'); if (!$cs->isStyleSheetFileRegistered($url)) { $cs->registerStyleSheetFile($url, $url); } }
protected function registerClientScript() { $path = 'javascripts' . DIRECTORY_SEPARATOR; $cs = $this->getPage()->getClientScript(); //$cs->registerBeginScript('PWCInitJS','var PWCInitJS="";'); if (!$cs->isScriptFileRegistered('PWCWindow')) { $cs->registerPradoScript('effects'); $cs->registerScriptFile('PWCWindow', $this->publishAsset($path . 'window.js')); //$cs->registerScriptFile('PWCPrado',$this->publishAsset($path.'pwc-prado.js')); } $options = $this->getClientOptions(); switch ($this->getMode()) { case 'Existing': $endJS2 = "Prado.Registry.get('{$this->ClientID}').setContent('{$this->Content}',{$this->AutoResize},{$this->AutoPosition});\";"; break; case 'Url': $options['url'] = $this->getContent(); $endJS2 = '"'; break; case 'HTML': $escaped = str_replace(array('"', "\n", "\r", "\t"), array('\\"'), $this->Content); $endJS2 = "Prado.Registry.get('{$this->ClientID}').setHTMLContent('{$escaped}');\";"; break; default: $endJS2 = '"'; break; } $options = TJavaScript::encode($options); $endJS = "Windows.codes['{$this->ClientID}']=\"Prado.Registry.set('{$this->ClientID}', new Window('{$this->ClientID}',{$options}));" . $endJS2; $cs->registerEndScript('PWCCode:' . $this->getClientID(), $endJS); }