You are here

scrolltext.module in ScrollText 5

Same filename and directory in other branches
  1. 6 scrolltext.module
  2. 7 scrolltext.module

This module used for scrolling text from node title

File

scrolltext.module
View source
<?php

/**
 * @file
 * This module used for scrolling text from node title
 */

/**
 * Implementation of hook_help().
 */
function scrolltext_help($section) {
  switch ($section) {
    case 'admin/help#scrolltext':
    case 'admin/modules#description':
      return "This module used for scrolling text from node title.";
  }
}

/**
 * Implementation of hook_perm
 */
function scrolltext_perm() {
  return array(
    'access scrolltext',
    'administer scrolltext',
  );
}

/**
 * Menu callback. Prints a listing of active nodes on the site.
 */
function scrolltext_menu($may_cache) {
  $items = array();
  $items[] = array(
    'path' => 'admin/settings/scrolltext',
    'title' => t('ScrollText'),
    'callback' => 'drupal_get_form',
    'callback arguments' => array(
      'scrolltext_settings_form',
    ),
    'access' => user_access('administer scrolltext'),
    'description' => t("ScrollText settings"),
  );
  return $items;
}
function scrolltext_settings_form() {
  $form['scrolltext_general'] = array(
    '#type' => 'fieldset',
    '#title' => t('General settings'),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
    '#description' => t('Remember to enable the ScrollText on Drupal !blocks . CSS id is "scrollttext" to theming ScrollText.', array(
      '!blocks' => l('blocks', 'admin/build/block'),
    )),
  );
  $form['scrolltext_general']['scrolltext_speed'] = array(
    '#type' => 'textfield',
    '#title' => t('Scroll Speed'),
    '#default_value' => variable_get('scrolltext_speed', '1'),
  );
  $form['scrolltext_general']['scrolltext_width'] = array(
    '#type' => 'textfield',
    '#title' => t('Scroll Width'),
    '#default_value' => variable_get('scrolltext_width', '100%'),
  );
  $form['scrolltext_general']['scrolltext_height'] = array(
    '#type' => 'textfield',
    '#title' => t('Scroll Height'),
    '#default_value' => variable_get('scrolltext_height', '100'),
  );
  $form['scrolltext_general']['scrolltext_nodetype'] = array(
    '#type' => 'textfield',
    '#title' => t('Node Type'),
    '#default_value' => variable_get('scrolltext_nodetype', 'page,story'),
    '#description' => t('<p>Get title from certain node type, i.e: page,story</p>'),
  );
  $form['scrolltext_general']['scrolltext_count'] = array(
    '#type' => 'textfield',
    '#title' => t('Title Count'),
    '#default_value' => variable_get('scrolltext_count', '10'),
    '#description' => t('<p>How many new title would you like to scrol? NOTE: greater number will cause you website slowly!</p>'),
  );
  return system_settings_form($form);
}

/**
 * Implementation of hook_block().
 *
 */
function scrolltext_block($op = 'list', $delta = 0) {
  global $user;
  if ($op == 'list') {
    $blocks[0]['info'] = 'ScrollText';
    return $blocks;
  }
  if ($op == 'view') {
    switch ($delta) {
      case 0:
        $block['subject'] = t('<none>');
        $block['content'] = '';
        $scrolltext_speed = variable_get('scrolltext_speed', '1');
        $scrolltext_width = variable_get('scrolltext_width', '100%');
        $scrolltext_height = variable_get('scrolltext_height', '100');
        $scrolltext_nodetype = variable_get('scrolltext_nodetype', 'page,story');
        $scrolltext_count = variable_get('scrolltext_count', '10');
        $sql = "SELECT n.title FROM {node} n ORDER BY n.created DESC LIMIT {$scrolltext_count}";
        $results = db_query($sql);
        $block['content'] = '<div id="scrolltext"><marquee>';
        while ($data = db_fetch_object($results)) {
          $block['content'] .= l("{$data->title}", "node/{$data->nid}") . str_repeat('&nbsp', 5);
        }
        $block['content'] .= '</marquee></div>';
        break;
    }
    return $block;
  }
}

Functions

Namesort descending Description
scrolltext_block Implementation of hook_block().
scrolltext_help Implementation of hook_help().
scrolltext_menu Menu callback. Prints a listing of active nodes on the site.
scrolltext_perm Implementation of hook_perm
scrolltext_settings_form