Browse Source

Sync componentry for basic image.

7.x-2.x
Daniel Lamb 10 years ago
parent
commit
f190890154
  1. 50
      islandora_medium_size_service/include/islandora_medium_size_service.inc
  2. 6
      islandora_medium_size_service/islandora_medium_size_service.info
  3. 48
      islandora_medium_size_service/islandora_medium_size_service.module
  4. 47
      islandora_tn_service/include/islandora_tn_service.inc
  5. 6
      islandora_tn_service/islandora_tn_service.info
  6. 48
      islandora_tn_service/islandora_tn_service.module

50
islandora_medium_size_service/include/islandora_medium_size_service.inc

@ -0,0 +1,50 @@
<?php
/**
* @file
* Provides the callback implementations for the service.
*/
/**
* The POST callback for the MEDIUM_SIZE service.
*
* @param array $args
* JSON encoded arguments.
*
* @return string
* Response message.
*/
function islandora_medium_size_service_create($args) {
$uuid = $args['uuid'];
$tn_b64 = $args['file'];
$mimetype = $args['mimetype'];
$exploded = explode("/", $mimetype);
$extension = $exploded[1];
$entities = entity_uuid_load('node', array($uuid));
if (empty($entities)) {
return "Could not add medium sized image because there is no entity identified by $uuid";
}
$node = array_pop($entities);
$file = file_save_data(base64_decode($tn_b64), "public://" . $uuid . "_MEDIUM_SIZE." . $extension, FILE_EXISTS_REPLACE);
$node->field_medium_size[LANGUAGE_NONE][] = array(
'fid' => $file->fid,
'alt' => "Medium sized image for node $uuid",
'title' => "Medium sized image for node $uuid",
);
$node->field_tn[LANGUAGE_NONE][] = array(
'fid' => $file->fid,
'width' => 100,
'height' => 100,
'alt' => "Thumbnail for node $uuid",
'title' => "Thumbnail for node $uuid",
);
node_save($node);
return "Successfully added medium sized image to node $uuid";
}

6
islandora_medium_size_service/islandora_medium_size_service.info

@ -0,0 +1,6 @@
name = Islandora Medium Size Service
description = "Adds medium size images to nodes"
package = Islandora
version = 7.x-dev
core = 7.x
dependencies[] = rest_server

48
islandora_medium_size_service/islandora_medium_size_service.module

@ -0,0 +1,48 @@
<?php
/**
* @file
* Provides a service for adding medium size images to nodes.
*/
/**
* Implements hook_permission().
*/
function islandora_medium_size_service_permission() {
return array(
'islandora medium size service create' => array(
'title' => t('Add Medium Size'),
'description' => t('Allows external sources to add medium size images to nodes.'),
),
);
}
/**
* Implements hook_services_resources().
*/
function islandora_medium_size_service_services_resources() {
return array(
'medium_size' => array(
'create' => array(
'help' => t('Adds a medium sized image to the node identified by UUID.'),
'file' => array(
'type' => 'inc',
'module' => 'islandora_medium_size_service',
'name' => 'include/islandora_medium_size_service',
),
'callback' => 'islandora_medium_size_service_create',
'access callback' => 'user_access',
'access arguments' => array('islandora medium size service create'),
'args' => array(
array(
'name' => 'args',
'type' => 'array',
'description' => t("JSON data containing arguments to add the medium sized image."),
'source' => 'data',
'optional' => FALSE,
),
),
),
),
);
}

47
islandora_tn_service/include/islandora_tn_service.inc

@ -0,0 +1,47 @@
<?php
/**
* @file
* Provides the callback implementations for the service.
*/
/**
* The POST callback for the TN service.
*
* @param string $type
* Entity type to which the RDF mapping belongs.
* @param string $bundle
* Bundle to which the RDF mapping belongs.
*
* @return array
* The RDF mapping.
*/
function islandora_tn_service_create($args) {
$uuid = $args['uuid'];
$tn_b64 = $args['file'];
$mimetype = $args['mimetype'];
$exploded = explode("/", $mimetype);
$extension = $exploded[1];
$entities = entity_uuid_load('node', array($uuid));
if (empty($entities)) {
return "Could not add thumbnail because there is no entity identified by $uuid";
}
$node = array_pop($entities);
$file = file_save_data(base64_decode($tn_b64), "public://" . $uuid . "_TN." . $extension, FILE_EXISTS_REPLACE);
$node->field_tn[LANGUAGE_NONE][] = array(
'fid' => $file->fid,
'width' => 100,
'height' => 100,
'alt' => "Thumbnail for node $uuid",
'title' => "Thumbnail for node $uuid",
);
node_save($node);
return "Successfully added thumbnail to node $uuid";
}

6
islandora_tn_service/islandora_tn_service.info

@ -0,0 +1,6 @@
name = Islandora TN Service
description = "Adds thumbnail images to nodes"
package = Islandora
version = 7.x-dev
core = 7.x
dependencies[] = rest_server

48
islandora_tn_service/islandora_tn_service.module

@ -0,0 +1,48 @@
<?php
/**
* @file
* Provides a service for adding thumbnails to Drupal.
*/
/**
* Implements hook_permission().
*/
function islandora_tn_service_permission() {
return array(
'islandora tn service create' => array(
'title' => t('Add Thumbnails'),
'description' => t('Allows external sources to add thumbnails to nodes.'),
),
);
}
/**
* Implements hook_services_resources().
*/
function islandora_tn_service_services_resources() {
return array(
'tn' => array(
'create' => array(
'help' => t('Adds a thumbnail to the node identified by UUID.'),
'file' => array(
'type' => 'inc',
'module' => 'islandora_tn_service',
'name' => 'include/islandora_tn_service',
),
'callback' => 'islandora_tn_service_create',
'access callback' => 'user_access',
'access arguments' => array('islandora tn service create'),
'args' => array(
array(
'name' => 'args',
'type' => 'array',
'description' => t("JSON data containing arguments to add the thumbnail."),
'source' => 'data',
'optional' => FALSE,
),
),
),
),
);
}
Loading…
Cancel
Save