本文整理汇总了PHP中JApplicationCms::getInstance方法的典型用法代码示例。如果您正苦于以下问题:PHP JApplicationCms::getInstance方法的具体用法?PHP JApplicationCms::getInstance怎么用?PHP JApplicationCms::getInstance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JApplicationCms
的用法示例。
在下文中一共展示了JApplicationCms::getInstance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* Class constructor
*
* @param JApplicationCms $app JApplicationCms Object
* @param JMenu $menu JMenu object
*
* @since 3.4
*/
public function __construct(JApplicationCms $app = null, JMenu $menu = null)
{
$this->app = $app ? $app : JApplicationCms::getInstance('site');
$this->menu = $menu ? $menu : $this->app->getMenu();
// Add core rules
if ($this->app->get('force_ssl') == 2) {
$this->attachParseRule(array($this, 'parseCheckSSL'), self::PROCESS_BEFORE);
}
$this->attachParseRule(array($this, 'parseInit'), self::PROCESS_BEFORE);
$this->attachBuildRule(array($this, 'buildInit'), self::PROCESS_BEFORE);
$this->attachBuildRule(array($this, 'buildComponentPreprocess'), self::PROCESS_BEFORE);
if ($this->app->get('sef')) {
if ($this->app->get('sef_suffix')) {
$this->attachParseRule(array($this, 'parseFormat'), self::PROCESS_BEFORE);
$this->attachBuildRule(array($this, 'buildFormat'), self::PROCESS_AFTER);
}
$this->attachParseRule(array($this, 'parseSefRoute'), self::PROCESS_DURING);
$this->attachBuildRule(array($this, 'buildSefRoute'), self::PROCESS_DURING);
$this->attachParseRule(array($this, 'parsePaginationData'), self::PROCESS_AFTER);
$this->attachBuildRule(array($this, 'buildPaginationData'), self::PROCESS_AFTER);
if ($this->app->get('sef_rewrite')) {
$this->attachBuildRule(array($this, 'buildRewrite'), self::PROCESS_AFTER);
}
}
$this->attachParseRule(array($this, 'parseRawRoute'), self::PROCESS_DURING);
$this->attachBuildRule(array($this, 'buildBase'), self::PROCESS_AFTER);
}
示例2: postflight
/**
* method to run after an install/update/uninstall method
*
* @return void
*/
function postflight($type, $parent)
{
// $parent is the class calling this method
// $type is the type of change (install, update or discover_install)
$siteApp = JApplicationCms::getInstance('site');
$menu = $siteApp->getMenu()->getItems('link', 'index.php?option=com_alfcontact&view=alfcontact');
$firstmenu = array_shift($menu);
if ($type == 'update' && !$firstmenu->params->exists('header')) {
//upgrade v3.1.1: moved parameters from component to menu-item
echo 'The Title, Header and Footer parameters have now been moved to the menu-item settings!';
//check for component parameters
$c_params = JComponentHelper::getParams('com_alfcontact');
// get the 'old' values from the component settings
$temp_title = $c_params->get('title');
$temp_header = $c_params->get('header');
$temp_footer = $c_params->get('footer');
//clear the 'old' settings in the component settings
$c_params->set('title', '');
$c_params->set('header', '');
$c_params->set('footer', '');
//Copy the parameteres to the menu-item settings
$db = JFactory::getDBO();
$name = 'com_alfcontact';
$query = "UPDATE #__extensions SET params =" . $db->quote((string) $c_params) . "WHERE name =" . $db->quote((string) $name);
$db->setQuery($query);
foreach ($menu as $val) {
$val->params->set('title', $temp_title);
$val->params->set('header', $temp_header);
$val->params->set('footer', $temp_footer);
$query = "UPDATE #__menu SET params = " . $db->quote((string) $val->params) . " WHERE id = " . $db->quote((string) $val->id);
$db->setQuery($query);
}
}
echo '<p>' . JText::_('COM_ALFCONTACT_POSTFLIGHT_' . $type . '_TEXT') . '</p>';
}
示例3: __construct
public function __construct()
{
$this->app = \JApplicationCms::getInstance('site');
$lang = \JFactory::getLanguage();
$tag = \JLanguageMultilang::isEnabled() ? $lang->getTag() : '*';
$this->menu = $this->app->getMenu();
$this->default = $this->menu->getDefault($tag);
$this->active = $this->menu->getActive();
}
示例4: __construct
/**
* Class constructor.
*
* @param array $options The class options.
*
* @since 1.5
*/
public function __construct($options = array())
{
$this->_pathway = array();
$app = JApplicationCms::getInstance('site');
$menu = $app->getMenu();
if ($item = $menu->getActive()) {
$menus = $menu->getMenu();
$home = $menu->getDefault();
if (is_object($home) && $item->id != $home->id) {
foreach ($item->tree as $menupath) {
$url = '';
$link = $menu->getItem($menupath);
switch ($link->type) {
case 'separator':
case 'heading':
$url = null;
break;
case 'url':
if (strpos($link->link, 'index.php?') === 0 && strpos($link->link, 'Itemid=') === false) {
// If this is an internal Joomla link, ensure the Itemid is set.
$url = $link->link . '&Itemid=' . $link->id;
} else {
$url = $link->link;
}
break;
case 'alias':
// If this is an alias use the item id stored in the parameters to make the link.
$url = 'index.php?Itemid=' . $link->params->get('aliasoptions');
break;
default:
$router = $app::getRouter();
if ($router->getMode() == JROUTER_MODE_SEF) {
$url = 'index.php?Itemid=' . $link->id;
} else {
$url .= $link->link . '&Itemid=' . $link->id;
}
break;
}
$this->addItem($menus[$menupath]->title, $url);
}
}
}
}
示例5: __construct
/**
* Class constructor.
*
* @param array $options The class options.
*
* @since 1.5
*/
public function __construct($options = array())
{
$this->_pathway = array();
$app = JApplicationCms::getInstance('site');
$menu = $app->getMenu();
$lang = JFactory::getLanguage();
if ($item = $menu->getActive()) {
$menus = $menu->getMenu();
// Look for the home menu
if (JLanguageMultilang::isEnabled()) {
$home = $menu->getDefault($lang->getTag());
} else {
$home = $menu->getDefault();
}
if (is_object($home) && $item->id != $home->id) {
foreach ($item->tree as $menupath) {
$link = $menu->getItem($menupath);
switch ($link->type) {
case 'separator':
case 'heading':
$url = null;
break;
case 'url':
if (strpos($link->link, 'index.php?') === 0 && strpos($link->link, 'Itemid=') === false) {
// If this is an internal Joomla link, ensure the Itemid is set.
$url = $link->link . '&Itemid=' . $link->id;
} else {
$url = $link->link;
}
break;
case 'alias':
// If this is an alias use the item id stored in the parameters to make the link.
$url = 'index.php?Itemid=' . $link->params->get('aliasoptions');
break;
default:
$url = $link->link . '&Itemid=' . $link->id;
break;
}
$this->addItem($menus[$menupath]->title, $url);
}
}
}
}
示例6: __construct
/**
* Class constructor
*
* @param array $options Array of options
* @param JApplicationCms $app JApplicationCms Object
* @param JMenu $menu JMenu object
*
* @since 3.4
*/
public function __construct($options = array(), JApplicationCms $app = null, JMenu $menu = null)
{
parent::__construct($options);
$this->app = $app ? $app : JApplicationCms::getInstance('site');
$this->menu = $menu ? $menu : $this->app->getMenu();
}
示例7: sendMail
protected function sendMail($project, $emailId)
{
$app = JFactory::getApplication();
/** @var $app JApplicationSite */
// Get website
$uri = JUri::getInstance();
$website = $uri->toString(array("scheme", "host"));
$emailMode = $this->params->get("email_mode", "plain");
// Route project URI
$appSite = JApplicationCms::getInstance('site');
$router = $appSite->getRouter('site');
$routedUri = $router->build(CrowdfundingHelperRoute::getDetailsRoute($project->slug, $project->catslug));
if ($routedUri instanceof JUri) {
$routedUri = $routedUri->toString();
}
if (0 === strpos($routedUri, "/administrator")) {
$routedUri = str_replace("/administrator", "", $routedUri);
}
// Prepare data for parsing
$data = array("site_name" => $app->get("sitename"), "site_url" => JUri::root(), "item_title" => $project->title, "item_url" => $website . $routedUri);
// Send mail to the administrator
if (!$emailId) {
return false;
}
$email = new EmailTemplates\Email();
$email->setDb(JFactory::getDbo());
$email->load($emailId);
if (!$email->getSenderName()) {
$email->setSenderName($app->get("fromname"));
}
if (!$email->getSenderEmail()) {
$email->setSenderEmail($app->get("mailfrom"));
}
$recipientName = $project->name;
$recipientMail = $project->email;
// Prepare data for parsing
$data["sender_name"] = $email->getSenderName();
$data["sender_email"] = $email->getSenderEmail();
$data["recipient_name"] = $recipientName;
$data["recipient_email"] = $recipientMail;
$email->parse($data);
$subject = $email->getSubject();
$body = $email->getBody($emailMode);
$mailer = JFactory::getMailer();
if (strcmp("html", $emailMode) == 0) {
// Send as HTML message
$result = $mailer->sendMail($email->getSenderEmail(), $email->getSenderName(), $recipientMail, $subject, $body, Prism\Constants::MAIL_MODE_HTML);
} else {
// Send as plain text.
$result = $mailer->sendMail($email->getSenderEmail(), $email->getSenderName(), $recipientMail, $subject, $body, Prism\Constants::MAIL_MODE_PLAIN);
}
// Log the error.
if ($result !== true) {
$this->log->add(JText::sprintf("PLG_CONTENT_CROWDFUNDINGUSERMAIL_ERROR_SEND_MAIL", $this->name), "PLG_CONTENT_USERE_MAIL_ERROR", JText::sprintf("PLG_CONTENT_CROWDFUNDINGUSERMAIL_ERROR_SEND_MAIL_NOTE", $mailer->ErrorInfo));
return false;
}
return true;
}
示例8: sendMail
/**
* @param stdClass $project
* @param int $emailId
*
* @return bool
*/
protected function sendMail($project, $emailId)
{
$app = JFactory::getApplication();
/** @var $app JApplicationSite */
// Get website
$uri = JUri::getInstance();
$website = $uri->toString(array('scheme', 'host'));
$emailMode = $this->params->get('email_mode', 'plain');
// Route project URI
$appSite = JApplicationCms::getInstance('site');
$router = $appSite->getRouter('site');
$routedUri = $router->build(CrowdfundingHelperRoute::getDetailsRoute($project->slug, $project->catslug));
if ($routedUri instanceof JUri) {
$routedUri = $routedUri->toString();
}
if (0 === strpos($routedUri, '/administrator')) {
$routedUri = str_replace('/administrator', '', $routedUri);
}
// Prepare data for parsing
$data = array('site_name' => $app->get('sitename'), 'site_url' => JUri::root(), 'item_title' => $project->title, 'item_url' => $website . $routedUri);
$email = new Emailtemplates\Email();
$email->setDb(JFactory::getDbo());
$email->load($emailId);
if (!$email->getSenderName()) {
$email->setSenderName($app->get('fromname'));
}
if (!$email->getSenderEmail()) {
$email->setSenderEmail($app->get('mailfrom'));
}
$recipientName = $project->name;
$recipientMail = $project->email;
// Prepare data for parsing
$data['sender_name'] = $email->getSenderName();
$data['sender_email'] = $email->getSenderEmail();
$data['recipient_name'] = $recipientName;
$data['recipient_email'] = $recipientMail;
$email->parse($data);
$subject = $email->getSubject();
$body = $email->getBody($emailMode);
$mailer = JFactory::getMailer();
if (strcmp('html', $emailMode) === 0) {
// Send as HTML message
$result = $mailer->sendMail($email->getSenderEmail(), $email->getSenderName(), $recipientMail, $subject, $body, Prism\Constants::MAIL_MODE_HTML);
} else {
// Send as plain text.
$result = $mailer->sendMail($email->getSenderEmail(), $email->getSenderName(), $recipientMail, $subject, $body, Prism\Constants::MAIL_MODE_PLAIN);
}
// Log the error.
if ($result !== true) {
JLog::add($this->errorPrefix . $mailer->ErrorInfo, JLog::WARNING, 'com_crowdfunding');
return false;
}
return true;
}
示例9: siteRoute
/**
* Route URI to front-end.
*
* @param string $url
*
* @return string
*/
public static function siteRoute($url)
{
$appSite = JApplicationCms::getInstance('site');
$routerSite = $appSite->getRouter('site');
$routedUri = $routerSite->build($url);
if ($routedUri instanceof JUri) {
$routedUri = $routedUri->toString();
}
if (false !== strpos($routedUri, '/administrator')) {
$routedUri = str_replace('/administrator', '', $routedUri);
}
return JUri::root() . $routedUri;
}
示例10: batch
/**
* Method to run the next batch of content through the indexer.
*
* @return void
*
* @since 2.5
*/
public function batch()
{
static $log;
$params = JComponentHelper::getParams('com_finder');
if ($params->get('enable_logging', '0')) {
if ($log == null) {
$options['format'] = '{DATE}\\t{TIME}\\t{LEVEL}\\t{CODE}\\t{MESSAGE}';
$options['text_file'] = 'indexer.php';
$log = JLog::addLogger($options);
}
}
// Log the start
JLog::add('Starting the indexer batch process', JLog::INFO);
// We don't want this form to be cached.
header('Pragma: no-cache');
header('Cache-Control: no-cache');
header('Expires: -1');
// Check for a valid token. If invalid, send a 403 with the error message.
JSession::checkToken('request') or $this->sendResponse(new Exception(JText::_('JINVALID_TOKEN'), 403));
// Put in a buffer to silence noise.
ob_start();
// Remove the script time limit.
@set_time_limit(0);
// Get the indexer state.
$state = FinderIndexer::getState();
// Reset the batch offset.
$state->batchOffset = 0;
// Update the indexer state.
FinderIndexer::setState($state);
// Import the finder plugins.
JPluginHelper::importPlugin('finder');
/*
* We are going to swap out the raw document object with an HTML document
* in order to work around some plugins that don't do proper environment
* checks before trying to use HTML document functions.
*/
$raw = clone JFactory::getDocument();
$lang = JFactory::getLanguage();
// Get the document properties.
$attributes = array('charset' => 'utf-8', 'lineend' => 'unix', 'tab' => ' ', 'language' => $lang->getTag(), 'direction' => $lang->isRtl() ? 'rtl' : 'ltr');
// Get the HTML document.
$html = JDocument::getInstance('html', $attributes);
$doc = JFactory::getDocument();
// Swap the documents.
$doc = $html;
// Get the admin application.
$admin = clone JFactory::getApplication();
// Get the site app.
$site = JApplicationCms::getInstance('site');
// Swap the app.
$app = JFactory::getApplication();
$app = $site;
// Start the indexer.
try {
// Trigger the onBeforeIndex event.
JEventDispatcher::getInstance()->trigger('onBeforeIndex');
// Trigger the onBuildIndex event.
JEventDispatcher::getInstance()->trigger('onBuildIndex');
// Get the indexer state.
$state = FinderIndexer::getState();
$state->start = 0;
$state->complete = 0;
// Swap the documents back.
$doc = $raw;
// Swap the applications back.
$app = $admin;
// Send the response.
$this->sendResponse($state);
} catch (Exception $e) {
// Swap the documents back.
$doc = $raw;
// Send the response.
$this->sendResponse($e);
}
}
示例11: getDefault
/**
* Get menu item by id
*
* @param string $language The language code.
*
* @return mixed The item object or null when not found for given language
*
* @since 1.6
*/
public function getDefault($language = '*')
{
if (array_key_exists($language, $this->_default) && JApplicationCms::getInstance('site')->getLanguageFilter()) {
return $this->_items[$this->_default[$language]];
} elseif (array_key_exists('*', $this->_default)) {
return $this->_items[$this->_default['*']];
} else {
return null;
}
}
示例12: getApplication
/**
* Get an application object.
*
* Returns the global {@link JApplicationCms} object, only creating it if it doesn't already exist.
*
* @param mixed $id A client identifier or name.
* @param array $config An optional associative array of configuration settings.
* @param string $prefix Application prefix
* @param Container $container An optional dependency injection container to inject into the application.
*
* @return JApplicationCms object
*
* @see JApplication
* @since 11.1
* @throws Exception
*/
public static function getApplication($id = null, array $config = array(), $prefix = 'JApplication', Container $container = null)
{
if (!self::$application) {
if (!$id) {
throw new Exception('Application Instantiation Error', 500);
}
$container = $container ?: self::getContainer();
self::$application = JApplicationCms::getInstance($id, $prefix, $container);
}
return self::$application;
}
示例13: getApplication
/**
* Get a application object.
*
* Returns the global {@link JApplicationCms} object, only creating it if it doesn't already exist.
*
* @param mixed $id A client identifier or name.
* @param array $config An optional associative array of configuration settings.
* @param string $prefix Application prefix
*
* @return JApplicationCms object
*
* @see JApplication
* @since 11.1
* @throws Exception
*/
public static function getApplication($id = null, array $config = array(), $prefix = 'J')
{
if (!self::$application) {
if (!$id) {
throw new Exception('Application Instantiation Error', 500);
}
self::$application = JApplicationCms::getInstance($id);
}
return self::$application;
}
示例14: getData
/**
* Main get data method
*
* @access public
* @return Object[]
*/
public function getData()
{
// Load data from XML file, parse it to load records
$cachedSitemapFilePath = JPATH_COMPONENT_ADMINISTRATOR . '/cache/analyzer/';
// Has sitemap some vars such as lang or Itemid?
$sitemapLang = $this->getState('sitemaplang', '');
$sitemapLinksLang = $sitemapLang ? $sitemapLang . '/' : '';
$sitemapLang = $sitemapLang ? '_' . $sitemapLang : '';
$sitemapDataset = $this->getState('sitemapdataset', '');
$sitemapDataset = $sitemapDataset ? '_dataset' . (int) $sitemapDataset : '';
$sitemapItemid = $this->getState('sitemapitemid', '');
$sitemapItemid = $sitemapItemid ? '_menuid' . (int) $sitemapItemid : '';
// Final name
$cachedSitemapFilename = 'sitemap_xml' . $sitemapLang . $sitemapDataset . $sitemapItemid . '.xml';
// Start processing
try {
// Now check if the file correctly exists
if (JFile::exists($cachedSitemapFilePath . $cachedSitemapFilename)) {
$loadedSitemapXML = simplexml_load_file($cachedSitemapFilePath . $cachedSitemapFilename);
} else {
throw new JMapException(JText::sprintf('COM_JMAP_ANALYZER_NOCACHED_FILE_EXISTS', $this->_db->getErrorMsg()), 'error');
}
// Execute HTTP request and associate HTTP response code with each record links
$httpClient = new JMapHttp();
if ($loadedSitemapXML->url->count()) {
// Manage splice pagination here for the XML records
$convertedIteratorToArray = iterator_to_array($loadedSitemapXML->url, false);
// Store number of records for pagination
$this->recordsNumber = count($convertedIteratorToArray);
// Execute pagination splicing if any limit is set
$limit = $this->getState('limit');
if ($limit) {
$loadedSitemapXML = array_splice($convertedIteratorToArray, $this->getState('limitstart'), $this->getState('limit'));
} else {
$loadedSitemapXML = $convertedIteratorToArray;
}
// Now start the Analyzer
$siteRouter = JRouterSite::getInstance('site', array('mode' => JROUTER_MODE_SEF));
if (version_compare(JVERSION, '3.4', '>=')) {
JApplicationCms::getInstance('site')->loadLanguage();
}
$headers = array('Accept' => 'text/html', 'User-Agent' => 'Googlebot-Image/1.0');
foreach ($loadedSitemapXML as $url) {
$httpResponse = $httpClient->get($url->loc, $headers);
$url->httpstatus = $httpResponse->code;
// Find informations about the link, component and menu itemid if any, need a workaround to parse correctly from backend
$baseAdmin = JURI::base();
$baseSite = str_replace('/administrator', '', $baseAdmin);
$fakedUrl = str_replace($baseSite, $baseAdmin, $url->loc);
$fakedUrl = str_replace($sitemapLinksLang, '', $fakedUrl);
// Now instantiate and parse the faked url from backend, replacing the uri base it will be = site
$uriObject = JURI::getInstance((string) $fakedUrl);
$parseUri = $siteRouter->parse($uriObject);
// Now augment the object to show informations
$url->component = isset($parseUri['option']) ? $parseUri['option'] : JText::_('COM_JMAP_ANALYZER_NOINFO');
$url->menuId = isset($parseUri['Itemid']) ? $parseUri['Itemid'] : JText::_('COM_JMAP_ANALYZER_NOINFO');
$url->menuTitle = JText::_('COM_JMAP_ANALYZER_NOINFO');
// Translate human menu
if (isset($parseUri['Itemid'])) {
$query = "SELECT" . $this->_db->quoteName('title') . "\n FROM #__menu" . "\n WHERE " . $this->_db->quoteName('id') . " = " . (int) $parseUri['Itemid'];
$menuTitle = $this->_db->setQuery($query)->loadResult();
$url->menuTitle = $menuTitle;
}
}
// Perform array sorting if any
$order = $this->getState('order', null);
$jmapAnalyzerOrderDir = $this->getState('order_dir', 'asc');
if ($order == 'httpstatus') {
function cmpAsc($a, $b)
{
return (int) $a->httpstatus < (int) $b->httpstatus ? -1 : 1;
}
function cmpDesc($a, $b)
{
return (int) $a->httpstatus > (int) $b->httpstatus ? -1 : 1;
}
$callbackName = $jmapAnalyzerOrderDir == 'asc' ? 'cmpAsc' : 'cmpDesc';
usort($loadedSitemapXML, $callbackName);
}
if ($order == 'link') {
function cmpAsc($a, $b)
{
return strcmp($a->loc, $b->loc);
}
function cmpDesc($a, $b)
{
return strcmp($b->loc, $a->loc);
}
$callbackName = $jmapAnalyzerOrderDir == 'asc' ? 'cmpAsc' : 'cmpDesc';
usort($loadedSitemapXML, $callbackName);
}
} else {
throw new JMapException(JText::sprintf('COM_JMAP_ANALYZER_EMPTY_SITEMAP', $this->_db->getErrorMsg()), 'notice');
}
//.........这里部分代码省略.........
示例15: createURI
/**
* Create a uri based on a full or partial url string
*
* @param string $url The URI
*
* @return JUri
*
* @since 3.2
*/
protected function createURI($url)
{
// Create the URI
$uri = parent::createURI($url);
// Set URI defaults
$app = JApplicationCms::getInstance('site');
$menu = $app->getMenu();
// Get the itemid form the URI
$itemid = $uri->getVar('Itemid');
if (is_null($itemid)) {
if ($option = $uri->getVar('option')) {
$item = $menu->getItem($this->getVar('Itemid'));
if (isset($item) && $item->component == $option) {
$uri->setVar('Itemid', $item->id);
}
} else {
if ($option = $this->getVar('option')) {
$uri->setVar('option', $option);
}
if ($itemid = $this->getVar('Itemid')) {
$uri->setVar('Itemid', $itemid);
}
}
} else {
if (!$uri->getVar('option')) {
if ($item = $menu->getItem($itemid)) {
$uri->setVar('option', $item->component);
}
}
}
return $uri;
}