Skip to content
This repository was archived by the owner on Aug 14, 2023. It is now read-only.

Commit 9ac7c1d

Browse files
authored
Merge pull request #22 from aakb/feature/views_update
Feature/views update
2 parents 2808654 + 8d24afb commit 9ac7c1d

39 files changed

+15016
-4320
lines changed

sites/all/modules/contrib/read_time/LICENSE.txt

+339
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
name = Read time
2+
description = "Displays the time it will take to read content on your site."
3+
core = 7.x
4+
5+
6+
; Information added by Drupal.org packaging script on 2016-02-10
7+
version = "7.x-1.1"
8+
core = "7.x"
9+
project = "read_time"
10+
datestamp = "1455085760"
11+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
/**
3+
* @file
4+
* Install, update and uninstall functions for the Read Time module.
5+
*/
6+
7+
/**
8+
* Implements read_time_schema().
9+
*/
10+
function read_time_schema() {
11+
return array(
12+
'read_time' => array(
13+
'description' => 'The calculated read times of nodes.',
14+
'fields' => array(
15+
'nid' => array(
16+
'description' => 'The {node}.nid of the node.',
17+
'type' => 'int',
18+
'not null' => TRUE,
19+
'unsigned' => TRUE,
20+
),
21+
'read_time' => array(
22+
'description' => 'The calculated and formatted read time of the node.',
23+
'type' => 'varchar',
24+
'not null' => TRUE,
25+
'default' => '',
26+
'length' => 255,
27+
),
28+
),
29+
'primary key' => array('nid'),
30+
),
31+
);
32+
}
33+
34+
/**
35+
* Implements hook_uninstall().
36+
*/
37+
function read_time_uninstall() {
38+
foreach (node_type_get_names() as $bundle => $label) {
39+
variable_del('read_time_fields_' . $bundle);
40+
variable_del('read_time_wpm_' . $bundle);
41+
variable_del('read_time_format_' . $bundle);
42+
variable_del('read_time_display_' . $bundle);
43+
}
44+
}
45+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,228 @@
1+
<?php
2+
/**
3+
* @file
4+
* Displays the time it will take to read content on your site.
5+
*/
6+
7+
/**
8+
* Implements hook_form_FORM_ID_alter() for node_type_form.
9+
*/
10+
function read_time_form_node_type_form_alter(&$form, &$form_state, $form_id) {
11+
$type = $form['#node_type'];
12+
$defaults = read_time_defaults();
13+
14+
// Get text fields in this bundle.
15+
$field_instances = field_info_instances('node', $type->type);
16+
foreach ($field_instances as $field => $field_instance) {
17+
$field_info = field_info_field($field);
18+
if (in_array($field_info['type'], array('text', 'text_long', 'text_with_summary'))) {
19+
$fields[$field] = $field_instance['label'];
20+
}
21+
}
22+
23+
$form['read_time'] = array(
24+
'#type' => 'fieldset',
25+
'#title' => t('Read time'),
26+
'#group' => 'additional_settings',
27+
);
28+
$form['read_time']['read_time_fields'] = array(
29+
'#type' => 'checkboxes',
30+
'#title' => t('Fields'),
31+
'#description' => t('Calculate the combined read time of these fields.'),
32+
'#options' => $fields,
33+
'#multiple' => TRUE,
34+
'#default_value' => variable_get('read_time_fields_' . $type->type, $defaults['fields']),
35+
);
36+
$form['read_time']['read_time_wpm'] = array(
37+
'#type' => 'textfield',
38+
'#title' => t('Words per minute'),
39+
'#description' => t('Average reading speed used for the calculation.'),
40+
'#size' => 2,
41+
'#maxlength' => 3,
42+
'#element_validate' => array('element_validate_integer_positive'),
43+
'#default_value' => variable_get('read_time_wpm_' . $type->type, $defaults['wpm']),
44+
);
45+
$form['read_time']['read_time_format'] = array(
46+
'#type' => 'select',
47+
'#title' => t('Format'),
48+
'#description' => t('How the calculation will be formatted.'),
49+
'#options' => array(
50+
'hour_short' => t('Hours & minutes, short (1 hr, 5 mins)'),
51+
'hour_long' => t('Hours & minutes, long (1 hour, 5 minutes)'),
52+
'min_short' => t('Minutes, short (65 mins)'),
53+
'min_long' => t('Minutes, long (65 minutes)'),
54+
),
55+
'#default_value' => variable_get('read_time_format_' . $type->type, $defaults['format']),
56+
);
57+
$form['read_time']['read_time_display'] = array(
58+
'#type' => 'textfield',
59+
'#title' => t('Read time display'),
60+
'#description' => t("How the read time will be displayed. Use <em>%read_time</em> to output the read time formatted as above."),
61+
'#default_value' => variable_get('read_time_display_' . $type->type, $defaults['display']),
62+
);
63+
}
64+
65+
/**
66+
* Implements hook_field_extra_fields().
67+
*/
68+
function read_time_field_extra_fields() {
69+
foreach (field_info_bundles('node') as $bundle => $bundle_info) {
70+
$extra['node'][$bundle]['display'] = array(
71+
'read_time' => array(
72+
'label' => t('Read time'),
73+
'description' => t('Read time'),
74+
'weight' => 0,
75+
),
76+
);
77+
}
78+
79+
return $extra;
80+
}
81+
82+
/**
83+
* Implements hook_node_insert().
84+
*/
85+
function read_time_node_insert($node) {
86+
$read_time = read_time_calculate($node);
87+
88+
db_insert('read_time')
89+
->fields(array(
90+
'nid' => $node->nid,
91+
'read_time' => $read_time,
92+
))
93+
->execute();
94+
}
95+
96+
/**
97+
* Implements hook_node_update().
98+
*/
99+
function read_time_node_update($node) {
100+
$read_time = read_time_calculate($node);
101+
102+
db_merge('read_time')
103+
->key(array(
104+
'nid' => $node->nid,
105+
))
106+
->fields(array(
107+
'read_time' => $read_time,
108+
))
109+
->execute();
110+
}
111+
112+
/**
113+
* Implements hook_node_view().
114+
*/
115+
function read_time_node_view($node, $view_mode, $langcode) {
116+
// Get read time field settings.
117+
$display_settings = field_extra_fields_get_display('node', $node->type, $view_mode);
118+
$settings = $display_settings['read_time'];
119+
120+
if ($settings['visible']) {
121+
// Get read time from database.
122+
$read_time = db_query('SELECT read_time FROM {read_time} WHERE nid = :nid', array(
123+
':nid' => $node->nid,
124+
))->fetchField();
125+
126+
// Calculate read time if it doesn't exist and save to database.
127+
if (empty($read_time)) {
128+
$read_time = read_time_calculate($node);
129+
130+
db_merge('read_time')
131+
->key(array(
132+
'nid' => $node->nid,
133+
))
134+
->fields(array(
135+
'read_time' => $read_time,
136+
))
137+
->execute();
138+
}
139+
140+
// Display read time with node.
141+
$node->content['read_time'] = array(
142+
'#markup' => '<span class="read-time">' . $read_time . '</span>',
143+
'#weight' => $settings['weight'],
144+
);
145+
}
146+
}
147+
148+
/**
149+
* Implements hook_node_delete().
150+
*/
151+
function read_time_node_delete($node) {
152+
db_delete('read_time')
153+
->condition('nid', $node->nid)
154+
->execute();
155+
}
156+
157+
/**
158+
* Implements hook_node_type_delete().
159+
*/
160+
function read_time_node_type_delete($info) {
161+
variable_del('read_time_fields_' . $info->type);
162+
variable_del('read_time_wpm_' . $info->type);
163+
variable_del('read_time_format_' . $info->type);
164+
variable_del('read_time_display_' . $info->type);
165+
}
166+
167+
/**
168+
* Calculate read time.
169+
*/
170+
function read_time_calculate($node) {
171+
$defaults = read_time_defaults();
172+
173+
// Get read time bundle settings.
174+
$fields = variable_get('read_time_fields_' . $node->type, $defaults['fields']);
175+
$wpm = variable_get('read_time_wpm_' . $node->type, $defaults['wpm']);
176+
$format = variable_get('read_time_format_' . $node->type, $defaults['format']);
177+
$display = variable_get('read_time_display_' . $node->type, $defaults['display']);
178+
179+
// Get fields to calculate read time of.
180+
$field_words = '';
181+
foreach ($fields as $field) {
182+
$field_items = field_get_items('node', $node, $field);
183+
foreach ($field_items as $field_item) {
184+
$field_words .= strip_tags($field_item['value']);
185+
}
186+
}
187+
188+
// Calculate read time.
189+
$words = str_word_count($field_words);
190+
$time = $words / $wpm;
191+
192+
// Format read time.
193+
if (in_array($format, array('hour_short', 'hour_long'))) {
194+
$hours = floor($time / 60);
195+
$minutes = ceil(fmod($time, 60));
196+
} else {
197+
$minutes = ceil($time);
198+
}
199+
if (in_array($format, array('hour_long', 'min_long'))) {
200+
$hour_suffix = 'hour';
201+
$min_suffix = 'minute';
202+
} else {
203+
$hour_suffix = 'hr';
204+
$min_suffix = 'min';
205+
}
206+
$minute_format = format_plural($minutes, '1 ' . $min_suffix, '@count ' . $min_suffix . 's');
207+
if (!empty($hours)) {
208+
$hour_format = format_plural($hours, '1 ' . $hour_suffix, '@count ' . $hour_suffix . 's');
209+
$read_time = format_string('@h, @m', array('@h' => $hour_format, '@m' => $minute_format));
210+
} else {
211+
$read_time = $minute_format;
212+
}
213+
214+
return check_plain(str_replace('%read_time', $read_time, $display));
215+
}
216+
217+
/**
218+
* Store default settings.
219+
*/
220+
function read_time_defaults() {
221+
return array(
222+
'fields' => array('body'),
223+
'wpm' => '225',
224+
'format' => 'hour_short',
225+
'display' => t('Read time: %read_time'),
226+
);
227+
}
228+

sites/all/modules/itk/osto_contact/osto_contact.pages_default.inc

+2-2
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ function osto_contact_default_page_manager_pages() {
9393
$pane->access = array();
9494
$pane->configuration = array(
9595
'admin_title' => 'OS2 kontaktinformationer',
96-
'title' => 'Forretningsledelsen',
97-
'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>',
96+
'title' => 'Sekretariatet',
97+
'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>',
9898
'format' => 'full_html',
9999
'substitute' => TRUE,
100100
'title_heading' => 'h2',

0 commit comments

Comments
 (0)