+
+
+function first_post_date($uid,$wall = false) {
+ $r = q("select id, created from item
+ where uid = %d and wall = %d and deleted = 0 and visible = 1 AND moderated = 0
+ and id = parent
+ order by created asc limit 1",
+ intval($uid),
+ intval($wall ? 1 : 0)
+ );
+ if(count($r)) {
+// logger('first_post_date: ' . $r[0]['id'] . ' ' . $r[0]['created'], LOGGER_DATA);
+ return substr(datetime_convert('',date_default_timezone_get(),$r[0]['created']),0,10);
+ }
+ return false;
+}
+
+function posted_dates($uid,$wall) {
+ $dnow = datetime_convert('',date_default_timezone_get(),'now','Y-m-d');
+
+ $dthen = first_post_date($uid,$wall);
+ if(! $dthen)
+ return array();
+
+ // If it's near the end of a long month, backup to the 28th so that in
+ // consecutive loops we'll always get a whole month difference.
+
+ if(intval(substr($dnow,8)) > 28)
+ $dnow = substr($dnow,0,8) . '28';
+ if(intval(substr($dthen,8)) > 28)
+ $dnow = substr($dthen,0,8) . '28';
+
+ $ret = array();
+ while($dnow >= $dthen) {
+ $start_month = datetime_convert('','','first day of ' . $dnow,'Y-m-d');
+ $end_month = datetime_convert('','','last day of ' . $dnow,'Y-m-d');
+ $str = day_translate(datetime_convert('','',$dnow,'F Y'));
+ $ret[] = array($str,$end_month,$start_month);
+ $dnow = datetime_convert('','',$dnow . ' -1 month', 'Y-m-d');
+ }
+ return $ret;
+}
+
+
+function posted_date_widget($url,$uid,$wall) {
+ $o = '';
+
+ // "first day of " constructs were added in php 5.3
+ // TODO: emulate posted_dates() logic for prior releases
+
+ if(version_compare(PHP_VERSION, '5.3.0') < 0)
+ return $o;
+
+ // For former Facebook folks that left because of "timeline"
+
+ if($wall && intval(get_pconfig($uid,'system','no_wall_archive_widget')))
+ return $o;
+
+ $ret = posted_dates($uid,$wall);
+ if(! count($ret))
+ return $o;
+
+ $o = replace_macros(get_markup_template('posted_date_widget.tpl'),array(
+ '$title' => t('Archives'),
+ '$size' => ((count($ret) > 6) ? 6 : count($ret)),
+ '$url' => $url,
+ '$dates' => $ret
+ ));
+ return $o;
+}
\ No newline at end of file