This repository has been archived by the owner on Feb 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplugin.php
65 lines (52 loc) · 1.83 KB
/
plugin.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
57
58
59
60
61
62
63
64
65
<?php
/*
Plugin Name: Flickr to Wordpress custom templates
Version: 0.1
Description: Lets you customize layout of photo posts shared from Flickr and make it a draft post.
Plugin URI: http://github.com/z4y4ts/flickr2wp-custom-templates/
Author: Alexander Zayats
Author URI: http://zayats.org.ua/
License: GPL
*/
function call_python_subprocess($input) {
$descriptorspec = array(
0 => array("pipe", "r"), // stdin is a pipe that the child will read from
1 => array("pipe", "w"), // stdout is a pipe that the child will write to
2 => array("file", "/tmp/error-output.txt", "a") // stderr is a file to write to
);
$cwd = plugin_dir_path(__FILE__);
// $env = array('some_option' => 'aeiou');
$process = proc_open('python flickr2wp_worker.py', $descriptorspec, $pipes, $cwd);
if (!is_resource($process)) {
return $input;
}
// $pipes now looks like this:
// 0 => writeable handle connected to child stdin
// 1 => readable handle connected to child stdout
// Any error output will be appended to /tmp/error-output.txt
fwrite($pipes[0], $input);
fclose($pipes[0]);
$output = stream_get_contents($pipes[1]);
fclose($pipes[1]);
// It is important that you close any pipes before calling
// proc_close in order to avoid a deadlock
proc_close($process);
return $output;
}
function flickr_custom_layout($post_body) {
if ($_SERVER['HTTP_USER_AGENT'] != 'Flickr') {
return $post_body;
}
$processed_body = call_python_subprocess($post_body);
return $processed_body;
}
function flickr_draft_post( $post_status ) {
if($_SERVER['HTTP_USER_AGENT'] == 'Flickr') {
return 'draft';
} else {
return $post_status;
}
}
add_filter('status_save_pre', 'flickr_draft_post');
add_filter('content_save_pre', 'flickr_custom_layout');
?>