当前位置: 首页>>代码示例>>PHP>>正文


PHP Convert::raw2js方法代码示例

本文整理汇总了PHP中Convert::raw2js方法的典型用法代码示例。如果您正苦于以下问题:PHP Convert::raw2js方法的具体用法?PHP Convert::raw2js怎么用?PHP Convert::raw2js使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Convert的用法示例。


在下文中一共展示了Convert::raw2js方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: validate

 /**
  * Overloaded so that form error messages are displayed.
  * 
  * @see OrderFormValidator::php()
  * @see Form::validate()
  */
 function validate()
 {
     if ($this->validator) {
         $errors = $this->validator->validate();
         if ($errors) {
             if (Director::is_ajax() && $this->validator->getJavascriptValidationHandler() == 'prototype') {
                 FormResponse::status_message(_t('Form.VALIDATIONFAILED', 'Validation failed'), 'bad');
                 foreach ($errors as $error) {
                     FormResponse::add(sprintf("validationError('%s', '%s', '%s');\n", Convert::raw2js($error['fieldName']), Convert::raw2js($error['message']), Convert::raw2js($error['messageType'])));
                 }
             } else {
                 $data = $this->getData();
                 $formError = array();
                 if ($formMessageType = $this->MessageType()) {
                     $formError['message'] = $this->Message();
                     $formError['messageType'] = $formMessageType;
                 }
                 // Load errors into session and post back
                 Session::set("FormInfo.{$this->FormName()}", array('errors' => $errors, 'data' => $data, 'formError' => $formError));
             }
             return false;
         }
     }
     return true;
 }
开发者ID:helpfulrobot,项目名称:swipestripe-swipestripe,代码行数:31,代码来源:AddToCartForm.php

示例2: javascriptTemplate

 /**
  * Load the given javascript template with the page.
  * @param file The template file to load.
  * @param vars The array of variables to load.  These variables are loaded via string search & replace.
  */
 static function javascriptTemplate($file, $vars, $uniquenessID = null)
 {
     $script = file_get_contents(Director::getAbsFile($file));
     foreach ($vars as $k => $v) {
         $search[] = '$' . $k;
         $replace[] = str_replace("\\'", "'", Convert::raw2js($v));
     }
     $script = str_replace($search, $replace, $script);
     Requirements::customScript($script, $uniquenessID);
 }
开发者ID:ramziammar,项目名称:websites,代码行数:15,代码来源:Requirements.php

示例3: emailpreview

 /**
  * Send the preview/test email
  * @param SS_HTTPRequest $request
  */
 public function emailpreview(SS_HTTPRequest $request = null)
 {
     $emailVar = $request->getVar('email');
     $recipient = new Recipient(Recipient::$test_data);
     if ($request && !empty($emailVar)) {
         $recipient->Email = Convert::raw2js($emailVar);
     } else {
         $recipient->Email = Member::currentUser()->Email;
     }
     $newsletter = $this->record;
     $email = new NewsletterEmail($newsletter, $recipient, true);
     $email->send();
     return Controller::curr()->redirectBack();
 }
开发者ID:alexandruz,项目名称:silverstripe-newsletter,代码行数:18,代码来源:NewsletterGridFieldDetailForm.php

示例4: Field

 function Field($options = array())
 {
     //GENERAL
     Requirements::javascript(THIRDPARTY_DIR . '/jquery/jquery.js');
     Requirements::javascript("datefield_simplified/javascript/SimpleDateField.js");
     $this->addExtraClass("simpledatefield");
     $this->setAttribute("placeholder", $this->Config()->get("placeholder_value"));
     $html = parent::Field($options);
     $fieldID = $this->id();
     $url = Convert::raw2js(Director::absoluteBaseURL() . Config::inst()->get("SimpleDateField_Controller", "url") . "/ajaxvalidation/");
     $objectID = $fieldID . "_OBJECT";
     Requirements::customScript("\r\n\t\t\tvar {$objectID} = new SimpleDateFieldAjaxValidationAPI('" . $fieldID . "');\r\n\t\t\t{$objectID}.init();\r\n\t\t\t{$objectID}.setVar('url', '{$url}');\r\n\t\t\t", 'func_SimpleDateField' . $fieldID);
     return $html;
 }
开发者ID:helpfulrobot,项目名称:sunnysideup-datefield-simplified,代码行数:14,代码来源:SimpleDateField.php

示例5: redirectToExternalLogin

    /**
     * Redirects the user to the external login page
     *
     * @return SS_HTTPResponse
     */
    protected function redirectToExternalLogin()
    {
        $loginURL = Security::create()->Link('login');
        $loginURLATT = Convert::raw2att($loginURL);
        $loginURLJS = Convert::raw2js($loginURL);
        $message = _t('CMSSecurity.INVALIDUSER', '<p>Invalid user. <a target="_top" href="{link}">Please re-authenticate here</a> to continue.</p>', 'Message displayed to user if their session cannot be restored', array('link' => $loginURLATT));
        $this->response->setStatusCode(200);
        $this->response->setBody(<<<PHP
<!DOCTYPE html>
<html><body>
{$message}
<script type="text/javascript">
setTimeout(function(){top.location.href = "{$loginURLJS}";}, 0);
</script>
</body></html>
PHP
);
        return $this->response;
    }
开发者ID:jakedaleweb,项目名称:AtomCodeChallenge,代码行数:24,代码来源:CMSSecurity.php

示例6: run

 function run(DataObjectSet $pages)
 {
     $pageIDs = $pages->column('ID');
     foreach ($pageIDs as $pageID) {
         FormResponse::add("\$('Form_EditForm').reloadIfSetTo({$pageID});");
     }
     $count = array();
     $count['PUBLISH_SUCCESS'] = $count['DELETE_SUCCESS'] = 0;
     $count['PUBLISH_FAILURE'] = $count['DELETE_FAILURE'] = 0;
     $arbitraryPage = $pages->First();
     $arbitraryPage->invokeWithExtensions('onBeforeBatchPublish', $pages);
     foreach ($pages as $page) {
         $type = $page->openWorkflowRequest() instanceof WorkflowDeletionRequest ? 'DELETE' : 'PUBLISH';
         if ($page->batchPublish()) {
             $count[$type . '_SUCCESS']++;
             // Now make sure the tree title is appropriately updated
             $publishedRecord = DataObject::get_by_id('SiteTree', $page->ID);
             if ($publishedRecord) {
                 $JS_title = Convert::raw2js($publishedRecord->TreeTitle());
                 FormResponse::add("\$('sitetree').setNodeTitle({$page->ID}, '{$JS_title}');");
             }
         } else {
             $count[$type . '_FAILURE']++;
             FormResponse::add("\$('sitetree').addNodeClassByIdx('{$page->ID}', 'failed');");
         }
         $page->destroy();
         unset($page);
     }
     $arbitraryPage->invokeWithExtensions('onAfterBatchPublish', $pages);
     $messages = array('PUBLISH_SUCCESS' => _t('BatchPublishPages.PUBLISH_SUCCESS', 'Published %d pages.'), 'PUBLISH_FAILURE' => _t('BatchPublishPages.PUBLISH_FAILURE', 'Failed to publish %d pages.'), 'DELETE_SUCCESS' => _t('BatchPublishPages.DELETE_SUCCESS', 'Deleted %d pages from the published site.'), 'DELETE_FAILURE' => _t('BatchPublishPages.DELETE_FAILURE', 'Failed to delete %d pages from the published site.'), 'PUBLISH_SUCCESS_ONE' => _t('BatchPublishPages.PUBLISH_SUCCESS_ONE', 'Published %d page.'), 'PUBLISH_FAILURE_ONE' => _t('BatchPublishPages.PUBLISH_FAILURE_ONE', 'Failed to publish %d page.'), 'DELETE_SUCCESS_ONE' => _t('BatchPublishPages.DELETE_SUCCESS_ONE', 'Deleted %d page from the published site.'), 'DELETE_FAILURE_ONE' => _t('BatchPublishPages.DELETE_FAILURE_ONE', 'Failed to delete %d page from the published site.'));
     $displayedMessages = array();
     foreach ($count as $type => $count) {
         if ($count) {
             $message = $count == 1 ? $messages[$type . '_ONE'] : $messages[$type];
             $displayedMessages[] = sprintf($message, $count);
         }
     }
     $displayedMessage = implode(" ", $displayedMessages);
     FormResponse::add('statusMessage("' . $displayedMessage . '","good");');
     return FormResponse::respond();
 }
开发者ID:helpfulrobot,项目名称:silverstripe-cmsworkflow,代码行数:41,代码来源:BatchPublishPages.php

示例7: forTemplate

 function forTemplate()
 {
     $page = $this->CurrentPage();
     if ($page) {
         $description = str_replace(array("\n", "\r"), "", $page->MetaDescription);
         $title = Convert::raw2js($page->Title);
         $level1 = $page->Level(1);
         $level2 = $page->Level(2);
         if ($level1->URLSegment == 'modes') {
             $level1 = $level2;
             $level2 = $page->Level(3);
         }
         if ($level2 && $level1->URLSegment == 'home') {
             $level1 = $level2;
             $level2 = $page->Level(3);
         }
         $section = $level1->Title;
         $service = $level2 ? $level2->Title : $section;
         $fullURL = $page->Link();
         $imprintID = ImprintStats::$imprintID;
         return "<!-- Start: Nexsys Imprint Code (Copyright Nexsys Development Ltd 2002-2005) -->\n\t\t<script src=\"cms/javascript/ImprintStats.js\" type=\"text/javascript\"></script>\n\t\t<script type=\"text/javascript\">\n\t\t//<![CDATA[\t\n\t\tvar NI_DESCRIPTION = \"{$description}\";\n\t\tvar NI_SECTION = \"{$section}\";\n\t\tvar NI_SERVICE = \"{$service}\";\n\t\tvar NI_TRIGGER = \"{$trigger}\";\n\t\tvar NI_AMOUNT = \"0\";\n\t\tvar NI_ADCAMPAIGN = \"\";\n\t\tvar NI_TITLE = \"{$title}\";\n\t\tvar NI_URL = \"{$fullURL}\";\n\t\tvar NI_BASKET_ADD = \"\";\n\t\tvar NI_BASKET_REMOVE = \"\";\n\t\tvar NI_PARAMETERS = \"\";\n\t\t\n\t\tif (typeof(NI_IW) != \"undefined\") ni_TrackHit(\"imprint1.nexsysdev.net\", {$imprintID}, NI_DESCRIPTION, NI_SECTION, NI_SERVICE, NI_TRIGGER, NI_AMOUNT, NI_ADCAMPAIGN, NI_TITLE, NI_URL, 1, NI_BASKET_ADD, NI_BASKET_REMOVE, NI_PARAMETERS);\n\t\telse document.write('<div style=\"position:absolute;width:1px;height:1px;overflow:hidden\"><img src=\"http://imprint1.nexsysdev.net/Hit.aspx?tv=1&sc={$imprintID}&js=1\" width=\"1\" height=\"1\" style=\"border:0\" alt=\"Nexsys Imprint\"/></div>');\n\t\t//]]>\n\t\t</script>\n\t\t\n\t\t<noscript>\n\t\t<div style=\"position:absolute;width:1px;height:1px;overflow:hidden\"><a href=\"http://www.nexsysdev.com\"><img src=\"http://imprint1.nexsysdev.net/Hit.aspx?tv=1&sc=55075&lo=&st=&sv=&tr=&ac=&js=0\" width=\"1\" height=\"1\" alt=\"Nexsys Imprint\" /></a></div>\n\t\t</noscript>\n\t\t<!-- End: Nexsys Imprint Code -->";
     }
 }
开发者ID:ramziammar,项目名称:websites,代码行数:23,代码来源:ImprintStats.php

示例8: output

    /**
     * Send this HTTPReponse to the browser
     */
    public function output()
    {
        // Attach appropriate X-Include-JavaScript and X-Include-CSS headers
        if (Director::is_ajax()) {
            Requirements::include_in_response($this);
        }
        if (in_array($this->statusCode, self::$redirect_codes) && headers_sent($file, $line)) {
            $url = Director::absoluteURL($this->headers['Location'], true);
            $urlATT = Convert::raw2htmlatt($url);
            $urlJS = Convert::raw2js($url);
            $title = Director::isDev() ? "{$urlATT}... (output started on {$file}, line {$line})" : "{$urlATT}...";
            echo <<<EOT
<p>Redirecting to <a href="{$urlATT}" title="Click this link if your browser does not redirect you">{$title}</a></p>
<meta http-equiv="refresh" content="1; url={$urlATT}" />
<script type="text/javascript">setTimeout(function(){
\twindow.location.href = "{$urlJS}";
}, 50);</script>";
EOT;
        } else {
            $line = $file = null;
            if (!headers_sent($file, $line)) {
                header($_SERVER['SERVER_PROTOCOL'] . " {$this->statusCode} " . $this->getStatusDescription());
                foreach ($this->headers as $header => $value) {
                    header("{$header}: {$value}", true, $this->statusCode);
                }
            } else {
                // It's critical that these status codes are sent; we need to report a failure if not.
                if ($this->statusCode >= 300) {
                    user_error("Couldn't set response type to {$this->statusCode} because " . "of output on line {$line} of {$file}", E_USER_WARNING);
                }
            }
            // Only show error pages or generic "friendly" errors if the status code signifies
            // an error, and the response doesn't have any body yet that might contain
            // a more specific error description.
            if (Director::isLive() && $this->isError() && !$this->body) {
                Debug::friendlyError($this->statusCode, $this->getStatusDescription());
            } else {
                echo $this->body;
            }
        }
    }
开发者ID:nickbooties,项目名称:silverstripe-framework,代码行数:44,代码来源:HTTPResponse.php

示例9: setPopupCaption

 /**
  * Sets the popup-title by javascript. Make sure to use FormResponse in ajax-requests,
  * otherwise the title-change will only take effect on items existing during page-load.
  *
  * @param $caption String
  */
 function setPopupCaption($caption)
 {
     $this->popupCaption = Convert::raw2js($caption);
 }
开发者ID:racontemoi,项目名称:shibuichi,代码行数:10,代码来源:ComplexTableField.php

示例10: update_dom_id

 /**
  * Replace a given DOM-element with the given content.
  * It automatically prefills {$non_ajax_content} with the passed content (as a fallback).
  * 
  * @param $domID string The DOM-ID of an HTML-element that should be replaced
  * @param $domContent string The new HTML-content
  * @param $reapplyBehaviour boolean Applies behaviour to the given domID after refreshing it
  * @param $replaceMethod string Method for replacing - either 'replace' (=outerHTML) or 'update' (=innerHTML)
  *   (Caution: "outerHTML" might cause problems on the client-side, e.g. on table-tags)
  * 
  * @todo More fancy replacing with loading-wheel etc.
  */
 static function update_dom_id($domID, $domContent, $reapplyBehaviour = true, $replaceMethod = 'replace', $uniquenessID = null)
 {
     //self::$non_ajax_content = $domContent;
     $JS_domID = Convert::raw2js($domID);
     $JS_domContent = Convert::raw2js($domContent);
     $JS_replaceMethod = Convert::raw2js($replaceMethod);
     if (isset($uniquenessID)) {
         self::$rules[$uniquenessID] = "Element.{$JS_replaceMethod}('{$JS_domID}','{$JS_domContent}');";
     } else {
         self::$rules[] = "Element.{$JS_replaceMethod}('{$JS_domID}','{$JS_domContent}');";
     }
     if ($reapplyBehaviour) {
         if (isset($uniquenessID)) {
             self::$behaviour_apply_rules[$uniquenessID] .= "Behaviour.apply('{$JS_domID}', true);";
         } else {
             self::$behaviour_apply_rules[] = "Behaviour.apply('{$JS_domID}', true);";
         }
     }
 }
开发者ID:nicmart,项目名称:comperio-site,代码行数:31,代码来源:FormResponse.php

示例11: getJavascript

 /**
  * retuns the customised Javascript for the form field.
  * @return String
  */
 protected function getJavascript()
 {
     return "\n\t\t\tvar GoogleAddressField" . $this->id() . " = new GoogleAddressField( '" . Convert::raw2js($this->getName()) . "')\n\t\t\t\t.setVar('errorMessageMoreSpecific', '" . Convert::raw2js(_t("GoogleAddressField.ERROR_MESSAGE_MORE_SPECIFIC", "Error: please enter a more specific location.")) . "')\n\t\t\t\t.setVar('errorMessageAddressNotFound', '" . Convert::raw2js(_t("GoogleAddressField.ERROR_MESSAGE_ADDRESS_NOT_FOUND", "Error: sorry, address could not be found.")) . "')\n\t\t\t\t.setVar('findNewAddressText', '" . Convert::raw2js(_t("GoogleAddressField.FIND_NEW_ADDRESS", "Find Alternative Address")) . "')\n\t\t\t\t.setVar('useSensor', " . Convert::raw2js($this->userSensor ? "true" : "false") . ")\n\t\t\t\t.setVar('relatedFields', " . Convert::raw2json($this->getFieldMap()) . ")\n\t\t\t\t.setVar('googleStaticMapLink', '" . Convert::raw2js($this->googleStaticMapLink) . "')\n\t\t\t\t.setVar('linkLabelToViewMap', '" . Convert::raw2js(_t("GoogleAddressField.LINK_LABEL_TO_VIEW_MAP", "view map")) . "')\n\t\t\t\t.init();";
 }
开发者ID:helpfulrobot,项目名称:sunnysideup-google-address-field,代码行数:8,代码来源:GoogleAddressField.php

示例12: redirectToChangePassword

    /**
     * Redirect the user to the change password form.
     *
     * @return SS_HTTPResponse
     */
    protected function redirectToChangePassword()
    {
        // Since this form is loaded via an iframe, this redirect must be performed via javascript
        $changePasswordForm = new ChangePasswordForm($this->controller, 'ChangePasswordForm');
        $changePasswordForm->sessionMessage(_t('Member.PASSWORDEXPIRED', 'Your password has expired. Please choose a new one.'), 'good');
        // Get redirect url
        $changePasswordURL = $this->getExternalLink('changepassword');
        if ($backURL = $this->controller->getRequest()->requestVar('BackURL')) {
            Session::set('BackURL', $backURL);
            $changePasswordURL = Controller::join_links($changePasswordURL, '?BackURL=' . urlencode($backURL));
        }
        $changePasswordURLATT = Convert::raw2att($changePasswordURL);
        $changePasswordURLJS = Convert::raw2js($changePasswordURL);
        $message = _t('CMSMemberLoginForm.PASSWORDEXPIRED', '<p>Your password has expired. <a target="_top" href="{link}">Please choose a new one.</a></p>', 'Message displayed to user if their session cannot be restored', array('link' => $changePasswordURLATT));
        // Redirect to change password page
        $this->controller->getResponse()->setStatusCode(200);
        $this->controller->getResponse()->setBody(<<<PHP
<!DOCTYPE html>
<html><body>
{$message}
<script type="application/javascript">
setTimeout(function(){top.location.href = "{$changePasswordURLJS}";}, 0);
</script>
</body></html>
PHP
);
        return $this->controller->getResponse();
    }
开发者ID:assertchris,项目名称:silverstripe-framework,代码行数:33,代码来源:CMSMemberLoginForm.php

示例13: savefile

    /**
     * Action handler for the save button on the file subform.
     * Saves the file
     */
    public function savefile($data, $form)
    {
        $record = DataObject::get_by_id("File", $data['ID']);
        if (!$record) {
            return $this->httpError(400);
        }
        $form->saveInto($record);
        $record->write();
        $title = Convert::raw2js($record->Title);
        $name = Convert::raw2js($record->Name);
        $saved = sprintf(_t('AssetAdmin.SAVEDFILE', 'Saved file %s'), "#{$data['ID']}");
        echo <<<JS
\t\t\tstatusMessage('{$saved}');
\t\t\t\$('record-{$data['ID']}').getElementsByTagName('td')[1].innerHTML = "{$title}";
\t\t\t\$('record-{$data['ID']}').getElementsByTagName('td')[2].innerHTML = "{$name}";
JS;
    }
开发者ID:comperio,项目名称:silverstripe-cms,代码行数:21,代码来源:AssetAdmin.php

示例14: cleanJS

 protected function cleanJS($s)
 {
     $s = Convert::raw2js($s);
     $s = str_replace("\r\n", " ", $s);
     $s = str_replace("\n", " ", $s);
     $s = str_replace('/', '\\/', $s);
     return $s;
 }
开发者ID:helpfulrobot,项目名称:sunnysideup-googlemapbasic,代码行数:8,代码来源:GoogleMapBasic.php

示例15: javascriptTemplate

 /**
  * Include the content of the given JavaScript file in the list of requirements. Dollar-sign
  * variables will be interpolated with values from $vars similar to a .ss template.
  *
  * @param string         $file         The template file to load, relative to docroot
  * @param string[] $vars The array of variables to interpolate.
  * @param string $uniquenessID A unique ID that ensures a piece of code is only added once
  */
 public function javascriptTemplate($file, $vars, $uniquenessID = null)
 {
     $script = file_get_contents(Director::getAbsFile($file));
     $search = array();
     $replace = array();
     if ($vars) {
         foreach ($vars as $k => $v) {
             $search[] = '$' . $k;
             $replace[] = str_replace("\\'", "'", Convert::raw2js($v));
         }
     }
     $script = str_replace($search, $replace, $script);
     $this->customScript($script, $uniquenessID);
 }
开发者ID:XDdesigners,项目名称:silverstripe-framework,代码行数:22,代码来源:Requirements.php


注:本文中的Convert::raw2js方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。