+ // Poll contacts
+ cron_poll_contacts($argc, $argv);
+
+ logger('cron: end');
+
+ set_config('system','last_cron', time());
+
+ return;
+}
+
+/**
+ * @brief Update the cached values for the number of photo albums per user
+ */
+function cron_update_photo_albums() {
+ $r = q("SELECT `uid` FROM `user` WHERE NOT `account_expired` AND NOT `account_removed`");
+ if (!dbm::is_result($r)) {
+ return;
+ }
+
+ foreach ($r AS $user) {
+ photo_albums($user['uid'], true);
+ }
+}
+
+/**
+ * @brief Expire and remove user entries
+ */
+function cron_expire_and_remove_users() {
+ // expire any expired accounts
+ q("UPDATE user SET `account_expired` = 1 where `account_expired` = 0
+ AND `account_expires_on` != '0000-00-00 00:00:00'
+ AND `account_expires_on` < UTC_TIMESTAMP() ");
+
+ // delete user and contact records for recently removed accounts
+ $r = q("SELECT * FROM `user` WHERE `account_removed` AND `account_expires_on` < UTC_TIMESTAMP() - INTERVAL 3 DAY");
+ if ($r) {
+ foreach($r as $user) {
+ q("DELETE FROM `contact` WHERE `uid` = %d", intval($user['uid']));
+ q("DELETE FROM `user` WHERE `uid` = %d", intval($user['uid']));
+ }
+ }
+}
+
+/**
+ * @brief Poll contacts for unreceived messages
+ *
+ * @param Integer $argc Number of command line arguments
+ * @param Array $argv Array of command line arguments
+ */
+function cron_poll_contacts($argc, $argv) {