Advertisement
Guest User

Untitled

a guest
Jun 11th, 2012
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 8.00 KB | None | 0 0
  1. <?php
  2. /**
  3.  * name: Post Audio
  4.  * description: Add an mp3 to Posts
  5.  * version: 0.1
  6.  * folder: post_audio
  7.  * class: PostAudio
  8.  * hooks: header_include_raw, install_plugin, post_read_post, post_add_post, post_update_post, submit_2_fields, submit_functions_process_submitted, show_post_audio, admin_plugin_settings, admin_sidebar_plugin_settings
  9.  * author: Manolof
  10.  * authorurl: http://forums.hotarucms.org/member.php?1197-Manolof
  11.  *
  12.  * PHP version 5
  13.  *
  14.  * LICENSE: Hotaru CMS is free software: you can redistribute it and/or
  15.  * modify it under the terms of the GNU General Public License as
  16.  * published by the Free Software Foundation, either version 3 of
  17.  * the License, or (at your option) any later version.
  18.  *
  19.  * Hotaru CMS is distributed in the hope that it will be useful, but WITHOUT
  20.  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  21.  * FITNESS FOR A PARTICULAR PURPOSE.
  22.  *
  23.  * You should have received a copy of the GNU General Public License along
  24.  * with Hotaru CMS. If not, see http://www.gnu.org/licenses/.
  25.  *
  26.  * @category  Content Management System
  27.  * @package   HotaruCMS
  28.  * @author    Nick Ramsay <admin@hotarucms.org>
  29.  * @copyright Copyright (c) 2009, Hotaru CMS
  30.  * @license   http://www.gnu.org/copyleft/gpl.html GNU General Public License
  31.  * @link      http://www.hotarucms.org/
  32.  */
  33.  
  34. class PostAudio
  35. {  
  36.     /**
  37.      * Add a post_audio field to posts table if it doesn't already exist
  38.      */
  39.     public function install_plugin($h)
  40.     {
  41.         // Create a new table column called "post_audio" and "post_artist" if they don't already exist
  42.         $exists1 = $h->db->column_exists('posts', 'post_audio');
  43.         if (!$exists1) {
  44.             $h->db->query("ALTER TABLE " . TABLE_POSTS . " ADD post_audio VARCHAR(2000) NOT NULL DEFAULT '' " );
  45.         }
  46.         $exists2 = $h->db->column_exists('posts', 'post_artist');
  47.         if (!$exists2) {
  48.             $h->db->query("ALTER TABLE " . TABLE_POSTS . " ADD post_artist TEXT NOT NULL DEFAULT '' ");
  49.         }
  50.     }
  51.         if (!isset($post_audio_settings['size_limit'])) { $post_audio_settings['size_limit'] = ''; }
  52.         $h->updateSetting('post_audio_settings', serialize($post_audio_settings)
  53.    
  54.     public function header_include_raw($h)
  55.     {
  56.         // include the uploadify file
  57.        
  58.         if ($h->pageType == 'submit') {
  59.             include 'uploadify/settings.php';
  60.             }
  61.        
  62.         // include jPlayer
  63.        
  64.         if ($h->pageType == 'post') {?>
  65.         <script type="text/javascript" src="<?php echo SITEURL;?>content/plugins/post_audio/jplayer/js/jquery.jplayer.min.js"></script>
  66.         <link rel="stylesheet" href="<?php echo SITEURL;?>content/plugins/post_audio/jplayer/css/jplayer.blue.monday.css">
  67.        
  68.         <script type="text/javascript">
  69.         //<![CDATA[
  70.         $(document).ready(function(){
  71.             $("#jquery_jplayer_1").jPlayer({
  72.                 ready: function (event) {
  73.                     $(this).jPlayer("setMedia", {
  74.                         mp3:"<?php echo html_entity_decode($h->post->vars['audio'], ENT_QUOTES); ?>"
  75.                     });
  76.                 },
  77.                 swfPath: "<?php echo SITEURL;?>content/plugins/post_audio/jplayer/js",
  78.                 supplied: "mp3",
  79.                 wmode: "window"
  80.             });
  81.         });
  82.         //]]>
  83.         </script>
  84.        
  85.         <!--[if lt IE 9]>
  86.           <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
  87.         <![endif]-->
  88.         <?php }
  89.        
  90.     }
  91.        
  92.     /**
  93.      * Read post audio if post_id exists.
  94.      */
  95.     public function post_read_post($h)
  96.     {
  97.         if (!isset($h->post->vars['post_row']->post_audio)) { return false; }
  98.  
  99.         $h->post->vars['audio'] = $h->post->vars['post_row']->post_audio;
  100.     }
  101.  
  102.     /**
  103.      * Add audio to the posts table
  104.      */
  105.     public function post_add_post($h)
  106.     {
  107.     if ($h->post->type != 'news') { return false; }
  108.    
  109.         $h->post->vars['audio'] = html_entity_decode($h->vars['submitted_data']['submit_audio'], ENT_QUOTES);
  110.  
  111.         $sql = "UPDATE " . TABLE_POSTS . " SET post_audio = %s WHERE post_id = %d";
  112.         $h->db->query($h->db->prepare($sql, $h->post->vars['audio'] , $h->post->vars['last_insert_id']));
  113.     }
  114.  
  115.     /**
  116.      * Update audio in the posts table
  117.      */
  118.     public function post_update_post($h)
  119.     {
  120.         if (!isset($h->vars['submitted_data']['submit_audio'])) { return false; }
  121.        
  122.         $h->post->vars['audio'] = html_entity_decode($h->vars['submitted_data']['submit_audio'], ENT_QUOTES);
  123.  
  124.         $sql = "UPDATE " . TABLE_POSTS . " SET post_audio = %s WHERE post_id = %d";
  125.         $h->db->query($h->db->prepare($sql, $h->post->vars['audio'] , $h->post->id));
  126.     }
  127.  
  128.     /**
  129.      * Add a audio field to submit form 2 and edit post page
  130.      */
  131.     public function submit_2_fields($h)
  132.     {
  133.         if (!isset($h->post->vars['audio'])) {
  134.             if (isset($h->vars['submitted_data']['submit_audio'])) {
  135.                 $h->post->vars['audio'] = $h->vars['submitted_data']['submit_audio'];
  136.             } else {
  137.                 $h->post->vars['audio'] = '';
  138.             }
  139.         }
  140.         // audio URL field
  141.         if (!isset($h->post->vars['audio'])) { $h->post->vars['audio'] = '';}
  142.        
  143.         echo "<tr id='audio_upload'>\n";
  144.             echo "<th>" . $h->lang["submit_form_upload"] . "</th>\n";
  145.             echo "<td>\n";
  146.             echo "<input type='file' id='file_upload' name='file_upload' />\n";
  147.             ?>
  148.             <input id="submit_btn" type="button" class="submit uploadfile" style="margin:0 !important;display:none;" onClick="javascript:$('#file_upload').uploadify('upload','*')" value="Upload" />
  149.             <?php
  150.             echo "</td>\n";        
  151.         echo "</tr>\n";
  152.        
  153.         $audio = $h->post->vars['audio'];
  154.         echo "<tr id='audio_url' style='display:none;'>\n";
  155.             echo "<td>\n";
  156.             echo "<input id='post_audio' class='hidden' type='text' name='post_audio' value= '".htmlentities($audio, ENT_QUOTES)."' >\n";
  157.             echo "</td>\n";
  158.             $audio = $h->cage->post->keyExists('post_audio');
  159.         echo "</tr>\n";
  160.        
  161.        
  162.     }
  163.  
  164.     /**
  165.      * Check and update post_submit in Submit step 2 and Post Edit pages
  166.      */
  167.     public function submit_functions_process_submitted($h)
  168.     {  
  169.         if (($h->pageName != 'submit2') && ($h->pageName != 'edit_post')) { return false; }
  170.         if (preg_match('/^.*\.([mM][pP][3])$/i', $h->cage->post->keyExists('post_audio'))) {
  171.             $h->post->vars['audio'] = $h->cage->post->keyExists('post_audio');
  172.         } else {
  173.             $h->post->vars['audio'] = '';
  174.         }
  175.         $h->vars['submitted_data']['submit_audio'] = htmlentities($h->post->vars['audio'], ENT_QUOTES);
  176.     }
  177.        
  178.     /**
  179.      * Show audio in extra fields
  180.      */
  181.     public function show_post_audio($h)
  182.     {
  183.         $audio = $h->post->vars['audio'];
  184.    
  185.        
  186.         if ($h->pageType == 'post') {
  187.         if ($audio != null) { ?>
  188.         <div id="jquery_jplayer_1" class="jp-jplayer"></div>
  189.         <div id="jp_container_1" class="jp-audio">
  190.             <div class="jp-type-single">
  191.                 <div class="jp-gui jp-interface">
  192.                     <ul class="jp-controls">
  193.                         <li><a href="javascript:;" class="jp-play" tabindex="1">play</a></li>
  194.                         <li><a href="javascript:;" class="jp-pause" tabindex="1">pause</a></li>
  195.                         <li><a href="javascript:;" class="jp-mute" tabindex="1">mute</a></li>
  196.                         <li><a href="javascript:;" class="jp-unmute" tabindex="1">unmute</a></li>
  197.                         <li><a href="javascript:;" class="jp-volume-max" tabindex="1">max volume</a></li>
  198.                     </ul>
  199.                     <div class="jp-progress">
  200.                         <div class="jp-seek-bar">
  201.                             <div class="jp-play-bar"></div>
  202.                         </div>
  203.                     </div>
  204.                     <div class="jp-volume-bar">
  205.                         <div class="jp-volume-bar-value"></div>
  206.                     </div>
  207.                     <div class="jp-time-holder">
  208.                         <div class="jp-current-time"></div>
  209.                         <div class="jp-duration"></div>
  210.  
  211.                         <ul class="jp-toggles">
  212.                             <li><a href="javascript:;" class="jp-repeat" tabindex="1" title="repeat">repeat</a></li>
  213.                             <li><a href="javascript:;" class="jp-repeat-off" tabindex="1" title="repeat off">repeat off</a></li>
  214.                         </ul>
  215.                     </div>
  216.                 </div>
  217.  
  218.                 <a href="<?php echo SITEURL;?>content/plugins/post_audio/download.php?f=<?php echo htmlentities(basename($audio), ENT_QUOTES); ?>" class="jp-download" title="Download"></a>
  219.                
  220.                 <div class="jp-title">
  221.                     <ul>
  222.                         <li><?php echo ($h->post->artist." - ".$h->post->title); ?></li>
  223.                     </ul>
  224.                 </div>
  225.                 <div class="jp-no-solution">
  226.                     <span>Update Required</span>
  227.                     To play the media you will need to either update your browser to a recent version or update your <a href="http://get.adobe.com/flashplayer/" target="_blank">Flash plugin</a>.
  228.                 </div>
  229.             </div>
  230.         </div>
  231.             <?php }
  232.         }
  233.     }
  234. }
  235. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement