/
flickr_context_tags_admin.inc.php
142 lines (127 loc) · 4.86 KB
/
flickr_context_tags_admin.inc.php
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
<?php
function flickr_context_tags_flickr_user($form_state, $u) {
drupal_add_css(drupal_get_path('module','flickr_context_tags') . '/css/flickr.css');
$blocked = flickr_context_tags_images_blocked(array('owner'=>$u['id']));
$form = array(
'user_id' => array(
'#type' => 'value',
'#value' => $u['id'],
),
);
$form['name'] = array(
'#type' => 'markup',
'#value' =>
l('<img src="http://farm' . $u['iconfarm'] . '.static.flickr.com/' .
$u['iconserver'] . '/buddyicons/' . $u['id'] . '.jpg"/>' .
$u['username']['_content'], $u['profileurl']['_content'], array(
'html' => TRUE,
'attributes' => array(
'class' => 'flickr-user-link',
)
)),
);
$form['blocked'] = array(
'#type' => 'checkbox',
'#title' => t('Blocked'),
'#default_value' => $blocked,
);
$form['photos'] = array(
'#type' => 'item',
'#title' => t('Photo page'),
'#value' => l($u['photosurl']['_content'], $u['photosurl']['_content']),
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Save'),
);
return $form;
}
function flickr_context_tags_flickr_user_submit($form, $form_state) {
$values = $form_state['values'];
flickr_context_tags_set_user_block($values['user_id'], $values['blocked']);
}
function flickr_context_tags_settings() {
$form = array();
$mt_ns = variable_get('flickr_context_tags_mech_namespace', '');
//Make a qualified guess
if (empty($mt_ns)) {
$matches = array();
$site_name = variable_get('site_name','');
if (preg_match('/^\s*([^\s\.]+)/', $site_name, $matches)) {
$mt_ns = drupal_strtolower($matches[1]);
}
}
$form['flickr_context_tags_mech_namespace'] = array(
'#type' => 'textfield',
'#title' => t('Machine-tag namespace'),
'#default_value' => $mt_ns,
);
$form['flickr_context_tags_userid'] = array(
'#type' => 'textfield',
'#title' => t('Flickr id'),
'#description' => t('Can be used to get photos from a specified flickr user'),
'#default_value' => variable_get('flickr_context_tags_userid', ''),
);
$form['flickr_context_tags_default_place_id'] = array(
'#type' => 'textfield',
'#title' => t('Default place id'),
'#description' => t('The default place id can be used to keep the flickr pictures relevant'),
'#default_value' => variable_get('flickr_context_tags_default_place_id', ''),
);
$form['flickr_context_tags_force_default_place_id'] = array(
'#type' => 'checkbox',
'#title' => t('Always use the default place id'),
'#default_value' => variable_get('flickr_context_tags_force_default_place_id', FALSE),
);
$sizes = array('s' => t('Square'), 't' => t('Thumbnail'), 'm' => t('Small'), '-' => t('Medium'), 'b' => t('Large'), 'o' => t('Orginal'));
$form['flickr_context_tags_size'] = array(
'#type' => 'select',
'#title' => t('Select the size you want your photos in'),
'#default_value' => variable_get('flickr_context_tags_size', 'm'),
'#options' => $sizes,
);
// Tag configuration textarea
$paths = variable_get('flickr_context_tags_contexts', array());
$form['flickr_context_tags_contexts'] = array(
'#type' => 'textarea',
'#title' => t('Context tags for paths'),
'#default_value' => flickr_context_tags_pack_contexts($paths),
'#description' => t('Enter the path expression followed by a list of comma-separated tags'),
);
// Piggyback on the system settings form for buttons and so on
$form = system_settings_form($form);
// ...but replace the #submit function
$form['#submit'] = array('flickr_context_tags_settings_submit');
return $form;
}
function flickr_context_tags_pack_contexts($paths) {
$txt = '';
foreach($paths as $path => $tags) {
$txt .= $path . ' ' . join(', ', $tags) . "\n";
}
return $txt;
}
function flickr_context_tags_unpack_contexts($txt) {
$paths = array();
$lines = split("\n", $txt);
foreach ($lines as $line) {
$line = trim($line);
$matches = array();
if (preg_match('/([^\s]+)\s+(.*)/', $line, $matches)) {
$path = $matches[1];
$tags = preg_split('/\s*,\s*/', $matches[2]);
$paths[$path] = $tags;
}
}
return $paths;
}
function flickr_context_tags_settings_submit($form, $state) {
$values = $state['values'];
$paths = flickr_context_tags_unpack_contexts($values['flickr_context_tags_contexts']);
variable_set('flickr_context_tags_contexts', $paths);
variable_set('flickr_context_tags_mech_namespace', $values['flickr_context_tags_mech_namespace']);
variable_set('flickr_context_tags_userid', $values['flickr_context_tags_userid']);
variable_set('flickr_context_tags_default_place_id', $values['flickr_context_tags_default_place_id']);
variable_set('flickr_context_tags_force_default_place_id', $values['flickr_context_tags_force_default_place_id']);
variable_set('flickr_context_tags_size', $values['flickr_context_tags_size']);
}