| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
function searchBack($haystack, $needle, $offset=0) { |
|---|
| 7 |
$strrpos = false; |
|---|
| 8 |
if (is_string($haystack) && is_string($needle) && is_numeric($offset)) { |
|---|
| 9 |
$strlen = strlen($haystack); |
|---|
| 10 |
if ($offset <= 0) |
|---|
| 11 |
$offset = $strlen + $offset; |
|---|
| 12 |
|
|---|
| 13 |
$strpos = strpos(strrev(substr($haystack, 0, $offset)), strrev($needle)); |
|---|
| 14 |
if (is_numeric($strpos)) { |
|---|
| 15 |
$strrpos = $offset - $strpos - strlen($needle); |
|---|
| 16 |
} |
|---|
| 17 |
} |
|---|
| 18 |
return $strrpos; |
|---|
| 19 |
} |
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
function changeLog($logFile, $action, $item) { |
|---|
| 23 |
$timeStamp = date('Y-m-d G:i:s T'); |
|---|
| 24 |
$logString = "<history:$action><date>$timeStamp</date>$item</history:$action>\n"; |
|---|
| 25 |
$fh = fopen($logFile, 'a'); |
|---|
| 26 |
fwrite($fh, $logString); |
|---|
| 27 |
fclose($fh); |
|---|
| 28 |
} |
|---|
| 29 |
|
|---|
| 30 |
|
|---|
| 31 |
function getTrimmedArray($separator, $string) { |
|---|
| 32 |
$tmp = explode($separator, $string); |
|---|
| 33 |
for ($i = 0; $i < count($tmp); $i++) |
|---|
| 34 |
$tmp[$i] = trim($tmp[$i]); |
|---|
| 35 |
return $tmp; |
|---|
| 36 |
} |
|---|
| 37 |
|
|---|
| 38 |
|
|---|
| 39 |
function getContent($xml, $startTag, $endTag) { |
|---|
| 40 |
$content = ""; |
|---|
| 41 |
$startPos = strpos($xml, $startTag); |
|---|
| 42 |
if ($startPos === false) |
|---|
| 43 |
return $content; |
|---|
| 44 |
|
|---|
| 45 |
$endPos = strpos($xml, $endTag, $startPos); |
|---|
| 46 |
if ($endPos === false) |
|---|
| 47 |
return $content; |
|---|
| 48 |
|
|---|
| 49 |
$startPos += strlen($startTag); |
|---|
| 50 |
$content = substr($xml, $startPos, $endPos - $startPos); |
|---|
| 51 |
|
|---|
| 52 |
return $content; |
|---|
| 53 |
|
|---|
| 54 |
|
|---|
| 55 |
getTagContent($xml, $tag) { |
|---|
| 56 |
getContent($xml, "<$tag>", "</$tag>"); |
|---|
| 57 |
|
|---|
| 58 |
|
|---|
| 59 |
|
|---|
| 60 |
|
|---|
| 61 |
function xml2fields($item) { |
|---|
| 62 |
$url = getTagContent($item, "link"); |
|---|
| 63 |
$title = getTagContent($item, "title"); |
|---|
| 64 |
$desc = getTagContent($item, "description"); |
|---|
| 65 |
$desc = substr($desc, 9); |
|---|
| 66 |
$desc = substr($desc, 0, strlen($desc) - 3); |
|---|
| 67 |
$user = getTagContent($item, "author"); |
|---|
| 68 |
|
|---|
| 69 |
$geoType = "point"; |
|---|
| 70 |
$coords = ""; |
|---|
| 71 |
|
|---|
| 72 |
$line = getTagContent($item, "geo:line"); |
|---|
| 73 |
$poly = getTagContent($item, "geo:polygon"); |
|---|
| 74 |
if ($line != "") { |
|---|
| 75 |
$geoType = "line"; |
|---|
| 76 |
$coords = $line; |
|---|
| 77 |
|
|---|
| 78 |
} |
|---|
| 79 |
$poly != "") { |
|---|
| 80 |
$geoType = "polygon"; |
|---|
| 81 |
$coords = $poly; |
|---|
| 82 |
|
|---|
| 83 |
} |
|---|
| 84 |
|
|---|
| 85 |
$lat = getTagContent($item, "geo:lat"); |
|---|
| 86 |
$lon = getTagContent($item, "geo:long"); |
|---|
| 87 |
$lat != "" && $lon != "") |
|---|
| 88 |
$coords = $lat . "," . $lon; |
|---|
| 89 |
|
|---|
| 90 |
|
|---|
| 91 |
$imgurl = getTagContent($item, "photo:thumbnail"); |
|---|
| 92 |
|
|---|
| 93 |
$tags = ""; |
|---|
| 94 |
$categories = str_replace("</category><category>", ", ", $item); |
|---|
| 95 |
$tags = getTagContent($categories, "category"); |
|---|
| 96 |
|
|---|
| 97 |
$title, $url, $desc, $imgurl, $tags, $coords, $geoType, $user); |
|---|
| 98 |
|
|---|
| 99 |
|
|---|
| 100 |
|
|---|
| 101 |
function fields2xml($uid,$title,$url,$description,$imgurl,$tags,$coords,$geoType,$user) { |
|---|
| 102 |
$item = ''; |
|---|
| 103 |
if (empty($coords)) |
|---|
| 104 |
return $item; |
|---|
| 105 |
if (empty($file)) |
|---|
| 106 |
$file = "rss.xml"; |
|---|
| 107 |
|
|---|
| 108 |
|
|---|
| 109 |
$catTag = ""; |
|---|
| 110 |
$tmp = explode(",", $tags); |
|---|
| 111 |
foreach($tmp as $tag) { |
|---|
| 112 |
$catTag .= "<category>" . trim($tag) . "</category>"; |
|---|
| 113 |
} |
|---|
| 114 |
|
|---|
| 115 |
|
|---|
| 116 |
$imgTag = ""; |
|---|
| 117 |
if (!empty($imgurl)) { |
|---|
| 118 |
$imgTag = "<photo:thumbnail>" . $imgurl . "</photo:thumbnail>"; |
|---|
| 119 |
} |
|---|
| 120 |
|
|---|
| 121 |
|
|---|
| 122 |
$uidTag = ""; |
|---|
| 123 |
if (!empty($uid)) $uidTag = "<guid>$uid</guid>"; |
|---|
| 124 |
|
|---|
| 125 |
|
|---|
| 126 |
$coordString = trim($coords); |
|---|
| 127 |
|
|---|
| 128 |
if ($geoType == "point") { |
|---|
| 129 |
$tmp = explode(",", $coordString); |
|---|
| 130 |
$coordTag = "<geo:lat>$tmp[0]</geo:lat><geo:long>$tmp[1]</geo:long>"; |
|---|
| 131 |
} |
|---|
| 132 |
else if ($geoType == "line") |
|---|
| 133 |
$coordTag = "<geo:line>$coordString</geo:line>"; |
|---|
| 134 |
else if ($geoType == "polygon") |
|---|
| 135 |
$coordTag = "<geo:polygon>$coordString</geo:polygon>"; |
|---|
| 136 |
|
|---|
| 137 |
|
|---|
| 138 |
$item = "<item>" . $uidTag . "<title>$title</title><link>$url</link><description><![CDATA[" . $description . "]]></description><author>$user</author>" . $coordTag . $catTag . $imgTag . "</item>"; |
|---|
| 139 |
|
|---|
| 140 |
return $item; |
|---|
| 141 |
} |
|---|
| 142 |
|
|---|
| 143 |
|
|---|
| 144 |
|
|---|
| 145 |
?> |
|---|
| 146 |
|
|---|