getGroupName(); } if (!isset($this->_content[$groupName])) { $this->_content[$groupName] = array(); } array_unshift($this->_content[$groupName], new Qs_Doc_Item($item)); return $this; } public function displayJson($data) { header('Cache-Control: no-store, no-cache, must-revalidate, private'); header('Pragma: no-cache'); header('Content-Type: application/x-javascript; charset=utf-8'); $json = json_encode($data); if ($this->_getCompressJson()) { header('Content-Encoding: gzip'); $json = gzencode($json, 9); } die($json); } protected function _getCompressJson() { if (null === $this->_compressJson) { if (strpos(Qs_Request::getHeader('ACCEPT-ENCODING'), 'gzip') === false) { $this->_setCompressJson(false); } else { $this->_setCompressJson(true); } } return $this->_compressJson; } protected function _setCompressJson($flag) { $this->_compressJson = (bool) $flag; return $this; } public function addInlineScript($name, $body, $_attribs = array()) { $attribs = array( 'type' => 'text/javascript', 'beforeScripts' => false, ); $attribs = array_merge($attribs, $_attribs); $beforeScripts = (int) $attribs['beforeScripts']; unset($attribs['beforeScripts']); $this->_content['head']['inlineScript'][$beforeScripts][$name] = array( 'attribs' => $attribs, 'body' => $body, ); return $this; } public function renderInlineScripts($indents = null, $showLanguageAttrib = true, $beforeScripts = false) { $html = ''; $scriptsHtml = array(); $indents = (!$indents) ? 1 : $indents; $indent = str_repeat(' ', $indents * 4); $beforeScripts = (int) $beforeScripts; if (is_array($this->_content['head']['inlineScript'][$beforeScripts])) { foreach ($this->_content['head']['inlineScript'][$beforeScripts] as $name => $script) { $attribs = ''; foreach ($script['attribs'] as $attribute => $attributeValue) { $attribs .= $attribute . ' = "' . htmlspecialchars($attributeValue, ENT_COMPAT, 'UTF-8') . '" '; } $attribs = trim($attribs); $body = PHP_EOL . '/* Inline Script: ' . $name . ' */' . PHP_EOL . $script['body']; $scriptsHtml[$attribs] .= str_replace(PHP_EOL, PHP_EOL . $indent . $indent, $body) . PHP_EOL; } foreach ($scriptsHtml as $scriptAttribs => $scriptHtml) { $html = ''; } } return $html; } public function addResources(array $resources) { foreach ($resources as $type => $list) { $method = 'add' . $type; if (method_exists($this, $method)) { foreach ($list as $arguments) { call_user_func_array(array($this, $method), $arguments); } } else { trigger_error('Undefined resource type'); } } return $this; } }