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

Contents of /contributions/modules/artman2/artman2.module

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


Revision 1.2 - (show annotations) (download) (as text)
Fri Sep 5 19:52:50 2008 UTC (14 months, 3 weeks ago) by bangpound
Branch: MAIN
CVS Tags: HEAD
Branch point for: DRUPAL-6--1
Changes since 1.1: +1 -24 lines
File MIME type: text/x-php
remove irrelevant hook_filter implementation
1 <?php
2 // $Id: artman2.module,v 1.1 2008/09/05 19:50:47 bangpound Exp $
3
4 /**
5 * @file
6 * Article Manager 2 migration module
7 *
8 * @description Article Manager 2 data migration to nodes
9 */
10
11 module_load_include('inc', 'artman2');
12
13 function artman2_menu() {
14 $items['admin/content/artman2'] = array(
15 'title' => 'Article Manager 2',
16 'description' => "View and migrate your Article Manager 2 article content.",
17 'page callback' => 'drupal_get_form',
18 'page arguments' => array('artman2_admin_settings'),
19 'access arguments' => array('administer nodes'),
20 'type' => MENU_NORMAL_ITEM,
21 'file' => 'artman2.admin.inc',
22 );
23 return $items;
24 }
25
26 /**
27 * Implementation of hook_help().
28 */
29 function artman2_help($path, $arg) {
30 switch ($path) {
31 case 'admin/help#artman2':
32 $output = 'Article Manager 2';
33 return $output;
34 }
35 }
36
37 function artman2_cron() {
38 if (variable_get('artman2_migrate', FALSE)) {
39 _artman2_db_connect();
40 $limit = (int)variable_get('artman2_cron_limit', 10);
41 $drupal_max = db_result(db_query('SELECT MAX(num) FROM {artman2}'));
42 $drupal_latest = db_result(db_query('SELECT MAX(last_updated_time) FROM {artman2}'));
43 db_set_active('artman2');
44 $result = db_query_range("SELECT * FROM {article} WHERE num > %d OR lastUpdatedTime > %d ORDER BY lastUpdatedTime", $drupal_max, $drupal_latest, 0, $limit);
45 db_set_active();
46 while ($article = db_fetch_object($result)) {
47 if ($nid = artman2_num2nid($article->num)) {
48 $node = node_load($nid);
49 }
50 else {
51 $node = new stdClass();
52 }
53 artman2_migrate($node, $article);
54 }
55 }
56 }
57
58 /**
59 * Set database connection for artman2
60 */
61 function _artman2_db_connect() {
62 global $db_url;
63 global $db_prefix;
64
65 if (is_array($db_url)) {
66 $db_url2 = $db_url;
67 $db_url2['artman2'] = variable_get('artman2_db_url', '');
68 }
69 else {
70 $db_url2['default'] = $db_url;
71 $db_url2['artman2'] = variable_get('artman2_db_url', '');
72 }
73
74 if (is_array($db_prefix)) {
75 $db_prefix2 = $db_prefix;
76 $db_prefix2['article'] = variable_get('artman2_db_prefix', 'db_');
77 }
78 else {
79 $db_prefix2['default'] = $db_prefix;
80 $db_prefix2['article'] = variable_get('artman2_db_prefix', 'db_');
81 }
82
83 $GLOBALS['db_url'] =& $db_url2;
84 $GLOBALS['db_prefix'] =& $db_prefix2;
85 }
86
87 function artman2_theme() {
88 return array(
89 'artman2_image' => array(
90 'arguments' => array('path' => NULL, 'alt' => NULL, 'title' => NULL, 'attributes' => NULL, 'caption' => NULL),
91 ),
92 );
93 }
94
95 function theme_artman2_image($path, $alt = '', $title = '', $attributes = array(), $caption = '') {
96 drupal_add_css(drupal_get_path('module', 'artman2') .'/artman2.css');
97 $output = '<span'. drupal_attributes($attributes) .'>';
98 $output .= theme('image', $path, $alt, $title, NULL, FALSE);
99 if ($caption) {
100 $output .= '<span class="caption">'. $caption .'</span>';
101 }
102 $output .= '</span>';
103 return $output;
104 }
105
106 function artman2_nid2num($nid) {
107 return db_result(db_query('SELECT num FROM {artman2} WHERE nid = %d', $nid));
108 }
109
110 function artman2_num2nid($num) {
111 return db_result(db_query('SELECT nid FROM {artman2} WHERE num = %d', $num));
112 }
113
114 function artman2_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
115 switch ($op) {
116 case 'load':
117 $artman2_num = artman2_nid2num($node->nid);
118 if ($artman2_num) {
119 _artman2_db_connect();
120 db_set_active('artman2');
121 $output['artman2'] = db_fetch_object(db_query("SELECT * FROM {article} WHERE num = %d", $artman2_num));
122 db_set_active();
123 return $output;
124 }
125 break;
126 case 'insert':
127 if ($node->artman2) {
128 $article = $node->artman2;
129 $map->nid = $node->nid;
130 $map->num = $article->num;
131 $map->last_updated_time = $article->lastUpdatedTime;
132 drupal_write_record('artman2', $map);
133 }
134 break;
135 case 'update':
136 if ($node->artman2) {
137 $article = $node->artman2;
138 $map->nid = $node->nid;
139 $map->num = $article->num;
140 $map->last_updated_time = $article->lastUpdatedTime;
141 drupal_write_record('artman2', $map, array('nid'));
142 }
143 break;
144 case 'delete':
145 if ($node->artman2) {
146 db_query('DELETE FROM {artman2} WHERE nid = %d', $node->nid);
147 }
148 break;
149 case 'alter':
150 if ($node->artman2) {
151 $article = $node->artman2;
152 $image = $article->image;
153 $node->teaser = _artman2_images($node->teaser, $image);
154 $node->body = _artman2_images($node->body, $image);
155 }
156 break;
157 default:
158 break;
159 }
160 }
161
162 function artman2_migrate($node, $article) {
163 $node_type_default = variable_get('node_options_'. $node->type, array('status', 'promote'));
164
165 $node->title = filter_xss($article->title, array());
166 $node->type = variable_get('artman2_default_node_type', 'story');
167 if ($article->content) {
168 $node->teaser = _artman2_stripbr($article->summary);
169 $node->body = "<!--break-->\r\n". _artman2_stripbr($article->content);
170 }
171 else {
172 $node->teaser = _artman2_stripbr($article->summary);
173 $node->body = _artman2_stripbr($article->summary) ."\r\n<!--break-->\r\n";
174 }
175 $node->format = variable_get('artman2_default_format', 0);
176
177 $node->created = $article->createdTime;
178
179 $node->revision = in_array('revision', $node_type_default);
180 $node->log = 'imported from Article Manager 2';
181
182 $node->status = ($article->status == 'visible' ? 1 : 0);
183 $node->promote = in_array('promote', $node_type_default);
184 $node->sticky = in_array('sticky', $node_type_default);
185
186 $node->comment = variable_get('comment_'. $node->type, 2);
187
188 if (function_exists('artman2_map')) {
189 if ($extra = artman2_map($article)) {
190 foreach ($extra as $key => $value) {
191 $node->$key = $value;
192 }
193 }
194 }
195
196 $node->artman2 = $article;
197
198 node_save($node);
199 }
200
201 function _artman2_stripbr($text) {
202 $pattern = array('|\s?+<br ?/?>\s?+|i');
203 $replacement = array("\n");
204 return preg_replace($pattern, $replacement, $text);
205 }
206
207 function _artman2_images($text, $artman2_image) {
208 $input = explode("\t", $artman2_image);
209 if ($count = array_shift($input)) {
210 foreach ($input as $string) {
211 parse_str($string, $image);
212 $images[$image['_num']] = $image;
213 }
214 }
215 if (is_array($images)) {
216 foreach ($images as $key => $image) {
217 $attributes = array();
218 $attributes['class'] = "artman2 artman2-$image[align]";
219 $attributes['style'] = "width:$image[width]px;";
220 $themed_image = theme('artman2_image', variable_get('artman2_upload_path', '') . $image['pathFromUploadDir'], $image['caption'], $image['title'], $attributes, $image['caption']);
221 $token = '***image'. $key .'***';
222 $text = str_replace($token, $themed_image, $text);
223 }
224 }
225 return $text;
226 }

  ViewVC Help
Powered by ViewVC 1.1.2