コード例 #1
0
function mc_manage_locations()
{
    global $wpdb;
    $mcdb = $wpdb;
    // pull the locations from the database
    $items_per_page = 50;
    $current = empty($_GET['paged']) ? 1 : intval($_GET['paged']);
    $locations = $mcdb->get_results("SELECT SQL_CALC_FOUND_ROWS * FROM " . my_calendar_locations_table() . " ORDER BY location_label ASC LIMIT " . ($current - 1) * $items_per_page . ", " . $items_per_page);
    $found_rows = $wpdb->get_col("SELECT FOUND_ROWS();");
    $items = $found_rows[0];
    $num_pages = ceil($items / $items_per_page);
    if ($num_pages > 1) {
        $page_links = paginate_links(array('base' => add_query_arg('paged', '%#%'), 'format' => '', 'prev_text' => __('&laquo; Previous<span class="screen-reader-text"> Locations</span>', 'my-calendar'), 'next_text' => __('Next<span class="screen-reader-text"> Locations</span> &raquo;', 'my-calendar'), 'total' => $num_pages, 'current' => $current, 'mid_size' => 1));
        printf("<div class='tablenav'><div class='tablenav-pages'>%s</div></div>", $page_links);
    }
    if (!empty($locations)) {
        ?>
	<form action="<?php 
        echo esc_url(add_query_arg($_GET, admin_url('admin.php')));
        ?>
" method="post">
		<div><input type="hidden" name="_wpnonce" value="<?php 
        echo wp_create_nonce('my-calendar-nonce');
        ?>
"/></div>
		<div class='mc-actions'>
			<input type="submit" class="button-secondary delete" name="mass_delete"
			       value="<?php 
        _e('Delete locations', 'my-calendar');
        ?>
"/>
		</div>
		<table class="widefat page" id="my-calendar-admin-table">
			<thead>
			<tr>
				<th scope="col"><?php 
        _e('ID', 'my-calendar');
        ?>
</th>
				<th scope="col"><?php 
        _e('Location', 'my-calendar');
        ?>
</th>
				<th scope="col"><?php 
        _e('Edit', 'my-calendar');
        ?>
</th>
				<th scope="col"><?php 
        _e('Delete', 'my-calendar');
        ?>
</th>
			</tr>
			</thead>
			<?php 
        $class = '';
        foreach ($locations as $location) {
            $class = $class == 'alternate' ? '' : 'alternate';
            ?>
				<tr class="<?php 
            echo $class;
            ?>
">
					<th scope="row"><input type="checkbox" value="<?php 
            echo $location->location_id;
            ?>
"
					                       name="mass_edit[]" id="mc<?php 
            echo $location->location_id;
            ?>
"/> <label
							for="mc<?php 
            echo $location->location_id;
            ?>
"><?php 
            echo $location->location_id;
            ?>
</label>
					</th>
					<td><?php 
            echo mc_hcard($location, 'true', 'false', 'location');
            ?>
</td>
					<td>
						<a href="<?php 
            echo admin_url("admin.php?page=my-calendar-locations&amp;mode=edit&amp;location_id={$location->location_id}");
            ?>
"
						   class='edit'><?php 
            _e('Edit', 'my-calendar');
            ?>
</a></td>
					<td>
						<a href="<?php 
            echo admin_url("admin.php?page=my-calendar-locations&amp;mode=delete&amp;location_id={$location->location_id}");
            ?>
"
						   class="delete"
						   onclick="return confirm('<?php 
            _e('Are you sure you want to delete this category?', 'my-calendar');
            ?>
')"><?php 
            _e('Delete', 'my-calendar');
            ?>
</a>
					</td>
				</tr>
			<?php 
        }
        ?>
		</table>
		<p>
			<input type="submit" class="button-secondary delete" name="mass_delete"
			       value="<?php 
        _e('Delete locations', 'my-calendar');
        ?>
"/>
		</p>
		</form><?php 
    } else {
        echo '<p>' . __('There are no locations in the database yet!', 'my-calendar') . '</p>';
    }
    ?>
	<p><em>
			<?php 
    _e('Please note: editing or deleting locations stored for re-use will have no effect on any event previously scheduled at that location. The location database exists purely as a shorthand method to enter frequently used locations into event records.', 'my-calendar');
    ?>
		</em></p>

	<form method="post" action="<?php 
    echo admin_url("admin.php?page=my-calendar-locations");
    ?>
">
		<div><input type="hidden" name="_wpnonce" value="<?php 
    echo wp_create_nonce('my-calendar-nonce');
    ?>
"/></div>
		<div><input type="hidden" name="mc_locations" value="true"/></div>
		<fieldset>
			<legend><?php 
    _e('Control Input Options for Location Fields', 'my-calendar');
    ?>
</legend>
			<div id="mc-accordion">
				<?php 
    // array of fields allowing input control.
    $location_fields = array('event_label', 'event_city', 'event_state', 'event_country', 'event_postcode', 'event_region');
    $mc_location_controls = get_option('mc_location_controls');
    foreach ($location_fields as $field) {
        ?>
					<h4><?php 
        echo ucfirst(str_replace('event_', '', $field));
        ?>
</h4>
					<div>
						<label
							for="loc_values_<?php 
        echo $field;
        ?>
"><?php 
        printf(__('Location Controls for %s', 'my-calendar'), ucfirst(str_replace('event_', '', $field)));
        ?>
							(<?php 
        _e('Value, Label (one per line)', 'my-calendar');
        ?>
)</label><br/>
						<?php 
        $locations = '';
        if (is_array($mc_location_controls) && isset($mc_location_controls[$field])) {
            foreach ($mc_location_controls[$field] as $key => $value) {
                $locations .= stripslashes("{$key},{$value}") . "\n";
            }
        }
        ?>
						<textarea name="mc_location_controls[<?php 
        echo $field;
        ?>
][]"
						          id="loc_values_<?php 
        echo $field;
        ?>
" cols="80"
						          rows="6"><?php 
        echo trim($locations);
        ?>
</textarea>
					</div>
				<?php 
    }
    ?>
			</div>
			<p><input type='submit' class='button secondary'
			          value='<?php 
    _e('Save Location Controls', 'my-calendar');
    ?>
'/></p>
		</fieldset>
</div>
<?php 
}
コード例 #2
0
function my_calendar_show_locations($show = 'list', $datatype = 'name', $template = '')
{
    global $wpdb;
    $mcdb = $wpdb;
    if (get_option('mc_remote') == 'true' && function_exists('mc_remote_db')) {
        $mcdb = mc_remote_db();
    }
    switch ($datatype) {
        case "name":
        case "location":
            $data = "location_label";
            break;
        case "city":
            $data = "location_city";
            break;
        case "state":
            $data = "location_state";
            break;
        case "zip":
            $data = "location_postcode";
            break;
        case "country":
            $data = "location_country";
            break;
        case "hcard":
            $data = "location_label";
            break;
        case "region":
            $data = "location_region";
            break;
        default:
            $data = "location_label";
    }
    $locations = $mcdb->get_results("SELECT DISTINCT * FROM " . MY_CALENDAR_LOCATIONS_TABLE . " ORDER BY {$data} ASC");
    if ($locations) {
        $output = "<ul class='mc-locations'>";
        foreach ($locations as $key => $value) {
            $id = $value->location_id;
            if ($datatype != 'hcard' && $template == '') {
                $label = stripslashes($value->{$data});
                $url = mc_maplink($value, 'url', $source = 'location');
                if ($url) {
                    $output .= "<li>{$url}</li>";
                } else {
                    $output .= "<li>{$label}</li>";
                }
            } else {
                if ($datatype == 'hcard') {
                    $label = mc_hcard($value, true, true, 'location');
                    $output .= "<li>{$label}</li>";
                } else {
                    if ($template != '') {
                        $values = array('id' => $value->location_id, 'label' => $value->location_label, 'street' => $value->location_street, 'street2' => $value->location_street2, 'city' => $value->location_city, 'state' => $value->location_state, 'postcode' => $value->location_postcode, 'region' => $value->location_region, 'url' => $value->location_url, 'country' => $value->location_country, 'longitude' => $value->location_longitude, 'latitude' => $value->location_latitude, 'zoom' => $value->location_zoom, 'phone' => $value->location_phone);
                        $label = jd_draw_template($values, $template);
                        $output .= "<li>{$label}</li>";
                    }
                }
            }
        }
        $output .= "</ul>";
        $output = apply_filters('mc_location_list', $output, $locations);
        return $output;
    }
}
コード例 #3
0
function mc_generate_map($event, $source = 'event')
{
    $id = rand();
    $zoom = $event->event_zoom != 0 ? $event->event_zoom : '15';
    $category_icon = mc_category_icon($event, 'img');
    if (!$category_icon) {
        $category_icon = "//maps.google.com/mapfiles/marker_green.png";
    }
    $address = addslashes(mc_map_string($event, $source));
    if (strlen($address) < 10) {
        return '';
    }
    $hcard = mc_hcard($event, true, false, 'event', 'map');
    $hcard = wp_kses(str_replace(array('</div>', '<br />', '<br><br>'), '<br>', $hcard), array('br' => array()));
    $html = addslashes(apply_filters('mc_map_html', $hcard, $event));
    $width = apply_filters('mc_map_height', '100%', $event);
    $height = apply_filters('mc_map_height', '300px', $event);
    $styles = " style='width: {$width};height: {$height}'";
    $value = "\n<script type='text/javascript'>\n\t(function (\$) { 'use strict';\n\t\t\$(function () {\n\t\t\t\$('#mc_gmap_{$id}').gmap3(\n\t\t\t\t{\n\t\t\t\t\tmarker:{ \n\t\t\t\t\t\tvalues:[{\n\t\t\t\t\t\t\taddress: '{$address}',\n\t\t\t\t\t\t\toptions: { icon: new google.maps.MarkerImage( '{$category_icon}', new google.maps.Size(32,32,'px','px') ) }, \n\t\t\t\t\t\t\tdata:'{$html}'\n\t\t\t\t\t\t\t}], \n\t\t\t\t\t\tevents:{\n\t\t\t\t\t\t  click: function( marker, event, context ){\n\t\t\t\t\t\t\tvar map = \$(this).gmap3('get'),\n\t\t\t\t\t\t\t  infowindow = \$(this).gmap3( { get:{name:'infowindow'} } );\n\t\t\t\t\t\t\tif ( infowindow ){\n\t\t\t\t\t\t\t  infowindow.open(map, marker);\n\t\t\t\t\t\t\t  infowindow.setContent(context.data);\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t  \$(this).gmap3({\n\t\t\t\t\t\t\t\tinfowindow:{\n\t\t\t\t\t\t\t\t  anchor:marker, \n\t\t\t\t\t\t\t\t  options:{content: context.data}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t  });\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t  }\n\t\t\t\t\t\t}\n\t\t\t\t\t},\n\t\t\t\t\tmap:{\n\t\t\t\t\t\toptions:{\n\t\t\t\t\t\t  zoom: {$zoom},\n\t\t\t\t\t\t  mapTypeControl: true,\n\t\t\t\t\t\t  mapTypeControlOptions: {\n\t\t\t\t\t\t\tstyle: google.maps.MapTypeControlStyle.DROPDOWN_MENU\n\t\t\t\t\t\t  },\n\t\t\t\t\t\t  navigationControl: true,\n\t\t\t\t\t\t  scrollwheel: true,\n\t\t\t\t\t\t  streetViewControl: false\n\t\t\t\t\t\t}\n\t\t\t\t\t}\t\n\t\t\t});\t\n\t\t}); \n\t})(jQuery);\n</script>\n\t<div id='mc_gmap_{$id}' class='mc-gmap-fupup'{$styles}></div>";
    return apply_filters('mc_gmap_html', $value, $event);
}
コード例 #4
0
function mc_manage_locations()
{
    global $wpdb;
    $mcdb = $wpdb;
    // pull the locations from the database
    $items_per_page = 50;
    $current = empty($_GET['paged']) ? 1 : intval($_GET['paged']);
    $locations = $mcdb->get_results("SELECT SQL_CALC_FOUND_ROWS * FROM " . my_calendar_locations_table() . " ORDER BY location_label ASC LIMIT " . ($current - 1) * $items_per_page . ", " . $items_per_page);
    $found_rows = $wpdb->get_col("SELECT FOUND_ROWS();");
    $items = $found_rows[0];
    $num_pages = ceil($items / $items_per_page);
    if ($num_pages > 1) {
        $page_links = paginate_links(array('base' => add_query_arg('paged', '%#%'), 'format' => '', 'prev_text' => __('&laquo; Previous<span class="screen-reader-text"> Locations</span>', 'my-calendar'), 'next_text' => __('Next<span class="screen-reader-text"> Locations</span> &raquo;', 'my-calendar'), 'total' => $num_pages, 'current' => $current, 'mid_size' => 1));
        printf("<div class='tablenav'><div class='tablenav-pages'>%s</div></div>", $page_links);
    }
    if (!empty($locations)) {
        ?>
	<form action="<?php 
        echo esc_url(add_query_arg($_GET, admin_url('admin.php')));
        ?>
" method="post">
		<div><input type="hidden" name="_wpnonce" value="<?php 
        echo wp_create_nonce('my-calendar-nonce');
        ?>
"/></div>
		<div class='mc-actions'>
			<input type="submit" class="button-secondary delete" name="mass_delete"
			       value="<?php 
        _e('Delete locations', 'my-calendar');
        ?>
"/>
		</div>
		<table class="widefat page" id="my-calendar-admin-table">
			<thead>
			<tr>
				<th scope="col"><?php 
        _e('ID', 'my-calendar');
        ?>
</th>
				<th scope="col"><?php 
        _e('Location', 'my-calendar');
        ?>
</th>
				<th scope="col"><?php 
        _e('Edit', 'my-calendar');
        ?>
</th>
				<th scope="col"><?php 
        _e('Delete', 'my-calendar');
        ?>
</th>
			</tr>
			</thead>
			<?php 
        $class = '';
        foreach ($locations as $location) {
            $class = $class == 'alternate' ? '' : 'alternate';
            ?>
				<tr class="<?php 
            echo $class;
            ?>
">
					<th scope="row"><input type="checkbox" value="<?php 
            echo $location->location_id;
            ?>
"
					                       name="mass_edit[]" id="mc<?php 
            echo $location->location_id;
            ?>
"/> <label
							for="mc<?php 
            echo $location->location_id;
            ?>
"><?php 
            echo $location->location_id;
            ?>
</label>
					</th>
					<td><?php 
            echo mc_hcard($location, 'true', 'false', 'location');
            ?>
</td>
					<td>
						<a href="<?php 
            echo admin_url("admin.php?page=my-calendar-locations&amp;mode=edit&amp;location_id={$location->location_id}");
            ?>
"
						   class='edit'><?php 
            _e('Edit', 'my-calendar');
            ?>
</a></td>
					<td>
						<a href="<?php 
            echo admin_url("admin.php?page=my-calendar-locations&amp;mode=delete&amp;location_id={$location->location_id}");
            ?>
"
						   class="delete"
						   onclick="return confirm('<?php 
            _e('Are you sure you want to delete this category?', 'my-calendar');
            ?>
')"><?php 
            _e('Delete', 'my-calendar');
            ?>
</a>
					</td>
				</tr>
			<?php 
        }
        ?>
		</table>
		<p>
			<input type="submit" class="button-secondary delete" name="mass_delete"
			       value="<?php 
        _e('Delete locations', 'my-calendar');
        ?>
"/>
		</p>
		</form><?php 
    } else {
        echo '<p>' . __('There are no locations in the database yet!', 'my-calendar') . '</p>';
    }
    ?>
	<p><em>
			<?php 
    _e('Please note: editing or deleting locations stored for re-use will have no effect on any event previously scheduled at that location. The location database exists purely as a shorthand method to enter frequently used locations into event records.', 'my-calendar');
    ?>
		</em></p>
<?php 
}