You are here

quote.module in Quote 7.2

Allows users to quote posts or comments.

File

quote.module
View source
<?php

/**
 * @file
 * Allows users to quote posts or comments.
 */

/**
 * Implements hook_help().
 */
function quote_help($path, $arg) {
  return '';
}

/**
 * Implements hook_permission().
 */
function quote_permission() {
  return [
    'administer quote' => [
      'title' => t('Administer Quote module'),
    ],
    'use quote' => [
      'title' => t('Use Quote module'),
    ],
  ];
}

/**
 * Implements hook_node_view().
 */
function quote_node_view($node, $view_mode) {
  if (user_access('post comments') && user_access('use quote') && in_array($node->type, array_filter(variable_get('quote_allow_types'))) && $node->comment == COMMENT_NODE_OPEN) {
    drupal_add_js(drupal_get_path('module', 'quote') . '/js/quote.js');
    drupal_add_js([
      'quote' => [
        'quote_selector' => variable_get('quote_selector', '#edit-comment-body textarea'),
        'quote_limit' => variable_get('quote_limit', '400'),
        'quote_selector_comment_quote_all' => variable_get('quote_selector_comment_quote_all', '.field-name-comment-body'),
        'quote_selector_node_quote_all' => variable_get('quote_selector_node_quote_all', '.field-name-body'),
        'quote_ckeditor_support' => variable_get('quote_ckeditor_support', 'FALSE'),
      ],
    ], [
      'type' => 'setting',
    ]);
    if (variable_get('quote_modes_quote_sel', TRUE)) {
      $links['node-quote-sel'] = [
        'title' => t('quote selected'),
        'href' => '#',
        'query' => '',
        'fragment' => '',
      ];
      $node->content['links']['comment']['#links']['node-quote-sel'] = $links['node-quote-sel'];
    }
    if (variable_get('quote_modes_quote_all', TRUE)) {
      $links['node-quote-all'] = [
        'title' => t('quote all'),
        'href' => '#',
        'query' => '',
        'fragment' => '',
      ];
      $node->content['links']['comment']['#links']['node-quote-all'] = $links['node-quote-all'];
    }

    /*$links['node-quote-all-reply'] = [
      'title' => t('reply and quote all'),
      'href' => "comment/reply/$node->nid/",
      'query' => ['node-quote-all-reply-nid' => $node->nid],
      'fragment' => ''
      ];
      $node->content['links']['comment']['#links']['node-quote-all-reply'] = $links['node-quote-all-reply'];*/
  }
}

/**
 * Implements hook_comment_view().
 */
function quote_comment_view($comment) {
  $node = node_load($comment->nid);
  if (user_access('post comments') && user_access('use quote') && in_array($node->type, array_filter(variable_get('quote_allow_types'))) && $node->comment == COMMENT_NODE_OPEN && variable_get('quote_allow_comments')) {
    drupal_add_js(drupal_get_path('module', 'quote') . '/js/quote.js');
    drupal_add_js([
      'quote' => [
        'quote_selector' => variable_get('quote_selector', '#edit-comment-body textarea'),
        'quote_limit' => variable_get('quote_limit', '400'),
        'quote_selector_comment_quote_all' => variable_get('quote_selector_comment_quote_all', '.field-name-comment-body'),
        'quote_selector_node_quote_all' => variable_get('quote_selector_node_quote_all', '.field-name-body'),
        'quote_ckeditor_support' => variable_get('quote_ckeditor_support', 'FALSE'),
      ],
    ], [
      'type' => 'setting',
    ]);
    if (variable_get('quote_modes_quote_sel', TRUE)) {
      $links['comment-quote-sel'] = [
        'title' => t('quote selected'),
        'href' => '#',
        'query' => '',
        'fragment' => '',
      ];
      $comment->content['links']['comment']['#links']['comment-quote-sel'] = $links['comment-quote-sel'];
    }
    if (variable_get('quote_modes_quote_all', TRUE)) {
      $links['comment-quote-all'] = [
        'title' => t('quote all'),
        'href' => '#',
        'query' => '',
        'fragment' => '',
      ];
      $comment->content['links']['comment']['#links']['comment-quote-all'] = $links['comment-quote-all'];
    }
    if (variable_get('quote_modes_quote_reply_all', TRUE)) {
      $links['comment-quote-all-reply'] = [
        'title' => t('reply and quote all'),
        'href' => "comment/reply/{$node->nid}/{$comment->cid}",
        'query' => [
          'comment-quote-all-reply' => $comment->cid,
        ],
        'fragment' => '',
      ];
      $comment->content['links']['comment']['#links']['comment-quote-all-reply'] = $links['comment-quote-all-reply'];
    }
  }
}

/**
 * Implements hook_form_alter().
 */
function quote_form_alter(&$form, &$form_state, $form_id) {

  /*if ($form['#id'] == 'comment-form' &&
    isset($_GET['node-quote-all-reply-nid'])) {
    $node = node_load($_GET['node-quote-all-reply-nid']);
    $user = user_load($node->uid);
    $language = $form['comment_body']['#language'];
    $form['comment_body'][$language][0]['#default_value'] =
    '<blockquote><strong>' . $user->name . ' wrote:</strong> ' .
    $node->body['und'][0]['value'] . '</blockquote>';
    }*/
  if ($form['#id'] == 'comment-form' && isset($_GET['comment-quote-all-reply'])) {
    $comment = comment_load($_GET['comment-quote-all-reply']);
    $user = user_load($comment->uid);
    $language = $form['comment_body']['#language'];
    $limit = variable_get('quote_limit', 400);
    $comment_limit = substr($comment->comment_body[LANGUAGE_NONE][0]['value'], 0, $limit);
    $form['comment_body'][$language][0]['#default_value'] = '<blockquote><strong>' . $user->name . ' wrote:</strong> ' . $comment_limit . '</blockquote><p><br/></p>';
  }
}

/**
 * Implements hook_menu().
 */
function quote_menu() {
  $items['admin/config/content/quote'] = [
    'title' => 'Quote',
    'description' => 'Global configuration of quote functionality.',
    'page callback' => 'drupal_get_form',
    'page arguments' => [
      '_quote_settings_form',
    ],
    'access arguments' => [
      'administer quote',
    ],
  ];
  return $items;
}

/**
 * Form settings.
 */
function _quote_settings_form() {
  $form = [];
  $form['modes'] = [
    '#type' => 'fieldset',
    '#title' => t('Select quote modes'),
  ];
  $form['modes']['quote_modes_quote_sel'] = [
    '#type' => 'checkbox',
    '#title' => t('Quote selected'),
    '#default_value' => variable_get('quote_modes_quote_sel', TRUE),
  ];
  $form['modes']['quote_modes_quote_all'] = [
    '#type' => 'checkbox',
    '#title' => t('Quote all'),
    '#default_value' => variable_get('quote_modes_quote_all', TRUE),
  ];
  $form['modes']['quote_modes_quote_reply_all'] = [
    '#type' => 'checkbox',
    '#title' => t('Quote and reply all'),
    '#default_value' => variable_get('quote_modes_quote_reply_all', TRUE),
  ];
  $form['modes']['quote_modes_quote_reply_sel'] = [
    '#type' => 'checkbox',
    '#title' => t('Quote and reply selected'),
    '#default_value' => variable_get('quote_modes_quote_reply_sel', FALSE),
    '#disabled' => TRUE,
  ];
  $types = node_type_get_types();
  $options = [];
  foreach ($types as $type => $info) {
    $options[$type] = $info->name;
  }
  $form['where'] = [
    '#type' => 'fieldset',
    '#title' => t('Allow quotes in the:'),
  ];
  $form['where']['quote_allow_types'] = [
    '#type' => 'checkboxes',
    '#title' => t('Content types'),
    '#options' => $options,
    '#default_value' => variable_get('quote_allow_types', []),
  ];
  $form['where']['quote_allow_comments'] = [
    '#type' => 'checkbox',
    '#title' => t('Comments'),
    '#description' => t('Checkbox works if node type allow quoting'),
    '#default_value' => variable_get('quote_allow_comments', TRUE),
  ];
  $form['ckeditor_support_set'] = [
    '#type' => 'fieldset',
    '#title' => t('CKEditor support'),
  ];
  $form['ckeditor_support_set']['quote_ckeditor_support'] = [
    '#type' => 'checkbox',
    '#title' => t('CKEditor support'),
    '#description' => t('If checkbox checked and CKEditor found on the page, CKEditor will have a priority'),
    '#default_value' => variable_get('quote_ckeditor_support', FALSE),
    '#disabled' => !module_exists('ckeditor'),
  ];
  $form['other'] = [
    '#type' => 'fieldset',
    '#title' => t('Other settings'),
  ];
  $form['other']['quote_selector'] = [
    '#type' => 'textfield',
    '#title' => t('CSS selector of your comment form textarea (where you write new comments)'),
    '#description' => t('By default it is: #edit-comment-body textarea'),
    '#default_value' => variable_get('quote_selector', '#edit-comment-body textarea'),
  ];
  $form['other']['quote_selector_comment_quote_all'] = [
    '#type' => 'textfield',
    '#title' => t('CSS selector of your comment body class (where you quote all)'),
    '#description' => t('By default it is: .field-name-comment-body'),
    '#default_value' => variable_get('quote_selector_comment_quote_all', '.field-name-comment-body'),
  ];
  $form['other']['quote_selector_node_quote_all'] = [
    '#type' => 'textfield',
    '#title' => t('CSS selector of your node body class (where you quote all)'),
    '#description' => t('By default it is: .field-name-body'),
    '#default_value' => variable_get('quote_selector_node_quote_all', '.field-name-body'),
  ];
  $form['other']['quote_limit'] = [
    '#type' => 'textfield',
    '#title' => t('Quote limit'),
    '#default_value' => variable_get('quote_limit', 400),
    '#attributes' => [
      ' type' => 'number',
    ],
  ];
  return system_settings_form($form);
}

Functions

Namesort descending Description
quote_comment_view Implements hook_comment_view().
quote_form_alter Implements hook_form_alter().
quote_help Implements hook_help().
quote_menu Implements hook_menu().
quote_node_view Implements hook_node_view().
quote_permission Implements hook_permission().
_quote_settings_form Form settings.