You are here

gd_image_chart.module in Charts 6

@author Mads Peter Henderson http://drupal.org/user/421971

Use GD library to draw chart on your site

@note only hooks are here.

File

gd_image_chart/gd_image_chart.module
View source
<?php

/**
 * @author Mads Peter Henderson http://drupal.org/user/421971
 * @file
 * Use GD library to draw chart on your site
 *
 * @note only hooks are here.
 */

/**
 * Implementation of hook_perm().
 */
function gd_image_chart_perm() {
  return array(
    'administer GD chart',
  );
}

/**
 * Implementation of hook_menu().
 */
function gd_image_chart_menu() {
  $items['admin/settings/gd_image_charts'] = array(
    'access arguments' => array(
      'administer GD chart',
    ),
    'description' => 'Set the filepath to use for generated images and setup cleaning up',
    'file' => 'gd_image_chart.admin.inc',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      '_gd_image_chart_settings_page',
    ),
    'title' => 'GD Image chart',
  );
  return $items;
}

/**
 * Implementation of hook_charts_info().
 *
 * Its a Charts module hook. It defines almost all aspects
 * of a chart provider, like its name, what types of charts
 * it can perform and what are the restrictions.
 */
function gd_image_chart_charts_info() {
  return array(
    'gd_image_chart' => array(
      'file' => drupal_get_path('module', 'gd_image_chart') . '/gd_image_chart.inc',
      'name' => t('GD Image Chart'),
      'render' => '_gd_image_chart_charts_render',
      'types' => array(
        'vbar2D',
        'line2D',
      ),
    ),
  );
}

/**
 * Implementation of hook_cron().
 *
 * Delete the images created by this module after a certain time specified by the admin
 */
function gd_image_chart_cron() {
  if (variable_get('gd_image_chart_keep_files', '86400') > 0) {
    $path = file_directory_path() . "/" . variable_get('gd_image_chart_path', 'gd_image_chart');
    file_scan_directory($path, '\\.png$', array(
      '.',
      '..',
      'CVS',
    ), '_gd_image_chart_delete_old_images', TRUE);
  }
}

/**
 * Search and destroy images
 */
function _gd_image_chart_delete_old_images($file_name) {
  $now = time();
  $seconds_to_live = variable_get('gd_image_chart_keep_files', '86400');
  if (file_exists($file_name)) {
    if ($now - filemtime($file_name) > $seconds_to_live) {
      file_delete($file_name);
    }
  }
}

Functions

Namesort descending Description
gd_image_chart_charts_info Implementation of hook_charts_info().
gd_image_chart_cron Implementation of hook_cron().
gd_image_chart_menu Implementation of hook_menu().
gd_image_chart_perm Implementation of hook_perm().
_gd_image_chart_delete_old_images Search and destroy images