0x14D wrote:pitje wrote:here's my current desktop:

(finally changed my wallpaper....)
such a fancy time/calendar - at first I thought what the hell are those numbers 
would you mind sharing it?
sure, no problem 
the clock and calendar are made in php (so you need to have php5-cli installed)
Here's the php-script:
#!/usr/bin/php
<?php
/* // TEST
$year = 1989;
$month = 1;
$day = 12;
$hour = 18;
$min = 24;
/*/ // REAL
$year = date('Y');
$month = date('n');
$day = date('j');
$hour = date('H');
$min = date('i');
//*/
//var_dump($argv);
if (isset($argv[1]))
{
switch ($argv[1])
{
case 'simplecal':
case 'simplecalendar':
case 'simpledate':
echo simplecalendar($year, $month, $day);
break;
case 'cal':
case 'calendar':
case 'date':
echo calendar($year, $month, $day);
break;
case 'simpleclock':
case 'simpletime':
echo simpleclock($hour, $min);
break;
case 'verysimpleclock':
case 'verysimpletime':
echo verysimpleclock($hour, $min);
break;
case 'clock':
case 'time':
default:
echo clock($hour, $min);
break;
}
}
//* HERE BE FUNCTIONS !! *//
function calendar($year, $month, $day)
{
$nl = "\n";
$font = '${font Kates}';
$pref = '${alignr}';
$offset = ' ';
$_offset = '.';
$_pref = '${color1}';
$_suff = '${color}';
$daysinmonth= (int) date('t', mktime(0, 0, 0, $month, $day, $year));
$diff = abs($day - $month);
if ($day >= 12)
{
$startday = $diff < 0 ? $diff : 0;
$startmonth = $diff < 0 ? 0 : $diff;
}
else
{
$startday = $diff < 0 ? 0 : $diff;
$startmonth = $diff < 0 ? $diff : 0;
}
$endmonth = $startmonth + 12;
$endday = $startday + $daysinmonth;
$CURDATE = "{$_pref}{$year}{$_offset}" . f($month) . $_offset . f($day) . $_suff;
$M = 1;
$D = 1;
$OUT = $font;
for ($i = 1; $i < $daysinmonth + 12; $i++)
{
$OUT .= $pref;
if ($i > $startmonth && $i <= $endmonth)
{
if ($i == $month + $startmonth) $OUT .= $CURDATE;
else $OUT .= f($M) . $offset;
$M++;
}
else $OUT .= ' ' . $offset;
if ($i > $startday && $i <= $endday)
{
if ($i == $day + $startday) $OUT .= $nl;
else $OUT .= f($D) . $nl;
$D++;
}
else $OUT .= ' ' . $nl;
}
return $OUT;
}
function simplecalendar($year, $month, $day)
{
$nl = "\n";
$font = '${font Kates}';
$pref = '${alignr}';
$_pref = '${alignr}${color1}';
$suf = $nl;
$_suf = ' ${color}' . $nl;
$OUT = $font;
##Year
$OUT .= $_pref . $year . $suf;
$OUT .= $nl;
##Month
for ($m = 1; $m <= 12; $m++)
{
if ($m < 10) $m = "0$m";
$OUT .= ($m == $month) ? $_pref . $m . $_suf : $pref . $m . $suf;
}
$OUT .= $nl;
##Day
for ($d = 1, $x = date('t'); $d <= $x; $d++)
{
if ($d < 10) $d = "0$d";
$OUT .= ($d == $day) ? $_pref . $d . $_suf : $pref . $d . $suf;
}
#Output
return $OUT;
}
function clock($hour, $min)
{
$space = 0;
$_space = 2;
$font = '${voffset 10}${font Kates}';
$pref = '${offset ' . $space . '}';
$_pref = '${voffset -7}${offset ' . $_space . '}${color1}';
$suf = '';
$_suf = '${color}${voffset 7}${offset ' . $_space . '}';
$offset = $min - $hour;
if ($offset == 0)
{
$minspaces = '';
$hourspaces = '';
}
elseif ($offset < 0)
{
$minspaces = str_repeat(" $pref", abs($offset));
$hourspaces = '';
}
else
{
$minspaces = '';
$hourspaces = str_repeat(" $pref", abs($offset));
}
$hr = $hourspaces;
for ($h = 0; $h < 24; $h++) $hr .= ($h == $hour) ? $_pref . f($h) . $_suf : $pref . f($h) . $suf;
$mr = $minspaces;
for ($m = 0; $m < 60; $m++) $mr .= ($m == $min) ? $_pref . f($m) . $_suf : $pref . f($m) . $suf;
$OUT = $font . $hr . "\n" . '' . $mr;
return $OUT;
}
function simpleclock($hour, $min)
{
$font = "\n" . '${font Kates}';
$pref = '${offset 1}';
$_pref = '${voffset -7}${offset 1}${color1}';
$suf = '';
$_suf = '${color}${voffset 7}';
$OUT = $font;
for ($h = 0; $h < 24; $h++) $OUT .= ($h == $hour) ? $_pref . f($h) . $_suf : $pref . f($h) . $suf;
$OUT .= ' ';
for ($m = 0; $m < 60; $m++) $OUT .= ($m == $min) ? $_pref . f($m) . $_suf : $pref . f($m) . $suf;
#Output
return $OUT;
}
function verysimpleclock($hour, $min) { return '${voffset -30}${font Arial Black:size=60}' . f($hour) . ':' . f($min) . '${font}${voffset -45}'; }
function f($v) { return ($v < 10 ? "0$v" : $v); }
The above script contains 4 clocktypes, and 2 calendartypes.
You can use them in your conky like this:
${execp /full/path/to/the/php/file clock}
The argument you're using (in the above code the argument is 'clock') defines what sort of clock/calendar you're using.
You can choose between
calendar (you can also use cal, or date)
simplecal (you can also use simplecalendar, or simpledate)
clock (you can also use clock, or time)
simpleclock (you can also use simpletime)
verysimpleclock (you can also use verysimpletime)
To make the numbers line up correctly, you should use a monospaced font. I use Kates, from the artwiz font pack
I've had problems with the calendar-code, the days and months not lining up, but I believe I've fixed it 
laptop: asus zenbook UX31 [debian wheezy, kernel 3.3.0-rc7-custom]
tablet: acer iconia a500 [honeycomb]
home: C2D E8500, 4GB RAM, 74GB Raptor HDD + 2.5TB in various HDD [debian squeeze, liquorix kernel]