View source
<?php
function hijri_block_info() {
$blocks['hijri'] = array(
'info' => t('Hijri Date Block'),
);
return $blocks;
}
function hijri_block_view($delta = '') {
$block = array();
switch ($delta) {
case 'hijri':
$block['subject'] = t('Hijri Date');
$block['content'] = _hijri_date_block();
break;
}
return $block;
}
function _hijri_date_block() {
$correction = variable_get('hijri_correction_value', 0);
$hijri_value = variable_get('hijri_display_block');
$format = hijri_format_date(time(), $hijri_value, NULL, $correction);
$content = theme('hijri_date', array(
'data' => $format,
));
return $content;
}
function hijri_theme($existing, $type, $theme, $path) {
$item = array();
$item = array(
'hijri_date' => array(
'variables' => array(
'data' => Null,
),
'template' => 'hijri-date',
'path' => drupal_get_path('module', 'hijri') . '/theme',
),
);
return $item;
}
function hijri_settings_form_submit($form, &$form_state) {
if (!field_info_field('field_hijri_correction')) {
$field = array(
'field_name' => 'field_hijri_correction',
'type' => 'number_integer',
);
field_create_field($field);
}
foreach ($form_state['values']['hijri_types'] as $key => $type) {
$instance = array(
'field_name' => 'field_hijri_correction',
'entity_type' => 'node',
'bundle' => $key,
'label' => t('Hijri Date Correction'),
'description' => t('This field will save the Correction and different between months'),
'required' => FALSE,
);
if ((string) $type == (string) $key) {
$prior_instance = field_read_instance($instance['entity_type'], $instance['field_name'], $instance['bundle']);
if (empty($prior_instance)) {
field_create_instance($instance);
}
}
else {
$prior_instance = field_read_instance($instance['entity_type'], $instance['field_name'], $instance['bundle']);
if (!empty($prior_instance)) {
field_delete_instance($instance, FALSE);
}
}
}
}
function hijri_node_presave($node) {
$node_types = variable_get('hijri_types', array());
foreach ($node_types as $type) {
if ($node->type == $type) {
$node->field_hijri_correction[$node->language][0]['value'] = variable_get('hijri_correction_value', 0);
}
}
}
function hijri_views_api() {
return array(
'api' => 3,
'path' => drupal_get_path('module', 'hijri') . '/views',
);
}
function hijri_node_view($node) {
unset($node->content['field_hijri_correction']);
}