-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimage_insert_codes.module
More file actions
150 lines (130 loc) · 4.27 KB
/
image_insert_codes.module
File metadata and controls
150 lines (130 loc) · 4.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
<?php
/**
* Implements hook_menu().
*/
function image_insert_codes_menu() {
$items = array();
$items['admin/config/user-interface/image-insert-codes'] = array(
'title' => 'Image Insert Codes',
'page callback' => 'drupal_get_form',
'page arguments' => array('image_insert_codes_admin_settings'),
'access arguments' => array('administer site configuration'),
'file' => 'image_insert_codes.admin.inc',
);
return $items;
}
/**
* Implements hook_block_info().
*/
function image_insert_codes_block_info() {
$blocks['image-insert-codes'] = array(
'info' => t('Image insert codes'),
);
return $blocks;
}
/**
* Implements hook_block_view().
*/
function image_insert_codes_block_view($delta = '') {
$block = array();
if ($delta == 'image-insert-codes') {
$block['subject'] = t('Image insert codes');
$block['content'] = image_insert_codes_form();
}
return $block;
}
/**
* Implements hook_preprocess_node().
*/
function image_insert_codes_preprocess_node(&$vars) {
$vars['image_insert_codes'] = image_insert_codes_form();
}
/**
* Form builder.
*/
function image_insert_codes_form() {
$node = menu_get_object();
$code = variable_get('image_insert_codes_code');
$field_name = variable_get('image_insert_codes_field');
$image_style = variable_get('image_insert_codes_image_style');
$collapsible = variable_get('image_insert_codes_collapsible');
if (!empty($node->{$field_name}) && node_is_page($node)) {
//$uri = $node->field_image['und'][0]['uri'];
$uri = $node->{$field_name}['und'][0]['uri'];
$url = file_create_url($uri);
$preview = theme('image_style', array(
'style_name' => $image_style,
'path' => $uri,
'alt' => $node->title,
));
//$form = array();
if ($collapsible == 1) {
$form['codes'] = array(
'#type' => 'fieldset',
'#title' => t('Show codes'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#attached' => array(
'library' => array(
array('system', 'drupal.collapse'),
),
),
'#attributes' => array(
'class' => array('collapsible', 'collapsed')
),
);
}
if ($code[1]) {
$form['codes']['html-full-img'] = array(
'#type' => 'textfield',
'#title' => t('HTML'),
'#value' => '<img src="' . $url . '" alt="' . $node->title . '" />',
'#size' => 22,
'#attributes' => array('class' => array('imageinsertcodes')),
'#description' => t('Full image.'),
);
}
if ($code[2]) {
$form['codes']['html-clickable'] = array(
'#type' => 'textfield',
'#title' => t('HTML'),
'#value' => '<a href="' . $url . '" title="' . $node->title . '">' . $preview . '</a>',
'#size' => 22,
'#attributes' => array('class' => array('imageinsertcodes')),
'#description' => t('Clickable preview.'),
);
}
if ($code[3]) {
$form['codes']['bbcode-full-img'] = array(
'#type' => 'textfield',
'#title' => t('BBCode'),
'#value' => '[IMG]' . $url . '[/IMG]',
'#size' => 22,
'#attributes' => array('class' => array('imageinsertcodes')),
'#description' => t('Full image.'),
);
}
if ($code[4]) {
$form['codes']['bbcode-clickable'] = array(
'#type' => 'textfield',
'#title' => t('BBCode'),
'#value' => '[URL=' . $url . '][IMG]' . image_style_url($image_style, $uri) . '[/IMG][/URL]',
'#size' => 22,
'#attributes' => array('class' => array('imageinsertcodes')),
'#description' => t('Clickable preview.'),
);
}
if ($code[5]) {
$form['codes']['picture-url'] = array(
'#type' => 'textfield',
'#title' => t('Picture URL'),
'#value' => $url,
'#size' => 22,
'#attributes' => array('class' => array('imageinsertcodes')),
);
}
$form['codes']['#attached']['js'][] = drupal_get_path('module', 'image_insert_codes') . '/image_insert_codes.js';
$form['codes']['#attached']['css'][] = drupal_get_path('module', 'image_insert_codes') . '/image_insert_codes.css';
return $form;
}
}