piecemaker.module 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  1. <?php
  2. /**
  3. * @file Module hooks and required files
  4. */
  5. /**
  6. * Implements hook_menu()
  7. */
  8. function piecemaker_menu() {
  9. $items['piecemaker/%piecemaker_handler/%/settings.xml'] = array(
  10. 'page callback' => 'piecemaker_xml_build',
  11. 'page arguments' => array(1),
  12. 'load arguments' => array(2),
  13. 'access callback' => 'piecemaker_settings_access',
  14. 'access arguments' => array(1),
  15. 'type' => MENU_CALLBACK,
  16. 'file' => 'theme/piecemaker.xml.inc',
  17. );
  18. $items['admin/config/media/piecemaker'] = array(
  19. 'title' => 'Piecemaker',
  20. 'description' => 'Configure the Piecemaker API Profiles and Settings.',
  21. 'page callback' => 'piecemaker_profiles_page',
  22. 'access arguments' => array('administer site configuration'),
  23. 'file' => 'piecemaker.admin.inc',
  24. );
  25. $items['admin/config/media/piecemaker/profiles'] = array(
  26. 'title' => 'Profiles',
  27. 'description' => 'Piecemaker API Profiles',
  28. 'type' => MENU_DEFAULT_LOCAL_TASK,
  29. 'weight' => -50,
  30. );
  31. $items['admin/config/media/piecemaker/settings'] = array(
  32. 'title' => 'Settings',
  33. 'description' => 'Configure the Piecemaker API Settings.',
  34. 'page callback' => 'drupal_get_form',
  35. 'page arguments' => array('piecemaker_settings_page'),
  36. 'access arguments' => array('administer site configuration'),
  37. 'file' => 'piecemaker.admin.inc',
  38. 'type' => MENU_LOCAL_TASK,
  39. );
  40. $items['admin/config/media/piecemaker/settings/delete_trans/%'] = array(
  41. 'title' => 'Settings',
  42. 'description' => 'Configure the Piecemaker API Settings.',
  43. 'page callback' => 'piecemaker_default_delete_transition',
  44. 'page arguments' => array(6),
  45. 'access arguments' => array('administer site configuration'),
  46. 'file' => 'piecemaker.admin.inc',
  47. 'type' => MENU_CALLBACK,
  48. );
  49. $items['admin/config/media/piecemaker/profiles/add'] = array(
  50. 'title' => 'Add Piecemaker Profile',
  51. 'description' => 'Add a Piecemaker API Profile.',
  52. 'page callback' => 'drupal_get_form',
  53. 'page arguments' => array('piecemaker_profile_form', NULL),
  54. 'access arguments' => array('administer site configuration'),
  55. 'file' => 'piecemaker.admin.inc',
  56. 'type' => MENU_LOCAL_ACTION,
  57. );
  58. $items['admin/config/media/piecemaker/profiles/%piecemaker_profile/edit'] = array(
  59. 'title' => 'Edit Piecemaker Profile',
  60. 'description' => 'Add a Piecemaker API Profile.',
  61. 'page callback' => 'drupal_get_form',
  62. 'page arguments' => array('piecemaker_profile_form', 5),
  63. 'access arguments' => array('administer site configuration'),
  64. 'file' => 'piecemaker.admin.inc',
  65. );
  66. $items['admin/config/media/piecemaker/profiles/%piecemaker_profile/delete'] = array(
  67. 'title' => 'Delete',
  68. 'page callback' => 'drupal_get_form',
  69. 'page arguments' => array('piecemaker_profile_delete_confirm', 5),
  70. 'access arguments' => array('administer site configuration'),
  71. 'file' => 'piecemaker.admin.inc',
  72. );
  73. return $items;
  74. }
  75. /**
  76. * Loads the Piecemaker settings array.
  77. *
  78. * Uses the handlers defined in hook_piecemaker_handler()
  79. *
  80. * @param $handler
  81. * The Handler key as set in hook_piecemaker_handler()
  82. *
  83. * @param $key
  84. * A key to pass to the handler for it to get it's settings
  85. *
  86. * @return
  87. * An associative array containing the needed variables for the settings form
  88. * see @template_preprocess_piecemaker_xml() for the structure of the array
  89. */
  90. function piecemaker_handler_load($handler, $key) {
  91. $func = piecemaker_handlers($handler);
  92. if (isset($func['callback']) && function_exists($func['callback'])) {
  93. $settings = call_user_func($func['callback'], $key);
  94. $settings['key'] = $key;
  95. $settings['handler'] = array($handler => $func);
  96. return $settings;
  97. }
  98. return FALSE;
  99. }
  100. /**
  101. * Gets the access value for the specific piecemaker settings
  102. *
  103. * @param $handler
  104. * The Handler key as set in hook_piecemaker_handler()
  105. *
  106. * @param $key
  107. * A key to pass to the handler for it to get it's settings
  108. *
  109. * @return
  110. * TRUE or FALSE access value.
  111. */
  112. function piecemaker_settings_access($handler) {
  113. $func = $handler['handler'];
  114. if (isset($func['access']) && function_exists($func['access'])) {
  115. return call_user_func($func['access'], $key);
  116. }
  117. //default to TRUE
  118. return TRUE;
  119. }
  120. /**
  121. * Gets the piecemaker handlers
  122. *
  123. * @param $handler
  124. * A handler ID to pull from the list of handlers
  125. */
  126. function piecemaker_handlers($handler = NULL) {
  127. $handlers = &drupal_static(__FUNCTION__);
  128. if (!$handlers) {
  129. $handlers = module_invoke_all('piecemaker_handler');
  130. }
  131. if ($handler && !empty($handlers[$handler])) {
  132. return $handlers[$handler];
  133. }
  134. elseif ($handler && empty($handlers[$handler])) {
  135. return FALSE;
  136. }
  137. return $handlers;
  138. }
  139. /**
  140. * Loads a piecemaker profile
  141. *
  142. * @param $pid
  143. * The profile ID number to load.
  144. *
  145. * @return
  146. * An object containing:
  147. * - pid: The profile ID number
  148. * - title: The profile Title
  149. * - settings: An associative array representing the base settings for this profile
  150. * Returns NULL if no profile with the provided pid is available.
  151. */
  152. function piecemaker_profile_load($pid) {
  153. $profiles = &drupal_static(__FUNCTION__, array());
  154. if (!empty($profiles[$pid])) {
  155. return $profiles[$pid];
  156. }
  157. $query = db_query('SELECT * FROM {piecemaker_profiles} WHERE pid = :pid', array(':pid' => $pid));
  158. $profile = $query->fetch();
  159. if ($profile) {
  160. $profile->settings = unserialize($profile->settings);
  161. $profile->transitions = !empty($profile->transitions) ? unserialize($profile->transitions) : variable_get('piecemaker_default_transitions', array());
  162. $profile->flash_settings = !empty($profile->flash_settings) ? unserialize($profile->flash_settings) : _piecemaker_default_flash_settings();
  163. }
  164. $profiles[$pid] = $profile;
  165. return $profiles[$pid];
  166. }
  167. /**
  168. * Provides default settings to profiles
  169. *
  170. * @return
  171. * Array of settings values;
  172. */
  173. function _piecemaker_default_settings() {
  174. $vals = variable_get('piecemaker_default_settings', array());
  175. $settings['ImageWidth'] = isset($vals['ImageWidth']) ? $vals['ImageWidth'] : '900';
  176. $settings['ImageHeight'] = isset($vals['ImageHeight']) ? $vals['ImageHeight'] : '360';
  177. $settings['LoaderColor'] = isset($vals['LoaderColor']) ? $vals['LoaderColor'] : '0x333333';
  178. $settings['InnerSideColor'] = isset($vals['InnerSideColor']) ? $vals['InnerSideColor'] : '0x222222';
  179. $settings['SideShadowAlpha'] = isset($vals['SideShadowAlpha']) ? $vals['SideShadowAlpha'] : '0.8';
  180. $settings['DropShadowAlpha'] = isset($vals['DropShadowAlpha']) ? $vals['DropShadowAlpha'] : '0.7';
  181. $settings['DropShadowDistance'] = isset($vals['DropShadowDistance']) ? $vals['DropShadowDistance'] : '25';
  182. $settings['DropShadowScale'] = isset($vals['DropShadowScale']) ? $vals['DropShadowScale'] : '0.95';
  183. $settings['DropShadowBlurX'] = isset($vals['DropShadowBlurX']) ? $vals['DropShadowBlurX'] : '40';
  184. $settings['DropShadowBlurY'] = isset($vals['DropShadowBlurY']) ? $vals['DropShadowBlurY'] : '4';
  185. $settings['MenuDistanceX'] = isset($vals['MenuDistanceX']) ? $vals['MenuDistanceX'] : '20';
  186. $settings['MenuDistanceY'] = isset($vals['MenuDistanceY']) ? $vals['MenuDistanceY'] : '50';
  187. $settings['MenuColor1'] = isset($vals['MenuColor1']) ? $vals['MenuColor1'] : '0x999999';
  188. $settings['MenuColor2'] = isset($vals['MenuColor2']) ? $vals['MenuColor2'] : '0x333333';
  189. $settings['MenuColor3'] = isset($vals['MenuColor3']) ? $vals['MenuColor3'] : '0xFFFFFF';
  190. $settings['ControlSize'] = isset($vals['ControlSize']) ? $vals['ControlSize'] : '100';
  191. $settings['ControlDistance'] = isset($vals['ControlDistance']) ? $vals['ControlDistance'] : '20';
  192. $settings['ControlColor1'] = isset($vals['ControlColor1']) ? $vals['ControlColor1'] : '0x222222';
  193. $settings['ControlColor2'] = isset($vals['ControlColor2']) ? $vals['ControlColor2'] : '0xFFFFFF';
  194. $settings['ControlAlpha'] = isset($vals['ControlAlpha']) ? $vals['ControlAlpha'] : '0.8';
  195. $settings['ControlAlphaOver'] = isset($vals['ControlAlphaOver']) ? $vals['ControlAlphaOver'] : '0.95';
  196. $settings['ControlsX'] = isset($vals['ControlsX']) ? $vals['ControlsX'] : '450';
  197. $settings['ControlsY'] = isset($vals['ControlsY']) ? $vals['ControlsY'] : '280';
  198. $settings['ControlsAlign'] = isset($vals['ControlsAlign']) ? $vals['ControlsAlign'] : 'center';
  199. $settings['TooltipHeight'] = isset($vals['TooltipHeight']) ? $vals['TooltipHeight'] : '31';
  200. $settings['TooltipColor'] = isset($vals['TooltipColor']) ? $vals['TooltipColor'] : '0x222222';
  201. $settings['TooltipTextY'] = isset($vals['TooltipTextY']) ? $vals['TooltipTextY'] : '5';
  202. $settings['TooltipTextStyle'] = isset($vals['TooltipTextStyle']) ? $vals['TooltipTextStyle'] : 'P-Italic';
  203. $settings['TooltipTextColor'] = isset($vals['TooltipTextColor']) ? $vals['TooltipTextColor'] : '0xFFFFFF';
  204. $settings['TooltipMarginLeft'] = isset($vals['TooltipMarginLeft']) ? $vals['TooltipMarginLeft'] : '5';
  205. $settings['TooltipMarginRight'] = isset($vals['TooltipMarginRight']) ? $vals['TooltipMarginRight'] : '7';
  206. $settings['TooltipTextSharpness'] = isset($vals['TooltipTextSharpness']) ? $vals['TooltipTextSharpness'] : '50';
  207. $settings['TooltipTextThickness'] = isset($vals['TooltipTextThickness']) ? $vals['TooltipTextThickness'] : '-100';
  208. $settings['InfoWidth'] = isset($vals['InfoWidth']) ? $vals['InfoWidth'] : '400';
  209. $settings['InfoBackground'] = isset($vals['InfoBackground']) ? $vals['InfoBackground'] : '0xFFFFFF';
  210. $settings['InfoBackgroundAlpha'] = isset($vals['InfoBackgroundAlpha']) ? $vals['InfoBackgroundAlpha'] : '0.95';
  211. $settings['InfoMargin'] = isset($vals['InfoMargin']) ? $vals['InfoMargin'] : '15';
  212. $settings['InfoSharpness'] = isset($vals['InfoSharpness']) ? $vals['InfoSharpness'] : '0';
  213. $settings['InfoThickness'] = isset($vals['InfoThickness']) ? $vals['InfoThickness'] : '0';
  214. $settings['Autoplay'] = isset($vals['Autoplay']) ? $vals['Autoplay'] : '10';
  215. $settings['FieldOfView'] = isset($vals['FieldOfView']) ? $vals['FieldOfView'] : '45';
  216. return $settings;
  217. }
  218. /**
  219. * Provides the default flash settings to profiles
  220. */
  221. function _piecemaker_default_flash_settings() {
  222. $vals = variable_get('piecemaker_default_flash_settings', array('params' => array()));
  223. $pm_path = libraries_get_path('piecemaker');
  224. $settings['width'] = isset($vals['width']) ? $vals['width'] : '900';
  225. $settings['height'] = isset($vals['height']) ? $vals['height'] : '600';
  226. $settings['flashvars']['cssSource'] = isset($vals['flashvars']['cssSource']) ? $vals['flashvars']['cssSource'] : $pm_path . '/piecemaker.css';
  227. $settings['params']['play'] = isset($vals['params']['play']) ? $vals['params']['play'] : 'true';
  228. $settings['params']['menu'] = isset($vals['params']['menu']) ? $vals['params']['menu'] : 'false';
  229. $settings['params']['scale'] = isset($vals['params']['scale']) ? $vals['params']['scale'] : 'showall';
  230. $settings['params']['wmode'] = isset($vals['params']['wmode']) ? $vals['params']['wmode'] : 'transparent';
  231. $settings['params']['allowfullscreen'] = isset($vals['params']['allowfullscreen']) ? $vals['params']['allowfullscreen'] : 'true';
  232. $settings['params']['allowscriptaccess'] = isset($vals['params']['allowscriptaccess']) ? $vals['params']['allowscriptaccess'] : 'always';
  233. $settings['params']['allownetowrking'] = isset($vals['params']['allownetworking']) ? $vals['params']['allownetworking'] : 'true';
  234. $settings['params'] = array_merge($settings['params'], $vals['params']);
  235. return $settings;
  236. }
  237. /**
  238. * Implements hook_theme()
  239. */
  240. function piecemaker_theme() {
  241. $path = drupal_get_path('module', 'piecemaker');
  242. return array(
  243. 'piecemaker' => array(
  244. 'variables' => array('handler' => NULL, 'key' => NULL, 'profile' => array(), 'alternate_callback' => NULL),
  245. 'path' => $path . '/theme',
  246. 'file' => 'theme.inc',
  247. ),
  248. 'piecemaker_transition_form' => array(
  249. 'render element' => 'form',
  250. 'path' => $path . '/theme',
  251. 'file' => 'theme.inc',
  252. ),
  253. 'piecemaker_profile_params' => array(
  254. 'render element' => 'form',
  255. 'path' => $path . '/theme',
  256. 'file' => 'theme.inc',
  257. ),
  258. 'piecemaker_xml' => array(
  259. 'template' => 'piecemaker-xml',
  260. 'path' => $path . '/theme',
  261. 'file' => 'piecemaker.xml.inc',
  262. 'variables' => array('Settings' => array(), 'Transitions' => array(), 'Contents' => array(), 'handler' => array(), 'key' => NULL),
  263. ),
  264. 'piecemaker_xml_node' => array(
  265. 'path' => $path . '/theme',
  266. 'file' => 'piecemaker.xml.inc',
  267. 'variables' => array('item' => array()),
  268. ),
  269. 'piecemaker_xml_node_Image' => array(
  270. 'template' => 'piecemaker-xml-image',
  271. 'path' => $path . '/theme',
  272. 'file' => 'theme.inc',
  273. 'variables' => array('item' => array()),
  274. ),
  275. 'piecemaker_xml_node_Video' => array(
  276. 'template' => 'piecemaker-xml-video',
  277. 'path' => $path . '/theme',
  278. 'file' => 'theme.inc',
  279. 'variables' => array('item' => array()),
  280. ),
  281. 'piecemaker_xml_node_Flash' => array(
  282. 'template' => 'piecemaker-xml-flash',
  283. 'path' => $path . '/theme',
  284. 'file' => 'theme.inc',
  285. 'variables' => array('item' => array()),
  286. ),
  287. );
  288. }
  289. /**
  290. * Ajax callback for admin form
  291. */
  292. function piecemaker_add_transition_ajax($form, $form_state) {
  293. $key = $form_state['#transition_element'];
  294. return $form[$key];
  295. }
  296. /**
  297. * Ajax callback for admin form
  298. */
  299. function piecemaker_add_flash_params($form, $form_state) {
  300. return $form['flash_settings']['params'];
  301. }
  302. /**
  303. * Utility function that allows other modules to get a list of profiles keyed on the pid
  304. *
  305. * @return
  306. * An array of profiles keyed on the pid
  307. */
  308. function piecemaker_profile_options() {
  309. $profiles = &drupal_static(__FUNCTION__);
  310. if (!$profiles) {
  311. $profiles = db_query('SELECT title, pid FROM {piecemaker_profiles}')
  312. ->fetchAllKeyed(1,0);
  313. }
  314. return $profiles;
  315. }
  316. /**
  317. * Implements hook_page_alter()
  318. */
  319. function piecemaker_page_alter(&$page) {
  320. //We add all our piecemaker settings here right before the page renders to ensure that there are no
  321. //array merging errors
  322. $settings = drupal_static('theme_piecemaker_settings');
  323. if (is_array($settings)) {
  324. drupal_add_js($settings, 'setting');
  325. }
  326. }