WSP-41
This commit is contained in:
@@ -48,6 +48,7 @@ function superdesk_admin() {
|
||||
'slugline-separator' => $_POST['slugline-separator'],
|
||||
'slugline-ignored' => $_POST['slugline-ignored'],
|
||||
'priority_threshhold' => $_POST['priority_threshhold'],
|
||||
'download-images' => $_POST['download-images'],
|
||||
);
|
||||
update_option('superdesk_settings', $settings);
|
||||
} else if (get_option('superdesk_settings')) {
|
||||
@@ -76,6 +77,7 @@ function superdesk_admin() {
|
||||
'slugline-separator' => '',
|
||||
'slugline-ignored' => '',
|
||||
'priority_threshhold' => '',
|
||||
'download-images' => '',
|
||||
);
|
||||
}
|
||||
$statuses = array(
|
||||
@@ -464,6 +466,30 @@ function superdesk_admin() {
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">
|
||||
Download images from SD
|
||||
</th>
|
||||
<td>
|
||||
<fieldset>
|
||||
<label for="download-images-off">
|
||||
<input type="radio" name="download-images" id="download-images-off" value="off"<?php
|
||||
if ($settings['download-images'] == 'off') {
|
||||
echo(' checked');
|
||||
}
|
||||
?>> off
|
||||
</label>
|
||||
<br>
|
||||
<label for="download-images-on">
|
||||
<input type="radio" name="download-images" id="download-images-on" value="on"<?php
|
||||
if ($settings['download-images'] == 'on') {
|
||||
echo(' checked');
|
||||
}
|
||||
?>> on
|
||||
</label>
|
||||
</fieldset>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<p class="submit">
|
||||
|
||||
@@ -121,6 +121,10 @@ if ($obj['type'] == 'text') {
|
||||
$author_id = 0;
|
||||
}
|
||||
|
||||
if ($settings['download-images'] && $settings['download-images'] == 'on') {
|
||||
$content = embed_images($content);
|
||||
}
|
||||
|
||||
$sync = $wpdb->get_row("SELECT post_id FROM " . $wpdb->prefix . DB_TABLE_SYNC_POST . " WHERE guid = '" . $guid . "'");
|
||||
|
||||
if ($sync) {
|
||||
|
||||
@@ -148,6 +148,53 @@ function generate_caption_image($media) {
|
||||
return $caption;
|
||||
}
|
||||
|
||||
function embed_src($src) {
|
||||
$filename = sha1($src);
|
||||
|
||||
saveFile($src, wp_upload_dir()['path'] . "/" . $filename);
|
||||
return wp_upload_dir()['url'] . "/" . $filename;
|
||||
}
|
||||
|
||||
function embed_images($html) {
|
||||
$result = array();
|
||||
preg_match_all('/<img[^>]+>/i', $html, $result);
|
||||
if (count($result) > 0) {
|
||||
$img = array();
|
||||
foreach ($result as $row) {
|
||||
if (count($row) > 0) {
|
||||
foreach ($row as $img_tag) {
|
||||
preg_match_all('/(src|title|alt)=("[^"]*")/i', $img_tag, $img[$img_tag]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (count($img) > 0) {
|
||||
foreach ($img as $htmlTag => $src) {
|
||||
$attrs = array();
|
||||
if (isset($src[1], $src[2])) {
|
||||
foreach ($src[1] as $key => $attr) {
|
||||
$value = $src[2][$key];
|
||||
if ($attr === "src") {
|
||||
$value = mb_substr($value, 1, mb_strlen($value) - 2);
|
||||
$value = '"' . embed_src($value) . '"';
|
||||
}
|
||||
|
||||
$attrs[$attr] = $value;
|
||||
}
|
||||
$newHtmlTag = "<img";
|
||||
foreach ($attrs as $attrName => $attrValue) {
|
||||
$newHtmlTag .= " " . $attrName . "=" . $attrValue;
|
||||
}
|
||||
$newHtmlTag .= ">";
|
||||
$html = str_replace($htmlTag, $newHtmlTag, $html);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
add_filter('wp_kses_allowed_html', 'custom_wpkses_post_tags', 10, 2);
|
||||
|
||||
wp_oembed_add_provider('#http://(www\.)?youtube\.com/watch.*#i', 'http://www.youtube.com/oembed', true);
|
||||
|
||||
Reference in New Issue
Block a user