0
if (!Visitor::current()->group()->can("add_post"))
0
show_403(__("Access Denied"), __("You do not have sufficient privileges to import content."));
0
- foreach (array("success_wordpress",
0
+ foreach (array("success_chyrp",
0
- "invalid_chyrp_pages") as $message)
0
+ "invalid_chyrp_pages",
0
+ "invalid_tumblr") as $message)
0
$this->context[$message] = isset($_GET[$message]);
0
public function import_chyrp() {
0
- $trigger = Trigger::current();
0
+ redirect("/admin/?action=import");
0
+ if (!Visitor::current()->group()->can("add_post"))
0
+ show_403(__("Access Denied"), __("You do not have sufficient privileges to import content."));
0
- if (isset($_FILES['posts_file']) and $_FILES['posts_file']['error'] == 0) {
0
- $posts = simplexml_load_file($_FILES['posts_file']['tmp_name']);
0
+ $trigger = Trigger::current();
0
- if (!$posts or $posts->generator != "Chyrp")
0
+ if (isset($_FILES['posts_file']) and $_FILES['posts_file']['error'] == 0)
0
+ if (!$posts = simplexml_load_file($_FILES['posts_file']['tmp_name']) or $posts->generator != "Chyrp")
0
redirect("/admin/?action=import&invalid_chyrp_posts");
0
- if (isset($_FILES['pages_file']) and $_FILES['pages_file']['error'] == 0) {
0
- $pages = simplexml_load_string(file_get_contents($_FILES['pages_file']['tmp_name']));
0
- if (!$pages or $pages->generator != "Chyrp")
0
+ if (isset($_FILES['pages_file']) and $_FILES['pages_file']['error'] == 0)
0
+ if (!$pages = simplexml_load_file($_FILES['pages_file']['tmp_name']) or $pages->generator != "Chyrp")
0
redirect("/admin/?action=import&invalid_chyrp_pages");
0
+ if (ini_get("memory_limit") < 20)
0
+ ini_set("memory_limit", "20M");
0
if (isset($_FILES['posts_file']) and $_FILES['posts_file']['error'] == 0)
0
foreach ($posts->entry as $entry) {
0
public function import_wordpress() {
0
- $trigger = Trigger::current();
0
- $config = Config::current();
0
redirect("/admin/?action=import");
0
+ if (!Visitor::current()->group()->can("add_post"))
0
+ show_403(__("Access Denied"), __("You do not have sufficient privileges to import content."));
0
+ $config = Config::current();
0
if (!in_array("text", $config->enabled_feathers))
0
error(__("Missing Feather"), __("Importing from WordPress requires the Text feather to be installed and enabled."));
0
- if (ini_get("memory_limit") < 20)
# Some imports are relatively large.0
+ if (ini_get("memory_limit") < 20)
0
ini_set("memory_limit", "20M");
0
+ $trigger = Trigger::current();
0
$stupid_xml = file_get_contents($_FILES['xml_file']['tmp_name']);
0
$sane_xml = preg_replace(array("/<wp:comment_content>/", "/<\/wp:comment_content>/"),
0
array("<wp:comment_content><![CDATA[", "]]></wp:comment_content>"),
0
+ * Function: import_tumblr
0
+ public function import_tumblr() {
0
+ redirect("/admin/?action=import");
0
+ if (!Visitor::current()->group()->can("add_post"))
0
+ show_403(__("Access Denied"), __("You do not have sufficient privileges to import content."));
0
+ $config = Config::current();
0
+ if (!in_array("text", $config->enabled_feathers) or
0
+ !in_array("video", $config->enabled_feathers) or
0
+ !in_array("audio", $config->enabled_feathers) or
0
+ !in_array("chat", $config->enabled_feathers) or
0
+ !in_array("photo", $config->enabled_feathers) or
0
+ !in_array("quote", $config->enabled_feathers) or
0
+ !in_array("link", $config->enabled_feathers))
0
+ error(__("Missing Feather"), __("Importing from Tumblr requires the Text, Video, Audio, Chat, Photo, Quote, and Link feathers to be installed and enabled."));
0
+ if (ini_get("memory_limit") < 20)
0
+ ini_set("memory_limit", "20M");
0
+ if (!parse_url($_POST['tumblr_url'], PHP_URL_SCHEME))
0
+ $_POST['tumblr_url'] = "http://".$_POST['tumblr_url'];
0
+ $url = rtrim($_POST['tumblr_url'], "/")."/api/read?num=50";
0
+ $api = preg_replace("/<(\/?)([^\-]+)\-([^ >]+)/", "<\\1\\2_\\3", get_remote($url));
0
+ $api = preg_replace("/ ([a-z]+)\-([a-z]+)=/", " \\1_\\2=", $api);
0
+ $xml = simplexml_load_string($api);
0
+ if (!isset($xml->tumblelog))
0
+ redirect("/admin/?action=import&invalid_tumblr");
0
+ $already_in = $posts = array();
0
+ foreach ($xml->posts->post as $post) {
0
+ $already_in[] = $post->attributes()->id;
0
+ while ($xml->posts->attributes()->total > count($posts)) {
0
+ $api = preg_replace("/<(\/?)([a-z]+)\-([a-z]+)/", "<\\1\\2_\\3", get_remote($url."&start=".count($posts)));
0
+ $api = preg_replace("/ ([a-z]+)\-([a-z]+)=/", " \\1_\\2=", $api);
0
+ $xml = simplexml_load_string($api, "SimpleXMLElement", LIBXML_NOCDATA);
0
+ foreach ($xml->posts->post as $post)
0
+ if (!in_array($post->attributes()->id, $already_in)) {
0
+ $already_in[] = $post->attributes()->id;
0
+ function reverse($a, $b) {
0
+ if (empty($a) or empty($b)) return 0;
0
+ return (strtotime($a->attributes()->date) < strtotime($b->attributes()->date)) ? -1 : 1 ;
0
+ usort($posts, "reverse");
0
+ foreach ($posts as $key => $post) {
0
+ if ($post->attributes()->type == "audio")
0
+ continue; # Can't import Audio posts since Tumblr has the files locked in to Amazon.
0
+ $translate_types = array("regular" => "text", "conversation" => "chat");
0
+ switch($post->attributes()->type) {
0
+ $title = fallback($post->regular_title);
0
+ $values = array("title" => $title,
0
+ "body" => $post->regular_body);
0
+ $clean = sanitize($title);
0
+ $values = array("embed" => $post->video_player,
0
+ "caption" => fallback($post->video_caption));
0
+ $title = fallback($post->conversation_title);
0
+ foreach ($post->conversation_line as $line)
0
+ $lines[] = $line->attributes()->label." ".$line;
0
+ $values = array("title" => $title,
0
+ "dialogue" => implode("\n", $lines));
0
+ $clean = sanitize($title);
0
+ $values = array("filename" => upload_from_url($post->photo_url[0]),
0
+ "caption" => fallback($post->photo_caption));
0
+ $values = array("quote" => $post->quote_text,
0
+ "source" => preg_replace("/^— /", "",
0
+ fallback($post->quote_source)));
0
+ $name = fallback($post->link_text);
0
+ $values = array("name" => $name,
0
+ "source" => $post->link_url,
0
+ "description" => fallback($post->link_description));
0
+ $clean = sanitize($name);
0
+ $_POST['status'] = "public";
0
+ $_POST['pinned'] = false;
0
+ $_POST['created_at'] = datetime((int) $post->attributes()->unix_timestamp);
0
+ $_POST['feather'] = str_replace(array_keys($translate_types),
0
+ array_values($translate_types),
0
+ $post->attributes()->type);
0
+ $new_post = Post::add($values, $clean, Post::check_url($clean));
0
+ Trigger::current()->call("import_tumble", $post, $new_post);
0
+ redirect("/admin/?action=import&success_tumblr");
0
* Function: extend_modules
0
* Module enabling/disabling.
0
if (file_exists(MODULES_DIR."/".$folder."/locale/".$config->locale.".mo"))
0
load_translator($folder, MODULES_DIR."/".$folder."/locale/".$config->locale.".mo");
0
- $info =
Spyc::YAMLLoad(MODULES_DIR."/".$folder."/info.yaml");
0
+ $info =
Horde_Yaml::loadFile(MODULES_DIR."/".$folder."/info.yaml");