/** * Set subscription information * * Allows to set subscription informations for permanent storage in meta files. * Subscriptions consist of a target object, a subscribing user, a subscribe * style and optional data. * A subscription may be deleted by specifying an empty subscribe style. * Only one subscription per target and user is allowed. * The function returns false on error, otherwise true. Note that no error is * returned if a subscription should be deleted but the user is not subscribed * and the subscription meta file exists. * * @param string $user The subscriber or unsubscriber * @param string $page The target object (page or namespace), specified by * id; Namespaces are identified by a trailing colon. * @param string $style The subscribe style; DokuWiki currently implements * “every”, “digest”, and “list”. * @param string $data An optional data blob * @param bool $overwrite Whether an existing subscription may be overwritten * * @author Adrian Lang <*****@*****.**> */ function subscription_set($user, $page, $style, $data = null, $overwrite = false) { global $lang; if (is_null($style)) { // Delete subscription. $file = subscription_filename($page); if (!@file_exists($file)) { msg(sprintf($lang['subscr_not_subscribed'], $user, prettyprint_id($page)), -1); return false; } // io_deleteFromFile does not return false if no line matched. return io_deleteFromFile($file, subscription_regex(array('user' => $user)), true); } // Delete subscription if one exists and $overwrite is true. If $overwrite // is false, fail. $subs = subscription_find($page, array('user' => $user)); if (count($subs) > 0 && array_pop(array_keys($subs)) === $page) { if (!$overwrite) { msg(sprintf($lang['subscr_already_subscribed'], $user, prettyprint_id($page)), -1); return false; } // Fail if deletion failed, else continue. if (!subscription_set($user, $page, null)) { return false; } } $file = subscription_filename($page); $content = auth_nameencode($user) . ' ' . $style; if (!is_null($data)) { $content .= ' ' . $data; } return io_saveFile($file, $content . "\n", true); }
function test_delete() { $file = TMP_DIR . '/test.txt'; $contents = "The\nDelete\nDelete01\nDelete02\nDelete\nDeleteX\nTest\n"; io_saveFile($file, $contents); $this->assertTrue(io_deleteFromFile($file, "Delete\n")); $this->assertEquals("The\nDelete01\nDelete02\nDeleteX\nTest\n", io_readFile($file)); $this->assertTrue(io_deleteFromFile($file, "#Delete\\d+\n#", true)); $this->assertEquals("The\nDeleteX\nTest\n", io_readFile($file)); }
/** * Remove one or more users from the list of registered users * * @author Christopher Smith <*****@*****.**> * @param array $users array of users to be deleted * @return int the number of users deleted */ function deleteUsers($users) { global $config_cascade; if (!is_array($users) || empty($users)) { return 0; } if ($this->users === null) { $this->_loadUserData(); } $deleted = array(); foreach ($users as $user) { if (isset($this->users[$user])) { $deleted[] = preg_quote($user, '/'); } } if (empty($deleted)) { return 0; } $pattern = '/^(' . join('|', $deleted) . '):/'; if (io_deleteFromFile($config_cascade['plainauth.users']['default'], $pattern, true)) { foreach ($deleted as $user) { unset($this->users[$user]); } return count($deleted); } // problem deleting, reload the user list and count the difference $count = count($this->users); $this->_loadUserData(); $count -= count($this->users); return $count; }
/** * Removes a subscription for the given page or namespace * * This removes all subscriptions matching the given criteria on the given page or * namespace. It will *not* modify any subscriptions that may exist in higher * namespaces. * * @param string $id The target object’s (namespace or page) id * @param string|array $user * @param string|array $style * @param string|array $data * @return bool */ public function remove($id, $user = null, $style = null, $data = null) { if (!$this->isenabled()) { return false; } $file = $this->file($id); if (!file_exists($file)) { return true; } $re = $this->buildregex($user, $style, $data); return io_deleteFromFile($file, $re, true); }
/** * Handle namespace 'subscribe', 'unsubscribe' * */ function act_subscriptionns($act) { global $ID; global $INFO; global $lang; if (!getNS($ID)) { $file = metaFN(getNS($ID), '.mlist'); $ns = "root"; } else { $file = metaFN(getNS($ID), '/.mlist'); $ns = getNS($ID); } // reuse strings used to display the status of the subscribe action $act_msg = rtrim($act, 'ns'); if ($act == 'subscribens' && !$INFO['subscribedns']) { if ($INFO['userinfo']['mail']) { if (io_saveFile($file, $_SERVER['REMOTE_USER'] . "\n", true)) { $INFO['subscribedns'] = true; msg(sprintf($lang[$act_msg . '_success'], $INFO['userinfo']['name'], $ns), 1); } else { msg(sprintf($lang[$act_msg . '_error'], $INFO['userinfo']['name'], $ns), 1); } } else { msg($lang['subscribe_noaddress']); } } elseif ($act == 'unsubscribens' && $INFO['subscribedns']) { if (io_deleteFromFile($file, $_SERVER['REMOTE_USER'] . "\n")) { $INFO['subscribedns'] = false; msg(sprintf($lang[$act_msg . '_success'], $INFO['userinfo']['name'], $ns), 1); } else { msg(sprintf($lang[$act_msg . '_error'], $INFO['userinfo']['name'], $ns), 1); } } return 'show'; }
/** * remove acl-entry from conf/acl.auth.php * * @author Frank Schubert <*****@*****.**> */ function _acl_del($acl_scope, $acl_user) { global $config_cascade; $acl_user = auth_nameencode($acl_user, true); $acl_pattern = '^' . preg_quote($acl_scope, '/') . '[ \\t]+' . $acl_user . '[ \\t]+[0-8].*$'; return io_deleteFromFile($config_cascade['acl']['default'], "/{$acl_pattern}/", true); }
/** * Remove one or more users from the list of registered users * * @author Christopher Smith <*****@*****.**> * @param array $users array of users to be deleted * @return int the number of users deleted */ public function deleteUsers($users) { global $config_cascade; if (!is_array($users) || empty($users)) { return 0; } if ($this->users === null) { $this->_loadUserData(); } $deleted = array(); foreach ($users as $user) { // don't delete protected users if (!empty($this->users[$user]['protected'])) { msg(sprintf($this->getLang('protected'), hsc($user)), -1); continue; } if (isset($this->users[$user])) { $deleted[] = preg_quote($user, '/'); } } if (empty($deleted)) { return 0; } $pattern = '/^(' . join('|', $deleted) . '):/'; if (!io_deleteFromFile($config_cascade['plainauth.users']['default'], $pattern, true)) { msg($this->getLang('writefail'), -1); return 0; } // reload the user list and count the difference $count = count($this->users); $this->_loadUserData(); $count -= count($this->users); return $count; }