本文整理汇总了PHP中JDocument类的典型用法代码示例。如果您正苦于以下问题:PHP JDocument类的具体用法?PHP JDocument怎么用?PHP JDocument使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了JDocument类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: fetchScripts
/**
* Generates the head HTML and return the results as a string
*
* @param JDocument $document The document for which the head will be created
*
* @return string The head hTML
*
* @since 11.1
*/
public function fetchScripts($document)
{
// Trigger the onBeforeCompileHead event
$app = JFactory::getApplication();
// Get line endings
$lnEnd = $document->_getLineEnd();
$tab = $document->_getTab();
$tagEnd = ' />';
$buffer = '';
if ($disabled_scripts_list = $document->params->get('disabled_scripts_list', '')) {
$disable_scripts = preg_split("#\n" . '|' . "\r\n#", $disabled_scripts_list);
}
// Generate script file links
foreach ($document->_scripts as $strSrc => $strAttr) {
if (!in_array($strSrc, $disable_scripts)) {
$buffer .= $tab . '<script src="' . $strSrc . '"';
$defaultMimes = array('text/javascript', 'application/javascript', 'text/x-javascript', 'application/x-javascript');
if (!is_null($strAttr['mime']) && (!$document->isHtml5() || !in_array($strAttr['mime'], $defaultMimes))) {
$buffer .= ' type="' . $strAttr['mime'] . '"';
}
if ($strAttr['defer']) {
$buffer .= ' defer="defer"';
}
if ($strAttr['async']) {
$buffer .= ' async="async"';
}
$buffer .= '></script>' . $lnEnd;
}
}
// Generate script declarations
foreach ($document->_script as $type => $content) {
$buffer .= $tab . '<script type="' . $type . '">' . $lnEnd;
// This is for full XHTML support.
if ($document->_mime != 'text/html') {
$buffer .= $tab . $tab . '<![CDATA[' . $lnEnd;
}
$buffer .= $content . $lnEnd;
// See above note
if ($document->_mime != 'text/html') {
$buffer .= $tab . $tab . ']]>' . $lnEnd;
}
$buffer .= $tab . '</script>' . $lnEnd;
}
// Generate script language declarations.
if (count(JText::script())) {
$buffer .= $tab . '<script type="text/javascript">' . $lnEnd;
$buffer .= $tab . $tab . '(function() {' . $lnEnd;
$buffer .= $tab . $tab . $tab . 'var strings = ' . json_encode(JText::script()) . ';' . $lnEnd;
$buffer .= $tab . $tab . $tab . 'if (typeof Joomla == \'undefined\') {' . $lnEnd;
$buffer .= $tab . $tab . $tab . $tab . 'Joomla = {};' . $lnEnd;
$buffer .= $tab . $tab . $tab . $tab . 'Joomla.JText = strings;' . $lnEnd;
$buffer .= $tab . $tab . $tab . '}' . $lnEnd;
$buffer .= $tab . $tab . $tab . 'else {' . $lnEnd;
$buffer .= $tab . $tab . $tab . $tab . 'Joomla.JText.load(strings);' . $lnEnd;
$buffer .= $tab . $tab . $tab . '}' . $lnEnd;
$buffer .= $tab . $tab . '})();' . $lnEnd;
$buffer .= $tab . '</script>' . $lnEnd;
}
return $buffer;
}
示例2: mapJS
/**
* Adds the map javascript to the document
*/
protected function mapJS(JDocument $document)
{
// Add map interface Javascript
JHtml::_('behavior.framework', true);
$document->addScript('/libraries/openlayers/OpenLayers.debug.js');
$document->addScript('/swg/js/maps.js');
$document->addScript('/swg/js/events.js');
}
示例3: fetchJs
/**
* Generates the javascript HTML and return the results as a string
*
* @param JDocument $document The document for which the javascript will be created
*
* @return string The javascript hTML
*
* @since 11.1
*/
public function fetchJs($document)
{
// Get line endings
$lnEnd = $document->_getLineEnd();
$tab = $document->_getTab();
$buffer = '';
// Generate script file links
foreach ($document->_scripts as $strSrc => $strAttr) {
$buffer .= $tab . '<script src="' . $strSrc . '"';
$defaultMimes = array('text/javascript', 'application/javascript', 'text/x-javascript', 'application/x-javascript');
if (!is_null($strAttr['mime']) && (!$document->isHtml5() || !in_array($strAttr['mime'], $defaultMimes))) {
$buffer .= ' type="' . $strAttr['mime'] . '"';
}
if ($strAttr['defer']) {
$buffer .= ' defer="defer"';
}
if ($strAttr['async']) {
$buffer .= ' async="async"';
}
$buffer .= '></script>' . $lnEnd;
}
// Generate script declarations
foreach ($document->_script as $type => $content) {
$buffer .= $tab . '<script type="' . $type . '">' . $lnEnd;
// This is for full XHTML support.
if ($document->_mime != 'text/html') {
$buffer .= $tab . $tab . '<![CDATA[' . $lnEnd;
}
$buffer .= $content . $lnEnd;
// See above note
if ($document->_mime != 'text/html') {
$buffer .= $tab . $tab . ']]>' . $lnEnd;
}
$buffer .= $tab . '</script>' . $lnEnd;
}
// Generate script language declarations.
if (count(JText::script())) {
$buffer .= $tab . '<script type="text/javascript">' . $lnEnd;
$buffer .= $tab . $tab . '(function() {' . $lnEnd;
$buffer .= $tab . $tab . $tab . 'var strings = ' . json_encode(JText::script()) . ';' . $lnEnd;
$buffer .= $tab . $tab . $tab . 'if (typeof Joomla == \'undefined\') {' . $lnEnd;
$buffer .= $tab . $tab . $tab . $tab . 'Joomla = {};' . $lnEnd;
$buffer .= $tab . $tab . $tab . $tab . 'Joomla.JText = strings;' . $lnEnd;
$buffer .= $tab . $tab . $tab . '}' . $lnEnd;
$buffer .= $tab . $tab . $tab . 'else {' . $lnEnd;
$buffer .= $tab . $tab . $tab . $tab . 'Joomla.JText.load(strings);' . $lnEnd;
$buffer .= $tab . $tab . $tab . '}' . $lnEnd;
$buffer .= $tab . $tab . '})();' . $lnEnd;
$buffer .= $tab . '</script>' . $lnEnd;
}
foreach ($document->_custom as $custom) {
$buffer .= $tab . $custom . $lnEnd;
}
return $buffer;
}
示例4: render
/**
* Render the error page based on an exception.
*
* @param Exception $error The exception for which to render the error page.
*
* @return void
*
* @since 3.0
*/
public static function render(Exception $error)
{
try {
$app = JFactory::getApplication();
$document = JDocument::getInstance('error');
if (!$document) {
// We're probably in an CLI environment
jexit($error->getMessage());
}
// Get the current template from the application
$template = $app->getTemplate();
// Push the error object into the document
$document->setError($error);
if (ob_get_contents()) {
ob_end_clean();
}
$document->setTitle(JText::_('Error') . ': ' . $error->getCode());
$data = $document->render(false, array('template' => $template, 'directory' => JPATH_THEMES, 'debug' => JDEBUG));
// Do not allow cache
$app->allowCache(false);
// If nothing was rendered, just use the message from the Exception
if (empty($data)) {
$data = $error->getMessage();
}
$app->setBody($data);
echo $app->toString();
} catch (Exception $e) {
// Try to set a 500 header if they haven't already been sent
if (!headers_sent()) {
header('HTTP/1.1 500 Internal Server Error');
}
jexit('Error displaying the error page: ' . $e->getMessage() . ': ' . $error->getMessage());
}
}
示例5: resetDocumentType
/**
* Resets the document type to format=raw
*
* @return void
* @since 0.1
* @todo Figure out if there is a better way to do this
*/
private function resetDocumentType()
{
$document =& JFactory::getDocument();
$raw =& JDocument::getInstance('raw');
$document = $raw;
JResponse::clearHeaders();
}
示例6: display
function display()
{
$doDisplay = true;
// Set a default view if none exists
if (!JRequest::getCmd('view')) {
JRequest::setVar('view', 'tickets');
}
// Handle displaying an attachment
if (JRequest::getCmd('view') == 'attachment') {
$model = $this->getModel('attachment');
$result = $model->download(JRequest::getVar('ArticleID', '', '', 'integer'), JRequest::getVar('AtmID', '', '', 'integer'));
if (array_key_exists('data', $result)) {
$document =& JFactory::getDocument();
$doc =& JDocument::getInstance('raw');
$document = $doc;
JResponse::clearHeaders();
$document->setMimeEncoding($result['data']->ContentType);
JResponse::setHeader('Content-length', $result['data']->FilesizeRaw, true);
$fn = preg_replace('/"/', '\\"', $result['data']->Filename);
JResponse::setHeader('Content-disposition', sprintf('attachment;filename="%s"', $fn), true);
$document->render();
echo $result['data']->Content;
$doDisplay = false;
}
}
if ($doDisplay) {
parent::display();
}
}
示例7: testCalendar
/**
* Tests JHtml::calendar() method with and without 'readonly' attribute.
*/
public function testCalendar()
{
// Create a world for the test
jimport('joomla.session.session');
jimport('joomla.application.application');
jimport('joomla.document.document');
$cfg = new JObject();
JFactory::$session = $this->getMock('JSession', array('_start'));
JFactory::$application = $this->getMock('ApplicationMock');
JFactory::$config = $cfg;
JFactory::$application->expects($this->any())->method('getTemplate')->will($this->returnValue('atomic'));
$cfg->live_site = 'http://example.com';
$cfg->offset = 'Europe/Kiev';
$_SERVER['HTTP_USER_AGENT'] = 'Test Browser';
// two sets of test data
$test_data = array('date' => '2010-05-28 00:00:00', 'friendly_date' => 'Friday, 28 May 2010', 'name' => 'cal1_name', 'id' => 'cal1_id', 'format' => '%Y-%m-%d', 'attribs' => array());
$test_data_ro = array_merge($test_data, array('attribs' => array('readonly' => 'readonly')));
foreach (array($test_data, $test_data_ro) as $data) {
// Reset the document
JFactory::$document = JDocument::getInstance('html', array('unique_key' => serialize($data)));
$input = JHtml::calendar($data['date'], $data['name'], $data['id'], $data['format'], $data['attribs']);
$this->assertEquals((string) $xml->input['title'], $data['friendly_date'], 'Line:' . __LINE__ . ' The calendar input should have `title == "' . $data['friendly_date'] . '"`');
$this->assertEquals((string) $xml->input['name'], $data['name'], 'Line:' . __LINE__ . ' The calendar input should have `name == "' . $data['name'] . '"`');
$this->assertEquals((string) $xml->input['id'], $data['id'], 'Line:' . __LINE__ . ' The calendar input should have `id == "' . $data['id'] . '"`');
$head_data = JFactory::getDocument()->getHeadData();
if (!isset($data['attribs']['readonly']) || !$data['attribs']['readonly'] === 'readonly') {
$this->assertArrayHasKey('/media/system/js/calendar.js', $head_data['scripts'], 'Line:' . __LINE__ . ' JS file "calendar.js" should be loaded');
$this->assertArrayHasKey('/media/system/js/calendar-setup.js', $head_data['scripts'], 'Line:' . __LINE__ . ' JS file "calendar-setup.js" should be loaded');
}
}
}
示例8: sendBug
/**
* Submits a bug report to Dioscouri.
* Thanks so much! They really help improve the product!
*/
function sendBug()
{
$mainframe = JFactory::getApplication();
$body = JRequest::getVar('body');
$name = JRequest::getVar('title');
$body .= "\n\n Project: tienda";
$body .= "\n Tracker: Bug";
$body .= "\n Affected Version: " . Tienda::getVersion();
$doc = JDocument::getInstance('raw');
ob_start();
$option = JRequest::getCmd('option');
$db = JFactory::getDBO();
$path = JPATH_ADMINISTRATOR . '/components/com_admin/';
require_once $path . 'admin.admin.html.php';
$path .= 'tmpl/';
require_once $path . 'sysinfo_system.php';
require_once $path . 'sysinfo_directory.php';
require_once $path . 'sysinfo_phpinfo.php';
require_once $path . 'sysinfo_phpsettings.php';
require_once $path . 'sysinfo_config.php';
jimport('joomla.filesystem.file');
$contents = ob_get_contents();
ob_end_clean();
$doc->setBuffer($contents);
$contents = $doc->render();
$sitename = $config->get('sitename', $mainframe->getCfg('sitename'));
// write file with info
$config = JFactory::getConfig();
$filename = 'system_info_' . $sitename . '.html';
$file = JPATH_SITE . '/tmp/' . $filename;
JFile::write($file, $contents);
$mailer = JFactory::getMailer();
$success = false;
// For now, bug submission goes to info@dioscouri.com,
// but in the future, it will go to projects@dioscouri.com
// (once we get the Redmine auto-create working properly
// and format the subject/body of the email properly)
$mailer->addRecipient('projects@dioscouri.com');
$mailer->setSubject($name);
$mailfrom = $config->get('emails_defaultemail', $mainframe->getCfg('mailfrom'));
$fromname = $config->get('emails_defaultname', $mainframe->getCfg('fromname'));
// check user mail format type, default html
$mailer->setBody($body);
$mailer->addAttachment($file);
$sender = array($mailfrom, $fromname);
$mailer->setSender($sender);
$sent = $mailer->send();
if ($sent == '1') {
$success = true;
}
JFile::delete($file);
if ($success) {
$msg = JText::_('COM_TIENDA_BUG_SUBMIT_OK');
$msgtype = 'message';
} else {
$msg = JText::_('COM_TIENDA_BUG_SUBMIT_FAIL');
$msgtype = 'notice';
}
$mainframe->redirect(JRoute::_('index.php?option=com_tienda&view=dashboard'), $msg, $msgtype);
}
示例9: testRender
/**
* @todo Implement testRender().
*/
public function testRender()
{
$this->object = new JDocument();
$this->object->render();
$headers = JResponse::getHeaders();
$lastMod = false;
$contentType = false;
foreach ($headers as $header) {
if ($header['name'] == 'Last-Modified') {
$lastMod = $header;
}
if ($header['name'] == 'Content-Type') {
$contentType = $header;
}
}
$this->assertThat($lastMod, $this->equalTo(false));
$this->assertThat($contentType['value'], $this->equalTo('; charset=utf-8'));
$this->object->setModifiedDate('My date');
$this->object->setMimeEncoding('MyMimeType');
$this->object->setCharset('MyCharset');
$this->object->render();
$headers = JResponse::getHeaders();
$lastMod = false;
$contentType = false;
foreach ($headers as $header) {
if ($header['name'] == 'Last-Modified') {
$lastMod = $header;
}
if ($header['name'] == 'Content-Type') {
$contentType = $header;
}
}
$this->assertThat($lastMod['value'], $this->equalTo('My date'));
$this->assertThat($contentType['value'], $this->equalTo('mymimetype; charset=MyCharset'));
}
示例10: render
/**
* Render the error page based on an exception.
*
* @param Exception $error The exception for which to render the error page.
*
* @return void
*
* @since 3.0
*/
public static function render(Exception $error)
{
try {
$app = JFactory::getApplication();
$document = JDocument::getInstance('error');
if (!$document) {
// We're probably in an CLI environment
exit($error->getMessage());
$app->close(0);
}
$config = JFactory::getConfig();
// Get the current template from the application
$template = $app->getTemplate();
// Push the error object into the document
$document->setError($error);
if (ob_get_contents()) {
ob_end_clean();
}
$document->setTitle(JText::_('Error') . ': ' . $error->getCode());
$data = $document->render(false, array('template' => $template, 'directory' => JPATH_THEMES, 'debug' => $config->get('debug')));
// Failsafe to get the error displayed.
if (empty($data)) {
exit($error->getMessage());
} else {
// Do not allow cache
$app->allowCache(false);
$app->setBody($data);
echo $app->toString();
}
} catch (Exception $e) {
exit('Error displaying the error page: ' . $e->getMessage() . ': ' . $error->getMessage());
}
}
示例11: register
/**
* Register the API server.
*
* @throws \Exception
* @return boolean
*/
public function register()
{
$uri = \JURI::getInstance();
if (!$this->isApi()) {
return false;
}
$app = \JFactory::getApplication();
$input = $app->input;
// Restore Joomla handler and using our Json handler.
JsonResponse::registerErrorHandler();
// Authentication
if (!$this->isUserOperation($uri) && $this->option['authorise']) {
if (!Authentication::authenticate($input->get('session_key'))) {
throw new \Exception(\JText::_('JERROR_ALERTNOAUTHOR'), 403);
}
}
// Set Format to JSON
$input->set('format', 'json');
// Store JDocumentJson to Factory
\JFactory::$document = \JDocument::getInstance('json');
$router = $app::getRouter();
// Attach a hook to Router
$router->attachParseRule(array($this, 'parseRule'));
return true;
}
示例12: render
/**
* Render the document.
*
* @access public
* @param boolean $cache If true, cache the output
* @param array $params Associative array of attributes
* @return The rendered data
*/
function render($cache = false, $params = array())
{
// Instantiate feed renderer and set the mime encoding
require_once dirname(__FILE__) . DS . 'renderer' . DS . 'xml.php';
$renderer =& $this->loadRenderer('xml');
if (!is_a($renderer, 'JDocumentRenderer')) {
JError::raiseError(404, JText::_('Resource Not Found'));
}
$url = 'http://demo.fabrikar.com/index.php?option=com_fabrik&view=table&tableid=' . $this->tableid . '&format=raw&type=xml';
$url = htmlspecialchars($url, ENT_COMPAT, 'UTF-8');
$data = '<?xml version="1.0" encoding="UTF-8"?>
<table xmlns="http://query.yahooapis.com/v1/schema/table.xsd">
<meta>
<author>' . htmlspecialchars($this->author, ENT_COMPAT, 'UTF-8') . '</author>
<documentationURL>None</documentationURL>
<description>' . htmlspecialchars($this->description, ENT_COMPAT, 'UTF-8') . '</description>
<sampleQuery>SELECT * FROM {table} WHERE jos_fabrik_calendar_events___visualization_id_raw="0"</sampleQuery>
</meta>
<bindings>
<select itemPath="root.row" produces="XML">
<urls>
<url>' . $url . '</url>
</urls>
</select>
</bindings>
</table>';
// Render the feed
//$data .= $renderer->render();
parent::render();
return $data;
}
示例13: _prepareDocument
/**
* Prepares the document
*/
protected function _prepareDocument()
{
$app = JFactory::getApplication();
$menus = $app->getMenu();
$title = null;
// Because the application sets a default page title,
// we need to get it from the menu item itself
$menu = $menus->getActive();
if ($menu) {
$this->params->get('page_heading', $this->params->get('page_title', $menu->title));
}
$title = $this->params->get('page_title', '');
if (empty($title)) {
$title = $app->getCfg('sitename');
} elseif ($app->getCfg('sitename_pagetitles', 0) == 1) {
$title = JText::sprintf('JPAGETITLE', $app->getCfg('sitename'), $title);
} elseif ($app->getCfg('sitename_pagetitles', 0) == 2) {
$title = JText::sprintf('JPAGETITLE', $title, $app->getCfg('sitename'));
}
$this->document->setTitle($title);
if ($this->params->get('menu-meta_description')) {
$this->document->setDescription($this->params->get('menu-meta_description'));
}
if ($this->params->get('menu-meta_keywords')) {
$this->document->setMetadata('keywords', $this->params->get('menu-meta_keywords'));
}
if ($this->params->get('robots')) {
$this->document->setMetadata('robots', $this->params->get('robots'));
}
}
示例14: populate
public function populate()
{
if (!empty($this->script_files)) {
ksort($this->script_files);
foreach ($this->script_files as $order => $order_entries) {
foreach ($order_entries as $entry_key => $entry) {
$this->document->addScript($entry);
}
}
}
if (!empty($this->inline_scripts)) {
ksort($this->inline_scripts);
foreach ($this->inline_scripts as $order => $order_entries) {
foreach ($order_entries as $entry_key => $entry) {
$this->document->addScriptDeclaration($entry);
}
}
}
if (!empty($this->style_files)) {
ksort($this->style_files);
foreach ($this->style_files as $order => $order_entries) {
foreach ($order_entries as $entry_key => $entry) {
$this->document->addStyleSheet($entry);
}
}
}
if (!empty($this->inline_styles)) {
ksort($this->inline_styles);
foreach ($this->inline_styles as $order => $order_entries) {
foreach ($order_entries as $entry_key => $entry) {
$this->document->addStyleDeclaration($entry);
}
}
}
// Generate domready script
if (!empty($this->domready_scripts)) {
ksort($this->domready_scripts);
$strHtml = 'window.addEvent(\'domready\', function() {';
foreach ($this->domready_scripts as $order => $order_entries) {
foreach ($order_entries as $entry_key => $entry) {
$strHtml .= chr(13) . $entry;
}
}
$strHtml .= chr(13) . '});' . chr(13);
$this->document->addScriptDeclaration($strHtml);
}
if (!empty($this->loadevent_scripts)) {
ksort($this->loadevent_scripts);
$strHtml = 'window.addEvent(\'load\', function() {';
foreach ($this->loadevent_scripts as $order => $order_entries) {
foreach ($order_entries as $entry_key => $entry) {
$strHtml .= chr(13) . $entry;
}
}
$strHtml .= chr(13) . '});' . chr(13);
$this->document->addScriptDeclaration($strHtml);
}
$this->populated = true;
$this->reset();
}
示例15: render
/**
* Render the document.
*
* @param boolean $cache If true, cache the output
* @param array $params Associative array of attributes
*
* @return The rendered data
*
* @since 3.1
*/
public function render($cache = false, $params = array())
{
JResponse::allowCache($cache);
JResponse::setHeader('Content-disposition', 'attachment; filename="' . $this->getName() . '.json"', true);
// Unfortunately, the exact syntax of the Content-Type header
// is not defined, so we have to try to be a bit clever here.
$contentType = $this->_mime;
if (stripos($contentType, 'json') === false) {
$contentType .= '+' . $this->_type;
}
$this->_mime = $contentType;
parent::render();
// Get the HAL object from the buffer.
$hal = $this->getBuffer();
// If required, change relative links to absolute.
if ($this->absoluteHrefs && is_object($hal) && isset($hal->_links)) {
// Adjust hrefs in the _links object.
$this->relToAbs($hal->_links);
// Adjust hrefs in the _embedded object (if there is one).
if (isset($hal->_embedded)) {
foreach ($hal->_embedded as $rel => $resources) {
foreach ($resources as $id => $resource) {
if (isset($resource->_links)) {
$this->relToAbs($resource->_links);
}
}
}
}
}
// Return it as a JSON string.
return json_encode($hal);
}