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-6 of 6 total  RSS 

Export del.icio.us links to MT Import Format

A friend of mine needed his del.icio.us links in MT Import format for some reason. This solved that problem.

require 'rexml/document'
require 'net/https'
require 'rubygems'

# change credentials!
user = 'username'
pass = 'password'

# User-Agent: required for del.icio.us api
agent = 'delicious-mt'
xml = ''

http = Net::HTTP.new('api.del.icio.us', 443)
http.use_ssl = true
http.start do |http|
  request = Net::HTTP::Get.new('/v1/posts/all', {'User-Agent' => agent})
  request.basic_auth(user, pass)
  response = http.request(request)
  response.value
  xml = response.body
end
 
REXML::Document.new(xml).elements.each('posts/post') do |el|
  puts "TITLE: #{el.attributes['description']}"
  puts "AUTHOR: Author Name"
  puts "DATE: #{DateTime.parse(el.attributes['time']).strftime("%m/%d/%Y %H:%M:%S")}"
  puts "-----"
  puts "BODY:"
  puts el.attributes['extended']
  puts "-----"
  puts "EXCERPT:"
  puts el.attributes['href']
  puts "KEYWORDS:"
  puts el.attributes['tag']
  puts "-----"
  puts "--------"
end

Movable Type Navigation

This will generate nested unordered lists of links to all category and sub-category archives that are descendants of the "Articles" category, but not a link to the "Articles" category itself. Requires the wonderful Compare plugin.

<MTSubCategories>
<MTIfIsDescendant parent="Articles">
<MTIfEqual a="[MTCategoryLabel]" b="Articles">
<MTSubCatsRecurse>
<MTElse>
<MTSubCatIsFirst><ul class="leftnav"></MTSubCatIsFirst>
<li><strong><a href="<MTCategoryArchiveLink$>" title="<$MTCategoryDescription$>"><$MTCategoryLabel$></a><MTSubCatsRecurse></strong></li>
<MTSubCatIsLast></ul></MTSubCatIsLast>
</MTElse>
</MTIfEqual>
</MTIfIsDescendant>
</MTSubCategories>

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>

Monthly List

A list of the Monthly Archive pages linked to their archives.

<ul>
<MTArchiveList archive_type="Monthly">
<li><a href="<$MTArchiveLink$>"><$MTArchiveTitle$></a> [ <MTArchiveCount> ]</li>
</MTArchiveList>
</ul>

Recent Entries

List of the latest 10 entries linked to their Individual Archive Pages.

<ul>
<MTEntries lastn="10">
<li><a href="<$MTEntryPermalink$>"><$MTEntryTitle$></a> [ <a href="<MTEntryLink archive_type="Category">"><MTEntryCategory ></a> ]</li>
</MTEntries>
</ul>

Category List

List of all categories in an MT blog linked to their archive pages.

<ul>
<MTCategories>
<li><a href="<$MTCategoryArchiveLink$>"><$MTCategoryLabel$></a> [ <MTCategoryCount> ]</li>
</MTCategories>
</ul>
« Newer Snippets
Older Snippets »
Showing 1-6 of 6 total  RSS