Ejemplo n.º 1
0
<?php

/**
 * Metabox "submitdiv"
 *
 * Used in class-popup-admin.php
 * Available variables: $popup
 */
$delete_url = get_delete_post_link($post->ID);
$duplicate_url = esc_url_raw(add_query_arg('do', 'duplicate'));
$warn = 0 != IncPopupDatabase::count_active($post->ID);
?>
<div class="submitbox" id="submitpost">
	<?php 
/* Save/Deactivate/Preview */
?>
	<div id="minor-publishing">
		<?php 
// Hidden submit button early on so that the browser chooses the right button when form is submitted with Return key
?>
		<div style="display:none;">
			<?php 
submit_button(__('Save', PO_LANG), 'button', 'save', false);
?>
		</div>

		<div id="minor-publishing-actions" class="non-sticky">
			<div class="status"
				<?php 
if ($warn) {
    ?>
	/**
	 * Save the current popup to the database.
	 *
	 * @since  4.6
	 * @param  bool $show_message If true then a success message will be
	 *                displayed. Set to false when saving via ajax.
	 */
	public function save( $show_message = true ) {
		global $allowedposttags;

		$this->validate_data();

		if ( ! did_action( 'wp_loaded' ) ) {
			add_action( 'wp_loaded', array( $this, 'save' ) );
			return false;
		}

		switch ( $this->status ) {
			case 'active':   $status = 'publish'; break;
			case 'inactive': $status = 'draft'; break;
			case 'trash':    $status = 'trash'; break;
			default:         $status = 'draft'; break;
		}

		if ( 'publish' == $status ) {
			// Limit the number of active PopUps.
			if ( 3 <= IncPopupDatabase::count_active( $this->id ) ) {
				$status = 'draft';
				$show_message = false;

				lib2()->ui->admin_message(
					sprintf(
						__(
							'In the free version you can activate 3 PopUps. ' .
							'You can activate this PopUp when you first ' .
							'deactivate another PopUp.<br>' .
							'The PRO Version allows you to have unlimited ' .
							'active PopUps! ' .
							'<a href="%1$s" target="_blank">Find out more &raquo;</a>',
							PO_LANG
						),
						'http://premium.wpmudev.org/project/the-pop-over-plugin/'
					),
					'err'
				);
			}
		}

		// When the content changed make sure to only allow valid code!
		if ( $this->content != $this->orig_content
			&& ! current_user_can( 'unfiltered_html' )
		) {
			$this->content = wp_kses( $this->content, $allowedposttags );
		}

		// Check if the content contains (potentially) incompatible shortcodes.
		self::validate_shortcodes( $this->content );

		$post = array(
			'ID' => (0 == $this->id ? '' : $this->id),
			'post_title' => $this->name,
			'post_status' => $status,
			'post_type' => self::POST_TYPE,
			'post_content' => $this->content,
			'menu_order' => $this->order,
		);

		// Save the main popup item.
		$res = wp_insert_post( $post );

		if ( ! empty( $res ) ) {
			$this->id = $res;

			// Save metadata of the popup.
			update_post_meta( $this->id, 'po_title', $this->title );
			update_post_meta( $this->id, 'po_image', $this->image );
			update_post_meta( $this->id, 'po_image_pos', $this->image_pos );
			update_post_meta( $this->id, 'po_image_mobile', $this->image_mobile );
			update_post_meta( $this->id, 'po_subtitle', $this->subtitle );
			update_post_meta( $this->id, 'po_cta_label', $this->cta_label );
			update_post_meta( $this->id, 'po_cta_link', $this->cta_link );
			update_post_meta( $this->id, 'po_cta_target', $this->cta_target );
			update_post_meta( $this->id, 'po_custom_size', $this->custom_size );
			update_post_meta( $this->id, 'po_size', $this->size );
			update_post_meta( $this->id, 'po_color', $this->color );
			update_post_meta( $this->id, 'po_custom_colors', $this->custom_colors );
			update_post_meta( $this->id, 'po_style', $this->style );
			update_post_meta( $this->id, 'po_custom_css', $this->custom_css );
			update_post_meta( $this->id, 'po_class', $this->class );
			update_post_meta( $this->id, 'po_animation_in', $this->animation_in );
			update_post_meta( $this->id, 'po_animation_out', $this->animation_out );
			update_post_meta( $this->id, 'po_inline', $this->inline );
			update_post_meta( $this->id, 'po_round_corners', $this->round_corners );
			update_post_meta( $this->id, 'po_scroll_body', $this->scroll_body );
			update_post_meta( $this->id, 'po_can_hide', $this->can_hide );
			update_post_meta( $this->id, 'po_close_hides', $this->close_hides );
			update_post_meta( $this->id, 'po_hide_expire', $this->hide_expire );
			update_post_meta( $this->id, 'po_overlay_close', $this->overlay_close );
			update_post_meta( $this->id, 'po_form_submit', $this->form_submit );
			update_post_meta( $this->id, 'po_display', $this->display );
			update_post_meta( $this->id, 'po_display_data', $this->display_data );
			update_post_meta( $this->id, 'po_rule', $this->rule );
			update_post_meta( $this->id, 'po_rule_files', $this->rule_files );
			update_post_meta( $this->id, 'po_rule_data', $this->rule_data );
		}

		if ( $show_message ) {
			if ( ! empty( $res ) ) {
				if ( $this->orig_status === $this->status ) {
					$msg = __( 'Saved PopUp "<strong>%1$s</strong>"', PO_LANG );
				} else {
					switch ( $status ) {
						case 'publish':
							$msg = __( 'Activated PopUp "<strong>%1$s</strong>".', PO_LANG );
							break;

						case 'draft':
							$msg = __( 'Deactivated PopUp "<strong>%1$s</strong>".', PO_LANG );
							break;

						case 'trash':
							$msg = __( 'Moved PopUp "<strong>%1$s</strong>" to trash.', PO_LANG );
							break;

						default:
							$msg = __( 'Saved PopUp "<strong>%1$s</strong>".', PO_LANG );
							break;
					}
				}
				lib2()->ui->admin_message( sprintf( $msg, $this->name ) );
			} else {
				lib2()->ui->admin_message( __( 'Could not save PopUp.', PO_LANG ), 'err' );
			}
		}

		return true;
	}