PluginProbe
Markup Markdown / 3.9.0
Markup Markdown v3.9.0
4.0.2 4.0.1 3.14.1 3.14.2 3.14.3 3.14.4 3.14.5 3.14.6 3.14.7 3.15.0 3.15.1 3.15.2 3.16.0 3.17.0 3.17.1 3.18.0 3.18.1 3.18.2 3.19.0 3.19.1 3.20.0 3.20.1 3.20.10 3.20.11 3.20.12 All 61 releases
markup-markdown / markup-markdown.php

markup-markdown.php in Markup Markdown 3.9.0, at markup-markdown.php

180 lines 4.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Markup Markdown
4 *
5 * Plugin Name: Markup Markdown
6 * Description: Replaces the Gutenberg Block Editor in favor of pure markdown based markups
7 * Version: 3.9.0
8 * Author: Pierre-Henri Lavigne
9 * Author URI: https://www.markup-markdown.com
10 * License: GPLv2 or later
11 * License URI: http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
12 * Text Domain: markup-markdown
13 * Domain Path: /languages
14 * Requires at least: 4.9
15 * Tested up to: 6.6.2
16 *
17 * This program is free software; you can redistribute it and/or modify it under the terms of the GNU
18 * General Public License version 2, as published by the Free Software Foundation. You may NOT assume
19 * that you can use any other version of the GPL.
20 *
21 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
22 * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
23 */
24
25 defined( 'ABSPATH' ) || exit;
26 define('MMD_FILE_URL', __FILE__);
27
28 if ( ! class_exists( 'Markup_Markdown' ) ) :
29
30 class Markup_Markdown {
31
32 protected $parser;
33
34 protected $settings = array(
35 'version' => '3.9.0',
36 'plugin_uri' => '',
37 'plugin_dir' => '',
38 'plugin_slug' => '',
39 'cache_dir' => '',
40 'conf_dir' => '',
41 'curr_blog' => '1_1',
42 'default_conf' => array()
43 );
44
45
46 public function __construct() {
47 $this->settings[ 'plugin_slug' ] = plugin_basename( __DIR__ );
48 $this->settings[ 'plugin_uri' ] = plugin_dir_url( __FILE__ );
49 $this->settings[ 'plugin_dir' ] = plugin_dir_path( __FILE__ );
50 $this->settings[ 'cache_dir' ] = WP_CONTENT_DIR . '/mmd-cache';
51 $this->settings[ 'conf_dir' ] = WP_CONTENT_DIR . '/mmd-conf';
52 $this->settings[ 'cache_blog_prefix' ] = WP_CONTENT_DIR . '/mmd-cache/' . get_current_network_id() . '_' . get_current_blog_id() . '_';
53 $this->settings[ 'conf_blog_prefix' ] = WP_CONTENT_DIR . '/mmd-conf/' . get_current_network_id() . '_' . get_current_blog_id() . '_';
54 require_once $this->settings[ 'plugin_dir' ] . '/MarkupMarkdown/Core/Activation.php';
55 }
56
57
58 /**
59 * Overloading method __get
60 *
61 * @since 2.0.0
62 * @access public
63 *
64 * @param String $name The name of the key in the $settings variable to retrieve
65 * @return Mixed The value of the related key in $settings or an empty string
66 */
67 public function __get( $name ) {
68 return isset( $this->settings[ $name ] ) ? $this->settings[ $name ] : '';
69 }
70
71
72 /**
73 * Overloading method __set
74 *
75 * @since 2.0.0
76 * @access public
77 *
78 * @param String $name The name of the key in the $settings variable to overwrite
79 * @param Mixed $val The new value of the related key in the $settings variable
80 * @return Void
81 */
82 public function __set( $name, $val ) {
83 if ( isset( $this->settings[ $name ] ) && is_array( $this->settings[ $name ] ) && is_array( $val ) ) :
84 $this->settings[ $name ] = array_merge( $this->settings[ $name ], $val );
85 else :
86 $fixed = array( 'plugin_uri', 'plugin_dir', 'plugin_slug', 'cache_dir', 'conf_dir', 'curr_blog', 'default_conf' );
87 if ( ! in_array( $name, $fixed ) ) :
88 $this->settings[ $name ] = $val;
89 endif;
90 endif;
91 }
92
93
94 /**
95 * @since 1.0
96 * @access public
97 *
98 * @param String $content The markdown code
99 *
100 * @return String The HTML content
101 */
102 public function markdown2html( $content ) {
103 $filtered = apply_filters( 'field_markdown2html', $content );
104 $html = htmlspecialchars_decode( $filtered, ENT_COMPAT );
105 return do_shortcode( $html );
106 }
107
108
109 /**
110 * @since 3.0
111 * @access public
112 *
113 * @param $file String Target file
114 *
115 * @return Void
116 */
117 public function clear_cache( $file = '' ) {
118 if ( function_exists( 'wp_opcache_invalidate' ) ) :
119 wp_opcache_invalidate( $file );
120 elseif ( function_exists( 'opcache_invalidate' ) ) :
121 opcache_invalidate( $file );
122 endif;
123 }
124
125
126 /**
127 * Tiny function to filter user permissions
128 *
129 * @since 3.3.0
130 * @access public
131 *
132 * @param Boolean TRUE to grant access user with enough premission
133 *
134 * @return Boolean TRUE if granted or FALSE
135 */
136 public function user_allowed( $user_id = 0 ) {
137 if ( ! $user_id ) :
138 $user_id = get_current_user_id();
139 endif;
140 if ( ! $user_id ) :
141 # Disable *Guest* users
142 return false;
143 endif;
144 $user = new \WP_User( $user_id );
145 if ( $user && ! $user->has_cap( 'edit_posts' ) ) :
146 # Disable *Subscribers* or users without edit permissions
147 return false;
148 endif;
149 return true;
150 }
151
152 }
153
154
155 // Allow developers to access our properties and methods of the instance
156 final class Markup_Markdown_Instance {
157
158 private static $instance;
159
160 public static function instance() {
161 if ( ! isset( self::$instance ) && ! ( self::$instance instanceOf Markup_Markdown_Instance ) ) :
162 self::$instance = new Markup_Markdown();
163 endif;
164 return self::$instance;
165 }
166
167 }
168
169
170 if ( ! function_exists( 'mmd' ) ) :
171 function mmd() {
172 return Markup_Markdown_Instance::instance();
173 }
174 // Run
175 mmd();
176 endif;
177
178
179 endif;
180