Diskuse

Téma: Vypis datumu

Zdravím, chtěl bych se zeptat kde v sunlightu bych měl zakomponovat tuto úpravu výpisu datumu (primárně se mi jedná o články a fórum?

http://www.joomlaportal.cz/index.php/clanky-a-novinky/vyvojarske-tipy-a-triky/315-zobrazeni-qdnesq-a-qveraq-misto-data-u-lank

Jedná se úpravu pro joomlu ale do SL to určitě také půjde zakomponovat.

//Hack for showing "Today" and "Yesterday" by Kryštof Korb | Copyright August 2008
$lang = "cz"; //Language en, cz, fr

$today['en'] = 'Today!';
$today['cz'] = 'Dnes!';
$today['fr'] = 'Aujourd\'hui!';
$yesterday['en'] = 'Yesterday';
$yesterday['cz'] = 'Včera';
$yesterday['fr'] = 'Hier';
if ($create_date == mosFormatDate(date("Y-m-d H:i:s", strtotime("now")))) {
$create_date = '<span style="color: red;">' . $today[$lang] . '</span>';
}
if ($create_date == mosFormatDate(date("Y-m-d H:i:s", strtotime("1 day ago")))) {
$create_date = '<span style="color: red;">' . $yesterday[$lang] . '</span>';
}
//End of Today/Yesterday hack
postZaslat odpověď
Když budu předpokládat, že $create_date je timestamp ze SL db

//Hack for showing "Today" and "Yesterday" by Kryštof Korb | Copyright August 2008
$lang = "cz"; //Language en, cz, fr

$create_date = date("Y-m-d",$create_date);

$today['en'] = 'Today!';
$today['cz'] = 'Dnes!';
$today['fr'] = 'Aujourd\'hui!';
$yesterday['en'] = 'Yesterday';
$yesterday['cz'] = 'Včera';
$yesterday['fr'] = 'Hier';
if ($create_date == date("Y-m-d", strtotime("now"))) {
$create_date = '<span style="color: red;">' . $today[$lang] . '</span>';
}
if ($create_date == date("Y-m-d", strtotime("1 day ago"))) {
$create_date = '<span style="color: red;">' . $yesterday[$lang] . '</span>';
}
//End of Today/Yesterday hack
Samozřejmě s tím, že v SL se ještě jinak používá lang, ale to by bylo na delší vysvětlování
Pro začátek bych to chtěl přidát aspoň do articlePreview pluginu ale nedaří 😞
Povedlo se v articlePreview pluginu jsme přidal
$create_date = date('d.m.Y', $art['time']);
$today = 'Dnes!';
$yesterday = 'Včera';
if ($create_date == date('d.m.Y', strtotime("now"))) {
$create_date = '<span style="color: red;">' . $today. '</span>';
}
if ($create_date == date('d.m.Y', strtotime("1 day ago"))) {
$create_date = '<span style="color: red;">' . $yesterday. '</span>';
}
a místo
<span class='date'>".date('d.m.Y', $art['time'])."</span>jsem nahradil
<span class='date'>".$create_date."</span>a šlape. :-)
Ještě bych měl dotaz chtěl bych dolu mezi datum a kategorie umístit kategorii ale nedaří se mi to :-( poradíte?

<?php
/* --- kontrola jadra --- */

if(!defined('_core')) {
exit;
}

$GLOBALS['_odd']=true;

// funkce
function _plugin_articlePreview($art, $info, $perex, $comment_count)
{
global $_odd;

$status=((true===$_odd)?"odd":"even");

$link = _linkArticle($art['id'], $art['title_seo']);

// uprava datumu na dnes, vcara
$my_date = date('d.m.Y', $art['time']); // formatuje i datum pouze na den,mesic, rok

$today = 'Dnes';
$yesterday = 'Včera';
if ($my_date == date('d.m.Y', strtotime("now"))) {
$my_date = '' . $today. '';
}
if ($my_date == date('d.m.Y', strtotime("1 day ago"))) {
$my_date = '' . $yesterday. '';
}

// dalsi upravy na kategorie
$cat = DB::query("SELECT r.title FROM `"._mysql_prefix."-articles` a LEFT JOIN `"._mysql_prefix."-root` r ON ( a.home1 = r.id ) WHERE a.home1 = ".$art['id']." LIMIT 0 , 1 ");


$out = "
<div class='list-article num-{$status}'>
<div class='list-perex-media'>
".(($perex && isset($art['picture_uid'])) ? "<a href='{$link}'><img src='"._pictureStorageGet(_indexroot.'pictures/articles/', null, $art['picture_uid'], 'jpg')."' class='list-perex-image' alt='{$art['title']}' /></a>" : '')."
</div>
<h2 class='list-title'><a href='{$link}'>"._cutStr(_htmlStrUndo($art['title']), 70)."</a></h2>
".($perex ? "<p class='list-perex'>
"._cutStr(strip_tags(_parsePost(_htmlStrUndo($art['perex']))), 250)."
</p>" : '')."
".($info ? "<div class='list-info'>
<span class='date'>".$my_date."</span>&nbsp;&nbsp;&nbsp;
<span class='categories'>".$cat."</span>&nbsp;&nbsp;&nbsp;
<span class='comments'><img class='icon' alt='comment' src='./plugins/templates/default/images/icons/comment.gif'></img>".(isset($comment_count) ? " komentářů {$comment_count}" : '')."</span>
</div>" : '')."
</div>
<div class='hr_line'></div>";

if (true===$_odd){
$_odd=false;
}else{
$_odd=true;
}

return $out;

}

_extend('reg', 'article.preview', function($args) {
$args['callback'] .='_plugin_articlePreview';
});
Zrovna jsem to řešil. Mám funkci (zaregistruj si třeba v ní, já ji registruji v soudružném souboru nad ní):
<?php
/* --- kontrola jadra --- */
if(!defined('_core')) {
exit;
}

// funkce
function _plugin_articles_formatTime($timestamp){

$days = array("","Pondělí","Úterý","Středa","Čtvrtek","Pátek","Sobota","Neděle");
$months = array("","ledna","února","března","dubna","května","června","července","srpna","září","října","listopadu","prosince");

$date = date('Y-m-d', $timestamp);
$today = date('Y-m-d');
$tomorrow = date('Y-m-d', strtotime('tomorrow'));
$day_after_tomorrow = date('Y-m-d', strtotime('tomorrow + 1 day'));

//clock
$hourminute=date('H:i',$timestamp);
$minute=date('j',$timestamp);

//yesterday
$startTime = mktime(0, 0, 0, date('m'), date('d')-1, date('Y'));
$endTime = mktime(23, 59, 59, date('m'), date('d')-1, date('Y'));

$ago = date("H:i",strtotime('-30 minutes',$timestamp));

//place out
if($timestamp > $startTime and $timestamp < $endTime){

//yesterday
$out="<span class='yesterday'>včera v {$hourminute}</span>";

}
elseif ($date == $today) {

//time is today?
//if($ago){

// $out="před 30 minutami";

//}else {

//tody long ago
$out="<span class='today'>dnes v {$hourminute}</span>";

//}

}else if ($date == $tomorrow) {

//time is tomorrow?
$out="<span class='tomorrow'>zítra</span>";

} else if ($date == $day_after_tomorrow) {

//time is after tomorrow?
$out="<span class='aftertomorrow'>pozítří</span>";

}else {

//oldest
$out=($days[date('N',$timestamp)].' '.date('j',$timestamp).'. '.$months[date('n',$timestamp)].' '.date('Y',$timestamp));

}

return $out;

}
Chtěl jsem tam v případě "dnes" dodělat i "před 3 / 5 / 10 / 15 / 30 minutami".
v overloadu articlePreview:
<div class='date'>"._plugin_articles_formatTime($art['time'])."</div>Jinak se dívám, že tam vypisuješ i kategorii, na to spíše použij script, co je v article.php v systému, taky ti můžu poslat upravený, vypadá to u mě asi takto:
img
Díky za další dožnosti jestli bych tě mohl poprosit s radou na ty kategorie uvítal bych to :-)
//dotaz
$article = DB::query_row("SELECT
a.id, a.title_seo, a.home1, a.home2, a.home3
FROM `"._mysql_prefix."-articles` a
WHERE a.id= ".DB::val($art['id']));

//zjistit v jakych je kategoriich
$categories="";
$homes = array();
for($i = 1; $i <= 3; ++$i) if ($article['home' . $i] != -1) $homes[] = $article['home' . $i];
$q = DB::query('SELECT id,title,title_seo,var3 FROM `' . _mysql_prefix . '-root` WHERE id IN(' . implode(',', $homes) . ')');

$homes = array();
$cat_showinfo = false;
while ($r = DB::row($q)) {
if ($r['id'] == $article['home1']) $homei = 1;
elseif ($r['id'] == $article['home2']) $homei = 2;
else $homei = 3;
$homes[$homei] = $r;
if ($r['var3'] == 1) $cat_showinfo = true;
}

for ($i = 1; $i <= 3; ++$i) {
if (!isset($homes[$i])) continue;
$homes[$i] = "<a href='" . _linkRoot($homes[$i]['id'], $homes[$i]['title_seo']) . "' class='list-category-link category-"._anchorStr($homes[$i]['title'])."'><span>" . $homes[$i]['title'] . "</span></a>";
}
$categories .= implode('', $homes);
unset($homes);

<div class='list-categories'>
{$categories}
</div>
Dík moc za ten kód, ale mám s tím problém :-( možná jsem to dal do špatné části pluginu
<?php
/* --- kontrola jadra --- */
if(!defined('_core')) {
exit;
}

$GLOBALS['_odd']=true;

// funkce
function _plugin_articlePreview($art, $info, $perex, $comment_count)
{
global $_odd;

$status=((true===$_odd)?"odd":"even");

$link = _linkArticle($art['id'], $art['title_seo']);

// uprava datumu na dnes, vcara
$my_date = date('d.m.Y', $art['time']); // formatuje i datum pouze na den,mesic, rok
$today = 'Dnes';
$yesterday = 'Včera';
if ($my_date == date('d.m.Y', strtotime("now"))) {
$my_date = '' . $today. '';
}
if ($my_date == date('d.m.Y', strtotime("1 day ago"))) {
$my_date = '' . $yesterday. '';
}

// kategorie
//dotaz
$article = DB::query_row("SELECT
a.id, a.title_seo, a.home1, a.home2, a.home3
FROM `"._mysql_prefix."-articles` a
WHERE a.id= ".DB::val($art['id']));

//zjistit v jakych je kategoriich
$categories="";
$homes = array();
for($i = 1; $i <= 3; ++$i) if ($article['home' . $i] != -1) $homes[] = $article['home' . $i];
$q = DB::query('SELECT id,title,title_seo,var3 FROM `' . _mysql_prefix . '-root` WHERE id IN(' . implode(',', $homes) . ')');

$homes = array();
$cat_showinfo = false;
while ($r = DB::row($q)) {
if ($r['id'] == $article['home1']) $homei = 1;
elseif ($r['id'] == $article['home2']) $homei = 2;
else $homei = 3;
$homes[$homei] = $r;
if ($r['var3'] == 1) $cat_showinfo = true;
}

for ($i = 1; $i <= 3; ++$i) {
if (!isset($homes)) continue;
$homes = "<a href='" . _linkRoot($homes['id'], $homes['title_seo']) . "' class='list-category-link category-"._anchorStr($homes['title'])."'><span>" . $homes['title'] . "</span></a>";
}
$categories .= implode('', $homes);
unset($homes);

$out = "
<div class='list-article num-{$status}'>
<div class='list-perex-media'>
".(($perex && isset($art['picture_uid'])) ? "<a href='{$link}'><img src='"._pictureStorageGet(_indexroot.'pictures/articles/', null, $art['picture_uid'], 'jpg')."' class='list-perex-image' alt='{$art['title']}' /></a>" : '')."
</div>
<h2 class='list-title'><a href='{$link}'>"._cutStr(_htmlStrUndo($art['title']), 70)."</a></h2>
".($perex ? "<p class='list-perex'>
"._cutStr(strip_tags(_parsePost(_htmlStrUndo($art['perex']))), 220)."
</p>" : '')."
".($info ? "<div class='list-info'>
<span class='date'>".$my_date."</span>&nbsp;&nbsp;&nbsp;
<span class='categorie'>{$categories}</span>&nbsp;&nbsp;&nbsp;
<span class='comments'><img class='icon' alt='comment' src='./plugins/templates/default/images/icons/comment.gif'></img>".(isset($comment_count) ? " komentářů {$comment_count}" : '')."</span>
</div>" : '')."
</div>
<div class='hr_line'></div>";

if (true===$_odd){
$_odd=false;
}else{
$_odd=true;
}

return $out;

}

_extend('reg', 'article.preview', function($args) {
$args['callback'] .='_plugin_articlePreview';
});
pořád to vypisuje
Notice: Undefined index: id in articlePreview.php on line 59
Notice: Undefined index: title in articlePreview.php on line 59
Notice: Undefined index: title_seo in articlePreview.php on line 59
Po radíč mi co dělám špatně? Dík
Jo ten 59 řádek je
$homes = "<a href='" . _linkRoot($homes['id'], $homes['title_seo']) . "' class='list-category-link category-"._anchorStr($homes['title'])."'><span>" . $homes['title'] . "</span></a>";
}
V další revizi to půjde udělat systémově přes extend plugin.
Strana: 1 2 další »