-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmarkdown-importer.php
56 lines (48 loc) · 1.65 KB
/
markdown-importer.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
/**
* Plugin name: Markdown importer
* Plugin URI:
* Description: Importing posts from markdown files.
* Version: 0.3.1
* Author: inc2734
* Author URI: https://2inc.org
* Created: July 19, 2016
* Modified: June 22, 2018
* Text Domain: markdown-importer
* Domain Path: /languages
* License: GPLv2 or later
* License URI: http://www.gnu.org/licenses/gpl-2.0.html
*/
class Markdown_Importer {
public static $map;
public function __construct() {
add_action( 'plugins_loaded', array( $this, 'plugins_loaded' ) );
}
public function plugins_loaded() {
require_once plugin_dir_path( __FILE__ ) . 'classes/controllers/admin.php';
require_once plugin_dir_path( __FILE__ ) . 'classes/models/import.php';
require_once plugin_dir_path( __FILE__ ) . 'classes/models/converting-image.php';
require_once plugin_dir_path( __FILE__ ) . 'classes/models/unicode-normalization.php';
new Markdown_Importer_Admin_Controller();
}
/**
* When filename has non half-width character, filename converted with sha1.
*
* @param string $filename
* @param int $post_id
* @return string
*/
public static function generate_normalization_filename( $filename, $post_id = null ) {
$pathinfo = pathinfo( $filename );
$Unicode_Normalization = new Markdown_Importer_Unicode_Normalization( basename( $filename ) );
$filename = $Unicode_Normalization->convert();
if ( ! preg_match( '/^[a-zA-Z0-9_-]+\.' . $pathinfo['extension'] . '$/', $filename ) ) {
$filename = sha1( $filename ) . '.' . $pathinfo['extension'];
}
if ( $post_id ) {
$filename = $post_id . '-' . $filename;
}
return $filename;
}
}
new Markdown_Importer();