| 1 |
<?php
|
| 2 |
// $Id$
|
| 3 |
|
| 4 |
/**
|
| 5 |
* @file
|
| 6 |
* Apture module for Drupal.
|
| 7 |
*
|
| 8 |
* This module places the apture button in your drupal editing page so that
|
| 9 |
* users can embed and/or link rich media into their drupal posts through the
|
| 10 |
* apture media hub.
|
| 11 |
*
|
| 12 |
* This program is free software; you can redistribute it and/or modify
|
| 13 |
* it under the terms of the GNU General Public License.
|
| 14 |
* This program is distributed in the hope that it will be useful,
|
| 15 |
* but WITHOUT ANY WARRANTY. See the LICENSE.txt file for more details.
|
| 16 |
*/
|
| 17 |
|
| 18 |
function apture_plugin_attributes() {
|
| 19 |
global $base_url;
|
| 20 |
return array(
|
| 21 |
"domain"=>"http://www.apture.com",
|
| 22 |
"baseurl"=>urlencode($base_url),
|
| 23 |
"version"=>"dp6_0",
|
| 24 |
"platform"=>"Drupal",
|
| 25 |
"configUrl"=>urlencode($base_url."?q=admin/settings/apture/editorsetup")
|
| 26 |
);
|
| 27 |
}
|
| 28 |
|
| 29 |
function apture_init() {
|
| 30 |
drupal_add_js(array('apture' => array('basePath' => base_path())), 'setting');
|
| 31 |
}
|
| 32 |
|
| 33 |
function apture_footer($main = 0) {
|
| 34 |
global $user;
|
| 35 |
$token = variable_get('apture_token', '');
|
| 36 |
$x = menu_get_item();
|
| 37 |
$cb = $x['page_callback'];
|
| 38 |
$plugin = apture_plugin_attributes();
|
| 39 |
$is_edit_page = ($cb == 'node_add' || $cb == 'node_page_edit');
|
| 40 |
|
| 41 |
if ($is_edit_page) {
|
| 42 |
$script = '<script id="aptureScript" type="text/javascript" src="'.$plugin['domain'].'/js/aptureEdit.js?platform='.$plugin['platform'].'&plugin='.$plugin['version'].'&configUrl='.$plugin['configUrl'].'&siteToken='.$token.'" charset="utf-8"></script>';
|
| 43 |
} else {
|
| 44 |
$script = '<script id="aptureScript" type="text/javascript" src="'.$plugin['domain'].'/js/apture.js?siteToken='.$token.'" charset="utf-8"></script>';
|
| 45 |
}
|
| 46 |
return $script;
|
| 47 |
}
|
| 48 |
|
| 49 |
function apture_menu () {
|
| 50 |
$items = array();
|
| 51 |
|
| 52 |
$items['admin/settings/apture'] = array(
|
| 53 |
'title' => t('Apture'),
|
| 54 |
'description' => t('Configuration Settings for Apture Integration.'),
|
| 55 |
'page callback' => 'drupal_get_form',
|
| 56 |
'page arguments' => array('apture_settings'),
|
| 57 |
'access arguments' => array('administer apture'),
|
| 58 |
'type' => MENU_NORMAL_ITEM
|
| 59 |
);
|
| 60 |
|
| 61 |
$items['admin/settings/apture/editorsetup'] = array(
|
| 62 |
'page callback' => 'apture_editor_setup',
|
| 63 |
'access arguments' => array('administer apture'),
|
| 64 |
'type' => MENU_CALLBACK
|
| 65 |
);
|
| 66 |
|
| 67 |
return $items;
|
| 68 |
}
|
| 69 |
|
| 70 |
function apture_settings () {
|
| 71 |
$form['apture_token'] = array(
|
| 72 |
'#type' => 'textfield',
|
| 73 |
'#title' => t('Apture Site Token'),
|
| 74 |
'#size' => '30',
|
| 75 |
'#default_value' => variable_get('apture_token', ""),
|
| 76 |
'#description' => t('Paste the Site Token provided by Apture when you registered this site.'),
|
| 77 |
);
|
| 78 |
$form['#validate'][] = 'apture_sitetoken_validate';
|
| 79 |
$form['#submit'][] = 'apture_sitetoken_submit';
|
| 80 |
return system_settings_form($form);
|
| 81 |
}
|
| 82 |
|
| 83 |
function apture_perm() {
|
| 84 |
return array('administer apture');
|
| 85 |
}
|
| 86 |
|
| 87 |
function apture_editor_setup() {
|
| 88 |
echo drupal_get_form('apture_editor_setup_form');
|
| 89 |
}
|
| 90 |
|
| 91 |
function apture_editor_setup_form() {
|
| 92 |
$form['apture_token'] = array('#type' => 'hidden', '#value' => $_GET['siteToken']);
|
| 93 |
$form['submit'] = array('#type' => 'submit', '#value'=>t('Update Token'));
|
| 94 |
$form['#submit'] = array('apture_editor_setup_form_submit');
|
| 95 |
$form['#validate'] = array('apture_editor_setup_form_validate');
|
| 96 |
return $form;
|
| 97 |
}
|
| 98 |
|
| 99 |
function apture_editor_setup_form_validate($form, &$form_state) {
|
| 100 |
apture_sitetoken_validate($form, $form_state);
|
| 101 |
}
|
| 102 |
|
| 103 |
function apture_editor_setup_form_submit($form, &$form_state) {
|
| 104 |
apture_sitetoken_submit($form, $form_state);
|
| 105 |
echo "<html><head><body><h3 style='color:#003399'>ALL DONE!</h3></body></head></html>";
|
| 106 |
die;
|
| 107 |
}
|
| 108 |
|
| 109 |
function apture_sitetoken_validate($form, &$form_state) {
|
| 110 |
$token = $form['apture_token']['#value'];
|
| 111 |
if (strlen($token) != strlen(strip_tags($token))) {
|
| 112 |
form_set_error('apture_token', t('Invalid apture site token') );
|
| 113 |
}
|
| 114 |
}
|
| 115 |
|
| 116 |
function apture_sitetoken_submit($form, &$form_state) {
|
| 117 |
$token = $form['apture_token']['#value'];
|
| 118 |
$form_state['values']['apture_token'] = $token;
|
| 119 |
variable_set('apture_token', check_plain($token));
|
| 120 |
}
|