Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- global $wpdb, $wp_version;
- define("POOLONETABLEQ", $wpdb->prefix . "pooloneq_wp_plugin");
- define("POOLONETABLEA", $wpdb->prefix . "poolonea_wp_plugin");
- if ( ! defined( 'POOLONE_PLUGIN_BASENAME' ) )
- define( 'POOLONE_PLUGIN_BASENAME', plugin_basename( __FILE__ ) );
- if ( ! defined( 'POOLONE_PLUGIN_NAME' ) )
- define( 'POOLONE_PLUGIN_NAME', trim( dirname( POOLONE_PLUGIN_BASENAME ), '/' ) );
- if ( ! defined( 'POOLONE_PLUGIN_DIR' ) )
- define( 'POOLONE_PLUGIN_DIR', WP_PLUGIN_DIR . '/' . POOLONE_PLUGIN_NAME );
- if ( ! defined( 'POOLONE_PLUGIN_URL' ) )
- define( 'POOLONE_PLUGIN_URL', WP_PLUGIN_URL . '/' . POOLONE_PLUGIN_NAME );
- function pool1_plugin_path( $path = '' ) {
- return path_join( POOLONE_PLUGIN_DIR, trim( $path, '/' ) );
- }
- function pool1_plugin_url( $path = '' ) {
- return plugins_url( $path, POOLONE_PLUGIN_BASENAME );
- }
- /*Функция голосования и вывода количества голосов*/
- function poolone()
- {
- global $wpdb;
- $pool1_que_css = "<div class='pool-question'>##QUESTION##</div>";
- $pool1_ans_css = "<div class='pool-answer'>##ANSWER##</div>";
- $pool1_btn_css = "<div class='pool-button'>##BUTTON##</div>";
- $pool_random = "YES";
- $sSql = "select poolq_id, poolq_question from ". POOLONETABLEQ ." where 1=1";
- $sSql = $sSql . " and (`poolq_start` <= NOW() and `poolq_end` >= NOW())";
- if($pool_random == "YES"){ $sSql = $sSql . " ORDER BY RAND()"; }
- $sSql = $sSql . " limit 0,1;";
- $pool_question = $wpdb->get_results($sSql);
- if ( ! empty($pool_question) )
- {
- // setcookie
- ob_start();
- $cookie_pool_question = $pool_question[0];
- if ( !empty($cookie_pool_question) ) $cookie_poolq_id = $cookie_pool_question->poolq_id;
- // setcookie
- if (isset($_COOKIE["POLLONE-$cookie_poolq_id"]))
- {
- $pool1_que_css = "<div class='pool-question'>##QUESTION##</div>";
- $pool1_ans_css = "<div class='pool-answer'>##ANSWER## <span class='pool-result'>(##RES##)</span></div>";
- $res = '<div id="pool1">';
- foreach ( $pool_question as $question )
- {
- $poolq_id = $question->poolq_id;
- $poolq_question = stripslashes($question->poolq_question);
- $poolq_question = str_replace( "##QUESTION##" , $poolq_question, $pool1_que_css);
- $res = $res . $poolq_question;
- $sSql = "select poola_id, poola_answer, poola_vote from ". POOLONETABLEA ." where 1=1 and poolq_id = ". $poolq_id;
- $pool_answer = $wpdb->get_results($sSql);
- if ( ! empty($pool_answer) )
- {
- foreach ( $pool_answer as $answer )
- {
- $poola_id = $answer->poola_id;
- $poola_answer = stripslashes($answer->poola_answer);
- $poola_vote = $answer->poola_vote;
- $poola_answer = str_replace( "##ANSWER##" , $poola_answer, $pool1_ans_css);
- $poola_answer = str_replace( "##RES##" , $poola_vote, $poola_answer, $pool1_res_css);
- $res = $res . $poola_answer;
- }
- }
- }
- $res = $res . '</div>';
- echo $res;
- }
- else
- {
- foreach ( $pool_question as $question )
- {
- echo '<div id="pool1"><span id="pool1_msg"></span>';
- $poolq_id = $question->poolq_id;
- $poolq_question = $question->poolq_question;
- $poolq_question = str_replace( "##QUESTION##" , $poolq_question, $pool1_que_css);
- echo $poolq_question;
- $sSql = "select poola_id, poola_answer from ". POOLONETABLEA ." where 1=1 and poolq_id = ". $poolq_id;
- $pool_answer = $wpdb->get_results($sSql);
- if ( ! empty($pool_answer) )
- {
- foreach ( $pool_answer as $answer )
- {
- $poola_id = $answer->poola_id;
- $poola_answer = stripslashes($answer->poola_answer);
- $poola_answer = "<input type ='Radio' onClick='SetPool(".$poola_id.")' name = 'poolanswer' id = 'poolanswer' value= '".$poola_id."'> ".$poola_answer."<br />";
- $poola_answer = str_replace( "##ANSWER##" , $poola_answer, $pool1_ans_css);
- echo $poola_answer;
- }
- }
- echo '<input name="pool1_ans" id="pool1_ans" type="hidden" value="" />';
- $url = '"' . pool1_plugin_url('') . '"';
- $pool_button = "<a class='pool1_btn_cls' name='pool1_btn' id='pool1_btn' onClick='return pool1_ajx(".$url.")'>Голосовать! </a>";
- $pool_button = str_replace( "##BUTTON##" , $pool_button, $pool1_btn_css);
- echo "<a class='pool-btn' onClick='pool1_ajx_res(".$url.")'> Результаты </a>";
- echo $pool_button;
- echo '</div>';
- }
- }
- }
- else
- {
- echo '<div style="text-align:center;">No pool available</div>';
- }
- }
- /*Создаем базу данных*/
- function pool1_install()
- {
- global $wpdb;
- if($wpdb->get_var("show tables like '". POOLONETABLEQ . "'") != POOLONETABLEQ)
- {
- $sSql = "CREATE TABLE IF NOT EXISTS `". POOLONETABLEQ . "` (";
- $sSql = $sSql . "`poolq_id` INT NOT NULL AUTO_INCREMENT ,";
- $sSql = $sSql . "`poolq_question` VARCHAR( 1024 ) NOT NULL ,";
- $sSql = $sSql . "`poolq_start` datetime NOT NULL default '0000-00-00 00:00:00' ,";
- $sSql = $sSql . "`poolq_end` datetime NOT NULL default '0000-00-00 00:00:00' ,";
- $sSql = $sSql . "`poolq_ext0` TEXT CHARACTER SET utf8 COLLATE utf8_bin NOT NULL ,";
- $sSql = $sSql . "`poolq_ext1` VARCHAR( 200 ) NOT NULL ,";
- $sSql = $sSql . "`poolq_ext2` VARCHAR( 200 ) NOT NULL ,";
- $sSql = $sSql . "`poolq_ext3` VARCHAR( 200 ) NOT NULL ,";
- $sSql = $sSql . "PRIMARY KEY ( `poolq_id` )";
- $sSql = $sSql . ")";
- $wpdb->query($sSql);
- $qid = mysql_insert_id();
- $sSql = "CREATE TABLE IF NOT EXISTS `". POOLONETABLEA . "` (";
- $sSql = $sSql . "`poola_id` INT NOT NULL AUTO_INCREMENT ,";
- $sSql = $sSql . "`poola_answer` VARCHAR( 1024 ) NOT NULL ,";
- $sSql = $sSql . "`poola_vote` INT NOT NULL default '0' ,";
- $sSql = $sSql . "`poolq_id` INT NOT NULL ,";
- $sSql = $sSql . "`poola_ext0` VARCHAR( 200 ) NOT NULL ,";
- $sSql = $sSql . "`poola_ext1` VARCHAR( 200 ) NOT NULL ,";
- $sSql = $sSql . "`poola_ext2` VARCHAR( 200 ) NOT NULL ,";
- $sSql = $sSql . "`poola_ext3` VARCHAR( 200 ) NOT NULL ,";
- $sSql = $sSql . "PRIMARY KEY ( `poola_id` )";
- $sSql = $sSql . ")";
- $wpdb->query($sSql);
- }
- }
- /*Добавляем админку*/
- function pool1_admin_options()
- {
- global $wpdb;
- $current_page = isset($_GET['ac']) ? $_GET['ac'] : '';
- switch($current_page)
- {
- case 'edit':
- include('pages/content-management-edit.php');
- break;
- case 'add':
- include('pages/content-management-add.php');
- break;
- case 'ans':
- include('pages/content-management-ans.php');
- break;
- default:
- include('pages/content-management-show.php');
- break;
- }
- }
- /*Удаляем плагин*/
- function pool1_deactivation()
- {
- // No action required.
- }
- function pool1_add_javascript_files()
- {
- if (!is_admin())
- {
- wp_enqueue_script( 'pool1_widget', pool1_plugin_url('js/widget.js'));
- wp_enqueue_script( 'pool1_page', pool1_plugin_url('js/page.js'));
- }
- }
- function pool1_add_to_menu()
- {
- if (is_admin())
- {
- add_menu_page( __( 'Poll one', 'PollOne' ), __( 'Poll one', 'PollOne' ), 'administrator', 'PollOne', 'pool1_admin_options' );
- add_submenu_page( 'PollOne', __( 'Poll One questions', 'PollOne' ), __( 'Poll Questions', 'PollOne' ),'administrator', 'PollOne', 'pool1_admin_options' );
- }
- }
- function pool1_widget($args)
- {
- extract($args);
- echo $before_widget . $before_title;
- echo get_option('pool1_title');
- echo $after_title;
- poolone();
- echo $after_widget;
- }
- function pool1_init()
- {
- if(function_exists('wp_register_sidebar_widget'))
- {
- wp_register_sidebar_widget('Pool one wp plugin', 'Poll one wp plugin', 'pool1_widget');
- }
- if(function_exists('wp_register_widget_control'))
- {
- wp_register_widget_control('Pool one wp plugin', array('Poll one wp plugin', 'widgets'), 'pool1_control', 'width=750');
- }
- }
- wp_enqueue_style ( 'pool1_style', pool1_plugin_url('/poolstyle.css'));
- add_action('admin_menu', 'pool1_add_to_menu');
- add_action("plugins_loaded", "pool1_init");
- register_activation_hook(__FILE__, 'pool1_install');
- register_deactivation_hook(__FILE__, 'pool1_deactivation');
- add_action('wp_enqueue_scripts', 'pool1_add_javascript_files');
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement