diff --git a/apps/pc_frontend/config/routing.yml b/apps/pc_frontend/config/routing.yml index 88d0f07ad..571e4761a 100644 --- a/apps/pc_frontend/config/routing.yml +++ b/apps/pc_frontend/config/routing.yml @@ -53,6 +53,10 @@ global_user_agreement: url: /userAgreement param: { module: default, action: userAgreement } +url_for: + url: /default/urlFor.txt + param: { module: default, action: urlFor } + # member rules member_config_image: url: /member/image/config diff --git a/apps/pc_frontend/config/view.yml b/apps/pc_frontend/config/view.yml index 2a98916c7..9e5340a08 100644 --- a/apps/pc_frontend/config/view.yml +++ b/apps/pc_frontend/config/view.yml @@ -11,7 +11,7 @@ default: stylesheets: [] - javascripts: [] + javascripts: ['util.js', 'op_url.js'] has_layout: true layout: layoutC diff --git a/apps/pc_frontend/modules/default/actions/urlForAction.class.php b/apps/pc_frontend/modules/default/actions/urlForAction.class.php new file mode 100644 index 000000000..e498dab9b --- /dev/null +++ b/apps/pc_frontend/modules/default/actions/urlForAction.class.php @@ -0,0 +1,62 @@ + + */ +class urlForAction extends sfAction +{ + /** + * Executes urlFor action + * + * @param opWebRequest $request A request object + */ + public function execute($request) + { + // for javascript. + $this->forward404Unless($request->isXmlHttpRequest()); + $this->getResponse()->setContentType('text/plain'); + $this->getResponse()->setHttpHeader('X-Content-Type-Options', 'nosniff', true); + + $this->getContext()->getConfiguration()->loadHelpers(array('Url', 'opUtil')); + + $application = $request['application']; + $params = (array)$request['params']; + $function = 'url_for'; + + if ($application) + { + $params = array_merge(array($application), $params); + $function = 'app_url_for'; + } + + try + { + return $this->renderText(call_user_func_array($function, $params)); + } + catch (Exception $e) + { + $this->logMessage($e->getMessage(), 'err'); + } + + return $this->set422Status('Can not find routing.'); + } + + protected function set422Status($message) + { + $this->getResponse()->setStatusCode(422, 'Unprocessable Entity'); + + return $this->renderText($message); + } +} diff --git a/apps/pc_frontend/templates/_layout.php b/apps/pc_frontend/templates/_layout.php index 574da7c66..e39a26973 100644 --- a/apps/pc_frontend/templates/_layout.php +++ b/apps/pc_frontend/templates/_layout.php @@ -9,6 +9,27 @@ get('customizing_css')): ?> + url_for('@url_for')); +if (opConfig::get('enable_jsonapi') && opToolkit::isSecurePage()) +{ + use_javascript('jquery.tmpl.min.js'); + use_javascript('jquery.notify.js'); + use_javascript('op_notify.js'); + $jsonData = array_merge(array( + 'apiKey' => $sf_user->getMemberApiKey(), + 'apiBase' => app_url_for('api', 'homepage'), + 'baseUrl' => $sf_request->getRelativeUrlRoot().'/', + ), $jsonData); +} + +$json = defined('JSON_PRETTY_PRINT') ? json_encode($jsonData, JSON_PRETTY_PRINT) : json_encode($jsonData); + +echo javascript_tag('var openpne = '.$json.';'); +?> + get('pc_html_head') ?>
diff --git a/web/js/op_url.js b/web/js/op_url.js new file mode 100644 index 000000000..64df6ad96 --- /dev/null +++ b/web/js/op_url.js @@ -0,0 +1,84 @@ +/** + * This file is part of the OpenPNE package. + * (c) OpenPNE Project (http://www.openpne.jp/) + * + * For the full copyright and license information, please view the LICENSE + * file and the NOTICE file that were distributed with this source code. + */ + +/** + * OpenPNE url JavaScript helper library + * + * @author Shinichi Urabe