Udtræk af dato!
Hej,Jeg er total grøn i php, men tiltrods for det har jeg prøvet at se om jeg kunne lave en løsning selv på problemet, men desværre så derfor dette spørgsmål!
Jeg bruger et modul jeg skal have hacke, så den kan vise datoen og tidspunktet - script ser sådan ud:
<?php
// no direct access
defined('_JEXEC') or die('Restricted access');
// cmslib is required for functions.jomcomment.php
if(!defined('CMSLIB_DEFINED')) {
include_once (JPATH_SITE.DS.'components'.DS.'libraries'.DS.'cmslib'.DS.'spframework.php');
}
require_once (JPATH_SITE.DS.'components'.DS.'com_jomcomment'.DS.'functions.jomcomment.php');
require_once (JPATH_SITE.DS.'components'.DS.'com_jomcomment'.DS.'helper'.DS.'comments.helper.php');
require_once (JPATH_SITE.DS.'components'.DS.'com_content'.DS.'helpers'.DS.'route.php');
class modJomLatestHelper
{
function getList(&$params)
{
global $mainframe;
$db =& JFactory::getDBO();
$user =& JFactory::getUser();
$userId = (int) $user->get('id');
$count = (int) $params->get('count', 5);
$displayLen = (int) $params->get('displayLen', 50);
$titleLen = (int) $params->get('titleLen', 50);
$query = "SELECT a.id, a.contentid, a.comment, a.name, b.title, b.sectionid, b.title,
CASE WHEN CHAR_LENGTH(b.alias) THEN CONCAT_WS(':', b.id, b.alias) ELSE b.id END as slug,
CASE WHEN CHAR_LENGTH(cc.alias) THEN CONCAT_WS(':', cc.id, cc.alias) ELSE cc.id END as catslug
FROM #__jomcomment as a , #__content as b
INNER JOIN #__categories AS cc ON cc.id = b.catid
INNER JOIN #__sections AS s ON s.id = b.sectionid
WHERE a.published=1 AND b.id=a.contentid
ORDER BY a.id DESC";
$db->setQuery($query, 0, $count);
$rows = $db->loadObjectList();
$list = array();
$i = 0;
foreach($rows as $row) {
$list[$i]->link = JRoute::_(ContentHelperRoute::getArticleRoute($row->slug, $row->catslug, $row->sectionid));
$row->comment = jcStripBbCode($row->comment);
$comment = modJomLatestHelper::_wrapText($row->comment, $displayLen);
$comment = jcTransformDbText($comment);
$comment = jcDecodeSmilies($comment);
$list[$i]->comment = $comment;
$list[$i]->name = jcTransformDbText(jcTextWrap($row->name, $nameLen));
$list[$i]->title = jcTransformDbText(jcTextWrap($row->title, $titleLen));
$i++;
}
return $list;
}
function _wrapText($text, $width = 20)
{
if(strlen($text) > $width)
return (substr($text , 0, $width) . '...');
else
return $text;
}
}
Visningen side ser såleders ud:
<?php
// no direct access
defined('_JEXEC') or die('Restricted access');
?>
<ul style="overflow: hidden" class="jomlatest<?php echo $params->get('moduleclass_sfx'); ?>">
<?php foreach ($list as $item) : ?>
<li class="jomlatest<?php echo $params->get('moduleclass_sfx'); ?>">
<a href="<?php echo $item->link; ?>" class="jomlatest<?php echo $params->get('moduleclass_sfx'); ?>">
<?php echo $item->title ?></a>
</a>
Kommentaret af <?php echo $item->name ?>
<?php echo $item->dato ?>
<?php echo ''.$row['date'].''?>
<p><?php echo $item->comment ?></p>
</li>
<?php endforeach; ?>
</ul>
På forhånd tak
c;") Per