'jquery_media.settings.inc', 'title' => 'jQuery Media', 'page callback' => 'drupal_get_form', 'page arguments' => array('_jquery_media_settings'), 'access arguments' => array('administer jquery media'), ); $items[JQUERY_MEDIA_DEFAULT_JS_FILEPATH] = array( 'file' => 'jquery_media.jq.inc', 'type' => MENU_CALLBACK, 'access arguments' => array('access content'), 'page callback' => '_jquery_media_default_js_file', ); return $items; } /** * Implements hook_perm */ function jquery_media_perm() { return array('administer jquery media', 'add jquery media to content'); } /** * Implements hook_help */ function jquery_media_help($section) { module_load_include('inc', 'jquery_media', 'jquery_media.settings'); return _jquery_media_help($section); } /** * Attempt to go through jQ first. Then add our files manually. */ function jquery_media_add($options = array()) { static $installed = FALSE; if (module_exists('jq')) { return module_invoke('jq', 'add', 'jquery_media'); } if (!$installed) { drupal_add_js(drupal_get_path('module', 'jquery_media') .'/js/jquery.media.js'); } module_load_include('inc', 'jquery_media', 'jquery_media.jq'); _jquery_media_add($options); return TRUE; } /** * Invoke the plugin if we support it for this node type. */ function jquery_media_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) { switch ($op) { case 'view': $types = variable_get('jquery_media_node_types', array()); if ($types[$node->type]) { jquery_media_add(); } // if (is_array($node->jquery_media)) { // jquery_media_add($node->jquery_media); // } break; case 'delete': // db_query("DELETE FROM {jquery_media_node} WHERE nid=%d", $node->nid); break; case 'update': // db_query("DELETE FROM {jquery_media_node} WHERE nid=%d", $node->nid); // Don't break yet; we may need to insert our new options. case 'insert': // if ($node->jquery_media_insert) { // $node->jquery_media = array(); // // @TODO: Build the node specific options from form. // db_query("INSERT INTO {jquery_media_node} (nid, options) VALUES (%d, '%s')", $node->nid, serialize($node->jquery_media)); // } // unset($node->jquery_media_insert); break; case 'load': // $jquery_media = db_result(db_query("SELECT options FROM {jquery_media_node} WHERE nid = %d", $node->nid)); // if (isset($jquery_media)) { // $node->jquery_media = unserialize($jquery_media); // } break; } } /** * Implement hook_form_alter. * This will add a jQuery Media fieldset to node edit pages, * allowing to enable the plugin from a particular node. */ function jquery_media_form_alter(&$form, $form_state, $form_id) { // if (substr($form_id, -10) == '_node_form') { // if (user_access('add jquery media to content')) { // $node = $form['#node']; // $form['jquery_media_fieldset'] = array( // '#type' => 'fieldset', // '#title' => t('jQuery Media'), // '#collapsible' => TRUE, // '#collapsed' => TRUE, // ); // $form['jquery_media_fieldset']['jquery_media_insert'] = array( // '#type' => 'checkbox', // '#title' => t('Invoke jQuery Media'), // '#default_value' => is_array($node->jquery_media), // ); // $form['jquery_media_fieldset']['jquery_media'] = array( // '#type' => 'value', // '#value' => $node->jquery_media, // ); // // @TODO: Add specific options here, such as w/h. // } // else { // $form['jquery_media_insert'] = array( // '#type' => 'value', // '#value' => is_array($node->jquery_media), // ); // $form['jquery_media'] = array( // '#type' => 'value', // '#value' => $node->jquery_media, // ); // } // } } /** * Implements hook_init(). * Invoke the plugin on any page listed from the configuration page. * Code swiped from block_list */ function jquery_media_init() { $path = drupal_get_path_alias($_GET['q']); $regexp = '/^('. preg_replace(array('/(\r\n?|\n)/', '/\\\\\*/', '/(^|\|)\\\\($|\|)/'), array('|', '.*', '\1'. preg_quote(variable_get('site_frontpage', 'node'), '/') .'\2'), preg_quote(variable_get('jquery_media_pages', ''), '/')) .')$/'; // Compare with the internal and path alias (if any). $page_match = preg_match($regexp, $path); if ($path != $_GET['q']) { $page_match = $page_match || preg_match($regexp, $_GET['q']); } if ($page_match) { jquery_media_add(); } }