*/ class Album_Reviewer_Admin { /** * The ID of this plugin. * * @since 1.0.0 * @access private * @var string $album_reviewer The ID of this plugin. */ private $album_reviewer; /** * Reference to the pages model object. * * @since 1.0.0 * @access private * @var string $pages Reference to the pages model object. */ private $pages; /** * Reference to the comments model object. * * @since 1.0.0 * @access private * @var string $comments Reference to the comments model object. */ private $comments; /** * The version of this plugin. * * @since 1.0.0 * @access private * @var string $version The current version of this plugin. */ private $version; /** * Initialize the class and set its properties. * * @since 1.0.0 * @param string $album_reviewer The name of this plugin. * @param string $version The version of this plugin. */ public function __construct( $album_reviewer, $pages, $comments, $version ) { $this->album_reviewer = $album_reviewer; $this->version = $version; $this->pages = $pages; $this->comments = $comments; $this->log('Album_Reviewer_Admin::__construct'); $this->log(serialize($album_reviewer)); $this->log(serialize($pages)); add_action( 'add_meta_boxes', array( $this, 'add_post_settings_meta_box' ), 10, 2 ); add_action( 'admin_menu', array( $this, 'add_album_review_settings_submenu' ) ); add_action( 'admin_init', array( $this, 'admin_init' ) ); /*--------------- Backend "Routes" --------------*/ add_action('wp_ajax_nopriv_pp_album_save_settings', array( $this, 'pp_album_review_save_settings' ) ); add_action('wp_ajax_pp_album_save_settings', array( $this, 'pp_album_review_save_settings' ) ); add_action('wp_ajax_nopriv_pp_album_review_post_pages', array( $this, 'insert_pages' ) ); add_action('wp_ajax_pp_album_review_post_pages', array( $this, 'insert_pages' ) ); add_action('wp_ajax_nopriv_pp_album_review_insert_comments', array( $this, 'insert_comments' ) ); add_action('wp_ajax_pp_album_review_insert_comments', array( $this, 'insert_comments' ) ); // add_meta_box("pp_album_review_page_meta", "Album Pages", "pp_album_review_page_meta", "pp_album", "normal", "high"); } /** * Admin initializations. * * @since 1.0.0 */ public function admin_init( ){ add_image_size( 'album-page', PP_ALBUM_BASE_WIDTH, PP_ALBUM_BASE_HEIGHT ); add_image_size( 'album-thumb', PP_ALBUM_THUMB_WIDTH, PP_ALBUM_THUMB_HEIGHT ); add_image_size( 'album-tablet', PP_ALBUM_TABLET_WIDTH, PP_ALBUM_TABLET_HEIGHT ); } /** * Logging. * * @since 1.0.0 */ public function log( $logentry ){ if( !defined(WP_DEBUG_LOG) ) { $upload_dir = wp_upload_dir(); file_put_contents( $upload_dir['basedir'] . '/pp_album.log' , "[" . current_time( 'mysql' ) . "] " . $logentry ."\n\n", FILE_APPEND | LOCK_EX); } } /** * Register admin settings meta box * * @since 1.0.0 */ public function add_album_review_settings_submenu( ) { add_submenu_page( 'edit.php?post_type=pp_album', 'Album Reviewer Settings', 'Settings', 'manage_options', 'album-reviewer-settings-menu', array( $this, 'pp_album_review_view_settings' ) ); } /** * Register post settings meta box * * @since 1.0.0 */ public function add_post_settings_meta_box( $post_type, $post ) { $this->log('add_post_settings_meta_box ' . $post_type); if ( 'pp_album' == $post_type ){ add_meta_box( 'pp_album_review_post_settings_meta_box' ,__( 'Album Spreads', 'pp_album_review_textdomain' ) ,array( $this, 'post_settings_meta_box' ) ,'pp_album' ,'normal' ,'high' ); } } function post_settings_meta_box() { global $post; ?> 0 */) { ?>

logo'); $bg_pattern = get_option('pp_album_review_bg_pattern'); $bg_pattern_repeat_type = get_option('pp_album_review_bg_pattern_repeat_type'); $pagination = get_option('pp_album_review_use_page_num'); if($pagination = '' || $pagination == 'pages') { $radio_val_pages = "checked='checked'"; $radio_val_spreads = ""; } else { $radio_val_spreads = "checked='checked'"; $radio_val_pages = ""; } $bg_color = get_option('pp_album_review_bg_color'); $font_color = get_option('pp_album_review_font_color'); $block_color = get_option('pp_album_review_block_color'); $greeting_font_size = get_option('pp_album_review_greeting_font_size'); $greeting_font_size = $greeting_font_size ? $greeting_font_size : 100; $title_font_size = get_option('pp_album_review_title_font_size'); $title_font_size = $title_font_size ? $title_font_size : 100; $logo_size = get_option('$this->logo_size'); $logo_size = $logo_size ? $logo_size : 100; $ga_code = get_option('pp_album_review_ga_property_id'); $custom_css_code = get_option('pp_album_review_custom_css_code'); $custom_js_code = get_option('pp_album_review_custom_js_code'); $redirect_page = get_option('pp_album_review_redirect_page'); $user = wp_get_current_user(); ?>

Album Reviewer Settings



Version

You are currently using Album Reviewer Version version; ?>.

You are currently using WordPress Version .

Upgrade to Pro!

Get 20% off. Submit your name and email and we'll send you a coupon for 20% off your upgrade to the pro version


log('add_settings_meta_box'); add_meta_box("pp_album_review_settings", "Album Settings", array( $this , "render_settings_view" ), "pp_album", "normal", "high"); } /** * Renders the settings view. * * @since 1.0.0 */ public function render_settings_view ( $post ) { // $this->log('render_settings_view'); echo "

Settings

"; } /** * Register the stylesheets for the admin area. * * @since 1.0.0 */ public function enqueue_styles( $hook ) { $post_type = isset($_REQUEST['post']) ? get_post_type($_REQUEST['post']) : null; $this->log('enqueue_styles ' . $hook); if(isset($_REQUEST['post_type'])){ $post_type = $_REQUEST['post_type']; } $this->log('post_type: ' . $post_type); $bootstrap_css = plugins_url('ppp-album-reviewer2/bower_components/bootstrap/dist/css/bootstrap.css'); $bootstrap_slider_css = plugins_url('ppp-album-reviewer2/bower_components/seiyria-bootstrap-slider/dist/css/bootstrap-slider.min.css'); $fontawesome_css = plugins_url('ppp-album-reviewer2/bower_components/font-awesome/css/font-awesome.min.css'); switch( $hook ){ case 'pp_album_page_album-reviewer-settings-menu' : $this->log( $bootstrap_css ); wp_enqueue_style( 'pp_album_review_bootstrap', $bootstrap_css ); wp_enqueue_style( 'pp_album_review_bootstrap_slider', $bootstrap_slider_css ); wp_enqueue_style( $this->album_reviewer, plugin_dir_url( __FILE__ ) . 'css/album-reviewer-admin.css', array(), $this->version, 'all' ); wp_enqueue_style( 'pp_album_review_font_awesome', $fontawesome_css, array(), $this->version, 'all' ); break; case 'post.php': case 'post-new.php': if('pp_album' != $post_type){ return; } $this->log( $bootstrap_css ); wp_enqueue_style( 'pp_album_review_bootstrap', $bootstrap_css ); wp_enqueue_style( 'pp_album_review_bootstrap_slider', $bootstrap_slider_css ); wp_enqueue_style( $this->album_reviewer, plugin_dir_url( __FILE__ ) . 'css/album-reviewer-admin.css', array(), $this->version, 'all' ); wp_enqueue_style( 'pp_album_review_font_awesome', $fontawesome_css, array(), $this->version, 'all' ); break; } } /** * Register the JavaScript for the admin area. * * @since 1.0.0 */ public function enqueue_scripts( $hook ) { $post_type = isset($_REQUEST['post']) ? get_post_type($_REQUEST['post']) : null; $this->log('enqueue_scripts ' . $hook); $this->log(serialize($_REQUEST)); $this->log($post_type); switch( $hook ){ case 'pp_album_page_album-reviewer-settings-menu' : /* Setup AJAX hooks for album-admin-settings */ wp_register_script( $this->album_reviewer, plugin_dir_url( __FILE__ ) . 'js/album-reviewer-admin-settings.js'); $params = array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ); wp_localize_script( $this->album_reviewer, 'pp_album_review_admin_settings', $params ); wp_enqueue_script( $this->album_reviewer ); wp_enqueue_script( 'pp_album_review_bootstrap', plugins_url('ppp-album-reviewer2/bower_components/bootstrap/dist/js/bootstrap.js'), array( 'jquery' ), $this->version, false); wp_enqueue_script( 'pp_album_review_bootstrap_slider', plugins_url('ppp-album-reviewer2/bower_components/seiyria-bootstrap-slider/dist/bootstrap-slider.min.js'), array( 'jquery' ), $this->version, false); break; case 'post-new.php': $post_type = isset($_REQUEST['post_type']) ?($_REQUEST['post_type']) : null; case 'post.php': if( $hook == 'post.php' ) $post_type = isset($_REQUEST['post']) ? get_post_type($_REQUEST['post']) : null; if('pp_album' != $post_type){ return; } // load jquery wp_enqueue_script( 'jquery-ui-core' ); wp_enqueue_script( 'jquery-ui-sortable' ); wp_enqueue_script( 'jquery-ui-draggable' ); wp_enqueue_script( 'jquery-ui-droppable' ); wp_enqueue_script( 'jquery-ui-selectable' ); wp_enqueue_script( 'pp_album_review_validate_js', plugins_url('ppp-album-reviewer2/bower_components/jquery-validation/dist/jquery.validate.min.js'), array( 'jquery' ), $this->version, false); wp_enqueue_script( 'pp_album_review_bootstrap', plugins_url('ppp-album-reviewer2/bower_components/bootstrap/dist/js/bootstrap.js'), array( 'jquery' ), $this->version, false); wp_enqueue_script( 'pp_album_review_handlebars', plugins_url('ppp-album-reviewer2/bower_components/handlebars/handlebars.min.js'), array( 'jquery' ), $this->version, false); /* Setup AJAX hooks for album-admin-settings */ wp_register_script( $this->album_reviewer, plugin_dir_url( __FILE__ ) . 'js/album-reviewer-admin-edit-post.js'); $params = array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ); wp_localize_script( $this->album_reviewer, 'pp_album_review_admin', $params ); wp_enqueue_script( $this->album_reviewer ); break; default : break; } if(function_exists('wp_enqueue_media')) { wp_enqueue_media(); } else { wp_enqueue_script('media-upload'); wp_enqueue_script('thickbox'); wp_enqueue_style('thickbox'); } } /** * Handler for admin settings save. * * @since 1.0.0 */ public function pp_album_review_save_settings( ){ $this->log('pp_album_review_save_settings entered'); update_option( 'pp_album_review_user_name' , $_REQUEST['user_name']); update_option( 'pp_album_review_user_email' , trim($_REQUEST['user_email'])); update_option( 'pp_album_review_use_page_num' , $_REQUEST['pagination']); update_option( 'pp_album_review_notify_msg_to_client' , (stripslashes($_REQUEST['msg_to_client']))); update_option( 'pp_album_review_notify_msg_to_client2' , (stripslashes($_REQUEST['notify_msg_to_client']))); update_option( 'pp_album_review_draw_divider', $_REQUEST['draw_divider']); update_option( '$this->logo' , $_REQUEST['logo']); update_option( 'pp_album_review_bg_pattern' , $_REQUEST['bg_pattern']); update_option( 'pp_album_review_bg_pattern_repeat_type', $_REQUEST['bg_pattern_repeat_type']); update_option( 'pp_album_review_bg_color', $_REQUEST['bg_color']); update_option( 'pp_album_review_block_color', $_REQUEST['block_color']); update_option( 'pp_album_review_clr_db', $_REQUEST['clr_db']); update_option( 'pp_album_review_auto_diable_comments', $_REQUEST['disable_comments']); update_option('pp_album_review_custom_css_code', (stripslashes($_REQUEST['custom_css_code']))); update_option('pp_album_review_custom_js_code', (stripslashes($_REQUEST['custom_js_code']))); if(array_key_exists('font', $_REQUEST)) update_option( 'pp_album_review_font', $_REQUEST['font']); if(array_key_exists('font_color', $_REQUEST)) update_option( 'pp_album_review_font_color', $_REQUEST['font_color']); if(array_key_exists('font_style', $_REQUEST)) update_option( 'pp_album_review_font_style', $_REQUEST['font_style']); if(array_key_exists('title_font', $_REQUEST)) update_option( 'pp_album_review_title_font', $_REQUEST['title_font']); if(array_key_exists('title_font_style', $_REQUEST)) update_option( 'pp_album_review_title_font_style', $_REQUEST['title_font_style']); if(array_key_exists('greeting_font_size', $_REQUEST)) update_option( 'pp_album_review_greeting_font_size', $_REQUEST['greeting_font_size']); if(array_key_exists('title_font_size', $_REQUEST)) update_option( 'pp_album_review_title_font_size', $_REQUEST['title_font_size']); if(array_key_exists('logo_size', $_REQUEST)) update_option( '$this->logo_size', $_REQUEST['logo_size']); if(array_key_exists('ga_property_id', $_REQUEST)) update_option( 'pp_album_review_ga_property_id', $_REQUEST['ga_property_id']); if(array_key_exists('redirect_page', $_REQUEST)) update_option( 'pp_album_review_redirect_page', $_REQUEST['redirect_page']); $this->log('pp_album_review_save_settings ' . serialize($_REQUEST) . ' ' . (stripslashes($_REQUEST['msg_to_client']))); require_once(ABSPATH . '/wp-includes/class-wp-ajax-response.php'); $response = new WP_Ajax_Response; $response->add( array('data' => 'success', 'supplemental' => array( 'message' => 'success'), ) ); $this->log('pp_album_review_save_settings response send'); $response->send(); die(); } /** * Saves album spread selections. * * @since 1.0.0 */ public function insert_pages( ){ // need to check if each page has a resized version. $this->log('insert_pages entered'); $post_id = absint($_REQUEST['post_id']); $attachments = $_REQUEST['attachments']; if(array_key_exists('page_type', $_REQUEST)) { $page_type = $_REQUEST['page_type']; if($page_type == 'spreads') update_post_meta($post_id, '_pp_album_pages', 'spreads'); else if($page_type == 'pages') update_post_meta($post_id, '_pp_album_pages', 'pages'); } else { $page_type = ''; } $this->log($post_id); $this->log(serialize($attachments)); if($attachments[0] != '0') { $this->log('calling pages insert'); $result = $this->pages->insert($post_id, $attachments); $this->log(serialize($attachments)); } // auto publish post after pages are posted // wp_publish_post( $post_id ); $all_pages = $this->pages->get_page_thumbnails( $post_id ); $this->log('get_page_thumbnails: ' . serialize( $all_pages) ); $all_filenames = $this->pages->get_page_file_locations( $post_id ); $this->log('get_page_file_locations: ' . serialize( $all_filenames) ); $all_page_ids = $this->pages->get_page_ids( $post_id ); $this->log('get_page_ids: ' . serialize( $all_page_ids) ); $this->log('page_type: ' . serialize( $page_type) ); $this->log('now generate response ' . count( $all_pages) ); $output = array(); for ( $i = 0; $i < count( $all_pages ); ++$i) { array_push($output, array( 'thumb' => $all_pages[$i], 'id' => $all_page_ids[$i], 'filename' => $all_filenames[$i] ) ); } wp_send_json( array( 'data' => 'success', 'result' => $output, 'page_type' => $page_type ) ); } /** * Saves album spread selections. * * @since 1.0.0 */ public function insert_comments( ){ $post_id = absint( $_REQUEST['post_id']); $page_id = absint( $_REQUEST['page_id']); $comment = $_REQUEST['comment']; $comment = sanitize_text_field($comment); $comment_from = $_REQUEST['comment_from']; if($comment_from === 'designer_comment') $commenter = PP_ALBUM_DESIGNER; else $commenter = PP_ALBUM_CLIENT; if( !$post_id || !$page_id ){ wp_send_json( array( 'data' => 'error', 'result' => 'Invalid post_id or page_id.' ) ); } $result = $this->comments->insert($page_id, $comment, $commenter); $this->log('pp_album_review_insert_comment_ajax: ' . $post_id . ' ' . $page_id .' '.$commenter); $comments = $this->comments->read_all( $post_id ); // $comments = 'testing'; if($commenter == PP_ALBUM_CLIENT){ add_post_meta($post_id, 'pp_album-view_stat_time_ip', 'PP_ALBUM_COMMENT_ADDED' . ',' . $_SERVER['REMOTE_ADDR'] . ',' . date_i18n( 'Y-m-d H:i:s', (int)current_time( 'timestamp' )) . ',' . $page_id . ',' . $comment); update_post_meta($post_id, 'pp_album_new_comments', '1'); } wp_send_json( array( 'data' => 'success', 'post_id' => $post_id, 'page_id' => $page_id, 'message' => $comments ) ); } }