View source
<?php
if (!defined('REQUEST_TIME')) {
define('REQUEST_TIME', time());
}
function drupagram_menu() {
$items = array();
$items['instagram/oauth'] = array(
'title' => 'Instagram',
'access callback' => TRUE,
'page callback' => 'drupal_get_form',
'page arguments' => array(
'drupagram_oauth_callback',
),
'type' => MENU_CALLBACK,
'file' => 'drupagram.pages.inc',
);
$items['admin/settings/services/instagram'] = array(
'title' => 'Instagram',
'description' => 'Configure integration with Instagram (and compatible) API services.',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'drupagram_admin_form',
),
'access arguments' => array(
'administer site configuration',
),
'file' => 'drupagram.pages.inc',
);
$items['admin/settings/services/instagram/default'] = array(
'title' => 'Instagram',
'type' => MENU_DEFAULT_LOCAL_TASK,
);
$items['user/%user/edit/drupagram'] = array(
'title' => 'Instagram accounts',
'page callback' => 'drupagram_user_settings',
'page arguments' => array(
1,
),
'access callback' => 'drupagram_edit_access',
'access arguments' => array(
1,
),
'load arguments' => array(
'%map',
'%index',
),
'weight' => 10,
'file' => 'drupagram.pages.inc',
'type' => MENU_LOCAL_TASK,
);
$items['user/%user/edit/drupagram/global/%'] = array(
'title' => 'Instagram accounts',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'drupagram_user_make_global',
1,
5,
),
'access arguments' => array(
'make drupagram accounts global',
),
'file' => 'drupagram.pages.inc',
);
return $items;
}
function drupagram_edit_access($account) {
return user_edit_access($account) && user_access('Add Instagram accounts');
}
function drupagram_perm() {
return array(
t('Add Instagram accounts'),
t('Use the site global Instagram account'),
t('Assign a Instagram account as the site global account'),
t('Import own media to the site'),
);
}
function _drupagram_use_oauth() {
return module_exists('oauth_common') && variable_get('drupagram_client_id', '') && variable_get('drupagram_client_secret', '');
}
function drupagram_user($op, &$edit, &$account, $category = NULL) {
switch ($op) {
case "load":
$account->drupagram_accounts = module_invoke_all("drupagram_accounts", $account);
break;
}
}
function drupagram_drupagram_accounts($account) {
module_load_include('inc', 'drupagram');
$query = "SELECT da.drupagram_id FROM {drupagram_account} da";
$condition = " WHERE da.uid = %d";
if (user_access('use global drupagram account', $account)) {
$condition .= " OR da.is_global=1";
}
$query = $query . $condition;
$drupagram_accounts = db_query($query, $account->uid);
$drupagram_accounts_list = array();
while ($drupagram_account = db_fetch_object($drupagram_accounts)) {
$drupagram_accounts_list[] = drupagram_account_load($drupagram_account->drupagram_id);
}
return $drupagram_accounts_list;
}
function drupagram_theme() {
return array(
'drupagram_account_list_form' => array(
'arguments' => array(
'form' => NULL,
),
),
'drupagram_likes' => array(
'arguments' => array(
'count' => NULL,
'data' => array(),
),
'file' => 'drupagram.theme.inc',
),
'drupagram_likes_data' => array(
'arguments' => array(
'data' => array(),
),
'file' => 'drupagram.theme.inc',
),
'drupagram_likes_data_item' => array(
'arguments' => array(
'id' => NULL,
'username' => NULL,
'full_name' => NULL,
'profile_picture' => NULL,
),
'file' => 'drupagram.theme.inc',
),
);
}
function drupagram_cron() {
if (!variable_get('drupagram_import', TRUE)) {
return;
}
module_load_include('inc', 'drupagram');
$result = db_query_range("SELECT drupagram_id FROM {drupagram_account} WHERE import = %d ORDER BY last_refresh ASC", 1, 0, 20);
while ($account = db_fetch_object($result)) {
if ($account->drupagram_id) {
drupagram_fetch_recent_items($account->drupagram_id);
}
}
if ($age = variable_get('drupagram_expire', 0)) {
db_query("DELETE FROM {drupagram} WHERE created_time=%d", REQUEST_TIME - $age);
}
}
function drupagram_views_api() {
return array(
'api' => 2,
'path' => drupal_get_path('module', 'drupagram') . '/views',
);
}