You are here

anonymous_publishing.module in Anonymous Publishing 8

Same filename and directory in other branches
  1. 5 anonymous_publishing.module
  2. 7 anonymous_publishing.module

Hooks for anonymous publishing parent module.

Common functions shared by more that one submodule in the project.

File

anonymous_publishing.module
View source
<?php

/**
 * @file
 * Hooks for anonymous publishing parent module.
 *
 * Common functions shared by more that one submodule in the project.
 */
use Drupal\Core\Link;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Url;

/**
 * Implements hook_help().
 */
function anonymous_publishing_help($route_name, RouteMatchInterface $route_match) {
  switch ($route_name) {
    case 'help.page.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 &mdash; some call this the &#8220;Craig's List model&#8221;.") . ' (';
      $output .= t('Enable') . ' <strong>' . t('Anonymous Publishing CL') . '</strong>.)</li>';
      $output .= '<li>' . t('Users who have previously published content without registering may later register and claim that content &mdash; sometimes called &#8220;lazy registration&#8221;.') . ' (';
      $output .= t('Enable') . ' <strong>' . t('Anonymous Publishing LR') . '</strong>.)</li>';
      $output .= '<li>' . 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>' . t('Anonymous Publishing PET') . '</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>");
      $output .= _anonymous_publishing_ah_hint();
      return $output;
  }
}

/**
 * Implements hook_cron().
 */

/*function anonymous_publishing_cron() {

  $cl_audodelhours = 999;
  $cl_period = $pet_period = -1;
  if (\Drupal::moduleHandler()->moduleExists('anonymous_publishing_cl')) {
    $cl_audodelhours = \Drupal::config('anonymous_publishing.settings')->get('autodelhours');
    // @FIXME
// Could not extract the default value because it is either indeterminate, or
// not scalar. You'll need to provide a default value in
// config/install/anonymous_publishing.settings.yml and config/schema/anonymous_publishing.schema.yml.
$cl_period = \Drupal::config('anonymous_publishing.settings')->get('retain_period');
  }
  if (\Drupal::moduleHandler()->moduleExists('anonymous_publishing_pet')) {
    // @FIXME
// Could not extract the default value because it is either indeterminate, or
// not scalar. You'll need to provide a default value in
// config/install/anonymous_publishing.settings.yml and config/schema/anonymous_publishing.schema.yml.
$pet_period = \Drupal::config('anonymous_publishing.settings')->get('anonymous_publishing_pet_period');
  }

  // Audeodelete not verified content.
  if ($cl_audodelhours < 999) {
    $limit = REQUEST_TIME - \Drupal::config('anonymous_publishing.settings')->get('autodelhours') * 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));

    while ($row = $result->fetchAssoc()) {
      db_delete('anonymous_publishing')
        ->condition('apid', $row['apid'])
        ->execute();
      $row['nid']->delete();
    }
    // 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()) {
      db_delete('anonymous_publishing')
        ->condition('apid', $row['apid'])
        ->execute();
      $row['cid']->delete();
    }
  }

  // Redact email 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 email 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();
      }
    }
  }
}*/

/**
 * Helper function to show hints about Advanced help.
 *
 * Code is commented out because it is buggy.
 */
function _anonymous_publishing_ah_hint() {

  /*
  $comdoc = Link::fromTextAndUrl(t('community documentation'), Url::fromUri('https://drupal.org/node/2024005'))->toRenderable();
  $comdoc = render($comdoc)->__tostring();
  if (\Drupal::moduleHandler()->moduleExists('advanced_help')) {
    $output = '<p>' . t("Additional help is available in the project's “!readme” file, and the !url.", array(
        '!readme' => Link::fromTextAndUrl(t('README'), Url::fromUri('/help/anonymous_publishing/README.md', array(
          'attributes' => array('title' => t('Link to README.md.'))
        ))),
        '!url' => $comdoc,
      )) . '</p>';
  }
  else {
    $ahlink = Link::fromTextAndUrl(t('Advanced help'), Url::fromUri('https://www.drupal.org/project/advanced_help'))->toRenderable();
    $output = '<p>' . t('Also see the !url. If you install the !module module, additional help will be available.', array(
        '!url' => $comdoc,
        '!module' => render($ahlink)->__tostring(),
      )) . '</p>';
  }
  */
  $output = '';
  return $output;
}

Functions

Namesort descending Description
anonymous_publishing_help Implements hook_help().
_anonymous_publishing_ah_hint Helper function to show hints about Advanced help.