You are here

ckeditor_readmore.module in CKEditor Read More 7

Same filename and directory in other branches
  1. 8 ckeditor_readmore.module
  2. 2.x ckeditor_readmore.module

Adds read more plugin to CKEditor.

File

ckeditor_readmore.module
View source
<?php

/**
 * @file
 * Adds read more plugin to CKEditor.
 */

/**
 * Implements hook_ckeditor_plugin().
 */
function ckeditor_readmore_ckeditor_plugin() {
  return array(
    'readmore' => array(
      'name' => 'readmore',
      'description' => t('Allows users to hide selected content and only show it on "Read more" button click'),
      'path' => drupal_get_path('module', 'ckeditor_readmore') . '/plugins/readmore/',
      'buttons' => array(
        'btn_readmore' => array(
          'icon' => 'icons/readmore.png',
          'label' => 'Read more',
        ),
      ),
    ),
  );
}

/**
 * Implements hook_wysiwyg_plugin().
 */
function ckeditor_readmore_wysiwyg_plugin($editor, $version) {
  $plugins = array();
  switch ($editor) {
    case 'ckeditor':
      $plugins['readmore'] = array(
        'title' => t('CKEditor readmore'),
        'description' => t('Allows users to hide selected content and only show it on "Read more" button click'),
        'path' => drupal_get_path('module', 'ckeditor_readmore') . '/plugins/readmore/',
        'load' => TRUE,
        'buttons' => array(
          'btn_readmore' => t('Read more'),
        ),
      );
      break;
  }
  return $plugins;
}

/**
 * Implements hook_help().
 */
function ckeditor_readmore_help($path, $arg) {
  switch ($path) {
    case 'admin/help#ckeditor_readmore':
      $filepath = dirname(__FILE__) . '/README.md';
      if (file_exists($filepath)) {
        $readme = file_get_contents($filepath);
      }
      else {
        $filepath = dirname(__FILE__) . '/README.txt';
        if (file_exists($filepath)) {
          $readme = file_get_contents($filepath);
        }
      }
      if (!isset($readme)) {
        return NULL;
      }
      if (module_exists('markdown')) {
        $filters = module_invoke('markdown', 'filter_info');
        $info = $filters['filter_markdown'];
        if (function_exists($info['process callback'])) {
          $output = $info['process callback']($readme, NULL);
        }
        else {
          $output = '<pre>' . $readme . '</pre>';
        }
      }
      else {
        $output = '<pre>' . $readme . '</pre>';
      }
      return $output;
  }
}