Skip to content
This repository was archived by the owner on Aug 14, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
339 changes: 339 additions & 0 deletions sites/all/modules/contrib/read_time/LICENSE.txt

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions sites/all/modules/contrib/read_time/read_time.info
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name = Read time
description = "Displays the time it will take to read content on your site."
core = 7.x


; Information added by Drupal.org packaging script on 2016-02-10
version = "7.x-1.1"
core = "7.x"
project = "read_time"
datestamp = "1455085760"

45 changes: 45 additions & 0 deletions sites/all/modules/contrib/read_time/read_time.install
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php
/**
* @file
* Install, update and uninstall functions for the Read Time module.
*/

/**
* Implements read_time_schema().
*/
function read_time_schema() {
return array(
'read_time' => array(
'description' => 'The calculated read times of nodes.',
'fields' => array(
'nid' => array(
'description' => 'The {node}.nid of the node.',
'type' => 'int',
'not null' => TRUE,
'unsigned' => TRUE,
),
'read_time' => array(
'description' => 'The calculated and formatted read time of the node.',
'type' => 'varchar',
'not null' => TRUE,
'default' => '',
'length' => 255,
),
),
'primary key' => array('nid'),
),
);
}

/**
* Implements hook_uninstall().
*/
function read_time_uninstall() {
foreach (node_type_get_names() as $bundle => $label) {
variable_del('read_time_fields_' . $bundle);
variable_del('read_time_wpm_' . $bundle);
variable_del('read_time_format_' . $bundle);
variable_del('read_time_display_' . $bundle);
}
}

228 changes: 228 additions & 0 deletions sites/all/modules/contrib/read_time/read_time.module
Original file line number Diff line number Diff line change
@@ -0,0 +1,228 @@
<?php
/**
* @file
* Displays the time it will take to read content on your site.
*/

/**
* Implements hook_form_FORM_ID_alter() for node_type_form.
*/
function read_time_form_node_type_form_alter(&$form, &$form_state, $form_id) {
$type = $form['#node_type'];
$defaults = read_time_defaults();

// Get text fields in this bundle.
$field_instances = field_info_instances('node', $type->type);
foreach ($field_instances as $field => $field_instance) {
$field_info = field_info_field($field);
if (in_array($field_info['type'], array('text', 'text_long', 'text_with_summary'))) {
$fields[$field] = $field_instance['label'];
}
}

$form['read_time'] = array(
'#type' => 'fieldset',
'#title' => t('Read time'),
'#group' => 'additional_settings',
);
$form['read_time']['read_time_fields'] = array(
'#type' => 'checkboxes',
'#title' => t('Fields'),
'#description' => t('Calculate the combined read time of these fields.'),
'#options' => $fields,
'#multiple' => TRUE,
'#default_value' => variable_get('read_time_fields_' . $type->type, $defaults['fields']),
);
$form['read_time']['read_time_wpm'] = array(
'#type' => 'textfield',
'#title' => t('Words per minute'),
'#description' => t('Average reading speed used for the calculation.'),
'#size' => 2,
'#maxlength' => 3,
'#element_validate' => array('element_validate_integer_positive'),
'#default_value' => variable_get('read_time_wpm_' . $type->type, $defaults['wpm']),
);
$form['read_time']['read_time_format'] = array(
'#type' => 'select',
'#title' => t('Format'),
'#description' => t('How the calculation will be formatted.'),
'#options' => array(
'hour_short' => t('Hours & minutes, short (1 hr, 5 mins)'),
'hour_long' => t('Hours & minutes, long (1 hour, 5 minutes)'),
'min_short' => t('Minutes, short (65 mins)'),
'min_long' => t('Minutes, long (65 minutes)'),
),
'#default_value' => variable_get('read_time_format_' . $type->type, $defaults['format']),
);
$form['read_time']['read_time_display'] = array(
'#type' => 'textfield',
'#title' => t('Read time display'),
'#description' => t("How the read time will be displayed. Use <em>%read_time</em> to output the read time formatted as above."),
'#default_value' => variable_get('read_time_display_' . $type->type, $defaults['display']),
);
}

/**
* Implements hook_field_extra_fields().
*/
function read_time_field_extra_fields() {
foreach (field_info_bundles('node') as $bundle => $bundle_info) {
$extra['node'][$bundle]['display'] = array(
'read_time' => array(
'label' => t('Read time'),
'description' => t('Read time'),
'weight' => 0,
),
);
}

return $extra;
}

/**
* Implements hook_node_insert().
*/
function read_time_node_insert($node) {
$read_time = read_time_calculate($node);

db_insert('read_time')
->fields(array(
'nid' => $node->nid,
'read_time' => $read_time,
))
->execute();
}

/**
* Implements hook_node_update().
*/
function read_time_node_update($node) {
$read_time = read_time_calculate($node);

db_merge('read_time')
->key(array(
'nid' => $node->nid,
))
->fields(array(
'read_time' => $read_time,
))
->execute();
}

/**
* Implements hook_node_view().
*/
function read_time_node_view($node, $view_mode, $langcode) {
// Get read time field settings.
$display_settings = field_extra_fields_get_display('node', $node->type, $view_mode);
$settings = $display_settings['read_time'];

if ($settings['visible']) {
// Get read time from database.
$read_time = db_query('SELECT read_time FROM {read_time} WHERE nid = :nid', array(
':nid' => $node->nid,
))->fetchField();

// Calculate read time if it doesn't exist and save to database.
if (empty($read_time)) {
$read_time = read_time_calculate($node);

db_merge('read_time')
->key(array(
'nid' => $node->nid,
))
->fields(array(
'read_time' => $read_time,
))
->execute();
}

// Display read time with node.
$node->content['read_time'] = array(
'#markup' => '<span class="read-time">' . $read_time . '</span>',
'#weight' => $settings['weight'],
);
}
}

/**
* Implements hook_node_delete().
*/
function read_time_node_delete($node) {
db_delete('read_time')
->condition('nid', $node->nid)
->execute();
}

/**
* Implements hook_node_type_delete().
*/
function read_time_node_type_delete($info) {
variable_del('read_time_fields_' . $info->type);
variable_del('read_time_wpm_' . $info->type);
variable_del('read_time_format_' . $info->type);
variable_del('read_time_display_' . $info->type);
}

/**
* Calculate read time.
*/
function read_time_calculate($node) {
$defaults = read_time_defaults();

// Get read time bundle settings.
$fields = variable_get('read_time_fields_' . $node->type, $defaults['fields']);
$wpm = variable_get('read_time_wpm_' . $node->type, $defaults['wpm']);
$format = variable_get('read_time_format_' . $node->type, $defaults['format']);
$display = variable_get('read_time_display_' . $node->type, $defaults['display']);

// Get fields to calculate read time of.
$field_words = '';
foreach ($fields as $field) {
$field_items = field_get_items('node', $node, $field);
foreach ($field_items as $field_item) {
$field_words .= strip_tags($field_item['value']);
}
}

// Calculate read time.
$words = str_word_count($field_words);
$time = $words / $wpm;

// Format read time.
if (in_array($format, array('hour_short', 'hour_long'))) {
$hours = floor($time / 60);
$minutes = ceil(fmod($time, 60));
} else {
$minutes = ceil($time);
}
if (in_array($format, array('hour_long', 'min_long'))) {
$hour_suffix = 'hour';
$min_suffix = 'minute';
} else {
$hour_suffix = 'hr';
$min_suffix = 'min';
}
$minute_format = format_plural($minutes, '1 ' . $min_suffix, '@count ' . $min_suffix . 's');
if (!empty($hours)) {
$hour_format = format_plural($hours, '1 ' . $hour_suffix, '@count ' . $hour_suffix . 's');
$read_time = format_string('@h, @m', array('@h' => $hour_format, '@m' => $minute_format));
} else {
$read_time = $minute_format;
}

return check_plain(str_replace('%read_time', $read_time, $display));
}

/**
* Store default settings.
*/
function read_time_defaults() {
return array(
'fields' => array('body'),
'wpm' => '225',
'format' => 'hour_short',
'display' => t('Read time: %read_time'),
);
}

Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ function osto_contact_default_page_manager_pages() {
$pane->access = array();
$pane->configuration = array(
'admin_title' => 'OS2 kontaktinformationer',
'title' => 'Forretningsledelsen',
'body' => '<div style="line-height:1.5em"><p>Du er også velkommen til at kontakte OS2s forretningsleder direkte. Eller sende os et brev, det er så hyggeligt.</p><p>&nbsp;</p><p>Rasmus Frey<br />Forretningsleder<br />Email: [email protected]<br />Telefon: +45 31154525</p><p>&nbsp;</p><p>OS2 - Offentligt digitaliseringsfællesskab<br />c/o Aarhus Kommune<br />Dokk1<br />Hack Kampmanns Plads 2<br />8000 Aarhus C<br />CVR: 55133018</p><p>&nbsp;</p><p>Email: [email protected]</p></div>',
'title' => 'Sekretariatet',
'body' => '<div style="line-height:1.5em"><p>Du er også velkommen til at kontakte OS2s sekretariat direkte. Eller sende os et brev, det er så hyggeligt.</p><p>&nbsp;</p><p>Rasmus Frey<br>Sekretariatschef<br>Email: [email protected]<br>Mobil: +45 3115 4525</p><p>&nbsp;</p><p>Terese Svinth Lorentzen<br>Kommunikations- og koordinationsmedarbejder<br>Email: [email protected]<br>Mobil: +45 25 39 91 85</p><p>&nbsp;</p><p>OS2 - Offentligt digitaliseringsfællesskab<br>c/o Aarhus Kommune<br>Dokk1<br>Hack Kampmanns Plads 2<br>8000 Aarhus C<br>CVR: 55133018</p><p>&nbsp;</p><p>Email: [email protected]<br>Kontor: +45 2920 8427</p></div>',
'format' => 'full_html',
'substitute' => TRUE,
'title_heading' => 'h2',
Expand Down
Loading