Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

« Newer Snippets
Older Snippets »
Showing 1-10 of 12 total  RSS 

Transfer Wordpress MySQL database to new webhost

// Transfer Wordpress MySQL database to new webhost in 3 steps (assumes: A. files have already been copied over, B. database created on new server, C. database user created on new server, D. wp-config.php updated on new server)
// 1. login to old host via ssh, run this command:
mysqldump -h DB_HOST -u DB_USER -p DB_NAME > dump.sql

// replace DB_HOST, DB_USER, & DB_NAME with info from the local wp-config.php file
// when asked for password, enter DB_PASSWORD from the local wp-config.php file

// 2. copy dump.sql to your new host using sftp

// 3. login go new host via ssh, run this command:
mysql -h DB_HOST -u DB_USER -p DB_NAME < dump.sql

// replace DB_HOST, DB_USER, & DB_NAME with info from the local wp-config.php file
// when asked for password, enter DB_PASSWORD from the local wp-config.php file

// adopted from this page: http://technosailor.com/2007/04/06/wordpress-faq-how-do-i-move-my-blog-to-a-new-host/

firefox not showing vertical scrollbars in blog

hey everyone,

I'm new here and wondering if someone can help me out. i have a couple wordpress blogs i've built for clients, and i'm occasionally getting a wierd behavior in Firefox Win/Mac: sometimes even though there is plenty of content below the fold, no vertical scrollbar will show at all. it only does this on firefox.

here's an example (must view in firefox):

http://www.lorihedrickphotography.com/blog/

and i've tried adding this:


html {
height:101%;
overflow-y:scroll;
}


i looked at it with firebug, it validates. i'm stumped! any help would be greatly appreciated.

-jared

RSS output of a Prologue post

// This is how Prologue outputs a post

<item>
		<title></title>
		<link>http://localhost/wordpress/?p=3</link>
		<comments>http://localhost/wordpress/?p=3#comments</comments>
		<pubDate>Tue, 29 Jan 2008 23:54:15 +0000</pubDate>

		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<category><![CDATA[welcome]]></category>

		<guid isPermaLink="false">http://localhost/wordpress/?p=3</guid>
		<description><![CDATA[Pretty cool, here&#8217;s the Twitta!]]></description>
			
                <content:encoded><![CDATA[<p>Pretty cool, here&#8217;s the Twitta!</p>]]></content:encoded>
			<wfw:commentRss>http://localhost/wordpress/?feed=rss2&p=3</wfw:commentRss>

</item>

Typo export to Wordpress WXR (script version)

I tried to use this method here: http://snippets.dzone.com/posts/show/3264 however my typo blog was too slow and it kept timing out (which is why we're switching to wordpress anyway...). So I stole the code and hacked it up a bit so it could be run as a script.

Put this in $RAILS_ROOT/script/wp_export.rb, and run it like:
RAILS_ENV=production ./script/wp_export.rb > out.wxr


Import it with the "Import Wordpress" tool in your wordpress blog's admin interface.

#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../config/boot'
require 'environment'

require 'application'

# we need a controller to generate html output
class FakeController < ApplicationController
  include ActionView::Helpers::TextHelper
  include ActionView::Helpers::TagHelper
end
fake_controller = FakeController.new

articles = Article.find(:all)

xml = Builder::XmlMarkup.new(:target => STDOUT, :indent => 2)

xml.instruct! :xml, :version=>"1.0", :encoding=>"UTF-8"
xml.rss 'version' => "2.0",
        'xmlns:content' => "http://purl.org/rss/1.0/modules/content/",
        'xmlns:wfw' => "http://wellformedweb.org/CommentAPI/",
        'xmlns:dc' => "http://purl.org/dc/elements/1.1/",
        'xmlns:wp' => "http://wordpress.org/export/1.0/" do
  xml.channel do
    xml.title "The Robot Co-op"
    xml.link "http://www.robotcoop.com"
    xml.language "en-us"
    xml.ttl "40"
    xml.description "Robot coop blog"

    articles.each do |a|
        xml.item do
          xml.title a.title
          xml.content(:encoded) { |x| x << a.html(fake_controller, :all) }
          xml.pubDate a.published_at.rfc2822
          xml.guid "urn:uuid:{a.guid}", "isPermaLink" => "false"
          author = a.user.name rescue a.author
          xml.author author
          xml.dc :creator, author
          for category in a.categories
            xml.category category.name
          end
          for tag in a.tags
            xml.category tag.display_name
          end
          xml.wp :post_id, a.id
          xml.wp :post_date, a.published_at.strftime("%Y-%m-%d %H:%M:%S")
          xml.wp :comment_status, 'closed'
          xml.wp :ping_status, 'closed'
          xml.wp :post_name, a.permalink
          xml.wp :status, 'publish'
          xml.wp :post_parent, '0'
          xml.wp :post_type, 'post'
          for comment in a.comments
            xml.wp(:comment) do
              xml.wp :comment_id, comment.id
              xml.wp :comment_author, comment.author
              xml.wp :comment_author_email, comment.email
              xml.wp :comment_author_url, comment.url
              xml.wp :comment_author_IP, comment.ip
              xml.wp :comment_date, comment.published_at.strftime("%Y-%m-%d %H:%M:%S")
              xml.wp(:comment_content) { |x| x << comment.body }
              xml.wp :comment_approved, '1'
              xml.wp :comment_parent, '0'
            end
          end
       end
    end
  end
end

Typo export to WordPress WXR

If you want to move from Typo to Wordpress, you can use this to export the strange Wordpress RSS file format (comments and all).

Just add this to the XmlController :

  def wp
    @articles = Article.find( :all, :include => [:categories, :tags, :user, :blog])
  end


And then add this file (app/views/xml/wp.rxml):

// insert code here..
xml.instruct! :xml, :version=>"1.0", :encoding=>"UTF-8"

xml.rss 'version' => "2.0", 'xmlns:content' => "http://purl.org/rss/1.0/modules/content/", 'xmlns:wfw' => "http://wellformedweb.org/CommentAPI/", 'xmlns:dc' => "http://purl.org/dc/elements/1.1/", 'xmlns:wp' => "http://wordpress.org/export/1.0/" do
  xml.channel do
    xml.title @feed_title
    xml.link @link
    xml.language "en-us"
    xml.ttl "40"
    xml.description this_blog.blog_subtitle

    @articles.each do |a|
        xml.item do
          xml.title post_title(a)
          xml.content(:encoded) { |x| x << '<![CDATA[' + a.full_html + ']]>' }
          xml.pubDate a.published_at.rfc2822
          xml.guid "urn:uuid:#{a.guid}", "isPermaLink" => "false"
          author = a.user.name rescue a.author
          xml.author author
          xml.dc :creator, author
          for category in a.categories
            xml.category category.name
          end
          for tag in a.tags
            xml.category tag.display_name
          end
          xml.wp :post_id, a.id
          xml.wp :post_date, a.published_at.strftime("%Y-%m-%d %H:%M:%S")
          xml.wp :comment_status, 'closed'
          xml.wp :ping_status, 'closed'
          xml.wp :post_name, a.permalink
          xml.wp :status, 'publish'
          xml.wp :post_parent, '0'
          xml.wp :post_type, 'post'
          for comment in a.comments
            xml.wp(:comment) do
              xml.wp :comment_id, comment.id
              xml.wp :comment_author, comment.author
              xml.wp :comment_author_email, comment.email
              xml.wp :comment_author_url, comment.url
              xml.wp :comment_author_IP, comment.ip
              xml.wp :comment_author_date, comment.published_at.strftime("%Y-%m-%d %H:%M:%S")
              xml.wp(:comment_content) { |x| x << comment.full_html }
              xml.wp :comment_approved, '1'
              xml.wp :comment_parent, '0'
            end
          end
        end
    end
end


Then hit your typo blog at http://myblog/xml/wp and save the file to import through the WordPress interface.

Wordpress HTML Outline

// Basic HTML structure for a wordpress page
<body>
	<div id="wrap">
		<div id="top">
		</div>

		<div id="content" class="single">
			<div class="post-wrap" id="post-6">
				<h1 class="post-title">The Title Of Your Post</h1>
				<div class="story-content">
				</div>
				
				<div class="metawrap">
				</div>
			</div>

			<div id="commentwrap">
				<h3 id="respond">Leave Your Comment</h3>
				<form>
				</form>
			</div>
		</div>

		<div id="side">
			<ul>
				<li><!-- One side bar item --></li>
			</ul>
		</div>

		<div id="bottom"></div>
		
	</div><!-- end wrap -->
</body>

Googleit WordPress Plugin

// description of your code here

<?php
/*
Plugin Name: Googleit
Plugin URI: http://lordrich.com/archives/2005/04/02/just-google-it/
Description: Link to google for the current title.  Usage: google_it();
Version: 0.1
Author: Richard Kirkcaldy
Author URI: http://lordrich.com
*/

function google_it(){
	$google = '<a href="http://www.google.com/search?q='.get_the_title().'">Google It</a>';
	echo $google;
	}
?>

Feedwordpress mod

A simplified version of update-feeds.php from the Feedwordpress project. This version doesn't bother checking for authentication as there's really no point. It doesn't check whether it's being run at the commandline either, it simply assumes it is being called by wget as a cron job. This is designed to be run with version 0.98

<?php

// Help us to pick out errors, if any.
ini_set('error_reporting', E_ALL & ~E_NOTICE);
ini_set('display_errors', true);
define('MAGPIE_DEBUG', true);

// Are we running from a web request or from the command line?
                $update_feeds_display = 'text/plain';
                $update_feeds_invoke = 'post';
                $update_feeds_verbose = false;

require_once ('../wp-blog-header.php');

function update_feeds_mention ($feed) {
        global $update_feeds_display;

        if ($update_feeds_display=='text/html') :
                echo "<li>Updating <cite>".$feed['link/name']."</cite> from &lt;<a href=\""
                        .$feed['link/uri']."\">".$feed['link/uri']."</a>&gt; ...</li>\n";
        else :
                echo "* Updating ".$feed['link/name']." from <".$feed['link/uri']."> ...\n";
        endif;
        flush();
}

# -- Don't change these unless you know what you're doing...
define ('RPC_MAGIC', 'tag:radgeek.com/projects/feedwordpress/'); // update all

// Query secret word from database
$rpc_secret = get_settings('feedwordpress_rpc_secret');

header("Content-Type: {$update_feeds_display}; charset=utf-8");


        // Henceforward, we can proceed on the assumption that we have an authenticated user
        $uri = (isset($_REQUEST['uri']) ? $_REQUEST['uri'] : RPC_MAGIC.$rpc_secret);

        if ($update_feeds_display=='text/html') :
                echo <<<EOHTML
<?xml version="1.0" encoding="utf-8"?>
<html>
<head>
<title>update-feeds :: FeedWordPress</title>
</head>

<body>
<h1>update-feeds: make FeedWordPress check for new syndicated content</h1>

EOHTML;
        endif;

$feedwordpress =& new FeedWordPress;

if ($update_feeds_display=='text/html' or $update_feeds_verbose) :
        add_action('feedwordpress_check_feed', 'update_feeds_mention');
endif;

if ($update_feeds_display=='text/html') : // HTTP GET or HTTP POST: add some web niceties


        echo "<form action=\"\" method=\"POST\">\n";
        echo "<select name=\"uri\">\n";
        echo "<option value=\"".RPC_MAGIC.$rpc_secret."\">All feeds</option>\n";
        foreach ($feedwordpress->feeds as $feed) :
                echo "<option value=\"{$feed['link/uri']}\"";
                if ($feed['link/uri']==$_REQUEST['uri']) : echo ' selected="selected"'; endif;
                echo ">{$feed['link/name']}</option>\n";
        endforeach;
        echo "</select> ";
        echo "<input type=\"submit\" name=\"update\" value=\"Update\" />\n";
        echo "</form>\n";
endif;

if ($update_feeds_invoke != 'get') : // Only do things with side-effects for HTTP POST or command l
ine
        if ($update_feeds_display == 'text/html') : echo "<ul>\n"; endif;
        $delta = @$feedwordpress->update($uri);
        if ($update_feeds_display == 'text/html') : echo "</ul>\n"; endif;

        if (is_null($delta)) :
                if ($update_feeds_invoke == 'cmd') :
                        $stderr = fopen('php://stderr', 'w');
                        fputs($stderr, "update-feeds (".date('Y-m-d H:i:s')."): ERROR: I don't synd
icate <$uri>\n");
                elseif ($update_feeds_display == 'text/plain') :
                        echo "update-feeds (".date('Y-m-d H:i:s')."): ERROR: I don't syndicate <$ur
i>\n";
                else :
                        echo "<p><strong>Error:</strong> I don't syndicate <a href=\"$uri\">$uri</a
></p>\n";
                endif;
        elseif ($update_feeds_display=='text/html' or $update_feeds_verbose) :
                $mesg = array();
                if (isset($delta['new'])) : $mesg[] = ' '.$delta['new'].' new posts were syndicated
'; endif;
                if (isset($delta['updated'])) : $mesg[] = ' '.$delta['updated'].' existing posts we
re updated'; endif;
                if ($update_feeds_display=='text/html') : echo "<p>"; endif;
                echo "Update complete.".implode(' and', $mesg);
                if ($update_feeds_display=='text/html') : echo "</p>"; endif;
                echo "\n"; flush();
        endif;
endif;

if ($update_feeds_display=='text/html') : // HTTP GET or HTTP POST: close off web niceties
        echo <<<EOHTML

<p><a href="../wp-admin">&larr; Return to WordPress Dashboard</a></p>
</body>
</html>
EOHTML;
endif;
?>

Use the contents of a WordPress database in your Rails app

These two models can be used to access the posts and associated comments of a WordPress database.

class WpBlogComment < ActiveRecord::Base

  # if wordpress tables live in a different database (i.e. 'wordpress') change the following
  # line to set_table_name "wordpress.wp_comments"
  # don't forget to give the db user permissions to access the wordpress db
  set_table_name "wp_comments"
  set_primary_key "comment_ID"

  belongs_to :post , :class_name => "WpBlogPost", :foreign_key => "comment_post_ID"

  validates_presence_of :comment_post_ID, :comment_author, :comment_content, :comment_author_email
  
  def validate_on_create
    if WpBlogPost.find(comment_post_ID).comment_status != 'open'
      errors.add_to_base('Sorry, comments are closed for this post')
    end
  end

end 


class WpBlogPost < ActiveRecord::Base

  set_table_name "wp_posts"
  set_primary_key "ID"

  has_many :comments, :class_name => "WpBlogComment", :foreign_key => "comment_post_ID"

  def self.find_by_permalink(year, month, day, title)
    find(:first, 
         :conditions => ["YEAR(post_date) = ? AND MONTH(post_date) = ? AND DAYOFMONTH(post_date) = ? AND post_name = ?", year.to_i, month.to_i, day.to_i, title])
  end
end 


Display In 2-Column Table

The below can be applied to MT, EE, etc, and will display the content in a 2 column table. The EE tags below are just an example, it will work equally well if you replace it with MT, Wordpress, etc, tags.

<? $set_table="0"; ?>

<table cellpadding="5" border="0">
{exp:gallery:categories gallery="{gallery_name}"}
<? 
$set_table = $set_table +1;
if ($set_table == "1") {echo"<tr>";} ?>


Insert other tags here.


<? if ($set_table == "2") {echo"</tr>";  $set_table="0";} ?>
{/exp:gallery:categories}
</table>
« Newer Snippets
Older Snippets »
Showing 1-10 of 12 total  RSS