/[drupal]/contributions/sandbox/junyor/import/blogger/4-5/blogger.inc
ViewVC logotype

Contents of /contributions/sandbox/junyor/import/blogger/4-5/blogger.inc

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


Revision 1.1 - (show annotations) (download) (as text)
Tue Apr 19 16:35:45 2005 UTC (4 years, 7 months ago) by junyor
Branch: MAIN
CVS Tags: HEAD
File MIME type: text/x-php
4.5.x and development version of Blogger importer
1 <?php
2 function import_set_title($title, $body) {
3 if ($title == '') {
4 $subject = '';
5 $arr = explode(' ', $body);
6
7 for($i = 0; $i < 5; $i++) {
8 $subject .= $arr[$i] . ' ';
9 }
10
11 strip_tags($subject);
12 }
13
14 else {
15 $subject = $title;
16 }
17
18 return $subject;
19 }
20
21 // add alias path to prevent broken links
22 // strip off first part of absolute part of URL (path module wants a relative URL)
23 function import_create_path($path, $nid) {
24 global $count_pid;
25
26 if (module_exist('path')) {
27 $path_array = parse_url($path);
28 $path = str_replace(dirname($_SERVER['PHP_SELF']), '', $path_array['path']);
29 $path = ltrim($path, "/");
30
31 path_set_alias("node/$nid", $path);
32 $count_pid++;
33 }
34 }
35
36 /**
37 * set author
38 * check if user already exists, otherwise add them
39 * use user e-mail as the key
40 */
41 function import_create_user($mail, $name) {
42 global $count_uid;
43
44 $user = user_load(array('mail' => $mail));
45
46 // echo('User ' . $user->uid . ' loaded.<BR><BR>');
47
48 if (!isset($user->uid)) {
49 $user->mail = $mail;
50 $user->name = $name;
51
52 $user = user_save(NULL, array('name' => $user->name, 'mail' => $user->mail, 'status' => 1, 'roles' => array(_user_authenticated_id())));
53 $count_uid++;
54 // echo('User ' . $user->uid . ' created.<BR><BR>');
55 }
56
57 return $user;
58 }
59
60 function import_create_node($node) {
61 global $count_nid;
62
63 $newNode = node_validate($node);
64
65 $newNode->nid = node_save($newNode);
66 $count_nid++;
67 /*
68 if ($errors = form_get_errors()) {
69 echo("Error in node $newNode->nid: ");
70 echo(implode("\n", $errors) . '<BR>');
71 }
72 */
73 return $newNode;
74 }
75
76 function import_create_comment($comment) {
77 global $user;
78
79 $user = user_load(array('uid' => 0));
80
81 $comment = _import_get_comment_user($comment);
82
83 $cid = comment_post(array("comment" => $comment->comment, "pid" => 0, "nid" => $node->nid, "timestamp" => $comment->timestamp, "name" => $comment->name, "homepage" => $comment->homepage));
84
85 $count_cid++;
86
87 return;
88 }
89
90 /**
91 * Blogger outputs commentor names as links if they have a profile
92 * This function separates the link, if present, from the name
93 */
94 function _import_get_comment_user($comment) {
95
96 $comment->homepage = _import_parse_link($comment->name);
97
98 $comment->name = strip_tags($comment->name);
99
100 return $comment;
101 }
102
103 /**
104 * Parse a link tag to get HREF
105 */
106 function _import_parse_link($str)
107 {
108 if (($openStart = strpos($str, "<")) !== false) {
109 $openStart++;
110 $openEnd = strpos($str, ">");
111 $parsedStr = substr($str, $openStart, ($openEnd - $openStart));
112 $parsedArray = explode(' ', $parsedStr);
113
114 // go through attributes, skipping tag name
115 for ($i = 1; $i < count($parsedArray); $i++) {
116 $attribute = strtolower(strtok($parsedArray[$i], "="));
117 $value = strtok('=');
118 $newStr = $value;
119 }
120 $newStr = trim($newStr, '"');
121 }
122 else {
123 $newStr = '';
124 }
125
126 return $newStr;
127 }
128
129 ?>

  ViewVC Help
Powered by ViewVC 1.1.2