function eme_options_radio_binary($title, $name, $description, $option_value=false) { if (!$option_value) $option_value = get_option($name); if ($name == "eme_permalink_events_prefix" || $name == "eme_permalink_locations_prefix") { $option_value = eme_permalink_convert($option_value); } ?> <tr valign="top" id='<?php echo $name;?>_row'> <th scope="row"><?php _e($title,'eme'); ?></th> <td> <input id="<?php echo $name; ?>_yes" name="<?php echo $name; ?>" type="radio" value="1" <?php if($option_value) echo "checked='checked'"; ?> /><?php _e('Yes'); ?> <br /> <input id="<?php echo $name; ?>_no" name="<?php echo $name; ?>" type="radio" value="0" <?php if(!$option_value) echo "checked='checked'"; ?> /><?php _e('No'); ?> <?php if (!empty($description)) echo "<br />".$description; ?> </td> </tr> <?php }
function eme_category_url($category) { global $wp_rewrite; $def_language = eme_detect_lang(); $language = $def_language; if (isset($wp_rewrite) && $wp_rewrite->using_permalinks() && get_option('eme_seo_permalink')) { $events_prefix=eme_permalink_convert(get_option ( 'eme_permalink_events_prefix')); $slug = $category['category_slug'] ? $category['category_slug'] : $category['category_name']; $name=$events_prefix."cat/".eme_permalink_convert($slug); $the_link = home_url(); // some plugins add the lang info to the home_url, remove it so we don't get into trouble or add it twice $the_link = preg_replace("/\/$def_language$/","",$the_link); $the_link = trailingslashit(remove_query_arg('lang',$the_link)); if (!empty($language)) { $url_mode=eme_lang_url_mode(); if ($url_mode==2) { $the_link = $the_link."$language/".user_trailingslashit($name); } else { $the_link = $the_link.user_trailingslashit($name); $the_link = add_query_arg( array( 'lang' => $language ), $the_link ); } } else { $the_link = $the_link.user_trailingslashit($name); } } else { $the_link = eme_get_events_page(true, false); // some plugins add the lang info to the home_url, remove it so we don't get into trouble or add it twice $the_link = remove_query_arg('lang',$the_link); $slug = $category['category_slug'] ? $category['category_slug'] : $category['category_name']; $the_link = add_query_arg( array( 'eme_event_cat' => $slug ), $the_link ); if (!empty($language)) $the_link = add_query_arg( array( 'lang' => $language ), $the_link ); } return $the_link; }
function eme_create_categories_table($charset, $collate) { global $wpdb; $db_version = get_option('eme_version'); $table_name = $wpdb->prefix . CATEGORIES_TBNAME; if ($wpdb->get_var("SHOW TABLES LIKE '{$table_name}'") != $table_name) { $sql = "CREATE TABLE " . $table_name . " (\n category_id int(11) NOT NULL auto_increment,\n category_name tinytext NOT NULL,\n description text DEFAULT NULL,\n category_slug text default NULL,\n UNIQUE KEY (category_id)\n ) {$charset} {$collate};"; maybe_create_table($table_name, $sql); } else { maybe_add_column($table_name, 'category_slug', "alter table {$table_name} add category_slug text DEFAULT NULL;"); maybe_add_column($table_name, 'description', "alter table {$table_name} add description text DEFAULT NULL;"); if ($db_version < 66) { $categories = $wpdb->get_results("SELECT * FROM {$table_name}", ARRAY_A); foreach ($categories as $this_category) { $where = array(); $fields = array(); $where['category_id'] = $this_category['category_id']; $fields['category_slug'] = untrailingslashit(eme_permalink_convert($this_category['category_name'])); $wpdb->update($table_name, $fields, $where); } } } }
function eme_locations_edit_layout($location, $message = "") { if (!isset($location['location_id'])) { $action = "add"; } else { $action = "edit"; } ?> <div class="wrap"> <div id="poststuff"> <div id="icon-edit" class="icon32"> <br /> </div> <h2><?php if ($action == "add") { _e('Add location', 'eme'); } else { _e('Edit location', 'eme'); } ?> </h2> <?php admin_show_warnings(); ?> <?php if ($message != "") { ?> <div id="message" class="updated fade below-h2" style="background-color: rgb(255, 251, 204);"> <p><?php echo $message; ?> </p> </div> <?php } ?> <div id="ajax-response"></div> <form enctype="multipart/form-data" name="editloc" id="editloc" method="post" action="<?php echo admin_url("admin.php?page=eme-locations"); ?> " class="validate"> <?php if ($action == "add") { ?> <input type="hidden" name="eme_admin_action" value="do_addlocation" /> <?php } else { ?> <input type="hidden" name="eme_admin_action" value="do_editlocation" /> <input type="hidden" name="location_id" value="<?php echo $location['location_id']; ?> " /> <?php } ?> <!-- we need titlediv and title for qtranslate as ID --> <div id="titlediv" class="postbox"> <h3> <?php _e('Location name', 'eme'); ?> </h3> <div class="inside"> <input name="location_name" id="title" type="text" required="required" value="<?php echo eme_sanitize_html($location['location_name']); ?> " size="40" /> <?php if ($action == "edit") { _e('Permalink: ', 'eme'); echo trailingslashit(home_url()) . eme_permalink_convert(get_option('eme_permalink_locations_prefix')) . $location['location_id'] . "/"; $slug = $location['location_slug'] ? $location['location_slug'] : $location['location_name']; $slug = untrailingslashit(eme_permalink_convert($slug)); ?> <input type="text" id="slug" name="location_slug" value="<?php echo $slug; ?> " /><?php echo user_trailingslashit(""); ?> <?php } ?> </div> </div> <div class="postbox"> <h3> <?php _e('Location address', 'eme'); ?> </h3> <div class="inside"> <input id="location_address" name="location_address" type="text" value="<?php echo eme_trans_sanitize_html($location['location_address']); ?> " size="40" /> </div> </div> <div class="postbox"> <h3> <?php _e('Location town', 'eme'); ?> </h3> <div class="inside"> <input name="location_town" id="location_town" type="text" value="<?php echo eme_trans_sanitize_html($location['location_town']); ?> " size="40" /> </div> </div> <div class="postbox"> <h3> <?php _e('Location latitude/longitude', 'eme'); ?> </h3> <div class="inside"> <table><tr> <td><label for="location_latitude"><?php _e('Latitude', 'eme'); ?> </label></td> <td><input id="location_latitude" name="location_latitude" type="text" value="<?php echo eme_sanitize_html($location['location_latitude']); ?> " size="40" /></td> </tr> <tr> <td><label for="location_longitude"><?php _e('Longitude', 'eme'); ?> </label></td> <td><input id="location_longitude" name="location_longitude" type="text" value="<?php echo eme_sanitize_html($location['location_longitude']); ?> " size="40" /></td> </tr></table> </div> </div> <div class="postbox"> <h3> <?php _e('Location image', 'eme'); ?> </h3> <div class="inside"> <?php if (isset($location['location_image_url']) && !empty($location['location_image_url'])) { echo "<img id='eme_location_image_example' src='" . $location['location_image_url'] . "' width='200' />"; echo "<input type='hidden' name='location_image_url' id='location_image_url' value='" . $location['location_image_url'] . "' />"; } else { echo "<img id='eme_location_image_example' src='' alt='' width='200' />"; echo "<input type='hidden' name='location_image_url' id='location_image_url' />"; } if (isset($location['location_image_id']) && !empty($location['location_image_id'])) { echo "<input type='hidden' name='location_image_id' id='location_image_id' value='" . $location['location_image_id'] . "' />"; } else { echo "<input type='hidden' name='location_image_id' id='location_image_id' />"; } // based on code found at http://codestag.com/how-to-use-wordpress-3-5-media-uploader-in-theme-options/ ?> <input type="button" name="location_image_button" id="location_image_button" value="<?php _e('Set a featured image', 'eme'); ?> " /> <input type="button" id="eme_remove_old_image" name="eme_remove_old_image" value=" <?php _e('Unset featured image', 'eme'); ?> " /> </div> <script> jQuery(document).ready(function($){ $('#eme_remove_old_image').click(function(e) { $('#location_image_url').val(''); $('#location_image_id').val(''); $('#eme_location_image_example' ).attr("src",''); }); $('#location_image_button').click(function(e) { e.preventDefault(); var custom_uploader = wp.media({ title: '<?php _e('Select the image to be used as featured image', 'eme'); ?> ', button: { text: '<?php _e('Set featured image', 'eme'); ?> ' }, // Tell the modal to show only images. library: { type: 'image' }, multiple: false // Set this to true to allow multiple files to be selected }) .on('select', function() { var attachment = custom_uploader.state().get('selection').first().toJSON(); $('#location_image_url').val(attachment.url); $('#location_image_id').val(attachment.id); $('#eme_location_image_example' ).attr("src",attachment.url); }) .open(); }); }); </script> </div> <?php if (get_option('eme_categories_enabled')) { ?> <div class="postbox"> <h3> <?php _e('Category', 'eme'); ?> </h3> <div class="inside"> <?php $categories = eme_get_categories(); foreach ($categories as $category) { if ($location['location_category_ids'] && in_array($category['category_id'], explode(",", $location['location_category_ids']))) { $selected = "checked='checked'"; } else { $selected = ""; } ?> <input type="checkbox" name="location_category_ids[]" value="<?php echo $category['category_id']; ?> " <?php echo $selected; ?> /><?php echo eme_trans_sanitize_html($category['category_name']); ?> <br /> <?php } ?> </div> </div> <?php } ?> <?php $gmap_is_active = get_option('eme_gmap_is_active'); if ($gmap_is_active) { ?> <div class="postbox"><?php if (function_exists('qtrans_getLanguage') || function_exists('ppqtrans_getLanguage') || defined('ICL_LANGUAGE_CODE')) { _e("Because qtranslate or a derivate is active, the title of the location might not update automatically in the balloon, so don't panic there."); } ?> </div> <div class="postbox" id="eme-admin-map-not-found"><p><?php _e('Map not found', 'eme'); ?> </p></div> <div class="postbox" id="eme-admin-location-map"></div> <br style="clear:both;" /> <?php } ?> <div class="postbox" id="loc_description"> <h3> <?php _e('Location description', 'eme'); ?> </h3> <div class="inside"> <div id="<?php echo user_can_richedit() ? 'postdivrich' : 'postdiv'; ?> " class="postarea"> <!-- we need content for qtranslate as ID --> <?php wp_editor($location['location_description'], "content"); ?> </div> <?php _e('A description of the Location. You may include any kind of info here.', 'eme'); ?> </div> </div> <?php if (get_option('eme_attributes_enabled')) { ?> <div class="postbox"> <h3> <?php _e('Attributes', 'eme'); ?> </h3> <?php eme_attributes_form($location); ?> </div> <?php } ?> <div class="postbox"> <h3> <?php _e('External link', 'eme'); ?> </h3> <div class="inside"> <input name="location_url" id="location_url" type="text" value="<?php echo eme_sanitize_html($location['location_url']); ?> " size="40" /> <p><?php _e('If this is filled in, the single location URL will point to this url instead of the standard location page.', 'eme'); ?> </p> </div> </div> <p class="submit"><input type="submit" class="button-primary" name="submit" value="<?php if ($action == "add") { _e('Add location', 'eme'); } else { _e('Update location', 'eme'); } ?> " /></p> </div> </form> </div> <?php }
function eme_categories_page() { global $wpdb; admin_show_warnings(); if (!current_user_can(get_option('eme_cap_categories')) && (isset($_GET['eme_admin_action']) || isset($_POST['eme_admin_action']))) { $message = __('You have no right to update categories!', 'eme'); eme_categories_table_layout($message); return; } if (isset($_GET['eme_admin_action']) && $_GET['eme_admin_action'] == "edit_category") { // edit category eme_categories_edit_layout(); return; } $message = ''; if (isset($_POST['eme_admin_action'])) { // Insert/Update/Delete Record $categories_table = $wpdb->prefix . CATEGORIES_TBNAME; if ($_POST['eme_admin_action'] == "do_editcategory") { // category update required $category = array(); $category['category_name'] = trim(stripslashes($_POST['category_name'])); $category['description'] = trim(stripslashes($_POST['description'])); $category['category_slug'] = untrailingslashit(eme_permalink_convert($category['category_name'])); $validation_result = $wpdb->update($categories_table, $category, array('category_id' => intval($_POST['category_id']))); if ($validation_result !== false) { $message = __("Successfully edited the category", "eme"); } else { $message = __("There was a problem editing your category, please try again.", "eme"); } } elseif ($_POST['eme_admin_action'] == "do_addcategory") { // Add a new category $category = array(); $category['category_name'] = trim(stripslashes($_POST['category_name'])); $category['description'] = trim(stripslashes($_POST['description'])); $category['category_slug'] = untrailingslashit(eme_permalink_convert($category['category_name'])); $validation_result = $wpdb->insert($categories_table, $category); if ($validation_result !== false) { $message = __("Successfully added the category", "eme"); } else { $message = __("There was a problem adding your category, please try again.", "eme"); } } elseif ($_POST['eme_admin_action'] == "do_deletecategory" && isset($_POST['categories'])) { // Delete category or multiple $categories = $_POST['categories']; if (is_array($categories)) { //Run the query if we have an array of category ids if (count($categories > 0)) { $validation_result = $wpdb->query("DELETE FROM {$categories_table} WHERE category_id IN ( " . implode(",", $categories) . ")"); if ($validation_result !== false) { $message = __("Successfully deleted the selected categories.", "eme"); } else { $message = __("There was a problem deleting the selected categories, please try again.", "eme"); } } else { $message = __("Couldn't delete the categories. Incorrect category IDs supplied. Please try again.", "eme"); } } else { $message = __("Couldn't delete the categories. Incorrect category IDs supplied. Please try again.", "eme"); } } } eme_categories_table_layout($message); }
function eme_meta_box_div_event_name($event) { ?> <!-- we need title for qtranslate as ID --> <input type="text" id="title" name="event_name" value="<?php echo eme_sanitize_html($event['event_name']); ?> " /> <br /> <?php _e('The event name. Example: Birthday party', 'eme'); ?> <br /> <br /> <?php if ($event['event_id'] && $event['event_name'] != "") { _e('Permalink: ', 'eme'); echo trailingslashit(home_url()) . eme_permalink_convert(get_option('eme_permalink_events_prefix')) . $event['event_id'] . "/"; $slug = $event['event_slug'] ? $event['event_slug'] : $event['event_name']; $slug = untrailingslashit(eme_permalink_convert($slug)); ?> <input type="text" id="slug" name="event_slug" value="<?php echo $slug; ?> " /><?php echo user_trailingslashit(""); ?> <?php } }