123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338 |
- <?php
- /**
- * @file Module hooks and required files
- */
- /**
- * Implements hook_menu()
- */
- function piecemaker_menu() {
- $items['piecemaker/%piecemaker_handler/%/settings.xml'] = array(
- 'page callback' => 'piecemaker_xml_build',
- 'page arguments' => array(1),
- 'load arguments' => array(2),
- 'access callback' => 'piecemaker_settings_access',
- 'access arguments' => array(1),
- 'type' => MENU_CALLBACK,
- 'file' => 'theme/piecemaker.xml.inc',
- );
- $items['admin/config/media/piecemaker'] = array(
- 'title' => 'Piecemaker',
- 'description' => 'Configure the Piecemaker API Profiles and Settings.',
- 'page callback' => 'piecemaker_profiles_page',
- 'access arguments' => array('administer site configuration'),
- 'file' => 'piecemaker.admin.inc',
- );
- $items['admin/config/media/piecemaker/profiles'] = array(
- 'title' => 'Profiles',
- 'description' => 'Piecemaker API Profiles',
- 'type' => MENU_DEFAULT_LOCAL_TASK,
- 'weight' => -50,
- );
- $items['admin/config/media/piecemaker/settings'] = array(
- 'title' => 'Settings',
- 'description' => 'Configure the Piecemaker API Settings.',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('piecemaker_settings_page'),
- 'access arguments' => array('administer site configuration'),
- 'file' => 'piecemaker.admin.inc',
- 'type' => MENU_LOCAL_TASK,
- );
- $items['admin/config/media/piecemaker/settings/delete_trans/%'] = array(
- 'title' => 'Settings',
- 'description' => 'Configure the Piecemaker API Settings.',
- 'page callback' => 'piecemaker_default_delete_transition',
- 'page arguments' => array(6),
- 'access arguments' => array('administer site configuration'),
- 'file' => 'piecemaker.admin.inc',
- 'type' => MENU_CALLBACK,
- );
- $items['admin/config/media/piecemaker/profiles/add'] = array(
- 'title' => 'Add Piecemaker Profile',
- 'description' => 'Add a Piecemaker API Profile.',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('piecemaker_profile_form', NULL),
- 'access arguments' => array('administer site configuration'),
- 'file' => 'piecemaker.admin.inc',
- 'type' => MENU_LOCAL_ACTION,
- );
- $items['admin/config/media/piecemaker/profiles/%piecemaker_profile/edit'] = array(
- 'title' => 'Edit Piecemaker Profile',
- 'description' => 'Add a Piecemaker API Profile.',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('piecemaker_profile_form', 5),
- 'access arguments' => array('administer site configuration'),
- 'file' => 'piecemaker.admin.inc',
- );
- $items['admin/config/media/piecemaker/profiles/%piecemaker_profile/delete'] = array(
- 'title' => 'Delete',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('piecemaker_profile_delete_confirm', 5),
- 'access arguments' => array('administer site configuration'),
- 'file' => 'piecemaker.admin.inc',
- );
- return $items;
- }
- /**
- * Loads the Piecemaker settings array.
- *
- * Uses the handlers defined in hook_piecemaker_handler()
- *
- * @param $handler
- * The Handler key as set in hook_piecemaker_handler()
- *
- * @param $key
- * A key to pass to the handler for it to get it's settings
- *
- * @return
- * An associative array containing the needed variables for the settings form
- * see @template_preprocess_piecemaker_xml() for the structure of the array
- */
- function piecemaker_handler_load($handler, $key) {
- $func = piecemaker_handlers($handler);
- if (isset($func['callback']) && function_exists($func['callback'])) {
- $settings = call_user_func($func['callback'], $key);
- $settings['key'] = $key;
- $settings['handler'] = array($handler => $func);
- return $settings;
- }
- return FALSE;
- }
- /**
- * Gets the access value for the specific piecemaker settings
- *
- * @param $handler
- * The Handler key as set in hook_piecemaker_handler()
- *
- * @param $key
- * A key to pass to the handler for it to get it's settings
- *
- * @return
- * TRUE or FALSE access value.
- */
- function piecemaker_settings_access($handler) {
- $func = $handler['handler'];
- if (isset($func['access']) && function_exists($func['access'])) {
- return call_user_func($func['access'], $key);
- }
- //default to TRUE
- return TRUE;
- }
- /**
- * Gets the piecemaker handlers
- *
- * @param $handler
- * A handler ID to pull from the list of handlers
- */
- function piecemaker_handlers($handler = NULL) {
- $handlers = &drupal_static(__FUNCTION__);
- if (!$handlers) {
- $handlers = module_invoke_all('piecemaker_handler');
- }
- if ($handler && !empty($handlers[$handler])) {
- return $handlers[$handler];
- }
- elseif ($handler && empty($handlers[$handler])) {
- return FALSE;
- }
- return $handlers;
- }
- /**
- * Loads a piecemaker profile
- *
- * @param $pid
- * The profile ID number to load.
- *
- * @return
- * An object containing:
- * - pid: The profile ID number
- * - title: The profile Title
- * - settings: An associative array representing the base settings for this profile
- * Returns NULL if no profile with the provided pid is available.
- */
- function piecemaker_profile_load($pid) {
- $profiles = &drupal_static(__FUNCTION__, array());
- if (!empty($profiles[$pid])) {
- return $profiles[$pid];
- }
- $query = db_query('SELECT * FROM {piecemaker_profiles} WHERE pid = :pid', array(':pid' => $pid));
- $profile = $query->fetch();
- if ($profile) {
- $profile->settings = unserialize($profile->settings);
- $profile->transitions = !empty($profile->transitions) ? unserialize($profile->transitions) : variable_get('piecemaker_default_transitions', array());
- $profile->flash_settings = !empty($profile->flash_settings) ? unserialize($profile->flash_settings) : _piecemaker_default_flash_settings();
-
- }
- $profiles[$pid] = $profile;
- return $profiles[$pid];
- }
- /**
- * Provides default settings to profiles
- *
- * @return
- * Array of settings values;
- */
- function _piecemaker_default_settings() {
- $vals = variable_get('piecemaker_default_settings', array());
- $settings['ImageWidth'] = isset($vals['ImageWidth']) ? $vals['ImageWidth'] : '900';
- $settings['ImageHeight'] = isset($vals['ImageHeight']) ? $vals['ImageHeight'] : '360';
- $settings['LoaderColor'] = isset($vals['LoaderColor']) ? $vals['LoaderColor'] : '0x333333';
- $settings['InnerSideColor'] = isset($vals['InnerSideColor']) ? $vals['InnerSideColor'] : '0x222222';
- $settings['SideShadowAlpha'] = isset($vals['SideShadowAlpha']) ? $vals['SideShadowAlpha'] : '0.8';
- $settings['DropShadowAlpha'] = isset($vals['DropShadowAlpha']) ? $vals['DropShadowAlpha'] : '0.7';
- $settings['DropShadowDistance'] = isset($vals['DropShadowDistance']) ? $vals['DropShadowDistance'] : '25';
- $settings['DropShadowScale'] = isset($vals['DropShadowScale']) ? $vals['DropShadowScale'] : '0.95';
- $settings['DropShadowBlurX'] = isset($vals['DropShadowBlurX']) ? $vals['DropShadowBlurX'] : '40';
- $settings['DropShadowBlurY'] = isset($vals['DropShadowBlurY']) ? $vals['DropShadowBlurY'] : '4';
- $settings['MenuDistanceX'] = isset($vals['MenuDistanceX']) ? $vals['MenuDistanceX'] : '20';
- $settings['MenuDistanceY'] = isset($vals['MenuDistanceY']) ? $vals['MenuDistanceY'] : '50';
- $settings['MenuColor1'] = isset($vals['MenuColor1']) ? $vals['MenuColor1'] : '0x999999';
- $settings['MenuColor2'] = isset($vals['MenuColor2']) ? $vals['MenuColor2'] : '0x333333';
- $settings['MenuColor3'] = isset($vals['MenuColor3']) ? $vals['MenuColor3'] : '0xFFFFFF';
- $settings['ControlSize'] = isset($vals['ControlSize']) ? $vals['ControlSize'] : '100';
- $settings['ControlDistance'] = isset($vals['ControlDistance']) ? $vals['ControlDistance'] : '20';
- $settings['ControlColor1'] = isset($vals['ControlColor1']) ? $vals['ControlColor1'] : '0x222222';
- $settings['ControlColor2'] = isset($vals['ControlColor2']) ? $vals['ControlColor2'] : '0xFFFFFF';
- $settings['ControlAlpha'] = isset($vals['ControlAlpha']) ? $vals['ControlAlpha'] : '0.8';
- $settings['ControlAlphaOver'] = isset($vals['ControlAlphaOver']) ? $vals['ControlAlphaOver'] : '0.95';
- $settings['ControlsX'] = isset($vals['ControlsX']) ? $vals['ControlsX'] : '450';
- $settings['ControlsY'] = isset($vals['ControlsY']) ? $vals['ControlsY'] : '280';
- $settings['ControlsAlign'] = isset($vals['ControlsAlign']) ? $vals['ControlsAlign'] : 'center';
- $settings['TooltipHeight'] = isset($vals['TooltipHeight']) ? $vals['TooltipHeight'] : '31';
- $settings['TooltipColor'] = isset($vals['TooltipColor']) ? $vals['TooltipColor'] : '0x222222';
- $settings['TooltipTextY'] = isset($vals['TooltipTextY']) ? $vals['TooltipTextY'] : '5';
- $settings['TooltipTextStyle'] = isset($vals['TooltipTextStyle']) ? $vals['TooltipTextStyle'] : 'P-Italic';
- $settings['TooltipTextColor'] = isset($vals['TooltipTextColor']) ? $vals['TooltipTextColor'] : '0xFFFFFF';
- $settings['TooltipMarginLeft'] = isset($vals['TooltipMarginLeft']) ? $vals['TooltipMarginLeft'] : '5';
- $settings['TooltipMarginRight'] = isset($vals['TooltipMarginRight']) ? $vals['TooltipMarginRight'] : '7';
- $settings['TooltipTextSharpness'] = isset($vals['TooltipTextSharpness']) ? $vals['TooltipTextSharpness'] : '50';
- $settings['TooltipTextThickness'] = isset($vals['TooltipTextThickness']) ? $vals['TooltipTextThickness'] : '-100';
- $settings['InfoWidth'] = isset($vals['InfoWidth']) ? $vals['InfoWidth'] : '400';
- $settings['InfoBackground'] = isset($vals['InfoBackground']) ? $vals['InfoBackground'] : '0xFFFFFF';
- $settings['InfoBackgroundAlpha'] = isset($vals['InfoBackgroundAlpha']) ? $vals['InfoBackgroundAlpha'] : '0.95';
- $settings['InfoMargin'] = isset($vals['InfoMargin']) ? $vals['InfoMargin'] : '15';
- $settings['InfoSharpness'] = isset($vals['InfoSharpness']) ? $vals['InfoSharpness'] : '0';
- $settings['InfoThickness'] = isset($vals['InfoThickness']) ? $vals['InfoThickness'] : '0';
- $settings['Autoplay'] = isset($vals['Autoplay']) ? $vals['Autoplay'] : '10';
- $settings['FieldOfView'] = isset($vals['FieldOfView']) ? $vals['FieldOfView'] : '45';
-
- return $settings;
- }
- /**
- * Provides the default flash settings to profiles
- */
- function _piecemaker_default_flash_settings() {
- $vals = variable_get('piecemaker_default_flash_settings', array('params' => array()));
- $pm_path = libraries_get_path('piecemaker');
- $settings['width'] = isset($vals['width']) ? $vals['width'] : '900';
- $settings['height'] = isset($vals['height']) ? $vals['height'] : '600';
- $settings['flashvars']['cssSource'] = isset($vals['flashvars']['cssSource']) ? $vals['flashvars']['cssSource'] : $pm_path . '/piecemaker.css';
- $settings['params']['play'] = isset($vals['params']['play']) ? $vals['params']['play'] : 'true';
- $settings['params']['menu'] = isset($vals['params']['menu']) ? $vals['params']['menu'] : 'false';
- $settings['params']['scale'] = isset($vals['params']['scale']) ? $vals['params']['scale'] : 'showall';
- $settings['params']['wmode'] = isset($vals['params']['wmode']) ? $vals['params']['wmode'] : 'transparent';
- $settings['params']['allowfullscreen'] = isset($vals['params']['allowfullscreen']) ? $vals['params']['allowfullscreen'] : 'true';
- $settings['params']['allowscriptaccess'] = isset($vals['params']['allowscriptaccess']) ? $vals['params']['allowscriptaccess'] : 'always';
- $settings['params']['allownetowrking'] = isset($vals['params']['allownetworking']) ? $vals['params']['allownetworking'] : 'true';
- $settings['params'] = array_merge($settings['params'], $vals['params']);
- return $settings;
- }
- /**
- * Implements hook_theme()
- */
- function piecemaker_theme() {
- $path = drupal_get_path('module', 'piecemaker');
- return array(
- 'piecemaker' => array(
- 'variables' => array('handler' => NULL, 'key' => NULL, 'profile' => array(), 'alternate_callback' => NULL),
- 'path' => $path . '/theme',
- 'file' => 'theme.inc',
- ),
- 'piecemaker_transition_form' => array(
- 'render element' => 'form',
- 'path' => $path . '/theme',
- 'file' => 'theme.inc',
- ),
- 'piecemaker_profile_params' => array(
- 'render element' => 'form',
- 'path' => $path . '/theme',
- 'file' => 'theme.inc',
- ),
- 'piecemaker_xml' => array(
- 'template' => 'piecemaker-xml',
- 'path' => $path . '/theme',
- 'file' => 'piecemaker.xml.inc',
- 'variables' => array('Settings' => array(), 'Transitions' => array(), 'Contents' => array(), 'handler' => array(), 'key' => NULL),
- ),
- 'piecemaker_xml_node' => array(
- 'path' => $path . '/theme',
- 'file' => 'piecemaker.xml.inc',
- 'variables' => array('item' => array()),
- ),
- 'piecemaker_xml_node_Image' => array(
- 'template' => 'piecemaker-xml-image',
- 'path' => $path . '/theme',
- 'file' => 'theme.inc',
- 'variables' => array('item' => array()),
- ),
- 'piecemaker_xml_node_Video' => array(
- 'template' => 'piecemaker-xml-video',
- 'path' => $path . '/theme',
- 'file' => 'theme.inc',
- 'variables' => array('item' => array()),
- ),
- 'piecemaker_xml_node_Flash' => array(
- 'template' => 'piecemaker-xml-flash',
- 'path' => $path . '/theme',
- 'file' => 'theme.inc',
- 'variables' => array('item' => array()),
- ),
- );
- }
- /**
- * Ajax callback for admin form
- */
- function piecemaker_add_transition_ajax($form, $form_state) {
- $key = $form_state['#transition_element'];
- return $form[$key];
- }
- /**
- * Ajax callback for admin form
- */
- function piecemaker_add_flash_params($form, $form_state) {
- return $form['flash_settings']['params'];
- }
- /**
- * Utility function that allows other modules to get a list of profiles keyed on the pid
- *
- * @return
- * An array of profiles keyed on the pid
- */
- function piecemaker_profile_options() {
- $profiles = &drupal_static(__FUNCTION__);
- if (!$profiles) {
- $profiles = db_query('SELECT title, pid FROM {piecemaker_profiles}')
- ->fetchAllKeyed(1,0);
- }
- return $profiles;
- }
- /**
- * Implements hook_page_alter()
- */
- function piecemaker_page_alter(&$page) {
- //We add all our piecemaker settings here right before the page renders to ensure that there are no
- //array merging errors
- $settings = drupal_static('theme_piecemaker_settings');
- if (is_array($settings)) {
- drupal_add_js($settings, 'setting');
- }
- }
|