Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- Plugin Name: test88
- Plugin URI: http://test.org
- Description: test plugin
- Version: 4.44
- Author: Kitsune
- Author URI: http://test.org
- */
- add_action('init','zzz_init_func');
- add_action('admin_menu', 'zzz_test_menu');
- add_action('wp_head','zzz_head_scripts');
- add_action('wp_enqueue_scripts', 'zzz_test_scripts');
- add_action('admin_enqueue_scripts', 'zzz_admin_scripts');
- add_shortcode('test88_pic','zzz_shortcode');
- add_action('wp_ajax_getmessage', 'zzz_ajaxfunc');
- add_action('wp_ajax_nopriv_getmessage', 'zzz_ajaxfunc');
- add_action('widgets_init','zzz_widgetsinit');
- add_action('activate_test88/test88.php', 'zzz_activateplugin');
- //--------------------------------- init
- function zzz_init_func() {
- if ((!current_user_can('edit_posts')) && (!current_user_can('edit_pages')))
- return;
- if (get_user_option('rich_editing')==true) {
- add_filter('mce_external_plugins', 'zzz_add_mce_plugin');
- add_filter('mce_buttons','zzz_mce_regbutton');
- }
- }
- //--------------------------------- mce_external_plugins
- function zzz_add_mce_plugin($plugin_array) {
- $plugin_array['test88_pics'] = plugins_url('test88/mce_test88.js');
- return $plugin_array;
- }
- //--------------------------------- mce_buttons
- function zzz_mce_regbutton($buttons) {
- array_push($buttons, 'separator', 'test88_pics_button');
- return $buttons;
- }
- //--------------------------------- admin_menu
- function zzz_test_menu() {
- add_menu_page(__('Test88 Pics Page'), __('Test88 Pics Page'), 'activate_plugins', 'test88/main_admin_page.php');
- add_submenu_page('test88/main_admin_page.php', __('Options Page'), __('Options Page'), 'activate_plugins', 'test88/sub_admin_page.php');
- }
- //--------------------------------- wp_head
- function zzz_head_scripts() {
- $test_opt = get_option('zzzz_render');
- if ($test_opt['style']=='slide') {
- ?>
- <script type="text/javascript">
- jQuery(document).ready(
- function() {
- jQuery('.ajax_button').click(zClick);
- }
- )
- </script>
- <style type="text/css">
- .gallery {
- position: relative;
- }
- </style>
- <?php
- }
- }
- //--------------------------------- wp_enqueue_scripts
- function zzz_test_scripts() {
- /*if (@file_exists(TEMPLATEPATH.'/test88.css')) {
- wp_enqueue_style('test88_style', get_stylesheet_directory_uri().'/test88.css');
- }*/
- if (@file_exists(plugins_url('test88/base.css')))
- wp_enqueue_style('test88_base_style', plugins_url('test88/base.css'));
- $test_opt = get_option('zzzz_render');
- if ($test_opt['style']=='slide') {
- wp_enqueue_script('test88_slide_js', plugins_url('test88/slide.js'), array('jquery'));
- $ajax_nonce = wp_create_nonce('querty');
- wp_localize_script('test88_slide_js', 't88slide',
- array ('ajax_url'=>admin_url('admin-ajax.php',(is_ssl() ? 'https' : 'http')),
- 'container'=>'ajax_container', 'ajax_nonce' => $ajax_nonce)
- );
- }
- }
- //--------------------------------- admin_enqueue_scripts
- function zzz_admin_scripts() {
- }
- //--------------------------------- shortcode
- function zzz_shortcode($atts) {
- extract (
- shortcode_atts(
- array('title'=>'Test88 Gallery', 'sclass'=>'gallery'))
- );
- $test_opt = get_option('zzzz_render');
- $out = '<div class="'.$sclass.'" style="background:'.$test_opt['background'].';"><h3>'.$title.'</h3>';
- global $wpdb;
- $pics = $wpdb->get_results("SELECT id, pic_address FROM pics_test88 ORDER BY id DESC LIMIT 12");
- foreach ($pics as $pic) {
- $out.='<img src="'.$pic->pic_address.'" />';
- }
- if ($test_opt['style']=='slide') {
- $out .= '<div><input type="button" class="ajax_button" value="load" />'.
- '</div><div id="ajax_container">ajax container</div>';
- }
- $out.='</div>';
- return $out;
- }
- //---------------------------------
- /*function set_schedule() {
- wp_clear_scheduled_hook('test88_cron');
- if (!wp_next_scheduled('test88_cron'))
- wp_schedule_event(time(), 'twicedaily', 'test88_cron');
- }
- //---------------------------------
- add_action('test88_cron', 'zzz_cron_action');
- //--------------------------------- test88_cron
- function zzz_cron_action() {
- $tmp = get_option('zzzz_counter');
- $inf4 = update_option('zzzz_counter', $tmp+1);
- }*/
- //--------------------------------- wp_ajax_getmessage / wp_ajax_nopriv_getmessage
- function zzz_ajaxfunc() {
- global $wpdb, $user_identity, $user_ID;
- if (!check_ajax_referer('querty', 'security', false)) {
- _e('Failed to Verify Referer');
- exit();
- }
- echo 'test ajax return 4';
- }
- //---------------------------------
- class WP_Widget_test88 extends WP_Widget {
- //------------------
- function WP_Widget_test88() {
- $widget_opts = array('description'=>__('WP test88 Pics Widget'));
- $this->WP_Widget('test88-widget',__('Tes88'), $widget_opts);
- }
- //------------------
- function widget($args, $instance) {
- extract($args);
- $title = apply_filters('widget_title', esc_attr($instance['title']));
- $bkg_id = intval($instance['bkg_id']);
- echo $before_widget;
- echo $before_title;
- echo $title;
- echo $after_title;
- switch ($bkg_id) {
- case 0: $bkg='#444';break;
- case 4: $bkg='#eee';break;
- case 5: $bkg='red';break;
- default: $bkg='green';
- }
- $out = '<div style="background:'.$bkg.';"><h3>'.$title.'</h3>';
- global $wpdb;
- $wpdb->show_errors();
- $pics = $wpdb->get_results("SELECT id, pic_address FROM pics_test88 ORDER BY id DESC LIMIT 12");
- foreach ($pics as $pic) {
- $out.='<img src="'.$pic->pic_address.'" />';
- }
- $out.='</div>';
- echo $out;
- echo $after_widget;
- }
- //------------------
- function update($new_instance, $old_instance) {
- $instance = $old_instance;
- $instance['title'] = strip_tags($new_instance['title']);
- $instance['bkg_id'] = intval($new_instance['bkg_id']);
- return $instance;
- }
- //------------------
- function form($instance) {
- $instance =
- wp_parse_args( (array)$instance,
- array('title'=>__('Test88 widget'),
- 'test_id'=>0)
- );
- $title = esc_attr($instance['title']);
- $test_id = intval($instance['test_id']);
- echo '<input id="'.$this->get_field_id('title').'" name="'.
- $this->get_field_name('title').'" type="text" value="'.$title.'" /><br/>';
- echo '<select name="'.$this->get_field_name('bkg_id').'" id="'.$this->get_field_id('bkg_id').'">';
- echo '<option value="0" '.selected(0, $test_id).'>'.'Dark background'.'</option>';
- echo '<option value="4" '.selected(4, $test_id).'>'.'Light background'.'</option>';
- echo '<option value="5" '.selected(5, $test_id).'>'.'Red background'.'</option>';
- echo '</select><br/>';
- }
- }
- //--------------------------------- widgets_init
- function zzz_widgetsinit() {
- register_widget('WP_Widget_test88');
- }
- //--------------------------------- activate_test88/test88.php
- function zzz_activateplugin() {
- global $wpdb;
- $sq = "CREATE TABLE pics_test88 (
- id int(10) NOT NULL auto_increment,
- pic_address varchar(500) NOT NULL default '',
- PRIMARY KEY (id));";
- include_once(ABSPATH.'/wp-admin/includes/upgrade.php');
- /*$wpdb->show_errors();
- maybe_create_table($wpdb->pics_test88, $sq);*/
- dbDelta($sq);
- $tmp = $wpdb->get_var("SELECT id FROM pics_test88 LIMIT 1");
- if (empty($tmp)) {
- $tmp4 = $wpdb->query("INSERT INTO pics_test88 VALUES(1,
- 'http://bigpicture.ru/wp-content/uploads/2012/09/Long-Exposure-Fireworks-12.jpg');");
- }
- add_option('zzzz_render',array('style' => 'default', 'background' => '#d8e1eb'));
- add_option('zzzz_latest_id',0);
- $role = get_role('administrator');
- if (!$role->has_cap('manage_test88'))
- $role->add_cap('manage_test88');
- //set_schedule();
- }
- ?>
- <?php
- /*------------------------------------------------------------------------------
- main_admin_page.php
- -------------------------------------------------------------------------------*/
- if (!current_user_can('manage_test88'))
- die('Access denied');
- $base_name = plugin_basename('test88/main_admin_page.php');
- $base_page = 'admin.php?page='.$base_name;
- //----------------------------------
- if (!empty($_POST['do'])) {
- check_admin_referer('add-test88');
- $pic_addr = trim($_POST['pic_addr']);
- $wpdb->show_errors();
- $addpic = $wpdb->query("INSERT INTO pics_test88 VALUES(0, '$pic_addr')");
- if (!$addpic) {
- $tx = '<p style="color:red">error in adding picture</p>';
- } else {
- $tx = '<p style="color:green">picture successfully added</p>';
- $insid = intval($wpdb->insert_id);
- update_option('zzzz_latest_id', $insid);
- }
- echo $tx;
- }
- //----------------------------------
- ?>
- <h3>Add picture</h3>
- <form method="post" action="<?php echo admin_url('admin.php?page='.plugin_basename(__FILE__)); ?>">
- <?php wp_nonce_field('add-test88'); ?>
- <p>Input picture address: <input type="text" name="pic_addr" size="70" value="" /></p>
- <input type="submit" name="do" value="<?php _e('Add pic');?>" />
- </form>
- <?php
- //----------------------------------
- ?>
- <?php
- /*------------------------------------------------------------------------------
- sub_admin_page.php
- -------------------------------------------------------------------------------*/
- if (!current_user_can('manage_test88'))
- die('Access denied');
- $base_name = plugin_basename('test88/sub_admin_page.php');
- $base_page = 'admin.php?page='.$base_name;
- if (isset($_POST['submit'])) {
- check_admin_referer('options-test88');
- $zz_style = strip_tags(trim($_POST['zz_style']));
- $zz_background = strip_tags(trim($_POST['zz_background']));
- $zzzz_render = array('style'=>$zz_style, 'background'=>$zz_background);
- $tst = update_option('zzzz_render', $zzzz_render);
- if (!$tst) {
- $tx = '<p style="color:red">error updating option</p>';
- } else {
- $tx = '<p style="color:green">option successfully updated</p>';
- }
- echo $tx;
- }
- //------------------------------------------
- ?>
- <form method="post" action="<?php echo admin_url('admin.php?page='.plugin_basename(__FILE__)); ?>">
- <?php
- wp_nonce_field('options-test88');
- $zzzz_render = get_option('zzzz_render');
- ?>
- <h3>select image box style</h3>
- <p>default style <input type="radio" name="zz_style" value="default" <?php checked('default',$zzzz_render['style']);?> /></p>
- <p>slide style <input type="radio" name="zz_style" value="slide" <?php checked('slide', $zzzz_render['style']);?> /></p>
- <h3>select image box background</h3>
- <p><input type="text" name="zz_background" value="<?php echo $zzzz_render['background'];?>" /></p>
- <p><input type="submit" name="submit" value="<?php _e('Save options'); ?>" /></p>
- </form>
- /*-----------------------------------------------------------
- slide.js
- -----------------------------------------------------------*/
- function zClick() {
- jQuery.ajax({
- type:'GET',
- url: t88slide.ajax_url,
- data: 'action=getmessage&security='+t88slide.ajax_nonce,
- cache: false,
- success: onSuccess})
- }
- function onSuccess(data) {
- var el = document.getElementById(t88slide.container);
- el.innerHTML = data;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement