/[drupal]/contributions/modules/export_opml/export_opml.module
ViewVC logotype

Contents of /contributions/modules/export_opml/export_opml.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.3 - (show annotations) (download) (as text)
Tue Nov 29 19:32:42 2005 UTC (3 years, 11 months ago) by puregin
Branch: MAIN
CVS Tags: HEAD
Branch point for: DRUPAL-5, DRUPAL-4-7
Changes since 1.2: +8 -20 lines
File MIME type: text/x-php
  - tidied up formatting of _link() code
  - removed _menu() hook - not needed.
  - added to documentation for book_export_opml, emphasizing access
    permissions
1 <?php
2 // $Id: $
3
4 /**
5 * @file
6 * Allows authorized users to export a book's structure as OPML.
7 */
8
9 /**
10 * Implementation of hook_perm().
11 */
12 function export_opml_perm() {
13 return array('export books as opml');
14 }
15
16 /**
17 * Implementation of hook_link().
18 */
19 function export_opml_link($type, $node = 0, $main = 0) {
20 $links = array();
21 if ($type == 'node' && isset($node->parent)) {
22 if (!$main) {
23 if (user_access('export books as opml')) {
24 $links[] = l(t('export OPML'),
25 'book/export/opml/'. $node->nid,
26 array('title' => t('Export this book page and its sub-pages as OPML.')));
27 }
28 }
29 }
30 return $links;
31 }
32
33
34 /**
35 * This function is called by book_export() to generate OPML for export.
36 *
37 * Unlike HTML output, OPML output is not embedded to its absolute
38 * level in the parent book. The exported node will be the top level
39 * element in the OPML outline.
40 *
41 * The function also calls drupal_set_header() to set a header suitable
42 * for returning XML content.
43 *
44 * Note that the user must have both 'access content' permissions (checked
45 * when the menu item for export is invoked in book.module) and
46 * 'export books as opml' permissions to export a book.
47 *
48 * @param nid
49 * - an integer representing the node id (nid) of the node to export
50 * @param depth
51 * - an integer giving the depth in the book hierarchy of the node
52 which is to be exported
53 * @return
54 * - the OPML representing the node and its children in the book
55 * hierarchy. Only titles are exported.
56
57 */
58 function book_export_opml($nid, $depth) {
59 if (user_access('export books as opml')) {
60 drupal_set_header('Content-Type: text/xml; charset=utf-8');
61 $output .= book_recurse($nid, $depth, 'book_node_visitor_opml_pre', 'book_node_visitor_opml_post');
62 $ompl = "<?xml version='1.0'?>\n";
63 $opml .= "<opml version='1.0'>\n";
64 $opml .= "<head>\n<title>". check_plain($node->title) ."</title>\n";
65 $opml .= "</head>\n<body>\n". $output . "\n</body>\n</opml>\n";
66 return $opml;
67 }
68 else {
69 drupal_access_denied();
70 }
71 }
72
73 /**
74 * Generates OPML for a node. This function is a 'pre-node' visitor
75 * function for book_recurse().
76 *
77 * @param $node
78 * - the node to generate output for.
79 * @param $depth
80 * - the depth of the given node in the hierarchy. This is used only
81 * for generating output.
82 * @param $nid
83 * - the node id (nid) of the given node. This is used only for
84 * generating output.
85 * @return
86 * - the OPML generated for the given node.
87 */
88 function book_node_visitor_opml_pre($node, $depth, $nid) {
89 // Output the content:
90 if (node_hook($node, 'content')) {
91 $node = node_invoke($node, 'content');
92 }
93
94 $output .= "<outline type=\"id:node-". $node->nid ."\"\n";
95 $text = check_plain($node->title);
96 $output .= "text=\"$text\">\n";
97 return $output;
98 }
99
100 /**
101 * Finishes up generation of OPML after visiting a node. This function
102 * is a 'post-node' visitor function for book_recurse().
103 */
104 function book_node_visitor_opml_post($node, $depth) {
105 return "</outline>\n";
106 }
107
108
109 /**
110 * Implementation of hook_help().
111 */
112 function export_opml_help($section) {
113 switch ($section) {
114 case 'admin/help#export_opml':
115 $output .= '<p>'. t('Users can choose to <em>export</em> the page and its subsections as an an OPML format outline (titles only) for editing with OPML aware outline editors, by selecting the <em>export OPML</em> link.') .'</p>';
116 return $output;
117 case 'admin/modules#description':
118 return t('Allows authorized users to export a book outline as OPML.');
119 case 'admin/node/export_opml':
120 return t("<p>The export_opml module offers a way to export a Drupal book's structural outline as OPML.</p>");
121 }
122 }
123
124
125

  ViewVC Help
Powered by ViewVC 1.1.2