Skip to content

beta changes #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Aug 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 45 additions & 5 deletions admin_section/common-function.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,54 @@ function saswp_get_tab( $default = '', $available = array() ) {
return $tab;
}

$sd_data=array();
add_action('plugins_loaded', 'saswp_defaultSettings' );

$sd_data=array();
function saswp_defaultSettings(){
global $sd_data;
global $sd_data;
$current_user = wp_get_current_user();
$current_url = get_home_url();
$custom_logo_id = get_theme_mod( 'custom_logo' );
$logo = wp_get_attachment_image_src( $custom_logo_id , 'full' );
$defaults = array(
'saswp-for-wordpress' => 0,
'saswp-for-amp' => 0,
'saswp-for-amp' => 1,
'saswp-for-wordpress'=>1,
'sd_post_type'=> 'Blogposting',
'sd_page_type'=> 'WebPage',
'saswp_kb_type' => 'Organization',
'saswp_kb_contact_1' => 0,
'sd_name' => $current_user->user_login,
'sd_alt_name' => $current_user->user_login,
'sd-person-name' => $current_user->user_nicename,
'sd-person-url' => $current_url,
'saswp-logo-width' => '600',
'saswp-logo-height' => '60',
'sd_logo' => array(
'url'=>$logo[0],
'id'=>$custom_logo_id,
'height'=>$logo[2],
'width'=>$logo[1],
'thumbnail'=>$logo[0]
),
'sd-data-logo-ampforwp' => array(
'url'=>$logo[0],
'id'=>$custom_logo_id,
'height'=>$logo[2],
'width'=>$logo[1],
'thumbnail'=>$logo[0]
),
'sd_default_image' => array(
'url'=>$logo[0],
'id'=>$custom_logo_id,
'height'=>$logo[2],
'width'=>$logo[1],
'thumbnail'=>$logo[0]
),
'sd_default_image_width' =>$logo[1],
'sd_default_image_height' =>$logo[2]

);
$sd_data = $settings = get_option( 'sd_data', $defaults);
$sd_data = $settings = get_option( 'sd_data', $defaults);
return $settings;
}
saswp_defaultSettings();
7 changes: 5 additions & 2 deletions admin_section/css/main-style.css
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ and open the template in the editor.
width:100%
}
.saswp-settings-list li{
padding:15px;
padding-left:0px;
padding:15px;
padding-left:0px;
}
.saswp-settings-list li div label{
font-weight: 600;
Expand All @@ -53,6 +53,9 @@ padding-left:0px;
.saswp_qanda_p{
font-weight: 500;
}
.saswp-display-none{
display: none !important;
}



Expand Down
18 changes: 17 additions & 1 deletion admin_section/fields-generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,19 @@ public function saswp_field_generator( $meta_fields, $settings ) {
$input .= '</select>';
break;
default:
$socialfield = array('sd_facebook', 'sd_twitter', 'sd_google_plus', 'sd_instagram', 'sd_youtube', 'sd_linkedin', 'sd_pinterest', 'sd_soundcloud', 'sd_tumblr');

if(in_array($meta_field['id'], $socialfield)){
$input = sprintf(
'<input data-id="'.esc_attr($meta_field['id']).'" type="checkbox" class="saswp-social-field-check" ><input class="%s saswp-social-fields" %s id="%s" name="%s" type="%s" value="%s">',
$class,
$meta_field['type'] !== 'color' ? 'style="width: 100%"' : '',
esc_attr($meta_field['id']),
esc_attr($meta_field['name']),
esc_attr($meta_field['type']),
esc_attr($settings[$meta_field['id']])
);
}else{
$input = sprintf(
'<input class="%s" %s id="%s" name="%s" type="%s" value="%s">',
$class,
Expand All @@ -92,7 +105,10 @@ public function saswp_field_generator( $meta_fields, $settings ) {
esc_attr($meta_field['name']),
esc_attr($meta_field['type']),
esc_attr($settings[$meta_field['id']])
);
);
}


}

$allowed_html = saswp_expanded_allowed_tags();
Expand Down
30 changes: 23 additions & 7 deletions admin_section/js/main-script.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,21 @@ jQuery(document).ready(function($){
window.history.pushState("", "", href);
return false;
});
//Settings page jquery starts here
//Settings page jquery starts here

$(".saswp-social-fields").each(function(){
var val = $(this).val();
if(val){
$(this).parent().find(".saswp-social-field-check").hide();
}else{
$(this).hide();
}
});
$(".saswp-social-field-check").change(function(){
var socialtype = $(this).attr("data-id");
$(".saswp-social-fields[id="+socialtype+"]").show();
$(this).hide();
});
$(".saswp-checkbox").change(function(){
var id = $(this).attr("id");
switch(id){
Expand All @@ -47,18 +61,18 @@ jQuery(document).ready(function($){

if ($(this).is(':checked')) {
$("#saswp_kb_contact_1").val(1);
$("#saswp_kb_telephone, #saswp_contact_type").parent().parent('li').show();
}else{
$("#saswp_kb_telephone, #saswp_contact_type").parent().parent('li').removeClass("saswp-display-none");
}else{
$("#saswp_kb_contact_1").val(0);
$("#saswp_kb_telephone, #saswp_contact_type").parent().parent('li').hide();
$("#saswp_kb_telephone, #saswp_contact_type").parent().parent('li').addClass("saswp-display-none");
}
break;
case 'saswp-logo-dimensions-check':

if ($(this).is(':checked')) {
$("#saswp-logo-dimensions").val(1);
$("#saswp-logo-width, #saswp-logo-height").parent().parent('li').show();
}else{
$("#saswp-logo-width, #saswp-logo-height").parent().parent('li').show();
}else{
$("#saswp-logo-dimensions").val(0);
$("#saswp-logo-width, #saswp-logo-height").parent().parent('li').hide();
}
Expand Down Expand Up @@ -94,12 +108,14 @@ jQuery(document).ready(function($){
}else{
$( ".saswp-knowledge-base li:eq('"+i+"')" ).show();
}
}else{
}else if(datatype ==="Organization"){
if(i<8){
$( ".saswp-knowledge-base li:eq('"+i+"')" ).show();
}else{
$( ".saswp-knowledge-base li:eq('"+i+"')" ).hide();
}
}else{
$( ".saswp-knowledge-base li:eq('"+i+"')" ).hide();
}

}
Expand Down
2 changes: 1 addition & 1 deletion admin_section/js/structure_admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jQuery(document).ready(function($){
parent.children(".spinner").addClass("show");
var ajaxURL = amp_sdwp_field_data.ajax_url;
//ajax call
$.ajax({
$.ajax({
url : ajaxURL,
method : "POST",
data: {
Expand Down
131 changes: 131 additions & 0 deletions admin_section/newsletter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
<?php class saswp_newsletter {
const DISPLAY_VERSION = 'v1.0';
function __construct () {
add_action('admin_enqueue_scripts', array($this, 'saswp_admin_enqueue_scripts'));
}
function saswp_admin_enqueue_scripts () {
$dismissed = explode (',', get_user_meta (wp_get_current_user ()->ID, 'dismissed_wp_pointers', true));
$do_tour = !in_array ('saswp_subscribe_pointer', $dismissed);
if ($do_tour) {
wp_enqueue_style ('wp-pointer');
wp_enqueue_script ('wp-pointer');
add_action('admin_print_footer_scripts', array($this, 'saswp_admin_print_footer_scripts'));
add_action('admin_head', array($this, 'saswp_admin_head')); // Hook to admin head
}
}
function saswp_admin_head () {
?>
<style type="text/css" media="screen"> #pointer-primary { margin: 0 5px 0 0; } </style>
<?php }
function saswp_admin_print_footer_scripts () {

global $pagenow;
global $current_user;
$tour = array ();
$tab = isset($_GET['tab']) ? $_GET['tab'] : '';
$function = '';
$button2 = '';
$options = array ();
$show_pointer = false;

if (!array_key_exists($tab, $tour)) {
$show_pointer = true;
$displayID = '#menu-posts-saswp'; // Define ID used on page html element where we want to display pointer
$content = '<h3>' . sprintf (__('Thanks for using Structured Data!', 'schema-and-structured-data-for-wp'), self::DISPLAY_VERSION) . '</h3>';
$content .= __('<p>Do you want the latest on <b>Structured Data update</b> before others and some best resources on monetization in a single email? - Free just for users of Structured Data!</p>', 'schema-and-structured-data-for-wp');
$content .= __('
<style type="text/css">
.wp-pointer-buttons{ padding:0; overflow: hidden; }
.wp-pointer-content .button-secondary{ left: -25px;background: transparent;top: 5px; border: 0;position: relative; padding: 0; box-shadow: none;margin: 0;color: #0085ba;} .wp-pointer-content .button-primary{ display:none} #afw_mc_embed_signup{background:#fff; clear:left; font:14px Helvetica,Arial,sans-serif; }
</style>
<div id="afw_mc_embed_signup">
<form class="ml-block-form" action="https://app.mailerlite.com/webforms/submit/z7t4b8" data-code="z7t4b8" method="post" target="_blank">
<div id="afw_mc_embed_signup_scroll">
<div class="afw-mc-field-group" style=" margin-left: 15px; width: 195px; float: left;">
<input type="text" name="fields[name]" class="form-control" placeholder="Name" hidden value="' . esc_attr( $current_user->display_name ) . '" style="display:none">

<input type="text" value="' . esc_attr( $current_user->user_email ) . '" name="fields[email]" class="form-control" placeholder="Email*" style=" width: 180px; padding: 6px 5px;">

<input type="text" name="fields[company]" class="form-control" placeholder="Website" hidden style=" display:none; width: 168px; padding: 6px 5px;" value="' . esc_attr( get_home_url() ) . '">

<input type="hidden" name="ml-submit" value="1" />
</div>
<div id="mce-responses">
<div class="response" id="mce-error-response" style="display:none"></div>
<div class="response" id="mce-success-response" style="display:none"></div>
</div>
<!-- real people should not fill this in and expect good things - do not remove this or risk form bot signups-->
<div style="position: absolute; left: -5000px;" aria-hidden="true"><input type="text" name="b_a631df13442f19caede5a5baf_c9a71edce6" tabindex="-1" value=""></div>
<input type="submit" value="Subscribe" name="subscribe" id="pointer-close" class="button mc-newsletter-sent" style=" background: #0085ba; border-color: #006799; padding: 0px 16px; text-shadow: 0 -1px 1px #006799,1px 0 1px #006799,0 1px 1px #006799,-1px 0 1px #006799; height: 30px; margin-top: 1px; color: #fff; box-shadow: 0 1px 0 #006799;">
</div>
</form>
</div>','schema-and-structured-data-for-wp');
$options = array (
'content' => $content,
'position' => array ('edge' => 'top', 'align' => 'left')
);
}
if ($show_pointer) {
$this->saswp_pointer_script ($displayID, $options, esc_html__('No Thanks', 'schema-and-structured-data-for-wp'), $button2, $function);
}
}
function saswp_get_admin_url($page, $tab) {
$url = admin_url();
$url .= $page.'?tab='.$tab;
return $url;
}
function saswp_pointer_script ($displayID, $options, $button1, $button2=false, $function='') {
?>
<script type="text/javascript">
(function ($) {
var wp_pointers_tour_opts = <?php echo json_encode ($options); ?>, setup;
wp_pointers_tour_opts = $.extend (wp_pointers_tour_opts, {
buttons: function (event, t) {
button= jQuery ('<a id="pointer-close" class="button-secondary">' + '<?php echo $button1; ?>' + '</a>');
button_2= jQuery ('#pointer-close.button');
button.bind ('click.pointer', function () {
t.element.pointer ('close');
});
button_2.on('click', function() {
t.element.pointer ('close');
} );
return button;
},
close: function () {
$.post (ajaxurl, {
pointer: 'saswp_subscribe_pointer',
action: 'dismiss-wp-pointer'
});
},
show: function(event, t){
t.pointer.css({'left':'170px', 'top':'160px'});
}
});
setup = function () {
$('<?php echo esc_attr($displayID); ?>').pointer(wp_pointers_tour_opts).pointer('open');
<?php if ($button2) { ?>
jQuery ('#pointer-close').after ('<a id="pointer-primary" class="button-primary">' + '<?php echo $button2; ?>' + '</a>');
jQuery ('#pointer-primary').click (function () {
<?php echo $function; ?>
});
jQuery ('#pointer-close').click (function () {
$.post (ajaxurl, {
pointer: 'asaswp_subscribe_pointer',
action: 'dismiss-wp-pointer'
});
})
<?php } ?>
};
if (wp_pointers_tour_opts.position && wp_pointers_tour_opts.position.defer_loading) {
$(window).bind('load.wp-pointers', setup);
}
else {
setup ();
}
}) (jQuery);
</script>
<?php
}
}
$saswp_newsletter = new saswp_newsletter();
?>
3 changes: 2 additions & 1 deletion admin_section/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function saswp_admin_interface_render(){
}
// Handing save settings
if ( isset( $_GET['settings-updated'] ) ) {
// Show Settings Saved Message
// Show Settings Saved Message
settings_errors();
}
$tab = saswp_get_tab('general', array('general','knowledge','schema', 'help'));
Expand Down Expand Up @@ -343,6 +343,7 @@ function saswp_knowledge_page_callback(){
'name' => 'sd_data[saswp_kb_type]',
'type' => 'select',
'options' => array(
''=>'Select an item',
'Organization'=>'Organization',
'Person'=>'Person',
)
Expand Down
8 changes: 4 additions & 4 deletions admin_section/structure_admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ function saswp_generate_field_data( $post_id ){
}

function saswp_comparison_logic_checker($input){
global $post;
global $post;
$type = $input['key_1'];
$comparison = $input['key_2'];
$data = $input['key_3'];
Expand Down Expand Up @@ -513,9 +513,9 @@ function saswp_select_save_data ( $post_id ) {
if( !isset( $_POST['saswp_select_name_nonce'] ) || !wp_verify_nonce( $_POST['saswp_select_name_nonce'], 'saswp_select_action_nonce' ) ) return;

// if our current user can't edit this post, bail
if( !current_user_can( 'edit_post' ) ) return;
$post_data_array = array();

if( !current_user_can( 'edit_post' ) ) return;
$meta_value = get_post_meta( $post_id, null, true );
$post_data_array = array();
foreach($_POST['data_array'] as $post){
$post_data_array[] = array_map('sanitize_text_field', $post);
}
Expand Down
1 change: 1 addition & 0 deletions structured-data-for-wp.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,6 @@ function saswp_non_amp(){
require_once SASWP_DIR_NAME.'/admin_section/settings.php';
require_once SASWP_DIR_NAME.'/admin_section/common-function.php';
require_once SASWP_DIR_NAME.'/admin_section/fields-generator.php';
require_once SASWP_DIR_NAME.'/admin_section/newsletter.php';
//Loading Metaboxes
require SASWP_DIR_NAME.'/metaboxes/help.php';