t(DASH_PLAYER_NAME . ' Settings'), 'description' => t('Administer the '. DASH_PLAYER_NAME .' on this site.'), 'page callback' => 'drupal_get_form', 'page arguments' => array('dashplayer_settings'), 'access arguments' => array('administer ' . DASH_PLAYER_SYS_NAME) ); return $items; } /** * Implementation of hook_theme() */ function dashplayer_theme() { return array( 'dashplayer_play_flash' => array( 'template' => 'dashplayer', 'arguments' => array('params' => NULL), ), ); } function template_preprocess_dashplayer_play_flash(&$variables) { // Add the Dash Player Interface JavaScript drupal_add_js(drupal_get_path('module', 'dashplayer') .'/dashPlayer.js'); if( $variables['params']['id'] && $variables['params']['connect'] ) { drupal_add_js("dashAddObject( '" . $variables['params']['id'] . "' );", 'inline', 'header'); } $flashvars = ''; $width = 460; $height = 525; $player = ''; $id = 'dashplayer'; foreach($variables['params'] as $param => $value) { $param = strtolower($param); if( $param == 'player' ) { $player = $value; } else if( $param == 'width' ) { $width = $value; } else if( $param == 'height' ) { $height = $value; } else if( $param == 'id' ) { $flashvars .= $param . '=' . $value . '&'; $id = $value; } else { if( $value ) { $flashvars .= $param . '=' . $value . '&'; } } } $flashvars = rtrim($flashvars, '&'); // Creates an absolute path for the player. if( $player !== '' ) { $loader_path = check_url(file_create_url($player)); } else { $loader_path = check_url(variable_get('dashplayer_path', file_create_url(DEFAULT_PLAYER_NAME))); } $variables['flashvars'] = $flashvars; $variables['width'] = $width; $variables['height'] = $height; $variables['player'] = $loader_path; $variables['id'] = $id; } /** * Callback for 'services/browse' */ function dashplayer_settings() { $form['dashplayer_path'] = array( '#title' => t(DASH_PLAYER_NAME .' Path'), '#type' => 'textfield', '#default_value' => variable_get('dashplayer_path', file_create_url(DEFAULT_PLAYER_NAME)), '#maxlength' => 128, '#description' => t('The path to the ' . DASH_PLAYER_NAME), '#required' => TRUE ); return system_settings_form($form); } /** * Implementation of hook_service() */ function dashplayer_service() { return array( array( '#method' => 'dashplayer.getView', '#callback' => 'dashplayer_get_view', '#key' => FALSE, '#args' => array( array( '#name' => 'view_name', '#type' => 'string', '#description' => t('View name.')), array( '#name' => 'limit', '#type' => 'int', '#optional' => TRUE, '#description' => t('The limit for the view to show.')), array( '#name' => 'page', '#type' => 'int', '#optional' => TRUE, '#description' => t('The page number to show.')), array( '#name' => 'args', '#type' => 'array', '#optional' => TRUE, '#description' => t('An array of arguments to pass to the view.')) ), '#return' => 'array', '#help' => t('Retrieves a view defined in views.module.') ), array( '#method' => 'dashplayer.incrementNodeCounter', '#callback' => 'dashplayer_increment_node_counter', '#args' => array( array( '#name' => 'nid', '#type' => 'int', '#description' => t('The node to increment the counter for.')) ), '#return' => 'int', '#help' => t('Increments the node counter for any given node.') ), array( '#method' => 'dashplayer.getDrupalVersion', '#callback' => 'dashplayer_get_drupal_version', '#key' => FALSE, '#return' => 'int', '#help' => t('Returns the correct drupal version.') ) ); } function dashplayer_nodeapi(&$node, $op, $teaser) { // Only if the node type is enabled. switch ($op) { case 'load': $additions = array(); if (module_exists('statistics') && variable_get('statistics_count_content_views', 0)) { $node_count = db_result(db_query("SELECT totalcount FROM {node_counter} WHERE nid=%d", $node->nid)); $additions['node_counter'] = number_format($node_count); } // We need to add a type to the taxonomy so that the Dash Media Player can figure out which // taxonomy vocabularies are "free tagging" vocabularies. if( module_exists('taxonomy') && module_exists('tagging_service') ) { $vid = db_result(db_query("SELECT v.vid FROM {vocabulary} v LEFT JOIN {vocabulary_node_types} vt ON v.vid=vt.vid WHERE vt.type='%s' AND v.tags=1", $node->type)); if( $vid ) { $additions['tagging_vid'] = $vid; } } // Here we need to look for images attached to this node... if( module_exists('image_attach') ) { $image_nodes = db_query("SELECT iid FROM {image_attach} WHERE nid=%d", $node->nid); while($image_node = db_fetch_object($image_nodes)) { $images = db_query("SELECT f.* FROM {files} f LEFT JOIN {image} img ON img.fid=f.fid WHERE img.nid=%d AND (f.filemime='jpg' OR f.filemime='jpeg' OR f.filemime='png' OR f.filemime='gif' OR f.filemime='image/jpeg' OR f.filemime='image/jpg' OR f.filemime='image/png' OR f.filemime='image/gif')", $image_node->iid); while( $image = db_fetch_object($images)) { $additions['dashplayer_images'][] = $image; } } } return $additions; } } function dashplayer_increment_node_counter( $nid ) { if( $nid && module_exists('statistics') && variable_get('statistics_count_content_views', 0) ) { db_query('UPDATE {node_counter} SET daycount = daycount + 1, totalcount = totalcount + 1, timestamp = %d WHERE nid = %d', time(), $nid); if (!db_affected_rows()) { db_query('INSERT INTO {node_counter} (nid, daycount, totalcount, timestamp) VALUES (%d, 1, 1, %d)', $nid, time()); } return db_result(db_query("SELECT totalcount FROM {node_counter} WHERE nid=%d", $nid)); } else { return 0; } } function dashplayer_get_drupal_version() { return 6; } /** * Get a view from the database. */ function dashplayer_get_view($view_name, $limit = 0, $page = 0, $args = array()) { $view = views_get_view($view_name); if (is_null($view)) { return services_error('View does not exist.'); } // Check access if (!views_access($view)) { return services_error('You do not have access to this view.'); } $view->set_use_pager(FALSE); $view->set_items_per_page($limit); $view->set_offset($page*$limit); $view->set_arguments($args); $view->get_total_rows = TRUE; $view->execute(); foreach ($view->result as $node) { // Not ready for this quite yet... want more people to upgrade players first. //$nodes[] = services_node_load(node_load($node->nid), $fields); $nodes['nodes'][] = services_node_load(node_load($node->nid), $fields); } $nodes['total_rows'] = $view->total_rows; return $nodes; } function dashplayer_get_player($params) { print theme('dashplayer_play_flash', $params); }