Audior - a powerful mp3 web recording solution. Author: NusoftHQ Version: 1.0 Author URI: http://www.nusofthq.com Copyright (C) 2009-2014 NusoftHQ This WordPress Plugin is distributed under the terms of the GNU General Public License. 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 any later version. You should have received a copy of the GNU General Public License along with this plugin. If not, see . */ //DEFINES if(session_id() == "") { session_start(); } require_once(ABSPATH . 'wp-content/plugins/audio-comments/sql.php'); function deleteAudiorComment($commentId) { global $wpdb; $uploadDir = wp_upload_dir(); $uploadsPath = $uploadDir['basedir'] . '/audio-comments/'; $audioComment = $wpdb->get_row("SELECT * FROM " . $wpdb->prefix . "audior_comments WHERE comment_id =" . intval($commentId)); if ($audioComment->id > 0) { //delete file @unlink($uploadsPath . $audioComment->file); //delete db record $wpdb->delete($wpdb->prefix . 'audior_comments', array('id' => $audioComment->id)); } } function audiorDeleteFile() { global $wpdb; $uploadDir = wp_upload_dir(); $uploadsPath = $uploadDir['basedir'] . '/audio-comments/'; $audioComment = $wpdb->get_row("SELECT * FROM " . $wpdb->prefix . "audior_comments WHERE id =" . esc_sql(intval($_POST['aid']))); if ($audioComment->id > 0) { //delete file @unlink($uploadsPath . $audioComment->file); //delete db record $wpdb->delete($wpdb->prefix . 'audior_comments', array('id' => $audioComment->id)); //send msg to user echo 'The audio comment has been removed!'; } else { echo 'invalid-id'; } die(); } function audiorCommentsJavaScript() { ?> get_row("SELECT * FROM " . $wpdb->prefix . "audior_comments WHERE comment_id =" . $comment->comment_ID); $audioFile = $filesPath . $audioComment->file; if (file_exists($uploadsPath . $audioComment->file) && $audioComment->file != '') { $html .= <<
Delete audio file
EOF; } else { $html = '

This comment doesn\'t have audio!

'; } echo $html; } function addAudiorMetaBox() { add_meta_box('audior_comments_box', __('Audio Comment'), 'audiorCommentsAdminBox', 'comment', 'normal'); } function showAudiorPlayer($text) { global $wpdb; $uploadDir = wp_upload_dir(); $uploadsPath = $uploadDir['basedir'] . '/audio-comments/'; $filesPath = $uploadDir['baseurl'] . '/audio-comments/'; $audioComment = $wpdb->get_row("SELECT * FROM " . $wpdb->prefix . "audior_comments WHERE comment_id =" . get_comment_ID()); if (file_exists($uploadsPath . $audioComment->file) && $audioComment->file != '') { $html .= '
'; } return $text . $html; } function saveAudior($commentId, $status) { global $current_user; global $wpdb; global $blog_id; get_currentuserinfo(); $uploadDir = wp_upload_dir(); $uploadsPath = $uploadDir['basedir'] . '/audio-comments/'; if (file_exists($uploadsPath . $_POST['audior-file']) && $_POST['audior-file'] != '') { $insert = "INSERT INTO " . $wpdb->prefix . "audior_comments (comment_id, comment_post_id, user_id, file, date) VALUES ('" . $commentId . "', '" . esc_sql($_POST['comment_post_ID']) . "', '".$current_user->ID."', '" . esc_sql($_POST['audior-file']) . "', '" . time() . "')"; $results = $wpdb->query($insert); } } function audior($commentField) { //define vars $flashVersion = '12.0.0.44'; //get wordpress and user info global $current_user; global $wpdb; global $blog_id; get_currentuserinfo(); $pluginPath = plugin_dir_url(__FILE__); $uploadDir = wp_upload_dir(); $_SESSION['audior-upload-path'] = $uploadDir['basedir'] . '/audio-comments/'; $audiorSettings = $wpdb->get_results( "SELECT * FROM " . $wpdb->prefix . "audior_settings LIMIT 1 "); $_SESSION['audior-settings'] = $audiorSettings[0]; $uniqID = uniqid(); $licenseKey= $audiorSettings[0]->license_key; //detect user role if (($current_user->ID != NULL) && ($current_user->ID != "") && ($current_user->ID > 0)) { if ($current_user->roles[0] != "") { $userRole = $current_user->roles[0]; } else { $userRole = "networkuser"; } } else { $userRole = "visitors"; } //select user role permissions $query = "SELECT * FROM " . $wpdb->prefix . "audior_permissions WHERE user_role = '".$userRole."'"; $userPermissions = $wpdb->get_results($query); $_SESSION['audior-permissions'] = $userPermissions[0]; //this user role can't post audio comments if ($userPermissions[0]->enable_audior == 0) { return $commentField; } //check if audior exists if (!file_exists(dirname(__FILE__) . '/audior/Audior.swf')) { return $commentField . '

For the plugin to work, you need the Audior files to be copied to the plugin directory! You can buy it from audior.ec or review the Documentation!

'; } //html for select //$htmlSelect .= 'here we will show a select'; //default html comment field $commentField = '

'; $logged = 0; if (($current_user->ID != NULL) && ($current_user->ID != "") && ($current_user->ID > 0)) { $logged = 1; } $html .= ''; $html .= ''; $html .= << var swfVersionStr = "{$flashVersion}"; var xiSwfUrlStr = ""; var flashvars = {}; flashvars.lstext="Loading..."; //you can provide a translation here for the "Laoding..." text taht shows up while this file and the external language file is loaded flashvars.recorderId = "recorder_{$uniqID}"; //set this var if you have multiple instances of Audior on a page and you want to identify them flashvars.userId ="user1";//this variable is sent back to upload.php when the user presses the [SAVE] button flashvars.licenseKey = "{$licenseKey}"; //licensekey variable, you get it when you purchase the software flashvars.sscode="php" //instructs Audior to use the PHP set of server side files (switch to sscode="aspx") to use the .NET/ASPX set of files flashvars.settingsFile = "audior_settings.php" //this setting instructs Audior what setting file to load. Either the static .XML or the dynamic .PHP that generates a dynamic xml. var params = {}; params.quality = "high"; params.bgcolor = "#ffffff"; params.allowscriptaccess = "sameDomain"; params.allowfullscreen = "true"; params.base = "{$pluginPath}audior/"; var attributes = {}; attributes.id = "Audior"; attributes.name = "Audior"; attributes.align = "middle"; swfobject.embedSWF("{$pluginPath}audior/Audior.swf", "audiorContent", "600", "140", swfVersionStr, xiSwfUrlStr, flashvars, params, attributes); swfobject.createCSS("#audiorContent", "display:block;text-align:left;"); EOF; $html .= 'var logged = ' . $logged . ';'; $html .= << EOF; $html .= '
'; $html .= '

To view this page ensure that Adobe Flash Player version '.$flashVersion.' or greater is installed.

Get Adobe Flash Player

'; $html .= '
'; return $htmlSelect.$commentField.$html; } function AudiorCommentsAdminConfing(){ add_options_page('Audio Comments Settings', 'Audio Comments', 'manage_options', 'audio-comments/audior-settings.php'); } register_activation_hook(__FILE__,'AudiorCommentsInstall'); add_action('admin_menu', 'AudiorCommentsAdminConfing'); //display audior in comment form //add_action('comment_form_logged_in_after', 'audior'); add_action('comment_form_field_comment', 'audior'); //save audior file to disk add_action('comment_post', 'saveAudior', 10, 2); //show audior player add_filter('comment_text', 'showAudiorPlayer'); //add box to adin comments area add_action('add_meta_boxes', addAudiorMetaBox); //bind javascript add_action('admin_footer', 'audiorCommentsJavaScript'); //delete audio file when comment is deleted add_action('delete_comment', 'deleteAudiorComment', 10, 1); //bind function to ajax call add_action('wp_ajax_audiorDeleteFile', 'audiorDeleteFile'); ?>