public function submit() { if (empty($_POST['quote'])) { error(__("Error"), __("Quote can't be empty.", "quote")); } return Post::add(array("quote" => $_POST['quote'], "source" => $_POST['source']), $_POST['slug'], Post::check_url($_POST['slug'])); }
public function submit() { if (empty($_POST['video'])) { error(__("Error"), __("Video can't be blank.")); } return Post::add(array("embed" => $this->embed_tag($_POST['video']), "video" => $_POST['video'], "caption" => $_POST['caption']), $_POST['slug'], Post::check_url($_POST['slug'])); }
public function submit() { if (empty($_POST['body'])) { error(__("Error"), __("Body can't be blank.")); } fallback($_POST['slug'], sanitize($_POST['title'])); return Post::add(array("title" => $_POST['title'], "body" => $_POST['body']), $_POST['slug'], Post::check_url($_POST['slug'])); }
public function main_index($main) { $config = Config::current(); if ($config->disable_aggregation or time() - $config->last_aggregation < $config->aggregate_every * 60) { return; } $aggregates = (array) $config->aggregates; if (empty($aggregates)) { return; } foreach ($aggregates as $name => $feed) { $xml_contents = preg_replace(array("/<(\\/?)dc:date>/", "/xmlns=/"), array("<\\1date>", "a="), get_remote($feed["url"])); $xml = simplexml_load_string($xml_contents, "SimpleXMLElement", LIBXML_NOCDATA); if ($xml === false) { continue; } # Flatten namespaces recursively $this->flatten($xml); $items = array(); if (isset($xml->entry)) { foreach ($xml->entry as $entry) { array_unshift($items, $entry); } } elseif (isset($xml->item)) { foreach ($xml->item as $item) { array_unshift($items, $item); } } else { foreach ($xml->channel->item as $item) { array_unshift($items, $item); } } foreach ($items as $item) { $date = oneof(@$item->pubDate, @$item->date, @$item->updated, 0); $updated = strtotime($date); if ($updated > $feed["last_updated"]) { # Get creation date ('created' in Atom) $created = @$item->created ? strtotime($item->created) : 0; if ($created <= 0) { $created = $updated; } # Construct the post data from the user-defined XPath mapping: $data = array("aggregate" => $name); foreach ($feed["data"] as $attr => $field) { $field = !empty($field) ? $this->parse_field($field, $item) : ""; $data[$attr] = is_string($field) ? $field : YAML::dump($field); } if (isset($data["title"]) or isset($data["name"])) { $clean = sanitize(oneof(@$data["title"], @$data["name"])); } Post::add($data, $clean, null, $feed["feather"], $feed["author"], false, "public", datetime($created), datetime($updated)); $aggregates[$name]["last_updated"] = $updated; } } } $config->set("aggregates", $aggregates); $config->set("last_aggregation", time()); }
public function submit() { if (empty($_POST['source'])) { error(__("Error"), __("URL can't be empty.")); } if (!@parse_url($_POST['source'], PHP_URL_SCHEME)) { $_POST['source'] = "http://" . $_POST['source']; } fallback($_POST['slug'], sanitize($_POST['name'])); return Post::add(array("name" => $_POST['name'], "source" => $_POST['source'], "description" => $_POST['description']), $_POST['slug'], Post::check_url($_POST['slug'])); }
public function submit() { if (!isset($_POST['filename'])) { if (isset($_FILES['photo']) and $_FILES['photo']['error'] == 0) { $filename = upload($_FILES['photo'], array("jpg", "jpeg", "png", "gif", "bmp")); } elseif (!empty($_POST['from_url'])) { $filename = upload_from_url($_POST['from_url'], array("jpg", "jpeg", "png", "gif", "bmp")); } else { error(__("Error"), __("Couldn't upload photo.")); } } else { $filename = $_POST['filename']; } return Post::add(array("filename" => $filename, "caption" => $_POST['caption']), $_POST['slug'], Post::check_url($_POST['slug'])); }
public function submit() { if (!isset($_POST['filename'])) { if (isset($_FILES['audio']) and $_FILES['audio']['error'] == 0) { $filename = upload($_FILES['audio'], array("mp3", "m4a", "mp4", "oga", "ogg", "webm")); } elseif (!empty($_POST['from_url'])) { $filename = upload_from_url($_POST['from_url'], array("mp3", "m4a", "mp4", "oga", "ogg", "webm")); } else { error(__("Error"), __("Couldn't upload audio file.", "audio")); } } else { $filename = $_POST['filename']; } return Post::add(array("title" => $_POST['title'], "filename" => $filename, "description" => $_POST['description']), $_POST['slug'], Post::check_url($_POST['slug'])); }
public function submit() { if (!isset($_POST['filename'])) { if (isset($_FILES['filename']) and $_FILES['filename']['error'] == 0) { $filename = upload($_FILES['filename']); } elseif (!empty($_POST['from_url'])) { $filename = upload_from_url($_POST['from_url']); } else { error(__("Error"), __("Couldn't upload file.")); } } else { $filename = $_POST['filename']; } # Prepend scheme if a URL is detected if (preg_match('~^((([a-z]|[0-9]|\\-)+)\\.)+([a-z]){2,6}/~', @$_POST['option']['source'])) { $_POST['option']['source'] = "http://" . $_POST['option']['source']; } return Post::add(array("filename" => $filename, "caption" => $_POST['caption'], "title" => $_POST['title']), $_POST['slug'], Post::check_url($_POST['slug'])); }
function blogger_newPost() { $params = func_get_args(); $post = new Post(); $post->content = $params[4]; $post->contentformatter = getDefaultFormatter(); $post->contenteditor = getDefaultEditor(); $post->title = htmlspecialchars(api_get_title($params[4])); if ($params[5]) { $post->visibility = "public"; } else { $post->visibility = "private"; } $result = api_login($params[2], $params[3]); if ($result) { return $result; } if (!$post->add($params[2])) { $post->close(); return new XMLRPCFault(1, "Posting error"); } RSS::refresh(); $id = "{$post->id}"; fireEvent('AddPostByBlogAPI', $id, $post); $post->close(); return $id; }
function retrieveCallback($lines, $uid) { $this->appendUid($uid); $mail = $this->pop3->parse($lines); if (isset($mail['date_string'])) { $slogan = $mail['date_string']; $docid = $mail['time_string']; } else { $slogan = date("Y-m-d"); $docid = date("H:i:s"); } if (in_array($mail['subject'], array('제목없음'))) { $mail['subject'] = ''; } if (!$this->isAllowed($mail)) { return false; } if (false && empty($mail['attachments'])) { $this->logMail($mail, "SKIP"); return false; } $post = new Post(); $moblog_begin = "\n<div class=\"moblog-entry\">"; $moblog_end = "\n</div>\n"; if ($post->open("slogan = '{$slogan}'")) { $post->loadTags(); $this->log("* 기존 글을 엽니다. (SLOGAN:{$slogan})"); if (empty($post->tags)) { $post->tags = array(); } $tags = $this->extractTags($mail); /* mail content will be changed */ $post->tags = array_merge($post->tags, $tags); $post->content .= $moblog_begin . $this->_getDecoratedContent($mail, $docid); $post->modified = $mail['date']; $post->visibility = $this->visibility; } else { $this->log("* 새 글을 작성합니다. (SLOGAN:{$slogan})"); if (isset($mail['date_year'])) { $post->title = str_replace(array('%Y', '%M', '%D'), array($mail['date_year'], $mail['date_month'], $mail['date_day']), $this->subject); } else { $post->title = str_replace(array('%Y', '%M', '%D'), array(date("Y"), date("m"), date("d")), $this->subject); } $post->userid = $this->userid; $post->category = $this->category; $post->tags = $this->extractTags($mail); /* Go with csv string, Tag class supports both string and array */ $post->content = $moblog_begin . $this->_getDecoratedContent($mail, $docid); $post->contentformatter = getDefaultFormatter(); $post->contenteditor = getDefaultEditor(); $post->created = time(); $post->acceptcomment = true; $post->accepttrackback = true; $post->visibility = $this->visibility; $post->published = time(); $post->modified = $mail['date']; $post->slogan = $slogan; if (!$post->add()) { $this->logMail($mail, "ERROR"); $this->log(_t("실패: 글을 추가하지 못하였습니다") . " : " . $post->error); return false; } else { CacheControl::flushCategory($post->category); } } /* 슬로건을 지워야만 문제가 발생하지 않습니다. */ //unset($post->slogan); if (isset($mail['attachments']) && count($mail['attachments'])) { importlib("model.blog.api"); $post->content .= "<div class=\"moblog-attachments\">\n"; foreach ($mail['attachments'] as $mail_att) { $this->log("* " . _t("첨부") . " : {$mail_att['filename']}"); $att = api_addAttachment(getBlogId(), $post->id, array('name' => $mail_att['filename'], 'content' => $mail_att['decoded_content'], 'size' => $mail_att['length'])); if (!$att) { $this->logMail($mail, "ERROR"); $this->log(_t("실패: 첨부파일을 추가하지 못하였습니다") . " : " . $post->error); return false; } $alt = htmlentities($mail_att['filename'], ENT_QUOTES, 'utf-8'); $content = '[##_1C|$FILENAME|width="$WIDTH" height="$HEIGHT" alt="' . $alt . '"|_##]'; $content = str_replace('$FILENAME', $att['name'], $content); $content = str_replace('$WIDTH', $att['width'], $content); $content = str_replace('$HEIGHT', $att['height'], $content); $post->content .= $content; } $post->content .= "\n</div>"; } $post->content .= $moblog_end; if (!$post->update()) { $this->logMail($mail, "ERROR"); $this->log(_t("실패: 첨부파일을 본문에 연결하지 못하였습니다") . ". : " . $post->error); return false; } $this->logMail($mail, "OK"); return true; }
/** * Function: import_movabletype * MovableType importing. */ public function import_movabletype() { if (empty($_POST)) { redirect("/admin/?action=import"); } if (!Visitor::current()->group->can("add_post")) { show_403(__("Access Denied"), __("You do not have sufficient privileges to import content.")); } $config = Config::current(); $trigger = Trigger::current(); $dbcon = $dbsel = false; if ($link = @mysql_connect($_POST['host'], $_POST['username'], $_POST['password'])) { $dbcon = true; $dbsel = @mysql_select_db($_POST['database'], $link); } if (!$dbcon or !$dbsel) { Flash::warning(__("Could not connect to the specified MovableType database."), "/admin/?action=import"); } mysql_query("SET NAMES 'utf8'"); $get_authors = mysql_query("SELECT * FROM mt_author ORDER BY author_id ASC", $link) or error(__("Database Error"), mysql_error()); $users = array(); while ($author = mysql_fetch_array($get_authors)) { # Try to figure out if this author is the same as the person doing the import. if ($author["author_name"] == Visitor::current()->login or $author["author_nickname"] == Visitor::current()->login or $author["author_nickname"] == Visitor::current()->full_name or $author["author_url"] == Visitor::current()->website or $author["author_email"] == Visitor::current()->email) { $users[$author["author_id"]] = Visitor::current(); } else { $users[$author["author_id"]] = User::add($author["author_name"], $author["author_password"], $author["author_email"], $author["author_nickname"] != $author["author_name"] ? $author["author_nickname"] : "", $author["author_url"], $author["author_can_create_blog"] == "1" ? Visitor::current()->group : null, $author["author_created_on"], false); } } $get_posts = mysql_query("SELECT * FROM mt_entry ORDER BY entry_id ASC", $link) or error(__("Database Error"), mysql_error()); $posts = array(); while ($post = mysql_fetch_array($get_posts)) { $posts[$post["entry_id"]] = $post; } foreach ($posts as $post) { $body = $post["entry_text"]; if (!empty($post["entry_text_more"])) { $body .= "\n\n<!--more-->\n\n" . $post["entry_text_more"]; } $regexp_url = preg_quote($_POST['media_url'], "/"); if (!empty($_POST['media_url']) and preg_match_all("/{$regexp_url}([^\\.\\!,\\?;\"\\'<>\\(\\)\\[\\]\\{\\}\\s\t ]+)\\.([a-zA-Z0-9]+)/", $body, $media)) { foreach ($media[0] as $matched_url) { $filename = upload_from_url($matched_url); $body = str_replace($matched_url, $config->url . $config->uploads_path . $filename, $body); } } $status_translate = array(1 => "draft", 2 => "public", 3 => "draft", 4 => "draft"); $clean = oneof($post["entry_basename"], sanitize($post["entry_title"])); if (empty($post["entry_class"]) or $post["entry_class"] == "entry") { $new_post = Post::add(array("title" => $post["entry_title"], "body" => $body, "imported_from" => "movabletype"), $clean, Post::check_url($clean), "text", @$users[$post["entry_author_id"]], false, $status_translate[$post["entry_status"]], oneof(@$post["entry_authored_on"], @$post["entry_created_on"], datetime()), $post["entry_modified_on"], "", false); $trigger->call("import_movabletype_post", $post, $new_post, $link); } elseif (@$post["entry_class"] == "page") { $new_page = Page::add($post["entry_title"], $body, null, 0, true, 0, $clean, Page::check_url($clean)); $trigger->call("import_movabletype_page", $post, $new_page, $link); } } mysql_close($link); Flash::notice(__("MovableType content successfully imported!"), "/admin/?action=import"); }
public function metaWeblog_newPost($args) { $this->auth($args[1], $args[2], 'add'); global $user; # Support for extended body $body = $args[3]['description']; if (!empty($args[3]['mt_text_more'])) { $body .= '<!--more-->' . $args[3]['mt_text_more']; } # Add excerpt to body so it isn't lost if (!empty($args[3]['mt_excerpt'])) { $body = $args[3]['mt_excerpt'] . "\n\n" . $body; } if (trim($body) === '') { return new IXR_Error(500, __("Body can't be blank.")); } $clean = sanitize(oneof(@$args[3]['mt_basename'], $args[3]['title'])); $url = Post::check_url($clean); $_POST['user_id'] = $user->id; $_POST['feather'] = XML_RPC_FEATHER; $_POST['created_at'] = oneof($this->convertFromDateCreated($args[3]), datetime()); if ($user->group->can('add_post')) { $_POST['status'] = $args[4] ? 'public' : 'draft'; } else { $_POST['status'] = 'draft'; } $trigger = Trigger::current(); $trigger->call('metaWeblog_newPost_preQuery', $args[3]); $post = Post::add(array('title' => $args[3]['title'], 'body' => $body), $clean, $url); if ($post->no_results) { return new IXR_Error(500, __("Post not found.")); } $trigger->call('metaWeblog_newPost', $args[3], $post); # Send any and all pingbacks to URLs in the body if (Config::current()->send_pingbacks) { send_pingbacks($args[3]['description'], $post); } return $post->id; }
function importer($path, $node, $line) { global $blogid, $migrational, $items, $item; switch ($path) { case '/blog/setting': setProgress($item++ / $items * 100, _t('블로그 설정을 복원하고 있습니다.')); $setting = new BlogSetting(); if (isset($node['title'][0]['.value'])) { $setting->title = $node['title'][0]['.value']; } if (isset($node['description'][0]['.value'])) { $setting->description = $node['description'][0]['.value']; } if (isset($node['banner'][0]['name'][0]['.value'])) { $setting->banner = $node['banner'][0]['name'][0]['.value']; } if (isset($node['useSloganOnPost'][0]['.value'])) { $setting->useSloganOnPost = $node['useSloganOnPost'][0]['.value']; } if (isset($node['postsOnPage'][0]['.value'])) { $setting->postsOnPage = $node['postsOnPage'][0]['.value']; } if (isset($node['postsOnList'][0]['.value'])) { $setting->postsOnList = $node['postsOnList'][0]['.value']; } if (isset($node['postsOnFeed'][0]['.value'])) { $setting->postsOnFeed = $node['postsOnFeed'][0]['.value']; } if (isset($node['publishWholeOnFeed'][0]['.value'])) { $setting->publishWholeOnFeed = $node['publishWholeOnFeed'][0]['.value']; } if (isset($node['acceptGuestComment'][0]['.value'])) { $setting->acceptGuestComment = $node['acceptGuestComment'][0]['.value']; } if (isset($node['acceptcommentOnGuestComment'][0]['.value'])) { $setting->acceptcommentOnGuestComment = $node['acceptcommentOnGuestComment'][0]['.value']; } if (isset($node['language'][0]['.value'])) { $setting->language = $node['language'][0]['.value']; } if (isset($node['timezone'][0]['.value'])) { $setting->timezone = $node['timezone'][0]['.value']; } if (!$setting->save()) { user_error(__LINE__ . $setting->error); } if (!empty($setting->banner) && !empty($node['banner'][0]['content'][0]['.stream'])) { Attachment::confirmFolder(); Utils_Base64Stream::decode($node['banner'][0]['content'][0]['.stream'], Path::combine(ROOT, 'attach', $blogid, $setting->banner)); Attachment::adjustPermission(Path::combine(ROOT, 'attach', $blogid, $setting->banner)); fclose($node['banner'][0]['content'][0]['.stream']); unset($node['banner'][0]['content'][0]['.stream']); } return true; case '/blog/category': setProgress($item++ / $items * 100, _t('분류를 복원하고 있습니다.')); $category = new Category(); $category->name = $node['name'][0]['.value']; $category->priority = $node['priority'][0]['.value']; if (isset($node['root'][0]['.value'])) { $category->id = 0; } if (!$category->add()) { user_error(__LINE__ . $category->error); } if (isset($node['category'])) { for ($i = 0; $i < count($node['category']); $i++) { $childCategory = new Category(); $childCategory->parent = $category->id; $cursor =& $node['category'][$i]; $childCategory->name = $cursor['name'][0]['.value']; $childCategory->priority = $cursor['priority'][0]['.value']; if (!$childCategory->add()) { user_error(__LINE__ . $childCategory->error); } } } return true; case '/blog/post': setProgress($item++ / $items * 100, _t('글을 복원하고 있습니다.')); $post = new Post(); $post->id = $node['id'][0]['.value']; $post->slogan = @$node['.attributes']['slogan']; $post->visibility = $node['visibility'][0]['.value']; if (isset($node['starred'][0]['.value'])) { $post->starred = $node['starred'][0]['.value']; } else { $post->starred = 0; } $post->title = $node['title'][0]['.value']; $post->content = $node['content'][0]['.value']; $post->contentformatter = isset($node['content'][0]['.attributes']['formatter']) ? $node['content'][0]['.attributes']['formatter'] : 'ttml'; $post->contenteditor = isset($node['content'][0]['.attributes']['editor']) ? $node['content'][0]['.attributes']['editor'] : 'modern'; $post->location = $node['location'][0]['.value']; $post->password = isset($node['password'][0]['.value']) ? $node['password'][0]['.value'] : null; $post->acceptcomment = $node['acceptComment'][0]['.value']; $post->accepttrackback = $node['acceptTrackback'][0]['.value']; $post->published = $node['published'][0]['.value']; if (isset($node['longitude'][0]['.value'])) { $post->longitude = $node['longitude'][0]['.value']; } if (isset($node['latitude'][0]['.value'])) { $post->latitude = $node['latitude'][0]['.value']; } $post->created = @$node['created'][0]['.value']; $post->modified = @$node['modified'][0]['.value']; if ($post->visibility == 'private' && intval($post->published) > $_SERVER['REQUEST_TIME'] || !empty($node['appointed'][0]['.value']) && $node['appointed'][0]['.value'] == 'true') { // for compatibility of appointed entries $post->visibility = 'appointed'; } if ($post->slogan == '') { $post->slogan = 'Untitled' . $post->id; } if (!empty($node['category'][0]['.value'])) { $post->category = Category::getId($node['category'][0]['.value']); } if (isset($node['tag'])) { $post->tags = array(); for ($i = 0; $i < count($node['tag']); $i++) { if (!empty($node['tag'][$i]['.value'])) { array_push($post->tags, $node['tag'][$i]['.value']); } } } if (floatval(Setting::getServiceSettingGlobal('newlineStyle')) >= 1.1 && floatval(@$node['.attributes']['format']) < 1.1) { $post->content = nl2brWithHTML($post->content); } if (!$post->add()) { user_error(__LINE__ . $post->error); } if (isset($node['attachment'])) { for ($i = 0; $i < count($node['attachment']); $i++) { $attachment = new Attachment(); $attachment->parent = $post->id; $cursor =& $node['attachment'][$i]; $attachment->name = $cursor['name'][0]['.value']; $attachment->label = $cursor['label'][0]['.value']; $attachment->mime = @$cursor['.attributes']['mime']; $attachment->size = $cursor['.attributes']['size']; $attachment->width = $cursor['.attributes']['width']; $attachment->height = $cursor['.attributes']['height']; $attachment->enclosure = @$cursor['enclosure'][0]['.value']; $attachment->attached = $cursor['attached'][0]['.value']; $attachment->downloads = @$cursor['downloads'][0]['.value']; if (!$attachment->add()) { user_error(__LINE__ . $attachment->error); } else { if ($cursor['name'][0]['.value'] != $attachment->name) { $post2 = new Post(); if ($post2->open($post->id, 'id, content')) { $post2->content = str_replace($cursor['name'][0]['.value'], $attachment->name, $post2->content); $post2->loadTags(); $post2->update(); $post2->close(); } unset($post2); } } if (!empty($cursor['content'][0]['.stream'])) { Utils_Base64Stream::decode($cursor['content'][0]['.stream'], Path::combine(ROOT, 'attach', $blogid, $attachment->name)); Attachment::adjustPermission(Path::combine(ROOT, 'attach', $blogid, $attachment->name)); fclose($cursor['content'][0]['.stream']); unset($cursor['content'][0]['.stream']); } } } if (isset($node['comment'])) { for ($i = 0; $i < count($node['comment']); $i++) { $comment = new Comment(); $comment->entry = $post->id; $cursor =& $node['comment'][$i]; $comment->name = $cursor['commenter'][0]['name'][0]['.value']; if (!empty($cursor['id'][0]['.value'])) { $comment->id = $cursor['id'][0]['.value']; } if (!empty($cursor['commenter'][0]['.attributes']['id'])) { $comment->commenter = $cursor['commenter'][0]['.attributes']['id']; } if (!empty($cursor['commenter'][0]['homepage'][0]['.value'])) { $comment->homepage = $cursor['commenter'][0]['homepage'][0]['.value']; } if (!empty($cursor['commenter'][0]['ip'][0]['.value'])) { $comment->ip = $cursor['commenter'][0]['ip'][0]['.value']; } if (!empty($cursor['commenter'][0]['openid'][0]['.value'])) { $comment->openid = $cursor['commenter'][0]['openid'][0]['.value']; } $comment->password = $cursor['password'][0]['.value']; $comment->secret = $cursor['secret'][0]['.value']; $comment->written = $cursor['written'][0]['.value']; if (isset($cursor['longitude'][0]['.value'])) { $comment->longitude = $cursor['longitude'][0]['.value']; } if (isset($cursor['latitude'][0]['.value'])) { $comment->latitude = $cursor['latitude'][0]['.value']; } $comment->content = $cursor['content'][0]['.value']; if (!empty($cursor['isFiltered'][0]['.value'])) { $comment->isfiltered = $cursor['isFiltered'][0]['.value']; } if (!$comment->add()) { user_error(__LINE__ . $comment->error); } if (isset($node['comment'][$i]['comment'])) { for ($j = 0; $j < count($node['comment'][$i]['comment']); $j++) { $childComment = new Comment(); $childComment->entry = $post->id; $childComment->parent = $comment->id; $cursor =& $node['comment'][$i]['comment'][$j]; if (!empty($cursor['id'][0]['.value'])) { $childComment->id = $cursor['id'][0]['.value']; } if (!empty($cursor['commenter'][0]['.attributes']['id'])) { $childComment->commenter = $cursor['commenter'][0]['.attributes']['id']; } $childComment->name = $cursor['commenter'][0]['name'][0]['.value']; if (!empty($cursor['commenter'][0]['homepage'][0]['.value'])) { $childComment->homepage = $cursor['commenter'][0]['homepage'][0]['.value']; } if (!empty($cursor['commenter'][0]['ip'][0]['.value'])) { $childComment->ip = $cursor['commenter'][0]['ip'][0]['.value']; } if (!empty($cursor['commenter'][0]['openid'][0]['.value'])) { $childComment->openid = $cursor['commenter'][0]['openid'][0]['.value']; } $childComment->password = $cursor['password'][0]['.value']; $childComment->secret = $cursor['secret'][0]['.value']; $childComment->written = $cursor['written'][0]['.value']; if (isset($cursor['longitude'][0]['.value'])) { $comment->longitude = $cursor['longitude'][0]['.value']; } if (isset($cursor['latitude'][0]['.value'])) { $comment->latitude = $cursor['latitude'][0]['.value']; } $childComment->content = $cursor['content'][0]['.value']; if (!empty($cursor['isFiltered'][0]['.value'])) { $childComment->isfiltered = $cursor['isFiltered'][0]['.value']; } if (!$childComment->add()) { user_error(__LINE__ . $childComment->error); } } } } } if (isset($node['trackback'])) { for ($i = 0; $i < count($node['trackback']); $i++) { $trackback = new Trackback(); $trackback->entry = $post->id; $cursor =& $node['trackback'][$i]; $trackback->url = $cursor['url'][0]['.value']; $trackback->site = $cursor['site'][0]['.value']; $trackback->title = $cursor['title'][0]['.value']; $trackback->excerpt = @$cursor['excerpt'][0]['.value']; if (!empty($cursor['ip'][0]['.value'])) { $trackback->ip = $cursor['ip'][0]['.value']; } if (!empty($cursor['received'][0]['.value'])) { $trackback->received = $cursor['received'][0]['.value']; } if (!empty($cursor['isFiltered'][0]['.value'])) { $trackback->isFiltered = $cursor['isFiltered'][0]['.value']; } if (!$trackback->add()) { user_error(__LINE__ . $trackback->error); } } } if (isset($node['logs'][0]['trackback'])) { for ($i = 0; $i < count($node['logs'][0]['trackback']); $i++) { $log = new TrackbackLog(); $log->entry = $post->id; $cursor =& $node['logs'][0]['trackback'][$i]; $log->url = $cursor['url'][0]['.value']; if (!empty($cursor['sent'][0]['.value'])) { $log->sent = $cursor['sent'][0]['.value']; } if (!$log->add()) { user_error(__LINE__ . $log->error); } } } return true; case '/blog/page': setProgress($item++ / $items * 100, _t('페이지를 복원하고 있습니다.')); $page = new Page(); $page->id = $node['id'][0]['.value']; $page->slogan = @$node['.attributes']['slogan']; $page->visibility = $node['visibility'][0]['.value']; if (isset($node['starred'][0]['.value'])) { $page->starred = $node['starred'][0]['.value']; } else { $page->starred = 0; } $page->title = $node['title'][0]['.value']; $page->content = $node['content'][0]['.value']; $page->contentformatter = isset($node['content']['.attributes']['formatter']) ? $node['content']['.attributes']['formatter'] : getDefaultFormatter(); $page->contenteditor = isset($node['content']['.attributes']['editor']) ? $node['content']['.attributes']['editor'] : getDefaultEditor(); $page->published = $node['published'][0]['.value']; $page->created = @$node['created'][0]['.value']; $page->modified = @$node['modified'][0]['.value']; if (floatval(Setting::getServiceSettingGlobal('newlineStyle')) >= 1.1 && floatval(@$node['.attributes']['format']) < 1.1) { $page->content = nl2brWithHTML($page->content); } if (!$page->add()) { user_error(__LINE__ . $page->error); } if (isset($node['attachment'])) { for ($i = 0; $i < count($node['attachment']); $i++) { $attachment = new Attachment(); $attachment->parent = $page->id; $cursor =& $node['attachment'][$i]; $attachment->name = $cursor['name'][0]['.value']; $attachment->label = $cursor['label'][0]['.value']; $attachment->mime = @$cursor['.attributes']['mime']; $attachment->size = $cursor['.attributes']['size']; $attachment->width = $cursor['.attributes']['width']; $attachment->height = $cursor['.attributes']['height']; $attachment->enclosure = @$cursor['enclosure'][0]['.value']; $attachment->attached = $cursor['attached'][0]['.value']; $attachment->downloads = @$cursor['downloads'][0]['.value']; if (Attachment::doesExist($attachment->name)) { if (!$attachment->add()) { user_error(__LINE__ . $attachment->error); } $page2 = new Page(); if ($page2->open($page->id, 'id, content')) { $page2->content = str_replace($cursor['name'][0]['.value'], $attachment->name, $page2->content); $page2->update(); $page2->close(); } unset($page2); } else { if (!$attachment->add()) { user_error(__LINE__ . $attachment->error); } } if (!empty($cursor['content'][0]['.stream'])) { Utils_Base64Stream::decode($cursor['content'][0]['.stream'], Path::combine(ROOT, 'attach', $blogid, $attachment->name)); Attachment::adjustPermission(Path::combine(ROOT, 'attach', $blogid, $attachment->name)); fclose($cursor['content'][0]['.stream']); unset($cursor['content'][0]['.stream']); } } } return true; case '/blog/notice': setProgress($item++ / $items * 100, _t('공지를 복원하고 있습니다.')); $notice = new Notice(); $notice->id = $node['id'][0]['.value']; $notice->slogan = @$node['.attributes']['slogan']; $notice->visibility = $node['visibility'][0]['.value']; if (isset($node['starred'][0]['.value'])) { $notice->starred = $node['starred'][0]['.value']; } else { $notice->starred = 0; } $notice->title = $node['title'][0]['.value']; $notice->content = $node['content'][0]['.value']; $notice->contentformatter = isset($node['content'][0]['.attributes']['formatter']) ? $node['content'][0]['.attributes']['formatter'] : getDefaultFormatter(); $notice->contenteditor = isset($node['content'][0]['.attributes']['editor']) ? $node['content'][0]['.attributes']['editor'] : getDefaultEditor(); $notice->published = intval($node['published'][0]['.value']); $notice->created = @$node['created'][0]['.value']; $notice->modified = @$node['modified'][0]['.value']; if (floatval(Setting::getServiceSettingGlobal('newlineStyle')) >= 1.1 && floatval(@$node['.attributes']['format']) < 1.1) { $notice->content = nl2brWithHTML($notice->content); } if (!$notice->add()) { user_error(__LINE__ . $notice->error); } if (isset($node['attachment'])) { for ($i = 0; $i < count($node['attachment']); $i++) { $attachment = new Attachment(); $attachment->parent = $notice->id; $cursor =& $node['attachment'][$i]; $attachment->name = $cursor['name'][0]['.value']; $attachment->label = $cursor['label'][0]['.value']; $attachment->mime = @$cursor['.attributes']['mime']; $attachment->size = $cursor['.attributes']['size']; $attachment->width = $cursor['.attributes']['width']; $attachment->height = $cursor['.attributes']['height']; $attachment->enclosure = @$cursor['enclosure'][0]['.value']; $attachment->attached = $cursor['attached'][0]['.value']; $attachment->downloads = @$cursor['downloads'][0]['.value']; if (Attachment::doesExist($attachment->name)) { if (!$attachment->add()) { user_error(__LINE__ . $attachment->error); } $notice2 = new Notice(); if ($notice2->open($notice->id, 'id, content')) { $notice2->content = str_replace($cursor['name'][0]['.value'], $attachment->name, $notice2->content); $notice2->update(); $notice2->close(); } unset($notice2); } else { if (!$attachment->add()) { user_error(__LINE__ . $attachment->error); } } if (!empty($cursor['content'][0]['.stream'])) { Utils_Base64Stream::decode($cursor['content'][0]['.stream'], Path::combine(ROOT, 'attach', $blogid, $attachment->name)); Attachment::adjustPermission(Path::combine(ROOT, 'attach', $blogid, $attachment->name)); fclose($cursor['content'][0]['.stream']); unset($cursor['content'][0]['.stream']); } } } return true; case '/blog/keyword': setProgress($item++ / $items * 100, _t('키워드를 복원하고 있습니다.')); $keyword = new Keyword(); $keyword->id = $node['id'][0]['.value']; $keyword->visibility = $node['visibility'][0]['.value']; if (isset($node['starred'][0]['.value'])) { $keyword->starred = $node['starred'][0]['.value']; } else { $keyword->starred = 0; } $keyword->name = $node['name'][0]['.value']; $keyword->description = $node['description'][0]['.value']; $keyword->descriptionEditor = isset($node['description'][0]['.attributes']['editor']) ? $node['description'][0]['.attributes']['editor'] : getDefaultEditor(); $keyword->descriptionFormatter = isset($node['description'][0]['.attributes']['formatter']) ? $node['description'][0]['.attributes']['formatter'] : getDefaultFormatter(); $keyword->published = intval($node['published'][0]['.value']); $keyword->created = @$node['created'][0]['.value']; $keyword->modified = @$node['modified'][0]['.value']; if (floatval(Setting::getServiceSettingGlobal('newlineStyle')) >= 1.1 && floatval(@$node['.attributes']['format']) < 1.1) { $keyword->description = nl2brWithHTML($keyword->description); } if (!$keyword->add()) { user_error(__LINE__ . $keyword->error); } if (isset($node['attachment'])) { for ($i = 0; $i < count($node['attachment']); $i++) { $attachment = new Attachment(); $attachment->parent = $keyword->id; $cursor =& $node['attachment'][$i]; $attachment->name = $cursor['name'][0]['.value']; $attachment->label = $cursor['label'][0]['.value']; $attachment->mime = @$cursor['.attributes']['mime']; $attachment->size = $cursor['.attributes']['size']; $attachment->width = $cursor['.attributes']['width']; $attachment->height = $cursor['.attributes']['height']; $attachment->enclosure = @$cursor['enclosure'][0]['.value']; $attachment->attached = $cursor['attached'][0]['.value']; $attachment->downloads = @$cursor['downloads'][0]['.value']; if (Attachment::doesExist($attachment->name)) { if (!$attachment->add()) { user_error(__LINE__ . $attachment->error); } $keyword2 = new Keyword(); if ($keyword2->open($keyword->id, 'id, content')) { $keyword2->content = str_replace($cursor['name'][0]['.value'], $attachment->name, $keyword2->content); $keyword2->update(); $keyword2->close(); } unset($keyword2); } else { if (!$attachment->add()) { user_error(__LINE__ . $attachment->error); } } if (!empty($cursor['content'][0]['.stream'])) { Utils_Base64Stream::decode($cursor['content'][0]['.stream'], Path::combine(ROOT, 'attach', $blogid, $attachment->name)); Attachment::adjustPermission(Path::combine(ROOT, 'attach', $blogid, $attachment->name)); fclose($cursor['content'][0]['.stream']); unset($cursor['content'][0]['.stream']); } } } return true; case '/blog/linkCategories': setProgress($item++ / $items * 100, _t('링크 카테고리를 복원하고 있습니다.')); $linkCategory = new LinkCategories(); $linkCategory->name = $node['name'][0]['.value']; $linkCategory->priority = $node['priority'][0]['.value']; $linkCategory->visibility = !isset($node['visibility'][0]['.value']) || empty($node['visibility'][0]['.value']) ? 2 : $node['visibility'][0]['.value']; $linkCategory->id = LinkCategories::getId($linkCategory->name); if ($linkCategory->id) { if (!$linkCategory->update()) { user_error(__LINE__ . $linkCategory->error); } } else { if (!$linkCategory->add()) { user_error(__LINE__ . $linkCategory->error); } } return true; case '/blog/link': setProgress($item++ / $items * 100, _t('링크를 복원하고 있습니다.')); $link = new Link(); $link->category = empty($node['category'][0]['.value']) ? 0 : $node['category'][0]['.value']; $link->url = $node['url'][0]['.value']; $link->title = $node['title'][0]['.value']; if (!empty($node['feed'][0]['.value'])) { $link->feed = $node['feed'][0]['.value']; } if (!empty($node['registered'][0]['.value'])) { $link->registered = $node['registered'][0]['.value']; } if (!empty($node['xfn'][0]['.value'])) { $link->xfn = $node['xfn'][0]['.value']; } $link->id = Link::getId($link->url); if ($link->id) { if (!$link->update()) { user_error(__LINE__ . $link->error); } } else { if (!$link->add()) { user_error(__LINE__ . $link->error); } } return true; case '/blog/logs/referer': setProgress($item++ / $items * 100, _t('리퍼러 로그를 복원하고 있습니다.')); $log = new RefererLog(); if (isset($node['path'][0]['.value'])) { $log->url = $node['path'][0]['.value']; } else { $log->url = $node['url'][0]['.value']; } $log->referred = $node['referred'][0]['.value']; if (!$log->add(false)) { user_error(__LINE__ . $log->error); } return true; case '/blog/commentsNotified/comment': setProgress($item++ / $items * 100, _t('댓글 알리미 내용을 복원하고 있습니다.')); $cmtNotified = new CommentNotified(); $cmtNotified->id = $node['id'][0]['.value']; $cursor =& $node['commenter'][0]; $cmtNotified->name = $cursor['name'][0]['.value']; $cmtNotified->homepage = $cursor['homepage'][0]['.value']; $cmtNotified->ip = $cursor['ip'][0]['.value']; $cmtNotified->entry = $node['entry'][0]['.value']; $cmtNotified->password = $node['password'][0]['.value']; $cmtNotified->content = $node['content'][0]['.value']; $cmtNotified->parent = $node['parent'][0]['.value']; $cmtNotified->secret = $node['secret'][0]['.value']; $cmtNotified->written = $node['written'][0]['.value']; $cmtNotified->modified = $node['modified'][0]['.value']; $cmtNotified->url = $node['url'][0]['.value']; $cmtNotified->isnew = $node['isNew'][0]['.value']; $site = new CommentNotifiedSiteInfo(); if (!$site->open("url = '{$node['site'][0]['.value']}'")) { $site->title = ''; $site->name = ''; $site->modified = 31536000; $site->url = $node['site'][0]['.value']; $site->add(); } $cmtNotified->siteid = $site->id; $site->close(); $cmtNotified->remoteid = $node['remoteId'][0]['.value']; $cmtNotified->entrytitle = !isset($node['entryTitle'][0]['.value']) || empty($node['entryTitle'][0]['.value']) ? 'No title' : $node['entryTitle'][0]['.value']; $cmtNotified->entryurl = $node['entryUrl'][0]['.value']; if (!$cmtNotified->add()) { user_error(__LINE__ . $cmtNotified->error); } return true; case '/blog/commentsNotifiedSiteInfo/site': setProgress($item++ / $items * 100, _t('댓글 알리미 내용을 복원하고 있습니다.')); $cmtNotifiedSite = new CommentNotifiedSiteInfo(); if ($cmtNotifiedSite->open("url = '{$node['url'][0]['.value']}'")) { if (intval($node['modified'][0]['.value']) > intval($cmtNotifiedSite->modified)) { $cmtNotifiedSite->title = $node['title'][0]['.value']; $cmtNotifiedSite->name = $node['name'][0]['.value']; $cmtNotifiedSite->modified = $node['modified'][0]['.value']; } if (!$cmtNotifiedSite->update()) { user_error(__LINE__ . $cmtNotifiedSite->error); } } else { $cmtNotifiedSite->url = $node['url'][0]['.value']; $cmtNotifiedSite->title = $node['title'][0]['.value']; $cmtNotifiedSite->name = $node['name'][0]['.value']; $cmtNotifiedSite->modified = $node['modified'][0]['.value']; if (!$cmtNotifiedSite->add()) { user_error(__LINE__ . $cmtNotifiedSite->error); } } return true; case '/blog/statistics/referer': setProgress($item++ / $items * 100, _t('리퍼러 통계를 복원하고 있습니다.')); $statistics = new RefererStatistics(); $statistics->host = $node['host'][0]['.value']; $statistics->count = $node['count'][0]['.value']; if (!$statistics->add()) { user_error(__LINE__ . $statistics->error); } return true; case '/blog/statistics/visits': setProgress($item++ / $items * 100, _t('블로그 통계 정보를 복원하고 있습니다.')); $statistics = new BlogStatistics(); $statistics->visits = $node['.value']; if (!$statistics->add()) { user_error(__LINE__ . $statistics->error); } return true; case '/blog/statistics/daily': setProgress($item++ / $items * 100, _t('일별 통계 정보를 복원하고 있습니다.')); $statistics = new DailyStatistics(); $statistics->date = $node['date'][0]['.value']; $statistics->visits = $node['visits'][0]['.value']; if (!$statistics->add()) { user_error(__LINE__ . $statistics->error); } return true; case '/blog/skin': setProgress($item++ / $items * 100, _t('스킨 설정을 복원하고 있습니다.')); $setting = new SkinSetting(); if (false) { $setting->skin = $node['name'][0]['.value']; if (!$setting->save()) { user_error(__LINE__ . $setting->error); } $setting->skin = null; } $setting->entriesOnRecent = $node['entriesOnRecent'][0]['.value']; $setting->commentsOnRecent = $node['commentsOnRecent'][0]['.value']; $setting->trackbacksOnRecent = $node['trackbacksOnRecent'][0]['.value']; $setting->commentsOnGuestbook = $node['commentsOnGuestbook'][0]['.value']; $setting->tagsOnTagbox = $node['tagsOnTagbox'][0]['.value']; $setting->alignOnTagbox = $node['alignOnTagbox'][0]['.value']; $setting->expandComment = $node['expandComment'][0]['.value']; $setting->expandTrackback = $node['expandTrackback'][0]['.value']; if (!empty($node['recentNoticeLength'][0]['.value'])) { $setting->recentNoticeLength = $node['recentNoticeLength'][0]['.value']; } $setting->recentEntryLength = $node['recentEntryLength'][0]['.value']; $setting->recentTrackbackLength = $node['recentTrackbackLength'][0]['.value']; $setting->linkLength = $node['linkLength'][0]['.value']; $setting->showListOnCategory = $node['showListOnCategory'][0]['.value']; $setting->showListOnArchive = $node['showListOnArchive'][0]['.value']; if (isset($node['tree'])) { $cursor =& $node['tree'][0]; $setting->tree = $cursor['name'][0]['.value']; $setting->colorOnTree = $cursor['color'][0]['.value']; $setting->bgcolorOnTree = $cursor['bgColor'][0]['.value']; $setting->activecolorOnTree = $cursor['activeColor'][0]['.value']; $setting->activebgcolorOnTree = $cursor['activeBgColor'][0]['.value']; $setting->labelLengthOnTree = $cursor['labelLength'][0]['.value']; $setting->showValueOnTree = $cursor['showValue'][0]['.value']; } if (!$setting->save()) { user_error(__LINE__ . $setting->error); } return true; case '/blog/plugin': // setProgress($item++ / $items * 100, _t('플러그인 설정을 복원하고 있습니다.')); // $setting = new PluginSetting(); // $setting->name = $node['name'][0]['.value']; // $setting->setting = $node['setting'][0]['.value']; // if (!$setting->add()) // user_error(__LINE__ . $setting->error); return true; case '/blog/personalization': // setProgress($item++ / $items * 100, _t('사용자 편의 설정을 복원하고 있습니다.')); // $setting = new UserSetting(); // $setting->name = 'rowsPerPage'; // $setting->value = $node['rowsPerPage'][0]['.value']; // if (!$setting->add()) // user_error(__LINE__ . $setting->error); // $setting->name = 'readerPannelVisibility'; // $setting->value = $node['readerPannelVisibility'][0]['.value']; // if (!$setting->add()) // user_error(__LINE__ . $setting->error); // $setting->name = 'readerPannelHeight'; // $setting->value = $node['readerPannelHeight'][0]['.value']; // if (!$setting->add()) // user_error(__LINE__ . $setting->error); // $setting->name = 'lastVisitNotifiedPage'; // $setting->value = $node['lastVisitNotifiedPage'][0]['.value']; // if (!$setting->add()) // user_error(__LINE__ . $setting->error); return true; case '/blog/userSetting': // setProgress($item++ / $items * 100, _t('사용자 편의 설정을 복원하고 있습니다')); // $setting = new UserSetting(); // $setting->name = $node['name'][0]['.value']; // $setting->value = $node['value'][0]['.value']; // if (!$setting->add()) // user_error(__LINE__ . $setting->error); return true; case '/blog/guestbook/comment': setProgress($item++ / $items * 100, _t('방명록을 복원하고 있습니다.')); $comment = new GuestComment(); $comment->name = $node['commenter'][0]['name'][0]['.value']; if (!empty($node['id'][0]['.value'])) { $comment->id = $node['id'][0]['.value']; } if (!empty($node['commenter'][0]['.attributes']['id'])) { $comment->commenter = $node['commenter'][0]['.attributes']['id']; } if (!empty($node['commenter'][0]['homepage'][0]['.value'])) { $comment->homepage = $node['commenter'][0]['homepage'][0]['.value']; } if (!empty($node['commenter'][0]['ip'][0]['.value'])) { $comment->ip = $node['commenter'][0]['ip'][0]['.value']; } if (!empty($node['commenter'][0]['openid'][0]['.value'])) { $comment->openid = $node['commenter'][0]['openid'][0]['.value']; } $comment->password = $node['password'][0]['.value']; $comment->secret = @$node['secret'][0]['.value']; $comment->written = $node['written'][0]['.value']; $comment->content = $node['content'][0]['.value']; if (!$comment->add()) { user_error(__LINE__ . $comment->error); } if (isset($node['comment'])) { for ($j = 0; $j < count($node['comment']); $j++) { $childComment = new GuestComment(); $childComment->parent = $comment->id; $cursor =& $node['comment'][$j]; $childComment->name = $cursor['commenter'][0]['name'][0]['.value']; if (!empty($cursor['id'][0]['.value'])) { $comment->id = $cursor['id'][0]['.value']; } if (!empty($cursor['commenter'][0]['.attributes']['id'])) { $childComment->commenter = $cursor['commenter'][0]['.attributes']['id']; } if (!empty($cursor['commenter'][0]['homepage'][0]['.value'])) { $childComment->homepage = $cursor['commenter'][0]['homepage'][0]['.value']; } if (!empty($cursor['commenter'][0]['ip'][0]['.value'])) { $childComment->ip = $cursor['commenter'][0]['ip'][0]['.value']; } if (!empty($cursor['commenter'][0]['openid'][0]['.value'])) { $childComment->openid = $cursor['commenter'][0]['openid'][0]['.value']; } $childComment->password = $cursor['password'][0]['.value']; $childComment->secret = @$cursor['secret'][0]['.value']; $childComment->written = $cursor['written'][0]['.value']; $childComment->content = $cursor['content'][0]['.value']; if (!$childComment->add()) { user_error(__LINE__ . $childComment->error); } } } return true; case '/blog/filter': setProgress($item++ / $items * 100, _t('필터 설정을 복원하고 있습니다.')); $filter = new Filter(); $filter->type = $node['.attributes']['type']; $filter->pattern = $node['pattern'][0]['.value']; if (!$filter->add()) { user_error(__LINE__ . $filter->error); } return true; case '/blog/feed': setProgress($item++ / $items * 100, _t('리더 데이터를 복원하고 있습니다.')); $feed = new Feed(); if (!empty($node['group'][0]['.value'])) { $feed->group = FeedGroup::getId($node['group'][0]['.value'], true); } $feed->url = $node['url'][0]['.value']; if (!$feed->add()) { user_error(__LINE__ . $feed->error); } return true; case '/blog/line': setProgress($item++ / $items * 100, _t('라인을 복원하고 있습니다.')); $line = Model_Line::getInstance(); $line->reset(); if (!empty($node['author'][0]['.value'])) { $line->author = $node['author'][0]['.value']; } if (!empty($node['category'][0]['.value'])) { $line->category = $node['category'][0]['.value']; } if (!empty($node['root'][0]['.value'])) { $line->root = $node['root'][0]['.value']; } if (!empty($node['permalink'][0]['.value'])) { $line->permalink = $node['permalink'][0]['.value']; } if (!empty($node['content'][0]['.value'])) { $line->content = $node['content'][0]['.value']; } if (!empty($node['created'][0]['.value'])) { $line->created = intval($node['created'][0]['.value']); } if ($line->add()) { return true; } else { user_error(__LINE__ . $line->_error); } } }
{ $query = "SELECT * FROM posts WHERE active=1 AND id > " . $lastId; $result = $this->db->query($query); while ($row = $result->fetch_object()) { $out[] = $row; } if (empty($out)) { $out[] = ''; } return $out; } } if (isset($_POST['findNew'])) { $post = new Post(); $out = $post->findNew($_POST['findNew']); if (!empty($out)) { echo json_encode($out); } else { header('HTTP/1.1 500 F**k'); exit; } } if (isset($_POST['deleteId'])) { $post = new Post(); $post->delete($_POST['deleteId']); } if (isset($_POST['body'])) { $post = new Post(); $post->setBody($_POST['body']); $post->add(); }
static function admin_manage_dropbox($admin) { if (!Visitor::current()->group->can("add_post", "add_draft")) { show_403(__("Access Denied"), __("You do not have sufficient privileges to create posts.")); } if (empty($_POST)) { return $admin->display("manage_dropbox"); } $config = Config::current(); if (!isset($config->module_dropbox["oauth_token"])) { Flash::notice(__("You need to authorize Dropbox first.", "dropbox"), "/admin/?action=dropbox_settings"); } $data = json_decode(file_get_contents("http://chyrp.net/api/1/dropboxsync.php?keys"), true); $app_key = $data["key"]; $app_secret = $data["secret"]; $storage = new \Dropbox\OAuth\Storage\Session(); $OAuth = new \Dropbox\OAuth\Consumer\Curl($app_key, $app_secret, $storage); $dropbox = new \Dropbox\API($OAuth); $delta = $dropbox->delta(); $delta = $delta["body"]; if ($delta->cursor != $config->module_dropbox["cursor"]) { if (count($delta->entries) > 0) { foreach ($delta->entries as $entry) { $tmpfname = tempnam("/tmp", "md"); $file = $dropbox->getFile(ltrim($entry[0], "/"), $tmpfname); $post = new FrontMatter($file["name"]); $date = explode(".", ltrim($entry[0], "/")); $values = array("title" => $post->fetch("title"), "body" => $post->fetch("content")); # Set defaults fallback($clean, oneof($post->fetch("slug"), strtolower(str_replace(" ", "-", $post->fetch("title"))))); fallback($url, Post::check_url($clean)); fallback($pinned, oneof($post->fetch("pinned"), 0)); fallback($status, oneof($post->fetch("status"), "public")); fallback($date, oneof(datetime($post->fetch("date")), datetime($date[0]))); $post = Post::add($values, $clean, $url, "text", 1, $pinned, $status, datetime($post->fetch("date")), datetime($post->fetch("date")), false); } } $set = array($config->set("module_dropbox", array("oauth_token_secret" => $config->module_dropbox['oauth_token_secret'], "oauth_token" => $config->module_dropbox['oauth_token'], "uid" => $config->module_dropbox['uid'], "cursor" => $delta->cursor))); if (!in_array(false, $set)) { Flash::notice(__("Post imported successfully.", "dropbox"), "/admin/?action=manage_posts"); } } }
/** * Gets the mail from the inbox * Reads all the messages there, and adds posts based on them. Then it deletes the entire mailbox. */ function getMail() { $config = Config::current(); if (time() - 60 * $config->emailblog_minutes >= $config->emailblog_mail_checked) { $hostname = '{' . $config->emailblog_server . '}INBOX'; # this isn't working well on localhost $username = $config->emailblog_address; $password = $config->emailblog_pass; $subjpass = $config->emailblog_subjpass; $inbox = imap_open($hostname, $username, $password) or exit("Cannot connect to Gmail: " . imap_last_error()); $emails = imap_search($inbox, 'SUBJECT "' . $subjpass . '"'); if ($emails) { rsort($emails); foreach ($emails as $email_number) { $message = imap_body($inbox, $email_number); $overview = imap_headerinfo($inbox, $email_number); imap_delete($inbox, $email_number); $title = htmlspecialchars($overview->Subject); $title = preg_replace($subjpass, "", $title); $clean = strtolower($title); $body = htmlspecialchars($message); # The subject of the email is used as the post title # the content of the email is used as the body # not sure about compatibility with images or audio feathers Post::add(array("title" => $title, "body" => $message), $clean, Post::check_url($clean), "text"); } } # close the connection imap_close($inbox, CL_EXPUNGE); $config->set("emailblog_mail_checked", time()); } }