PageRenderTime 46ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/modules/media/bpm_audio_embed/loader.php

http://buddypress-media.googlecode.com/
PHP | 792 lines | 289 code | 197 blank | 306 comment | 34 complexity | e988477dc592c0f691749ed6b9b1741e MD5 | raw file
Possible License(s): AGPL-1.0, Apache-2.0, GPL-2.0, LGPL-2.1
  1. <?php
  2. /**
  3. * MEDIA MODULE - BPM Embedded Audio
  4. *
  5. * @version 0.1.9
  6. * @since 0.1.9
  7. * @package BP-Media
  8. * @subpackage Media Modules
  9. * @license GPL v2.0
  10. * @link http://code.google.com/p/buddypress-media/
  11. *
  12. * ========================================================================================================
  13. */
  14. class BPMM_audioEmbed extends BPM_mediaModule_base implements iBPM_mediaModule {
  15. var $name = "Audio - Embed"; // Human readable name for this module
  16. var $slug = "bpm_audio_embed"; // Internal slug for this module
  17. // ============================================================================================================ //
  18. /**
  19. * Returns the human-readable name of the media module. This is displayed in the admin interface.
  20. * Example: "Video Gallery"
  21. *
  22. * @version 0.1.9
  23. * @since 0.1.9
  24. * @return string | Media module admin name
  25. */
  26. public function getName(){
  27. return $this->name;
  28. }
  29. /**
  30. * Returns the url-safe slug for the media module. Must be unique from all other
  31. * media modules installed on the system. Example: "bpm_photo"
  32. *
  33. * @version 0.1.9
  34. * @since 0.1.9
  35. * @return string | Media module slug
  36. */
  37. public function getSlug(){
  38. return $this->slug;
  39. }
  40. /**
  41. * Returns the guid of the media module as assigned by the database
  42. *
  43. * @version 0.1.9
  44. * @since 0.1.9
  45. * @return int | Media module id
  46. */
  47. public function getId(){
  48. global $bpm;
  49. $result = $bpm->mediaModules->getBySlug( $this->slug );
  50. return $result["module_id"];
  51. }
  52. /**
  53. * Returns the HTTP path to the module's icon. Icons MUST be 64px*64px .PNG files.
  54. *
  55. * @version 0.1.9
  56. * @since 0.1.9
  57. * @return string | path to icon file
  58. */
  59. public function getIconPath(){
  60. return BPM_URL_BASE . "/modules/media/bpm_audio_embed/admin/icon.png";
  61. }
  62. /**
  63. * Returns a short (30 words) description of what the media module does.
  64. *
  65. * @version 0.1.9
  66. * @since 0.1.9
  67. * @return string | description
  68. */
  69. public function getDesc(){
  70. return __("The embedded audio module lets BP-Media embed streaming audio files from any website that has
  71. oEmbed capability, including SoundCloud, AudioFarm, and ccMixter.","bp-media");
  72. }
  73. /**
  74. * Returns the media module's version number. 64 chars max.
  75. *
  76. * @version 0.1.9
  77. * @since 0.1.9
  78. * @return string | version number
  79. */
  80. public static function getVersion(){
  81. return "0.1.0";
  82. }
  83. /**
  84. * Returns a composited HTML string, including the name of the content module developer
  85. * and a link to their personal or company website.
  86. *
  87. * @version 0.1.9
  88. * @since 0.1.9
  89. * @return string | version number
  90. */
  91. public function getAuthor(){
  92. return "<a href='http://code.google.com/p/buddypress-media/'>The BP-Media Team</a>";
  93. }
  94. /**
  95. * Returns a composited HTML string containing a link to the media module's support page, or dedicated
  96. * project site. Example: <a href='http://code.google.com/p/buddypress-media/'>The BP-Media Team</a>
  97. *
  98. * @version 0.1.9
  99. * @since 0.1.9
  100. * @return string | version number
  101. */
  102. public static function getSite(){
  103. return "<a href='http://code.google.com/p/buddypress-media/'>Support Forum</a>";
  104. }
  105. /**
  106. * Performs all of the media module's installation operations
  107. *
  108. * @version 0.1.9
  109. * @since 0.1.9
  110. * @return bool | True on success. False on failure.
  111. */
  112. public function install(){
  113. global $bpm;
  114. // Load the base install classes
  115. $bpm->config->installMode();
  116. $cls = new BPM_mediaModule_install_base( $slug=self::getSlug(), $name=self::getName(), $php_class=get_class($this) );
  117. // Add 'settings' page keys and set default values
  118. $settings_ok = $cls->settings($error);
  119. if(!$settings_ok){
  120. $error_string = "Media module install error during 'settings'";
  121. $error_string .= " Module class: " . get_class($this);
  122. $error_string .= " Failed keys: " . implode(",", $error) . "\n";
  123. trigger_error($error_string);
  124. }
  125. // Add 'templates' page keys and set default values
  126. $templates_ok = $cls->templates($error);
  127. if(!$settings_ok){
  128. $error_string = "Media module install error during 'templates'";
  129. $error_string .= " Module class: " . get_class($this);
  130. $error_string .= " Failed keys: " . implode(",", $error) . "\n";
  131. trigger_error($error_string);
  132. }
  133. // Add module-specific keys
  134. // ============================================
  135. if(!$bpm->config->createKey( $tree="mediaModules",
  136. $branch = self::getSlug(),
  137. $key="actionName",
  138. $val="Embedded Audio",
  139. $filter="i18nString",
  140. $ctrl=null,
  141. $error=null)
  142. ) {$result[]=$key;}
  143. if(!$bpm->config->createKey( $tree="mediaModules",
  144. $branch = self::getSlug(),
  145. $key="actionDescription",
  146. $val="Embed an audio file from another website",
  147. $filter="i18nString",
  148. $ctrl=null,
  149. $error=null)
  150. ) {$result[]=$key;}
  151. if(!$bpm->config->createKey( $tree="mediaModules",
  152. $branch = self::getSlug(),
  153. $key="thumbMasterX",
  154. $val=640,
  155. $filter="int",
  156. $ctrl=null,
  157. $error=null)
  158. ) {$result[]=$key;}
  159. if(!$bpm->config->createKey( $tree="mediaModules",
  160. $branch = self::getSlug(),
  161. $key="thumbMasterY",
  162. $val=640,
  163. $filter="int",
  164. $ctrl=null,
  165. $error=null)
  166. ) {$result[]=$key;}
  167. if(!$bpm->config->createKey( $tree="mediaModules",
  168. $branch = self::getSlug(),
  169. $key="thumbFormat",
  170. $val="JPG",
  171. $filter="textAndNumbers",
  172. $ctrl=null,
  173. $error=null)
  174. ) {$result[]=$key;}
  175. if(!$bpm->config->createKey( $tree="mediaModules",
  176. $branch = self::getSlug(),
  177. $key="thumbQuality",
  178. $val=80,
  179. $filter="int",
  180. $ctrl=null,
  181. $error=null)
  182. ) {$result[]=$key;}
  183. if(!$bpm->config->createKey( $tree="mediaModules",
  184. $branch = self::getSlug(),
  185. $key="thumbDefaultPath",
  186. $val= BPM_PATH_MEDIA_MODULES . "/" . self::getSlug(). "/templates/default_thumb.png",
  187. $filter="fileStringLocal",
  188. $ctrl=null,
  189. $error=null)
  190. ) {$result[]=$key;}
  191. if(!$bpm->config->createKey( $tree="mediaModules",
  192. $branch = self::getSlug(),
  193. $key="enabledHosts",
  194. $val=array(
  195. "ccMixter"=>true,
  196. "SoundCloud"=>true,
  197. "AudioFarm"=>true
  198. ),
  199. $filter="arraySimple",
  200. $ctrl=null,
  201. $error=null)
  202. ) { $result[] = $key; }
  203. if( count($result) == 0) {
  204. $custom_ok = true;
  205. }
  206. else {
  207. $custom_ok = false;
  208. $error_string = "Media module install error during 'custom settings'";
  209. $error_string .= " Module class: " . get_class($this);
  210. $error_string .= " Failed keys: " . implode(",", $result) . "\n";
  211. trigger_error($error_string);
  212. }
  213. // Activate the module and return result
  214. if($settings_ok && $templates_ok && $custom_ok){
  215. $activate_ok = $bpm->mediaModules->activateBySlug( self::getSlug() );
  216. return $activate_ok;
  217. }
  218. else {
  219. return false;
  220. }
  221. }
  222. /**
  223. * Performs all of the media module's uninstallation operations. Completely
  224. * removes the module from the system, and deletes all items stored within
  225. * medias that this module owns.
  226. *
  227. * @version 0.1.9
  228. * @since 0.1.9
  229. * @return bool | True on success. False on failure.
  230. */
  231. public function uninstall(){
  232. global $bpm;
  233. // Load the base uninstall classes
  234. $bpm->config->uninstallMode();
  235. $cls = new BPM_mediaModule_uninstall_base( $slug=self::getSlug(), $name=self::getName(), $php_class=get_class($this) );
  236. // Remove 'settings' page keys
  237. $settings_ok = $cls->settings($error);
  238. if(!$settings_ok){
  239. $error_string = "Media module uninstall error during 'settings'";
  240. $error_string .= " Module class: " . get_class($this);
  241. $error_string .= " Failed keys: " . implode(",", $error) . "\n";
  242. trigger_error($error_string);
  243. }
  244. // Remove 'templates' page keys
  245. $templates_ok = $cls->templates($error);
  246. if(!$settings_ok){
  247. $error_string = "Media module uninstall error during 'templates'";
  248. $error_string .= " Module class: " . get_class($this);
  249. $error_string .= " Failed keys: " . implode(",", $error) . "\n";
  250. trigger_error($error_string);
  251. }
  252. // Remove module-specific keys
  253. if(!$bpm->config->dropKey( $tree="mediaModules",
  254. $branch = self::getSlug(),
  255. $key="actionName")
  256. ) {$result[]=$key;}
  257. if(!$bpm->config->dropKey( $tree="mediaModules",
  258. $branch = self::getSlug(),
  259. $key="actionDescription")
  260. ) {$result[]=$key;}
  261. if(!$bpm->config->dropKey( $tree="mediaModules",
  262. $branch = self::getSlug(),
  263. $key="thumbMasterX")
  264. ) {$result[]=$key;}
  265. if(!$bpm->config->dropKey( $tree="mediaModules",
  266. $branch = self::getSlug(),
  267. $key="thumbMasterY")
  268. ) {$result[]=$key;}
  269. if(!$bpm->config->dropKey( $tree="mediaModules",
  270. $branch = self::getSlug(),
  271. $key="thumbFormat")
  272. ) {$result[]=$key;}
  273. if(!$bpm->config->dropKey( $tree="mediaModules",
  274. $branch = self::getSlug(),
  275. $key="thumbQuality")
  276. ) {$result[]=$key;}
  277. if(!$bpm->config->dropKey( $tree="mediaModules",
  278. $branch = self::getSlug(),
  279. $key="thumbDefaultPath")
  280. ) {$result[]=$key;}
  281. if(!$bpm->config->createKey( $tree="mediaModules",
  282. $branch = self::getSlug(),
  283. $key="enabledHosts")
  284. ) { $result[] = $key; }
  285. if( count($result) == 0) {
  286. $custom_ok = true;
  287. }
  288. else {
  289. $custom_ok = false;
  290. $error_string = "Media module uninstall error during 'custom settings'";
  291. $error_string .= " Module class: " . get_class($this);
  292. $error_string .= " Failed keys: " . implode(",", $result) . "\n";
  293. trigger_error($error_string);
  294. }
  295. // Delete the module's content and return result
  296. if($settings_ok && $templates_ok && $custom_ok){
  297. // Delete all of the module's albums, items, and content
  298. $delete_ok = $bpm->mediaModules->deleteBySlug( self::getSlug() );
  299. return $delete_ok;
  300. }
  301. else {
  302. return false;
  303. }
  304. }
  305. /**
  306. * Adds scripts used by the media module to the admin page header
  307. *
  308. * @version 0.1.9
  309. * @since 0.1.9
  310. * @param string $tab | Name of the admin tab the plugin is rendering
  311. */
  312. public function enqueueAdminScripts($tab){
  313. // BP-Media has centralized script management. See: /core/js/register.scripts.php
  314. // ==============================================================================
  315. // Loading a custom script
  316. // ===============================================
  317. // $file_path = BPM_URL_MEDIA_MODULES . "/" . self::getSlug() . "/admin/transcoder.js";
  318. // wp_register_script('BPMM_tab_transcoder', $file_path);
  319. // wp_enqueue_script( 'BPMM_tab_transcoder');
  320. switch($tab) {
  321. case "BPMM_tab_settings" : {
  322. } break;
  323. // Handle landing on default tab
  324. case null : {
  325. } break;
  326. // Handle all other tabs
  327. default : {
  328. } break;
  329. }
  330. }
  331. /**
  332. * Adds CSS styles used by the media module to the admin page header
  333. *
  334. * @version 0.1.9
  335. * @since 0.1.9
  336. * @param string $tab | Name of the admin tab the plugin is rendering
  337. */
  338. public function enqueueAdminStyles($tab){
  339. // Enqueue a custom style
  340. // ==============================================================================
  341. // $file_path = BPM_URL_MEDIA_MODULES . "/" . self::getSlug() . "/admin/transcoder.css";
  342. // wp_enqueue_style( self::getSlug(), $file_path, false, '2.8.1', 'screen' );
  343. switch($tab) {
  344. case "BPMM_tab_settings" : {
  345. } break;
  346. // Handle landing on default tab
  347. case null : {
  348. } break;
  349. // Handle all other tabs
  350. default : {
  351. } break;
  352. }
  353. }
  354. /**
  355. * Adds scripts used by the media module to the site page header
  356. *
  357. * @version 0.1.9
  358. * @since 0.1.9
  359. * @param string $page | Name of the site page the plugin is rendering
  360. */
  361. public function enqueueSiteScripts($page){
  362. return $page;
  363. }
  364. /**
  365. * Adds CSS styles used by the media module to the site page header
  366. *
  367. * @version 0.1.9
  368. * @since 0.1.9
  369. * @param string $page | Name of the site page the plugin is rendering
  370. */
  371. public function enqueueSiteStyles($page){
  372. return $page;
  373. }
  374. /**
  375. * Media module init function. Media modules place their hook and filter functions in the init
  376. * function inside their class. When the core loads media modules, it fires the init function in each
  377. * media module, attaching the module's functions to the core.
  378. *
  379. * @version 0.1.9
  380. * @since 0.1.9
  381. */
  382. public function init(){
  383. return true;
  384. }
  385. /**
  386. * Specifies the view structure of the module's screens
  387. *
  388. * @version 0.1.9
  389. * @since 0.1.9
  390. * @return array | mixed
  391. */
  392. public function viewStructure(){
  393. $result = array(
  394. "site"=>array("type"=>"page", "views"=>array("visitor") ),
  395. "profile"=>array("type"=>"page","views"=>array("visitor") ),
  396. "tab"=>array("type"=>"page","views"=>array("visitor") )
  397. );
  398. return $result;
  399. }
  400. /**
  401. * Processes a media item and returns relevant data to the media item manager
  402. *
  403. * @version 0.1.9
  404. * @since 0.1.9
  405. *
  406. * @param mixed $media_object | Media object (file handle or URL) to process
  407. * @param array $options | Array of options that controls how the module processes the item
  408. * @param array &$error | Array numeric error code and text error string
  409. * @return bool/array | False on failure. Media item data array on success.
  410. */
  411. public function processItem($media_object, $options, &$error=null){
  412. return true;
  413. }
  414. /**
  415. * Deletes the master content for a media item. This is implemented in the individual media
  416. * modules instead of the plugin core so that media modules which host content on 3rd-party
  417. * servers (Amazon S3, etc) can connect to the remote server's API and delete the item.
  418. *
  419. * @version 0.1.9
  420. * @since 0.1.9
  421. *
  422. * @param array $media_item | Full database record of the item being deleted
  423. * @param array &$error | Error data returned on failure
  424. * @return bool | False on failure. True on success
  425. */
  426. public function deleteItem($media_item, &$error=null){
  427. return true;
  428. }
  429. /**
  430. * Renders the configuration page for a media module, as seen on the admin
  431. * "media modules" screen.
  432. *
  433. * @version 0.1.9
  434. * @since 0.1.9
  435. * @return string | composited HTML block
  436. */
  437. public function adminConfigPage(){
  438. global $bpm;
  439. require ( dirname( __FILE__ ) . '/admin/loader.php' );
  440. $current_page = new BPMM_admin_loader( new self() );
  441. }
  442. /**
  443. * Renders the configuration page for a media module, as seen on the user's
  444. * site settings screens.
  445. *
  446. * @version 0.1.9
  447. * @since 0.1.9
  448. * @return string | composited HTML block
  449. */
  450. public function userConfigPage(){
  451. }
  452. /**
  453. * Renders the HTML block for the page a user sees when they create a new
  454. * instance of an media type owned by the media module.
  455. *
  456. * @version 0.1.9
  457. * @since 0.1.9
  458. * @param ?
  459. * @return string | composited HTML block
  460. */
  461. public function render_createMedia(){
  462. }
  463. /**
  464. * Renders the HTML block for an upload page when items are uploaded to an
  465. * media type owned by the media module.
  466. *
  467. * @version 0.1.9
  468. * @since 0.1.9
  469. * @param ?
  470. * @return string | composited HTML block
  471. */
  472. public function render_uploadItem(){
  473. }
  474. /**
  475. * Renders the HTML block for the page a user sees when they edit an
  476. * instance of an media type owned by the media module.
  477. *
  478. * @version 0.1.9
  479. * @since 0.1.9
  480. * @param ?
  481. * @return string | composited HTML block
  482. */
  483. public function render_editMedia(){
  484. }
  485. /**
  486. * Renders the HTML block for the page a user sees when they edit an individual
  487. * media item within an instance of an media type owned by the media module.
  488. *
  489. * @version 0.1.9
  490. * @since 0.1.9
  491. * @param ?
  492. * @return string | composited HTML block
  493. */
  494. public function render_editItem(){
  495. }
  496. /**
  497. * Renders the HTML block for the first page of items a user sees when they
  498. * view an instance of an media type owned by the media module.
  499. *
  500. * @version 0.1.9
  501. * @since 0.1.9
  502. * @param ?
  503. * @return string | composited HTML block
  504. */
  505. public function render_landingPage(){
  506. }
  507. /**
  508. * Renders the HTML block for for the second and subsequent pages of items a user
  509. * sees when they view an instance of an media type owned by the media module.
  510. *
  511. * @version 0.1.9
  512. * @since 0.1.9
  513. * @param ?
  514. * @return string | composited HTML block
  515. */
  516. public function render_galleryPage(){
  517. }
  518. /**
  519. * Renders the HTML block for the page a user sees when they view an individual
  520. * item within an media instance owned by the media module.
  521. *
  522. * @version 0.1.9
  523. * @since 0.1.9
  524. * @param ?
  525. * @return string | composited HTML block
  526. */
  527. public function render_singlePage(){
  528. }
  529. /**
  530. * Renders the HTML block for the page a user sees when they sort items within
  531. * an media instance owned by the media module.
  532. *
  533. * @version 0.1.9
  534. * @since 0.1.9
  535. * @param ?
  536. * @return string | composited HTML block
  537. */
  538. public function render_sortPage(){
  539. }
  540. /**
  541. * Renders the HTML block for the page a user sees when they apply user tags to a
  542. * media item within an media instance owned by the media module.
  543. *
  544. * @version 0.1.9
  545. * @since 0.1.9
  546. * @param ?
  547. * @return string | composited HTML block
  548. */
  549. public function render_userTagPage(){
  550. }
  551. /**
  552. * Renders the HTML block for the page a user sees when they apply keyword tags to
  553. * a media item within an media instance owned by the media module.
  554. *
  555. * @version 0.1.9
  556. * @since 0.1.9
  557. * @param ?
  558. * @return string | composited HTML block
  559. */
  560. public function render_keywordTagPage(){
  561. }
  562. /**
  563. * Renders the HTML block for the page a user sees when they add geotagging info to
  564. * a media item within an media instance owned by the media module.
  565. *
  566. * @version 0.1.9
  567. * @since 0.1.9
  568. * @param ?
  569. * @return string | composited HTML block
  570. */
  571. public function render_geoTagPage(){
  572. }
  573. /**
  574. * Renders the HTML block for the page a user sees when they add licensing info to
  575. * a media item within an media instance owned by the media module.
  576. *
  577. * @version 0.1.9
  578. * @since 0.1.9
  579. * @param ?
  580. * @return string | composited HTML block
  581. */
  582. public function render_licenseTagPage(){
  583. }
  584. public function register(){
  585. global $bpm;
  586. $slug = $this->getSlug();
  587. $name = $this->getName();
  588. $php_class = get_class($this);
  589. $bpm->mediaModules->register($slug, $name, $php_class);
  590. }
  591. }
  592. $temp = new BPMM_audioEmbed();
  593. $temp->register();
  594. unset($temp);
  595. ?>