March, 2010


27
Mar 10

Migrating from Facebook Page to WordPress.

Facebook has decided to close our group for political reasons, I’m not gonna discuss that here because its their site in the end and they can run it in whatever way they want, all we can do is become less dependent on facebook and migrate our stuff from there, from now on, I will think twice about posting any useful content on facebook and I will recommend everyone else to do just the same.

So we needed to pull out all the notes from the page we had, totalling 454 notes, there is no export functionality in facebook only an RSS feed that would give you the last 10 items.

So I found a post that shows how to use the API test tool to query the FB database, the relevant query is

SELECT note_id, title, created_time, content FROM note WHERE uid = 0000000000

and change the uid into the id of the facebook page you want.

I was able to get all the notes in XML format, now in order to get those into wordpress we need to import them, here is a post that shows a generic xml parser for wordpress, I had to change the script a bit to make is understand fb’s xml format.

here is the file xmltowp.php

Update: 20100402
Now we have migrated our photo albums from facebook aswell, its a bit more complicated but hey, it works :)
here are the queries for the FB API tool, first get your albums

SELECT name,aid FROM album WHERE owner = 00000000

next use the album ID to get the photos info for each album alone

SELECT pid, aid, src_big, src_big_height, src_big_width, link, caption, created, modified, object_id FROM photo WHERE aid= '00000000_00000'

now we have an XML file with all the photos info, lets get the URL and get all the files

$grep '<src_big>' album.xml > urls

in VIM do the following substitutes on the urls file

:%s/    <src_big>//g
:%s/<\/src_big>//g

now feed the urls file to wget through the -i option.
I have used the NextGEN gallery module for WordPress, using that I was able to import whole folders, the folders where wget saved all those photos. Now to get the captions of the original photos in WordPress aswell I have written a small ruby script that parses the albums.xml and generates an SQL file that you need to execute against your wordpress DB, here is the code, ugly but works

#!/usr/bin/ruby

require "rexml/document"
include REXML

file = File.new( "album.xml" )
doc = Document.new file
output = ""
doc.elements.each("*/photo") { |element|
  filename = ''
  caption = ''
  XPath.each( element, "src_big") { |src| filename = File.basename(src.text) }
  XPath.each( element, "caption") { |cap| caption = cap.text }
  output << "update wp_ngg_pictures set description = '#{caption}', alttext='#{caption}' where filename='#{filename}';\n"
}
outfile = File.new("update.sql", "w")
outfile << 'SET CHARACTER_SET_CLIENT=utf8;'
outfile << 'SET CHARACTER_SET_CONNECTION=utf8;'
outfile << 'SET CHARACTER_SET_RESULTS=utf8;'
outfile << output

hope this helps someone in need.


20
Mar 10

iWorld Cup 2010

512 logo

Obsessed with football? Afraid of missing out on anything off the upcoming WORLD CUP? This cool application will keep you updated with all the results and latest news. Get it now, and carry WORLD CUP 2010 within your pocket!

sc1

Here is what you get from this outstanding application:

  • Accurate minute by minute live update and coverage for all match details.
  • All games are ordered by date or by group so you can easily fit your schedule around your most anticipated games.
  • A unique and attractive design, switch easily between groups, matches, teams, venues and latest news.
  • Fifa.com direct RSS feed for all the latest news as it happens.
  • A count down till the first day of the tournament.
  • A detailed page for every team, contains team profile information and all team matches.
  • A detailed page for every match, containing the results, the venue, and all the match events.
  • A details page for every venue.
  • sc2

    We love football with a passion, we created this app for us and for you! A great deal of effort has been put in designing, developing and testing all the functionalities to make sure that this app is the best for football lovers and to let us and you enjoy the games to the max!

    sc5

    If you have any comments or suggestions please don’t hesitate in contacting us either on iTunes store or on our website, www.barmajeyat.com


16
Mar 10

Rails SEO/Freindly URLs

to get decent SEO URLs in your rails app, app the following snippet to the model in question

  #change the URL of the apps to be more SEO friendly
  def to_param
      "#{id}-#{parameterize}"
  end

that would generate URLs as the following

http://www.barmajeyat.com/apps/1-tajweed


6
Mar 10

Rails edit_polymorphic_path

This handy function comes in use when you don’t know that object type you want to edit, I used has_many_polymorphs to pull many objects related to my user object, here is the views code

<% @user.entities.each do |e| %>
<tr>
<td><%=h e.info.nameĀ  %>
<td><%= link_to 'Show', e %></td>
<td><%= link_to 'Edit', edit_polymorphic_path(e) %></td>
<td><%= link_to 'Destroy', e, :confirm => 'Are you sure?', :method => :delete %></td>
</tr>
<% end %>

5
Mar 10

using Has_many_polymorphs

So I needed to establish a relation between one model and many other models, the User model can own many other models like Restaurants and Cafes, has_many_polymorphs comes to the rescue, check the plugin homepage for installation details.

Here are my models

class User < ActiveRecord::Base
  acts_as_authentic
  has_many_polymorphs :entities, :from => [:restaurants, :travel_agencies]
end

class EntitiesUser < ActiveRecord::Base
 belongs_to :user
 belongs_to :entity, :polymorphic => true
end

following is the migration for the EntitiesUser model

class CreateEntitiesUsers < ActiveRecord::Migration
 def self.up
   create_table :entities_users do |t|
     t.references :entity, :polymorphic => true
     t.references :user
     t.timestamps
   end
 end

 def self.down
   drop_table :entities_users
 end
end

And to make sure the links between the two models are being established I used the following code in the Entity model

  after_create :add_entity_user
  after_destroy :delete_entity_user

  protected
  def add_entity_user #add a relation between the entity and the currently logged in user
    user = UserSession.find.record
    eu = EntitiesUser.new( :entity_id => self.id, :entity_type => self.class.name, :user_id => user.id  )
    eu.save
  end
  def delete_entity_user #delete the relations for this entity
    eus = EntitiesUser.find(:all, :conditions => ["entity_id = ? and entity_type = ?", self.id, self.class.name])
    eus.each { |e| e.destroy }
  end

hope this helps.