Drupal integration: Difference between revisions

From Scribus Wiki
Jump to navigation Jump to search
No edit summary
Line 30: Line 30:


== Proof of concept script ==
== Proof of concept script ==
<pre>
<code>
#!/usr/bin/env python
#!/usr/bin/env python
#-*- coding utf-8 -*-
#-*- coding utf-8 -*-
Line 133: Line 133:
db.close()
db.close()
print "You can import Your articles to Scribus\nHave a nice day!\n"
print "You can import Your articles to Scribus\nHave a nice day!\n"
</pre>
</code>

Revision as of 12:14, 20 November 2009

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


Requirenments

  • 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 (char counter)

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

  1. !/usr/bin/env python
  2. -*- coding utf-8 -*-

import os import re import MySQLdb

  1. 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"


  1. 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)

  1. create a cursor

cursor = db.cursor()

  1. # execute SQL statement

cursor.execute("your select goes here")

  1. 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")
  2. # 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

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() + '
\n' else: st = st + subtemp[j].strip()

text = text + '

' + st.strip() + '

\n'

st =


print titleID + ":: " + title_text + " -- " + author_text

f = open(file_name,"w") header = htmlhead() f.write(header)

f.write('

'+author_text+': '+title_text+'

\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"