| [ Index ] |
PHP Cross Reference of Drupal 6 (yi-drupal) |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * @file 5 * Provides wrapper functions for the s3 amazon webservices. 6 */ 7 /* 8 * Implementation of hook_perm(). 9 */ 10 function video_s3_perm() { 11 return array('administer amazon s3'); 12 } 13 14 /* 15 * Implmentation of hook_help(). 16 */ 17 18 function video_s3_help($path, $arg) { 19 switch ($path) { 20 case 'admin/settings/video/amazon_s3': 21 $output = t('Use Amazon Simple Storage Service (Amazon S3) to store your video files. This frees up bandwidth from your site, providing a faster experience for your users. Simply enable this module and enter your authentication details and you\'re done!'); 22 return $output; 23 } 24 } 25 26 /* 27 * Implementation of hook_menu(). 28 */ 29 30 function video_s3_menu() { 31 $items = array(); 32 $items['admin/settings/video/amazon_s3/bucket/%/delete'] = array( 33 'title' => 'Delete Bucket', 34 'page callback' => 'video_s3_bucket_delete', 35 'page arguments' => array(5), 36 'access arguments' => array('administer amazon s3'), 37 'file' => 'video_s3.admin.inc', 38 'type' => MENU_CALLBACK, 39 ); 40 return $items; 41 } 42 43 /* 44 * Implementation of hook_cron(). 45 */ 46 47 function video_s3_cron() { 48 if (!_video_s3_is_active_fs()) { 49 return; 50 } 51 52 module_load_include('lib.inc', 'video_s3'); 53 $s3 = new video_amazon_s3(); 54 $s3->connect(); 55 // Lets run our queue. 56 $s3->queue(); 57 } 58 59 /** 60 * Implementation of hook_video_delete. 61 * we can use hook_file_delete() 62 */ 63 function video_s3_video_delete($file) { 64 module_load_include('lib.inc', 'video_s3'); 65 $s3 = new video_amazon_s3(); 66 $s3->connect(); 67 // Lets run our queue. 68 $s3->delete($file->fid); 69 } 70 71 /** 72 * Implementation of hook_video_update. 73 * Submit handler to update our s3 table to include the node id. 74 */ 75 function video_s3_video_update($form, &$form_state) { 76 //lets update our video rending table to include the node id created 77 if (isset($form_state['nid']) && isset($form_state['values']['video_id']) && is_array($form_state['values']['video_id'])) { 78 foreach ($form_state['values']['video_id'] as $fid) { 79 //lets update our table to include the nid 80 db_query("UPDATE {video_s3} SET nid=%d WHERE fid=%d", $form_state['nid'], $fid); 81 } 82 } 83 } 84 85 /** 86 * Implementing hook_video_insert 87 * @param <type> $element 88 * @param <type> $form_state 89 */ 90 function video_s3_video_insert(&$element, &$form_state) { 91 if (!_video_s3_is_active_fs()) { 92 return; 93 } 94 95 $file = $element['#value']; 96 //we need to check if this fid has already been added to the database AND that there is in fact a fid 97 if (is_array($file) && isset($file['fid']) && !empty($file['fid'])) { 98 module_load_include('lib.inc', 'video_s3'); 99 $s3 = new video_amazon_s3(); 100 $s3->connect(); 101 // Lets verify that we haven't added this video already. Multiple validation fails will cause this to be ran more than once 102 if (!$video = $s3->verify($file['fid'])) { 103 // Video has not been added to the queue yet so lets add it. 104 $s3->insert($file['fid']); 105 drupal_set_message(t('Video submission queued for transfer to your Amazon S3 server. Will be there shortly.')); 106 } 107 } 108 } 109 110 function video_s3_get_object_info($object) { 111 module_load_include('lib.inc', 'video_s3'); 112 $s3 = new video_amazon_s3(); 113 $s3->connect(); 114 return $s3->get_object_info($object); 115 } 116 117 /** 118 * @param string $objectUri 119 * @deprecated Use video_amazon_s3::get_authenticated_url($objectUri) 120 */ 121 function video_s3_get_authenticated_url($objectUri) { 122 module_load_include('lib.inc', 'video_s3'); 123 $s3 = new video_amazon_s3(); 124 $s3->connect(); 125 return $s3->get_authenticated_url($objectUri); 126 } 127 128 function video_s3_get_object($object, $save_to = false) { 129 module_load_include('lib.inc', 'video_s3'); 130 $s3 = new video_amazon_s3(); 131 $s3->connect(); 132 return $s3->get_object($object, $save_to); 133 } 134 135 /* 136 * Deletes a bucket from your Amazon S3 server. 137 */ 138 139 function video_s3_bucket_delete($bucket) { 140 module_load_include('lib.inc', 'video_s3'); 141 $s3 = new video_amazon_s3(); 142 $s3->connect(); 143 $buckets = $s3->s3->listBuckets(); 144 if (is_array($buckets) && in_array($bucket, $buckets)) { 145 if ($s3->s3->deleteBucket($bucket)) { 146 drupal_set_message(t('Successfully deleted the bucket %bucket', array('%bucket' => $bucket))); 147 } else { 148 drupal_set_message(t('Could not delete the bucket %bucket', array('%bucket' => $bucket)), 'error'); 149 } 150 } else { 151 drupal_set_message(t('The bucket %bucket does not exist for deletion.', array('%bucket' => $bucket)), 'error'); 152 } 153 drupal_goto('admin/settings/video/amazon_s3'); 154 } 155 156 function _video_s3_is_active_fs() { 157 return variable_get('vid_filesystem', 'drupal') === 'video_s3'; 158 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Mon Jul 9 18:01:44 2012 | Cross-referenced by PHPXref 0.7 |