/[pkg-tikiwiki]/tags/feature/1.9.5/external-libs/tiki-import_structuredtext.php
ViewVC logotype

Contents of /tags/feature/1.9.5/external-libs/tiki-import_structuredtext.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 124 - (show annotations) (download)
Tue Nov 7 12:14:33 2006 UTC (6 years, 7 months ago) by marcusb-guest
File size: 4255 byte(s)
Tag and move branch.
1 <?php
2 // $Header: /cvsroot/tikiwiki/tiki/tiki-import_structuredtext.php,v 1.1.2.6 2006/09/03 16:32:32 ohertel Exp $
3
4 // Copyright (c) 2002-2005, Luis Argerich, Garland Foster, Eduardo Polidor, et. al.
5 // All Rights Reserved. See copyright.txt for details and a complete list of authors.
6 // Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
7
8 require_once ('tiki-setup.php');
9
10 if ($tiki_p_admin != 'y') {
11 $smarty->assign('msg', tra("You do not have permission to use this feature"));
12 $smarty->display("error.tpl");
13 die;
14 }
15
16
17 function parse_st($dump) {
18 $bodysep = '>>>>>>>>>>>>>>>>>>>>>>>>';
19 $titlesep = '>>>>>>>>>>--------------';
20 $pages = preg_split("/$bodysep/",$dump);
21 $res = array();
22 array_shift($pages);
23 foreach ($pages as $p) {
24 $ret['pagename'] = trim(substr($p,0,strpos($p,">")));
25 $ret['pagename'] = str_replace(' ','',ucwords(str_replace('_',' ',$ret['pagename'])));
26 $ret['body'] = substr($p,strpos($p,$titlesep)+strlen($titlesep));
27 $res[] = $ret;
28 }
29 return $res;
30 }
31
32 $smarty->assign('result', 'n');
33
34 if (isset($_REQUEST["import"])) {
35 check_ticket('import-st');
36
37 $path = 'dump/'.$tikidomain.'/'.$_REQUEST["path"];
38
39 if (is_file($path)) {
40 $fp = fopen($path, "r");
41 $full = fread($fp, filesize($path));
42 //$full = fread($fp, 16000);
43 fclose ($fp);
44
45 $parts = parse_st($full);
46
47 foreach ($parts as $part) {
48
49 $part["body"] = preg_replace("/\[([^\]]*)\]/e", "str_replace(' ','',ucwords('(($1))'))", $part["body"]);
50 $part["body"] = preg_replace("/(\(\([^\)]*\)\))/e", "str_replace(' ','',ucwords('$1'))", $part["body"]);
51
52 $part["body"] = preg_replace("/( |\n|^)(http:\/\/[^ ]+)( |\n)/", "$1[$2]$3", $part["body"]);
53
54 // "A link to Google":http://google.com
55 $part["body"] = preg_replace("~\"([^\"]*)\":(((ht|f)tps?://|mailto:)[^\s]*)~", "[$2|$1]", $part["body"]);
56
57 // internal labelled links
58 $part["body"] = preg_replace("~\"([^\"]+)\":([^\s]+)~", "(($2|$1))", $part["body"]);
59
60 // html links
61 $part["body"] = preg_replace("~<a href=\"([^\"]*)\">([^<]*)</a>~", "[$1|$2]", $part["body"]);
62
63 // remove <br>
64 $part["body"] = preg_replace("/<br(\s*\/)?>(\r?\n)?/", "\n", $part["body"]);
65
66 // manage lists
67 $part["body"] = preg_replace("/\n \*/","\n**", $part["body"]);
68 $part["body"] = preg_replace("/\n \*/","\n***", $part["body"]);
69
70 // change <b>..</b>
71 $part["body"] = preg_replace("/ _([^_]*)_ /", " ===$1=== ", $part["body"]);
72 $part["body"] = preg_replace("/\*\*([^\*\n]+)\*\*/", "__$1__", $part["body"]);
73 $part["body"] = preg_replace("~<b>([^<]*)</b>~", "__$1__", $part["body"]);
74 $part["body"] = preg_replace("/\*([^\*\n]+)\*/", "''$1''", $part["body"]);
75 $part["body"] = preg_replace("~<i>([^<]*)</i>~", "''$1''", $part["body"]);
76
77 // change <hr>
78 $part["body"] = preg_replace("/<hr(\s*\/)?>(\r?\n)?/", "---\n", $part["body"]);
79
80 // manage formatting
81 $part["body"] = preg_replace("/^(\n*)([^\n]+)(\n\n) /","!$2$3", $part["body"]);
82 $part["body"] = preg_replace("/(\n\n)([^\n]{1,200})(\n\n) /","$1!!$2$3", $part["body"]);
83 $part["body"] = preg_replace("/\n +/","\n", $part["body"]);
84
85 $pagename = urldecode($part["pagename"]);
86
87 $msg = '';
88
89 if (isset($_REQUEST["remo"]) and $_REQUEST["remo"] == 'y') {
90 $tikilib->remove_all_versions($pagename, '');
91 }
92
93 if ($tikilib->page_exists($pagename)) {
94 if (isset($_REQUEST["crunch"]) and $_REQUEST["crunch"] == 'y') {
95 $msg = '<b>' . tra('overwriting old page'). '</b>';
96 $tikilib->update_page($pagename, $part["body"], tra('updated from structured text import'), 'System', '0.0.0.0', '');
97 } else {
98 $msg = '<b>' . tra('page not added (Exists)'). '</b>';
99 }
100 } else {
101 $msg = tra('page created');
102 $tikilib->create_page($pagename, 0, $part["body"], time(), tra('created from structured text import'), 'System', 0, '');
103 }
104
105 $aux["page"] = $pagename;
106 $aux["ex"] = substr($part['body'],0,42);
107 $aux["msg"] = $msg;
108 $lines[] = $aux;
109 }
110 }
111
112 $smarty->assign('lines', $lines);
113 $smarty->assign('result', 'y');
114 }
115 ask_ticket('import-st');
116
117 // disallow robots to index page:
118 $smarty->assign('metatag_robots', 'NOINDEX, NOFOLLOW');
119
120 $smarty->assign('mid', 'tiki-import_structuredtext.tpl');
121 $smarty->display("tiki.tpl");
122
123 ?>

  ViewVC Help
Powered by ViewVC 1.1.5