Skip to content

Commit

Permalink
Add plugin events to com_contact (redo) Fixes #8024
Browse files Browse the repository at this point in the history
  • Loading branch information
wilsonge authored and Michael Babker committed Dec 2, 2015
1 parent 5c19acf commit 3c968ff
Show file tree
Hide file tree
Showing 10 changed files with 128 additions and 25 deletions.
7 changes: 7 additions & 0 deletions components/com_contact/views/category/tmpl/default_items.php
Expand Up @@ -71,6 +71,11 @@
<span class="label label-warning"><?php echo JText::_('JUNPUBLISHED'); ?></span>
<?php endif; ?>
</div>

<?php echo $item->event->afterDisplayTitle; ?>

<?php echo $item->event->beforeDisplayContent; ?>

<?php if ($this->params->get('show_position_headings')) : ?>
<?php echo $item->con_position; ?><br />
<?php endif; ?>
Expand All @@ -89,6 +94,8 @@
<?php echo $item->country; ?><br />
<?php endif; ?>
</div>

<?php echo $item->event->afterDisplayContent; ?>
</li>
<?php endif; ?>
<?php endforeach; ?>
Expand Down
30 changes: 22 additions & 8 deletions components/com_contact/views/contact/tmpl/default.php
Expand Up @@ -19,6 +19,7 @@
<?php echo $this->escape($this->params->get('page_heading')); ?>
</h1>
<?php endif; ?>

<?php if ($this->contact->name && $this->params->get('show_name')) : ?>
<div class="page-header">
<h2>
Expand All @@ -28,12 +29,16 @@
<span class="contact-name" itemprop="name"><?php echo $this->contact->name; ?></span>
</h2>
</div>
<?php endif; ?>
<?php endif; ?>

<?php if ($this->params->get('show_contact_category') == 'show_no_link') : ?>
<h3>
<span class="contact-category"><?php echo $this->contact->category_title; ?></span>
</h3>
<?php endif; ?>

<?php echo $this->item->event->afterDisplayTitle; ?>

<?php if ($this->params->get('show_contact_category') == 'show_with_link') : ?>
<?php $contactLink = ContactHelperRoute::getCategoryRoute($this->contact->catid); ?>
<h3>
Expand All @@ -42,6 +47,7 @@
</span>
</h3>
<?php endif; ?>

<?php if ($this->params->get('show_contact_list') && count($this->contacts) > 1) : ?>
<form action="#" method="get" name="selectForm" id="selectForm">
<?php echo JText::_('COM_CONTACT_SELECT_CONTACT'); ?>
Expand All @@ -54,19 +60,24 @@
<?php echo $this->item->tagLayout->render($this->item->tags->itemTags); ?>
<?php endif; ?>

<?php echo $this->item->event->beforeDisplayContent; ?>

<?php if ($this->params->get('presentation_style') == 'sliders') : ?>
<?php echo JHtml::_('bootstrap.startAccordion', 'slide-contact', array('active' => 'basic-details')); ?>
<?php endif; ?>

<?php if ($this->params->get('presentation_style') == 'tabs') : ?>
<?php echo JHtml::_('bootstrap.startTabSet', 'myTab', array('active' => 'basic-details')); ?>
<?php endif; ?>

<?php if ($this->params->get('presentation_style') == 'sliders') : ?>
<?php echo JHtml::_('bootstrap.addSlide', 'slide-contact', JText::_('COM_CONTACT_DETAILS'), 'basic-details'); ?>
<?php endif; ?>

<?php if ($this->params->get('presentation_style') == 'tabs') : ?>
<?php echo JHtml::_('bootstrap.addTab', 'myTab', 'basic-details', JText::_('COM_CONTACT_DETAILS', true)); ?>
<?php endif; ?>

<?php if ($this->params->get('presentation_style') == 'plain'):?>
<?php echo '<h3>' . JText::_('COM_CONTACT_DETAILS') . '</h3>'; ?>
<?php endif; ?>
Expand Down Expand Up @@ -96,6 +107,7 @@
<?php if ($this->params->get('presentation_style') == 'sliders') : ?>
<?php echo JHtml::_('bootstrap.endSlide'); ?>
<?php endif; ?>

<?php if ($this->params->get('presentation_style') == 'tabs') : ?>
<?php echo JHtml::_('bootstrap.endTab'); ?>
<?php endif; ?>
Expand All @@ -108,7 +120,8 @@
<?php if ($this->params->get('presentation_style') == 'tabs') : ?>
<?php echo JHtml::_('bootstrap.addTab', 'myTab', 'display-form', JText::_('COM_CONTACT_EMAIL_FORM', true)); ?>
<?php endif; ?>
<?php if ($this->params->get('presentation_style') == 'plain'):?>

<?php if ($this->params->get('presentation_style') == 'plain'): ?>
<?php echo '<h3>' . JText::_('COM_CONTACT_EMAIL_FORM') . '</h3>'; ?>
<?php endif; ?>

Expand All @@ -117,10 +130,10 @@
<?php if ($this->params->get('presentation_style') == 'sliders') : ?>
<?php echo JHtml::_('bootstrap.endSlide'); ?>
<?php endif; ?>
<?php if ($this->params->get('presentation_style') == 'tabs') : ?>
<?php echo JHtml::_('bootstrap.endTab'); ?>
<?php endif; ?>

<?php if ($this->params->get('presentation_style') == 'tabs') : ?>
<?php echo JHtml::_('bootstrap.endTab'); ?>
<?php endif; ?>
<?php endif; ?>

<?php if ($this->params->get('show_links')) : ?>
Expand All @@ -132,9 +145,11 @@
<?php if ($this->params->get('presentation_style') == 'sliders') : ?>
<?php echo JHtml::_('bootstrap.addSlide', 'slide-contact', JText::_('JGLOBAL_ARTICLES'), 'display-articles'); ?>
<?php endif; ?>

<?php if ($this->params->get('presentation_style') == 'tabs') : ?>
<?php echo JHtml::_('bootstrap.addTab', 'myTab', 'display-articles', JText::_('JGLOBAL_ARTICLES', true)); ?>
<?php endif; ?>

<?php if ($this->params->get('presentation_style') == 'plain'):?>
<?php echo '<h3>' . JText::_('JGLOBAL_ARTICLES') . '</h3>'; ?>
<?php endif; ?>
Expand All @@ -144,14 +159,14 @@
<?php if ($this->params->get('presentation_style') == 'sliders') : ?>
<?php echo JHtml::_('bootstrap.endSlide'); ?>
<?php endif; ?>

<?php if ($this->params->get('presentation_style') == 'tabs') : ?>
<?php echo JHtml::_('bootstrap.endTab'); ?>
<?php endif; ?>

<?php endif; ?>

<?php if ($this->params->get('show_profile') && $this->contact->user_id && JPluginHelper::isEnabled('user', 'profile')) : ?>

<?php if ($this->params->get('presentation_style') == 'sliders') : ?>
<?php echo JHtml::_('bootstrap.addSlide', 'slide-contact', JText::_('COM_CONTACT_PROFILE'), 'display-profile'); ?>
<?php endif; ?>
Expand All @@ -170,11 +185,9 @@
<?php if ($this->params->get('presentation_style') == 'tabs') : ?>
<?php echo JHtml::_('bootstrap.endTab'); ?>
<?php endif; ?>

<?php endif; ?>

<?php if ($this->contact->misc && $this->params->get('show_misc')) : ?>

<?php if ($this->params->get('presentation_style') == 'sliders') : ?>
<?php echo JHtml::_('bootstrap.addSlide', 'slide-contact', JText::_('COM_CONTACT_OTHER_INFORMATION'), 'display-misc'); ?>
<?php endif; ?>
Expand Down Expand Up @@ -215,4 +228,5 @@
<?php if ($this->params->get('presentation_style') == 'tabs') : ?>
<?php echo JHtml::_('bootstrap.endTabSet'); ?>
<?php endif; ?>
<?php echo $this->item->event->afterDisplayContent; ?>
</div>
33 changes: 31 additions & 2 deletions components/com_contact/views/contact/view.html.php
Expand Up @@ -102,7 +102,7 @@ public function display($tpl = null)
$app->enqueueMessage(JText::_('JERROR_ALERTNOAUTHOR'), 'error');
$app->setHeader('status', 403, true);

return;
return false;
}

$options['category_id'] = $item->catid;
Expand All @@ -113,6 +113,7 @@ public function display($tpl = null)
{
$item->email_to = JHtml::_('email.cloak', $item->email_to);
}

if ($params->get('show_street_address') || $params->get('show_suburb') || $params->get('show_state')
|| $params->get('show_postcode') || $params->get('show_country'))
{
Expand Down Expand Up @@ -231,6 +232,31 @@ public function display($tpl = null)
$item->link = JRoute::_(ContactHelperRoute::getContactRoute($item->slug, $item->catid));
}

// Process the content plugins.
$dispatcher = JEventDispatcher::getInstance();
JPluginHelper::importPlugin('content');
$offset = $state->get('list.offset');

// Fix for where some plugins require a text attribute
!empty($item->description)? $item->text = $item->description : $item->text = null;
$dispatcher->trigger('onContentPrepare', array ('com_contact.contact', &$item, &$this->params, $offset));

// Store the events for later
$item->event = new stdClass;
$results = $dispatcher->trigger('onContentAfterTitle', array('com_contact.contact', &$item, &$this->params, $offset));
$item->event->afterDisplayTitle = trim(implode("\n", $results));

$results = $dispatcher->trigger('onContentBeforeDisplay', array('com_contact.contact', &$item, &$this->params, $offset));
$item->event->beforeDisplayContent = trim(implode("\n", $results));

$results = $dispatcher->trigger('onContentAfterDisplay', array('com_contact.contact', &$item, &$this->params, $offset));
$item->event->afterDisplayContent = trim(implode("\n", $results));

if ($item->text)
{
$item->description = $item->text;
}

// Escape strings for HTML output
$this->pageclass_sfx = htmlspecialchars($params->get('pageclass_sfx'));

Expand Down Expand Up @@ -273,6 +299,8 @@ public function display($tpl = null)
* Prepares the document
*
* @return void
*
* @since 1.6
*/
protected function _prepareDocument()
{
Expand Down Expand Up @@ -301,12 +329,12 @@ protected function _prepareDocument()
// If the menu item does not concern this contact
if ($menu && ($menu->query['option'] != 'com_contact' || $menu->query['view'] != 'contact' || $id != $this->item->id))
{

// If this is not a single contact menu item, set the page title to the contact title
if ($this->item->name)
{
$title = $this->item->name;
}

$path = array(array('title' => $this->contact->name, 'link' => ''));
$category = JCategories::getInstance('Contact')->get($this->contact->catid);

Expand Down Expand Up @@ -341,6 +369,7 @@ protected function _prepareDocument()
{
$title = $this->item->name;
}

$this->document->setTitle($title);

if ($this->item->metadesc)
Expand Down
7 changes: 4 additions & 3 deletions components/com_contact/views/featured/tmpl/default.php
Expand Up @@ -22,16 +22,17 @@
<?php endif; ?>

<?php echo $this->loadTemplate('items'); ?>

<?php if ($this->params->def('show_pagination', 2) == 1 || ($this->params->get('show_pagination') == 2 && $this->pagination->pagesTotal > 1)) : ?>
<div class="pagination">

<?php if ($this->params->def('show_pagination_results', 1)) : ?>
<p class="counter">
<?php echo $this->pagination->getPagesCounter(); ?>
</p>
<?php endif; ?>
<?php echo $this->pagination->getPagesLinks(); ?>
<?php endif; ?>

<?php echo $this->pagination->getPagesLinks(); ?>
</div>
<?php endif; ?>

</div>
12 changes: 8 additions & 4 deletions components/com_contact/views/featured/view.html.php
Expand Up @@ -61,11 +61,13 @@ class ContactViewFeatured extends JViewLegacy
protected $pagination;

/**
* Display the view
* Method to display the view.
*
* @param string $tpl The name of the template file to parse; automatically searches through the template paths.
*
* @return mixed False on error, null otherwise.
* @return mixed Exception on failure, void on success.
*
* @since 1.6
*/
public function display($tpl = null)
{
Expand All @@ -84,6 +86,7 @@ public function display($tpl = null)
if (count($errors = $this->get('Errors')))
{
JError::raiseWarning(500, implode("\n", $errors));

return false;
}

Expand All @@ -96,8 +99,9 @@ public function display($tpl = null)
$temp = new Registry;

$temp->loadString($item->params);
$item->params = clone($params);
$item->params = clone $params;
$item->params->merge($temp);

if ($item->params->get('show_email', 0) == 1)
{
$item->email_to = trim($item->email_to);
Expand Down Expand Up @@ -128,7 +132,7 @@ public function display($tpl = null)

$this->_prepareDocument();

parent::display($tpl);
return parent::display($tpl);
}

/**
Expand Down
19 changes: 13 additions & 6 deletions layouts/joomla/content/category_default.php
Expand Up @@ -9,15 +9,19 @@

defined('JPATH_BASE') or die;

// Note that this layout opens a div with the page class suffix. If you do not use the category children
// layout you need to close this div either by overriding this file or in your main layout.
/**
* Note that this layout opens a div with the page class suffix. If you do not use the category children
* layout you need to close this div either by overriding this file or in your main layout.
*/
$params = $displayData->params;
$extension = $displayData->get('category')->extension;
$canEdit = $params->get('access-edit');
$className = substr($extension, 4);

// This will work for the core components but not necessarily for other components
// that may have different pluralisation rules.
/**
* This will work for the core components but not necessarily for other components
* that may have different pluralisation rules.
*/
if (substr($className, -1) == 's')
{
$className = rtrim($className, 's');
Expand All @@ -31,21 +35,24 @@
<?php echo $displayData->escape($params->get('page_heading')); ?>
</h1>
<?php endif; ?>
<?php if($params->get('show_category_title', 1)) : ?>

<?php if ($params->get('show_category_title', 1)) : ?>
<h2>
<?php echo JHtml::_('content.prepare', $displayData->get('category')->title, '', $extension . '.category.title'); ?>
</h2>
<?php endif; ?>

<?php if ($params->get('show_cat_tags', 1)) : ?>
<?php echo JLayoutHelper::render('joomla.content.tags', $tagsData); ?>
<?php endif; ?>

<?php if ($params->get('show_description', 1) || $params->def('show_description_image', 1)) : ?>
<div class="category-desc">
<?php if ($params->get('show_description_image') && $displayData->get('category')->getParams()->get('image')) : ?>
<img src="<?php echo $displayData->get('category')->getParams()->get('image'); ?>" alt="<?php echo htmlspecialchars($displayData->get('category')->getParams()->get('image_alt')); ?>"/>
<?php endif; ?>
<?php if ($params->get('show_description') && $displayData->get('category')->description) : ?>
<?php echo JHtml::_('content.prepare', $displayData->get('category')->description, '', $extension . '.category'); ?>
<?php echo JHtml::_('content.prepare', $displayData->get('category')->description, '', $extension . '.category.description'); ?>
<?php endif; ?>
<div class="clr"></div>
</div>
Expand Down
30 changes: 29 additions & 1 deletion libraries/legacy/view/category.php
Expand Up @@ -145,7 +145,35 @@ public function commonCategoryDisplay()
// Escape strings for HTML output
$this->pageclass_sfx = htmlspecialchars($params->get('pageclass_sfx'));

$maxLevel = $params->get('maxLevel', -1);
foreach ($items as $itemElement)
{
$itemElement = (object) $itemElement;
$itemElement->event = new stdClass;

// For some plugins.
!empty($itemElement->description)? $itemElement->text = $itemElement->description : $itemElement->text = null;

$dispatcher = JEventDispatcher::getInstance();
JPluginHelper::importPlugin('content');

$dispatcher->trigger('onContentPrepare', array ($this->extension . '.category', &$itemElement, &$itemElement->params, 0));

$results = $dispatcher->trigger('onContentAfterTitle', array($this->extension . '.category', &$itemElement, &$itemElement->core_params, 0));
$itemElement->event->afterDisplayTitle = trim(implode("\n", $results));

$results = $dispatcher->trigger('onContentBeforeDisplay', array($this->extension . '.category', &$itemElement, &$itemElement->core_params, 0));
$itemElement->event->beforeDisplayContent = trim(implode("\n", $results));

$results = $dispatcher->trigger('onContentAfterDisplay', array($this->extension . '.category', &$itemElement, &$itemElement->core_params, 0));
$itemElement->event->afterDisplayContent = trim(implode("\n", $results));

if ($itemElement->text)
{
$itemElement->description = $itemElement->text;
}
}

$maxLevel = $params->get('maxLevel', -1) < 0 ? PHP_INT_MAX : $params->get('maxLevel', PHP_INT_MAX);
$this->maxLevel = &$maxLevel;
$this->state = &$state;
$this->items = &$items;
Expand Down
2 changes: 1 addition & 1 deletion templates/beez3/html/com_contact/category/default.php
Expand Up @@ -27,7 +27,7 @@
<img src="<?php echo $this->category->getParams()->get('image'); ?>"/>
<?php endif; ?>
<?php if ($this->params->get('show_description') && $this->category->description) : ?>
<?php echo JHtml::_('content.prepare', $this->category->description, '', 'com_contact.category'); ?>
<?php echo JHtml::_('content.prepare', $this->category->description, '', 'com_contact.category.description'); ?>
<?php endif; ?>
<div class="clr"></div>
</div>
Expand Down

0 comments on commit 3c968ff

Please sign in to comment.