Commit cdbf4fda authored by Paul Booker's avatar Paul Booker

First alpha release of the openattribute module

parent e5c8548f
......@@ -2,4 +2,5 @@ name = Open Attribute
description = "Open attribute is a module designed to allow users to add reuse licenses into their Drupal sites and then provide features so that people using your Drupal site can attribute you. Built to allow users to be as flexible as possible with their licenses, Open Attribute allows you to attribute your entire site / content types with a license and to attribute each node individually if required."
core = 7.x
files[] = openattribute.module
files[] = openattribute.js
;dependencies[] =
(function ($) {
Drupal.behaviors.createLicense = {
attach: function (context) {
$("#openattribute_link").click(function(event){
event.preventDefault();
author = $("[name=author]").val();
title = $("[name=title]").val();
attribution_url = $("[name=url]").val();
license_shorthand = $("[name=license] :selected").text();
license_url = $("[name=license]").val();
node_url = 'http://drupal7.local/test';
license = '<a id="oatitle" href="' + node_url + '" xmlns:dc="http://purl.org/dc/terms/" property="dc:title">' + title + '</a>'
license += ' by <a id="oaattributionurl" xmlns:cc="http://creativecommons.org/ns#" href="' + attribution_url + '" property="cc:attributionName" rel="cc:attributionURL" oaauthor="' + author + '">' + author + '</a>'
license += ' is licensed under a <a id="oalicense" rel="license" href="' + license_url + '">' + license_shorthand + '</a><br />'
license += ' Based on a work at <a xmlns:dct="http://purl.org/dc/terms/" href="' + node_url + '" rel="dct:source">' + node_url + '</a>.'
alert(license);
body = $("textarea#edit-body-und-0-value").val() + '\n\n' + license
$("textarea#edit-body-und-0-value").val(body);
});
}
};
})(jQuery);
\ No newline at end of file
......@@ -13,6 +13,14 @@ define('OPENATTRIBUTE_LICENSE_AUTHOR', 'openattribute_license_author');
define('OPENATTRIBUTE_AUTHOR_ATTRIBUTION_URL', 'openattribute_author_attribution_url');
define('OPENATTRIBUTE_LICENSES_DEFAULT_OPTIONS', "http://creativecommons.org/licenses/by-nd/3.0,Attribution-NoDerivatives CC BY-ND\nhttp://creativecommons.org/licenses/by-nc-sa/3.0,Attribution-NonCommercial-ShareAlike CC BY-NC-SA\nhttp://creativecommons.org/licenses/by-sa/3.0,Attribution-ShareAlike CC BY-SA\nhttp://creativecommons.org/licenses/by-nc/3.0,Attribution-NonCommercial CC BY-NC\nhttp://creativecommons.org/licenses/by-nc-nd/3.0,Attribution-NonCommercial-NoDerivatives CC BY-NC-ND\n");
define('OPENATTRIBUTE_LICENSE_HTML_ID', 'oaattributionurl');
/**
* Implements hook_init().
*/
function openattribute_init() {
drupal_add_js(drupal_get_path('module', 'openattribute') . '/openattribute.js');
}
/**
* Implements hook_help().
......@@ -48,7 +56,7 @@ function openattribute_menu() {
'page arguments' => array('openattribute_admin_settings'),
'access arguments' => array('administer site configuration'),
);
//drupal_add_js(drupal_get_path('module', 'openattribute'). '/openattribute.js');
drupal_add_js(drupal_get_path('module', 'openattribute'). '/openattribute.js');
return $items;
}
......@@ -141,16 +149,7 @@ function openattribute_admin_settings() {
'#collapsed' => FALSE,
);
$site_licenses = array();
$licenses = variable_get(OPENATTRIBUTE_LICENSES,'');
$licenses = explode("\n", $licenses);
foreach ($licenses as $license) {
$license = explode(",", $license);
$url = $license[0];
$license = $license[1];
$site_licenses[$url] = $license;
}
$site_licenses = _openattribute_get_site_licenses();
$form['openattribute_settings']['licenses_setup'][OPENATTRIBUTE_SITE_LICENSE] = array(
'#type' => 'select',
......@@ -177,4 +176,145 @@ function openattribute_admin_settings() {
);
return system_settings_form($form['openattribute_settings']);
}
function openattribute_form_alter(&$form, $form_state, $form_id) {
if ($form_id == 'node_type_form') {
$form['openattribute'] = array(
'#type' => 'fieldset',
'#title' => t('Open Attribution license settings'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#group' => 'additional_settings',
'#weight' => 5,
);
$form['openattribute']['licensing_enabled'] = array(
'#type' => 'radios',
'#title' => t('Open Attribution Licensing'),
'#default_value' => variable_get('licensing_enabled_' . $form['#node_type']->type, FALSE),
'#options' => array(FALSE => t('Disabled'), TRUE => t('Enabled')),
'#description' => t('Should this node type have a license attributed to it?'),
);
}
elseif (isset($form['type']) && isset($form['#node']) && $form['type']['#value'] . '_node_form' == $form_id) {
$node = $form['#node'];
if (variable_get('licensing_enabled_' . $form['type']['#value'], FALSE)) {
global $user;
global $base_root;
$form['disable_attribution'] = array(
'#type' => 'checkbox',
'#title' => t('To disable attribution for this post please tick this box'),
'#default_value' => FALSE,
'#weight' => -3,
);
$form['openattribute_license'] = array(
'#type' => 'fieldset',
'#title' => t('Add license'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#weight' => -4,
);
$form['openattribute_license']['author'] = array(
'#title' => t('If you wish to change the details of the author you can do so now '),
'#type' => 'textfield',
'#maxlength' => 100,
'#size' => 50,
'#default_value' => $user->name,
);
$form['openattribute_license']['work_title'] = array(
'#title' => t('If you wish to give the work a title you can do so'),
'#type' => 'textfield',
'#maxlength' => 100,
'#size' => 50,
);
$form['openattribute_license']['url'] = array(
'#title' => t('You can set a URL for yourself as an author (Site address set by default)'),
'#type' => 'textfield',
'#maxlength' => 100,
'#size' => 50,
'#default_value' => $base_root,
);
$site_licenses = _openattribute_get_site_licenses();
$form['openattribute_license']['license'] = array(
'#title' => t('Now choose a license'),
'#type' => 'select',
'#options' => $site_licenses,
);
$form['openattribute_license']['description'] = array(
'#type' => 'item',
'#description' => t('When you click on this ' . l("link","#",array('attributes' => array( 'id' => 'openattribute_link' ) ) ) . ' your licence will be generated and rendered within the body text field'),
);
}
}
}
/**
* Implements hook_node_submit().
*/
function openattribute_node_submit($node, $form, &$form_state){
$form_values = $form_state['values'];
if ($form_values['disable_attribution'] || !(variable_get(OPENATTRIBUTE_SHOW_ATTRIBUTION, FALSE))) return;
global $base_root;
$license_data = "";
$node->body['und'][0]['format'] = 'full_html'; // Not sure about doing this.
if (strpos($node->body['und'][0]['value'], OPENATTRIBUTE_LICENSE_HTML_ID) && variable_get(OPENATTRIBUTE_REMOVE_SITE_LICENSE, FALSE)){
} else {
$author = variable_get(OPENATTRIBUTE_LICENSE_AUTHOR,'');
$site_license_url = variable_get(OPENATTRIBUTE_SITE_LICENSE, '');
$site_attribution_url = variable_get(OPENATTRIBUTE_AUTHOR_ATTRIBUTION_URL, '');
$site_licenses = _openattribute_get_site_licenses();
$site_license = $site_licenses[$site_license_url];
$license_data .= '<div class="license"><span xmlns:dct="http://purl.org/dc/terms/" property="dct:title">' . '</span>'; // what does the_title( '', '', 0 ) give?
$license_data .= ' by <a xmlns:cc="http://creativecommons.org/ns#" href="' . $site_attribution_url . '" property="cc:attributionName" rel="cc:attributionURL" >' . $author . '</a>';
$license_data .= ' is licensed under a <a rel="license" href="' . $site_license_url . '">' . $site_license . '</a></div>';
}
if (variable_get(OPENATTRIBUTE_SHOW_ATTRIBUTE_ME_BUTTON, FALSE)){
$license_data .= '<div><img src="' . $base_root. '/' . drupal_get_path('module', 'openattribute') . '/' . 'attrib_button.png" /></div>';
}
$node->body['und'][0]['value'] .= "\n\n";
$node->body['und'][0]['value'] .= $license_data;
}
function _openattribute_get_site_licenses() {
$site_licenses = array();
$licenses = variable_get(OPENATTRIBUTE_LICENSES,'');
$licenses = explode("\n", $licenses);
foreach ($licenses as $license) {
$license = explode(",", $license);
$url = $license[0];
$license = $license[1];
$site_licenses[$url] = $license;
}
return $site_licenses;
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment