| 1 |
<?php |
| 2 |
/** |
| 3 |
* Common functions |
| 4 |
* |
| 5 |
* @package Import_Facebook_Events |
| 6 |
* @subpackage Common functions |
| 7 |
* @copyright Copyright (c) 2016, Dharmesh Patel |
| 8 |
* @since 1.0 |
| 9 |
*/ |
| 10 |
|
| 11 |
// Exit if accessed directly |
| 12 |
if ( ! defined( 'ABSPATH' ) ) exit; |
| 13 |
|
| 14 |
/** |
| 15 |
* Render multi-select category input for TEC import. |
| 16 |
* |
| 17 |
* @since 1.0 |
| 18 |
* @return void |
| 19 |
*/ |
| 20 |
function ife_render_tec_category_input(){ |
| 21 |
$ife_event_cats = get_terms( IFE_TEC_TAXONOMY, array( 'hide_empty' => 0 ) ); |
| 22 |
?> |
| 23 |
<tr class="event_cats_wrapper"> |
| 24 |
<th scope="row"> |
| 25 |
<?php esc_attr_e( 'Event Categories for Event Import','import-facebook-events' ); ?> : |
| 26 |
</th> |
| 27 |
<td> |
| 28 |
<select name="event_cats[]" multiple="multiple"> |
| 29 |
<?php if( ! empty( $ife_event_cats ) ): ?> |
| 30 |
<?php foreach ($ife_event_cats as $ife_cat ): ?> |
| 31 |
<option value="<?php echo $ife_cat->term_id; ?>"> |
| 32 |
<?php echo $ife_cat->name; ?> |
| 33 |
</option> |
| 34 |
<?php endforeach; ?> |
| 35 |
<?php endif; ?> |
| 36 |
</select> |
| 37 |
<span class="ife_small"> |
| 38 |
<?php esc_attr_e( 'These categories are assign to imported event.', 'import-facebook-events' ); ?> |
| 39 |
</span> |
| 40 |
</td> |
| 41 |
</tr> |
| 42 |
<?php |
| 43 |
} |
| 44 |
|
| 45 |
/** |
| 46 |
* Render multi-select category input for EM import. |
| 47 |
* |
| 48 |
* @since 1.0 |
| 49 |
* @return void |
| 50 |
*/ |
| 51 |
function ife_render_em_category_input(){ |
| 52 |
$ife_event_cats = get_terms( IFE_EM_TAXONOMY, array( 'hide_empty' => 0 ) ); |
| 53 |
?> |
| 54 |
<tr class="event_cats_wrapper"> |
| 55 |
<th scope="row"> |
| 56 |
<?php esc_attr_e( 'Event Categories for Event Import','import-facebook-events' ); ?> : |
| 57 |
</th> |
| 58 |
<td> |
| 59 |
<select name="event_cats[]" multiple="multiple"> |
| 60 |
<?php if( ! empty( $ife_event_cats ) ): ?> |
| 61 |
<?php foreach ($ife_event_cats as $ife_cat ): ?> |
| 62 |
<option value="<?php echo $ife_cat->term_id; ?>"> |
| 63 |
<?php echo $ife_cat->name; ?> |
| 64 |
</option> |
| 65 |
<?php endforeach; ?> |
| 66 |
<?php endif; ?> |
| 67 |
</select> |
| 68 |
<span class="ife_small"> |
| 69 |
<?php esc_attr_e( 'These categories are assign to imported event.', 'import-facebook-events' ); ?> |
| 70 |
</span> |
| 71 |
</td> |
| 72 |
</tr> |
| 73 |
<?php |
| 74 |
} |
| 75 |
|
| 76 |
|
| 77 |
/** |
| 78 |
* Get Import events setting options |
| 79 |
* |
| 80 |
* @since 1.0 |
| 81 |
* @return void |
| 82 |
*/ |
| 83 |
function ife_get_import_options( $type = '' ){ |
| 84 |
|
| 85 |
$ife_options = get_option( IFE_OPTIONS ); |
| 86 |
if( $type != '' ){ |
| 87 |
$ife_options = isset( $ife_options[$type] ) ? $ife_options[$type] : array(); |
| 88 |
} |
| 89 |
|
| 90 |
return $ife_options; |
| 91 |
} |
| 92 |
|
| 93 |
|
| 94 |
/** |
| 95 |
* Render dropdown for Imported event status. |
| 96 |
* |
| 97 |
* @since 1.0 |
| 98 |
* @return void |
| 99 |
*/ |
| 100 |
function ife_render_eventstatus_input(){ |
| 101 |
?> |
| 102 |
<tr class="event_status_wrapper"> |
| 103 |
<th scope="row"> |
| 104 |
<?php esc_attr_e( 'Status','import-facebook-events' ); ?> : |
| 105 |
</th> |
| 106 |
<td> |
| 107 |
<select name="event_status" > |
| 108 |
<option value="publish"> |
| 109 |
<?php esc_html_e( 'Published','import-facebook-events' ); ?> |
| 110 |
</option> |
| 111 |
<option value="pending"> |
| 112 |
<?php esc_html_e( 'Pending','import-facebook-events' ); ?> |
| 113 |
</option> |
| 114 |
<option value="draft"> |
| 115 |
<?php esc_html_e( 'Draft','import-facebook-events' ); ?> |
| 116 |
</option> |
| 117 |
</select> |
| 118 |
</td> |
| 119 |
</tr> |
| 120 |
<?php |
| 121 |
} |
| 122 |
|
| 123 |
function ife_render_import_frequency(){ |
| 124 |
?> |
| 125 |
<select name="import_frequency" class="import_frequency" > |
| 126 |
<option value='hourly'> |
| 127 |
<?php esc_html_e( 'Once Hourly','import-facebook-events' ); ?> |
| 128 |
</option> |
| 129 |
<option value='twicedaily'> |
| 130 |
<?php esc_html_e( 'Twice Daily','import-facebook-events' ); ?> |
| 131 |
</option> |
| 132 |
<option value="daily" selected="selected"> |
| 133 |
<?php esc_html_e( 'Once Daily','import-facebook-events' ); ?> |
| 134 |
</option> |
| 135 |
<option value="weekly" > |
| 136 |
<?php esc_html_e( 'Once Weekly','import-facebook-events' ); ?> |
| 137 |
</option> |
| 138 |
<option value="monthly"> |
| 139 |
<?php esc_html_e( 'Once a Month','import-facebook-events' ); ?> |
| 140 |
</option> |
| 141 |
</select> |
| 142 |
<?php |
| 143 |
} |
| 144 |
|
| 145 |
function ife_render_import_type(){ |
| 146 |
?> |
| 147 |
<select name="import_type" id="import_type" disabled="disabled"> |
| 148 |
<option value="onetime" ><?php esc_attr_e( 'One-time Import','import-facebook-events' ); ?></option> |
| 149 |
<option value="scheduled" ><?php esc_attr_e( 'Scheduled Import','import-facebook-events' ); ?></option> |
| 150 |
</select> |
| 151 |
<span class="hide_frequency"> |
| 152 |
<?php ife_render_import_frequency(); ?> |
| 153 |
</span> |
| 154 |
<?php do_action( 'ife_render_pro_notice'); ?> |
| 155 |
<?php |
| 156 |
} |
| 157 |
|
| 158 |
/** |
| 159 |
* remove query string from URL. |
| 160 |
* |
| 161 |
* @since 1.0.0 |
| 162 |
*/ |
| 163 |
function ife_remove_query_string_from_url( $url ) { |
| 164 |
$query = parse_url( $url, PHP_URL_QUERY ); |
| 165 |
|
| 166 |
if ( is_string( $query ) ) { |
| 167 |
$url = str_replace( "?$query", '', $url ); |
| 168 |
} |
| 169 |
$url_array = explode( '#', $url ); |
| 170 |
return stripslashes( $url_array[0] ); |
| 171 |
} |
| 172 |
|
| 173 |
/** |
| 174 |
* remove query string from URL. |
| 175 |
* |
| 176 |
* @since 1.0.0 |
| 177 |
*/ |
| 178 |
function ife_convert_datetime_to_db_datetime( $datetime ) { |
| 179 |
try { |
| 180 |
$datetime = new DateTime( $datetime ); |
| 181 |
return $datetime->format( 'Y-m-d H:i:s' ); |
| 182 |
} |
| 183 |
catch ( Exception $e ) { |
| 184 |
return $datetime; |
| 185 |
} |
| 186 |
} |
| 187 |
|
| 188 |
/** |
| 189 |
* remove query string from URL. |
| 190 |
* |
| 191 |
* @since 1.0.0 |
| 192 |
*/ |
| 193 |
function ife_clean_url( $url ) { |
| 194 |
|
| 195 |
$url = str_replace( '&#038;', '&', $url ); |
| 196 |
$url = str_replace( '&', '&', $url ); |
| 197 |
return $url; |
| 198 |
|
| 199 |
} |
| 200 |
|
| 201 |
/** |
| 202 |
* Display upgrade to pro notice in form. |
| 203 |
* |
| 204 |
* @since 1.0.0 |
| 205 |
*/ |
| 206 |
function ife_render_pro_notice(){ |
| 207 |
?> |
| 208 |
<span class="ife_small"> |
| 209 |
<?php printf( '<span style="color: red">%s</span> <a href="' . IFE_PLUGIN_BUY_NOW_URL. '" target="_blank" >%s</a>', __( 'Available in Pro version.', 'wp-event-aggregator' ), __( 'Upgrade to PRO', 'import-facebook-events' ) ); ?> |
| 210 |
</span> |
| 211 |
<?php |
| 212 |
} |
| 213 |
add_action( 'ife_render_pro_notice', 'ife_render_pro_notice' ); |