('admin/settings/' . DASH_PLAYER_SYS_NAME),
'title' => t(DASH_PLAYER_NAME . ' Settings'),
'description' => t('Administer the '. DASH_PLAYER_NAME .' on this site.'),
'callback' => 'drupal_get_form',
'callback arguments' => array('dashplayer_settings'),
'access' => user_access('administer ' . DASH_PLAYER_SYS_NAME),
'type' => MENU_NORMAL_ITEM
);
}
return $items;
}
/**
* 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.setUserStatus',
'#callback' => 'dashplayer_user_set_status',
'#key' => FALSE,
'#args' => array(
array(
'#name' => 'verb',
'#type' => 'string',
'#description' => t('What this person is doing. "Travis is listening to."')),
array(
'#name' => 'noun',
'#type' => 'string',
'#description' => t('The noun associated with the verb. "Travis is listening to music"'))
),
'#return' => 'bool',
'#help' => t('Returns if a successful status was made.')
),
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_user_set_status( $verb, $noun) {
global $user;
if( $user->uid ) {
// Look for an existing status by looking for the same user & verb.
if( db_result( db_query("SELECT COUNT(*) FROM {dashplayer_user} WHERE uid=%d", $user->uid )) > 0 ) {
// We just need to update the current status.
db_query( "UPDATE {dashplayer_user} SET verb='%s', noun='%s' WHERE uid=%d", $verb, $noun, $user->uid );
}
else {
// Insert a new user status into the dashplayer_user database.
db_query( "INSERT INTO {dashplayer_user} (uid, verb, noun) VALUES (%d, '%s', '%s')", $user->uid, $verb, $noun );
}
}
return true;
}
function dashplayer_user_get_status( $uid )
{
return db_fetch_object( db_query( "SELECT * FROM {dashplayer_user} WHERE uid=%d", $uid ) );
}
/**
* Implementation of hook_token_list().
*/
function dashplayer_token_list($type = 'all') {
if ($type == 'user' || $type == 'all') {
$tokens['user']['user-verb'] = t('What this person is doing. "Travis is listening to."');
$tokens['user']['user-noun'] = t('The noun associated with the verb. "Travis is listening to music"');
return $tokens;
}
}
/**
* Implementation of hook_token_values().
*/
function dashplayer_token_values($type, $object = NULL) {
switch ($type) {
case 'user':
case 'all' :
// Get the user...
if (isset($object)) {
$object = (object)$object;
$uid = $object->uid;
}
else {
global $user;
$uid = $user->uid;
}
// Get the user status.
$status = dashplayer_user_get_status( $uid );
// Set the verb and noun of this token.
$values['user-verb'] = check_plain( $status->verb );
$values['user-noun'] = check_plain( $status->noun );
return $values;
}
}
function dashplayer_nodeapi(&$node, $op, $teaser, $page) {
// Only if the node type is enabled.
global $base_url;
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;
}
}
if( $node->audio_file ) {
$additions["field_dashplayer_media"][0]["value"] = $base_url . "/" . $node->audio_file["file_path"];
}
// 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 * FROM {files} WHERE nid=%d AND
(filemime='jpg' OR
filemime='jpeg' OR
filemime='png' OR
filemime='gif' OR
filemime='image/jpeg' OR
filemime='image/jpg' OR
filemime='image/png' OR
filemime='image/gif')", $image_node->iid);
while( $image = db_fetch_object($images)) {
$additions['dashplayer_images'][] = $image;
}
}
}
if( module_exists('flashvideo_s3') ) {
$video = flashvideo_get_video( $node, array(), TRUE );
if( $video != "" ) {
$additions["field_dashplayer_media"][0]["value"] = $video;
}
$image = flashvideo_get_thumbnail( $node, array(), TRUE );
if( $image != "" ) {
$additions["field_dashplayer_image"][0]["value"] = $image;
}
}
if( module_exists('audio') ) {
if( $node->audio_file ) {
$additions["dashplayer_media"]["filepath"] = $node->audio_file->file_path;
}
}
if( module_exists('emfield') ) {
foreach( $node as $fieldname => $field ) {
// If this is a CCK field.
if( strpos( $fieldname, 'field_' ) === 0 ) {
// If the asset exists.
if( ($field[0]["provider"] == "youtube") || ($field[0]["provider"] == "google") ) {
$newfile["path"] = $field[0]["data"]["thumbnail"]["url"];
$newfile["filename"] = $field[0]["data"]["thumbnail"]["url"];
$additions["dashplayer_media"][] = $newfile;
$newfile["path"] = $field[0]["data"]["flash"]["url"];
$newfile["filename"] = $field[0]["data"]["flash"]["url"];
$newfile["mediatype"] = "youtube";
$additions["dashplayer_media"][] = $newfile;
}
}
}
}
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 5;
}
/**
* 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.');
}
$result = views_build_view('result', $view, $args, false, 0, 0);
$nodes['total_rows'] = $view->num_rows;
$result = views_build_view('result', $view, $args, false, $limit, $page);
while ($node = db_fetch_object($result['result'])) {
$nodes['nodes'][] = services_node_load(node_load(array('nid' => $node->nid)), array());
}
return $nodes;
}
function dashplayer_get_player($params) {
print theme('dashplayer_play_flash', $params);
}
/**
* Play videos from in FLV Flash video format
*
* @param $node
* object with node information
*
* @return
* string of content to display
*/
function theme_dashplayer_play_flash($params) {
// Add the Dash Player Interface JavaScript
drupal_add_js(drupal_get_path('module', 'dashplayer') .'/dashPlayer.js');
if( !$params['id'] ) {
$params['id'] = "dashplayer";
}
if( $params['connect'] ) {
drupal_add_js("dashAddObject( '" . $params['id'] . "' );", 'inline', 'header');
}
$flashvars = '';
$width = 652;
$height = 432;
$player = '';
$id = 'dashplayer';
foreach($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)));
}
$output .= '' . "\n";
return $output;
}