function insert_posts() { global $wpdb; $this->counter_imported = 0; $this->counter_skipped = 0; if (count($this->posts) > 0) { foreach ($this->posts as $post) { // check if it is existing in wp database already $facebook_id = $post['facebook_id']; if ($wpdb->get_var($wpdb->prepare("SELECT meta_id FROM {$wpdb->postmeta} WHERE meta_key = 'facebook_id' AND meta_value = %s", $facebook_id)) || post_exists($post['post_title'], $post['post_content'], $post['post_date'])) { // already in database, skip $this->counter_skipped++; continue; } else { // insert into wp database $post_id = wp_insert_post($post); //if failed to insert, keep going to try next post. if (!$post_id) { continue; } add_post_meta($post_id, 'facebook_id', $facebook_id); $this->counter_imported++; } // end of if } // end of foreach } // end of if return true; }
private function remove_old($title, $post_id) { $old_post_id = post_exists($title); if ($old_post_id) { update_field('column_select', get_field('column_select', $old_post_id), $post_id); wp_delete_post($old_post_id); echo '<br>"' . $title . '" updated.'; } else { $this->set_visible_columns($post_id); echo '<br>"' . $title . '" added.'; } }
function _insert_events($event) { //update_field $post_id = post_exists($event->name); if (!$post_id) { $params = array('post_status' => 'publish', 'post_name' => $event->name, 'post_type' => 'event', 'post_title' => $event->name); $post_id = wp_insert_post($params); if (is_numeric($post_id)) { update_field('meetup_id', $event->id, $post_id); update_field('titel', $event->name, $post_id); update_field('description', $event->description, $post_id); echo '<p>Evenement: \'' . $event->name . '\' is geimporteerd.</p>'; //update_field(); //update_field(); } } }
function process_posts() { global $wpdb; $i = -1; echo "<ol>"; foreach ($this->posts as $post) { if ('' != trim($post)) { ++$i; unset($post_categories); // Take the pings out first preg_match("|(-----\n\nPING:.*)|s", $post, $pings); $post = preg_replace("|(-----\n\nPING:.*)|s", '', $post); // Then take the comments out preg_match("|(-----\nCOMMENT:.*)|s", $post, $comments); $post = preg_replace("|(-----\nCOMMENT:.*)|s", '', $post); // We ignore the keywords $post = preg_replace("|(-----\nKEYWORDS:.*)|s", '', $post); // We want the excerpt preg_match("|-----\nEXCERPT:(.*)|s", $post, $excerpt); $excerpt = $wpdb->escape(trim($excerpt[1])); $post = preg_replace("|(-----\nEXCERPT:.*)|s", '', $post); // We're going to put extended body into main body with a more tag preg_match("|-----\nEXTENDED BODY:(.*)|s", $post, $extended); $extended = trim($extended[1]); if ('' != $extended) { $extended = "\n<!--more-->\n{$extended}"; } $post = preg_replace("|(-----\nEXTENDED BODY:.*)|s", '', $post); // Now for the main body preg_match("|-----\nBODY:(.*)|s", $post, $body); $body = trim($body[1]); $post_content = $wpdb->escape($body . $extended); $post = preg_replace("|(-----\nBODY:.*)|s", '', $post); // Grab the metadata from what's left $metadata = explode("\n", $post); foreach ($metadata as $line) { preg_match("/^(.*?):(.*)/", $line, $token); $key = trim($token[1]); $value = trim($token[2]); // Now we decide what it is and what to do with it switch ($key) { case '': break; case 'AUTHOR': $post_author = $value; break; case 'TITLE': $post_title = $wpdb->escape($value); break; case 'STATUS': // "publish" and "draft" enumeration items match up; no change required $post_status = $value; if (empty($post_status)) { $post_status = 'publish'; } break; case 'ALLOW COMMENTS': $post_allow_comments = $value; if ($post_allow_comments == 1) { $comment_status = 'open'; } else { $comment_status = 'closed'; } break; case 'CONVERT BREAKS': $post_convert_breaks = $value; break; case 'ALLOW PINGS': $post_allow_pings = trim($meta[2][0]); if ($post_allow_pings == 1) { $post_allow_pings = 'open'; } else { $post_allow_pings = 'closed'; } break; case 'PRIMARY CATEGORY': if (!empty($value)) { $post_categories[] = $wpdb->escape($value); } break; case 'CATEGORY': if (!empty($value)) { $post_categories[] = $wpdb->escape($value); } break; case 'DATE': $post_modified = strtotime($value); $post_modified = date('Y-m-d H:i:s', $post_modified); $post_modified_gmt = get_gmt_from_date("{$post_modified}"); $post_date = $post_modified; $post_date_gmt = $post_modified_gmt; break; default: // echo "\n$key: $value"; break; } // end switch } // End foreach // Let's check to see if it's in already if ($post_id = post_exists($post_title, '', $post_date)) { echo '<li>'; printf(__('Post <i>%s</i> already exists.'), stripslashes($post_title)); } else { echo '<li>'; printf(__('Importing post <i>%s</i>...'), stripslashes($post_title)); $post_author = $this->checkauthor($post_author); //just so that if a post already exists, new users are not created by checkauthor $postdata = compact('post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_title', 'post_excerpt', 'post_status', 'comment_status', 'ping_status', 'post_modified', 'post_modified_gmt'); $post_id = wp_insert_post($postdata); // Add categories. if (0 != count($post_categories)) { wp_create_categories($post_categories, $post_id); } } $comment_post_ID = $post_id; // Now for comments $comments = explode("-----\nCOMMENT:", $comments[0]); $num_comments = 0; foreach ($comments as $comment) { if ('' != trim($comment)) { // Author preg_match("|AUTHOR:(.*)|", $comment, $comment_author); $comment_author = $wpdb->escape(trim($comment_author[1])); $comment = preg_replace('|(\\n?AUTHOR:.*)|', '', $comment); preg_match("|EMAIL:(.*)|", $comment, $comment_author_email); $comment_author_email = $wpdb->escape(trim($comment_author_email[1])); $comment = preg_replace('|(\\n?EMAIL:.*)|', '', $comment); preg_match("|IP:(.*)|", $comment, $comment_author_IP); $comment_author_IP = trim($comment_author_IP[1]); $comment = preg_replace('|(\\n?IP:.*)|', '', $comment); preg_match("|URL:(.*)|", $comment, $comment_author_url); $comment_author_url = $wpdb->escape(trim($comment_author_url[1])); $comment = preg_replace('|(\\n?URL:.*)|', '', $comment); preg_match("|DATE:(.*)|", $comment, $comment_date); $comment_date = trim($comment_date[1]); $comment_date = date('Y-m-d H:i:s', strtotime($comment_date)); $comment = preg_replace('|(\\n?DATE:.*)|', '', $comment); $comment_content = $wpdb->escape(trim($comment)); $comment_content = str_replace('-----', '', $comment_content); // Check if it's already there if (!comment_exists($comment_author, $comment_date)) { $commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_url', 'comment_author_email', 'comment_author_IP', 'comment_date', 'comment_content'); $commentdata = wp_filter_comment($commentdata); wp_insert_comment($commentdata); $num_comments++; } } } if ($num_comments) { printf(__('(%s comments)'), $num_comments); } // Finally the pings // fix the double newline on the first one $pings[0] = str_replace("-----\n\n", "-----\n", $pings[0]); $pings = explode("-----\nPING:", $pings[0]); $num_pings = 0; foreach ($pings as $ping) { if ('' != trim($ping)) { // 'Author' preg_match("|BLOG NAME:(.*)|", $ping, $comment_author); $comment_author = $wpdb->escape(trim($comment_author[1])); $ping = preg_replace('|(\\n?BLOG NAME:.*)|', '', $ping); preg_match("|IP:(.*)|", $ping, $comment_author_IP); $comment_author_IP = trim($comment_author_IP[1]); $ping = preg_replace('|(\\n?IP:.*)|', '', $ping); preg_match("|URL:(.*)|", $ping, $comment_author_url); $comment_author_url = $wpdb->escape(trim($comment_author_url[1])); $ping = preg_replace('|(\\n?URL:.*)|', '', $ping); preg_match("|DATE:(.*)|", $ping, $comment_date); $comment_date = trim($comment_date[1]); $comment_date = date('Y-m-d H:i:s', strtotime($comment_date)); $ping = preg_replace('|(\\n?DATE:.*)|', '', $ping); preg_match("|TITLE:(.*)|", $ping, $ping_title); $ping_title = $wpdb->escape(trim($ping_title[1])); $ping = preg_replace('|(\\n?TITLE:.*)|', '', $ping); $comment_content = $wpdb->escape(trim($ping)); $comment_content = str_replace('-----', '', $comment_content); $comment_content = "<strong>{$ping_title}</strong>\n\n{$comment_content}"; $comment_type = 'trackback'; // Check if it's already there if (!comment_exists($comment_author, $comment_date)) { $commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_url', 'comment_author_email', 'comment_author_IP', 'comment_date', 'comment_content', 'comment_type'); $commentdata = wp_filter_comment($commentdata); wp_insert_comment($commentdata); $num_pings++; } } } if ($num_pings) { printf(__('(%s pings)'), $num_pings); } echo "</li>"; } flush(); } echo '</ol>'; wp_import_cleanup($this->id); echo '<h3>' . sprintf(__('All done. <a href="%s">Have fun!</a>'), get_option('home')) . '</h3>'; }
function options_page() { global $thesis_site, $thesis_data; $head = $thesis_site->head; $javascript = $thesis_site->javascript; $nav = $thesis_site->nav; $home = $thesis_site->home; $publishing = $thesis_site->publishing; $custom = $thesis_site->custom; $rtl = get_bloginfo('text_direction') == 'rtl' ? ' rtl' : ''; #wp echo "<script>jQuery.noConflict();function charCount(ctrlId, counterId){jQuery(counterId).val(jQuery(ctrlId).val().trim().length);}</script>\n"; echo "<div id=\"thesis_options\" class=\"wrap{$rtl}\">\n"; thesis_version_indicator(); thesis_options_title(__('Thesis Site Options', 'thesis')); thesis_options_nav(); thesis_options_status_check(); if (version_compare($thesis_site->version, thesis_version()) < 0) { ?> <form id="upgrade_needed" action="<?php echo admin_url('admin-post.php?action=thesis_upgrade'); ?> " method="post"> <h3><?php _e('Oooh, Exciting!', 'thesis'); ?> </h3> <p><?php _e('It’s time to upgrade your Thesis, which means there’s new awesomeness in your immediate future. Click the button below to fast-track your way to the awesomeness!', 'thesis'); ?> </p> <p><input type="submit" class="upgrade_button" id="teh_upgrade" name="upgrade" value="<?php _e('Upgrade Thesis', 'thesis'); ?> " /></p> </form> <?php } else { thesis_is_css_writable(); ?> <form class="thesis" action="<?php echo admin_url('admin-post.php?action=thesis_options'); ?> " method="post"> <div class="options_column"> <div class="options_module" id="document-head"> <h3><?php _e('Document Head', 'thesis'); ?> <code><head></code></h3> <div class="module_subsection"> <h4 class="module_switch"><a href="" title="<?php _e('Show/hide additional information', 'thesis'); ?> "><span class="pos">+</span><span class="neg">–</span></a><?php _e('Title Tag Settings', 'thesis'); ?> <code><title></code></h4> <div class="more_info"> <p><?php _e('As far as <acronym title="Search Engine Optimization">SEO</acronym> is concerned, this is the single most important element on your site. For all pages except the home page, Thesis will construct your <code><title></code> tags automatically according to the settings below, but you can override these settings by adding a custom <code><title></code> to any post or page via the post editing screen.', 'thesis'); ?> </p> <ul class="add_margin"> <li><input type="checkbox" id="head[title][branded]" name="head[title][branded]" value="1" <?php if ($head['title']['branded']) { echo 'checked="checked" '; } ?> /><label for="head[title][branded]"><?php _e('Append site name to page titles', 'thesis'); ?> </label></li> </ul> <p class="form_input add_margin"> <input type="text" class="text_input short" id="head[title][separator]" name="head[title][separator]" value="<?php echo $head['title']['separator'] ? urldecode($head['title']['separator']) : __('—', 'thesis'); ?> " /> <label for="head[title][separator]"><?php _e('Character separator in titles', 'thesis'); ?> </label> </p> <p class="tip"><?php printf(__('You can set your home page <code><title></code> tag in the Home Page SEO box on this page. For categories and tags, visit the <a href="%1$s">edit category</a> and <a href="%2$s">edit tag</a> pages within WordPress.', 'thesis'), admin_url('edit-tags.php?taxonomy=category'), admin_url('edit-tags.php')); ?> </p> </div> </div> <div class="module_subsection" id="robots-meta"> <h4 class="module_switch"><a href="" title="<?php _e('Show/hide additional information', 'thesis'); ?> "><span class="pos">+</span><span class="neg">–</span></a><?php _e('Robots Meta Tags', 'thesis'); ?> <code><meta></code></h4> <div class="more_info"> <div class="mini_module indented_module" id="robots-noindex"> <h5 class="module_switch"><a href="" title="<?php _e('Show/hide additional information', 'thesis'); ?> "><span class="pos">+</span><span class="neg">–</span></a><?php _e('Noindex', 'thesis'); ?> <code>noindex</code></h5> <div class="more_info"> <p><?php _e('Adding the <code>noindex</code> robot meta tag is a great way to fine-tune your site’s <acronym title="Search Engine Optimization">SEO</acronym> by streamlining the amount of pages that get indexed by the search engines. The options below will help you prevent the indexing of “bloat” pages that do nothing but dilute your search results and keep you from ranking as well as you should.', 'thesis'); ?> </p> <ul> <?php foreach ($head['meta']['robots']['noindex'] as $page_type => $value) { $checked = $value ? 'checked="checked" ' : ''; echo "\t\t\t\t\t\t\t\t\t" . '<li><input type="checkbox" id="head[meta][robots][noindex][' . $page_type . ']" name="head[meta][robots][noindex][' . $page_type . ']" value="1" ' . $checked . '/><label for="head[meta][robots][noindex][' . $page_type . ']">' . sprintf(__('<code>noindex</code> %s pages', 'thesis'), $page_type) . '</label></li>' . "\n"; } ?> </ul> </div> </div> <div class="mini_module indented_module" id="robots-nofollow"> <h5 class="module_switch"><a href="" title="<?php _e('Show/hide additional information', 'thesis'); ?> "><span class="pos">+</span><span class="neg">–</span></a><?php _e('Nofollow', 'thesis'); ?> <code>nofollow</code></h5> <div class="more_info"> <p><?php _e('The <code>nofollow</code> robot meta tag is another useful tool for nailing down your site’s <acronym title="Search Engine Optimization">SEO</acronym>. Links from pages with the <code>nofollow</code> meta tag won’t pass any juice.', 'thesis'); ?> </p> <ul> <?php foreach ($head['meta']['robots']['nofollow'] as $page_type => $value) { $checked = $value ? 'checked="checked" ' : ''; echo "\t\t\t\t\t\t\t\t\t" . '<li><input type="checkbox" id="head[meta][robots][nofollow][' . $page_type . ']" name="head[meta][robots][nofollow][' . $page_type . ']" value="1" ' . $checked . '/><label for="head[meta][robots][nofollow][' . $page_type . ']">' . sprintf(__('Add <code>nofollow</code> to %s pages', 'thesis'), $page_type) . '</label></li>' . "\n"; } ?> </ul> </div> </div> <div class="mini_module indented_module" id="robots-noarchive"> <h5 class="module_switch"><a href="" title="<?php _e('Show/hide additional information', 'thesis'); ?> "><span class="pos">+</span><span class="neg">–</span></a><?php _e('Noarchive', 'thesis'); ?> <code>noarchive</code></h5> <div class="more_info"> <p><?php _e('The <code>noarchive</code> robot meta tag prevents search engines and Internet archive services from saving cached versions of pages on your site. Generally, people use this to protect their privacy, but there are certainly times when having access to archived versions of your pages might prove useful.', 'thesis'); ?> </p> <ul> <?php foreach ($head['meta']['robots']['noarchive'] as $page_type => $value) { $checked = $value ? 'checked="checked" ' : ''; echo "\t\t\t\t\t\t\t\t\t" . '<li><input type="checkbox" id="head[meta][robots][noarchive][' . $page_type . ']" name="head[meta][robots][noarchive][' . $page_type . ']" value="1" ' . $checked . '/><label for="head[meta][robots][noarchive][' . $page_type . ']">' . sprintf(__('Add <code>noarchive</code> to %s pages', 'thesis'), $page_type) . '</label></li>' . "\n"; } ?> </ul> </div> </div> <div class="mini_module indented_module" id="robots-noodp"> <h5 class="module_switch"><a href="" title="<?php _e('Show/hide additional information', 'thesis'); ?> "><span class="pos">+</span><span class="neg">–</span></a><?php _e('Directory Tags', 'thesis'); ?> <code>noodp</code> <code>noydir</code></h5> <div class="more_info"> <p><?php _e('Using the <code>noodp</code> robot meta tag will prevent search engines from displaying Open Directory Project (DMOZ) listings in your meta descriptions. The <code>noydir</code> tag is pretty much the same, except that it only affects the Yahoo! Directory. Both of these options are sitewide.', 'thesis'); ?> </p> <ul> <li><input type="checkbox" id="head[meta][robots][noodp]" name="head[meta][robots][noodp]" value="1" <?php if ($head['meta']['robots']['noodp']) { echo 'checked="checked" '; } ?> /><label for="head[meta][robots][noodp]"><?php _e('Add <code>noodp</code> to your site', 'thesis'); ?> </label></li> <li><input type="checkbox" id="head[meta][robots][noydir]" name="head[meta][robots][noydir]" value="1" <?php if ($head['meta']['robots']['noydir']) { echo 'checked="checked" '; } ?> /><label for="head[meta][robots][noydir]"><?php _e('Add <code>noydir</code> to your site', 'thesis'); ?> </label></li> </ul> </div> </div> </div> </div> <div class="module_subsection"> <h4 class="module_switch"><a href="" title="<?php _e('Show/hide additional information', 'thesis'); ?> "><span class="pos">+</span><span class="neg">–</span></a><?php _e('Canonical <acronym title="Uniform Resource Locator">URL</acronym>s', 'thesis'); ?> </h4> <ul class="more_info"> <li><input type="checkbox" id="head[links][canonical]" name="head[links][canonical]" value="1" <?php if ($head['links']['canonical']) { echo 'checked="checked" '; } ?> /><label for="head[links][canonical]"><?php _e('Add canonical <acronym title="Uniform Resource Locator">URL</acronym>s to your site', 'thesis'); ?> </label></li> </ul> </div> <div class="module_subsection" id="syndication"> <h4 class="module_switch"><a href="" title="<?php _e('Show/hide additional information', 'thesis'); ?> "><span class="pos">+</span><span class="neg">–</span></a><?php _e('Syndication/Feed <acronym title="Uniform Resource Locator">URL</acronym>', 'thesis'); ?> </h4> <div class="more_info"> <p><?php printf(__('If you’re using a service like <a href="%s">Feedburner</a> to manage your <acronym title="Really Simple Syndication">RSS</acronym> feed, you should enter the <acronym title="Uniform Resource Locator">URL</acronym> of your feed in the box below. If you’d prefer to use the default WordPress feed, simply leave this box blank.', 'thesis'), 'http://www.feedburner.com/'); ?> </p> <p class="form_input"> <input type="text" class="text_input" id="head[feed][url]" name="head[feed][url]" value="<?php if ($head['feed']['url']) { echo stripslashes($head['feed']['url']); } ?> " /> <label for="head[feed][url]"><?php _e('Feed <acronym title="Uniform Resource Locator">URL</acronym> (including ‘http://’)', 'thesis'); ?> </label> </p> </div> </div> <div class="module_subsection"> <h4 class="module_switch"><a href="" title="<?php _e('Show/hide additional information', 'thesis'); ?> "><span class="pos">+</span><span class="neg">–</span></a><?php _e('Additional Scripts', 'thesis'); ?> </h4> <div class="more_info"> <p><?php printf(__('If you need to add scripts to your document <code><head></code>, you should enter them in the box below; however, if you’re adding stat-tracking code, you should add that to the <a href="%s">Stats and Scripts section below</a>.', 'thesis'), '#javascript-options'); ?> </p> <p class="form_input"> <label for="head[scripts]"><?php _e('Additional <code><head></code> scripts (code)', 'thesis'); ?> </label> <textarea class="scripts" id="head[scripts]" name="head[scripts]"><?php if ($head['scripts']) { echo $thesis_data->o_htmlentities($head['scripts']); } ?> </textarea> </p> </div> </div> </div> <div class="options_module" id="javascript-options"> <h3><?php _e('Stats Software/Scripts', 'thesis'); ?> </h3> <div class="module_subsection" id="javascript-scripts"> <h4 class="module_switch"><a href="" title="<?php _e('Show/hide additional information', 'thesis'); ?> "><span class="pos">+</span><span class="neg">–</span></a><?php _e('Stat and Tracking Scripts', 'thesis'); ?> </h4> <div class="more_info"> <p><?php _e('If you’ve got a stat-tracking script (from, say, Mint or Google Analytics), you’ll want to place it here. Anything you add here will be served after the <acronym title="HyperText Markup Language">HTML</acronym> on <em>every page of your site</em>. This is the preferred position because it prevents the scripts from interrupting the page load.', 'thesis'); ?> </p> <p class="form_input"> <label for="javascript[scripts]"><?php _e('Tracking scripts (include <code><script></code> tags!)', 'thesis'); ?> </label> <textarea class="scripts" id="javascript[scripts]" name="javascript[scripts]"><?php if ($javascript['scripts']) { echo $thesis_data->o_htmlentities($javascript['scripts']); } ?> </textarea> </p> </div> </div> </div> <div class="options_module" id="home-page-options"> <h3><?php _e('Custom Stylesheet Options', 'thesis'); ?> </h3> <div class="module_subsection"> <h4 class="module_switch"><a href="" title="<?php _e('Show/hide additional information', 'thesis'); ?> "><span class="pos">+</span><span class="neg">–</span></a><?php _e('Enable Stylesheet', 'thesis'); ?> </h4> <div class="more_info"> <p class="add_margin"><?php _e('The only reason to deselect this option is to reduce the total number of <code>http</code> requests your site makes because this will improve your page load speed. If you’re not using your custom stylesheet, then you may consider deselecting this option.', 'thesis'); ?> </p> <?php if (!file_exists(THESIS_CUSTOM)) { echo "\t\t\t\t\t\t<p class=\"tip add_margin\">" . __('Your custom stylesheet <strong>will not work</strong> until you rename your <code>/custom-sample</code> folder to <code>/custom</code>.', 'thesis') . "</p>\n"; } ?> <ul> <li><input type="checkbox" id="custom[stylesheet]" name="custom[stylesheet]" value="1" <?php if ($custom['stylesheet']) { echo 'checked="checked" '; } ?> /><label for="custom[stylesheet]"><?php _e('Enable custom stylesheet', 'thesis'); ?> </label></li> </ul> </div> </div> </div> </div> <div class="options_column"> <div class="options_module button_module"> <?php wp_nonce_field('thesis-update-site', '_wpnonce-thesis-update-site'); ?> <input type="submit" class="save_button" id="options_submit" name="submit" value="<?php thesis_save_button_text(); ?> " /> </div> <div class="options_module" id="thesis-nav-menu"> <h3><?php _e('Navigation Menu', 'thesis'); ?> </h3> <?php global $wp_version; if (version_compare($wp_version, '3', '>=')) { ?> <div class="module_subsection"> <h4 class="module_switch"><a href="" title="<?php _e('Show/hide additional information', 'thesis'); ?> "><span class="pos">+</span><span class="neg">–</span></a><?php _e('Select Menu Type', 'thesis'); ?> </h4> <div class="more_info"> <ul id="nav_switch"> <li><input type="radio" name="nav[type]" value="wp" <?php if ($nav['type'] == 'wp') { echo 'checked="checked" '; } ?> /><label><?php _e('WordPress nav menu', 'thesis'); ?> <a href="<?php echo admin_url("nav-menus.php"); ?> " target="_blank">[?]</a></label></li> <li><input type="radio" name="nav[type]" value="thesis" <?php if ($nav['type'] == 'thesis') { echo 'checked="checked" '; } ?> /><label><?php _e('Thesis nav menu', 'thesis'); ?> </label></li> </ul> </div> </div> <?php } ?> <div id="thesis_nav_controls"> <div class="module_subsection"> <h4 class="module_switch"><a href="" title="<?php _e('Show/hide additional information', 'thesis'); ?> "><span class="pos">+</span><span class="neg">–</span></a><?php _e('Pages', 'thesis'); ?> </h4> <div class="more_info"> <p><?php _e('Start by selecting the pages you want to include in your nav menu. Next, drag and drop the pages to change their display order (topmost item displays first), and if you <em>really</em> want to get crazy, you can even edit the display text on each item. <strong>Try it!</strong>', 'thesis'); ?> </p> <p><?php _e('Thesis features automatic dropdown menus, so if you have nested pages or categories, you’ll save space <em>and</em> gain style points with your slick new nav menu!', 'thesis'); ?> </p> <ul id="nav_pages" class="sortable add_margin"> <?php $pages =& get_pages('sort_column=post_parent,menu_order'); $active_pages = array(); if ($nav['pages']) { foreach ($nav['pages'] as $id => $nav_page) { $active_page = get_page($id); if (post_exists($active_page->post_title)) { $checked = $nav_page['show'] ? ' checked="checked"' : ''; $link_text = $nav['pages'][$id]['text'] != '' ? $thesis_data->o_htmlspecialchars($nav['pages'][$id]['text'], true) : $active_page->post_title; echo "\t\t\t\t\t\t\t<li><input class=\"checkbox\" type=\"checkbox\" id=\"nav[pages][{$id}][show]\" name=\"nav[pages][{$id}][show]\" value=\"1\"{$checked} /><input type=\"text\" class=\"text_input\" id=\"nav[pages][{$id}][text]\" name=\"nav[pages][{$id}][text]\" value=\"{$link_text}\" /></li>\n"; $active_pages[] = $id; } } } if ($pages) { foreach ($pages as $page) { if (!in_array($page->ID, $active_pages)) { $link_text = $nav['pages'][$page->ID]['text'] != '' ? $thesis_data->o_htmlentities($nav['pages'][$page->ID]['text'], true) : $page->post_title; echo "\t\t\t\t\t\t\t<li><input class=\"checkbox\" type=\"checkbox\" id=\"nav[pages][{$page->ID}][show]\" name=\"nav[pages][{$page->ID}][show]\" value=\"1\" /><input type=\"text\" class=\"text_input\" id=\"nav[pages][{$page->ID}][text]\" name=\"nav[pages][{$page->ID}][text]\" value=\"{$link_text}\" /></li>\n"; } } } ?> </ul> </div> </div> <div class="module_subsection"> <h4 class="module_switch"><a href="" title="<?php _e('Show/hide additional information', 'thesis'); ?> "><span class="pos">+</span><span class="neg">–</span></a><?php _e('Categories', 'thesis'); ?> </h4> <div class="more_info"> <p><?php _e('If you’d like to include category pages in your nav menu, simply select the appropriate categories from the list below (you can select more than one).', 'thesis'); ?> </p> <p class="form_input"> <select class="select_multiple" id="nav[categories]" name="nav[categories][]" multiple="multiple" size="1"> <option value="0"><?php _e('No category page links', 'thesis'); ?> </option> <?php $categories =& get_categories('type=post&orderby=name&hide_empty=0'); if ($categories) { $nav_category_pages = explode(',', $nav['categories']); foreach ($categories as $category) { $selected = in_array($category->cat_ID, $nav_category_pages) ? ' selected="selected"' : ''; echo "\t\t\t\t\t\t\t\t<option value=\"{$category->cat_ID}\"{$selected}>{$category->cat_name}</option>\n"; } } ?> </select> </p> </div> </div> <div class="module_subsection"> <h4 class="module_switch"><a href="" title="<?php _e('Show/hide additional information', 'thesis'); ?> "><span class="pos">+</span><span class="neg">–</span></a><?php _e('Add More Links', 'thesis'); ?> </h4> <div class="more_info"> <p><?php printf(__('You can insert additional navigation links on the <a href="%1$s">Manage Links</a> page. To ensure that things go smoothly, you should first <a href="%2$s">create a link category</a> solely for your navigation menu, and then make sure you place your new links in that category. Once you’ve done that, you can select your category below to include it in your nav menu.', 'thesis'), get_bloginfo('wpurl') . '/wp-admin/link-manager.php', get_bloginfo('wpurl') . '/wp-admin/edit-link-categories.php#addcat'); ?> </p> <p class="form_input"> <select id="nav[links]" name="nav[links]" size="1"> <option value="0"><?php _e('No additional links', 'thesis'); ?> </option> <?php $link_categories =& get_categories('type=link&hide_empty=0'); if ($link_categories) { foreach ($link_categories as $link_category) { $selected = $nav['links'] == $link_category->cat_ID ? ' selected="selected"' : ''; echo "\t\t\t\t\t\t\t\t<option value=\"{$link_category->cat_ID}\"{$selected}>{$link_category->cat_name}</option>\n"; } } ?> </select> </p> </div> </div> <div class="module_subsection"> <h4 class="module_switch"><a href="" title="<?php _e('Show/hide additional information', 'thesis'); ?> "><span class="pos">+</span><span class="neg">–</span></a><?php _e('Home Link', 'thesis'); ?> </h4> <div class="control_box more_info"> <ul class="control"> <li><input type="checkbox" id="nav[home][show]" name="nav[home][show]" value="1" <?php if ($nav['home']['show']) { echo 'checked="checked" '; } ?> /><label for="nav[home][show]"><?php _e('Show home link in nav menu', 'thesis'); ?> </label></li> </ul> <div class="dependent"> <p class="form_input add_margin"> <input type="text" id="nav[home][text]" name="nav[home][text]" value="<?php echo $thesis_data->o_htmlspecialchars(thesis_home_link_text(), true); ?> " /> <label for="nav[home][text]"><?php _e('home link text', 'thesis'); ?> </label> </p> <ul> <li><input type="checkbox" id="nav[home][nofollow]" name="nav[home][nofollow]" value="1" <?php if ($nav['home']['nofollow']) { echo 'checked="checked" '; } ?> /><label for="nav[home][nofollow]"><?php _e('Add <code>nofollow</code> to home link', 'thesis'); ?> </label></li> </ul> </div> </div> </div> <div class="module_subsection"> <h4 class="module_switch"><a href="" title="<?php _e('Show/hide additional information', 'thesis'); ?> "><span class="pos">+</span><span class="neg">–</span></a><?php _e('Feed Link', 'thesis'); ?> </h4> <div class="control_box more_info"> <ul class="control"> <li><input type="checkbox" id="nav[feed][show]" name="nav[feed][show]" value="1" <?php if ($nav['feed']['show']) { echo 'checked="checked" '; } ?> /><label for="nav[feed][show]"><?php _e('Show feed link in nav menu', 'thesis'); ?> </label></li> </ul> <div class="dependent"> <p class="form_input add_margin"> <input type="text" class="text_input" id="nav[feed][text]" name="nav[feed][text]" value="<?php echo $thesis_data->o_htmlspecialchars(thesis_feed_link_text(), true); ?> " /> <label for="nav[feed][text]"><?php _e('Change your feed link text', 'thesis'); ?> </label> </p> <ul> <li><input type="checkbox" id="nav[feed][nofollow]" name="nav[feed][nofollow]" value="1" <?php if ($nav['feed']['nofollow']) { echo 'checked="checked" '; } ?> /><label for="nav[feed][nofollow]"><?php _e('Add <code>nofollow</code> to feed link', 'thesis'); ?> </label></li> </ul> </div> </div> </div> </div> </div> <div class="options_module" id="home-page-options"> <h3><?php _e('Home Page <acronym title="Search Engine Optimization">SEO</acronym>', 'thesis'); ?> </h3> <div class="module_subsection"> <h4 class="module_switch"><a href="" title="<?php _e('Show/hide additional information', 'thesis'); ?> "><span class="pos">+</span><span class="neg">–</span></a><?php _e('Document Head', 'thesis'); ?> <code><head></code></h4> <div class="more_info"> <p class="form_input add_margin"> <input type="text" class="text_input" id="home_head_title" name="home[head][title]" value="<?php if ($home['head']['title']) { echo $thesis_data->o_htmlspecialchars($home['head']['title'], false, true); } ?> " /> <script>jQuery('#home_head_title').keyup(function(){charCount('#home_head_title', '#length_home_title');});</script> <label for="home[head][title]"><?php _e('home page <code><title></code> tag', 'thesis'); ?> <input type="text" readonly="readonly" class="counter" id="length_home_title" size="3" maxlength="3" value="0"></label> </p> <p class="form_input add_margin"> <textarea class="scripts" id="home_head_description" name="home[head][meta][description]"><?php if ($home['head']['meta']['description']) { echo $thesis_data->o_htmlspecialchars($home['head']['meta']['description'], false, true); } ?> </textarea> <script>jQuery('#home_head_description').keyup(function(){charCount('#home_head_description', '#length_home_description');});</script> <label for="home[head][meta][description]"><?php _e('home page <code><meta></code> description', 'thesis'); ?> <input type="text" readonly="readonly" class="counter" id="length_home_description" size="3" maxlength="3" value="0"></label> </p> <p class="form_input add_margin"> <input type="text" class="text_input" id="home[head][meta][keywords]" name="home[head][meta][keywords]" value="<?php if ($home['head']['meta']['keywords']) { echo $thesis_data->o_htmlspecialchars($home['head']['meta']['keywords'], false, true); } ?> " /> <label for="home[head][meta][keywords]"><?php _e('home page <code><meta></code> keywords', 'thesis'); ?> </label> </p> <ul> <li><input type="checkbox" id="home[head][meta][robots][noindex]" name="home[head][meta][robots][noindex]" value="1" <?php if ($home['head']['meta']['robots']['noindex']) { echo 'checked="checked" '; } ?> /><label for="home[head][meta][robots][noindex]"><?php _e('<code>noindex</code> this page', 'thesis'); ?> </label></li> <li><input type="checkbox" id="home[head][meta][robots][nofollow]" name="home[head][meta][robots][nofollow]" value="1" <?php if ($home['head']['meta']['robots']['nofollow']) { echo 'checked="checked" '; } ?> /><label for="home[head][meta][robots][nofollow]"><?php _e('<code>nofollow</code> this page', 'thesis'); ?> </label></li> <li><input type="checkbox" id="home[head][meta][robots][noarchive]" name="home[head][meta][robots][noarchive]" value="1" <?php if ($home['head']['meta']['robots']['noarchive']) { echo 'checked="checked" '; } ?> /><label for="home[head][meta][robots][noarchive]"><?php _e('<code>noarchive</code> this page', 'thesis'); ?> </label></li> </ul> </div> </div> </div> </div> <div class="options_column"> <div class="options_module" id="publishing-tools"> <h3><?php _e('Publishing Tools', 'thesis'); ?> </h3> <div class="module_subsection"> <h4 class="module_switch"><a href="" title="<?php _e('Show/hide additional information', 'thesis'); ?> "><span class="pos">+</span><span class="neg">–</span></a><?php _e('Windows Live Writer', 'thesis'); ?> </h4> <div class="more_info"> <ul> <li><input type="checkbox" id="publishing[wlw]" name="publishing[wlw]" value="1" <?php if ($publishing['wlw']) { echo 'checked="checked" '; } ?> /><label for="publishing[wlw]"><?php _e('Enable support for Windows Live Writer', 'thesis'); ?> </label></li> </ul> </div> </div> </div> <div class="options_module" id="save_button_control"> <div class="module_subsection"> <h4 class="module_switch"><a href="" title="<?php _e('Show/hide additional information', 'thesis'); ?> "><span class="pos">+</span><span class="neg">–</span></a><?php _e('Change Save Button Text', 'thesis'); ?> </h4> <p class="form_input more_info"> <input type="text" id="save_button_text" name="save_button_text" value="<?php if ($thesis_site->save_button_text) { echo $thesis_data->o_htmlspecialchars($thesis_site->save_button_text); } ?> " /> <label for="save_button_text"><?php _e('not recommended (heh)', 'thesis'); ?> </label> </p> </div> </div> </div> </form> <?php } ?> </div> <?php }
function posts2wp($posts = '') { // General Housekeeping global $wpdb; $count = 0; $dcposts2wpposts = array(); $cats = array(); // Do the Magic if (is_array($posts)) { echo '<p>' . __('Importing Posts...') . '<br /><br /></p>'; foreach ($posts as $post) { $count++; extract($post); // Set DotClear-to-WordPress status translation $stattrans = array(0 => 'draft', 1 => 'publish'); $comment_status_map = array(0 => 'closed', 1 => 'open'); //Can we do this more efficiently? $uinfo = get_userdatabylogin($user_id) ? get_userdatabylogin($user_id) : 1; $authorid = is_object($uinfo) ? $uinfo->ID : $uinfo; $Title = $wpdb->escape(csc($post_titre)); $post_content = textconv($post_content); $post_excerpt = ""; if ($post_chapo != "") { $post_excerpt = textconv($post_chapo); $post_content = $post_excerpt . "\n<!--more-->\n" . $post_content; } $post_excerpt = $wpdb->escape($post_excerpt); $post_content = $wpdb->escape($post_content); $post_status = $stattrans[$post_pub]; // Import Post data into WordPress if ($pinfo = post_exists($Title, $post_content)) { $ret_id = wp_insert_post(array('ID' => $pinfo, 'post_author' => $authorid, 'post_date' => $post_dt, 'post_date_gmt' => $post_dt, 'post_modified' => $post_upddt, 'post_modified_gmt' => $post_upddt, 'post_title' => $Title, 'post_content' => $post_content, 'post_excerpt' => $post_excerpt, 'post_status' => $post_status, 'post_name' => $post_titre_url, 'comment_status' => $comment_status_map[$post_open_comment], 'ping_status' => $comment_status_map[$post_open_tb], 'comment_count' => $post_nb_comment + $post_nb_trackback)); if (is_wp_error($ret_id)) { return $ret_id; } } else { $ret_id = wp_insert_post(array('post_author' => $authorid, 'post_date' => $post_dt, 'post_date_gmt' => $post_dt, 'post_modified' => $post_modified_gmt, 'post_modified_gmt' => $post_modified_gmt, 'post_title' => $Title, 'post_content' => $post_content, 'post_excerpt' => $post_excerpt, 'post_status' => $post_status, 'post_name' => $post_titre_url, 'comment_status' => $comment_status_map[$post_open_comment], 'ping_status' => $comment_status_map[$post_open_tb], 'comment_count' => $post_nb_comment + $post_nb_trackback)); if (is_wp_error($ret_id)) { return $ret_id; } } $dcposts2wpposts[$post_id] = $ret_id; // Make Post-to-Category associations $cats = array(); $category1 = get_category_by_slug($post_cat_name); $category1 = $category1->term_id; if ($cat1 = $category1) { $cats[1] = $cat1; } if (!empty($cats)) { wp_set_post_categories($ret_id, $cats); } } } // Store ID translation for later use add_option('dcposts2wpposts', $dcposts2wpposts); echo '<p>' . sprintf(__('Done! <strong>%1$s</strong> posts imported.'), $count) . '<br /><br /></p>'; return true; }
function import_post($post) { global $wpdb; // Make sure we haven't already imported this one if ($this->get_wp_post_ID($post['itemid'])) { return; } $user = wp_get_current_user(); $post_author = $user->ID; $post['security'] = !empty($post['security']) ? $post['security'] : ''; $post_status = 'private' == trim($post['security']) ? 'private' : 'publish'; // Only me $post_password = '******' == trim($post['security']) ? $this->protected_password : ''; // "Friends" via password // For some reason, LJ sometimes sends a date as "2004-04-1408:38:00" (no space btwn date/time) $post_date = $post['eventtime']; if (18 == strlen($post_date)) { $post_date = substr($post_date, 0, 10) . ' ' . substr($post_date, 10); } // Cleaning up and linking the title $post_title = isset($post['subject']) ? trim($post['subject']) : ''; $post_title = $this->translate_lj_user($post_title); // Translate it, but then we'll strip the link $post_title = strip_tags($post_title); // Can't have tags in the title in WP $post_title = $wpdb->escape($post_title); // Clean up content $post_content = $post['event']; $post_content = preg_replace_callback('|<(/?[A-Z]+)|', array(&$this, '_normalize_tag'), $post_content); // XHTMLize some tags $post_content = str_replace('<br>', '<br />', $post_content); $post_content = str_replace('<hr>', '<hr />', $post_content); // lj-cut ==> <!--more--> $post_content = preg_replace('|<lj-cut text="([^"]*)">|is', '<!--more $1-->', $post_content); $post_content = str_replace(array('<lj-cut>', '</lj-cut>'), array('<!--more-->', ''), $post_content); $first = strpos($post_content, '<!--more'); $post_content = substr($post_content, 0, $first + 1) . preg_replace('|<!--more(.*)?-->|sUi', '', substr($post_content, $first + 1)); // lj-user ==> a href $post_content = $this->translate_lj_user($post_content); //$post_content = force_balance_tags( $post_content ); $post_content = $wpdb->escape($post_content); // Handle any tags associated with the post $tags_input = !empty($post['props']['taglist']) ? $post['props']['taglist'] : ''; // Check if comments are closed on this post $comment_status = !empty($post['props']['opt_nocomments']) ? 'closed' : 'open'; echo '<li>'; if ($post_id = post_exists($post_title, $post_content, $post_date)) { printf(__('Post <strong>%s</strong> already exists.'), stripslashes($post_title)); } else { printf(__('Imported post <strong>%s</strong>...'), stripslashes($post_title)); $postdata = compact('post_author', 'post_date', 'post_content', 'post_title', 'post_status', 'post_password', 'tags_input', 'comment_status'); $post_id = wp_insert_post($postdata, true); if (is_wp_error($post_id)) { if ('empty_content' == $post_id->get_error_code()) { return; } // Silent skip on "empty" posts return $post_id; } if (!$post_id) { _e('Couldn’t get post ID (creating post failed!)'); echo '</li>'; return new WP_Error('insert_post_failed', __('Failed to create post.')); } // Handle all the metadata for this post $this->insert_postmeta($post_id, $post); } echo '</li>'; }
function get_archive() { global $wpdb; $output = '<h2>'.__('Importing Blogger archives into WordPress').'</h2>'; $did_one = false; $post_array = $posts = array(); foreach ( $this->import['blogs'][$_GET['blog']]['archives'] as $url => $status ) { $archivename = substr(basename($url),0,7); if ( $status || $did_one ) { $foo = 'bar'; // Do nothing. } else { // Import the selected month $postcount = 0; $skippedpostcount = 0; $commentcount = 0; $skippedcommentcount = 0; $status = __('in progress...'); $this->import['blogs'][$_GET['blog']]['archives']["$url"] = $status; update_option('import-blogger', $import); $archive = $this->get_blogger($url); if ( $archive['code'] > 200 ) continue; $posts = explode('<wordpresspost>', $archive['body']); for ($i = 1; $i < count($posts); $i = $i + 1) { $postparts = explode('<wordpresscomment>', $posts[$i]); $postinfo = explode('|W|P|', $postparts[0]); $post_date = $postinfo[0]; $post_content = $postinfo[2]; // Don't try to re-use the original numbers // because the new, longer numbers are too // big to handle as ints. //$post_number = $postinfo[3]; $post_title = ( $postinfo[4] != '' ) ? $postinfo[4] : $postinfo[3]; $post_author_name = $wpdb->escape(trim($postinfo[1])); $post_author_email = $postinfo[5] ? $postinfo[5] : '*****@*****.**'; if ( $this->lump_authors ) { // Ignore Blogger authors. Use the current user_ID for all posts imported. $post_author = $GLOBALS['user_ID']; } else { // Add a user for each new author encountered. if (! username_exists($post_author_name) ) { $user_login = $wpdb->escape($post_author_name); $user_email = $wpdb->escape($post_author_email); $user_password = substr(md5(uniqid(microtime())), 0, 6); $result = wp_create_user( $user_login, $user_password, $user_email ); $status.= sprintf('Registered user <strong>%s</strong>.', $user_login); $this->import['blogs'][$_GET['blog']]['newusers'][] = $user_login; } $userdata = get_userdatabylogin( $post_author_name ); $post_author = $userdata->ID; } $post_date = explode(' ', $post_date); $post_date_Ymd = explode('/', $post_date[0]); $postyear = $post_date_Ymd[2]; $postmonth = zeroise($post_date_Ymd[0], 2); $postday = zeroise($post_date_Ymd[1], 2); $post_date_His = explode(':', $post_date[1]); $posthour = zeroise($post_date_His[0], 2); $postminute = zeroise($post_date_His[1], 2); $postsecond = zeroise($post_date_His[2], 2); if (($post_date[2] == 'PM') && ($posthour != '12')) $posthour = $posthour + 12; else if (($post_date[2] == 'AM') && ($posthour == '12')) $posthour = '00'; $post_date = "$postyear-$postmonth-$postday $posthour:$postminute:$postsecond"; $post_content = addslashes($post_content); $post_content = str_replace(array('<br>','<BR>','<br/>','<BR/>','<br />','<BR />'), "\n", $post_content); // the XHTML touch... ;) $post_title = addslashes($post_title); $post_status = 'publish'; if ( $ID = post_exists($post_title, '', $post_date) ) { $post_array[$i]['ID'] = $ID; $skippedpostcount++; } else { $post_array[$i]['post'] = compact('post_author', 'post_content', 'post_title', 'post_category', 'post_author', 'post_date', 'post_status'); $post_array[$i]['comments'] = false; } // Import any comments attached to this post. if ($postparts[1]) : for ($j = 1; $j < count($postparts); $j = $j + 1) { $commentinfo = explode('|W|P|', $postparts[$j]); $comment_date = explode(' ', $commentinfo[0]); $comment_date_Ymd = explode('/', $comment_date[0]); $commentyear = $comment_date_Ymd[2]; $commentmonth = zeroise($comment_date_Ymd[0], 2); $commentday = zeroise($comment_date_Ymd[1], 2); $comment_date_His = explode(':', $comment_date[1]); $commenthour = zeroise($comment_date_His[0], 2); $commentminute = zeroise($comment_date_His[1], 2); $commentsecond = '00'; if (($comment_date[2] == 'PM') && ($commenthour != '12')) $commenthour = $commenthour + 12; else if (($comment_date[2] == 'AM') && ($commenthour == '12')) $commenthour = '00'; $comment_date = "$commentyear-$commentmonth-$commentday $commenthour:$commentminute:$commentsecond"; $comment_author = addslashes(strip_tags($commentinfo[1])); if ( strpos($commentinfo[1], 'a href') ) { $comment_author_parts = explode('"', htmlentities($commentinfo[1])); $comment_author_url = $comment_author_parts[1]; } else $comment_author_url = ''; $comment_content = $commentinfo[2]; $comment_content = str_replace(array('<br>','<BR>','<br/>','<BR/>','<br />','<BR />'), "\n", $comment_content); $comment_approved = 1; if ( comment_exists($comment_author, $comment_date) ) { $skippedcommentcount++; } else { $comment = compact('comment_author', 'comment_author_url', 'comment_date', 'comment_content', 'comment_approved'); $post_array[$i]['comments'][$j] = wp_filter_comment($comment); } $commentcount++; } endif; $postcount++; } if ( count($post_array) ) { krsort($post_array); foreach($post_array as $post) { if ( ! $comment_post_ID = $post['ID'] ) $comment_post_ID = wp_insert_post($post['post']); if ( $post['comments'] ) { foreach ( $post['comments'] as $comment ) { $comment['comment_post_ID'] = $comment_post_ID; wp_insert_comment($comment); } } } } $status = sprintf(__('%s post(s) parsed, %s skipped...'), $postcount, $skippedpostcount).' '. sprintf(__('%s comment(s) parsed, %s skipped...'), $commentcoun, $skippedcommentcount).' '. ' <strong>'.__('Done').'</strong>'; $import = $this->import; $import['blogs'][$_GET['blog']]['archives']["$url"] = $status; update_option('import-blogger', $import); $did_one = true; } $output.= "<p>$archivename $status</p>\n"; } if ( ! $did_one ) $this->set_next_step(7); die( $this->refresher(1000) . $output ); }
function options_page() { global $thesis_site, $thesis_design; $head = $thesis_site->head; $javascript = $thesis_site->javascript; $nav = $thesis_site->nav; $comments = $thesis_site->comments; $display = $thesis_site->display; ?> <div id="thesis_options" class="wrap<?php if (get_bloginfo('text_direction') == 'rtl') { echo ' rtl'; } ?> "> <?php thesis_version_indicator(); thesis_options_title(__('Thesis Site Options', 'thesis')); thesis_options_nav(); thesis_options_status_check(); if (version_compare($thesis_site->version, thesis_version()) != 0) { ?> <form id="upgrade_needed" action="<?php echo admin_url('admin-post.php?action=thesis_upgrade'); ?> " method="post"> <h3><?php _e('Oooh, Exciting!', 'thesis'); ?> </h3> <p><?php _e('It’s time to upgrade your Thesis, which means there’s new awesomeness in your immediate future. Click the button below to fast-track your way to the awesomeness!', 'thesis'); ?> </p> <p><input type="submit" class="upgrade_button" id="teh_upgrade" name="upgrade" value="<?php _e('Upgrade Thesis', 'thesis'); ?> " /></p> </form> <?php } else { thesis_is_css_writable(); ?> <form class="thesis" action="<?php echo admin_url('admin-post.php?action=thesis_options'); ?> " method="post"> <div class="options_column"> <div class="options_module" id="document-head"> <h3><?php _e('Document Head', 'thesis'); ?> <code><head></code></h3> <div class="module_subsection"> <h4 class="module_switch"><a href="" title="<?php _e('Show/hide additional information', 'thesis'); ?> "><span class="pos">+</span><span class="neg">–</span></a><?php _e('Title Tag Settings', 'thesis'); ?> <code><title></code></h4> <div class="more_info"> <p><?php _e('As far as <acronym title="Search Engine Optimization">SEO</acronym> is concerned, this is the single most important element on your site. For all pages except the home page, Thesis will construct your <code><title></code> tags automatically according to the settings below, but you can override these settings by adding a custom <code><title></code> to any post or page via the post editing screen.', 'thesis'); ?> </p> <ul class="add_margin"> <li><input type="checkbox" id="head[title][branded]" name="head[title][branded]" value="1" <?php if ($head['title']['branded']) { echo 'checked="checked" '; } ?> /><label for="head[title][branded]"><?php _e('Append site name to page titles', 'thesis'); ?> </label></li> </ul> <p class="form_input add_margin"> <input type="text" class="text_input short" id="head[title][separator]" name="head[title][separator]" value="<?php echo $head['title']['separator'] ? urldecode($head['title']['separator']) : '—'; ?> " /> <label for="head[title][separator]"><?php _e('Character separator in titles', 'thesis'); ?> </label> </p> <p class="tip"><?php printf(__('To set the <code><title></code> tags on your home page, category pages, or tag pages, visit the new <a href="%s">Page Options screen</a>.', 'thesis'), admin_url('admin.php?page=thesis-pages')); ?> </p> </div> </div> <div class="module_subsection" id="robots-meta"> <h4 class="module_switch"><a href="" title="<?php _e('Show/hide additional information', 'thesis'); ?> "><span class="pos">+</span><span class="neg">–</span></a><?php _e('Robots Meta Tags', 'thesis'); ?> <code><meta></code></h4> <div class="more_info"> <div class="mini_module indented_module" id="robots-noindex"> <h5 class="module_switch"><a href="" title="<?php _e('Show/hide additional information', 'thesis'); ?> "><span class="pos">+</span><span class="neg">–</span></a><?php _e('Noindex Tag', 'thesis'); ?> <code>noindex</code></h5> <div class="more_info"> <p><?php _e('Adding the <code>noindex</code> robot meta tag is a great way to fine-tune your site’s <acronym title="Search Engine Optimization">SEO</acronym> by streamlining the amount of pages that get indexed by the search engines. The options below will help you prevent the indexing of “bloat” pages that do nothing but dilute your search results and keep you from ranking as well as you should.', 'thesis'); ?> </p> <ul> <?php foreach ($head['meta']['robots']['noindex'] as $page_type => $value) { $checked = $value ? 'checked="checked" ' : ''; echo "\t\t\t\t\t\t\t\t\t" . '<li><input type="checkbox" id="head[meta][robots][noindex][' . $page_type . ']" name="head[meta][robots][noindex][' . $page_type . ']" value="1" ' . $checked . '/><label for="head[meta][robots][noindex][' . $page_type . ']">' . sprintf(__('Add <code>noindex</code> to %s pages', 'thesis'), $page_type) . '</label></li>' . "\n"; } ?> </ul> </div> </div> <div class="mini_module indented_module" id="robots-nofollow"> <h5 class="module_switch"><a href="" title="<?php _e('Show/hide additional information', 'thesis'); ?> "><span class="pos">+</span><span class="neg">–</span></a><?php _e('Nofollow Tag', 'thesis'); ?> <code>nofollow</code></h5> <div class="more_info"> <p><?php _e('The <code>nofollow</code> robot meta tag is another useful tool for nailing down your site’s <acronym title="Search Engine Optimization">SEO</acronym>. Links from pages with the <code>nofollow</code> meta tag won’t pass any juice.', 'thesis'); ?> </p> <ul> <?php foreach ($head['meta']['robots']['nofollow'] as $page_type => $value) { $checked = $value ? 'checked="checked" ' : ''; echo "\t\t\t\t\t\t\t\t\t" . '<li><input type="checkbox" id="head[meta][robots][nofollow][' . $page_type . ']" name="head[meta][robots][nofollow][' . $page_type . ']" value="1" ' . $checked . '/><label for="head[meta][robots][nofollow][' . $page_type . ']">' . sprintf(__('Add <code>nofollow</code> to %s pages', 'thesis'), $page_type) . '</label></li>' . "\n"; } ?> </ul> </div> </div> <div class="mini_module indented_module" id="robots-noarchive"> <h5 class="module_switch"><a href="" title="<?php _e('Show/hide additional information', 'thesis'); ?> "><span class="pos">+</span><span class="neg">–</span></a><?php _e('Noarchive Tag', 'thesis'); ?> <code>noarchive</code></h5> <div class="more_info"> <p><?php _e('The <code>noarchive</code> robot meta tag prevents search engines and Internet archive services from saving cached versions of pages on your site. Generally, people use this to protect their privacy, but there are certainly times when having access to archived versions of your pages might prove useful.', 'thesis'); ?> </p> <ul> <?php foreach ($head['meta']['robots']['noarchive'] as $page_type => $value) { $checked = $value ? 'checked="checked" ' : ''; echo "\t\t\t\t\t\t\t\t\t" . '<li><input type="checkbox" id="head[meta][robots][noarchive][' . $page_type . ']" name="head[meta][robots][noarchive][' . $page_type . ']" value="1" ' . $checked . '/><label for="head[meta][robots][noarchive][' . $page_type . ']">' . sprintf(__('Add <code>noarchive</code> to %s pages', 'thesis'), $page_type) . '</label></li>' . "\n"; } ?> </ul> </div> </div> <div class="mini_module indented_module" id="robots-noodp"> <h5 class="module_switch"><a href="" title="<?php _e('Show/hide additional information', 'thesis'); ?> "><span class="pos">+</span><span class="neg">–</span></a><?php _e('Directory Tags', 'thesis'); ?> <code>noodp</code> <code>noydir</code></h5> <div class="more_info"> <p><?php _e('Using the <code>noodp</code> robot meta tag will prevent search engines from displaying Open Directory Project (DMOZ) listings in your meta descriptions. The <code>noydir</code> tag is pretty much the same, except that it only affects the Yahoo! Directory. Both of these options are sitewide.', 'thesis'); ?> </p> <ul> <li><input type="checkbox" id="head[meta][robots][noodp]" name="head[meta][robots][noodp]" value="1" <?php if ($head['meta']['robots']['noodp']) { echo 'checked="checked" '; } ?> /><label for="head[meta][robots][noodp]"><?php _e('Add <code>noodp</code> to your site', 'thesis'); ?> </label></li> <li><input type="checkbox" id="head[meta][robots][noydir]" name="head[meta][robots][noydir]" value="1" <?php if ($head['meta']['robots']['noydir']) { echo 'checked="checked" '; } ?> /><label for="head[meta][robots][noydir]"><?php _e('Add <code>noydir</code> to your site', 'thesis'); ?> </label></li> </ul> </div> </div> </div> </div> <div class="module_subsection"> <h4 class="module_switch"><a href="" title="<?php _e('Show/hide additional information', 'thesis'); ?> "><span class="pos">+</span><span class="neg">–</span></a><?php _e('Canonical <acronym title="Uniform Resource Locator">URL</acronym>s', 'thesis'); ?> </h4> <ul class="more_info"> <li><input type="checkbox" id="head[links][canonical]" name="head[links][canonical]" value="1" <?php if ($head['links']['canonical']) { echo 'checked="checked" '; } ?> /><label for="head[links][canonical]"><?php _e('Add canonical <acronym title="Uniform Resource Locator">URL</acronym>s to your site', 'thesis'); ?> </label></li> </ul> </div> <div class="module_subsection" id="syndication"> <h4 class="module_switch"><a href="" title="<?php _e('Show/hide additional information', 'thesis'); ?> "><span class="pos">+</span><span class="neg">–</span></a><?php _e('Syndication/Feed <acronym title="Uniform Resource Locator">URL</acronym>', 'thesis'); ?> </h4> <div class="more_info"> <p><?php printf(__('If you’re using a service like <a href="%s">Feedburner</a> to manage your <acronym title="Really Simple Syndication">RSS</acronym> feed, you should enter the <acronym title="Uniform Resource Locator">URL</acronym> of your feed in the box below. If you’d prefer to use the default WordPress feed, simply leave this box blank.', 'thesis'), 'http://www.feedburner.com/'); ?> </p> <p class="form_input"> <input type="text" class="text_input" id="head[feed][url]" name="head[feed][url]" value="<?php if ($head['feed']['url']) { echo $head['feed']['url']; } ?> " /> <label for="head[feed][url]"><?php _e('Feed <acronym title="Uniform Resource Locator">URL</acronym> (including ‘http://’)', 'thesis'); ?> </label> </p> </div> </div> <div class="module_subsection"> <h4 class="module_switch"><a href="" title="<?php _e('Show/hide additional information', 'thesis'); ?> "><span class="pos">+</span><span class="neg">–</span></a><?php _e('Additional Scripts', 'thesis'); ?> </h4> <div class="more_info"> <p><?php printf(__('If you need to add scripts to your document <code><head></code>, you should enter them in the box below; however, if you’re adding stat-tracking code, you should add that to the <a href="%s">Stats and Scripts section below</a>.', 'thesis'), '#javascript-options'); ?> </p> <p class="form_input"> <label for="head[scripts]"><?php _e('Additional <code><head></code> scripts (code)', 'thesis'); ?> </label> <textarea class="scripts" id="head[scripts]" name="head[scripts]"><?php if ($head['scripts']) { thesis_massage_code($head['scripts']); } ?> </textarea> </p> </div> </div> </div> <div class="options_module" id="javascript-options"> <h3><?php _e('Stats Software/Scripts', 'thesis'); ?> </h3> <div class="module_subsection" id="javascript-scripts"> <h4 class="module_switch"><a href="" title="<?php _e('Show/hide additional information', 'thesis'); ?> "><span class="pos">+</span><span class="neg">–</span></a><?php _e('Stat and Tracking Scripts', 'thesis'); ?> </h4> <div class="more_info"> <p><?php _e('If you’ve got a stat-tracking script (from, say, Mint or Google Analytics), you’ll want to place it here. Anything you add here will be served after the <acronym title="HyperText Markup Language">HTML</acronym> on <em>every page of your site</em>. This is the preferred position because it prevents the scripts from interrupting the page load.', 'thesis'); ?> </p> <p class="form_input"> <label for="javascript[scripts]"><?php _e('Tracking scripts (include <code><script></code> tags!)', 'thesis'); ?> </label> <textarea class="scripts" id="javascript[scripts]" name="javascript[scripts]"><?php if ($javascript['scripts']) { thesis_massage_code($javascript['scripts']); } ?> </textarea> </p> </div> </div> </div> </div> <div class="options_column"> <div class="options_module" id="display-options"> <h3><?php _e('Display Options', 'thesis'); ?> </h3> <div class="module_subsection"> <h4 class="module_switch"><a href="" title="<?php _e('Show/hide additional information', 'thesis'); ?> "><span class="pos">+</span><span class="neg">–</span></a><?php _e('Header', 'thesis'); ?> </h4> <ul class="more_info"> <li><input type="checkbox" id="display[header][title]" name="display[header][title]" value="1" <?php if ($display['header']['title']) { echo 'checked="checked" '; } ?> /><label for="display[header][title]"><?php _e('Show site name in header', 'thesis'); ?> </label></li> <li><input type="checkbox" id="display[header][tagline]" name="display[header][tagline]" value="1" <?php if ($display['header']['tagline']) { echo 'checked="checked" '; } ?> /><label for="display[header][tagline]"><?php _e('Show site tagline in header', 'thesis'); ?> </label></li> </ul> </div> <div class="module_subsection"> <h4 class="module_switch"><a href="" title="<?php _e('Show/hide additional information', 'thesis'); ?> "><span class="pos">+</span><span class="neg">–</span></a><?php _e('Bylines', 'thesis'); ?> </h4> <div class="more_info"> <div class="control_box"> <ul class="control no_margin"> <li><input type="checkbox" id="display[byline][author][show]" name="display[byline][author][show]" value="1" <?php if ($display['byline']['author']['show']) { echo 'checked="checked" '; } ?> /><label for="display[byline][author][show]"><?php _e('Show author name in <strong>post</strong> byline', 'thesis'); ?> </label></li> </ul> <ul class="dependent"> <li><input type="checkbox" id="display[byline][author][link]" name="display[byline][author][link]" value="1" <?php if ($display['byline']['author']['link']) { echo 'checked="checked" '; } ?> /><label for="display[byline][author][link]"><?php _e('Link author names to archives', 'thesis'); ?> </label></li> <li><input type="checkbox" id="display[byline][author][nofollow]" name="display[byline][author][nofollow]" value="1" <?php if ($display['byline']['author']['nofollow']) { echo 'checked="checked" '; } ?> /><label for="display[byline][author][nofollow]"><?php _e('Add <code>nofollow</code> to author links', 'thesis'); ?> </label></li> </ul> </div> <ul> <li><input type="checkbox" id="display[byline][date][show]" name="display[byline][date][show]" value="1" <?php if ($display['byline']['date']['show']) { echo 'checked="checked" '; } ?> /><label for="display[byline][date][show]"><?php _e('Show published-on date in <strong>post</strong> byline', 'thesis'); ?> </label></li> <li><input type="checkbox" id="display[byline][page][author]" name="display[byline][page][author]" value="1" <?php if ($display['byline']['page']['author']) { echo 'checked="checked" '; } ?> /><label for="display[byline][page][author]"><?php _e('Show author name in <strong>page</strong> byline', 'thesis'); ?> </label></li> <li><input type="checkbox" id="display[byline][page][date]" name="display[byline][page][date]" value="1" <?php if ($display['byline']['page']['date']) { echo 'checked="checked" '; } ?> /><label for="display[byline][page][date]"><?php _e('Show published-on date in <strong>page</strong> byline', 'thesis'); ?> </label></li> <li><input type="checkbox" id="display[byline][num_comments][show]" name="display[byline][num_comments][show]" value="1" <?php if ($display['byline']['num_comments']['show']) { echo 'checked="checked" '; } ?> /><label for="display[byline][num_comments][show]"><?php _e('Show number of comments in byline', 'thesis'); ?> </label></li> <li><input type="checkbox" id="display[byline][categories][show]" name="display[byline][categories][show]" value="1" <?php if ($display['byline']['categories']['show']) { echo 'checked="checked" '; } ?> /><label for="display[byline][categories][show]"><?php _e('Show <strong>post</strong> categories', 'thesis'); ?> </label></li> </ul> </div> </div> <div class="module_subsection"> <h4 class="module_switch"><a href="" title="<?php _e('Show/hide additional information', 'thesis'); ?> "><span class="pos">+</span><span class="neg">–</span></a><?php _e('Posts', 'thesis'); ?> </h4> <div class="more_info"> <p><?php _e('The display setting you select below only affects your <strong>features</strong>; teasers (if you’re using them) are always displayed in excerpt format.', 'thesis'); ?> </p> <ul class="add_margin"> <li><input type="radio" name="display[posts][excerpts]" value="0" <?php if (!$display['posts']['excerpts']) { echo 'checked="checked" '; } ?> /><label><?php _e('Display full post content', 'thesis'); ?> </label></li> <li><input type="radio" name="display[posts][excerpts]" value="1" <?php if ($display['posts']['excerpts']) { echo 'checked="checked" '; } ?> /><label><?php _e('Display post excerpts', 'thesis'); ?> </label></li> </ul> <p class="label_note"><?php _e('“Read More” link', 'thesis'); ?> </p> <p><?php _e('This is the clickthrough text on home and archive pages that appears on any post where you use the <code><!--more--></code> tag:', 'thesis'); ?> </p> <p class="form_input add_margin"> <input type="text" class="text_input" id="display[posts][read_more_text]" name="display[posts][read_more_text]" value="<?php echo thesis_read_more_text(); ?> " /> <label for="display[posts][read_more_text]"><?php _e('clickthrough text', 'thesis'); ?> </label> </p> <p class="label_note"><?php _e('Single entry pages', 'thesis'); ?> </p> <ul> <li><input type="checkbox" id="display[posts][nav]" name="display[posts][nav]" value="1" <?php if ($display['posts']['nav']) { echo 'checked="checked" '; } ?> /><label for="display[posts][nav]"><?php _e('Show previous/next post links', 'thesis'); ?> </label></li> </ul> </div> </div> <div class="module_subsection"> <h4 class="module_switch"><a href="" title="<?php _e('Show/hide additional information', 'thesis'); ?> "><span class="pos">+</span><span class="neg">–</span></a><?php _e('Archives', 'thesis'); ?> </h4> <div class="more_info"> <p><?php _e('Select a display format for your archive pages:', 'thesis'); ?> </p> <ul> <li><input type="radio" name="display[archives][style]" value="titles" <?php if ($display['archives']['style'] == 'titles') { echo 'checked="checked" '; } ?> /><label><?php _e('Titles only', 'thesis'); ?> </label></li> <li><input type="radio" name="display[archives][style]" value="teasers" <?php if ($display['archives']['style'] == 'teasers') { echo 'checked="checked" '; } ?> /><label><?php _e('Everything’s a teaser!', 'thesis'); ?> </label></li> <li><input type="radio" name="display[archives][style]" value="content" <?php if ($display['archives']['style'] == 'content') { echo 'checked="checked" '; } ?> /><label><?php _e('Same as your home page', 'thesis'); ?> </label></li> <li><input type="radio" name="display[archives][style]" value="excerpts" <?php if ($display['archives']['style'] == 'excerpts') { echo 'checked="checked" '; } ?> /><label><?php _e('Post excerpts', 'thesis'); ?> </label></li> </ul> </div> </div> <div class="module_subsection"> <h4 class="module_switch"><a href="" title="<?php _e('Show/hide additional information', 'thesis'); ?> "><span class="pos">+</span><span class="neg">–</span></a><?php _e('Comments', 'thesis'); ?> </h4> <div class="more_info"> <ul> <li><input type="checkbox" id="comments[disable_pages]" name="comments[disable_pages]" value="1" <?php if ($comments['disable_pages']) { echo 'checked="checked" '; } ?> /><label for="comments[disable_pages]"><?php _e('Disable comments on all <strong>pages</strong>', 'thesis'); ?> </label></li> <li><input type="checkbox" id="comments[show_closed]" name="comments[show_closed]" value="1" <?php if ($comments['show_closed']) { echo 'checked="checked" '; } ?> /><label for="comments[show_closed]"><?php _e('If comments are closed, display a message', 'thesis'); ?> </label></li> </ul> </div> </div> <div class="module_subsection"> <h4 class="module_switch"><a href="" title="<?php _e('Show/hide additional information', 'thesis'); ?> "><span class="pos">+</span><span class="neg">–</span></a><?php _e('Tagging', 'thesis'); ?> </h4> <ul class="more_info"> <li><input type="checkbox" id="display[tags][single]" name="display[tags][single]" value="1" <?php if ($display['tags']['single']) { echo 'checked="checked" '; } ?> /><label for="display[tags][single]"><?php _e('Show tags on single entry pages', 'thesis'); ?> </label></li> <li><input type="checkbox" id="display[tags][index]" name="display[tags][index]" value="1" <?php if ($display['tags']['index']) { echo 'checked="checked" '; } ?> /><label for="display[tags][index]"><?php _e('Show tags on index and archives pages', 'thesis'); ?> </label></li> <li><input type="checkbox" id="display[tags][nofollow]" name="display[tags][nofollow]" value="1" <?php if ($display['tags']['nofollow']) { echo 'checked="checked" '; } ?> /><label for="display[tags][nofollow]"><?php _e('Add <code>nofollow</code> to tag links', 'thesis'); ?> </label></li> </ul> </div> <div class="module_subsection"> <h4 class="module_switch"><a href="" title="<?php _e('Show/hide additional information', 'thesis'); ?> "><span class="pos">+</span><span class="neg">–</span></a><?php _e('Sidebars', 'thesis'); ?> </h4> <ul class="more_info"> <li><input type="checkbox" id="display[sidebars][default_widgets]" name="display[sidebars][default_widgets]" value="1" <?php if ($display['sidebars']['default_widgets']) { echo 'checked="checked" '; } ?> /><label for="display[sidebars][default_widgets]"><?php _e('Show default sidebar widgets', 'thesis'); ?> </label></li> </ul> </div> <div class="module_subsection"> <h4 class="module_switch"><a href="" title="<?php _e('Show/hide additional information', 'thesis'); ?> "><span class="pos">+</span><span class="neg">–</span></a><?php _e('Administration', 'thesis'); ?> </h4> <div class="more_info"> <ul> <li><input type="checkbox" id="display[admin][edit_post]" name="display[admin][edit_post]" value="1" <?php if ($display['admin']['edit_post']) { echo 'checked="checked" '; } ?> /><label for="display[admin][edit_post]"><?php _e('Show edit post links', 'thesis'); ?> </label></li> <li><input type="checkbox" id="display[admin][link]" name="display[admin][link]" value="1" <?php if ($display['admin']['link']) { echo 'checked="checked" '; } ?> /><label><?php _e('Show admin link in footer', 'thesis'); ?> </label></li> </ul> </div> </div> </div> </div> <div class="options_column"> <div class="options_module button_module"> <input type="submit" class="save_button" id="options_submit" name="submit" value="<?php thesis_save_button_text(); ?> " /> </div> <div class="options_module" id="thesis-nav-menu"> <h3><?php _e('Navigation Menu', 'thesis'); ?> </h3> <div class="module_subsection"> <h4 class="module_switch"><a href="" title="<?php _e('Show/hide additional information', 'thesis'); ?> "><span class="pos">+</span><span class="neg">–</span></a><?php _e('Pages', 'thesis'); ?> </h4> <div class="more_info"> <p><?php _e('Start by selecting the pages you want to include in your nav menu. Next, drag and drop the pages to change their display order (topmost item displays first), and if you <em>really</em> want to get crazy, you can even edit the display text on each item. <strong>Try it!</strong>', 'thesis'); ?> </p> <p><?php _e('Thesis features automatic dropdown menus, so if you have nested pages or categories, you’ll save space <em>and</em> gain style points with your slick new nav menu!', 'thesis'); ?> </p> <ul id="nav_pages" class="sortable add_margin"> <?php $pages =& get_pages('sort_column=post_parent,menu_order'); $active_pages = array(); if ($nav['pages']) { foreach ($nav['pages'] as $id => $nav_page) { $active_page = get_page($id); if (post_exists($active_page->post_title)) { $checked = $nav_page['show'] ? ' checked="checked"' : ''; $link_text = $nav['pages'][$id]['text'] != '' ? $nav['pages'][$id]['text'] : $active_page->post_title; echo "\t\t\t\t\t\t\t<li><input class=\"checkbox\" type=\"checkbox\" id=\"nav[pages][{$id}][show]\" name=\"nav[pages][{$id}][show]\" value=\"1\"{$checked} /><input type=\"text\" class=\"text_input\" id=\"nav[pages][{$id}][text]\" name=\"nav[pages][{$id}][text]\" value=\"{$link_text}\" /></li>\n"; $active_pages[] = $id; } } } if ($pages) { foreach ($pages as $page) { if (!in_array($page->ID, $active_pages)) { $link_text = $nav['pages'][$page->ID]['text'] != '' ? $nav['pages'][$page->ID]['text'] : $page->post_title; echo "\t\t\t\t\t\t\t<li><input class=\"checkbox\" type=\"checkbox\" id=\"nav[pages][{$page->ID}][show]\" name=\"nav[pages][{$page->ID}][show]\" value=\"1\" /><input type=\"text\" class=\"text_input\" id=\"nav[pages][{$page->ID}][text]\" name=\"nav[pages][{$page->ID}][text]\" value=\"{$link_text}\" /></li>\n"; } } } ?> </ul> </div> </div> <div class="module_subsection"> <h4 class="module_switch"><a href="" title="<?php _e('Show/hide additional information', 'thesis'); ?> "><span class="pos">+</span><span class="neg">–</span></a><?php _e('Categories', 'thesis'); ?> </h4> <div class="more_info"> <p><?php _e('If you’d like to include category pages in your nav menu, simply select the appropriate categories from the list below (you can select more than one).', 'thesis'); ?> </p> <p class="form_input"> <select class="select_multiple" id="nav[categories]" name="nav[categories][]" multiple="multiple" size="1"> <option value="0"><?php _e('No category page links', 'thesis'); ?> </option> <?php $categories =& get_categories('type=post&orderby=name&hide_empty=0'); if ($categories) { $nav_category_pages = explode(',', $nav['categories']); foreach ($categories as $category) { $selected = in_array($category->cat_ID, $nav_category_pages) ? ' selected="selected"' : ''; echo "\t\t\t\t\t\t\t\t<option value=\"{$category->cat_ID}\"{$selected}>{$category->cat_name}</option>\n"; } } ?> </select> </p> </div> </div> <div class="module_subsection"> <h4 class="module_switch"><a href="" title="<?php _e('Show/hide additional information', 'thesis'); ?> "><span class="pos">+</span><span class="neg">–</span></a><?php _e('Add More Links', 'thesis'); ?> </h4> <div class="more_info"> <p><?php printf(__('You can insert additional navigation links on the <a href="%1$s">Manage Links</a> page. To ensure that things go smoothly, you should first <a href="%2$s">create a link category</a> solely for your navigation menu, and then make sure you place your new links in that category. Once you’ve done that, you can select your category below to include it in your nav menu.', 'thesis'), get_bloginfo('wpurl') . '/wp-admin/link-manager.php', get_bloginfo('wpurl') . '/wp-admin/edit-link-categories.php#addcat'); ?> </p> <p class="form_input"> <select id="nav[links]" name="nav[links]" size="1"> <option value="0"><?php _e('No additional links', 'thesis'); ?> </option> <?php $link_categories =& get_categories('type=link&hide_empty=0'); if ($link_categories) { foreach ($link_categories as $link_category) { $selected = $nav['links'] == $link_category->cat_ID ? ' selected="selected"' : ''; echo "\t\t\t\t\t\t\t\t<option value=\"{$link_category->cat_ID}\"{$selected}>{$link_category->cat_name}</option>\n"; } } ?> </select> </p> </div> </div> <div class="module_subsection"> <h4 class="module_switch"><a href="" title="<?php _e('Show/hide additional information', 'thesis'); ?> "><span class="pos">+</span><span class="neg">–</span></a><?php _e('Home Link', 'thesis'); ?> </h4> <div class="control_box more_info"> <ul class="control"> <li><input type="checkbox" id="nav[home][show]" name="nav[home][show]" value="1" <?php if ($nav['home']['show']) { echo 'checked="checked" '; } ?> /><label for="nav[home][show]"><?php _e('Show home link in nav menu', 'thesis'); ?> </label></li> </ul> <div class="dependent"> <p class="form_input add_margin"> <input type="text" id="nav[home][text]" name="nav[home][text]" value="<?php echo thesis_home_link_text(); ?> " /> <label for="nav[home][text]"><?php _e('home link text', 'thesis'); ?> </label> </p> <ul> <li><input type="checkbox" id="nav[home][nofollow]" name="nav[home][nofollow]" value="1" <?php if ($nav['home']['nofollow']) { echo 'checked="checked" '; } ?> /><label for="nav[home][nofollow]"><?php _e('Add <code>nofollow</code> to home link', 'thesis'); ?> </label></li> </ul> </div> </div> </div> <div class="module_subsection"> <h4 class="module_switch"><a href="" title="<?php _e('Show/hide additional information', 'thesis'); ?> "><span class="pos">+</span><span class="neg">–</span></a><?php _e('Feed Link in Nav Menu', 'thesis'); ?> </h4> <div class="control_box more_info"> <ul class="control"> <li><input type="checkbox" id="nav[feed][show]" name="nav[feed][show]" value="1" <?php if ($nav['feed']['show']) { echo 'checked="checked" '; } ?> /><label for="nav[feed][show]"><?php _e('Show feed link in nav menu', 'thesis'); ?> </label></li> </ul> <div class="dependent"> <p class="form_input add_margin"> <input type="text" class="text_input" id="nav[feed][text]" name="nav[feed][text]" value="<?php echo thesis_feed_link_text(); ?> " /> <label for="nav[feed][text]"><?php _e('Change your feed link text', 'thesis'); ?> </label> </p> <ul> <li><input type="checkbox" id="nav[feed][nofollow]" name="nav[feed][nofollow]" value="1" <?php if ($nav['feed']['nofollow']) { echo 'checked="checked" '; } ?> /><label for="nav[feed][nofollow]"><?php _e('Add <code>nofollow</code> to feed link', 'thesis'); ?> </label></li> </ul> </div> </div> </div> </div> <div class="options_module" id="save_button_control"> <div class="module_subsection"> <h4 class="module_switch"><a href="" title="<?php _e('Show/hide additional information', 'thesis'); ?> "><span class="pos">+</span><span class="neg">–</span></a><?php _e('Change Save Button Text', 'thesis'); ?> </h4> <p class="form_input more_info"> <input type="text" id="save_button_text" name="save_button_text" value="<?php if ($thesis_site->save_button_text) { echo $thesis_site->save_button_text; } ?> " /> <label for="save_button_text"><?php _e('not recommended (heh)', 'thesis'); ?> </label> </p> </div> </div> </div> </form> <?php } ?> </div> <?php }
function save_post(&$post, &$comments, &$pings) { // Reset the counter set_time_limit(30); $post = get_object_vars($post); $post = add_magic_quotes($post); $post = (object) $post; if ($post_id = post_exists($post->post_title, '', $post->post_date)) { echo '<li>'; printf(__('Post <em>%s</em> already exists.'), stripslashes($post->post_title)); } else { echo '<li>'; printf(__('Importing post <em>%s</em>...'), stripslashes($post->post_title)); if ('' != trim($post->extended)) { $post->post_content .= "\n<!--more-->\n{$post->extended}"; } $post->post_author = $this->checkauthor($post->post_author); //just so that if a post already exists, new users are not created by checkauthor $post_id = wp_insert_post($post); if (is_wp_error($post_id)) { return $post_id; } // Add categories. if (0 != count($post->categories)) { wp_create_categories($post->categories, $post_id); } // Add tags or keywords if (1 < strlen($post->post_keywords)) { // Keywords exist. printf(__('<br />Adding tags <i>%s</i>...'), stripslashes($post->post_keywords)); wp_add_post_tags($post_id, $post->post_keywords); } } $num_comments = 0; foreach ($comments as $comment) { $comment = get_object_vars($comment); $comment = add_magic_quotes($comment); if (!comment_exists($comment['comment_author'], $comment['comment_date'])) { $comment['comment_post_ID'] = $post_id; $comment = wp_filter_comment($comment); wp_insert_comment($comment); $num_comments++; } } if ($num_comments) { printf(' ' . __ngettext('(%s comment)', '(%s comments)', $num_comments), $num_comments); } $num_pings = 0; foreach ($pings as $ping) { $ping = get_object_vars($ping); $ping = add_magic_quotes($ping); if (!comment_exists($ping['comment_author'], $ping['comment_date'])) { $ping['comment_content'] = "<strong>{$ping['title']}</strong>\n\n{$ping['comment_content']}"; $ping['comment_post_ID'] = $post_id; $ping = wp_filter_comment($ping); wp_insert_comment($ping); $num_pings++; } } if ($num_pings) { printf(' ' . __ngettext('(%s ping)', '(%s pings)', $num_pings), $num_pings); } echo "</li>"; //ob_flush();flush(); }
/** * Does the post exist? * * @param array $data Post data to check against. * @return int|bool Existing post ID if it exists, false otherwise. */ protected function post_exists($data) { // Constant-time lookup if we prefilled $exists_key = $data['guid']; if ($this->options['prefill_existing_posts']) { return isset($this->exists['post'][$exists_key]) ? $this->exists['post'][$exists_key] : false; } // No prefilling, but might have already handled it if (isset($this->exists['post'][$exists_key])) { return $this->exists['post'][$exists_key]; } // Still nothing, try post_exists, and cache it $exists = post_exists($data['post_title'], $data['post_content'], $data['post_date']); $this->exists['post'][$exists_key] = $exists; return $exists; }
function cherry_plugin_import_posts() { $nonce = $_POST['nonce']; if (!wp_verify_nonce($nonce, 'import_ajax-nonce')) { exit('instal_error'); } if (session_id() != "import_xml") { session_name("import_xml"); session_start(); } do_action('cherry_plugin_import_posts'); $_SESSION['url_remap'] = array(); $_SESSION['featured_images'] = array(); $_SESSION['attachment_posts'] = array(); $_SESSION['processed_posts'] = array(); $posts_array = $_SESSION['posts']; $posts_array = apply_filters('wp_import_posts', $posts_array); $attachment_posts = array(); foreach ($posts_array as $post) { $post = apply_filters('wp_import_post_data_raw', $post); if (!post_type_exists($post['post_type'])) { // Failed to import do_action('wp_import_post_exists', $post); continue; } if (isset($_SESSION['processed_posts'][$post['post_id']]) && !empty($post['post_id'])) { continue; } if ($post['status'] == 'auto-draft') { continue; } if ('nav_menu_item' == $post['post_type']) { continue; } //!!!!$post_type_object = get_post_type_object( $post['post_type'] ); $post_exists = post_exists($post['post_title'], '', $post['post_date']); if ($post_exists && get_post_type($post_exists) == $post['post_type']) { // already exists $comment_post_ID = $post_id = $post_exists; } else { $post_parent = (int) $post['post_parent']; if ($post_parent) { // if we already know the parent, map it to the new local ID if (isset($_SESSION['processed_posts'][$post_parent])) { $post_parent = $_SESSION['processed_posts'][$post_parent]; // otherwise record the parent for later } else { $_SESSION['post_orphans'][intval($post['post_id'])] = $post_parent; $post_parent = 0; } } $author = (int) get_current_user_id(); $postdata = array('import_id' => $post['post_id'], 'post_author' => $author, 'post_date' => $post['post_date'], 'post_date_gmt' => $post['post_date_gmt'], 'post_content' => $post['post_content'], 'post_excerpt' => $post['post_excerpt'], 'post_title' => $post['post_title'], 'post_status' => $post['status'], 'post_name' => $post['post_name'], 'comment_status' => $post['comment_status'], 'ping_status' => $post['ping_status'], 'guid' => $post['guid'], 'post_parent' => $post_parent, 'menu_order' => $post['menu_order'], 'post_type' => $post['post_type'], 'post_password' => $post['post_password']); $original_post_ID = $post['post_id']; $postdata = apply_filters('wp_import_post_data_processed', $postdata, $post); if ('attachment' == $postdata['post_type']) { array_push($attachment_posts, $post); } if ('attachment' != $postdata['post_type']) { ini_set('max_execution_time', -1); set_time_limit(0); $comment_post_ID = $post_id = wp_insert_post($postdata, true); do_action('wp_import_insert_post', $post_id, $original_post_ID, $postdata, $post); if (is_wp_error($post_id)) { // Failed to import continue; } if ($post['is_sticky'] == 1) { stick_post($post_id); } // map pre-import ID to local ID $_SESSION['processed_posts'][intval($post['post_id'])] = intval($post_id); if (!isset($post['terms'])) { $post['terms'] = array(); } $post['terms'] = apply_filters('wp_import_post_terms', $post['terms'], $post_id, $post); // add categories, tags and other terms if (!empty($post['terms'])) { $terms_to_set = array(); foreach ($post['terms'] as $term) { // back compat with WXR 1.0 map 'tag' to 'post_tag' $taxonomy = 'tag' == $term['domain'] ? 'post_tag' : $term['domain']; $term_exists = term_exists($term['slug'], $taxonomy); $term_id = is_array($term_exists) ? $term_exists['term_id'] : $term_exists; if (!$term_id) { $t = wp_insert_term($term['name'], $taxonomy, array('slug' => $term['slug'])); if (!is_wp_error($t)) { $term_id = $t['term_id']; do_action('cherry_plugin_import_insert_term', $t, $term, $post_id, $post); } else { // Failed to import do_action('cherry_plugin_import_insert_term_failed', $t, $term, $post_id, $post); continue; } } $terms_to_set[$taxonomy][] = intval($term_id); } foreach ($terms_to_set as $tax => $ids) { $tt_ids = wp_set_post_terms($post_id, $ids, $tax); do_action('wp_import_set_post_terms', $tt_ids, $ids, $tax, $post_id, $post); } unset($post['terms'], $terms_to_set); } if (!isset($post['comments'])) { $post['comments'] = array(); } $post['comments'] = apply_filters('wp_import_post_comments', $post['comments'], $post_id, $post); // add/update comments if (!empty($post['comments'])) { $num_comments = 0; $inserted_comments = array(); foreach ($post['comments'] as $comment) { $comment_id = $comment['comment_id']; $newcomments[$comment_id]['comment_post_ID'] = $comment_post_ID; $newcomments[$comment_id]['comment_author'] = $comment['comment_author']; $newcomments[$comment_id]['comment_author_email'] = $comment['comment_author_email']; $newcomments[$comment_id]['comment_author_IP'] = $comment['comment_author_IP']; $newcomments[$comment_id]['comment_author_url'] = $comment['comment_author_url']; $newcomments[$comment_id]['comment_date'] = $comment['comment_date']; $newcomments[$comment_id]['comment_date_gmt'] = $comment['comment_date_gmt']; $newcomments[$comment_id]['comment_content'] = $comment['comment_content']; $newcomments[$comment_id]['comment_approved'] = $comment['comment_approved']; $newcomments[$comment_id]['comment_type'] = $comment['comment_type']; $newcomments[$comment_id]['comment_parent'] = $comment['comment_parent']; $newcomments[$comment_id]['commentmeta'] = isset($comment['commentmeta']) ? $comment['commentmeta'] : array(); if (isset($processed_authors[$comment['comment_user_id']])) { $newcomments[$comment_id]['user_id'] = $processed_authors[$comment['comment_user_id']]; } } ksort($newcomments); foreach ($newcomments as $key => $comment) { // if this is a new post we can skip the comment_exists() check if (!$post_exists || !comment_exists($comment['comment_author'], $comment['comment_date'])) { if (isset($inserted_comments[$comment['comment_parent']])) { $comment['comment_parent'] = $inserted_comments[$comment['comment_parent']]; } $comment = wp_filter_comment($comment); $inserted_comments[$key] = wp_insert_comment($comment); do_action('cherry_plugin_import_insert_comment', $inserted_comments[$key], $comment, $comment_post_ID, $post); foreach ($comment['commentmeta'] as $meta) { $value = maybe_unserialize($meta['value']); add_comment_meta($inserted_comments[$key], $meta['key'], $value); } $num_comments++; } } unset($newcomments, $inserted_comments, $post['comments']); } if (!isset($post['postmeta'])) { $post['postmeta'] = array(); } $post['postmeta'] = apply_filters('wp_import_post_meta', $post['postmeta'], $post_id, $post); // add/update post meta if (isset($post['postmeta'])) { foreach ($post['postmeta'] as $meta) { $key = apply_filters('import_post_meta_key', $meta['key']); $value = false; if ('_edit_last' == $key) { if (isset($processed_authors[intval($meta['value'])])) { $value = $processed_authors[intval($meta['value'])]; } else { $key = false; } } if ($key) { // export gets meta straight from the DB so could have a serialized string if (!$value) { $value = maybe_unserialize($meta['value']); } ini_set('max_execution_time', -1); set_time_limit(0); add_post_meta($post_id, $key, $value); do_action('cherry_plugin_import_post_meta', $post_id, $key, $value); // if the post has a featured image, take note of this in case of remap if ('_thumbnail_id' == $key) { $_SESSION['featured_images'][$post_id] = (int) $value; } } } } } } } $_SESSION['attachment_posts'] = $attachment_posts; exit('import_menu_item'); }
function cpm_action_create_missing_posts() { global $comicpress_manager, $comicpress_manager_admin; $all_post_dates = array(); foreach ($comicpress_manager->query_posts() as $comic_post) { $all_post_dates[] = date(CPM_DATE_FORMAT, strtotime($comic_post->post_date)); } $all_post_dates = array_unique($all_post_dates); $duplicate_posts_within_creation = array(); $posts_created = array(); $thumbnails_written = array(); $thumbnails_not_written = array(); $invalid_filenames = array(); $duplicate_posts = array(); $new_thumbnails_not_needed = array(); $execution_time = ini_get("max_execution_time"); $max_posts_imported = (int) ($execution_time / 2); $imported_post_count = 0; $safe_exit = false; if (strtotime($_POST['time']) === false) { $comicpress_manager->warnings[] = sprintf(__('<strong>There was an error in the post time (%1$s)</strong>. The time is not parseable by strtotime().', 'comicpress-manager'), $_POST['time']); } else { foreach ($comicpress_manager->comic_files as $comic_file) { $comic_file = pathinfo($comic_file, PATHINFO_BASENAME); if (($result = $comicpress_manager->breakdown_comic_filename($comic_file)) !== false) { extract($result, EXTR_PREFIX_ALL, 'filename'); $ok_to_create_post = !in_array($result['date'], $all_post_dates); $show_duplicate_post_message = false; $post_id = null; if (isset($duplicate_posts_within_creation[$result['date']])) { $ok_to_create_post = false; $show_duplicate_post_message = true; $post_id = $duplicate_posts_within_creation[$result['date']]; } if ($ok_to_create_post) { if (isset($_POST['duplicate_check'])) { $ok_to_create_post = ($post_id = post_exists($post_title, $post_content, $post_date)) == 0; } } else { if (!isset($_POST['duplicate_check'])) { $ok_to_create_post = true; } } if ($ok_to_create_post) { if (($post_hash = $comicpress_manager->generate_post_hash($filename_date, $filename_converted_title)) !== false) { if (!is_null($post_id = wp_insert_post($post_hash))) { $imported_post_count++; $posts_created[] = get_post($post_id, ARRAY_A); $date = date(CPM_DATE_FORMAT, strtotime($filename_date)); $all_post_dates[] = $date; $duplicate_posts_within_creation[$date] = $post_id; foreach (array('hovertext', 'transcript') as $field) { if (!empty($_POST["{$field}-to-use"])) { update_post_meta($post_id, $field, $_POST["{$field}-to-use"]); } } if (isset($_POST['thumbnails'])) { $wrote_thumbnail = $comicpress_manager_admin->write_thumbnail($comicpress_manager->path . '/' . $comic_file, $comic_file); if (!is_null($wrote_thumbnail)) { if ($wrote_thumbnail) { $thumbnails_written[] = $comic_file; } else { $thumbnails_not_written[] = $comic_file; } } else { $new_thumbnails_not_needed[] = $comic_file; } } } } else { $invalid_filenames[] = $comic_file; } } else { if ($show_duplicate_post_message) { $duplicate_posts[] = array(get_post($post_id, ARRAY_A), $comic_file); } } } if ($imported_post_count >= $max_posts_imported) { $safe_exit = true; break; } } } $comicpress_manager->import_safe_exit = $safe_exit; if ($safe_exit) { $comicpress_manager->messages[] = __("<strong>Import safely exited before you ran out of execution time.</strong> Scroll down to continue creating missing posts.", 'comicpress-manager'); } if (count($posts_created) > 0) { $comicpress_manager_admin->display_operation_messages(compact('invalid_filenames', 'thumbnails_written', 'thumbnails_not_written', 'posts_created', 'duplicate_posts', 'new_thumbnails_not_needed')); } else { $comicpress_manager->messages[] = __("<strong>No new posts needed to be created.</strong>", 'comicpress-manager'); } }
function do_importer_exporter() { $submit = null; $count = 0; $post_exists = null; $post_warning = null; global $aioseop_options, $aiosp, $aioseop_module_list; if (isset($_REQUEST['nonce-aioseop'])) { $nonce = $_REQUEST['nonce-aioseop']; } $post_fields = array('keywords', 'description', 'title', 'meta', 'disable', 'disable', 'disable_analytics', 'titleatr', 'menulabel', 'togglekeywords'); if (!empty($_FILES['aiosp_importer_exporter_import_submit']['tmp_name'])) { $submit = 'Import'; } if (!empty($_REQUEST['export_submit'])) { $submit = 'Export'; } if ($submit != null && wp_verify_nonce($nonce, 'aioseop-nonce')) { switch ($submit) { case 'Import': try { // Parses export file $file = $this->get_sanitized_file($_FILES['aiosp_importer_exporter_import_submit']['tmp_name']); $section = array(); $section_label = null; foreach ($file as $line_number => $line) { $line = trim($line); $matches = array(); if (empty($line)) { continue; } if ($line[0] == ';') { continue; } if (preg_match("/^\\[(\\S+)\\]\$/", $line, $label)) { $section_label = strval($label[1]); if ($section_label == 'post_data') { $count++; } if (!isset($section[$section_label])) { $section[$section_label] = array(); } } elseif (preg_match("/^(\\S+)\\s*=\\s*'(.*)'\$/", $line, $matches)) { if ($section_label == 'post_data') { $section[$section_label][$count][$matches[1]] = $matches[2]; } else { $section[$section_label][$matches[1]] = $matches[2]; } } elseif (preg_match("/^(\\S+)\\s*=\\s*NULL\$/", $line, $matches)) { if ($section_label == 'post_data') { $section[$section_label][$count][$matches[1]] = null; } else { $section[$section_label][$matches[1]] = null; } } else { $this->warnings[] = sprintf(__('<b>Warning:</b> Line not matched: <b>"%s"</b>, On Line: <b>%s</b>', 'all-in-one-seo-pack'), $line, $line_number); } } // Updates Plugin Settings if (is_array($section)) { foreach ($section as $label => $module_options) { if (is_array($module_options)) { foreach ($module_options as $key => $value) { // Updates Post Data if ($label == 'post_data') { $post_exists = post_exists($module_options[$key]['post_title'], '', $module_options[$key]['post_date']); $target = get_post($post_exists); if (!empty($module_options[$key]['post_type']) && $post_exists != null) { if (is_array($value)) { foreach ($value as $field_name => $field_value) { if (substr($field_name, 1, 7) == 'aioseop') { if ($value) { update_post_meta($target->ID, $field_name, maybe_unserialize($field_value)); } else { delete_post_meta($target->ID, $field_name); } } } } $post_exists = null; } else { $target_title = $module_options[$key]['post_title']; $post_warning = sprintf(__('<b>Warning:</b> This following post could not be found: <b>"%s"</b>', 'all-in-one-seo-pack'), $target_title); } if ($post_warning != null) { $this->warnings[] = $post_warning; $post_warning = null; } // Updates Module Settings } else { $module_options[$key] = str_replace(array("\\'", '\\n', '\\r'), array("'", "\n", "\r"), maybe_unserialize($value)); } } // Updates Module Settings $this->update_class_option($module_options, $label); } } } } catch (Exception $e) { $this->warnings[] = $e->getMessage(); } // Shows all errors found if (!empty($this->warnings)) { add_action($this->prefix . 'settings_header', array($this, 'show_import_warnings'), 5); } break; case 'Export': // Creates Files Contents $settings_file = 'settings_aioseop.ini'; $buf = '; ' . __('Settings export file for All in One SEO Pack', ' all-in-one-seo-pack') . "\n"; // Adds all settings to settings file $buf = $aiosp->settings_export($buf); $buf = apply_filters('aioseop_export_settings', $buf); // Sends File to browser $strlength = strlen($buf); header('Content-type: application/ini'); header("Content-Disposition:\r\n\t\t\t\t\t\t\t\tattachment; filename={$settings_file}"); header('Content-Length: ' . $strlength); echo $buf; die; break; } } }
<?php require_once '../../load.php'; if (!isset($_POST['edit_post_btn']) || !isset($_POST['post_id']) || !post_exists($_GET['post_id']) || !is_logged_in()) { header('Location: ../index.php?page=all_posts'); die; } $post_title = mysqli_escape_string($conn, $_POST['post_title']); $post_content = mysqli_escape_string($conn, $_POST['post_content']); $category_id = (int) $_POST['category_name']; $post_id = (int) $_POST['post_id']; $update_query = "UPDATE posts\n\t\tSET\n\tpost_title='{$post_title}',\n\tpost_content='{$post_content}',\n\tcategory_id={$category_id}\n\t\n\tWHERE\n\tpost_id={$post_id}"; if (mysqli_query($conn, $update_query)) { mysqli_close($conn); header('location: ../?page=all_posts&msg=Post was successfully Updated'); } else { // unsuccessfull // echo mysqli_error($conn); // die(); mysqli_close($conn); header('location: ../?page=all_posts&msg=There was some error in updating post. Please try agian later.'); }
function import_posts() { global $wpdb, $current_user; set_magic_quotes_runtime(0); $importdata = file($this->file); // Read the file into an array $importdata = implode('', $importdata); // squish it $importdata = str_replace(array ("\r\n", "\r"), "\n", $importdata); preg_match_all('|<entry>(.*?)</entry>|is', $importdata, $posts); $posts = $posts[1]; unset($importdata); echo '<ol>'; foreach ($posts as $post) { flush(); preg_match('|<subject>(.*?)</subject>|is', $post, $post_title); $post_title = $wpdb->escape(trim($post_title[1])); if ( empty($post_title) ) { preg_match('|<itemid>(.*?)</itemid>|is', $post, $post_title); $post_title = $wpdb->escape(trim($post_title[1])); } preg_match('|<eventtime>(.*?)</eventtime>|is', $post, $post_date); $post_date = strtotime($post_date[1]); $post_date = gmdate('Y-m-d H:i:s', $post_date); preg_match('|<event>(.*?)</event>|is', $post, $post_content); $post_content = str_replace(array ('<![CDATA[', ']]>'), '', trim($post_content[1])); $post_content = $this->unhtmlentities($post_content); // Clean up content $post_content = preg_replace('|<(/?[A-Z]+)|e', "'<' . strtolower('$1')", $post_content); $post_content = str_replace('<br>', '<br />', $post_content); $post_content = str_replace('<hr>', '<hr />', $post_content); $post_content = $wpdb->escape($post_content); $post_author = $current_user->ID; $post_status = 'publish'; echo '<li>'; if ($post_id = post_exists($post_title, $post_content, $post_date)) { printf(__('Post <i>%s</i> already exists.'), stripslashes($post_title)); } else { printf(__('Importing post <i>%s</i>...'), stripslashes($post_title)); $postdata = compact('post_author', 'post_date', 'post_content', 'post_title', 'post_status'); $post_id = wp_insert_post($postdata); if (!$post_id) { _e("Couldn't get post ID"); echo '</li>'; break; } } preg_match_all('|<comment>(.*?)</comment>|is', $post, $comments); $comments = $comments[1]; if ( $comments ) { $comment_post_ID = (int) $post_id; $num_comments = 0; foreach ($comments as $comment) { preg_match('|<event>(.*?)</event>|is', $comment, $comment_content); $comment_content = str_replace(array ('<![CDATA[', ']]>'), '', trim($comment_content[1])); $comment_content = $this->unhtmlentities($comment_content); // Clean up content $comment_content = preg_replace('|<(/?[A-Z]+)|e', "'<' . strtolower('$1')", $comment_content); $comment_content = str_replace('<br>', '<br />', $comment_content); $comment_content = str_replace('<hr>', '<hr />', $comment_content); $comment_content = $wpdb->escape($comment_content); preg_match('|<eventtime>(.*?)</eventtime>|is', $comment, $comment_date); $comment_date = trim($comment_date[1]); $comment_date = date('Y-m-d H:i:s', strtotime($comment_date)); preg_match('|<name>(.*?)</name>|is', $comment, $comment_author); $comment_author = $wpdb->escape(trim($comment_author[1])); preg_match('|<email>(.*?)</email>|is', $comment, $comment_author_email); $comment_author_email = $wpdb->escape(trim($comment_author_email[1])); $comment_approved = 1; // Check if it's already there if (!comment_exists($comment_author, $comment_date)) { $commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_email', 'comment_date', 'comment_content', 'comment_approved'); $commentdata = wp_filter_comment($commentdata); wp_insert_comment($commentdata); $num_comments++; } } } if ( $num_comments ) { echo ' '; printf(__('(%s comments)'), $num_comments); } echo '</li>'; flush(); ob_flush(); } echo '</ol>'; }
function import() { global $wpdb; $wpvarstoreset = array('gmpath', 'archivespath', 'lastentry'); for ($i = 0; $i < count($wpvarstoreset); $i += 1) { $wpvar = $wpvarstoreset[$i]; if (!isset(${$wpvar})) { if (empty($_POST["{$wpvar}"])) { if (empty($_GET["{$wpvar}"])) { ${$wpvar} = ''; } else { ${$wpvar} = $_GET["{$wpvar}"]; } } else { ${$wpvar} = $_POST["{$wpvar}"]; } } } if (!chdir($archivespath)) { wp_die(sprintf(__("Wrong path, %s\ndoesn't exist\non the server"), $archivespath)); } if (!chdir($gmpath)) { wp_die(sprintf(__("Wrong path, %s\ndoesn't exist\non the server"), $gmpath)); } $this->header(); ?> <p><?php _e('The importer is running...'); ?> </p> <ul> <li><?php _e('importing users...'); ?> <ul><?php chdir($gmpath); $userbase = file("gm-authors.cgi"); foreach ($userbase as $user) { $userdata = explode("|", $user); $user_ip = "127.0.0.1"; $user_domain = "localhost"; $user_browser = "server"; $s = $userdata[4]; $user_joindate = substr($s, 6, 4) . "-" . substr($s, 0, 2) . "-" . substr($s, 3, 2) . " 00:00:00"; $user_login = $wpdb->escape($userdata[0]); $pass1 = $wpdb->escape($userdata[1]); $user_nickname = $wpdb->escape($userdata[0]); $user_email = $wpdb->escape($userdata[2]); $user_url = $wpdb->escape($userdata[3]); $user_joindate = $wpdb->escape($user_joindate); $user_id = username_exists($user_login); if ($user_id) { printf('<li>' . __('user %s') . '<strong>' . __('Already exists') . '</strong></li>', "<em>{$user_login}</em>"); $this->gmnames[$userdata[0]] = $user_id; continue; } $user_info = array("user_login" => "{$user_login}", "user_pass" => "{$pass1}", "user_nickname" => "{$user_nickname}", "user_email" => "{$user_email}", "user_url" => "{$user_url}", "user_ip" => "{$user_ip}", "user_domain" => "{$user_domain}", "user_browser" => "{$user_browser}", "dateYMDhour" => "{$user_joindate}", "user_level" => "1", "user_idmode" => "nickname"); $user_id = wp_insert_user($user_info); $this->gmnames[$userdata[0]] = $user_id; printf('<li>' . __('user %s...') . ' <strong>' . __('Done') . '</strong></li>', "<em>{$user_login}</em>"); } ?> </ul><strong><?php _e('Done'); ?> </strong></li> <li><?php _e('importing posts, comments, and karma...'); ?> <br /><ul><?php chdir($archivespath); for ($i = 0; $i <= $lastentry; $i = $i + 1) { $entryfile = ""; if ($i < 10000000) { $entryfile .= "0"; if ($i < 1000000) { $entryfile .= "0"; if ($i < 100000) { $entryfile .= "0"; if ($i < 10000) { $entryfile .= "0"; if ($i < 1000) { $entryfile .= "0"; if ($i < 100) { $entryfile .= "0"; if ($i < 10) { $entryfile .= "0"; } } } } } } } $entryfile .= "{$i}"; if (is_file($entryfile . ".cgi")) { $entry = file($entryfile . ".cgi"); $postinfo = explode("|", $entry[0]); $postmaincontent = $this->gm2autobr($entry[2]); $postmorecontent = $this->gm2autobr($entry[3]); $post_author = trim($wpdb->escape($postinfo[1])); $post_title = $this->gm2autobr($postinfo[2]); printf('<li>' . __('entry # %s : %s : by %s'), $entryfile, $post_title, $postinfo[1]); $post_title = $wpdb->escape($post_title); $postyear = $postinfo[6]; $postmonth = zeroise($postinfo[4], 2); $postday = zeroise($postinfo[5], 2); $posthour = zeroise($postinfo[7], 2); $postminute = zeroise($postinfo[8], 2); $postsecond = zeroise($postinfo[9], 2); if ($postinfo[10] == "PM" && $posthour != "12") { $posthour = $posthour + 12; } $post_date = "{$postyear}-{$postmonth}-{$postday} {$posthour}:{$postminute}:{$postsecond}"; $post_content = $postmaincontent; if (strlen($postmorecontent) > 3) { $post_content .= "<!--more--><br /><br />" . $postmorecontent; } $post_content = $wpdb->escape($post_content); $post_karma = $postinfo[12]; $post_status = 'publish'; //in greymatter, there are no drafts $comment_status = 'open'; $ping_status = 'closed'; if ($post_ID = post_exists($post_title, '', $post_date)) { echo ' '; _e('(already exists)'); } else { //just so that if a post already exists, new users are not created by checkauthor // we'll check the author is registered, or if it's a deleted author $user_id = username_exists($post_author); if (!$user_id) { // if deleted from GM, we register the author as a level 0 user $user_ip = "127.0.0.1"; $user_domain = "localhost"; $user_browser = "server"; $user_joindate = "1979-06-06 00:41:00"; $user_login = $wpdb->escape($post_author); $pass1 = $wpdb->escape("password"); $user_nickname = $wpdb->escape($post_author); $user_email = $wpdb->escape("*****@*****.**"); $user_url = $wpdb->escape(""); $user_joindate = $wpdb->escape($user_joindate); $user_info = array("user_login" => $user_login, "user_pass" => $pass1, "user_nickname" => $user_nickname, "user_email" => $user_email, "user_url" => $user_url, "user_ip" => $user_ip, "user_domain" => $user_domain, "user_browser" => $user_browser, "dateYMDhour" => $user_joindate, "user_level" => 0, "user_idmode" => "nickname"); $user_id = wp_insert_user($user_info); $this->gmnames[$postinfo[1]] = $user_id; echo ': '; printf(__('registered deleted user %s at level 0 '), "<em>{$user_login}</em>"); } if (array_key_exists($postinfo[1], $this->gmnames)) { $post_author = $this->gmnames[$postinfo[1]]; } else { $post_author = $user_id; } $postdata = compact('post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_title', 'post_excerpt', 'post_status', 'comment_status', 'ping_status', 'post_modified', 'post_modified_gmt'); $post_ID = wp_insert_post($postdata); } $c = count($entry); if ($c > 4) { $numAddedComments = 0; $numComments = 0; for ($j = 4; $j < $c; $j++) { $entry[$j] = $this->gm2autobr($entry[$j]); $commentinfo = explode("|", $entry[$j]); $comment_post_ID = $post_ID; $comment_author = $wpdb->escape($commentinfo[0]); $comment_author_email = $wpdb->escape($commentinfo[2]); $comment_author_url = $wpdb->escape($commentinfo[3]); $comment_author_IP = $wpdb->escape($commentinfo[1]); $commentyear = $commentinfo[7]; $commentmonth = zeroise($commentinfo[5], 2); $commentday = zeroise($commentinfo[6], 2); $commenthour = zeroise($commentinfo[8], 2); $commentminute = zeroise($commentinfo[9], 2); $commentsecond = zeroise($commentinfo[10], 2); if ($commentinfo[11] == "PM" && $commenthour != "12") { $commenthour = $commenthour + 12; } $comment_date = "{$commentyear}-{$commentmonth}-{$commentday} {$commenthour}:{$commentminute}:{$commentsecond}"; $comment_content = $wpdb->escape($commentinfo[12]); if (!comment_exists($comment_author, $comment_date)) { $commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_url', 'comment_author_email', 'comment_author_IP', 'comment_date', 'comment_content', 'comment_approved'); $commentdata = wp_filter_comment($commentdata); wp_insert_comment($commentdata); $numAddedComments++; } $numComments++; } if ($numAddedComments > 0) { echo ': '; printf(__('imported %d comment(s)'), $numAddedComments); } $preExisting = $numComments - numAddedComments; if ($preExisting > 0) { echo ' '; printf(__('ignored %d pre-existing comments'), $preExisting); } } echo '... <strong>' . __('Done') . '</strong></li>'; } } ?> </ul><strong><?php _e('Done'); ?> </strong></li></ul> <p> </p> <p><?php _e('Completed GreyMatter import!'); ?> </p> <?php $this->footer(); }
function posts2wp($posts = '') { // General Housekeeping global $wpdb; $count = 0; $txpposts2wpposts = array(); $cats = array(); // Do the Magic if (is_array($posts)) { echo '<p>' . __('Importing Posts...') . '<br /><br /></p>'; foreach ($posts as $post) { $count++; extract($post); // Set Textpattern-to-WordPress status translation $stattrans = array(1 => 'draft', 2 => 'private', 3 => 'draft', 4 => 'publish', 5 => 'publish'); //Can we do this more efficiently? $uinfo = get_userdatabylogin($AuthorID) ? get_userdatabylogin($AuthorID) : 1; $authorid = is_object($uinfo) ? $uinfo->ID : $uinfo; $Title = $wpdb->escape($Title); $Body = $wpdb->escape($Body); $Excerpt = $wpdb->escape($Excerpt); $post_status = $stattrans[$Status]; // Import Post data into WordPress if ($pinfo = post_exists($Title, $Body)) { $ret_id = wp_insert_post(array('ID' => $pinfo, 'post_date' => $Posted, 'post_date_gmt' => $post_date_gmt, 'post_author' => $authorid, 'post_modified' => $LastMod, 'post_modified_gmt' => $post_modified_gmt, 'post_title' => $Title, 'post_content' => $Body, 'post_excerpt' => $Excerpt, 'post_status' => $post_status, 'post_name' => $url_title, 'comment_count' => $comments_count)); if (is_wp_error($ret_id)) { return $ret_id; } } else { $ret_id = wp_insert_post(array('post_date' => $Posted, 'post_date_gmt' => $post_date_gmt, 'post_author' => $authorid, 'post_modified' => $LastMod, 'post_modified_gmt' => $post_modified_gmt, 'post_title' => $Title, 'post_content' => $Body, 'post_excerpt' => $Excerpt, 'post_status' => $post_status, 'post_name' => $url_title, 'comment_count' => $comments_count)); if (is_wp_error($ret_id)) { return $ret_id; } } $txpposts2wpposts[$ID] = $ret_id; // Make Post-to-Category associations $cats = array(); $category1 = get_category_by_slug($Category1); $category1 = $category1->term_id; $category2 = get_category_by_slug($Category2); $category2 = $category2->term_id; if ($cat1 = $category1) { $cats[1] = $cat1; } if ($cat2 = $category2) { $cats[2] = $cat2; } if (!empty($cats)) { wp_set_post_categories($ret_id, $cats); } } } // Store ID translation for later use add_option('txpposts2wpposts', $txpposts2wpposts); echo '<p>' . sprintf(__('Done! <strong>%1$s</strong> posts imported.'), $count) . '<br /><br /></p>'; return true; }
/** * Handle uploading a set of files. * @param array $files A list of valid $_FILES keys to process. */ function cpm_handle_file_uploads($files) { global $cpm_config; $posts_created = array(); $duplicate_posts = array(); $files_uploaded = array(); $thumbnails_written = array(); $invalid_filenames = array(); $thumbnails_not_written = array(); $files_not_uploaded = array(); $invalid_image_types = array(); $gd_rename_file = array(); $did_convert_cmyk_jpeg = array(); $target_root = CPM_DOCUMENT_ROOT . '/' . $cpm_config->properties[$_POST['upload-destination'] . "_folder"]; if (($subdir = cpm_get_subcomic_directory()) !== false) { $target_root .= '/' . $subdir; } $write_thumbnails = isset($_POST['thumbnails']) && $_POST['upload-destination'] == "comic"; $new_post = isset($_POST['new_post']) && $_POST['upload-destination'] == "comic"; $ok_to_keep_uploading = true; $files_created_in_operation = array(); $filename_original_titles = array(); foreach ($files as $key) { if (is_uploaded_file($_FILES[$key]['tmp_name'])) { if ($_FILES[$key]['error'] != 0) { switch ($_FILES[$key]['error']) { case UPLOAD_ERR_INI_SIZE: case UPLOAD_ERR_FORM_SIZE: $cpm_config->warnings[] = sprintf(__("<strong>The file you uploaded was too large.</strong> The max allowed filesize for uploads to your server is %s.", 'comicpress-manager'), ini_get('upload_max_filesize')); break; case UPLOAD_ERR_NO_FILE: break; default: $cpm_config->warnings[] = sprintf(__("<strong>There was an error in uploading.</strong> The <a href='http://php.net/manual/en/features.file-upload.errors.php'>PHP upload error code</a> was %s.", 'comicpress-manager'), $_FILES[$key]['error']); break; } } else { if (strpos($_FILES[$key]['name'], ".zip") !== false) { $invalid_files = array(); //harmonious zip_open zip_entry_name zip_read zip_entry_read zip_entry_open zip_entry_filesize zip_entry_close zip_close if (extension_loaded("zip")) { if (is_resource($zip = zip_open($_FILES[$key]['tmp_name']))) { while ($zip_entry = zip_read($zip)) { if (zip_entry_open($zip, $zip_entry, "r")) { $temp_path = $target_root . '/' . md5(rand()); file_write_contents($temp_path, zip_entry_read($zip_entry, zip_entry_filesize($zip_entry))); $comic_file = zip_entry_name($zip_entry); $target_filename = pathinfo(zip_entry_name($zip_entry), PATHINFO_BASENAME); $result = cpm_breakdown_comic_filename($target_filename, true); if (file_exists($temp_path)) { extract(cpm_do_gd_file_check_on_upload($temp_path, $target_filename)); if ($result !== false) { extract($result, EXTR_PREFIX_ALL, "filename"); if ($file_ok) { if (($obfuscated_filename = cpm_obfuscate_filename($target_filename)) !== $target_filename) { $cpm_config->messages[] = sprintf(__('Uploaded file %1$s renamed to %2$s.', 'comicpress-manager'), $target_filename, $obfuscated_filename); $filename_original_titles[$obfuscated_filename] = $result['converted_title']; $target_filename = $obfuscated_filename; } @rename($temp_path, $target_root . '/' . $target_filename); $files_created_in_operation[] = $target_root . '/' . $target_filename; $files_uploaded[] = $target_filename; if ($gd_did_rename) { $gd_rename_file[] = $comic_file; } if ($did_filecheck) { if ($is_cmyk) { $did_convert_cmyk_jpeg[] = $comic_file; } } } else { if ($did_filecheck) { $invalid_image_types[] = $comic_file; } else { $invalid_filenames[] = $comic_file; } } } else { $files_not_uploaded[] = $comic_file; } } else { $invalid_filenames[] = $comic_file; } @unlink($temp_path); zip_entry_close($zip_entry); } if (($result = cpm_breakdown_comic_filename($target_filename, true)) !== false) { extract($result, EXTR_PREFIX_ALL, 'filename'); $target_path = $target_root . '/' . $target_filename; if (isset($_POST['upload-date-format']) && !empty($_POST['upload-date-format'])) { $target_filename = date(CPM_DATE_FORMAT, strtotime($result['date'])) . $result['title'] . '.' . pathinfo($_FILES[$key]['name'], PATHINFO_EXTENSION); } } else { $invalid_filenames[] = $comic_file; } } zip_close($zip); } } else { $cpm_config->warnings[] = sprintf(__("The Zip extension is not installed. %s was not processed.", 'comicpress-manager'), $_FILES[$key]['name']); } //harmonious_end } else { $target_filename = $_FILES[$key]['name']; if (get_magic_quotes_gpc()) { $target_filename = stripslashes($target_filename); } $tried_replace = false; if (!empty($_POST['overwrite-existing-file-choice'])) { $tried_replace = true; $original_filename = $target_filename; $target_filename = $_POST['overwrite-existing-file-choice']; if (get_magic_quotes_gpc()) { $target_filename = stripslashes($target_filename); } $new_post = false; if (pathinfo($original_filename, PATHINFO_EXTENSION) != pathinfo($target_filename, PATHINFO_EXTENSION)) { if (@unlink($target_root . '/' . $target_filename)) { foreach (cpm_get_thumbnails_to_generate() as $type) { $path = CPM_DOCUMENT_ROOT . '/' . $cpm_config->properties[$type . "_comic_folder"]; if (($subdir = cpm_get_thumbnails_to_generate()) !== false) { $path .= '/' . $subdir; } @unlink($path . '/' . $target_filename); } } $target_filename = preg_replace('#\\.[^\\.]+$#', '', $target_filename) . '.' . pathinfo($original_filename, PATHINFO_EXTENSION); } $result = cpm_breakdown_comic_filename($target_filename); $cpm_config->messages[] = sprintf(__('Uploaded file <strong>%1$s</strong> renamed to <strong>%2$s</strong>.', 'comicpress-manager'), $original_filename, $target_filename); } else { if (count($files) == 1) { if (!empty($_POST['override-date'])) { $date = strtotime($_POST['override-date']); if ($date !== false && $date !== -1) { $new_date = date(CPM_DATE_FORMAT, $date); $old_filename = $target_filename; if (($target_result = cpm_breakdown_comic_filename($target_filename, true)) !== false) { $target_filename = $new_date . $target_result['title'] . '.' . pathinfo($target_filename, PATHINFO_EXTENSION); } else { $target_filename = $new_date . '-' . $target_filename; } if ($old_filename !== $target_filename) { $cpm_config->messages[] = sprintf(__('Uploaded file %1$s renamed to %2$s.', 'comicpress-manager'), $_FILES[$key]['name'], $target_filename); } $result = cpm_breakdown_comic_filename($target_filename); } else { if (preg_match('/\\S/', $_POST['override-date']) > 0) { $cpm_config->warnings[] = sprintf(__("Provided override date %s is not parseable by strtotime().", 'comicpress-manager'), $_POST['override-date']); } } } } $result = cpm_breakdown_comic_filename($target_filename, true); if ($result !== false) { // bad file, can we get a date attached? if (isset($_POST['upload-date-format']) && !empty($_POST['upload-date-format'])) { $target_filename = date(CPM_DATE_FORMAT, strtotime($result['date'])) . $result['title'] . '.' . pathinfo($_FILES[$key]['name'], PATHINFO_EXTENSION); } } } $comic_file = $_FILES[$key]['name']; extract(cpm_do_gd_file_check_on_upload($_FILES[$key]['tmp_name'], $target_filename)); $output_file = null; if ($result !== false) { extract($result, EXTR_PREFIX_ALL, "filename"); if ($file_ok) { if (($obfuscated_filename = cpm_obfuscate_filename($target_filename)) !== $target_filename) { $cpm_config->messages[] = sprintf(__('Uploaded file %1$s renamed to %2$s.', 'comicpress-manager'), $target_filename, $obfuscated_filename); $filename_original_titles[$obfuscated_filename] = $result['converted_title']; $target_filename = $obfuscated_filename; } $output_file = $target_root . '/' . $target_filename; @move_uploaded_file($_FILES[$key]['tmp_name'], $output_file); $files_created_in_operation[] = $output_file; if (file_exists($output_file)) { $files_uploaded[] = $target_filename; if ($gd_did_rename) { $gd_rename_file[] = $comic_file; } } else { $files_not_uploaded[] = $target_filename; } if ($did_filecheck) { if ($is_cmyk) { $did_convert_cmyk_jpeg[] = $comic_file; } } } else { if ($did_filecheck) { $invalid_image_types[] = $comic_file; } else { $invalid_filenames[] = $comic_file; } } } else { if (!$tried_replace) { $invalid_filenames[] = $comic_file; } } if ($cpm_config->scale_method_cache == CPM_SCALE_IMAGEMAGICK && cpm_option('cpm-strip-icc-profiles') == "1" && !empty($output_file)) { $temp_output_file = $output_file . '.' . md5(rand()); $command = array("convert", "\"{$output_file}\"", "-strip", "\"{$temp_output_file}\""); $strip_profiles = escapeshellcmd(implode(" ", $command)); exec($strip_profiles); if (file_exists($temp_output_file)) { @unlink($output_file); @rename($temp_output_file, $output_file); } } } } } if ($wpmu_version) { if (cpm_wpmu_is_over_storage_limit()) { $ok_to_keep_uploading = false; break; } } } if ($ok_to_keep_uploading) { foreach ($files_uploaded as $target_filename) { $target_path = $target_root . '/' . $target_filename; @chmod($target_path, CPM_FILE_UPLOAD_CHMOD); if ($write_thumbnails) { $wrote_thumbnail = cpm_write_thumbnail($target_path, $target_filename); } if (!is_null($wrote_thumbnail)) { if (is_array($wrote_thumbnail)) { $thumbnails_written[] = $target_filename; $files_created_in_operation = array_merge($files_created_in_operation, $wrote_thumbnail); } else { $thumbnails_not_written[] = $target_filename; } } } if ($wpmu_version) { if (cpm_wpmu_is_over_storage_limit()) { $ok_to_keep_uploading = false; } } } if ($ok_to_keep_uploading) { foreach ($files_uploaded as $target_filename) { if ($new_post) { extract(cpm_breakdown_comic_filename($target_filename), EXTR_PREFIX_ALL, "filename"); if (isset($filename_original_titles[$target_filename])) { $filename_converted_title = $filename_original_titles[$target_filename]; } if (($post_hash = generate_post_hash($filename_date, $filename_converted_title)) !== false) { extract($post_hash); $ok_to_create_post = true; if (isset($_POST['duplicate_check'])) { $ok_to_create_post = ($post_id = post_exists($post_title, $post_content, $post_date)) == 0; } if ($ok_to_create_post) { if (!is_null($post_id = wp_insert_post($post_hash))) { $posts_created[] = get_post($post_id, ARRAY_A); foreach (array('hovertext', 'transcript') as $field) { if (!empty($_POST["{$field}-to-use"])) { update_post_meta($post_id, $field, $_POST["{$field}-to-use"]); } } } } else { $duplicate_posts[] = array(get_post($post_id, ARRAY_A), $target_filename); } } else { $invalid_filenames[] = $target_filename; } } } cpm_display_operation_messages(compact('invalid_filenames', 'files_uploaded', 'files_not_uploaded', 'thumbnails_written', 'thumbnails_not_written', 'posts_created', 'duplicate_posts', 'invalid_image_types', 'gd_rename_file', 'did_convert_cmyk_jpeg')); } else { $cpm_config->messages = array(); $cpm_config->warnings = array($cpm_config->wpmu_disk_space_message); foreach ($files_created_in_operation as $file) { @unlink($file); } } return array($posts_created, $duplicate_posts); }
/** * Save post meta. * * @param int $post_id * @param object $post */ public static function save_post($post_id = null, $post = null) { if (!(defined("DOING_AUTOSAVE") && DOING_AUTOSAVE)) { if ($post->post_type == 'camp_bulkposter') { if ($post->post_status != 'auto-draft') { # keyword meta post $keyword = isset($_POST['keyword']) ? trim($_POST['keyword']) : ''; delete_post_meta($post_id, 'keyword'); if (!empty($keyword)) { add_post_meta($post_id, 'keyword', $keyword); } # Count meta post $count = isset($_POST['count']) ? trim($_POST['count']) : ''; delete_post_meta($post_id, 'count'); if (!empty($count)) { add_post_meta($post_id, 'count', $count); } # Category ID $category_id = isset($_POST['category_id']) ? trim($_POST['category_id']) : ''; delete_post_meta($post_id, 'category_id'); if (!empty($category_id)) { add_post_meta($post_id, 'category_id', $category_id); } # Post Status $status = isset($_POST['status']) ? trim($_POST['status']) : ''; delete_post_meta($post_id, 'status'); if (!empty($status)) { add_post_meta($post_id, 'status', $status); } # Post Type $ktzplg_post_type = isset($_POST['ktzplg_post_type']) ? trim($_POST['ktzplg_post_type']) : ''; delete_post_meta($post_id, 'ktzplg_post_type'); if (!empty($ktzplg_post_type)) { add_post_meta($post_id, 'ktzplg_post_type', $ktzplg_post_type); } # Schedule Post $ktzplg_next = isset($_POST['ktzplg_next']) ? trim($_POST['ktzplg_next']) : ''; delete_post_meta($post_id, 'ktzplg_next'); if (!empty($ktzplg_next)) { add_post_meta($post_id, 'ktzplg_next', $ktzplg_next); } $ktzplg_next_time = isset($_POST['ktzplg_next_time']) ? trim($_POST['ktzplg_next_time']) : ''; delete_post_meta($post_id, 'ktzplg_next_time'); if (!empty($ktzplg_next_time)) { add_post_meta($post_id, 'ktzplg_next_time', $ktzplg_next_time); } # Logical insert post after Publish campaign if (!empty($count) && !empty($keyword)) { $keyword = explode("\n", $keyword); # Rand Keyword Submission if (count($keyword > 0)) { shuffle($keyword); $keyword = array_slice($keyword, 0, $count); } foreach ($keyword as $kwd) { $title = sanitize_title($kwd); $title = str_replace('-', ' ', $title); $title = ucwords($title); # https://developer.wordpress.org/reference/functions/post_exists/ $post_id = post_exists($title); $content = Ktzagcplugin_Option::get_option('ktzplg_agc_content'); $replace_with_this = ' keyword="' . $title . '"]'; $content_wow = str_replace(']', $replace_with_this, $content); $content = do_shortcode($content_wow); # if not post same keyword do it.. if (!$post_id) { # Insert post => ktzplg_insert_post ( $post_type='', $title = '', $status = '', $category_id = array() , $content = '', $author = '' ); ktzplg_insert_post($ktzplg_post_type, $title, $status, array($category_id), $content, 1); } } # end if foreach ( $keyword as $kwd ) } # end if !empty( $count ) && !empty( $keyword ) } # end if ( $post->post_status != 'auto-draft' ) } } }
function insert_posts() { global $wpdb; $imported = 0; $skipped = 0; foreach ($this->posts as $post) { extract($post); if ($wpdb->get_var($wpdb->prepare("SELECT meta_id FROM {$wpdb->postmeta} WHERE meta_key = 'flickr_id' AND meta_value = %s", $flickr_id)) || ($post_id = post_exists($post_title, $post_content, $post_date))) { // Looks like a duplicate $skipped++; } else { $post_id = wp_insert_post($post); if (is_wp_error($post_id)) { return $post_id; } if (!$post_id) { continue; } // Mark it as an image set_post_format($post_id, 'image'); // Track which Keyring service was used wp_set_object_terms($post_id, self::LABEL, 'keyring_services'); // Store the flickr id add_post_meta($post_id, 'flickr_id', $flickr_id); add_post_meta($post_id, 'flickr_url', $flickr_url); // Update Category and Tags wp_set_post_categories($post_id, $post_category); if (count($tags)) { wp_set_post_terms($post_id, implode(',', $tags)); } // Store geodata if it's available if (!empty($geo)) { add_post_meta($post_id, 'geo_latitude', $geo['lat']); add_post_meta($post_id, 'geo_longitude', $geo['long']); add_post_meta($post_id, 'geo_public', 1); } add_post_meta($post_id, 'raw_import_data', wp_slash(json_encode($flickr_raw))); $this->sideload_media($flickr_img, $post_id, $post, apply_filters('keyring_flickr_importer_image_embed_size', 'large')); $imported++; do_action('keyring_post_imported', $post_id, static::SLUG, $post); } } $this->posts = array(); // Return, so that the handler can output info (or update DB, or whatever) return array('imported' => $imported, 'skipped' => $skipped); }
public function test_post_exists_should_match_nonempty_title_content_and_date() { $title = 'Foo Bar'; $content = 'Foo Bar Baz'; $date = '2014-05-08 12:00:00'; $p = self::factory()->post->create(array('post_title' => $title, 'post_content' => $content, 'post_date' => $date)); $this->assertSame($p, post_exists($title, $content, $date)); }
function import_news_as_post($news) { // lookup or create author for posts, but not comments $post_author = $this->lookup_author($news['props']['author_email'], $news['props']['author']); if (in_array($news['status'], $this->post_status_options)) { $post_status = $news['status']; } else { $post_status = 'draft'; } // leave draft's alone to prevent publishing something that had been hidden on TYPO3 $force_post_status = get_t3i_options('force_post_status'); if ('default' != $force_post_status && 'draft' != $post_status) { $post_status = $force_post_status; } $post_password = get_t3i_options('protected_password'); $post_category = $news['category']; $post_date = $news['datetime']; // Cleaning up and linking the title $post_title = isset($news['title']) ? $news['title'] : ''; $post_title = strip_tags($post_title); // Can't have tags in the title in WP $post_title = trim($post_title); // Clean up content // TYPO3 stores bodytext usually in psuedo HTML $post_content = $this->_prepare_content($news['bodytext']); // Handle any tags associated with the post $tags_input = !empty($news['props']['keywords']) ? $news['props']['keywords'] : ''; // Check if comments are closed on this post $comment_status = $news['props']['comments']; $ping_status = 'closed'; // Add excerpt $post_excerpt = !empty($news['props']['excerpt']) ? $news['props']['excerpt'] : ''; // add slug AKA url $post_name = $news['props']['slug']; $post_id = post_exists($post_title, $post_content, $post_date); $postdata = compact('post_author', 'post_date', 'post_content', 'post_title', 'post_status', 'post_password', 'tags_input', 'comment_status', 'ping_status', 'post_excerpt', 'post_category', 'post_name'); if (!$post_id) { $post_id = wp_insert_post($postdata, true); } else { $postdata['ID'] = $post_id; $post_id = wp_update_post($postdata); } if (is_wp_error($post_id)) { if ('empty_content' == $post_id->getErrorCode()) { return; } // Silent skip on "empty" posts } return $post_id; }
function import_post($entry) { global $importing_blog; // The old permalink is all Blogger gives us to link comments to their posts. if (isset($entry->draft)) { $rel = 'self'; } else { $rel = 'alternate'; } foreach ($entry->links as $link) { if ($link['rel'] == $rel) { $parts = parse_url($link['href']); $entry->old_permalink = $parts['path']; break; } } $post_date = $this->convert_date($entry->published); $post_content = trim(addslashes($this->no_apos(html_entity_decode($entry->content)))); $post_title = trim(addslashes($this->no_apos($this->min_whitespace($entry->title)))); $post_status = isset($entry->draft) ? 'draft' : 'publish'; // Clean up content $post_content = preg_replace('|<(/?[A-Z]+)|e', "'<' . strtolower('\$1')", $post_content); $post_content = str_replace('<br>', '<br />', $post_content); $post_content = str_replace('<hr>', '<hr />', $post_content); // Checks for duplicates if (isset($this->blogs[$importing_blog]['posts'][$entry->old_permalink])) { ++$this->blogs[$importing_blog]['posts_skipped']; } elseif ($post_id = post_exists($post_title, $post_content, $post_date)) { $this->blogs[$importing_blog]['posts'][$entry->old_permalink] = $post_id; ++$this->blogs[$importing_blog]['posts_skipped']; } else { $post = compact('post_date', 'post_content', 'post_title', 'post_status'); $post_id = wp_insert_post($post); if (is_wp_error($post_id)) { return $post_id; } wp_create_categories(array_map('addslashes', $entry->categories), $post_id); $author = $this->no_apos(strip_tags($entry->author)); add_post_meta($post_id, 'blogger_blog', $this->blogs[$importing_blog]['host'], true); add_post_meta($post_id, 'blogger_author', $author, true); add_post_meta($post_id, 'blogger_permalink', $entry->old_permalink, true); $this->blogs[$importing_blog]['posts'][$entry->old_permalink] = $post_id; ++$this->blogs[$importing_blog]['posts_done']; } $this->save_vars(); return; }
function get_post($path = '', $placeholder = false) { // this gets the content AND imports the post because we have to build $this->filearr as we go so we can find the new post IDs of files' parent directories set_time_limit(540); $options = get_option('html_import'); $updatepost = false; if ($placeholder) { $title = trim(strrchr($path, '/'), '/'); $title = str_replace('_', ' ', $title); $title = str_replace('-', ' ', $title); $my_post['post_title'] = ucwords($title); if (isset($options['preserve_slugs']) && '1' == $options['preserve_slugs']) { $filename = basename($path); $my_post['post_name'] = substr($filename, 0, strrpos($filename, '.')); } if ($options['timestamp'] == 'filemtime') { $date = filemtime($path); } else { $date = time(); } $my_post['post_date'] = date("Y-m-d H:i:s", $date); $my_post['post_date_gmt'] = date("Y-m-d H:i:s", $date); $my_post['post_type'] = $options['type']; $parentdir = rtrim($this->parent_directory($path), '/'); $my_post['post_parent'] = array_search($parentdir, $this->filearr); if ($my_post['post_parent'] === false) { $my_post['post_parent'] = $options['root_parent']; } $my_post['post_content'] = '<!-- placeholder -->'; $my_post['post_status'] = $options['status']; $my_post['post_author'] = $options['user']; } else { set_magic_quotes_runtime(0); $doc = new DOMDocument(); $doc->strictErrorChecking = false; // ignore invalid HTML, we hope $doc->preserveWhiteSpace = false; $doc->formatOutput = false; // speed this up if (!empty($options['encode'])) { // we have to deal with character encoding BEFORE calling loadHTML() - eureka! $content = $this->handle_accents(); @$doc->loadHTML($content); } else { @$doc->loadHTML($this->file); } $xml = @simplexml_import_dom($doc); // avoid asXML errors when it encounters character range issues libxml_clear_errors(); libxml_use_internal_errors(false); // start building the WP post object to insert $my_post = array(); // title if ($options['import_title'] == "region") { // appending strings unnecessarily so this plugin can be edited in Dreamweaver if needed $titlematch = '/<' . '!-- InstanceBeginEditable name="' . $options['title_region'] . '" --' . '>( .* )<' . '!-- InstanceEndEditable --' . '>/isU'; preg_match($titlematch, $this->file, $titlematches); $my_post['post_title'] = strip_tags(trim($titlematches[1])); } else { if ($options['import_title'] == "filename") { $path_split = explode('/', $path); $file_name = trim(end($path_split)); $file_name = preg_replace('/\\.[^.]*$/', '', $file_name); // remove extension $parent_directory = trim(prev($path_split)); if (basename($path) == $options['index_file']) { $title = $parent_directory; } else { $title = $file_name; } $title = str_replace('_', ' ', $title); $title = str_replace('-', ' ', $title); $my_post['post_title'] = ucwords($title); } else { // it's a tag $titletag = $options['title_tag']; $titletagatt = $options['title_tagatt']; $titleattval = $options['title_attval']; $titlequery = '//' . $titletag; if (!empty($titletagatt)) { $titlequery .= '[@' . $titletagatt . '="' . $titleattval . '"]'; } $title = $xml->xpath($titlequery); if (isset($title[0]) && is_object($title[0])) { $title = $title[0]->asXML(); } else { // fallback $title = $xml->xpath('//title'); if (isset($title[0])) { $title = $title[0]; } if (empty($title)) { $title = ''; } else { $title = (string) $title; } } // last resort: filename if (empty($title)) { $path_split = explode('/', $path); $title = trim(end($path_split)); } // replace break tags with spaces before we strip tags, to avoid accidentally concatenating words $title = str_replace('<br>', ' ', $title); $my_post['post_title'] = trim(strip_tags($title)); } } $remove = $options['remove_from_title']; if (!empty($remove)) { $my_post['post_title'] = str_replace($remove, '', $my_post['post_title']); } //echo '<pre>'.$my_post['post_title'].'</pre>'; exit; // slug if (isset($options['preserve_slugs']) && '1' == $options['preserve_slugs']) { // there is no path when we're working with a single uploaded file instead of a directory if (empty($path)) { $filename = $this->filename; } else { $filename = basename($path); } $my_post['post_name'] = substr($filename, 0, strrpos($filename, '.')); } // post type $my_post['post_type'] = $options['type']; if (is_post_type_hierarchical($my_post['post_type'])) { if (empty($path)) { $my_post['post_parent'] = $options['root_parent']; } else { $parentdir = rtrim($this->parent_directory($path), '/'); $my_post['post_parent'] = array_search($parentdir, $this->filearr); if ($my_post['post_parent'] === false) { $my_post['post_parent'] = $options['root_parent']; } } } // date if ($options['timestamp'] == 'filemtime' && !empty($path)) { $date = filemtime($path); $my_post['post_date'] = date("Y-m-d H:i:s", $date); $my_post['post_date_gmt'] = date("Y-m-d H:i:s", $date); } else { if ($options['timestamp'] == 'customfield') { if ($options['import_date'] == "region") { // appending strings unnecessarily so this plugin can be edited in Dreamweaver if needed $datematch = '/<' . '!-- InstanceBeginEditable name="' . $options['date_region'] . '" --' . '>( .* )<' . '!-- InstanceEndEditable --' . '>/isU'; preg_match($datematch, $this->file, $datematches); $date = $datematches[1]; } else { // it's a tag $tag = $options['date_tag']; $tagatt = $options['date_tagatt']; $attval = $options['date_attval']; $xquery = '//' . $tag; if (!empty($tagatt)) { $xquery .= '[@' . $tagatt . '="' . $attval . '"]'; } $date = $xml->xpath($xquery); if (is_array($date) && isset($date[0]) && is_object($date[0])) { if (isset($date[0]) && is_object($date[0])) { $stripdate = $date[0]->asXML(); } // asXML() preserves HTML in content $date = strip_tags($date[0]); $date = strtotime($date); //echo $date; exit; } else { // fallback $date = time(); } } } else { $date = time(); } } $my_post['post_date'] = date("Y-m-d H:i:s", $date); $my_post['post_date_gmt'] = date("Y-m-d H:i:s", $date); // content if ($options['import_content'] == "region") { // appending strings unnecessarily so this plugin can be edited in Dreamweaver if needed $contentmatch = '/<' . '!-- InstanceBeginEditable name="' . $options['content_region'] . '" --' . '>( .* )<' . '!-- InstanceEndEditable --' . '>/isU'; preg_match($contentmatch, $this->file, $contentmatches); $my_post['post_content'] = $contentmatches[1]; } else { if ($options['import_content'] == "file") { // import entire file $my_post['post_content'] = $this->file; } else { // it's a tag $tag = $options['content_tag']; $tagatt = $options['content_tagatt']; $attval = $options['content_attval']; $xquery = '//' . $tag; if (!empty($tagatt)) { $xquery .= '[@' . $tagatt . '="' . $attval . '"]'; } $content = $xml->xpath($xquery); if (is_array($content) && isset($content[0]) && is_object($content[0])) { $my_post['post_content'] = $content[0]->asXML(); // asXML() preserves HTML in content } else { // fallback $content = $xml->xpath('//body'); if (is_array($content) && isset($content[0]) && is_object($content[0])) { $my_post['post_content'] = $content[0]->asXML(); } else { $my_post['post_content'] = ''; } } } } // $my_post['post_content'] = (string) $my_post['post_content']; if ($options['title_inside']) { $my_post['post_content'] = str_replace($title, '', $my_post['post_content']); } if (!empty($my_post['post_content'])) { if (!empty($options['clean_html'])) { $my_post['post_content'] = $this->clean_html($my_post['post_content'], $options['allow_tags'], $options['allow_attributes']); } } // custom fields $customfields = array(); foreach ($options['customfield_name'] as $index => $fieldname) { if (!empty($fieldname)) { if ($options['import_field'][$index] == "region") { // appending strings unnecessarily so this plugin can be edited in Dreamweaver if needed $custommatch = '/<' . '!-- InstanceBeginEditable name="' . $options['customfield_region'][$index] . '" --' . '>( .* )<' . '!-- InstanceEndEditable --' . '>/isU'; preg_match($custommatch, $this->file, $custommatches); if (isset($custommatches[1])) { $customfields[$fieldname] = $custommatches[1]; } } else { // it's a tag $tag = $options['customfield_tag'][$index]; $tagatt = $options['customfield_tagatt'][$index]; $attval = $options['customfield_attval'][$index]; $xquery = '//' . $tag; if (!empty($tagatt)) { $xquery .= '[@' . $tagatt . '="' . $attval . '"]'; } $content = $xml->xpath($xquery); if (is_array($content) && isset($content[0]) && is_object($content[0])) { $fieldcontent = $content[0]->asXML(); if (!empty($options['customfield_html'][$index]) && !empty($options['clean_html'])) { $fieldcontent = $content[0]->asXML(); $fieldcontent = $this->clean_html($fieldcontent, $options['allow_tags'], $options['allow_attributes']); if (!empty($fieldcontent)) { $customfields[$fieldname] = $fieldcontent; } } else { $fieldcontent = trim(strip_tags($fieldcontent)); if (!empty($fieldcontent)) { $customfields[$fieldname] = $fieldcontent; } } } } } } // excerpt $excerpt = $options['meta_desc']; if (!empty($excerpt)) { $my_post['post_excerpt'] = $xml->xpath('//meta[@name="description"]'); if (isset($my_post['post_excerpt'][0])) { $my_post['post_excerpt'] = $my_post['post_excerpt'][0]['content']; } if (is_array($my_post['post_excerpt'])) { $my_post['post_excerpt'] = implode('', $my_post['post_excerpt']); } $my_post['post_excerpt'] = (string) $my_post['post_excerpt']; } // status $my_post['post_status'] = $options['status']; // author $my_post['post_author'] = $options['user']; } // if it's a single file, we can use a substitute for $path from here on if (empty($path)) { $handle = __("the uploaded file", 'import-html-pages'); } else { $handle = $path; } // see if the post already exists // but don't bother printing this message if we're doing an index file; we know its parent already exists if ($post_id = post_exists($my_post['post_title'], $my_post['post_content'], $my_post['post_date']) && basename($path) != $options['index_file']) { $this->table[] = "<tr><th class='error'>--</th><td colspan='3' class='error'> " . sprintf(__("%s ( %s ) has already been imported", 'html-import-pages'), $my_post['post_title'], $handle) . "</td></tr>"; } // if we're doing hierarchicals and this is an index file of a subdirectory, instead of importing this as a separate page, update the content of the placeholder page we created for the directory $index_files = explode(',', $options['index_file']); if (is_post_type_hierarchical($options['type']) && dirname($path) != $options['root_directory'] && in_array(basename($path), $index_files)) { $post_id = array_search(dirname($path), $this->filearr); if ($post_id !== 0) { $updatepost = true; } } if ($updatepost) { $my_post['ID'] = $post_id; wp_update_post($my_post); } else { // insert new post $post_id = wp_insert_post($my_post); } // handle errors if (is_wp_error($post_id)) { $this->table[] = "<tr><th class='error'>--</th><td colspan='3' class='error'> " . $post_id . "</td></tr>"; } if (!$post_id) { $this->table[] = "<tr><th class='error'>--</th><td colspan='3' class='error'> " . sprintf(__("Could not import %s. You should copy its contents manually.", 'html-import-pages'), $handle) . "</td></tr>"; } // if no errors, handle custom fields if (isset($customfields)) { foreach ($customfields as $fieldname => $fieldvalue) { // allow user to set tags via custom field named 'post_tag' if ($fieldname == 'post_tag') { $customfieldtags = $fieldvalue; } else { add_post_meta($post_id, $fieldname, $fieldvalue, true); } } } // ... and all the taxonomies... $taxonomies = get_taxonomies(array('public' => true), 'objects', 'and'); foreach ($taxonomies as $tax) { if (isset($options[$tax->name])) { wp_set_post_terms($post_id, $options[$tax->name], $tax->name, false); } } if (isset($customfieldtags)) { wp_set_post_terms($post_id, $customfieldtags, 'post_tag', false); } // ...and set the page template, if any if (isset($options['page_template']) && !empty($options['page_template'])) { add_post_meta($post_id, '_wp_page_template', $options['page_template'], true); } // create redirects from old and new paths; store old path in custom field if (!empty($path) && !$updatepost) { $url = esc_url($options['old_url']); $url = rtrim($url, '/'); if (!empty($url)) { $old = str_replace($options['root_directory'], $url, $path); } else { $old = $path; } $this->redirects .= "Redirect\t" . $old . "\t" . get_permalink($post_id) . "\t[R=301,NC,L]\n"; add_post_meta($post_id, 'URL_before_HTML_Import', $old, true); } // store path so we can check for parents later ( even if it's empty; need that info for image imports ). // Don't store the index file updates; they'll screw up the parent search, and they can use their parents' path anyway if (!$updatepost) { $this->filearr[$post_id] = $path; } else { // index files will have an incomplete hierarchy if there were empty directories in their path $this->fix_hierarchy($post_id, $path); } // create the results table row AFTER fixing hierarchy if (!empty($path)) { if (empty($my_post['post_title'])) { $my_post['post_title'] = __('( no title )', 'html-import'); } $this->table[$post_id] = " <tr><th>" . $post_id . "</th><td>" . $path . "</td><td>" . get_permalink($post_id) . '</td><td> <a href="post.php?action=edit&post=' . $post_id . '">' . esc_html($my_post['post_title']) . "</a></td></tr>"; } else { $this->single_result = sprintf(__('Imported the file as %s.', 'import-html-pages'), '<a href="post.php?action=edit&post=' . $post_id . '">' . $my_post['post_title'] . '</a>'); } }
function posts2wp($posts = '') { // General Housekeeping global $wpdb; $count = 0; $s9yposts2wpposts = get_option('s9yposts2wpposts'); if (!$s9yposts2wpposts) { $s9yposts2wpposts = array(); } $cats = array(); // Do the Magic if (is_array($posts)) { echo '<p>' . __('Importing Posts...') . '<br /><br /></p>'; foreach ($posts as $post) { $count++; if (!is_array($post)) { $post = (array) $post; } extract($post); $post_id = $id; // Jon (Snowulf.com) 2010-06-04 -- Re-instated & fixed draft/publish $post_status = null; if ($isdraft == "true") { $post_status = 'draft'; } else { $post_status = 'publish'; } // dobschat - 2008/11/08 - chenged $authorid -> $author $uinfo = get_user_by('login', $author) ? get_user_by('login', $author) : 1; $authorid = is_object($uinfo) ? $uinfo->ID : $uinfo; $post_title = $wpdb->escape($title); // dobschat - 2008/11/08 - split body and extended text in wp with <!--more--> if ($wpdb->escape($extended) != "") { $post_body = $wpdb->escape($body) . "<!--more-->" . $wpdb->escape($extended); } else { $post_body = $wpdb->escape($body); } // $post_time = date('Y-m-d H:i:s', $timestamp); $post_modified = date('Y-m-d H:i:s', $last_modified); // Import Post data into WordPress if ($pinfo = post_exists($post_title, $post_body)) { $ret_id = wp_insert_post(array('ID' => $pinfo, 'post_date' => $post_time, 'post_date_gmt' => $post_time, 'post_author' => $authorid, 'post_modified' => $post_modified, 'post_modified_gmt' => $post_modified_gmt, 'post_title' => $post_title, 'post_content' => $post_body, 'post_status' => $post_status, 'post_name' => sanitize_title($post_title))); } else { $ret_id = wp_insert_post(array('post_date' => $post_time, 'post_date_gmt' => $post_time, 'post_author' => $authorid, 'post_modified' => $post_modified, 'post_modified_gmt' => $post_modified, 'post_title' => $post_title, 'post_content' => $post_body, 'post_status' => $post_status, 'menu_order' => $post_id, 'post_name' => sanitize_title($post_title))); } $s9yposts2wpposts[] = array($id, $ret_id); // Make Post-to-Category associations $cats = $this->get_s9y_cat_assoc($id); $wpcats = array(); if (is_array($cats)) { foreach ($cats as $cat) { $c = get_category_by_slug($cat->categoryid . '-' . sanitize_title($cat->category_name)); $wpcats[] = $c->term_id; } } $cats = is_array($wpcats) ? $wpcats : (array) $wpcats; if (!empty($cats)) { wp_set_post_categories($ret_id, $cats); } else { wp_set_post_categories($ret_id, get_option('default_category')); } // dobschat - 2008/11/08 - added importing tags $tags = $this->get_s9y_tag_assoc($id); if (is_array($tags)) { array_walk_recursive($tags, 'set_tags_from_s9y', $ret_id); } // ----- } } // Store ID translation for later use update_option('s9yposts2wpposts', $s9yposts2wpposts); echo '<p>' . sprintf(__('Done! <strong>%1$s</strong> posts imported.'), $count) . '<br /><br /></p>'; return true; }
function save_updates() { global $user_ID; $leaflyData = make_leafly_request(); if ($leaflyData) { $updates = get_leafly_updates($leaflyData); foreach ($updates as $update) { if (!post_exists('Update ' . $update->date)) { //create a new post $new_post = array('post_title' => 'Update ' . $update->date, 'post_content' => $update->content, 'post_status' => 'publish', 'post_date' => date('Y-m-d H:i:s'), 'post_author' => $user_ID, 'post_type' => 'post', 'post_category' => array(0)); //Save it $post_id = wp_insert_post($new_post); } } } }
function process_post($post) { global $wpdb; $post_ID = (int) $this->get_tag($post, 'wp:post_id'); if ($post_ID && !empty($this->post_ids_processed[$post_ID])) { // Processed already return 0; } set_time_limit(60); // There are only ever one of these $post_title = $this->get_tag($post, 'title'); $post_date = $this->get_tag($post, 'wp:post_date'); $post_date_gmt = $this->get_tag($post, 'wp:post_date_gmt'); $comment_status = $this->get_tag($post, 'wp:comment_status'); $ping_status = $this->get_tag($post, 'wp:ping_status'); $post_status = $this->get_tag($post, 'wp:status'); $post_name = $this->get_tag($post, 'wp:post_name'); $post_parent = $this->get_tag($post, 'wp:post_parent'); $menu_order = $this->get_tag($post, 'wp:menu_order'); $post_type = $this->get_tag($post, 'wp:post_type'); $post_password = $this->get_tag($post, 'wp:post_password'); $is_sticky = $this->get_tag($post, 'wp:is_sticky'); $guid = $this->get_tag($post, 'guid'); $post_author = $this->get_tag($post, 'dc:creator'); $post_excerpt = $this->get_tag($post, 'excerpt:encoded'); $post_excerpt = preg_replace_callback('|<(/?[A-Z]+)|', create_function('$match', 'return "<" . strtolower($match[1]);'), $post_excerpt); $post_excerpt = str_replace('<br>', '<br />', $post_excerpt); $post_excerpt = str_replace('<hr>', '<hr />', $post_excerpt); $post_content = $this->get_tag($post, 'content:encoded'); $post_content = preg_replace_callback('|<(/?[A-Z]+)|', create_function('$match', 'return "<" . strtolower($match[1]);'), $post_content); $post_content = str_replace('<br>', '<br />', $post_content); $post_content = str_replace('<hr>', '<hr />', $post_content); preg_match_all('|<category domain="tag">(.*?)</category>|is', $post, $tags); $tags = $tags[1]; $tag_index = 0; foreach ($tags as $tag) { $tags[$tag_index] = $wpdb->escape($this->unhtmlentities(str_replace(array('<![CDATA[', ']]>'), '', $tag))); $tag_index++; } preg_match_all('|<category>(.*?)</category>|is', $post, $categories); $categories = $categories[1]; $cat_index = 0; foreach ($categories as $category) { $categories[$cat_index] = $wpdb->escape($this->unhtmlentities(str_replace(array('<![CDATA[', ']]>'), '', $category))); $cat_index++; } $post_exists = post_exists($post_title, '', $post_date); if ($post_exists) { echo '<li>'; printf(__('Post <em>%s</em> already exists.'), stripslashes($post_title)); $comment_post_ID = $post_id = $post_exists; } else { // If it has parent, process parent first. $post_parent = (int) $post_parent; if ($post_parent) { // if we already know the parent, map it to the local ID if ($parent = $this->post_ids_processed[$post_parent]) { $post_parent = $parent; // new ID of the parent } else { // record the parent for later $this->orphans[intval($post_ID)] = $post_parent; } } echo '<li>'; $post_author = $this->checkauthor($post_author); //just so that if a post already exists, new users are not created by checkauthor $postdata = compact('post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_excerpt', 'post_title', 'post_status', 'post_name', 'comment_status', 'ping_status', 'guid', 'post_parent', 'menu_order', 'post_type', 'post_password'); $postdata['import_id'] = $post_ID; if ($post_type == 'attachment') { $remote_url = $this->get_tag($post, 'wp:attachment_url'); if (!$remote_url) { $remote_url = $guid; } $comment_post_ID = $post_id = $this->process_attachment($postdata, $remote_url); if (!$post_id or is_wp_error($post_id)) { return $post_id; } } else { printf(__('Importing post <em>%s</em>...'), stripslashes($post_title)); $comment_post_ID = $post_id = wp_insert_post($postdata); if ($post_id && $is_sticky == 1) { stick_post($post_id); } } if (is_wp_error($post_id)) { return $post_id; } // Memorize old and new ID. if ($post_id && $post_ID) { $this->post_ids_processed[intval($post_ID)] = intval($post_id); } // Add categories. if (count($categories) > 0) { $post_cats = array(); foreach ($categories as $category) { if ('' == $category) { continue; } $slug = sanitize_term_field('slug', $category, 0, 'category', 'db'); $cat = get_term_by('slug', $slug, 'category'); $cat_ID = 0; if (!empty($cat)) { $cat_ID = $cat->term_id; } if ($cat_ID == 0) { $category = $wpdb->escape($category); $cat_ID = wp_insert_category(array('cat_name' => $category)); if (is_wp_error($cat_ID)) { continue; } } $post_cats[] = $cat_ID; } wp_set_post_categories($post_id, $post_cats); } // Add tags. if (count($tags) > 0) { $post_tags = array(); foreach ($tags as $tag) { if ('' == $tag) { continue; } $slug = sanitize_term_field('slug', $tag, 0, 'post_tag', 'db'); $tag_obj = get_term_by('slug', $slug, 'post_tag'); $tag_id = 0; if (!empty($tag_obj)) { $tag_id = $tag_obj->term_id; } if ($tag_id == 0) { $tag = $wpdb->escape($tag); $tag_id = wp_insert_term($tag, 'post_tag'); if (is_wp_error($tag_id)) { continue; } $tag_id = $tag_id['term_id']; } $post_tags[] = intval($tag_id); } wp_set_post_tags($post_id, $post_tags); } } // Now for comments preg_match_all('|<wp:comment>(.*?)</wp:comment>|is', $post, $comments); $comments = $comments[1]; $num_comments = 0; if ($comments) { foreach ($comments as $comment) { $comment_author = $this->get_tag($comment, 'wp:comment_author'); $comment_author_email = $this->get_tag($comment, 'wp:comment_author_email'); $comment_author_IP = $this->get_tag($comment, 'wp:comment_author_IP'); $comment_author_url = $this->get_tag($comment, 'wp:comment_author_url'); $comment_date = $this->get_tag($comment, 'wp:comment_date'); $comment_date_gmt = $this->get_tag($comment, 'wp:comment_date_gmt'); $comment_content = $this->get_tag($comment, 'wp:comment_content'); $comment_approved = $this->get_tag($comment, 'wp:comment_approved'); $comment_type = $this->get_tag($comment, 'wp:comment_type'); $comment_parent = $this->get_tag($comment, 'wp:comment_parent'); // if this is a new post we can skip the comment_exists() check if (!$post_exists || !comment_exists($comment_author, $comment_date)) { $commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_url', 'comment_author_email', 'comment_author_IP', 'comment_date', 'comment_date_gmt', 'comment_content', 'comment_approved', 'comment_type', 'comment_parent'); wp_insert_comment($commentdata); $num_comments++; } } } if ($num_comments) { printf(' ' . _n('(%s comment)', '(%s comments)', $num_comments), $num_comments); } // Now for post meta preg_match_all('|<wp:postmeta>(.*?)</wp:postmeta>|is', $post, $postmeta); $postmeta = $postmeta[1]; if ($postmeta) { foreach ($postmeta as $p) { $key = $this->get_tag($p, 'wp:meta_key'); $value = $this->get_tag($p, 'wp:meta_value'); $value = stripslashes($value); // add_post_meta() will escape. $this->process_post_meta($post_id, $key, $value); } } do_action('import_post_added', $post_id); print "</li>\n"; }
/** * Create new posts based on import information * * Posts marked as having a parent which doesn't exist will become top level items. * Doesn't create a new post if: the post type doesn't exist, the given post ID * is already noted as imported or a post with the same title and date already exists. * Note that new/updated terms, comments and meta are imported for the last of the above. */ function process_posts() { foreach ($this->posts as $post) { if (!post_type_exists($post['post_type'])) { printf(__('Failed to import “%s”: Invalid post type %s', 'radium'), esc_html($post['post_title']), esc_html($post['post_type'])); echo '<br />'; continue; } if (isset($this->processed_posts[$post['post_id']]) && !empty($post['post_id'])) { continue; } if ($post['status'] == 'auto-draft') { continue; } if ('nav_menu_item' == $post['post_type']) { $this->process_menu_item($post); continue; } $post_type_object = get_post_type_object($post['post_type']); $post_exists = post_exists($post['post_title'], '', $post['post_date']); if ($post_exists && get_post_type($post_exists) == $post['post_type']) { printf(__('%s “%s” already exists.', 'radium'), $post_type_object->labels->singular_name, esc_html($post['post_title'])); echo '<br />'; $comment_post_ID = $post_id = $post_exists; } else { $post_parent = (int) $post['post_parent']; if ($post_parent) { // if we already know the parent, map it to the new local ID if (isset($this->processed_posts[$post_parent])) { $post_parent = $this->processed_posts[$post_parent]; // otherwise record the parent for later } else { $this->post_orphans[intval($post['post_id'])] = $post_parent; $post_parent = 0; } } // map the post author $author = sanitize_user($post['post_author'], true); if (isset($this->author_mapping[$author])) { $author = $this->author_mapping[$author]; } else { $author = (int) get_current_user_id(); } $postdata = array('import_id' => $post['post_id'], 'post_author' => $author, 'post_date' => $post['post_date'], 'post_date_gmt' => $post['post_date_gmt'], 'post_content' => $post['post_content'], 'post_excerpt' => $post['post_excerpt'], 'post_title' => $post['post_title'], 'post_status' => $post['status'], 'post_name' => $post['post_name'], 'comment_status' => $post['comment_status'], 'ping_status' => $post['ping_status'], 'guid' => $post['guid'], 'post_parent' => $post_parent, 'menu_order' => $post['menu_order'], 'post_type' => $post['post_type'], 'post_password' => $post['post_password']); if ('attachment' == $postdata['post_type']) { $remote_url = !empty($post['attachment_url']) ? $post['attachment_url'] : $post['guid']; // try to use _wp_attached file for upload folder placement to ensure the same location as the export site // e.g. location is 2003/05/image.jpg but the attachment post_date is 2010/09, see media_handle_upload() $postdata['upload_date'] = $post['post_date']; if (isset($post['postmeta'])) { foreach ($post['postmeta'] as $meta) { if ($meta['key'] == '_wp_attached_file') { if (preg_match('%^[0-9]{4}/[0-9]{2}%', $meta['value'], $matches)) { $postdata['upload_date'] = $matches[0]; } break; } } } $comment_post_ID = $post_id = $this->process_attachment($postdata, $remote_url); } else { $comment_post_ID = $post_id = wp_insert_post($postdata, true); } if (is_wp_error($post_id)) { printf(__('Failed to import %s “%s”', 'radium'), $post_type_object->labels->singular_name, esc_html($post['post_title'])); if (defined('IMPORT_DEBUG') && IMPORT_DEBUG) { echo ': ' . $post_id->get_error_message(); } echo '<br />'; continue; } if ($post['is_sticky'] == 1) { stick_post($post_id); } } // map pre-import ID to local ID $this->processed_posts[intval($post['post_id'])] = (int) $post_id; // add categories, tags and other terms if (!empty($post['terms'])) { $terms_to_set = array(); foreach ($post['terms'] as $term) { // back compat with WXR 1.0 map 'tag' to 'post_tag' $taxonomy = 'tag' == $term['domain'] ? 'post_tag' : $term['domain']; $term_exists = term_exists($term['slug'], $taxonomy); $term_id = is_array($term_exists) ? $term_exists['term_id'] : $term_exists; if (!$term_id) { $t = wp_insert_term($term['name'], $taxonomy, array('slug' => $term['slug'])); if (!is_wp_error($t)) { $term_id = $t['term_id']; } else { printf(__('Failed to import %s %s', 'radium'), esc_html($taxonomy), esc_html($term['name'])); if (defined('IMPORT_DEBUG') && IMPORT_DEBUG) { echo ': ' . $t->get_error_message(); } echo '<br />'; continue; } } $terms_to_set[$taxonomy][] = intval($term_id); } foreach ($terms_to_set as $tax => $ids) { $tt_ids = wp_set_post_terms($post_id, $ids, $tax); } unset($post['terms'], $terms_to_set); } // add/update comments if (!empty($post['comments'])) { $num_comments = 0; $inserted_comments = array(); foreach ($post['comments'] as $comment) { $comment_id = $comment['comment_id']; $newcomments[$comment_id]['comment_post_ID'] = $comment_post_ID; $newcomments[$comment_id]['comment_author'] = $comment['comment_author']; $newcomments[$comment_id]['comment_author_email'] = $comment['comment_author_email']; $newcomments[$comment_id]['comment_author_IP'] = $comment['comment_author_IP']; $newcomments[$comment_id]['comment_author_url'] = $comment['comment_author_url']; $newcomments[$comment_id]['comment_date'] = $comment['comment_date']; $newcomments[$comment_id]['comment_date_gmt'] = $comment['comment_date_gmt']; $newcomments[$comment_id]['comment_content'] = $comment['comment_content']; $newcomments[$comment_id]['comment_approved'] = $comment['comment_approved']; $newcomments[$comment_id]['comment_type'] = $comment['comment_type']; $newcomments[$comment_id]['comment_parent'] = $comment['comment_parent']; $newcomments[$comment_id]['commentmeta'] = isset($comment['commentmeta']) ? $comment['commentmeta'] : array(); if (isset($this->processed_authors[$comment['comment_user_id']])) { $newcomments[$comment_id]['user_id'] = $this->processed_authors[$comment['comment_user_id']]; } } ksort($newcomments); foreach ($newcomments as $key => $comment) { // if this is a new post we can skip the comment_exists() check if (!$post_exists || !comment_exists($comment['comment_author'], $comment['comment_date'])) { if (isset($inserted_comments[$comment['comment_parent']])) { $comment['comment_parent'] = $inserted_comments[$comment['comment_parent']]; } $comment = wp_filter_comment($comment); $inserted_comments[$key] = wp_insert_comment($comment); foreach ($comment['commentmeta'] as $meta) { $value = maybe_unserialize($meta['value']); add_comment_meta($inserted_comments[$key], $meta['key'], $value); } $num_comments++; } } unset($newcomments, $inserted_comments, $post['comments']); } // add/update post meta if (isset($post['postmeta'])) { foreach ($post['postmeta'] as $meta) { $key = apply_filters('import_post_meta_key', $meta['key']); $value = false; if ('_edit_last' == $key) { if (isset($this->processed_authors[intval($meta['value'])])) { $value = $this->processed_authors[intval($meta['value'])]; } else { $key = false; } } if ($key) { // export gets meta straight from the DB so could have a serialized string if (!$value) { $value = maybe_unserialize($meta['value']); } add_post_meta($post_id, $key, $value); do_action('import_post_meta', $post_id, $key, $value); // if the post has a featured image, take note of this in case of remap if ('_thumbnail_id' == $key) { $this->featured_images[$post_id] = (int) $value; } } } } } unset($this->posts); }
/** * Undo demo setup and reverts back to state before importing the sample contents. * Does not remove post/pages that have been modified by the user. * * @since 1.7.6 */ function themify_undo_import_sample_content() { do_action('themify_before_demo_erase'); themify_import_sample_content_setup(); $import = new Themify_Import(); $data = $import->parse(themify_get_sample_content_file()); foreach ($data['categories'] as $cat) { $term_id = term_exists($cat['category_nicename'], 'category'); if ($term_id) { if (is_array($term_id)) { $term_id = $term_id['term_id']; } if (isset($cat['term_id'])) { wp_delete_category($term_id); } } } foreach ($data['tags'] as $tag) { $term_id = term_exists($tag['tag_slug'], 'post_tag'); if ($term_id) { if (is_array($term_id)) { $term_id = $term_id['term_id']; } if (isset($tag['term_id'])) { wp_delete_term($term_id, 'post_tag'); } } } foreach ($data['terms'] as $term) { $term_id = term_exists($term['slug'], $term['term_taxonomy']); if ($term_id) { if (is_array($term_id)) { $term_id = $term_id['term_id']; } if (isset($term['term_id'])) { wp_delete_term($term_id, $term['term_taxonomy']); } } } foreach ($data['posts'] as $post) { $post_exists = post_exists($post['post_title'], '', $post['post_date']); if ($post_exists && get_post_type($post_exists) == $post['post_type']) { /* check if the post has not been modified since it was created */ if ($post['post_date'] == get_post_field('post_modified', $post_exists)) { wp_delete_post($post_exists, true); // true: bypass trash } } } do_action('themify_after_demo_erase'); }