-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathskivers_instagram.module
158 lines (130 loc) · 4.63 KB
/
skivers_instagram.module
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
151
152
153
154
155
156
157
158
<?php
/*
@author surf
* */
define('SKIVERS_INSTAGRAM_ADMIN', 'admin/config/skivers/skivers_instagram');
function skivers_instagram_menu()
{
$items[SKIVERS_INSTAGRAM_ADMIN] = array(
'title' => 'Instagram',
'description' => 'Instagram',
'page callback' => 'drupal_get_form',
'page arguments' => array('skivers_instagram_admin'),
'access arguments' => array('administer skivers_instagram_admin module'),
'type' => MENU_NORMAL_ITEM,
);
return $items;
}
function skivers_instagram_init()
{
// drupal_add_js("skivers_instagram_code ='" . variable_get('skivers_instagram_code', 'Error Code') . "';", array('type' => 'inline', 'scope' => 'header'));
// drupal_add_js(drupal_get_path('module', 'skivers_instagram') . '/js/skivers_instagram.js', array('scope' => 'footer'));
// drupal_add_css(drupal_get_path('module', 'skivers_instagram') . '/css/skivers_instagram.css');
}
function skivers_instagram_admin()
{
$form = array();
$form['skivers_instagram_title'] = array(
);
$form['skivers_instagram_code'] = array(
'#type' => 'textfield',
'#title' => t('Client ID'),
'#default_value' => variable_get('skivers_instagram_code', 'Enter Your Code'),
'#size' => 60,
'#maxlength' => 125,
'#description' => t(""),
'#required' => TRUE,
);
$form['skivers_instagram_secret'] = array(
'#type' => 'textfield',
'#title' => t('Secret'),
'#default_value' => variable_get('skivers_instagram_secret', 'Enter Your Code'),
'#size' => 60,
'#maxlength' => 125,
'#description' => t(""),
'#required' => TRUE,
);
$form['skivers_instagram_user_id'] = array(
'#type' => 'textfield',
'#title' => t('Instagram Profile id'),
'#default_value' => variable_get('skivers_instagram_user_id', 'Enter Your Code'),
'#size' => 60,
'#maxlength' => 125,
'#description' => t(""),
'#required' => TRUE,
);
$form['skivers_instagram_markup'] = array(
'#markup' => '<b>
skivers_instagram_tag([enter a tag])</b> - use this to get an image with the tags listed
<br/>
<b>skivers_instagram_id() </b>- use this to get profile images'
);
return system_settings_form($form);
}
function skivers_instagram_tag($tag)
{
$client_id = variable_get('skivers_instagram_code', '');
$secret = variable_get('skivers_instagram_secret', '');
if (!empty($client_id) && !empty($secret))
{
try
{
$result = json_decode(skivers_instagram_curl_download('https://api.instagram.com/v1/tags/' . $tag . '/media/recent?client_id=' . $client_id));
// display images
$data = $result->data;
return $data;
} catch (Exception $e)
{
echo 'ERROR: ' . $e->getMessage() . print_r($client_id);
exit;
}
}
}
function skivers_instagram_id()
{
$client_id = variable_get('skivers_instagram_code', '');
$secret = variable_get('skivers_instagram_secret', '');
$id = variable_get('skivers_instagram_user_id', '');
if (!empty($client_id) && !empty($secret) && !empty($id))
{
try
{
$result = json_decode(skivers_instagram_curl_download('https://api.instagram.com/v1/users/' . $id . '/media/recent?client_id=' . $client_id));
// display images
$data = $result->data;
return $data;
} catch (Exception $e)
{
echo 'ERROR: ' . $e->getMessage() . print_r($client_id);
exit;
}
}
}
function skivers_instagram_curl_download($Url)
{
// is cURL installed yet?
if (!function_exists('curl_init'))
{
die('Sorry cURL is not installed!');
}
// OK cool - then let's create a new cURL resource handle
$ch = curl_init();
// Now set some options (most are optional)
// Set URL to download
curl_setopt($ch, CURLOPT_URL, $Url);
// Set a referer
curl_setopt($ch, CURLOPT_REFERER, $GLOBALS['base_url']);
// User agent
curl_setopt($ch, CURLOPT_USERAGENT, "MozillaXYZ/1.0");
// Include header in result? (0 = yes, 1 = no)
curl_setopt($ch, CURLOPT_HEADER, 0);
// Should cURL return or print out the data? (true = return, false = print)
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Timeout in seconds
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
// Download the given URL, and return output
$output = curl_exec($ch);
// Close the cURL resource, and free system resources
curl_close($ch);
return $output;
}