PageRenderTime 27ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/modules/media/bpm_pdf_embed/loader.php

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