Skip to content

Commit

Permalink
Enhance contect-contact plugin with direct links to webpage or email
Browse files Browse the repository at this point in the history
  • Loading branch information
mattiaverga committed Oct 6, 2017
1 parent ec26ad7 commit d585d3d
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 4 deletions.
9 changes: 9 additions & 0 deletions administrator/language/en-GB/en-GB.plg_content_contact.ini
Expand Up @@ -5,3 +5,12 @@

PLG_CONTENT_CONTACT="Content - Contact"
PLG_CONTENT_CONTACT_XML_DESCRIPTION="Provides a link between the content author and the contact item that can be used for an Author Profile."
PLG_CONTENT_CONTACT_PARAM_URL_LABEL="URL to link to"
PLG_CONTENT_CONTACT_PARAM_URL_DESCRIPTION="You can link the author name to:<UL><LI>Associated contact page.<LI>Webpage specified in the associated contact profile.<LI>Email specified in the associated contact profile.</UL>"
PLG_CONTENT_CONTACT_PARAM_URL_0="Internal contact page"
PLG_CONTENT_CONTACT_PARAM_URL_1="Webpage from contact"
PLG_CONTENT_CONTACT_PARAM_URL_2="Email from contact"
PLG_CONTENT_CONTACT_PARAM_ALIAS_LABEL="Apply link also to alias name"
PLG_CONTENT_CONTACT_PARAM_ALIAS_DESCRIPTION="Link to the real user data even if an author alias is set in article options."
PLG_CONTENT_CONTACT_PARAM_YES="Yes"
PLG_CONTENT_CONTACT_PARAM_NO="No"
24 changes: 20 additions & 4 deletions plugins/content/contact/contact.php
Expand Up @@ -51,20 +51,36 @@ public function onContentPrepare($context, &$row, $params, $page = 0)
return true;
}

// Return if we don't want to link to aliases
if ($this->params->get('LinkToAlias') == 0 & $row->created_by_alias != '')
{
return true;
}

// Return if we don't have a valid article id
if (!isset($row->id) || !(int) $row->id)
{
return true;
}

$contact = $this->getContactId($row->created_by);
$contact = $this->getContactData($row->created_by);
$row->contactid = $contact->contactid;
$row->webpage = $contact->webpage;
$row->email = $contact->email_to;

if ($row->contactid)
if ($row->contactid && $this->params->get('UrlType') == 0)
{
JLoader::register('ContactHelperRoute', JPATH_SITE . '/components/com_contact/helpers/route.php');
$row->contact_link = JRoute::_(ContactHelperRoute::getContactRoute($contact->contactid . ':' . $contact->alias, $contact->catid));
}
else if ($row->webpage && $this->params->get('UrlType') == 1)
{
$row->contact_link = $row->webpage;
}
else if ($row->email && $this->params->get('UrlType') == 2)
{
$row->contact_link = 'mailto:' . $row->email;
}
else
{
$row->contact_link = '';
Expand All @@ -80,7 +96,7 @@ public function onContentPrepare($context, &$row, $params, $page = 0)
*
* @return mixed|null|integer
*/
protected function getContactId($created_by)
protected function getContactData($created_by)
{
static $contacts = array();

Expand All @@ -91,7 +107,7 @@ protected function getContactId($created_by)

$query = $this->db->getQuery(true);

$query->select('MAX(contact.id) AS contactid, contact.alias, contact.catid');
$query->select('MAX(contact.id) AS contactid, contact.alias, contact.catid, contact.webpage, contact.email_to');
$query->from($this->db->quoteName('#__contact_details', 'contact'));
$query->where('contact.published = 1');
$query->where('contact.user_id = ' . (int) $created_by);
Expand Down
20 changes: 20 additions & 0 deletions plugins/content/contact/contact.xml
Expand Up @@ -18,6 +18,26 @@
</languages>
<config>
<fields name="params">
<fieldset name="basic">
<field name="UrlType" type="radio"
default="0"
description="PLG_CONTENT_CONTACT_PARAM_URL_DESCRIPTION"
label="PLG_CONTENT_CONTACT_PARAM_URL_LABEL"
>
<option value="0">PLG_CONTENT_CONTACT_PARAM_URL_0</option>
<option value="1">PLG_CONTENT_CONTACT_PARAM_URL_1</option>
<option value="2">PLG_CONTENT_CONTACT_PARAM_URL_2</option>
</field>

<field name="LinkToAlias" type="radio"
default="0"
description="PLG_CONTENT_CONTACT_PARAM_ALIAS_DESCRIPTION"
label="PLG_CONTENT_CONTACT_PARAM_ALIAS_LABEL"
>
<option value="0">PLG_CONTENT_CONTACT_PARAM_NO</option>
<option value="1">PLG_CONTENT_CONTACT_PARAM_YES</option>
</field>
</fieldset>
</fields>
</config>
</extension>

0 comments on commit d585d3d

Please sign in to comment.