anonymous_publishing.module in Anonymous Publishing 7
Same filename and directory in other branches
Hooks for the Anonymous Publishing parent module.
Common functions shared by more that one submodule in the project.
File
anonymous_publishing.moduleView source
<?php
/**
* @file
* Hooks for the Anonymous Publishing parent module.
*
* Common functions shared by more that one submodule in the project.
*/
/**
* Implements hook_help().
*/
function anonymous_publishing_help($path, $arg) {
switch ($path) {
case 'admin/help#anonymous_publishing':
$output = '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t("The modules in this project is used to mange anonymous publishing on your site. This is the project's parent module. By itself does nothing. You need to enable at least one of the submodules listed below to be able to use the feature's of this project.") . '</p>';
$output .= '<p>' . t('The major features of <strong>Anonymous Publishing</strong> project are:') . '</p><ol>';
$output .= '<li>' . t("Users may publish content without first registering an account at the site, but in a manner that affords some protection against spam — some call this the “Craig's List model”.") . ' ';
$output .= t('(Enable <strong>Anonymous Publishing CL</strong>.)</li><li>');
$output .= t('Users who have previously published content without registering may later register and claim that content — sometimes called “lazy registration”.') . ' ';
$output .= t('(Enable <strong>Anonymous Publishing LR</strong>.)</li><li>');
$output .= t('Authenticated users may publish content as an anonymous user. This is to provide privacy when authenticated users post about sensitive issues.') . ' ';
$output .= t('(Enable <strong>Anonymous Publishing PET</strong>.)</li><li>');
$output .= t('Site builders may use <strong>Views</strong> to create guestbooks and similar pages where anonymous publishers may post.') . ' ';
$output .= t('(Enable <strong>Anonymous Publishing Views</strong>.)</li></ol>');
$output .= t("<p>There is no module configuration page for the parent module. You may want to configure module permissions (permissions are shared by all the project's modules).</p>");
if (module_exists('advanced_help_hint')) {
$output .= advanced_help_hint_docs('anonymous_publishing', 'https://www.drupal.org/docs/7/modules/anonymous-publishing', TRUE);
}
else {
$output .= t('<p>Install and enable <a href="https://www.drupal.org/project/advanced_help_hint"><strong>Advanced Help Hint</strong></a> to get links to more help here.</p>');
}
return $output;
}
}
/**
* Implements hook_permission().
*/
function anonymous_publishing_permission() {
return array(
'administer anonymous_publishing' => array(
'title' => t('administer anonymous publishing'),
'description' => t('Administer the Anonymous Publishing module'),
),
);
}
/**
* Implements hook_cron().
*/
function anonymous_publishing_cron() {
$cl_audodelhours = -1;
$cl_period = $pet_period = -1;
if (module_exists('anonymous_publishing_cl')) {
$cl_audodelhours = variable_get('anonymous_publishing_cl_autodelhours', -1);
$cl_period = variable_get('anonymous_publishing_cl_period', -1);
}
if (module_exists('anonymous_publishing_pet')) {
$pet_period = variable_get('anonymous_publishing_pet_period', -1);
}
// Audeodelete not verified content.
if ($cl_audodelhours >= 0) {
$limit = REQUEST_TIME - $cl_audodelhours * 3600;
// Fetch all nodes that has not been verified older than limit.
$sql = "SELECT a.apid, n.nid, created FROM {anonymous_publishing} a JOIN {node} n ON a.nid = n.nid WHERE a.verified = 0 AND n.created < :limit AND a.cid = 0 ORDER BY a.nid ASC";
$result = db_query($sql, array(
':limit' => $limit,
));
$stats = variable_get('anonymous_publishing_cl_stats', array(
'start' => REQUEST_TIME,
'smart' => 0,
'stupid' => 0,
));
$bots = 0;
while ($row = $result
->fetchAssoc()) {
$bots++;
db_delete('anonymous_publishing')
->condition('apid', $row['apid'])
->execute();
node_delete($row['nid']);
}
// Fetch all comments that has not been verified older than limit.
$sql = "SELECT a.apid, c.cid, c.created FROM {anonymous_publishing} a JOIN {comment} c ON a.cid = c.cid WHERE a.verified = 0 AND c.created < :limit AND a.cid <> 0 ORDER BY a.cid ASC";
$result = db_query($sql, array(
':limit' => $limit,
));
while ($row = $result
->fetchAssoc()) {
$bots++;
db_delete('anonymous_publishing')
->condition('apid', $row['apid'])
->execute();
comment_delete($row['cid']);
}
if ($bots) {
$stats['smart'] += $bots;
variable_set('anonymous_publishing_cl_stats', $stats);
}
}
// Redact e-mail and IP address.
if ($cl_period > -1) {
$rows = db_query("SELECT apid, nid, cid FROM {anonymous_publishing}")
->fetchAll(PDO::FETCH_ASSOC);
foreach ($rows as $row) {
if ($row['cid']) {
$created = db_query("SELECT created FROM {comment} WHERE :cid = cid", array(
':cid' => $row['cid'],
))
->fetchField();
}
else {
$created = db_query("SELECT created FROM {node} WHERE :nid = nid", array(
':nid' => $row['nid'],
))
->fetchField();
}
$age = REQUEST_TIME - $created;
if ($age > $cl_period) {
db_delete('anonymous_publishing')
->condition('apid', $row['apid'])
->condition('verified', 1)
->execute();
db_update('anonymous_publishing')
->condition('apid', $row['apid'])
->fields(array(
'ip' => '',
))
->execute();
}
}
}
// Redact e-mail and real name.
if ($pet_period > -1) {
$rows = db_query("SELECT rnid, nid, cid FROM {anonymous_publishing_realname}")
->fetchAll(PDO::FETCH_ASSOC);
foreach ($rows as $row) {
if ($row['cid']) {
$created = db_query("SELECT created FROM {comment} WHERE :cid = cid", array(
':cid' => $row['cid'],
))
->fetchField();
}
else {
$created = db_query("SELECT created FROM {node} WHERE :nid = nid", array(
':nid' => $row['nid'],
))
->fetchField();
}
$age = REQUEST_TIME - $created;
if ($age > $pet_period) {
db_delete('anonymous_publishing_realname')
->condition('rnid', $row['rnid'])
->execute();
}
}
}
}
Functions
Name | Description |
---|---|
anonymous_publishing_cron | Implements hook_cron(). |
anonymous_publishing_help | Implements hook_help(). |
anonymous_publishing_permission | Implements hook_permission(). |