| 1 |
<?php if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly ?> |
| 2 |
<?php |
| 3 |
|
| 4 |
include('settings.php'); |
| 5 |
|
| 6 |
// ============================================================ |
| 7 |
// checking if the data exists on the database |
| 8 |
// ============================================================ |
| 9 |
global $wpdb; |
| 10 |
|
| 11 |
// ----------------------------------------------- |
| 12 |
// incase this is a regular page or a blog post |
| 13 |
// ----------------------------------------------- |
| 14 |
$this_post_id = intval( get_the_ID() ); |
| 15 |
|
| 16 |
if( isset($yydev_notes_active_dashbaord) && ($yydev_notes_active_dashbaord == 1) ) { |
| 17 |
$this_post_id = 0; |
| 18 |
} // if( isset($yydev_notes_active_dashbaord) && ($yydev_notes_active_dashbaord == 1) ) { |
| 19 |
|
| 20 |
$notes_id = ''; |
| 21 |
$notes_message = ''; |
| 22 |
$button_text = '+ Add Note'; |
| 23 |
$button_class = ''; |
| 24 |
$hide_notes = 'not-active-notes'; |
| 25 |
|
| 26 |
// setting the direction class from the theme direction |
| 27 |
if( is_rtl() ) { |
| 28 |
$table_direction_class = "direction-rtl"; |
| 29 |
} else { // if( is_rtl() ) { |
| 30 |
$table_direction_class = "direction-ltr"; |
| 31 |
} // } else { // if( is_rtl() ) { |
| 32 |
|
| 33 |
|
| 34 |
if( isset($this_post_id) ) { |
| 35 |
|
| 36 |
$yydevl_notes_data = $wpdb->get_row("SELECT * FROM " . $table_name . " WHERE page_post_id = $this_post_id "); |
| 37 |
|
| 38 |
if( $wpdb->num_rows > 0 ) { |
| 39 |
|
| 40 |
$notes_id = $yydevl_notes_data->id; |
| 41 |
|
| 42 |
// checking if this is an array and if not conver it to array |
| 43 |
if( strstr($yydevl_notes_data->notes, '###') ) { |
| 44 |
|
| 45 |
$yydevl_notes_data_output = explode('###', $yydevl_notes_data->notes); |
| 46 |
|
| 47 |
} else { // if( strstr($yydevl_notes_data->notes, '###') ) { |
| 48 |
|
| 49 |
$yydevl_notes_data_output = array($yydevl_notes_data->notes); |
| 50 |
|
| 51 |
} // } else { // if( strstr($yydevl_notes_data->notes, '###') ) { |
| 52 |
|
| 53 |
} // if( $wpdb->num_rows > 0 ) { |
| 54 |
|
| 55 |
|
| 56 |
} // if( !empty($this_post_id) ) { |
| 57 |
|
| 58 |
if(!empty($text_direction)) { |
| 59 |
$table_direction_class = $text_direction; |
| 60 |
} // if(!empty($text_direction)) { |
| 61 |
|
| 62 |
?> |
| 63 |
|
| 64 |
<div class="yydev-notes"> |
| 65 |
|
| 66 |
<?php |
| 67 |
|
| 68 |
if( isset($yydevl_notes_data_output) ) { |
| 69 |
|
| 70 |
// ============================================================ |
| 71 |
// If there are notes on the database |
| 72 |
// ============================================================ |
| 73 |
|
| 74 |
foreach($yydevl_notes_data_output as $notes_data_output) { |
| 75 |
|
| 76 |
$yydevl_notes_data = explode("^^", $notes_data_output); |
| 77 |
|
| 78 |
|
| 79 |
$notes_message = $yydevl_notes_data[0]; |
| 80 |
$table_direction_class = $yydevl_notes_data[1]; |
| 81 |
|
| 82 |
$hide_notes = ''; |
| 83 |
|
| 84 |
$button_text = '+ Add Another Note'; |
| 85 |
$button_class = 'yy-another-notes'; |
| 86 |
|
| 87 |
?> |
| 88 |
|
| 89 |
<div class="yydev-textarea-note <?php echo esc_attr($hide_notes); ?>"> |
| 90 |
<textarea cols="150" rows="8" class="table_notes <?php echo esc_attr($table_direction_class); ?>" name="yydev_notes[]" ><?php echo yydev_notes_html_output( esc_textarea($notes_message) ); ?></textarea> |
| 91 |
<a class='remove-notes-btn' href='#'><img src='<?php echo esc_url( plugins_url( 'images/remove.png', dirname(__FILE__) ) ); ?>' alt='' title='Remove Notes' /></a> |
| 92 |
<a class='text-direction_btn' href='#'><img src='<?php echo esc_url( plugins_url( 'images/text-direction.png', dirname(__FILE__) ) ); ?>' alt='' title='Test Direction' /></a> |
| 93 |
<a class='text-separator_btn' href='#'><img src='<?php echo esc_url( plugins_url( 'images/separator.png', dirname(__FILE__) ) ); ?>' alt='' title='Separator' /></a> |
| 94 |
<input type="hidden" name="yydev_direction_class[]" class="yydev_direction_class" value="<?php echo esc_attr($table_direction_class); ?>" /> |
| 95 |
<input type="hidden" name="yydev_notes_page_id" value="<?php echo intval($this_post_id); ?>" /> |
| 96 |
<input type="hidden" name="yydev_notes_id" value="<?php echo intval($notes_id); ?>" /> |
| 97 |
</div><!--add-table-notes--> |
| 98 |
|
| 99 |
<?php |
| 100 |
|
| 101 |
} // foreach($yydevl_notes_data_output as $notes_data_output) { |
| 102 |
|
| 103 |
} else { // if( isset($yydevl_notes_data_output) ) { |
| 104 |
|
| 105 |
// ============================================================ |
| 106 |
// If there are no notes on the database |
| 107 |
// ============================================================ |
| 108 |
|
| 109 |
?> |
| 110 |
<div class="yydev-textarea-note <?php echo esc_attr($hide_notes); ?>"> |
| 111 |
<textarea cols="150" rows="8" class="table_notes <?php echo esc_attr($table_direction_class); ?>" name="yydev_notes[]" ><?php echo yydev_notes_html_output( esc_textarea($notes_message) ); ?></textarea> |
| 112 |
<a class='remove-notes-btn' href='#'><img src='<?php echo esc_url( plugins_url( 'images/remove.png', dirname(__FILE__) ) ); ?>' alt='' title='Remove Notes' /></a> |
| 113 |
<a class='text-direction_btn' href='#'><img src='<?php echo esc_url( plugins_url( 'images/text-direction.png', dirname(__FILE__) ) ); ?>' alt='' title='Remove Notes' /></a> |
| 114 |
<a class='text-separator_btn' href='#'><img src='<?php echo esc_url( plugins_url( 'images/separator.png', dirname(__FILE__) ) ); ?>' alt='' title='Separator' /></a> |
| 115 |
<input type="hidden" name="yydev_direction_class[]" class="yydev_direction_class" value="<?php echo esc_attr($table_direction_class); ?>" /> |
| 116 |
<input type="hidden" name="yydev_notes_page_id" value="<?php echo intval($this_post_id); ?>" /> |
| 117 |
<input type="hidden" name="yydev_notes_id" value="<?php echo intval($notes_id); ?>" /> |
| 118 |
</div><!--add-table-notes--> |
| 119 |
|
| 120 |
<?php |
| 121 |
|
| 122 |
} // } else { // if( isset($yydevl_notes_data_output) ) { |
| 123 |
|
| 124 |
?> |
| 125 |
|
| 126 |
<?php |
| 127 |
// creating nonce to make sure the form was submitted correctly from the right page |
| 128 |
wp_nonce_field( 'yydev_notes_action', 'yydev_notes_nonce' ); |
| 129 |
?> |
| 130 |
|
| 131 |
<a href="#" class="direction-ltr add-notes-button <?php echo $button_class; ?>"><?php echo $button_text; ?></a> |
| 132 |
|
| 133 |
<?php |
| 134 |
|
| 135 |
// ============================================================ |
| 136 |
// Echo save button on dashboard |
| 137 |
// ============================================================ |
| 138 |
|
| 139 |
$save_data_button_class = 'yydev-notes-hide-button'; |
| 140 |
if( isset($yydev_notes_active_dashbaord) && ($yydev_notes_active_dashbaord == 1) ) { |
| 141 |
$save_data_button_class = ''; |
| 142 |
} // if( isset($yydev_notes_active_dashbaord) && ($yydev_notes_active_dashbaord == 1) ) { |
| 143 |
|
| 144 |
?> |
| 145 |
|
| 146 |
<a href="#" class="dashbaord-save-button <?php echo $save_data_button_class; ?>">Save Notes Data</a> |
| 147 |
<div class='yydev-notes-ajax-data'></div> |
| 148 |
|
| 149 |
</div><!--yydev-notes--> |