18 require_once SQ_PACKAGES_PATH.
'/web_services/rest/page_templates/page_rest_resource/page_rest_resource.inc';
44 parent::__construct($assetid);
61 $GLOBALS[
'SQ_SYSTEM']->setGlobalDefine(
'SQ_REPLACE_MYSOURCE_LEVEL_KEYWORDS', $this->
attr(
'allow_global_replace'));
76 $js =
'var _REST = Array();';
79 if (!empty($this->_res)) {
82 foreach ($this->_res[
'responses'] as &$resp) {
83 $resp[
'bodyx'] = preg_replace(
"/^<\?xml\s.*\?>/",
"", $resp[
'body']);
85 if (!function_exists(
'json_encode')) {
86 require_once
'Services/JSON.php';
87 $json =
new Services_JSON();
88 $js .=
'_REST = ' . $json->encodeUnsafe($this->_res) .
";\n";
90 $js .=
'_REST = ' .json_encode($this->_res) .
";\n";
95 $file_ids = $this->
attr(
'javascript_files');
96 foreach ($file_ids as $fid) {
97 $file =& $GLOBALS[
'SQ_SYSTEM']->am->getAsset($fid);
99 $existing = $file->getExistingFile();
100 if (!empty($existing)) {
101 $js .= file_get_contents($existing[
'path']);
104 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($file);
108 $js .= $this->
attr(
'javascript');
112 $engine = $this->
attr(
'js_engine');
113 if($engine ==
'spidermonkey')
115 else if($engine ==
'v8')
132 $descriptorspec = Array(
133 0 => Array(
'pipe',
'r'),
134 1 => Array(
'pipe',
'w'),
135 2 => Array(
'pipe',
'w')
137 require_once SQ_DATA_PATH.
'/private/conf/tools.inc';
139 $process = proc_open(SQ_TOOL_JS_PATH .
' - ', $descriptorspec, $pipes);
141 if (is_resource($process)) {
149 $js_output = stream_get_contents($STDOUT);
155 $read = Array($STDERR);
158 $num_changed_streams = stream_select($read, $write, $except, 0);
161 foreach ($read as $r) {
164 $js_errors = stream_get_contents($STDERR);
171 proc_close($process);
174 if ((isset($js_errors)) && (strlen($js_errors) > 0 )) {
175 trigger_error(__CLASS__ .
" (#$this->id) " . $js_errors);
193 if(!extension_loaded(
'v8js')){
194 trigger_error(
'PECL v8js extension is required');
202 $v8->executeString($js);
203 $js_output = ob_get_clean();
204 }
catch (V8JsException $e) {
205 $js_errors = $e->getMessage() .
' - \''.$e->getJsSourceLine().
'\' Line:
'.$e->getJsLineNumber();
206 trigger_error(__CLASS__ . " (#$this->id) " . $js_errors);
212 }//end _runJavascript()