Drupal integration: Difference between revisions

From Scribus Wiki
Jump to navigation Jump to search
Line 17: Line 17:


=== ToDo ===
=== ToDo ===
* Drupal module that allows you to create article presets (i.e. main article, editorial etc.) and informs if your article pass the layout (char counter)
* Drupal module that allows you to create article presets (i.e. main article, editorial etc.) and informs if your article pass the layout


== Scribus backend ==
== Scribus backend ==

Revision as of 00:08, 23 November 2009

Notes about creating a publishing platform with Scribus and Drupal (DRAFT)


Requirements

  • running Drupal6
  • external connection to Mysql database or a shell

Drupal backend

Articles are prepared to publish within the complete workflow system. The workflow system is build with help of: CCK, Views2, Workflow and Diff modules.

Done

  • workflow (from Draft state to Published state), revisioning included
  • input format -- html, with help of BueEditor and custom button set
  • a special dashboard for listing articles in different states (Views2), includes a tab with articles prepared for publishing

ToDo

  • Drupal module that allows you to create article presets (i.e. main article, editorial etc.) and informs if your article pass the layout

Scribus backend

Articles are fetched by a simple python script and converted to html readable by Scribus.

ToDo

  • script works outside Scribus. As a proof of concept we can create a similar script which imports articles directly to Scribus, unfortunately, text formatting is lost in this case...

Possible extensions

  • use of markdown syntax

Proof of concept script

#!/usr/bin/env python
#-*- coding utf-8 -*-

import os
import re
import MySQLdb

#database info
host="www.yourhosthere.info"
user="user"
passwd="password"
db="database"


def htmlhead():
	header = """<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
	"""
	return header

def htmlfoot():
	footer = """
</body>
</html>
	"""
	return footer

print "Scribus/Drupal brigde\n\nby mariusz slonina <mariusz.slonina@gmail.com>\n\n"


#connect to database
try:
	print 'Connecting to the database...\n'
	db = MySQLdb.connect(host, user,passwd,db)
	print 'Connected;)\n'
except MySQLdb.Error, e:
	print "Error %d: %s\n" % (e.args[0], e.args[1])
	print "Aborting...;(\n"
	sys.exit(1)
# create a cursor
cursor = db.cursor()
# # execute SQL statement
cursor.execute("your select goes here")
#cursor.execute("select nr.nid, nr.vid, nr.title, nr.body, pf.value from node_revisions nr
#inner join workflow_node wn on wn.nid = nr.nid
#inner join node n on n.vid = nr.vid 
#inner join profile_values pf on n.uid = pf.uid 
#where wn.sid = 6 and pf.fid = 4")

# # get the result set as a tuple
print "Fetching articles...\n"
result = cursor.fetchall()

for record in result:
	
	nid = str(record[0])
	titleID = "title_nid_" + str(record[0])
	bodyID = "body_nid_" + str(record[0])
	authorID = "author_nid_" + str(record[0])
	file_name = titleID + ".html"


	title_text = str(record[2])
	body_text = str(record[3])
	author_text = str(record[4])

	#split body and add <p></p> tags for proper import to Scribus
	temp = re.split("\n\s*\n",body_text)
	length = len(temp)
	i = 0
	text = ''
	st = ''
	for i in range(length):
		subtemp = re.split("\n",temp[i].strip())
		j = 0
		jl = len(subtemp)
		for j in range(jl):
			if not j == jl - 1:
				st = st + subtemp[j].strip() + '<br />\n'
			else:
				st = st + subtemp[j].strip()
		text = text + '<p>' + st.strip() + '</p>\n'
		st = ''
		
		
	print titleID + ":: " + title_text + " -- " + author_text

	f = open(file_name,"w")
	header = htmlhead()
	f.write(header)
	f.write('<p>'+author_text+': '+title_text+'</p>\n')
	f.write(text)
	footer = htmlfoot()
	f.write(footer)

	f.close()

print "Finishing...\n"
db.close()
print "You can import Your articles to Scribus\nHave a nice day!\n"