Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * name: Post Audio
- * description: Add an mp3 to Posts
- * version: 0.1
- * folder: post_audio
- * class: PostAudio
- * 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
- * author: Manolof
- * authorurl: http://forums.hotarucms.org/member.php?1197-Manolof
- *
- * PHP version 5
- *
- * LICENSE: Hotaru CMS is free software: you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation, either version 3 of
- * the License, or (at your option) any later version.
- *
- * Hotaru CMS is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.
- *
- * You should have received a copy of the GNU General Public License along
- * with Hotaru CMS. If not, see http://www.gnu.org/licenses/.
- *
- * @category Content Management System
- * @package HotaruCMS
- * @author Nick Ramsay <admin@hotarucms.org>
- * @copyright Copyright (c) 2009, Hotaru CMS
- * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License
- * @link http://www.hotarucms.org/
- */
- class PostAudio
- {
- /**
- * Add a post_audio field to posts table if it doesn't already exist
- */
- public function install_plugin($h)
- {
- // Create a new table column called "post_audio" and "post_artist" if they don't already exist
- $exists1 = $h->db->column_exists('posts', 'post_audio');
- if (!$exists1) {
- $h->db->query("ALTER TABLE " . TABLE_POSTS . " ADD post_audio VARCHAR(2000) NOT NULL DEFAULT '' " );
- }
- $exists2 = $h->db->column_exists('posts', 'post_artist');
- if (!$exists2) {
- $h->db->query("ALTER TABLE " . TABLE_POSTS . " ADD post_artist TEXT NOT NULL DEFAULT '' ");
- }
- }
- if (!isset($post_audio_settings['size_limit'])) { $post_audio_settings['size_limit'] = ''; }
- $h->updateSetting('post_audio_settings', serialize($post_audio_settings)
- public function header_include_raw($h)
- {
- // include the uploadify file
- if ($h->pageType == 'submit') {
- include 'uploadify/settings.php';
- }
- // include jPlayer
- if ($h->pageType == 'post') {?>
- <script type="text/javascript" src="<?php echo SITEURL;?>content/plugins/post_audio/jplayer/js/jquery.jplayer.min.js"></script>
- <link rel="stylesheet" href="<?php echo SITEURL;?>content/plugins/post_audio/jplayer/css/jplayer.blue.monday.css">
- <script type="text/javascript">
- //<![CDATA[
- $(document).ready(function(){
- $("#jquery_jplayer_1").jPlayer({
- ready: function (event) {
- $(this).jPlayer("setMedia", {
- mp3:"<?php echo html_entity_decode($h->post->vars['audio'], ENT_QUOTES); ?>"
- });
- },
- swfPath: "<?php echo SITEURL;?>content/plugins/post_audio/jplayer/js",
- supplied: "mp3",
- wmode: "window"
- });
- });
- //]]>
- </script>
- <!--[if lt IE 9]>
- <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
- <![endif]-->
- <?php }
- }
- /**
- * Read post audio if post_id exists.
- */
- public function post_read_post($h)
- {
- if (!isset($h->post->vars['post_row']->post_audio)) { return false; }
- $h->post->vars['audio'] = $h->post->vars['post_row']->post_audio;
- }
- /**
- * Add audio to the posts table
- */
- public function post_add_post($h)
- {
- if ($h->post->type != 'news') { return false; }
- $h->post->vars['audio'] = html_entity_decode($h->vars['submitted_data']['submit_audio'], ENT_QUOTES);
- $sql = "UPDATE " . TABLE_POSTS . " SET post_audio = %s WHERE post_id = %d";
- $h->db->query($h->db->prepare($sql, $h->post->vars['audio'] , $h->post->vars['last_insert_id']));
- }
- /**
- * Update audio in the posts table
- */
- public function post_update_post($h)
- {
- if (!isset($h->vars['submitted_data']['submit_audio'])) { return false; }
- $h->post->vars['audio'] = html_entity_decode($h->vars['submitted_data']['submit_audio'], ENT_QUOTES);
- $sql = "UPDATE " . TABLE_POSTS . " SET post_audio = %s WHERE post_id = %d";
- $h->db->query($h->db->prepare($sql, $h->post->vars['audio'] , $h->post->id));
- }
- /**
- * Add a audio field to submit form 2 and edit post page
- */
- public function submit_2_fields($h)
- {
- if (!isset($h->post->vars['audio'])) {
- if (isset($h->vars['submitted_data']['submit_audio'])) {
- $h->post->vars['audio'] = $h->vars['submitted_data']['submit_audio'];
- } else {
- $h->post->vars['audio'] = '';
- }
- }
- // audio URL field
- if (!isset($h->post->vars['audio'])) { $h->post->vars['audio'] = '';}
- echo "<tr id='audio_upload'>\n";
- echo "<th>" . $h->lang["submit_form_upload"] . "</th>\n";
- echo "<td>\n";
- echo "<input type='file' id='file_upload' name='file_upload' />\n";
- ?>
- <input id="submit_btn" type="button" class="submit uploadfile" style="margin:0 !important;display:none;" onClick="javascript:$('#file_upload').uploadify('upload','*')" value="Upload" />
- <?php
- echo "</td>\n";
- echo "</tr>\n";
- $audio = $h->post->vars['audio'];
- echo "<tr id='audio_url' style='display:none;'>\n";
- echo "<td>\n";
- echo "<input id='post_audio' class='hidden' type='text' name='post_audio' value= '".htmlentities($audio, ENT_QUOTES)."' >\n";
- echo "</td>\n";
- $audio = $h->cage->post->keyExists('post_audio');
- echo "</tr>\n";
- }
- /**
- * Check and update post_submit in Submit step 2 and Post Edit pages
- */
- public function submit_functions_process_submitted($h)
- {
- if (($h->pageName != 'submit2') && ($h->pageName != 'edit_post')) { return false; }
- if (preg_match('/^.*\.([mM][pP][3])$/i', $h->cage->post->keyExists('post_audio'))) {
- $h->post->vars['audio'] = $h->cage->post->keyExists('post_audio');
- } else {
- $h->post->vars['audio'] = '';
- }
- $h->vars['submitted_data']['submit_audio'] = htmlentities($h->post->vars['audio'], ENT_QUOTES);
- }
- /**
- * Show audio in extra fields
- */
- public function show_post_audio($h)
- {
- $audio = $h->post->vars['audio'];
- if ($h->pageType == 'post') {
- if ($audio != null) { ?>
- <div id="jquery_jplayer_1" class="jp-jplayer"></div>
- <div id="jp_container_1" class="jp-audio">
- <div class="jp-type-single">
- <div class="jp-gui jp-interface">
- <ul class="jp-controls">
- <li><a href="javascript:;" class="jp-play" tabindex="1">play</a></li>
- <li><a href="javascript:;" class="jp-pause" tabindex="1">pause</a></li>
- <li><a href="javascript:;" class="jp-mute" tabindex="1">mute</a></li>
- <li><a href="javascript:;" class="jp-unmute" tabindex="1">unmute</a></li>
- <li><a href="javascript:;" class="jp-volume-max" tabindex="1">max volume</a></li>
- </ul>
- <div class="jp-progress">
- <div class="jp-seek-bar">
- <div class="jp-play-bar"></div>
- </div>
- </div>
- <div class="jp-volume-bar">
- <div class="jp-volume-bar-value"></div>
- </div>
- <div class="jp-time-holder">
- <div class="jp-current-time"></div>
- <div class="jp-duration"></div>
- <ul class="jp-toggles">
- <li><a href="javascript:;" class="jp-repeat" tabindex="1" title="repeat">repeat</a></li>
- <li><a href="javascript:;" class="jp-repeat-off" tabindex="1" title="repeat off">repeat off</a></li>
- </ul>
- </div>
- </div>
- <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>
- <div class="jp-title">
- <ul>
- <li><?php echo ($h->post->artist." - ".$h->post->title); ?></li>
- </ul>
- </div>
- <div class="jp-no-solution">
- <span>Update Required</span>
- 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>.
- </div>
- </div>
- </div>
- <?php }
- }
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement