| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Suppress "error - 0 - No summary was found for this file" on phpdoc generation |
| 5 |
* |
| 6 |
* @package WPDataProjects\Project |
| 7 |
*/ |
| 8 |
namespace WPDataProjects\Project; |
| 9 |
|
| 10 |
use WPDataAccess\WPDA; |
| 11 |
use WPDataProjects\Parent_Child\WPDP_Child_List_Table; |
| 12 |
/** |
| 13 |
* Class WPDP_Project_Page_List extends WPDP_Child_List_Table |
| 14 |
* |
| 15 |
* @see WPDP_Child_List_Table |
| 16 |
* |
| 17 |
* @author Peter Schulz |
| 18 |
* @since 2.0.0 |
| 19 |
*/ |
| 20 |
class WPDP_Project_Page_List extends WPDP_Child_List_Table { |
| 21 |
/** |
| 22 |
* WPDP_Project_Page_List constructor |
| 23 |
* |
| 24 |
* Add specific column headers to list table |
| 25 |
* |
| 26 |
* @param array $args |
| 27 |
*/ |
| 28 |
public function __construct( array $args = array() ) { |
| 29 |
// Add column labels. |
| 30 |
$args['column_headers'] = self::column_headers_labels(); |
| 31 |
// Show action links in column page_name |
| 32 |
$this->first_display_column = 'page_id'; |
| 33 |
parent::__construct( $args ); |
| 34 |
} |
| 35 |
|
| 36 |
/** |
| 37 |
* Overwrites method column_default to support static pages |
| 38 |
* |
| 39 |
* @param array $item |
| 40 |
* @param string $column_name |
| 41 |
* |
| 42 |
* @return mixed|string |
| 43 |
*/ |
| 44 |
public function column_default( $item, $column_name ) { |
| 45 |
if ( 'page_id' === $column_name ) { |
| 46 |
// Validate schema, table and column names |
| 47 |
$warning = WPDA::validate_names( $item['page_schema_name'], $item['page_table_name'] ); |
| 48 |
if ( '' !== $warning ) { |
| 49 |
$content = $item['page_id'] . $warning . substr( parent::column_default( $item, $column_name ), strlen( $item['page_id'] ) ); |
| 50 |
return $content; |
| 51 |
} |
| 52 |
} |
| 53 |
if ( 'page_schema_name' === $column_name ) { |
| 54 |
global $wpdb; |
| 55 |
if ( $wpdb->dbname === $item[$column_name] ) { |
| 56 |
return "WordPress database ({$item[$column_name]})"; |
| 57 |
} |
| 58 |
} |
| 59 |
if ( 'static' === $item['page_type'] && ('page_table_name' === $column_name || 'page_mode' === $column_name || 'page_allow_insert' === $column_name || 'page_allow_delete' === $column_name) ) { |
| 60 |
return ''; |
| 61 |
} else { |
| 62 |
if ( 'static' !== $item['page_type'] && 'page_content' === $column_name ) { |
| 63 |
return ''; |
| 64 |
} else { |
| 65 |
return parent::column_default( $item, $column_name ); |
| 66 |
} |
| 67 |
} |
| 68 |
} |
| 69 |
|
| 70 |
/** |
| 71 |
* Add action "show shortcode" |
| 72 |
* |
| 73 |
* @param array $item |
| 74 |
* @param string $column_name |
| 75 |
* @param array $actions |
| 76 |
*/ |
| 77 |
protected function column_default_add_action( $item, $column_name, &$actions ) { |
| 78 |
$link_title = 'Get shortcode'; |
| 79 |
$title = 'Shortcode'; |
| 80 |
?> |
| 81 |
<div id="wpda_project_<?php |
| 82 |
echo esc_attr( $item['page_id'] ); |
| 83 |
?>" |
| 84 |
title="<?php |
| 85 |
echo __( 'Shortcodes', 'wp-data-access' ); |
| 86 |
?>" |
| 87 |
style="display:none" |
| 88 |
> |
| 89 |
<p class="wpda_shortcode_content"> |
| 90 |
Copy shortcode into your post or page to make this Data Project page available on your website. |
| 91 |
</p> |
| 92 |
|
| 93 |
<?php |
| 94 |
?> |
| 95 |
|
| 96 |
<p class="wpda_shortcode_text"> |
| 97 |
<strong> |
| 98 |
[wpdadiehard project_id="<?php |
| 99 |
echo esc_attr( $item['project_id'] ); |
| 100 |
?>" page_id="<?php |
| 101 |
echo esc_attr( $item['page_id'] ); |
| 102 |
?>"] |
| 103 |
</strong> |
| 104 |
</p> |
| 105 |
<p class="wpda_shortcode_buttons"> |
| 106 |
<button class="button wpda_shortcode_clipboard wpda_shortcode_button" |
| 107 |
type="button" |
| 108 |
data-clipboard-text='[wpdadiehard project_id="<?php |
| 109 |
echo esc_attr( $item['project_id'] ); |
| 110 |
?>" page_id="<?php |
| 111 |
echo esc_attr( $item['page_id'] ); |
| 112 |
?>"]' |
| 113 |
onclick="jQuery.notify('<?php |
| 114 |
echo __( 'Shortcode successfully copied to clipboard!' ); |
| 115 |
?>','info')" |
| 116 |
> |
| 117 |
<?php |
| 118 |
echo __( 'Copy', 'wp-data-access' ); |
| 119 |
?> |
| 120 |
</button> |
| 121 |
<button class="button button-primary wpda_shortcode_button" |
| 122 |
type="button" |
| 123 |
onclick="jQuery('.ui-dialog-content').dialog('close')" |
| 124 |
> |
| 125 |
<?php |
| 126 |
echo __( 'Close', 'wp-data-access' ); |
| 127 |
?> |
| 128 |
</button> |
| 129 |
</p> |
| 130 |
<?php |
| 131 |
$shortcode_enabled = 'on' === WPDA::get_option( WPDA::OPTION_PLUGIN_WPDADIEHARD_POST ) && 'on' === WPDA::get_option( WPDA::OPTION_PLUGIN_WPDADIEHARD_PAGE ); |
| 132 |
if ( !$shortcode_enabled ) { |
| 133 |
?> |
| 134 |
<p> |
| 135 |
Shortcode wpdadiehard is not enabled for all output types.<br/> |
| 136 |
<a href="<?php |
| 137 |
echo admin_url( 'options-general.php' ); |
| 138 |
// phpcs:ignore WordPress.Security.EscapeOutput |
| 139 |
?>?page=wpdataaccess" class="wpda_shortcode_link">» Manage settings</a> |
| 140 |
</p> |
| 141 |
<?php |
| 142 |
} |
| 143 |
?> |
| 144 |
</div> |
| 145 |
<?php |
| 146 |
$actions['shortcode2'] = sprintf( |
| 147 |
'<a href="javascript:void(0)" |
| 148 |
class="view wpda_tooltip" |
| 149 |
title="%s" |
| 150 |
onclick="jQuery(\'#wpda_project_%s\').dialog({width:400})" |
| 151 |
<span style="white-space:nowrap"> |
| 152 |
<i class="fas fa-code wpda_icon_on_button"></i> |
| 153 |
%s |
| 154 |
</span> |
| 155 |
</a> |
| 156 |
', |
| 157 |
$link_title, |
| 158 |
esc_attr( $item['page_id'] ), |
| 159 |
$title |
| 160 |
); |
| 161 |
} |
| 162 |
|
| 163 |
public static function column_headers_labels() { |
| 164 |
return array( |
| 165 |
'project_id' => __( 'Project ID', 'wp-data-access' ), |
| 166 |
'page_id' => __( 'Page ID', 'wp-data-access' ), |
| 167 |
'add_to_menu' => __( 'Add To Menu', 'wp-data-access' ), |
| 168 |
'page_name' => __( 'Menu Name', 'wp-data-access' ), |
| 169 |
'page_type' => __( 'Type', 'wp-data-access' ), |
| 170 |
'page_schema_name' => __( 'Schema Name', 'wp-data-access' ), |
| 171 |
'page_table_name' => __( 'Table Name', 'wp-data-access' ), |
| 172 |
'page_setname' => __( 'Template Set Name', 'wp-data-access' ), |
| 173 |
'page_mode' => __( 'Mode', 'wp-data-access' ), |
| 174 |
'page_allow_insert' => __( 'Allow insert?', 'wp-data-access' ), |
| 175 |
'page_allow_delete' => __( 'Allow delete?', 'wp-data-access' ), |
| 176 |
'page_allow_import' => __( 'Allow import?', 'wp-data-access' ), |
| 177 |
'page_allow_bulk' => __( 'Allow bulk actions?', 'wp-data-access' ), |
| 178 |
'page_allow_full_export' => __( 'Allow full table export?', 'wp-data-access' ), |
| 179 |
'page_content' => __( 'Post', 'wp-data-access' ), |
| 180 |
'page_title' => __( 'Title', 'wp-data-access' ), |
| 181 |
'page_subtitle' => __( 'Subtitle', 'wp-data-access' ), |
| 182 |
'page_role' => __( 'Role', 'wp-data-access' ), |
| 183 |
'page_where' => __( 'WHERE Clause', 'wp-data-access' ), |
| 184 |
'page_orderby' => __( 'Default ORDER BY', 'wp-data-access' ), |
| 185 |
'page_sequence' => __( 'Seq#', 'wp-data-access' ), |
| 186 |
); |
| 187 |
} |
| 188 |
|
| 189 |
// Overwrite method |
| 190 |
public function show() { |
| 191 |
parent::show(); |
| 192 |
WPDA::shortcode_popup(); |
| 193 |
} |
| 194 |
|
| 195 |
} |
| 196 |
|