Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,43 +7,50 @@
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

namespace Joomla\Component\Content\Administrator\Service\HTML;

defined('_JEXEC') or die;

use Joomla\CMS\Factory;
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Language\Associations;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Layout\LayoutHelper;
use Joomla\CMS\Router\Route;
use Joomla\Utilities\ArrayHelper;

JLoader::register('ContentHelper', JPATH_ADMINISTRATOR . '/components/com_content/helpers/content.php');

/**
* Content HTML helper
*
* @since 3.0
*/
abstract class JHtmlContentAdministrator
class AdministratorService
{

/**
* Render the list of associated items
*
* @param integer $articleid The article item id
*
* @return string The language HTML
*
* @throws Exception
* @throws \Exception
*/
public static function association($articleid)
public function association($articleid)
{
// Defaults
$html = '';

// Get the associations
if ($associations = JLanguageAssociations::getAssociations('com_content', '#__content', 'com_content.item', $articleid))
if ($associations = Associations::getAssociations('com_content', '#__content', 'com_content.item', $articleid))
{
foreach ($associations as $tag => $associated)
{
$associations[$tag] = (int) $associated->id;
}

// Get the associated menu items
$db = JFactory::getDbo();
$db = Factory::getDbo();
$query = $db->getQuery(true)
->select('c.*')
->select('l.sef as lang_sef')
Expand All @@ -62,18 +69,18 @@ public static function association($articleid)
{
$items = $db->loadObjectList('id');
}
catch (RuntimeException $e)
catch (\RuntimeException $e)
{
throw new Exception($e->getMessage(), 500, $e);
throw new \Exception($e->getMessage(), 500, $e);
}

if ($items)
{
foreach ($items as &$item)
{
$text = $item->lang_sef ? strtoupper($item->lang_sef) : 'XX';
$url = JRoute::_('index.php?option=com_content&task=article.edit&id=' . (int) $item->id);
$tooltip = htmlspecialchars($item->title, ENT_QUOTES, 'UTF-8') . '<br>' . JText::sprintf('JCATEGORY_SPRINTF', $item->category_title);
$url = Route::_('index.php?option=com_content&task=article.edit&id=' . (int) $item->id);
$tooltip = htmlspecialchars($item->title, ENT_QUOTES, 'UTF-8') . '<br>' . Text::sprintf('JCATEGORY_SPRINTF', $item->category_title);
$classes = 'hasPopover badge badge-secondary';

$item->link = '<a href="' . $url . '" title="' . $item->language_title . '" class="' . $classes
Expand All @@ -82,9 +89,9 @@ public static function association($articleid)
}
}

JHtml::_('bootstrap.popover');
HTMLHelper::_('bootstrap.popover');

$html = JLayoutHelper::render('joomla.content.associations', $items);
$html = LayoutHelper::render('joomla.content.associations', $items);
}

return $html;
Expand All @@ -99,7 +106,7 @@ public static function association($articleid)
*
* @return string HTML code
*/
public static function featured($value = 0, $i, $canChange = true)
public function featured($value = 0, $i, $canChange = true)
{
// Array of image, task, title, action
$states = array(
Expand All @@ -112,13 +119,13 @@ public static function featured($value = 0, $i, $canChange = true)
if ($canChange)
{
$html = '<a href="#" onclick="return listItemTask(\'cb' . $i . '\',\'' . $state[1] . '\')" class="tbody-icon hasTooltip'
. ($value == 1 ? ' active' : '') . '" title="' . JHtml::_('tooltipText', $state[3])
. ($value == 1 ? ' active' : '') . '" title="' . HTMLHelper::_('tooltipText', $state[3])
. '"><span class="icon-' . $icon . '" aria-hidden="true"></span></a>';
}
else
{
$html = '<a class="tbody-icon hasTooltip disabled' . ($value == 1 ? ' active' : '') . '" title="'
. JHtml::_('tooltipText', $state[2]) . '"><span class="icon-' . $icon . '" aria-hidden="true"></span></a>';
. HTMLHelper::_('tooltipText', $state[2]) . '"><span class="icon-' . $icon . '" aria-hidden="true"></span></a>';
}

return $html;
Expand Down
248 changes: 248 additions & 0 deletions administrator/components/com_content/Service/HTML/Icon.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,248 @@
<?php
/**
* @package Joomla.Site
* @subpackage com_content
*
* @copyright Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\Component\Content\Administrator\Service\HTML;

defined('_JEXEC') or die;

use Joomla\CMS\Application\CMSApplication;
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Layout\LayoutHelper;
use Joomla\CMS\Router\Route;
use Joomla\CMS\Uri\Uri;
use Joomla\Registry\Registry;

/**
* Content Component HTML Helper
*
* @since __DEPLOY_VERSION__
*/
class Icon
{
/**
* The application
*
* @var CMSApplication
*
* @since __DEPLOY_VERSION__
*/
private $application;

/**
* Service constructor
*
* @param CMSApplication $application The application
*
* @since __DEPLOY_VERSION__
*/
public function __construct(CMSApplication $application)
{
$this->application = $application;
}

/**
* Method to generate a link to the create item page for the given category
*
* @param object $category The category information
* @param Registry $params The item parameters
* @param array $attribs Optional attributes for the link
* @param boolean $legacy True to use legacy images, false to use icomoon based graphic
*
* @return string The HTML markup for the create item link
*
* @since __DEPLOY_VERSION__
*/
public function create($category, $params, $attribs = array(), $legacy = false)
{
$uri = Uri::getInstance();

$url = 'index.php?option=com_content&task=article.add&return=' . base64_encode($uri) . '&a_id=0&catid=' . $category->id;

$text = LayoutHelper::render('joomla.content.icons.create', array('params' => $params, 'legacy' => $legacy));

// Add the button classes to the attribs array
if (isset($attribs['class']))
{
$attribs['class'] .= ' btn btn-primary';
}
else
{
$attribs['class'] = 'btn btn-primary';
}

$button = HTMLHelper::_('link', Route::_($url), $text, $attribs);

$output = '<span class="hasTooltip" title="' . HTMLHelper::_('tooltipText', 'COM_CONTENT_CREATE_ARTICLE') . '">' . $button . '</span>';

return $output;
}

/**
* Method to generate a link to the email item page for the given article
*
* @param object $article The article information
* @param Registry $params The item parameters
* @param array $attribs Optional attributes for the link
* @param boolean $legacy True to use legacy images, false to use icomoon based graphic
*
* @return string The HTML markup for the email item link
*
* @since __DEPLOY_VERSION__
*/
public function email($article, $params, $attribs = array(), $legacy = false)
{
\JLoader::register('MailtoHelper', JPATH_SITE . '/components/com_mailto/helpers/mailto.php');

$uri = Uri::getInstance();
$base = $uri->toString(array('scheme', 'host', 'port'));
$template = $this->application->getTemplate();
$link = $base . Route::_(\ContentHelperRoute::getArticleRoute($article->slug, $article->catid, $article->language), false);
$url = 'index.php?option=com_mailto&tmpl=component&template=' . $template . '&link=' . \MailtoHelper::addLink($link);

$status = 'width=400,height=350,menubar=yes,resizable=yes';

$text = LayoutHelper::render('joomla.content.icons.email', array('params' => $params, 'legacy' => $legacy));

$attribs['title'] = Text::_('JGLOBAL_EMAIL_TITLE');
$attribs['onclick'] = "window.open(this.href,'win2','" . $status . "'); return false;";
$attribs['rel'] = 'nofollow';
$attribs['class'] = 'dropdown-item';

return HTMLHelper::_('link', Route::_($url), $text, $attribs);
}

/**
* Display an edit icon for the article.
*
* This icon will not display in a popup window, nor if the article is trashed.
* Edit access checks must be performed in the calling code.
*
* @param object $article The article information
* @param Registry $params The item parameters
* @param array $attribs Optional attributes for the link
* @param boolean $legacy True to use legacy images, false to use icomoon based graphic
*
* @return string The HTML for the article edit icon.
*
* @since __DEPLOY_VERSION__
*/
public function edit($article, $params, $attribs = array(), $legacy = false)
{
$user = JFactory::getUser();
$uri = JUri::getInstance();

// Ignore if in a popup window.
if ($params && $params->get('popup'))
{
return;
}

// Ignore if the state is negative (trashed).
if ($article->state < 0)
{
return;
}

// Set the link class
$attribs['class'] = 'dropdown-item';

// Show checked_out icon if the article is checked out by a different user
if (property_exists($article, 'checked_out')
&& property_exists($article, 'checked_out_time')
&& $article->checked_out > 0
&& $article->checked_out != $user->get('id'))
{
$checkoutUser = JFactory::getUser($article->checked_out);
$date = HTMLHelper::_('date', $article->checked_out_time);
$tooltip = Text::_('JLIB_HTML_CHECKED_OUT') . ' :: ' . Text::sprintf('COM_CONTENT_CHECKED_OUT_BY', $checkoutUser->name)
. ' <br> ' . $date;

$text = LayoutHelper::render('joomla.content.icons.edit_lock', array('tooltip' => $tooltip, 'legacy' => $legacy));

$output = HTMLHelper::_('link', '#', $text, $attribs);

return $output;
}

$contentUrl = \ContentHelperRoute::getArticleRoute($article->slug, $article->catid, $article->language);
$url = $contentUrl . '&task=article.edit&a_id=' . $article->id . '&return=' . base64_encode($uri);

if ($article->state == 0)
{
$overlib = Text::_('JUNPUBLISHED');
}
else
{
$overlib = Text::_('JPUBLISHED');
}

$date = HTMLHelper::_('date', $article->created);
$author = $article->created_by_alias ?: $article->author;

$overlib .= '&lt;br&gt;';
$overlib .= $date;
$overlib .= '&lt;br&gt;';
$overlib .= Text::sprintf('COM_CONTENT_WRITTEN_BY', htmlspecialchars($author, ENT_COMPAT, 'UTF-8'));

$text = LayoutHelper::render('joomla.content.icons.edit', array('article' => $article, 'overlib' => $overlib, 'legacy' => $legacy));

$attribs['title'] = Text::_('JGLOBAL_EDIT_TITLE');
$output = HTMLHelper::_('link', Route::_($url), $text, $attribs);

return $output;
}

/**
* Method to generate a popup link to print an article
*
* @param object $article The article information
* @param Registry $params The item parameters
* @param array $attribs Optional attributes for the link
* @param boolean $legacy True to use legacy images, false to use icomoon based graphic
*
* @return string The HTML markup for the popup link
*
* @since __DEPLOY_VERSION__
*/
public function print_popup($article, $params, $attribs = array(), $legacy = false)
{
$url = \ContentHelperRoute::getArticleRoute($article->slug, $article->catid, $article->language);
$url .= '&tmpl=component&print=1&layout=default';

$status = 'status=no,toolbar=no,scrollbars=yes,titlebar=no,menubar=no,resizable=yes,width=640,height=480,directories=no,location=no';

$text = LayoutHelper::render('joomla.content.icons.print_popup', array('params' => $params, 'legacy' => $legacy));

$attribs['title'] = Text::sprintf('JGLOBAL_PRINT_TITLE', htmlspecialchars($article->title, ENT_QUOTES, 'UTF-8'));
$attribs['onclick'] = "window.open(this.href,'win2','" . $status . "'); return false;";
$attribs['rel'] = 'nofollow';
$attribs['class'] = 'dropdown-item';

return HTMLHelper::_('link', Route::_($url), $text, $attribs);
}

/**
* Method to generate a link to print an article
*
* @param object $article Not used, @deprecated for 4.0
* @param Registry $params The item parameters
* @param array $attribs Not used, @deprecated for 4.0
* @param boolean $legacy True to use legacy images, false to use icomoon based graphic
*
* @return string The HTML markup for the popup link
*
* @since __DEPLOY_VERSION__
*/
public function print_screen($article, $params, $attribs = array(), $legacy = false)
{
$text = LayoutHelper::render('joomla.content.icons.print_screen', array('params' => $params, 'legacy' => $legacy));

return '<a href="#" onclick="window.print();return false;">' . $text . '</a>';
}
}
Loading