Commit 94165309 by Administrator

Initial commit

parents
This diff is collapsed. Click to expand it.
=== Plugin Name ===
Contributors: (this should be a list of wordpress.org userid's)
Donate link: http://example.com/
Tags: comments, spam
Requires at least: 3.0.1
Tested up to: 3.4
Stable tag: 4.3
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Here is a short description of the plugin. This should be no more than 150 characters. No markup here.
== Description ==
This is the long description. No limit, and you can use Markdown (as well as in the following sections).
For backwards compatibility, if this section is missing, the full length of the short description will be used, and
Markdown parsed.
A few notes about the sections above:
* "Contributors" is a comma separated list of wp.org/wp-plugins.org usernames
* "Tags" is a comma separated list of tags that apply to the plugin
* "Requires at least" is the lowest version that the plugin will work on
* "Tested up to" is the highest version that you've *successfully used to test the plugin*. Note that it might work on
higher versions... this is just the highest one you've verified.
* Stable tag should indicate the Subversion "tag" of the latest stable version, or "trunk," if you use `/trunk/` for
stable.
Note that the `readme.txt` of the stable tag is the one that is considered the defining one for the plugin, so
if the `/trunk/readme.txt` file says that the stable tag is `4.3`, then it is `/tags/4.3/readme.txt` that'll be used
for displaying information about the plugin. In this situation, the only thing considered from the trunk `readme.txt`
is the stable tag pointer. Thus, if you develop in trunk, you can update the trunk `readme.txt` to reflect changes in
your in-development version, without having that information incorrectly disclosed about the current stable version
that lacks those changes -- as long as the trunk's `readme.txt` points to the correct stable tag.
If no stable tag is provided, it is assumed that trunk is stable, but you should specify "trunk" if that's where
you put the stable version, in order to eliminate any doubt.
== Installation ==
This section describes how to install the plugin and get it working.
e.g.
1. Upload `plugin-name.php` to the `/wp-content/plugins/` directory
1. Activate the plugin through the 'Plugins' menu in WordPress
1. Place `<?php do_action('plugin_name_hook'); ?>` in your templates
== Frequently Asked Questions ==
= A question that someone might have =
An answer to that question.
= What about foo bar? =
Answer to foo bar dilemma.
== Screenshots ==
1. This screen shot description corresponds to screenshot-1.(png|jpg|jpeg|gif). Note that the screenshot is taken from
the /assets directory or the directory that contains the stable readme.txt (tags or trunk). Screenshots in the /assets
directory take precedence. For example, `/assets/screenshot-1.png` would win over `/tags/4.3/screenshot-1.png`
(or jpg, jpeg, gif).
2. This is the second screen shot
== Changelog ==
= 1.0 =
* A change since the previous version.
* Another change.
= 0.5 =
* List versions from most recent at top to oldest at bottom.
== Upgrade Notice ==
= 1.0 =
Upgrade notices describe the reason a user should upgrade. No more than 300 characters.
= 0.5 =
This version fixes a security related bug. Upgrade immediately.
== Arbitrary section ==
You may provide arbitrary sections, in the same format as the ones above. This may be of use for extremely complicated
plugins where more information needs to be conveyed that doesn't fit into the categories of "description" or
"installation." Arbitrary sections will be shown below the built-in sections outlined above.
== A brief Markdown Example ==
Ordered list:
1. Some feature
1. Another feature
1. Something else about the plugin
Unordered list:
* something
* something else
* third thing
Here's a link to [WordPress](http://wordpress.org/ "Your favorite software") and one to [Markdown's Syntax Documentation][markdown syntax].
Titles are optional, naturally.
[markdown syntax]: http://daringfireball.net/projects/markdown/syntax
"Markdown is what the parser uses to process much of the readme file"
Markdown uses email style notation for blockquotes and I've been told:
> Asterisks for *emphasis*. Double it up for **strong**.
`<?php code(); // goes in backticks ?>`
\ No newline at end of file
<?php
add_action( 'wp_ajax_wosmpl_upload_file', 'wosmpl_wosmpl_upload_file' );
function wosmpl_reduce_image($file_path,$ext,$width,$height,$new_widths) {
foreach ($new_widths as $new_width) {
$new_height = $height * ($new_width/$width);
if ($ext == 'jpeg') {
$source = imagecreatefromjpeg($file_path);
} else if ($ext == 'png') {
$source = imagecreatefrompng($file_path);
}
$thumb = imagecreatetruecolor($new_width, $new_height);
imagecopyresampled($thumb, $source, 0, 0, 0, 0, $new_width,$new_height, $width, $height);
$reduced_fn = str_replace('.','-'.$new_width.'.',$file_path);
if ($ext == 'jpeg') {
imagejpeg($thumb,$reduced_fn);
} else if ($ext == 'png') {
imagepng($thumb,$reduced_fn);
}
}
}
function wosmpl_wosmpl_upload_file() {
check_ajax_referer( 'wosmpl_ajax', '_ajax_nonce' );
$return = [];
$file = $_POST['file'] ;
if ($file) {
$base64 = sanitize_text_field($file['base64']);
$base64 = str_replace('data:'.$file['type'].';base64,', '', $base64);
list($mtype,$ext) = explode('/', $file['type']);
$fname = hash('sha1',$file['base64']) . '.' . $ext;
$file_path = get_option('wosmpl_upload_dir') .'/' .$fname;
if (file_put_contents($file_path,base64_decode($base64))) {
$return['file_url'] = str_replace(get_home_path(),'/',$file_path);
if (strpos($mtype, 'image') !== FALSE) {
$return['img_info'] = getimagesize($file_path);
$width = $return['img_info'][0];
$height = $return['img_info'][1];
wosmpl_reduce_image($file_path,$ext,$width,$height,[125,350]);
}
} else {
$return['error'] = 'File cannot be saved !';
}
}
wp_send_json($return);
wp_die(); // all ajax handlers should die when finished
}
\ No newline at end of file
/**
* All of the CSS for your admin-specific functionality should be
* included in this file.
*/
#wosmpl_geodata_box label {display: inline-block;}
#wosmpl_latlon_field, #wosmpl_plain_text_addr {float:left;}
#wosmpl_plain_text_addr {margin-left:30px;}
#wosmpl_address_auto, #wosmpl_address_suggestions {width:30em;}
#wosmpl_address_suggestions ul {list-style-type: none; padding: 0; margin: 0;}
#wosmpl_address_suggestions li {border-bottom: 1px #efefef solid; background: #f7fbfc; cursor:pointer;}
.clear {clear:both;}
#advanced-sortables h2 span {background: #efee00; }
#advanced-sortables .inside label {font-weight: bold;}
#wosmpl_additionnal_marker_data_box label ,
#wosmpl_partner_challenge label,
#wosmpl_partner_phone label,
#wosmpl_partner_email label,
#wosmpl_partner_website label
{display:block; float:left;min-width: 200px;}
#wosmpl_partner_challenge {margin-bottom:20px;}
\ No newline at end of file
<?php // Silence is golden
\ No newline at end of file
(function( $ ) {
'use strict';
var last_call_time = 0
var last_query_length = 0
var suggestions = null;
var sugg_li = null;
var selected_li = null;
var addresses = [];
function clear_suggest_list() {
suggestions.html('')
}
function search(params) {
var d = new Date()
var elapsed_since_last_call = d.getTime() - last_call_time
if (elapsed_since_last_call > 1000) {
clear_suggest_list()
addresses = []
last_call_time = d.getTime()
const geo_url = new URL('https://api-adresse.data.gouv.fr/search');
Object.keys(params).forEach(
key => geo_url.searchParams.append(key, params[key])
)
fetch(geo_url)
.then(response => {
if (response.status >= 200 && response.status < 300) {
return response
} else {
const error = new Error(response.statusText)
error.response = response
throw error
}
})
.then(response => response.json())
.then(data => display_received_points(data))
.catch(error => console.log('request failed', error))
}
}
function display_received_points(data) {
// console.log('Display_received_ points recu ', data)
if (typeof(data.features) != "undefined" && data.features.length > 0) {
var features = data.features
var list = $('<ul/>')
$.each(features, function(i,e) {
var li = $('<li/>')
.attr('data-index',i)
.text(e.properties.label)
list.append(li)
})
suggestions.append(list)
sugg_li = list.find('li');
selected_li = null;
addresses = data.features;
}
}
function confirm_chosen_address(){
if (selected_li) {
var selected_addr = addresses[selected_li.data('index')];
// Address elements are known
// Just display coordinates as an example
$('#wosmpl_address_auto').val(selected_addr.properties.label)
clear_suggest_list();
var lat = selected_addr.geometry.coordinates[1];
var lng = selected_addr.geometry.coordinates[0];
$('input[name="wosmpl_latlon"]').val(lat + ',' + lng);
$('input[name="wosmpl_post_addr"]').val(selected_addr.properties.label);
suggestions.html(msg);
} else {
// TODO
}
}
function select_li_suggest() {
var clicked = $(this);
selected_li = clicked;
confirm_chosen_address();
}
function li_up(){
if(selected_li) {
selected_li.removeClass('selected');
next = selected_li.prev();
if(next.length > 0) {
selected_li = next.addClass('selected');
} else {
selected_li = sugg_li.last().addClass('selected');
}
} else {
selected_li = sugg_li.last().addClass('selected');
}
}
function li_down(){
//move down in suggestions li list
if(selected_li) {
selected_li.removeClass('selected');
next = selected_li.next();
if(next.length > 0) {
selected_li = next.addClass('selected');
} else {
selected_li = sugg_li.eq(0).addClass('selected');
}
} else {
selected_li = sugg_li.eq(0).addClass('selected');
}
}
function search_address_auto(e) {
e = e || window.event;
if (e.keyCode == '13') {
// enter
e.preventDefault();
confirm_chosen_address();
}
else if (e.keyCode == '38') {
// up arrow
li_up();
}
else if (e.keyCode == '40') {
// down arrow
li_down();
}
else {
var query = $(this).val()
var worth = false
if (new RegExp('[0-9]+[ ,]+[a-z]+ [a-z]+','i').exec(query)) {
// ca ressemble a une debut d'adresse genre 1 rue g')
worth = true
} else if (new RegExp('^[a-z]+','i').exec(query)) {
worth = true
}
if (worth == true) search({q:query, limit:6})
}
}
$( window ).load(function() {
var gdb = $('#wosmpl_geodata_box');
if (gdb.length > 0) {
//alert('On va assister la loc');
suggestions = $('#wosmpl_address_suggestions');
$('#wosmpl_address_auto').keyup(search_address_auto);
suggestions.on('click','li',select_li_suggest);
let imageUpload = document.getElementById('wosml_img_selector');
imageUpload.onchange = wosmpl_show_file;
$('.wosmpl_upload_image_button').click(wosmpl_upload_file);
}
});
})( jQuery );
jQuery(document).ready(
function($) {
var img_upload_button = $('.wosmpl_upload_image_button');
var img_viewer = $('#wosmpl_upload_viewer');
var up_file = null;
//take a single JavaScript File object
function getFile(file) {
var reader = new FileReader();
return new Promise((resolve, reject) => {
reader.onerror = () => { reader.abort(); reject(new Error("Error parsing file"));}
reader.onload = function () {
let base64StringFile = reader.result;
resolve({
base64: base64StringFile,
name: file.name,
type: file.type
});
}
reader.readAsDataURL(file);
});
}
top.wosmpl_show_file = function() {
var input = document.getElementById('wosml_img_selector');
if (input.files.length > 0) {
var file = input.files[0];
getFile(file).then((customJsonFile) => {
up_file = customJsonFile;
img_viewer.attr('src',customJsonFile.base64);
img_upload_button.show();
});
}
}
top.wosmpl_upload_file = function() {
var clicked = $(this);
$.post(wosmpl_ajax_obj.ajax_url, { //POST request
_ajax_nonce: wosmpl_ajax_obj.nonce, //nonce
action: "wosmpl_upload_file", //action
file : up_file
}, function(data) { //callback
if (data.error) {
//
} else {
clicked.closest('.upload').find('input[type="hidden"]').val(data.file_url);
img_upload_button.hide();
}
}
);
}
}
);
\ No newline at end of file
<?php
function wosmpl_geodata_box_html($post)
{
$wosmpl_latlon = get_post_meta($post->ID, 'wosmpl_latlon', true);
$s_cat = get_post_meta($post->ID, 'wosmpl_geo_cat', true);
$geo_cats = get_option('wosmpl_geo_cats', []);
$presta_type = get_post_meta($post->ID, 'wosmpl_presta_type', true);
$wosmpl_post_addr = get_post_meta($post->ID, 'wosmpl_post_addr', true);
?>
<div>
<div id="wosmpl_latlon_field">
<label for="wosmpl_latlon">Latitude,Longitude</label>
<input name="wosmpl_latlon" class="postbox" value="<?php echo $wosmpl_latlon?>"/>
</div>
<div id="wosmpl_plain_text_addr">
<input role="combobox" aria-autocomplete="list" aria-expanded="false" autocomplete="off" value="" placeholder="Ex. 1 rue gaston ..." id="wosmpl_address_auto">
<div id="wosmpl_address_suggestions"></div>
</div>
<div class="clear"></div>
</div>
<?php if(count($geo_cats)>0) : ?>
<div>
<label for="wosmpl_geo_cat">Cat.</label>
<select name="wosmpl_geo_cat" class="postbox">
<option value="0" <?php selected($s_cat, '0'); ?>>Select cat.</option>
<?php
foreach ($geo_cats as $cat) {
echo '<option value="'.$cat['id'].'" '.selected($s_cat,$cat['id']).'>'.$cat['name'].'</option>';
}
?>
</select>
</div>
<div id="wosmpl_presta_type">
<label for="wosmpl_presta_type">Presta. type</label>
<input name="wosmpl_presta_type" value="<?php echo $presta_type?>"/>
</div>
<div>
<input type="hidden" name="wosmpl_post_addr" value="<?php echo $wosmpl_post_addr;?>"/>
<!-- adresse postale -->
<?php echo $wosmpl_post_addr; ?>
</div>
<?php endif;?>
<?php
}
function wosmpl_additionnal_marker_data_box_html($post){
$wosmpl_open_hours = get_post_meta($post->ID, 'wosmpl_partner_open_hours', true);
$wosmpl_partner_specialty = get_post_meta($post->ID, 'wosmpl_partner_specialty', true);
?>
<div>
<div id="wosmpl_open_hours">
<label for="wosmpl_partner_open_hours">Horaires d'ouverture</label>
<textarea name="wosmpl_partner_open_hours"><?php echo $wosmpl_open_hours; ?></textarea>
</div>
<div id="wosmpl_partner_specialty">
<label for="wosmpl_partner_specialty">Spécialité</label>
<textarea name="wosmpl_partner_specialty"><?php echo $wosmpl_partner_specialty; ?></textarea>
</div>
</div>
<?php
}
function wosmpl_additionnal_page_data_box_html($post){
$wosmpl_partner_challenge = get_post_meta($post->ID, 'wosmpl_partner_challenge', true);
$wosmpl_partner_phone = get_post_meta($post->ID, 'wosmpl_partner_phone', true);
$wosmpl_partner_phone_visible = get_post_meta($post->ID, 'wosmpl_partner_phone_visible', true);
if($wosmpl_partner_phone_visible == "yes") {
$phone_checked = 'checked="checked"';
}
$wosmpl_partner_email = get_post_meta($post->ID, 'wosmpl_partner_email', true);
$wosmpl_partner_email_visible = get_post_meta($post->ID, 'wosmpl_partner_email_visible', true);
if($wosmpl_partner_email_visible == "yes") {
$email_checked = 'checked="checked"';
}
$wosmpl_partner_website = get_post_meta($post->ID, 'wosmpl_partner_website', true);
$wosmpl_partner_website_visible = get_post_meta($post->ID, 'wosmpl_partner_website_visible', true);
if($wosmpl_partner_website_visible == "yes") {
$website_checked = 'checked="checked"';
}
$img_file = get_post_meta($post->ID, 'wosmpl_partner_pict', true);
if ($img_file && strlen($img_file) > 40) { //40 because filename is sha1
$img_src = $img_file;
} else {
$img_src = plugins_url('images/no-picture.png', __FILE__);
}
$width = $height = 0;
?>
<div>
<div class="upload">
<h5>Photo associée</h5>
<img id="wosmpl_upload_viewer" src="<?php echo $img_src;?>" width="150px" />
<?php if ($width > 0) { echo " ($width x $height)";} ?>
<div>
<input type="hidden" name="wosmpl_partner_pict" id="wosmpl_partner_pict" value="<?php echo $img_file;?>" />
<input type="file" id="wosml_img_selector" accept="image/png, image/jpeg"/>
<a class="wosmpl_upload_image_button button" style="display:none;">Envoyer
</a>
<a class="wosmpl_remove_image_button button">&times;</a>
</div>
</div>
<div id="wosmpl_partner_challenge">
<label for="wosmpl_partner_challenge">Défi</label>
<textarea name="wosmpl_partner_challenge"><?php echo $wosmpl_partner_challenge; ?></textarea>
</div>
<div id="wosmpl_partner_phone">
<label for="wosmpl_partner_phone">Téléphone</label>
<input name="wosmpl_partner_phone" type="tel" value="<?php echo $wosmpl_partner_phone; ?>" />
<input type="checkbox" name="wosmpl_partner_phone_visible" value="yes" <?php echo $phone_checked?>/> visible
</div>
<div id="wosmpl_partner_email">
<label for="wosmpl_partner_email">Email</label>
<input name="wosmpl_partner_email" type="email" value="<?php echo $wosmpl_partner_email; ?>" />
<input type="checkbox" name="wosmpl_partner_email_visible" value="yes" <?php echo $email_checked?>/> visible
</div>
<div id="wosmpl_partner_website">
<label for="wosmpl_partner_website">Site</label>
<input name="wosmpl_partner_website" type="text" value="<?php echo $wosmpl_partner_website; ?>" />
<input type="checkbox" name="wosmpl_partner_website_visible" value="yes" <?php echo $website_checked?>/> visible
</div>
</div>
<?php
}
\ No newline at end of file
<?php
$geo_cats = get_option('wosmpl_geo_cats', NULL);
if (is_null($geo_cats)) {
$geo_cats = [
['id'=>1, 'name'=>"Restaurant, bar, traiteur"],
['id'=>2, 'name'=>"Commerce alimentaire"],
['id'=>3, 'name'=>"Artisanat, métier d'art"],
['id'=>4, 'name'=>"Habillement, mode, accessoires"],
['id'=>5, 'name'=>"Hygiène, beauté"],
['id'=>6, 'name'=>"Papeterie, librairie, presse, édition"],
['id'=>7, 'name'=>"Décoration, ameublement, bricolage, jardin"],
['id'=>8, 'name'=>"Commerces divers"],
['id'=>9, 'name'=>"Sortie culturelle"],
['id'=>10 ,'name'=>"Informatique, électronique"],
['id'=>11, 'name'=>"Santé, bien-être"],
['id'=>12, 'name'=>"Mécanique, réparation"],
['id'=>13, 'name'=>"Transport, livraison"],
['id'=>14, 'name'=>"Web, multimédia, communication, imprimerie"],
['id'=>15, 'name'=>"Sports et loisirs"],
['id'=>16, 'name'=>"Formation, éducation"],
['id'=>17, 'name'=>"Produit de l'agriculture et élevage"],
['id'=>18, 'name'=>"Hébergement"],
['id'=>19, 'name'=>"Immobilier"],
['id'=>20, 'name'=>"Services à la personne"],
['id'=>21, 'name'=>"Divers"],
['id'=>22, 'name'=>"Marchés"]
];
add_option('wosmpl_geo_cats', $geo_cats);
}
add_option('wosmpl_cat_icon_path', '/wp-content/plugins/wosmpl/public/css/images/');
add_option('wosmpl_cat_icon_name_prefix','wosmpl-marker-icon');
\ No newline at end of file
<?php
/**
* Provide a admin area view for the plugin
*
* This file is used to markup the admin-facing aspects of the plugin.
*
* @link http://example.com
* @since 1.0.0
*
* @package Plugin_Name
* @subpackage Plugin_Name/admin/partials
*/
?>
<!-- This file should primarily consist of HTML with a little bit of PHP. -->
<?php
/**
* custom option and settings
*/
function wosmpl_settings_init() {
// register a new setting for "wosmpl" page
register_setting( 'wosmpl', 'wosmpl_options' );
// register a new section in the "wosmpl" page
add_settings_section(
'wosmpl_section_map_page', //id
__( 'Map Page', 'wosm' ), //title
'wosmpl_section_map_page', //callback
'wosmpl' //page slug
);
add_settings_section(
'wosmpl_section_menu_page', //id
__( 'Menu', 'wosm' ), //title
'wosmpl_section_menu_page', //callback
'wosmpl' //page slug
);
// register a new field in the "wosmpl_section_map_page" section, inside the "wosmpl" page
add_settings_field(
'wosmpl_map_page_id', // as of WP 4.6 this value is used only internally
// use $args' label_for to populate the id inside the callback
__( 'Main map page', 'wosmpl' ), //title
'wosmpl_main_map_page_id', //callback
'wosmpl', //page
'wosmpl_section_map_page', //section and args above
[
'label_for' => 'wosmpl_main_map_page_id',
'class' => 'wosmpl_row',
'wosmpl_custom_data' => 'custom',
]
);
add_settings_field(
'wosmpl_map_size_ref', //
__( 'Elt selector for map width', 'wosmpl' ), //title
'wosmpl_main_map_size_ref', //callback
'wosmpl', //page
'wosmpl_section_map_page', //section and args above
[
'label_for' => 'wosmpl_main_map_size_ref',
'class' => 'wosmpl_row'
]
);
add_settings_field(
'wosmpl_map_cat_legend', //
__( 'Cat. legend', 'wosmpl' ), //title
'wosmpl_main_map_legend', //callback
'wosmpl', //page
'wosmpl_section_map_page', //section and args above
[
'label_for' => 'wosmpl_main_map_cat_legend',
'class' => 'wosmpl_row'
]
);
add_settings_field(
'wosmpl_partner_menu', //
__( 'Show sub-menu', 'wosmpl' ), //title
'wosmpl_partner_menu_show', //callback
'wosmpl', //page
'wosmpl_section_menu_page', //section and args above
[
'label_for' => 'wosmpl_partner_sub_menu_show',
'class' => 'wosmpl_row'
]
);
}
add_action( 'admin_init', 'wosmpl_settings_init' );
function wosmpl_section_map_page( $args ) {
?>
<p id="<?php echo esc_attr( $args['id'] ); ?>"><?php esc_html_e( 'Main Map settings', 'wosmpl' ); ?></p>
<?php
}
function wosmpl_section_menu_page( $args ) {
?>
<p id="<?php echo esc_attr( $args['id'] ); ?>"><?php esc_html_e( 'Partner menu dispay', 'wosmpl' ); ?></p>
<?php
}
// field callbacks can accept an $args parameter, which is an array.
// $args is defined at the add_settings_field() function.
// wordpress has magic interaction with the following keys: label_for, class.
// the "label_for" key value is used for the "for" attribute of the <label>.
// the "class" key value is used for the "class" attribute of the <tr> containing the field.
// you can add custom key value pairs to be used inside your callbacks.
function wosmpl_main_map_page_id( $args ) {
// get the value of the setting we've registered with register_setting()
$options = get_option( 'wosmpl_options' );
// output the field
$candidate_pages = wosmpl_pages_with_shortcode('wosmpl_map');
?>
<select id="<?php echo esc_attr( $args['label_for'] ); ?>"
name="wosmpl_options[<?php echo esc_attr( $args['label_for'] ); ?>]"
>
<option value="0" <?php echo isset( $options[ $args['label_for'] ] ) ? ( selected( $options[ $args['label_for'] ], '0', false ) ) : ( '' ); ?>>
<?php esc_html_e( 'Select', 'wosmpl' ); ?>
</option>
<?php
foreach ($candidate_pages as $p) {
echo '<option value="'.$p->ID.'" '.selected($options[ $args['label_for'] ],$p->ID).'>'.$p->post_title.'</option>';
}
?>
</select>
<?php
}
function wosmpl_main_map_size_ref( $args ) {
$options = get_option( 'wosmpl_options' );
echo '<input name="wosmpl_options['.esc_attr( $args['label_for'] ).']"';
echo ' value="'.$options[ $args['label_for'] ].'" />';
}
function wosmpl_main_map_legend($args) {
$options = get_option( 'wosmpl_options' );
echo '<input maxlength="256" name="wosmpl_options['.esc_attr( $args['label_for'] ).']" value="'.$options[ $args['label_for'] ].'" style="min-width:75em;" />';
}
function wosmpl_partner_menu_show($args) {
$options = get_option( 'wosmpl_options' );
$checked = ($options[ $args['label_for'] ] == 'yes')?' checked="echecked"':'';
echo '<input name="wosmpl_options['.esc_attr( $args['label_for'] ).']" type="checkbox" value="yes" '.$checked.' />';
echo $options[ $args['label_for'] ];
}
function wosmpl_options_page_html()
{
// check user capabilities
if (!current_user_can('manage_options')) {
return;
}
// add error/update messages
// check if the user have submitted the settings
// wordpress will add the "settings-updated" $_GET parameter to the url
if ( isset( $_GET['settings-updated'] ) ) {
// add settings saved message with the class of "updated"
add_settings_error( 'wosmpl_messages', 'wosmpl_message', __( 'Settings Saved', 'wosmpl' ), 'updated' );
}
// show error/update messages
settings_errors( 'wosmpl_messages' );
?>
<div class="wrap">
<h1><?= esc_html(get_admin_page_title()); ?></h1>
<form action="options.php" method="post">
<?php
// output security fields for the registered setting "wosmpl_options"
settings_fields('wosmpl');
// output setting sections and their fields
// (sections are registered for "wospml", each field is registered to a specific section)
do_settings_sections('wosmpl');
// output save settings button
submit_button('Save Settings');
?>
</form>
</div>
<?php
}
<?php
/**
* Fired during plugin activation
*
* @link http://example.com
* @since 1.0.0
*
* @package Plugin_Name
* @subpackage Plugin_Name/includes
*/
/**
* Fired during plugin activation.
*
* This class defines all code necessary to run during the plugin's activation.
*
* @since 1.0.0
* @package Plugin_Name
* @subpackage Plugin_Name/includes
* @author Your Name <email@example.com>
*/
class WosmPL_Activator {
/**
* Short Description. (use period)
*
* Long Description.
*
* @since 1.0.0
*/
public static function activate() {
$wupload = wp_upload_dir();
mkdir($wupload['basedir'].'/wosmpl');
add_option('wosmpl_upload_dir',$wupload['basedir'].'/wosmpl');
flush_rewrite_rules();
}
}
<?php
/**
* Fired during plugin deactivation
*
* @link http://example.com
* @since 1.0.0
*
* @package Plugin_Name
* @subpackage Plugin_Name/includes
*/
/**
* Fired during plugin deactivation.
*
* This class defines all code necessary to run during the plugin's deactivation.
*
* @since 1.0.0
* @package Plugin_Name
* @subpackage Plugin_Name/includes
* @author Your Name <email@example.com>
*/
class WosmPL_Deactivator {
/**
* Short Description. (use period)
*
* Long Description.
*
* @since 1.0.0
*/
public static function deactivate() {
unregister_setting('wosmpl', 'wosmpl_options' );
}
}
<?php
/**
* Define the internationalization functionality
*
* Loads and defines the internationalization files for this plugin
* so that it is ready for translation.
*
* @link http://example.com
* @since 1.0.0
*
* @package Plugin_Name
* @subpackage Plugin_Name/includes
*/
/**
* Define the internationalization functionality.
*
* Loads and defines the internationalization files for this plugin
* so that it is ready for translation.
*
* @since 1.0.0
* @package Plugin_Name
* @subpackage Plugin_Name/includes
* @author Your Name <email@example.com>
*/
class WosmPL_i18n {
/**
* Load the plugin text domain for translation.
*
* @since 1.0.0
*/
public function load_plugin_textdomain() {
load_plugin_textdomain(
'wosmpl',
false,
dirname( dirname( plugin_basename( __FILE__ ) ) ) . '/languages/'
);
}
}
<?php
/**
* Register all actions and filters for the plugin
*
* @link http://example.com
* @since 1.0.0
*
* @package Plugin_Name
* @subpackage Plugin_Name/includes
*/
/**
* Register all actions and filters for the plugin.
*
* Maintain a list of all hooks that are registered throughout
* the plugin, and register them with the WordPress API. Call the
* run function to execute the list of actions and filters.
*
* @package Plugin_Name
* @subpackage Plugin_Name/includes
* @author Your Name <email@example.com>
*/
class WosmPL_Loader {
/**
* The array of actions registered with WordPress.
*
* @since 1.0.0
* @access protected
* @var array $actions The actions registered with WordPress to fire when the plugin loads.
*/
protected $actions;
/**
* The array of filters registered with WordPress.
*
* @since 1.0.0
* @access protected
* @var array $filters The filters registered with WordPress to fire when the plugin loads.
*/
protected $filters;
/**
* Initialize the collections used to maintain the actions and filters.
*
* @since 1.0.0
*/
public function __construct() {
$this->actions = array();
$this->filters = array();
}
/**
* Add a new action to the collection to be registered with WordPress.
*
* @since 1.0.0
* @param string $hook The name of the WordPress action that is being registered.
* @param object $component A reference to the instance of the object on which the action is defined.
* @param string $callback The name of the function definition on the $component.
* @param int $priority Optional. The priority at which the function should be fired. Default is 10.
* @param int $accepted_args Optional. The number of arguments that should be passed to the $callback. Default is 1.
*/
public function add_action( $hook, $component, $callback, $priority = 10, $accepted_args = 1 ) {
$this->actions = $this->add( $this->actions, $hook, $component, $callback, $priority, $accepted_args );
}
/**
* Add a new filter to the collection to be registered with WordPress.
*
* @since 1.0.0
* @param string $hook The name of the WordPress filter that is being registered.
* @param object $component A reference to the instance of the object on which the filter is defined.
* @param string $callback The name of the function definition on the $component.
* @param int $priority Optional. The priority at which the function should be fired. Default is 10.
* @param int $accepted_args Optional. The number of arguments that should be passed to the $callback. Default is 1
*/
public function add_filter( $hook, $component, $callback, $priority = 10, $accepted_args = 1 ) {
$this->filters = $this->add( $this->filters, $hook, $component, $callback, $priority, $accepted_args );
}
/**
* A utility function that is used to register the actions and hooks into a single
* collection.
*
* @since 1.0.0
* @access private
* @param array $hooks The collection of hooks that is being registered (that is, actions or filters).
* @param string $hook The name of the WordPress filter that is being registered.
* @param object $component A reference to the instance of the object on which the filter is defined.
* @param string $callback The name of the function definition on the $component.
* @param int $priority The priority at which the function should be fired.
* @param int $accepted_args The number of arguments that should be passed to the $callback.
* @return array The collection of actions and filters registered with WordPress.
*/
private function add( $hooks, $hook, $component, $callback, $priority, $accepted_args ) {
$hooks[] = array(
'hook' => $hook,
'component' => $component,
'callback' => $callback,
'priority' => $priority,
'accepted_args' => $accepted_args
);
return $hooks;
}
/**
* Register the filters and actions with WordPress.
*
* @since 1.0.0
*/
public function run() {
// TODO : Place to manage current_user_can(....) ?
foreach ( $this->filters as $hook ) {
add_filter( $hook['hook'], array( $hook['component'], $hook['callback'] ), $hook['priority'], $hook['accepted_args'] );
}
foreach ( $this->actions as $hook ) {
add_action( $hook['hook'], array( $hook['component'], $hook['callback'] ), $hook['priority'], $hook['accepted_args'] );
}
}
}
<?php
class WosmPL_GeoCat_Widget extends WP_Widget {
function __construct() {
$widget_ops = array(
'description' => 'Displays geo cat.',
);
// Instantiate the parent object
parent::__construct( false, 'WosmPL Geocat.', $widget_ops);
}
function widget( $args, $instance ) {
// Widget output
echo $args['before_widget'];
if ( ! empty( $instance['title'] ) ) {
echo $args['before_title'] . apply_filters( 'widget_title', $instance['title'] ) . $args['after_title'];
}
$with_map_link = TRUE;
echo wosmpl_get_categories_ul('widget-list',$with_map_link);
echo $args['after_widget'];
}
function update( $new_instance, $old_instance ) {
// Save widget options
$instance = array();
$instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : '';
return $instance;
}
function form( $instance ) {
// Output admin widget options form
$title = ! empty( $instance['title'] ) ? $instance['title'] : esc_html__( 'Title', 'wosmpl' );
?>
<p>
<label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>">
<?php esc_attr_e( 'Title:', 'wosmpl' ); ?>
</label>
<input
class="widefat"
id="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"
name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>"
type="text"
value="<?php echo esc_attr( $title ); ?>">
</p>
<?php
}
}
<?php
/**
* The core plugin class.
*
* This is used to define internationalization, admin-specific hooks, and
* public-facing site hooks.
*
* Also maintains the unique identifier of this plugin as well as the current
* version of the plugin.
*
* @since 1.0.0
* @package WosmPL
* @subpackage WosmPL/includes
* @author fracolo
*/
class WosmPL {
/**
* The loader that's responsible for maintaining and registering all hooks that power
* the plugin.
*
* @since 1.0.0
* @access protected
* @var Plugin_Name_Loader $loader Maintains and registers all hooks for the plugin.
*/
protected $loader;
/**
* The unique identifier of this plugin.
*
* @since 1.0.0
* @access protected
* @var string $plugin_name The string used to uniquely identify this plugin.
*/
protected $plugin_name;
/**
* The current version of the plugin.
*
* @since 1.0.0
* @access protected
* @var string $version The current version of the plugin.
*/
protected $version;
/**
* Define the core functionality of the plugin.
*
* Set the plugin name and the plugin version that can be used throughout the plugin.
* Load the dependencies, define the locale, and set the hooks for the admin area and
* the public-facing side of the site.
*
* @since 1.0.0
*/
public function __construct() {
if ( defined( 'WOSMPL_VERSION' ) ) {
$this->version = WOSMPL_VERSION;
} else {
$this->version = '1.0.0';
}
$this->plugin_name = 'wosmpl';
$this->load_dependencies();
$this->set_locale();
$this->define_admin_hooks();
$this->define_public_hooks();
}
/**
* Load the required dependencies for this plugin.
*
* Include the following files that make up the plugin:
*
* - Plugin_Name_Loader. Orchestrates the hooks of the plugin.
* - Plugin_Name_i18n. Defines internationalization functionality.
* - Plugin_Name_Admin. Defines all hooks for the admin area.
* - Plugin_Name_Public. Defines all hooks for the public side of the site.
*
* Create an instance of the loader which will be used to register the hooks
* with WordPress.
*
* @since 1.0.0
* @access private
*/
private function load_dependencies() {
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/functions.php';
/**
* The class responsible for orchestrating the actions and filters of the
* core plugin.
*/
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wosmpl-loader.php';
/**
* The class responsible for defining internationalization functionality
* of the plugin.
*/
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wosmpl-i18n.php';
/**
* The class responsible for defining all actions that occur in the admin area.
*/
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wosmpl-admin.php';
/**
* The class responsible for defining all actions that occur in the public-facing
* side of the site.
*/
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-wosmpl-public.php';
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/shortcodes.php';
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wosmpl-widgets.php';
$this->loader = new WosmPL_Loader();
}
/**
* Define the locale for this plugin for internationalization.
*
* Uses the Plugin_Name_i18n class in order to set the domain and to register the hook
* with WordPress.
*
* @since 1.0.0
* @access private
*/
private function set_locale() {
$plugin_i18n = new WosmPL_i18n();
$this->loader->add_action( 'plugins_loaded', $plugin_i18n, 'load_plugin_textdomain' );
}
/**
* Register all of the hooks related to the admin area functionality
* of the plugin.
*
* @since 1.0.0
* @access private
*/
private function define_admin_hooks() {
$plugin_admin = new WosmPL_Admin( $this->get_plugin_name(), $this->get_version() );
$this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_styles' );
$this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts' );
//TODO Add menu and settings
//https://developer.wordpress.org/plugins/administration-menus/top-level-menus/
$this->loader->add_action( 'save_post', $plugin_admin, 'wosmpl_save_post' );
$this->loader->add_action( 'add_meta_boxes', $plugin_admin, 'wosmpl_geodata_box' );
$this->loader->add_action( 'widgets_init', $plugin_admin, 'wosmpl_widgets' );
$this->loader->add_action( 'admin_menu', $plugin_admin, 'wosmpl_options_page' );
$this->loader->add_action( 'init', $plugin_admin, 'wosmpl_register_type' );
$this->loader->add_action( 'single_template', $plugin_admin, 'wosmpl_partner_template' );
}
/**
* Register all of the hooks related to the public-facing functionality
* of the plugin.
*
* @since 1.0.0
* @access private
*/
private function define_public_hooks() {
$options = get_option( 'wosmpl_options' );
$plugin_public = new WosmPL_Public( $this->get_plugin_name(), $this->get_version() );
$this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_styles' );
$this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_scripts' );
$this->loader->add_action( 'init', $plugin_public, 'wosmpl_register_nav_menu' );
}
/**
* Run the loader to execute all of the hooks with WordPress.
*
* @since 1.0.0
*/
public function run() {
$this->loader->run();
}
/**
* The name of the plugin used to uniquely identify it within the context of
* WordPress and to define internationalization functionality.
*
* @since 1.0.0
* @return string The name of the plugin.
*/
public function get_plugin_name() {
return $this->plugin_name;
}
/**
* The reference to the class that orchestrates the hooks with the plugin.
*
* @since 1.0.0
* @return Plugin_Name_Loader Orchestrates the hooks of the plugin.
*/
public function get_loader() {
return $this->loader;
}
/**
* Retrieve the version number of the plugin.
*
* @since 1.0.0
* @return string The version number of the plugin.
*/
public function get_version() {
return $this->version;
}
}
<?php
function wosmpl_leaflet_activate() {
wp_enqueue_script('leaflet-js', plugin_dir_url( dirname( __FILE__ ) ) . 'public/js/leaflet.js', array( 'jquery' ), '1.3.4', false);
wp_enqueue_script('markercluster-js', plugin_dir_url( dirname( __FILE__ ) ) . 'public/js/leaflet.markercluster-src.js', array( 'jquery' ), '1.3.4', false);
wp_enqueue_style( 'leaflet-css', plugin_dir_url ( dirname( __FILE__ ) ) . 'public/css/leaflet.css');
wp_enqueue_style( 'marker-cluster-css', plugin_dir_url ( dirname( __FILE__ ) ) . 'public/css/MarkerCluster.css');
wp_enqueue_style( 'marker-cluster-default-css', plugin_dir_url ( dirname( __FILE__ ) ) . 'public/css/MarkerCluster.Default.css');
}
function wosmpl_pages_with_shortcode($shortcode, $args = array()) {
if(!shortcode_exists($shortcode)) {
// shortcode was not registered (yet?)
return null;
}
// replace get_pages with get_posts
// if you want to search in posts
$pages = get_pages($args);
$list = array();
foreach($pages as $page) {
if(has_shortcode($page->post_content, $shortcode)) {
$list[] = $page;
}
}
return $list;
}
function wosmpl_get_cat_marker_icon($cat_id){
//get_option is caching result
$cat_icon_path = get_option('wosmpl_cat_icon_path');
$cat_icon_name_prefix = get_option('wosmpl_cat_icon_name_prefix');
return $cat_icon_path . $cat_icon_name_prefix . $cat_id . '.png';
}
function wosmpl_get_categories_with_nb(){
$geo_cats = get_option('wosmpl_geo_cats', []);
$contents = wosmpl_get_geolocalized_contents();
foreach ($contents as $c) {
if ($c->type == 'wosmpl_partners') {
for($i=0;$i < count($geo_cats);$i++) {
if ($geo_cats[$i]['id'] == $c->cat) {
if (!isset($geo_cats[$i]['nb'])) {
$geo_cats[$i]['nb'] = 1;
} else {
$geo_cats[$i]['nb']++;
}
break;
}
}
}
}
return $geo_cats;
}
/*
* All partner's retreived content is reordered
* to be returned an associative array
* in which keys are categories id
*/
function wosmpl_get_array_by_category($contents) {
$result = [];
$tmp_result = [];
$geo_cats = get_option('wosmpl_geo_cats', []);
$named_cats = [];
foreach ($geo_cats as $gc) {
$named_cats[$gc['id']] = $gc['name'];
}
foreach ($contents as $c) {
if ($c->cat > 0) {
if (!isset($tmp_result[$c->cat])) {
$tmp_result[$c->cat] = [];
}
$tmp_result[$c->cat][] = $c;
}
}
//sort by contents size
usort($tmp_result,function($a,$b) {
if (count($a) == count($b)) {
return 0;
}
return (count($a) > count($b)) ? -1 : 1;
});
// Set result with cat name keys
foreach ($tmp_result as $contents) {
$fc = $contents[0];
$result[$named_cats[$fc->cat]] = ['id'=>$fc->cat,
'contents'=>$contents];
}
//var_dump($result);
return $result;
}
function wosmpl_get_map_url(){
$options = get_option( 'wosmpl_options' );
$map_url = '';
if (isset($options['wosmpl_main_map_page_id'])) {
$p_id = $options['wosmpl_main_map_page_id'];
if ($p_id > 0) {
$map_url = get_permalink($p_id);
}
}
return $map_url;
}
/*
* Function returning HTML code of Partners categories (with or without map link url)
*/
function wosmpl_get_categories_ul($ul_class='sub-menu wosmpl-cat',$with_map_link=FALSE) {
$map_url = wosmpl_get_map_url();
$cats = wosmpl_get_categories_with_nb();
$o = '';
if (count($cats) > 0) {
$o = '<ul class="'.$ul_class.'">';
foreach ($cats as $cat) {
if ($cat['nb'] > 0) {
$img_url = wosmpl_get_cat_marker_icon($cat['id']);
$li_open = '<li>';
$img_width = '50';
if ($ul_class =='sub-menu') {
$li_open = '<li class="menu-item">';
$img_width = '35';
}
$o .= $li_open;
$o .= '<img src="'.$img_url.'" width="'.$img_width.'" /> ';
$o .= '<span>('.$cat['nb'].')</span>';
if ($map_url != '') {
$o .= ' <a href="'.$map_url.'?code_categorie='.$cat['id'].'" >'.$cat['name'].'</a>';
}
$o .= '</li>';
}
}
$o .= '</ul>';
if ($map_url != '' && $with_map_link === TRUE) {
$o .= '<a href="'.$map_url.'">Carte partenaire</a>';
}
}
return $o;
}
<?php // Silence is golden
\ No newline at end of file
<?php
/*
* Returning all geolocalized partner's
*/
function wosmpl_get_geolocalized_contents() {
$contents = [];
// WP_Query arguments
$args = array(
'post_type' => array( 'wosmpl_partners' ),
'order' => 'ASC',
'orderby' => 'ID',
'posts_per_page' => '-1',
'meta_query' => array(
array(
'key' => 'wosmpl_latlon',
)
),
);
// The Query
$query = new WP_Query( $args );
if ( $query->have_posts() ) {
while ( $query->have_posts() ) {
$query->the_post();
$p = get_post();
$metadata = get_post_meta( $p->ID);
//var_dump($p);
$c = new StdClass();
$c->title = $p->post_title;
$c->type = $p->post_type;
//These queries should be in cache (no pain after the first time)
$c->latlon = str_replace(' ','',get_post_meta($p->ID,'wosmpl_latlon', true));
$c->cat = $metadata['wosmpl_geo_cat'][0];
$c->presta_type = $metadata['wosmpl_presta_type'][0];
$c->url = get_permalink($p->ID);
$c->picture_url = $metadata['wosmpl_partner_pict'][0];
$c->open_hours = $metadata['wosmpl_partner_open_hours'][0];
$c->post_addr = $metadata['wosmpl_post_addr'][0];
$c->specialty = $metadata['wosmpl_partner_specialty'][0];
$contents[] = $c;
}
wp_reset_postdata();
}
return $contents;
}
<?php
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/queries.php';
/*
* Returning partner marker popup content
* (Could be done in browser side, to reduce json content length)
*/
function wosmpl_create_popup_content($content, $cat) {
$popup_content = "<h2><strong><a href=\"{$content->url}\" target=\"_blank\"> {$content->title} <i class=\"fa fa-external-link wo-icon\"> </i></a></strong></h2>";
if(isset($cat['name'])) {
$popup_content .= '<p class="cat">'.$cat['name'].'<p/>';
}
/** TODO : Input user settings to know if picture has to be shown
if (strlen($content->picture_url) > 0) {
$picture_url = str_replace('.','-125.',$content->picture_url);
$popup_content .= '<img src="'.$picture_url.'" alt="" />';
}
**/
if (strlen($content->post_addr) > 0) {
$popup_content .= '<p class="open_hours">'.$content->post_addr.'</p>';
}
if (strlen($content->open_hours) > 0) {
$popup_content .= '<p class="open_hours">'.nl2br($content->open_hours).'</p>';
}
if (strlen($content->specialty) > 0) {
$popup_content .= '<p class="specialty">'.nl2br($content->specialty).'</p>';
}
return $popup_content;
}
/*
* Returning partner's geojson content corresponding to the resquested map
*/
function wosmpl_create_geojson($contents){
$points = [];
$geo_cats = get_option('wosmpl_geo_cats', []);
$filtered_cat = NULL;
if (isset($_GET['code_categorie']) && is_numeric($_GET['code_categorie'])) {
$filtered_cat = $_GET['code_categorie'];
}
foreach ($contents as $c) {
if ($filtered_cat === NULL || $filtered_cat == $c->cat) {
list($lat,$lon) = explode(',', $c->latlon);
if ($lat) {
$p = new StdClass();
$p->type = "Feature";
$p->geometry = [
'type'=>'Point',
'coordinates' => [$lon,$lat]
];
$cat = [];
foreach ($geo_cats as $gc) {
if ($gc['id'] == $c->cat) {
$cat = $gc;
}
}
$p->cat = $cat;
$properties = [
'name'=>$c->title,
'popupContent'=>
wosmpl_create_popup_content($c, $cat)
];
if(isset($cat['id'])) {
$properties['cat'] = $cat['id'];
}
$p->properties = $properties;
$points[] = $p;
}
}
}
return json_encode($points);
}
/*
* Returning HTML code of partners list
* for each known categories or only for the one asked by GET parameter
*/
function wosmpl_cat_list_html($by_cat_content) {
$o = '<div class="wosmpl-box partner_list">';
foreach ($by_cat_content as $catname =>$elts) {
$add_it = TRUE;
$show_name = TRUE;
if (isset($_GET['code_categorie']) && is_numeric($_GET['code_categorie'])) {
if ($_GET['code_categorie'] == $elts['id']) {
$add_it = TRUE;
$show_name = FALSE;
} else {
$add_it = FALSE;
}
}
if ($add_it == TRUE){
$o .= '<div class="wosmpl_categ" data-catid="'.$elts['id'].'">';
if ($show_name == TRUE) {
$o .= '<h2><img width="35" src="'.wosmpl_get_cat_marker_icon($elts['id']).'" alt=""/>'.$catname.'</h2>';
}
foreach ($elts['contents'] as $c) {
//var_dump($c);
$o .= '<div class="partner_sum_up">';
$o .= '<h3><a href="'.$c->url.'" target="_blank">'.$c->title.' <i class="fa fa-external-link wo-icon"></i></a></h3>';
$o .= "<span class=\"presta-type\">{$c->presta_type}</span>";
$o .= '</div>';
}
$o .= '</div>';
}
}
$o .= '</div>';
return $o;
}
/*
* Return generated content of [map] shortcut
*
*/
function wosmpl_map_shortcode($atts = [], $content = null, $tag = '')
{
$o = '';
//Retrieve all geolocalized contents
$contents = wosmpl_get_geolocalized_contents();
if (count($contents) > 0) {
$cat_icon_path = get_option('wosmpl_cat_icon_path');
$cat_icon_name_prefix = get_option('wosmpl_cat_icon_name_prefix');
wosmpl_leaflet_activate();
// normalize attribute keys, lowercase
$atts = array_change_key_case((array)$atts, CASE_LOWER);
// override default attributes with user attributes
$wosmpl_atts = shortcode_atts([
'title' => '',
'cat_filter' => 'true'
], $atts, $tag);
$geo_cats = get_option('wosmpl_geo_cats', []);
$cat_filter = '';
$by_cat_content = wosmpl_get_array_by_category($contents);
$gcats = wosmpl_get_categories_with_nb();
$options = get_option( 'wosmpl_options' );
//var_dump($by_cat_content);
if (isset($_GET['code_categorie']) && is_numeric($_GET['code_categorie'])) {
foreach ($geo_cats as $gc) {
if ($gc['id'] == $_GET['code_categorie']) {
$wosmpl_atts['title'] = $gc['name'];
}
}
} else if (isset($wosmpl_atts['cat_filter']) && $wosmpl_atts['cat_filter'] == 'true'){
if (count($gcats) > 0) {
$cat_filter = '<div class="wosmpl_map_cat_filter">';
if (isset($options['wosmpl_main_map_cat_legend'])) {
$cat_filter .= '<p>'.$options['wosmpl_main_map_cat_legend'].'</p>';
}
$cat_filter .= '<div class="wospml_cat_choice" data-catid="0" ><div class="icon" title="Toutes les catégories"><img width="50" src="'.wosmpl_get_cat_marker_icon(0).'" alt=""/></div></div>';
foreach ($gcats as $gc) {
if ($gc['nb'] > 0) {
$cat_filter .= '<div class="wospml_cat_choice" data-catid="'.$gc['id'].'" >'."\n";
$cat_filter .= '<div class="icon" title="'.$gc['name'].'">';
$cat_filter .= '<img width="50" src="'.wosmpl_get_cat_marker_icon($gc['id']).'" alt=""/>';
$cat_filter .= '</div>';
$cat_filter .= '</div>'."\n";
}
}
$cat_filter .= '<div class="clear"></div>';
$cat_filter .= '</div>';
}
}
//var_dump($contents);
// start output
if (strlen($wosmpl_atts['title']) > 0) {
$o .= '<h2>' . esc_html__($wosmpl_atts['title'], 'wosmpl') . '</h2>';
}
$o .= '<a name="map"></a>';
$o .= '<div class="wosmpl-box map">';
$o .= '</div>';
$o .= $cat_filter;
$o .= wosmpl_cat_list_html($by_cat_content);
$o .= '<script type="text/javascript">';
$o .= 'top.cat_icon_path = "'.$cat_icon_path.'";';
$o .= 'top.cat_icon_name_prefix = "'.$cat_icon_name_prefix.'";';
$o .= 'top.contents_to_show = '.wosmpl_create_geojson($contents). ';';
if (isset($options['wosmpl_main_map_size_ref'])) {
$map_size_ref = $options['wosmpl_main_map_size_ref'];
if (strlen($map_size_ref) > 0) {
$o .= "top.map_size_ref = '$map_size_ref';";
}
}
$o .= '</script>';
}
// return output
return $o;
}
function wosmpl_shortcodes_init()
{
add_shortcode('wosmpl_map', 'wosmpl_map_shortcode');
}
add_action('init', 'wosmpl_shortcodes_init');
\ No newline at end of file
<?php
/*
* Template Name: wosmpl partner
* Template Post Type: wosmpl_partners
*/
get_header();
global $post;
$geo_cats = get_option('wosmpl_geo_cats', []);
$metadata = get_post_meta( $post->ID);
$catid = $metadata['wosmpl_geo_cat'][0];
$presta_type = $metadata['wosmpl_presta_type'][0];
$cat = NULL;
$post_addr = $metadata['wosmpl_post_addr'][0];
$latlon = $metadata['wosmpl_latlon'][0];
$pict_url = $metadata['wosmpl_partner_pict'][0];
if (strlen($pict_url) > 0){
$pict_url = str_replace('.','-350.',$pict_url);
}
$open_hours = $metadata['wosmpl_partner_open_hours'][0];
$specialty = $metadata['wosmpl_partner_specialty'][0];
$challenge = $metadata['wosmpl_partner_challenge'][0];
$phone = NULL;
if ($metadata['wosmpl_partner_phone_visible'][0] == 'yes') {
$phone = $metadata['wosmpl_partner_phone'][0];
}
$email = NULL;
if ($metadata['wosmpl_partner_email_visible'][0] == 'yes') {
$email = $metadata['wosmpl_partner_email'][0];
}
$website = NULL;
if ($metadata['wosmpl_partner_website_visible'][0] == 'yes') {
$website = $metadata['wosmpl_partner_website'][0];
}
foreach ($geo_cats as $gc) {
if ($gc['id'] == $catid) {
$cat = $gc['name'];
}
}
?>
<link rel="stylesheet" id="google-fonts-1-css" href="https://fonts.googleapis.com/css?family=Voltaire:100,100italic,200,200italic,300,300italic,400,400italic,500,500italic,600,600italic,700,700italic,800,800italic,900,900italic|Roboto:100,100italic,200,200italic,300,300italic,400,400italic,500,500italic,600,600italic,700,700italic,800,800italic,900,900italic" type="text/css" media="all">
<style type="text/css">
#primary h1 {padding-top:180px;
background-color: #0aa245;
border-bottom-left-radius: 450px 50px;
border-bottom-right-radius: 450px 50px;
text-align: center;
color: #FFF;
}
.partner_details .coord {float:left;}
.partner_details .picture {float:right;}
.partner_details .desc {clear:both;}
.hours div {float:left;}
.desc {margin-top:15px;}
@media only screen and (max-width: 375px) {
#primary h1 {max-height: 70px;padding-top:0px;}
}
</style>
<div id="primary" class="content-area">
<h1><?php echo $post->post_title; ?></h1>
<div class="container partner_details">
<?php if ($cat) :?>
<h3><?php echo $cat;?></h3>
<?php endif; ?>
<?php if ($presta_type): ?>
<h4 class="presta-type">> <?php echo $presta_type;?></h4>
<?php endif; ?>
<div class="coord">
<?php if ($post_addr):?>
<p>
Adresse : <?php echo $post_addr; ?>
</p>
<?php endif; ?>
<?php if ($phone) : ?>
<p>
Téléphone : <?php echo $phone; ?>
</p>
<?php endif; ?>
<?php if ($email) : ?>
<p>
Email : <?php echo $email; ?>
</p>
<?php endif; ?>
<?php if ($website) : ?>
<p>
Site Web : <a href="<?php echo $website; ?>" target="_blank"><?php echo $website; ?></a>
</p>
<?php endif; ?>
<?php if ($open_hours) :?>
<p class="hours">
Horaires d'ouverture : <br /><?php echo nl2br (esc_html($open_hours)); ?>
</p>
<?php endif; ?>
</div>
<div class="picture">
<?php if ($pict_url):?>
<img width="350" src="<?php echo $pict_url;?>" alt="Photo" />
<?php endif; ?>
</div>
<div class="desc">
<?php if(strlen($post->post_content) >0) :?>
<h3>Description</h3>
<?php echo nl2br($post->post_content); ?>
<?php endif; ?>
</div>
<div>
<?php if($specialty): ?>
<h3>Spécialité</h3>
<?php echo nl2br (esc_html($specialty)); ?>
<?php endif; ?>
</div>
<div>
<?php if($challenge): ?>
<h3>Défi</h3>
<?php echo nl2br (esc_html($challenge)); ?>
<?php endif; ?>
</div>
</div>
<div id="wosmpl_partner_detail_map" style="margin:15px auto;">
</div>
<?php if($latlon): ?>
<script type="text/javascript">
(function( $ ) {
$( window ).load(function() {
var partner_latlng = [<?php echo $latlon;?>];
var map_div = jQuery('#wosmpl_partner_detail_map');
var width = map_div.prev('div').innerWidth();
if (!isNaN(width)) {
if (width > 375) {
width = parseInt(width / 1.5,10);
}
var height = parseInt(width * 9 /16,10);
map_div.css({'width':width + 'px','height': height + 'px'});
var map = L.map('wosmpl_partner_detail_map').setView(partner_latlng, 16);
var osmUrl='https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png';
var osmAttrib='Map data © <a href="http://openstreetmap.org">OpenStreetMap</a> contributors';
var osm = new L.TileLayer(osmUrl, {minZoom: 9, maxZoom: 19, attribution: osmAttrib});
map.addLayer(osm);
var southWest = L.latLng(43.2022, 2.5887),
northEast = L.latLng(43.9562, 4.2586);
var bounds = L.latLngBounds(southWest, northEast);
map.setMaxBounds(bounds);
L.marker(partner_latlng).addTo(map);
}
});
})( jQuery );
</script>
<?php endif; ?>
</div><!-- #content -->
<?php /* var_dump($metadata);*/ ?>
</div><!-- #primary -->
<?php
get_footer();
<?php // Silence is golden
\ No newline at end of file
<?php
/**
* The public-facing functionality of the plugin.
*
* @link http://example.com
* @since 1.0.0
*
* @package Plugin_Name
* @subpackage Plugin_Name/public
*/
/**
* The public-facing functionality of the plugin.
*
* Defines the plugin name, version, and two examples hooks for how to
* enqueue the public-facing stylesheet and JavaScript.
*
* @package Plugin_Name
* @subpackage Plugin_Name/public
* @author Your Name <email@example.com>
*/
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/functions.php';
class WosmPL_Public {
/**
* The ID of this plugin.
*
* @since 1.0.0
* @access private
* @var string $plugin_name The ID of this plugin.
*/
private $plugin_name;
/**
* The version of this plugin.
*
* @since 1.0.0
* @access private
* @var string $version The current version of this plugin.
*/
private $version;
/**
* Initialize the class and set its properties.
*
* @since 1.0.0
* @param string $plugin_name The name of the plugin.
* @param string $version The version of this plugin.
*/
public function __construct( $plugin_name, $version ) {
$this->plugin_name = $plugin_name;
$this->version = $version;
}
/**
* Register the stylesheets for the public-facing side of the site.
*
* @since 1.0.0
*/
public function enqueue_styles() {
/**
* This function is provided for demonstration purposes only.
*
* An instance of this class should be passed to the run() function
* defined in Plugin_Name_Loader as all of the hooks are defined
* in that particular class.
*
* The Plugin_Name_Loader will then create the relationship
* between the defined hooks and the functions defined in this
* class.
*/
wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/wosmpl-public.css', array(), $this->version.'.1', 'all' );
}
/**
* Register the JavaScript for the public-facing side of the site.
*
* @since 1.0.0
*/
public function enqueue_scripts() {
/**
* This function is provided for demonstration purposes only.
*
* An instance of this class should be passed to the run() function
* defined in Plugin_Name_Loader as all of the hooks are defined
* in that particular class.
*
* The Plugin_Name_Loader will then create the relationship
* between the defined hooks and the functions defined in this
* class.
*/
wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/wosmpl-public.js', array( 'jquery' ), $this->version.'.1', false );
if (get_post()->post_type == 'wosmpl_partners') {
wosmpl_leaflet_activate();
}
}
public function wosmpl_register_nav_menu() {
//register_nav_menu('wosmpl_partner_list',__( 'Partners' ));
add_filter( 'wp_nav_menu_items','add_partner_categories', 10, 2 );
function add_partner_categories( $items, $args ) {
if ($args->menu->slug == 'menu-gauche') {
$map_url = wosmpl_get_map_url();
if (strlen($map_url) == 0) {
$map_url = '/catalogue-des-prestataires-partenaires/';
}
$menu = '<li class="menu-item menu-item-has-children partners">';
$menu .= '<a href="'.$map_url.'" class="parent">Prestataires</a>';
if ($options['wosmpl_partner_sub_menu_show'] == 'yes') {
$menu .= wosmpl_get_categories_ul();
}
$menu .= '</li>';
$items .= $menu;
}
return $items;
}
}
}
.marker-cluster-small {
background-color: rgba(181, 226, 140, 0.6);
}
.marker-cluster-small div {
background-color: rgba(110, 204, 57, 0.6);
}
.marker-cluster-medium {
background-color: rgba(241, 211, 87, 0.6);
}
.marker-cluster-medium div {
background-color: rgba(240, 194, 12, 0.6);
}
.marker-cluster-large {
background-color: rgba(253, 156, 115, 0.6);
}
.marker-cluster-large div {
background-color: rgba(241, 128, 23, 0.6);
}
/* IE 6-8 fallback colors */
.leaflet-oldie .marker-cluster-small {
background-color: rgb(181, 226, 140);
}
.leaflet-oldie .marker-cluster-small div {
background-color: rgb(110, 204, 57);
}
.leaflet-oldie .marker-cluster-medium {
background-color: rgb(241, 211, 87);
}
.leaflet-oldie .marker-cluster-medium div {
background-color: rgb(240, 194, 12);
}
.leaflet-oldie .marker-cluster-large {
background-color: rgb(253, 156, 115);
}
.leaflet-oldie .marker-cluster-large div {
background-color: rgb(241, 128, 23);
}
.marker-cluster {
background-clip: padding-box;
border-radius: 20px;
}
.marker-cluster div {
width: 30px;
height: 30px;
margin-left: 5px;
margin-top: 5px;
text-align: center;
border-radius: 15px;
font: 12px "Helvetica Neue", Arial, Helvetica, sans-serif;
}
.marker-cluster span {
line-height: 30px;
}
\ No newline at end of file
.leaflet-cluster-anim .leaflet-marker-icon, .leaflet-cluster-anim .leaflet-marker-shadow {
-webkit-transition: -webkit-transform 0.3s ease-out, opacity 0.3s ease-in;
-moz-transition: -moz-transform 0.3s ease-out, opacity 0.3s ease-in;
-o-transition: -o-transform 0.3s ease-out, opacity 0.3s ease-in;
transition: transform 0.3s ease-out, opacity 0.3s ease-in;
}
.leaflet-cluster-spider-leg {
/* stroke-dashoffset (duration and function) should match with leaflet-marker-icon transform in order to track it exactly */
-webkit-transition: -webkit-stroke-dashoffset 0.3s ease-out, -webkit-stroke-opacity 0.3s ease-in;
-moz-transition: -moz-stroke-dashoffset 0.3s ease-out, -moz-stroke-opacity 0.3s ease-in;
-o-transition: -o-stroke-dashoffset 0.3s ease-out, -o-stroke-opacity 0.3s ease-in;
transition: stroke-dashoffset 0.3s ease-out, stroke-opacity 0.3s ease-in;
}
/**
* All of the CSS for your public-facing functionality should be
* included in this file.
*/
#wosmpl-map {width:640px; height:640px;}
.wosmpl-icon {background-image: url(images/wosmpl-marker-icon.png);}
.widget_wosmpl_geocat_widget ul {list-style: none; padding:0; margin-left:0;}
.widget_wosmpl_geocat_widget li {margin-bottom:5px;}
.wosmpl_map_cat_filter {margin-top:5px;}
.wosmpl_map_cat_filter .wospml_cat_choice {float:left;}
.wosmpl_map_cat_filter .wospml_cat_choice[data-catid="0"] {padding-right:10px;border-right:1px solid #999;}
.wosmpl-box.partner_list {margin-top: 25px;}
.wosmpl-box.partner_list ul {list-style: none;margin-left:0;}
.leaflet-popup-content h2 {margin-bottom: 0 !important;}
.leaflet-popup-content p.cat {font-weight: bold;}
i.fa-external-link {background:none; color:#000;}
\ No newline at end of file
<?php // Silence is golden
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
(function( $ ) {
'use strict';
var map = null;
var contents_polygon = null;
var map_center = null;
var geojson_layer = null;
var markers = null;
var hidden_categories = null;
var list_container = null;
function _GET(param) {
var vars = {};
window.location.href.replace( location.hash, '' ).replace(
/[?&]+([^=&]+)=?([^&]*)?/gi, // regexp
function( m, key, value ) { // callback
vars[key] = value !== undefined ? value : '';
}
);
if ( param ) {
return vars[param] ? vars[param] : null;
}
return vars;
}
function update_partner_list() {
//TODO : store id and state in categories instead of hidden_categories
//It could avoid to make a part of code below
$('.wospml_cat_choice').each(function(i,e){
var state = $(e).data('state') || 'on';
var catid = $(e).data('catid');
if (state == 'off') {
$('.wosmpl_categ[data-catid="'+catid+'"]').hide();
} else {
$('.wosmpl_categ[data-catid="'+catid+'"]').show();
}
});
}
function wosmpl_get_hidden_cats(callback){
var cats = [];
$('.wospml_cat_choice').each(function(i,e){
var state = $(e).data('state') || 'on';
if (state == 'off') {
cats.push($(e).data('catid'));
}
});
callback(cats);
}
function filter_category(){
//.wosmpl_map_cat_filter .wospml_cat_choice img {filter: grayscale(100%);}
var clicked = $(this);
var state = clicked.data('state') || 'on';
var catid = clicked.data('catid');
if (catid != 0){
clicked.siblings('div').data('state','off');
clicked.siblings('div').css('filter','grayscale(100%)');
}
if (state == 'off') {
clicked.data('state','on');
clicked.css('filter','grayscale(0%)');
if (catid == 0) {
clicked.siblings('div').data('state','on');
clicked.siblings('div').css('filter','grayscale(0%)');
}
}
fill_map();
}
function onEachFeature(feature, layer) {
// does this feature have a property named popupContent?
if (feature.properties && feature.properties.popupContent) {
layer.bindPopup(feature.properties.popupContent);
}
}
function get_cat_icon_url(cat) {
return cat_icon_path + cat_icon_name_prefix + cat + '.png';
}
function wosmpl_is_feature_to_be_shown(feature) {
var answer = true;
var fcat = feature.properties.cat || '';
if (hidden_categories && hidden_categories.length > 0) {
for (var i=0;i<hidden_categories.length;i++) {
if (hidden_categories[i] == fcat) {
answer = false;
}
}
}
return answer;
}
function wosmpl_point_to_layer(feature, latlng) {
//console.log(get_icon_url(feature))
if (wosmpl_is_feature_to_be_shown(feature) == true) {
var icon = L.icon({
iconSize: [50, 50],
iconAnchor: [50,25],
className: 'wosmpl-icon',
iconUrl : get_cat_icon_url(feature.properties.cat || '')
});
return L.marker(latlng, {icon: icon});
}
}
function fill_layer(hidden_cats) {
hidden_categories = hidden_cats;
geojson_layer = L.geoJSON(top.contents_to_show, {
pointToLayer: wosmpl_point_to_layer,
onEachFeature: onEachFeature
});
markers = L.markerClusterGroup({maxClusterRadius: 1});
// geojson_layer.addTo(map);
markers.addLayer(geojson_layer);
map.addLayer(markers);
set_contents_polygon(function(){
map.fitBounds(contents_polygon.getBounds());
});
update_partner_list();
}
function fill_map() {
if (markers) {
map.removeLayer(markers);
}
wosmpl_get_hidden_cats(fill_layer);
}
function set_contents_polygon(callback) {
var points = [];
$.each(top.contents_to_show, function(i,e) {
if (e.geometry) {
if(wosmpl_is_feature_to_be_shown(e)) {
var lnglat = e.geometry.coordinates;
points.push([lnglat[1], lnglat[0]]);
}
}
});
if (points.length > 0) {
contents_polygon = L.polygon(points);
map_center = contents_polygon.getBounds().getCenter();
}
if (callback)
callback();
}
function init_map() {
var center = map_center || [43.611379, 3.875849];
map = L.map('wosmpl-map').setView(center, 13);
map.scrollWheelZoom.disable();
// create the tile layer with correct attribution
var osmUrl='https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png';
var osmAttrib='Map data © <a href="http://openstreetmap.org">OpenStreetMap</a> contributors';
var osm = new L.TileLayer(osmUrl, {minZoom: 9, maxZoom: 19, attribution: osmAttrib});
map.addLayer(osm);
var southWest = L.latLng(43.2022, 2.5887),
northEast = L.latLng(43.9562, 4.2586);
var bounds = L.latLngBounds(southWest, northEast);
map.setMaxBounds(bounds);
fill_map();
}
$( window ).load(function() {
if (top.contents_to_show) {
// As shorcode doesn't produce div with a map id, we need do choose the first one to be the unique map div
var map_divs = $('div.wosmpl-box.map');
if (map_divs.length > 0) {
var map_content_div = map_divs.first();
map_content_div.attr('id','wosmpl-map');
if(map_size_ref) {
var width = $(map_size_ref).css('max-width')
|| $(map_size_ref).css('width');
var num_width = width.replace('px','').replace('%','');
if(isNaN(num_width)){
num_width = $(map_size_ref).innerWidth();
if (!isNaN(num_width)) {
width = num_width + 'px';
}
}
if (num_width / 640 < 0.8) {
map_content_div.css('height', width);
}
map_content_div.css('width', width);
}
init_map();
list_container = $('div.wosmpl-box.partner_list');
$('.wospml_cat_choice').click(filter_category);
}
}
});
})( jQuery );
# How to contribute
- [Getting help](#getting-help)
- [Submitting bug reports](#submitting-bug-reports)
- [Contributing code](#contributing-code)
## Getting help
Community discussion, questions, and informal bug reporting is done on the
[dompdf Google group](http://groups.google.com/group/dompdf). You may also
seek help on
[StackOverflow](http://stackoverflow.com/questions/tagged/dompdf).
## Submitting bug reports
The preferred way to report bugs is to use the
[GitHub issue tracker](http://github.com/dompdf/dompdf/issues). Before
reporting a bug, read these pointers.
**Please search inside the bug tracker to see if the bug you found is not already reported.**
**Note:** The issue tracker is for *bugs* and *feature requests*, not requests for help.
Questions should be asked on the
[dompdf Google group](http://groups.google.com/group/dompdf) instead.
### Reporting bugs effectively
- dompdf is maintained by volunteers. They don't owe you anything, so be
polite. Reports with an indignant or belligerent tone tend to be moved to the
bottom of the pile.
- Include information about **the PHP version on which the problem occurred**. Even
if you tested several PHP version on different servers, and the problem occurred
in all of them, mention this fact in the bug report.
Also include the operating system it's installed on. PHP configuration can also help,
and server error logs (like Apache logs)
- Mention which release of dompdf you're using (the zip, the master branch, etc).
Preferably, try also with the current development snapshot, to ensure the
problem has not already been fixed.
- Mention very precisely what went wrong. "X is broken" is not a good bug
report. What did you expect to happen? What happened instead? Describe the
exact steps a maintainer has to take to make the problem occur. We can not
fix something that we can not observe.
- If the problem can not be reproduced in any of the demos included in the
dompdf distribution, please provide an HTML document that demonstrates
the problem. There are a few options to show us your code:
- [JS Fiddle](http://jsfiddle.net/)
- [dompdf debug helper](http://eclecticgeek.com/dompdf/debug.php) (provided by @bsweeney)
- Include the HTML/CSS inside the bug report, with
[code highlighting](https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet#wiki-code).
## Contributing code
- Make sure you have a [GitHub Account](https://github.com/signup/free)
- Fork [dompdf](https://github.com/dompdf/dompdf/)
([how to fork a repo](https://help.github.com/articles/fork-a-repo))
- *Make your changes on the dev branch* or the most appropriate feature branch. Please only patch
the master branch if you are attempting to address an urgent bug in the released code.
- Add a simple test file in `www/test/`, with a comprehensive name.
- Add a unit test in the ``test/Dompdf/Tests/`` directory.
- Submit a pull request
([how to create a pull request](https://help.github.com/articles/fork-a-repo))
Dompdf
======
[![Build Status](https://travis-ci.org/dompdf/dompdf.png?branch=master)](https://travis-ci.org/dompdf/dompdf)
[![Latest Stable Version](https://poser.pugx.org/dompdf/dompdf/v/stable.png)](https://packagist.org/packages/dompdf/dompdf)
[![Total Downloads](https://poser.pugx.org/dompdf/dompdf/downloads.png)](https://packagist.org/packages/dompdf/dompdf)
[![Latest Unstable Version](https://poser.pugx.org/dompdf/dompdf/v/unstable.png)](https://packagist.org/packages/dompdf/dompdf)
[![License](https://poser.pugx.org/dompdf/dompdf/license.png)](https://packagist.org/packages/dompdf/dompdf)
**Dompdf is an HTML to PDF converter**
At its heart, dompdf is (mostly) a [CSS 2.1](http://www.w3.org/TR/CSS2/) compliant
HTML layout and rendering engine written in PHP. It is a style-driven renderer:
it will download and read external stylesheets, inline style tags, and the style
attributes of individual HTML elements. It also supports most presentational
HTML attributes.
*This document applies to the latest stable code which may not reflect the current
release. For released code please
[navigate to the appropriate tag](https://github.com/dompdf/dompdf/tags).*
----
**Check out the [demo](https://dompdf.net/examples.php) and ask any
question on [StackOverflow](http://stackoverflow.com/questions/tagged/dompdf) or
on the [Google Groups](http://groups.google.com/group/dompdf).**
Follow us on [![Twitter](http://twitter-badges.s3.amazonaws.com/twitter-a.png)](http://www.twitter.com/dompdf) or
[![Follow us on Google+](https://ssl.gstatic.com/images/icons/gplus-16.png)](https://plus.google.com/108710008521858993320?prsrc=3).
---
## Features
* Handles most CSS 2.1 and a few CSS3 properties, including @import, @media &
@page rules
* Supports most presentational HTML 4.0 attributes
* Supports external stylesheets, either local or through http/ftp (via
fopen-wrappers)
* Supports complex tables, including row & column spans, separate & collapsed
border models, individual cell styling
* Image support (gif, png (8, 24 and 32 bit with alpha channel), bmp & jpeg)
* No dependencies on external PDF libraries, thanks to the R&OS PDF class
* Inline PHP support
* Basic SVG support
## Requirements
* PHP version 5.3.0 or higher
* DOM extension
* GD extension
* MBString extension
* php-font-lib
* php-svg-lib
### Recommendations
* OPcache (OPcache, XCache, APC, etc.): improves performance
* IMagick or GMagick extension: improves image processing performance
Visit the wiki for more information:
https://github.com/dompdf/dompdf/wiki/Requirements
## About Fonts & Character Encoding
PDF documents internally support the following fonts: Helvetica, Times-Roman,
Courier, Zapf-Dingbats, & Symbol. These fonts only support Windows ANSI
encoding. In order for a PDF to display characters that are not available in
Windows ANSI you must supply an external font. Dompdf will embed any referenced
font in the PDF so long as it has been pre-loaded or is accessible to dompdf and
reference in CSS @font-face rules. See the
[font overview](https://github.com/dompdf/dompdf/wiki/About-Fonts-and-Character-Encoding)
for more information on how to use fonts.
The [DejaVu TrueType fonts](http://dejavu-fonts.org) have been pre-installed
to give dompdf decent Unicode character coverage by default. To use the DejaVu
fonts reference the font in your stylesheet, e.g. `body { font-family: DejaVu
Sans; }` (for DejaVu Sans). The following DejaVu 2.34 fonts are available:
DejaVu Sans, DejaVu Serif, and DejaVu Sans Mono.
## Easy Installation
### Install with composer
To install with [Composer](https://getcomposer.org/), simply require the
latest version of this package.
```bash
composer require dompdf/dompdf
```
Make sure that the autoload file from Composer is loaded.
```php
// somewhere early in your project's loading, require the Composer autoloader
// see: http://getcomposer.org/doc/00-intro.md
require 'vendor/autoload.php';
```
### Download and install
Download an archive of dompdf and extract it into the directory where dompdf
will reside
* You can download stable copies of dompdf from
https://github.com/dompdf/dompdf/releases
* Or download a nightly (the latest, unreleased code) from
http://eclecticgeek.com/dompdf
Require dompdf, libraries, and helper functions in your PHP:
```php
// include autoloader
require_once 'dompdf/autoload.inc.php';
```
### Install with git
From the command line, switch to the directory where dompdf will reside and run
the following commands:
```sh
git clone https://github.com/dompdf/dompdf.git
cd dompdf
git clone https://github.com/PhenX/php-font-lib.git lib/php-font-lib
cd lib/php-font-lib
git checkout 0.4
cd ..
git clone https://github.com/PhenX/php-svg-lib.git php-svg-lib
cd php-svg-lib
git checkout v0.1
```
Require dompdf, libraries, and helper functions in your PHP:
```php
// include autoloader
require_once 'dompdf/autoload.inc.php';
```
## Quick Start
Just pass your HTML in to dompdf and stream the output:
```php
// reference the Dompdf namespace
use Dompdf\Dompdf;
// instantiate and use the dompdf class
$dompdf = new Dompdf();
$dompdf->loadHtml('hello world');
// (Optional) Setup the paper size and orientation
$dompdf->setPaper('A4', 'landscape');
// Render the HTML as PDF
$dompdf->render();
// Output the generated PDF to Browser
$dompdf->stream();
```
### Setting Options
Set options during dompdf instantiation:
```php
use Dompdf\Dompdf;
use Dompdf\Options;
$options = new Options();
$options->set('defaultFont', 'Courier');
$dompdf = new Dompdf($options);
```
or at run time
```php
use Dompdf\Dompdf;
$dompdf = new Dompdf();
$dompdf->set_option('defaultFont', 'Courier');
```
See [Dompdf\Options](src/Options.php) for a list of available options.
## Limitations (Known Issues)
* Dompdf is not particularly tolerant to poorly-formed HTML input. To avoid
any unexpected rendering issues you should either enable the built-in HTML5
parser at runtime (`$dompdf->set_option('isHtml5ParserEnabled', true);`)
or run your HTML through a HTML validator/cleaner (such as
[Tidy](http://tidy.sourceforge.net) or the
[W3C Markup Validation Service](http://validator.w3.org)).
* Large files or large tables can take a while to render.
* CSS float is in development and may not produce the desired result
---
[![Donate button](https://www.paypal.com/en_US/i/btn/btn_donate_SM.gif)](http://goo.gl/DSvWf)
*If you find this project useful, please consider making a donation. Any funds donated will be used to help further development on this project.)*
<9ea852c4>
\ No newline at end of file
<?php
/**
* @package dompdf
* @link http://dompdf.github.com/
* @author Benj Carson <benjcarson@digitaljunkies.ca>
* @author Fabien Ménager <fabien.menager@gmail.com>
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
*/
/**
* Dompdf autoload function
*
* If you have an existing autoload function, add a call to this function
* from your existing __autoload() implementation.
*
* @param string $class
*/
require_once __DIR__ . '/lib/html5lib/Parser.php';
// require_once __DIR__ . '/lib/php-font-lib/src/FontLib/Autoloader.php';
// require_once __DIR__ . '/lib/php-svg-lib/src/autoload.php';
/*
* New PHP 5.3.0 namespaced autoloader
*/
require_once __DIR__ . '/src/Autoloader.php';
Dompdf\Autoloader::register();
{
"name": "dompdf/dompdf",
"type": "library",
"description": "DOMPDF is a CSS 2.1 compliant HTML to PDF converter",
"homepage": "https://github.com/dompdf/dompdf",
"license": "LGPL-2.1",
"authors": [
{
"name": "Fabien Ménager",
"email": "fabien.menager@gmail.com"
},
{
"name": "Brian Sweeney",
"email": "eclecticgeek@gmail.com"
},
{
"name": "Gabriel Bull",
"email": "me@gabrielbull.com"
}
],
"autoload": {
"psr-4" : {
"Dompdf\\" : "src/"
},
"classmap" : ["lib/"]
},
"require": {
"php": ">=5.3.0",
"ext-gd": "*",
"ext-dom": "*",
"ext-mbstring": "*",
"phenx/php-font-lib": "0.5.*",
"phenx/php-svg-lib": "0.3.*"
},
"require-dev": {
"phpunit/phpunit": "4.8.*",
"squizlabs/php_codesniffer": "2.*"
},
"extra": {
"branch-alias": {
"dev-develop": "0.7-dev"
}
}
}
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment