/**
  * Send digest and list subscriptions
  *
  * This sends mails to all subscribers that have a subscription for namespaces above
  * the given page if the needed $conf['subscribe_time'] has passed already.
  *
  * This function is called form lib/exe/indexer.php
  *
  * @param string $page
  * @return int number of sent mails
  */
 public function send_bulk($page)
 {
     if (!$this->isenabled()) {
         return 0;
     }
     /** @var auth_basic $auth */
     global $auth;
     global $conf;
     global $USERINFO;
     $count = 0;
     $subscriptions = $this->subscribers($page, null, array('digest', 'list'));
     // remember current user info
     $olduinfo = $USERINFO;
     $olduser = $_SERVER['REMOTE_USER'];
     foreach ($subscriptions as $target => $users) {
         if (!$this->lock($target)) {
             continue;
         }
         foreach ($users as $user => $info) {
             list($style, $lastupdate) = $info;
             $lastupdate = (int) $lastupdate;
             if ($lastupdate + $conf['subscribe_time'] > time()) {
                 // Less than the configured time period passed since last
                 // update.
                 continue;
             }
             // Work as the user to make sure ACLs apply correctly
             $USERINFO = $auth->getUserData($user);
             $_SERVER['REMOTE_USER'] = $user;
             if ($USERINFO === false) {
                 continue;
             }
             if (!$USERINFO['mail']) {
                 continue;
             }
             if (substr($target, -1, 1) === ':') {
                 // subscription target is a namespace, get all changes within
                 $changes = getRecentsSince($lastupdate, null, getNS($target));
             } else {
                 // single page subscription, check ACL ourselves
                 if (auth_quickaclcheck($target) < AUTH_READ) {
                     continue;
                 }
                 $meta = p_get_metadata($target);
                 $changes = array($meta['last_change']);
             }
             // Filter out pages only changed in small and own edits
             $change_ids = array();
             foreach ($changes as $rev) {
                 $n = 0;
                 while (!is_null($rev) && $rev['date'] >= $lastupdate && ($_SERVER['REMOTE_USER'] === $rev['user'] || $rev['type'] === DOKU_CHANGE_TYPE_MINOR_EDIT)) {
                     $rev = getRevisions($rev['id'], $n++, 1);
                     $rev = count($rev) > 0 ? $rev[0] : null;
                 }
                 if (!is_null($rev) && $rev['date'] >= $lastupdate) {
                     // Some change was not a minor one and not by myself
                     $change_ids[] = $rev['id'];
                 }
             }
             // send it
             if ($style === 'digest') {
                 foreach ($change_ids as $change_id) {
                     $this->send_digest($USERINFO['mail'], $change_id, $lastupdate);
                     $count++;
                 }
             } elseif ($style === 'list') {
                 $this->send_list($USERINFO['mail'], $change_ids, $target);
                 $count++;
             }
             // TODO: Handle duplicate subscriptions.
             // Update notification time.
             $this->add($target, $user, $style, time());
         }
         $this->unlock($target);
     }
     // restore current user info
     $USERINFO = $olduinfo;
     $_SERVER['REMOTE_USER'] = $olduser;
     return $count;
 }
示例#2
0
 /**
  * Returns a list of recent media changes since give timestamp
  *
  * @author Michael Hamann <*****@*****.**>
  * @author Michael Klier <*****@*****.**>
  */
 function getRecentMediaChanges($timestamp)
 {
     if (strlen($timestamp) != 10) {
         throw new RemoteException('The provided value is not a valid timestamp', 311);
     }
     $recents = getRecentsSince($timestamp, null, '', RECENTS_MEDIA_CHANGES);
     $changes = array();
     foreach ($recents as $recent) {
         $change = array();
         $change['name'] = $recent['id'];
         $change['lastModified'] = $this->api->toDate($recent['date']);
         $change['author'] = $recent['user'];
         $change['version'] = $recent['date'];
         $change['perms'] = $recent['perms'];
         $change['size'] = @filesize(mediaFN($recent['id']));
         array_push($changes, $change);
     }
     if (!empty($changes)) {
         return $changes;
     } else {
         // in case we still have nothing at this point
         throw new RemoteException('There are no changes in the specified timeframe', 321);
     }
 }
示例#3
0
/**
 * Send digest and list mails for all subscriptions which are in effect for the
 * current page
 *
 * @author Adrian Lang <*****@*****.**>
 */
function sendDigest()
{
    echo 'sendDigest(): started' . NL;
    global $ID;
    global $conf;
    if (!$conf['subscribers']) {
        echo 'sendDigest(): disabled' . NL;
        return false;
    }
    $subscriptions = subscription_find($ID, array('style' => '(digest|list)', 'escaped' => true));
    /** @var auth_basic $auth */
    global $auth;
    global $lang;
    global $conf;
    global $USERINFO;
    // remember current user info
    $olduinfo = $USERINFO;
    $olduser = $_SERVER['REMOTE_USER'];
    foreach ($subscriptions as $id => $users) {
        if (!subscription_lock($id)) {
            continue;
        }
        foreach ($users as $data) {
            list($user, $style, $lastupdate) = $data;
            $lastupdate = (int) $lastupdate;
            if ($lastupdate + $conf['subscribe_time'] > time()) {
                // Less than the configured time period passed since last
                // update.
                continue;
            }
            // Work as the user to make sure ACLs apply correctly
            $USERINFO = $auth->getUserData($user);
            $_SERVER['REMOTE_USER'] = $user;
            if ($USERINFO === false) {
                continue;
            }
            if (substr($id, -1, 1) === ':') {
                // The subscription target is a namespace
                $changes = getRecentsSince($lastupdate, null, getNS($id));
            } else {
                if (auth_quickaclcheck($id) < AUTH_READ) {
                    continue;
                }
                $meta = p_get_metadata($id);
                $changes = array($meta['last_change']);
            }
            // Filter out pages only changed in small and own edits
            $change_ids = array();
            foreach ($changes as $rev) {
                $n = 0;
                while (!is_null($rev) && $rev['date'] >= $lastupdate && ($_SERVER['REMOTE_USER'] === $rev['user'] || $rev['type'] === DOKU_CHANGE_TYPE_MINOR_EDIT)) {
                    $rev = getRevisions($rev['id'], $n++, 1);
                    $rev = count($rev) > 0 ? $rev[0] : null;
                }
                if (!is_null($rev) && $rev['date'] >= $lastupdate) {
                    // Some change was not a minor one and not by myself
                    $change_ids[] = $rev['id'];
                }
            }
            if ($style === 'digest') {
                foreach ($change_ids as $change_id) {
                    subscription_send_digest($USERINFO['mail'], $change_id, $lastupdate);
                }
            } elseif ($style === 'list') {
                subscription_send_list($USERINFO['mail'], $change_ids, $id);
            }
            // TODO: Handle duplicate subscriptions.
            // Update notification time.
            subscription_set($user, $id, $style, time(), true);
        }
        subscription_unlock($id);
    }
    // restore current user info
    $USERINFO = $olduinfo;
    $_SERVER['REMOTE_USER'] = $olduser;
    echo 'sendDigest(): finished' . NL;
    return true;
}
示例#4
0
 /**
  * Returns a list of recent media changes since give timestamp
  *
  * @author Michael Hamann <*****@*****.**>
  * @author Michael Klier <*****@*****.**>
  */
 function getRecentMediaChanges($timestamp)
 {
     if (strlen($timestamp) != 10) {
         return new IXR_Error(20, 'The provided value is not a valid timestamp');
     }
     require_once DOKU_INC . 'inc/changelog.php';
     require_once DOKU_INC . 'inc/pageutils.php';
     $recents = getRecentsSince($timestamp, null, '', RECENTS_MEDIA_CHANGES);
     $changes = array();
     foreach ($recents as $recent) {
         $change = array();
         $change['name'] = $recent['id'];
         $change['lastModified'] = new IXR_Date($recent['date']);
         $change['author'] = $recent['user'];
         $change['version'] = $recent['date'];
         $change['perms'] = $recent['perms'];
         $change['size'] = @filesize(wikiFN($recent['id']));
         array_push($changes, $change);
     }
     if (!empty($changes)) {
         return $changes;
     } else {
         // in case we still have nothing at this point
         return new IXR_Error(30, 'There are no changes in the specified timeframe');
     }
 }
示例#5
0
/**
 * Send digest and list mails for all subscriptions which are in effect for the
 * current page
 *
 * @author Adrian Lang <*****@*****.**>
 */
function sendDigest()
{
    echo 'sendDigest(): start' . NL;
    global $ID;
    global $conf;
    if (!$conf['subscribers']) {
        return;
    }
    $subscriptions = subscription_find($ID, array('style' => '(digest|list)', 'escaped' => true));
    global $auth;
    global $lang;
    global $conf;
    global $USERINFO;
    // remember current user info
    $olduinfo = $USERINFO;
    $olduser = $_SERVER['REMOTE_USER'];
    foreach ($subscriptions as $id => $users) {
        if (!subscription_lock($id)) {
            continue;
        }
        foreach ($users as $data) {
            list($user, $style, $lastupdate) = $data;
            $lastupdate = (int) $lastupdate;
            if ($lastupdate + $conf['subscribe_time'] > time()) {
                // Less than the configured time period passed since last
                // update.
                continue;
            }
            // Work as the user to make sure ACLs apply correctly
            $USERINFO = $auth->getUserData($user);
            $_SERVER['REMOTE_USER'] = $user;
            if ($USERINFO === false) {
                continue;
            }
            if (substr($id, -1, 1) === ':') {
                // The subscription target is a namespace
                $changes = getRecentsSince($lastupdate, null, getNS($id));
                if (count($changes) === 0) {
                    continue;
                }
                if ($style === 'digest') {
                    foreach ($changes as $change) {
                        subscription_send_digest($USERINFO['mail'], $change, $lastupdate);
                    }
                } elseif ($style === 'list') {
                    subscription_send_list($USERINFO['mail'], $changes, $id);
                }
                // TODO: Handle duplicate subscriptions.
            } else {
                if (auth_quickaclcheck($id) < AUTH_READ) {
                    continue;
                }
                $meta = p_get_metadata($id);
                $rev = $meta['last_change']['date'];
                if ($rev < $lastupdate) {
                    // There is no new revision.
                    continue;
                }
                subscription_send_digest($USERINFO['mail'], $meta['last_change'], $lastupdate);
            }
            // Update notification time.
            subscription_set($user, $id, $style, time(), true);
        }
        subscription_unlock($id);
    }
    // restore current user info
    $USERINFO = $olduinfo;
    $_SERVER['REMOTE_USER'] = $olduser;
}