diff options
-rw-r--r-- | 3rdparty/SimplePie/library/SimplePie/IRI.php | 42 | ||||
-rw-r--r-- | 3rdparty/SimplePie/library/SimplePie/Misc.php | 12 | ||||
-rw-r--r-- | ajax/importopml.php | 98 |
3 files changed, 74 insertions, 78 deletions
diff --git a/3rdparty/SimplePie/library/SimplePie/IRI.php b/3rdparty/SimplePie/library/SimplePie/IRI.php index ffe3c9d91..012866da6 100644 --- a/3rdparty/SimplePie/library/SimplePie/IRI.php +++ b/3rdparty/SimplePie/library/SimplePie/IRI.php @@ -768,31 +768,27 @@ class SimplePie_IRI */ public function is_valid() { + $isauthority = $this->iuserinfo !== null || $this->ihost !== null || $this->port !== null; + if ($this->ipath !== '' && + ( + $isauthority && ( + $this->ipath[0] !== '/' || + substr($this->ipath, 0, 2) === '//' + ) || + ( + $this->scheme === null && + !$isauthority && + strpos($this->ipath, ':') !== false && + (strpos($this->ipath, '/') === false ? true : strpos($this->ipath, ':') < strpos($this->ipath, '/')) + ) + ) + ) + { + return false; + } + return true; } -// NOTE: this is temporary commented out to bypass issue #214: https://github.com/simplepie/simplepie/issues/214 -// -// $isauthority = $this->iuserinfo !== null || $this->ihost !== null || $this->port !== null; -// if ($this->ipath !== '' && -// ( -// $isauthority && ( -// $this->ipath[0] !== '/' || -// substr($this->ipath, 0, 2) === '//' -// ) || -// ( -// $this->scheme === null && -// !$isauthority && -// strpos($this->ipath, ':') !== false && -// (strpos($this->ipath, '/') === false ? true : strpos($this->ipath, ':') < strpos($this->ipath, '/')) -// ) -// ) -// ) -// { -// return false; -// } -// -// return true; -// } /** * Set the entire IRI. Returns true on success, false on failure (if there diff --git a/3rdparty/SimplePie/library/SimplePie/Misc.php b/3rdparty/SimplePie/library/SimplePie/Misc.php index 8af6b75ec..5c20f962b 100644 --- a/3rdparty/SimplePie/library/SimplePie/Misc.php +++ b/3rdparty/SimplePie/library/SimplePie/Misc.php @@ -80,7 +80,13 @@ class SimplePie_Misc public static function absolutize_url($relative, $base) { $iri = SimplePie_IRI::absolutize(new SimplePie_IRI($base), $relative); - return $iri->get_uri(); + +//NOTE: this is temporary commented out to bypass issue #214: https://github.com/simplepie/simplepie/issues/214 + if ( is_object( $iri ) ) { + return $iri->get_uri(); + } else { + return FALSE; + } } /** @@ -271,7 +277,9 @@ class SimplePie_Misc */ public static function windows_1252_to_utf8($string) { - static $convert_table = array("\x80" => "\xE2\x82\xAC", "\x81" => "\xEF\xBF\xBD", "\x82" => "\xE2\x80\x9A", "\x83" => "\xC6\x92", "\x84" => "\xE2\x80\x9E", "\x85" => "\xE2\x80\xA6", "\x86" => "\xE2\x80\xA0", "\x87" => "\xE2\x80\xA1", "\x88" => "\xCB\x86", "\x89" => "\xE2\x80\xB0", "\x8A" => "\xC5\xA0", "\x8B" => "\xE2\x80\xB9", "\x8C" => "\xC5\x92", "\x8D" => "\xEF\xBF\xBD", "\x8E" => "\xC5\xBD", "\x8F" => "\xEF\xBF\xBD", "\x90" => "\xEF\xBF\xBD", "\x91" => "\xE2\x80\x98", "\x92" => "\xE2\x80\x99", "\x93" => "\xE2\x80\x9C", "\x94" => "\xE2\x80\x9D", "\x95" => "\xE2\x80\xA2", "\x96" => "\xE2\x80\x93", "\x97" => "\xE2\x80\x94", "\x98" => "\xCB\x9C", "\x99" => "\xE2\x84\xA2", "\x9A" => "\xC5\xA1", "\x9B" => "\xE2\x80\xBA", "\x9C" => "\xC5\x93", "\x9D" => "\xEF\xBF\xBD", "\x9E" => "\xC5\xBE", "\x9F" => "\xC5\xB8", "\xA0" => "\xC2\xA0", "\xA1" => "\xC2\xA1", "\xA2" => "\xC2\xA2", "\xA3" => "\xC2\xA3", "\xA4" => "\xC2\xA4", "\xA5" => "\xC2\xA5", "\xA6" => "\xC2\xA6", "\xA7" => "\xC2\xA7", "\xA8" => "\xC2\xA8", "\xA9" => "\xC2\xA9", "\xAA" => "\xC2\xAA", "\xAB" => "\xC2\xAB", "\xAC" => "\xC2\xAC", "\xAD" => "\xC2\xAD", "\xAE" => "\xC2\xAE", "\xAF" => "\xC2\xAF", "\xB0" => "\xC2\xB0", "\xB1" => "\xC2\xB1", "\xB2" => "\xC2\xB2", "\xB3" => "\xC2\xB3", "\xB4" => "\xC2\xB4", "\xB5" => "\xC2\xB5", "\xB6" => "\xC2\xB6", "\xB7" => "\xC2\xB7", "\xB8" => "\xC2\xB8", "\xB9" => "\xC2\xB9", "\xBA" => "\xC2\xBA", "\xBB" => "\xC2\xBB", "\xBC" => "\xC2\xBC", "\xBD" => "\xC2\xBD", "\xBE" => "\xC2\xBE", "\xBF" => "\xC2\xBF", "\xC0" => "\xC3\x80", "\xC1" => "\xC3\x81", "\xC2" => "\xC3\x82", "\xC3" => "\xC3\x83", "\xC4" => "\xC3\x84", "\xC5" => "\xC3\x85", "\xC6" => "\xC3\x86", "\xC7" => "\xC3\x87", "\xC8" => "\xC3\x88", "\xC9" => "\xC3\x89", "\xCA" => "\xC3\x8A", "\xCB" => "\xC3\x8B", "\xCC" => "\xC3\x8C", "\xCD" => "\xC3\x8D", "\xCE" => "\xC3\x8E", "\xCF" => "\xC3\x8F", "\xD0" => "\xC3\x90", "\xD1" => "\xC3\x91", "\xD2" => "\xC3\x92", "\xD3" => "\xC3\x93", "\xD4" => "\xC3\x94", "\xD5" => "\xC3\x95", "\xD6" => "\xC3\x96", "\xD7" => "\xC3\x97", "\xD8" => "\xC3\x98", "\xD9" => "\xC3\x99", "\xDA" => "\xC3\x9A", "\xDB" => "\xC3\x9B", "\xDC" => "\xC3\x9C", "\xDD" => "\xC3\x9D", "\xDE" => "\xC3\x9E", "\xDF" => "\xC3\x9F", "\xE0" => "\xC3\xA0", "\xE1" => "\xC3\xA1", "\xE2" => "\xC3\xA2", "\xE3" => "\xC3\xA3", "\xE4" => "\xC3\xA4", "\xE5" => "\xC3\xA5", "\xE6" => "\xC3\xA6", "\xE7" => "\xC3\xA7", "\xE8" => "\xC3\xA8", "\xE9" => "\xC3\xA9", "\xEA" => "\xC3\xAA", "\xEB" => "\xC3\xAB", "\xEC" => "\xC3\xAC", "\xED" => "\xC3\xAD", "\xEE" => "\xC3\xAE", "\xEF" => "\xC3\xAF", "\xF0" => "\xC3\xB0", "\xF1" => "\xC3\xB1", "\xF2" => "\xC3\xB2", "\xF3" => "\xC3\xB3", "\xF4" => "\xC3\xB4", "\xF5" => "\xC3\xB5", "\xF6" => "\xC3\xB6", "\xF7" => "\xC3\xB7", "\xF8" => "\xC3\xB8", "\xF9" => "\xC3\xB9", "\xFA" => "\xC3\xBA", "\xFB" => "\xC3\xBB", "\xFC" => "\xC3\xBC", "\xFD" => "\xC3\xBD", "\xFE" => "\xC3\xBE", "\xFF" => "\xC3\xBF"); + static $convert_table = array("\x80" => "\xE2\x82\xAC", "\x81" => "\xEF\xBF\xBD", "\x82" => "\xE2\x80\x9A", "\x83" => "\xC6\x92", "\x84" => "\xE2\x80\x9E", "\x85" => "\xE2\x80\xA6", "\x86" => "\xE2\x80\xA0", "\x87" => "\xE2\x80\xA1", "\x88" => "\xCB\x86", "\x89" => "\xE2\x80\xB0", "\x8A" => "\xC5\xA0", "\x8B" => "\xE2\x80\xB9", "\x8C" => "\xC5\x92", "\x8D" => "\xEF\xBF\xBD", "\x8E" => "\xC5\xBD", "\x8F" => "\xEF\xBF\xBD", "\x90" => "\xEF\xBF\xBD", "\x91" => "\xE2\x80\x98", "\x92" => "\xE2\x80\x99", "\x93" => "\xE2\x80\x9C", "\x94" => "\xE2\x80\x9D", "\x95" => "\xE2\x80\xA2", "\x96" => "\xE2\x80\x93", "\x97" => "\xE2\x80\x94", "\x98" => "\xCB\x9C", "\x99" => "\xE2\x84\xA2", "\x9A" => "\xC5\xA1", "\x9B" => "\xE2\x80\xBA", "\x9C" => "\xC5\x93", "\x9D" => "\xEF\xBF\xBD", "\x9E" => "\xC5\xBE", "\x9F" => "\xC5\xB8", "\xA0" => "\xC2\xA0", "\xA1" => "\xC2\xA1", "\xA2" => "\xC2\xA2", "\xA3" => "\xC2\xA3", "\xA4" => "\xC2\xA4", "\xA5" => "\xC2\xA5", "\xA6" => "\xC2\xA6", "\xA7" => "\xC2\xA7", "\xA8" => "\xC2\xA8", "\ +xA9" => "\xC2\xA9", "\xAA" => "\xC2\xAA", "\xAB" => "\xC2\xAB", "\xAC" => "\xC2\xAC", "\xAD" => "\xC2\xAD", "\xAE" => "\xC2\xAE", "\xAF" => "\xC2\xAF", "\xB0" => "\xC2\xB0", "\xB1" => "\xC2\xB1", "\xB2" => "\xC2\xB2", "\xB3" => "\xC2\xB3", "\xB4" => "\xC2\xB4", "\xB5" => "\xC2\xB5", "\xB6" => "\xC2\xB6", "\xB7" => "\xC2\xB7", "\xB8" => "\xC2\xB8", "\xB9" => "\xC2\xB9", "\xBA" => "\xC2\xBA", "\xBB" => "\xC2\xBB", "\xBC" => "\xC2\xBC", "\xBD" => "\xC2\xBD", "\xBE" => "\xC2\xBE", "\xBF" => "\xC2\xBF", "\xC0" => "\xC3\x80", "\xC1" => "\xC3\x81", "\xC2" => "\xC3\x82", "\xC3" => "\xC3\x83", "\xC4" => "\xC3\x84", "\xC5" => "\xC3\x85", "\xC6" => "\xC3\x86", "\xC7" => "\xC3\x87", "\xC8" => "\xC3\x88", "\xC9" => "\xC3\x89", "\xCA" => "\xC3\x8A", "\xCB" => "\xC3\x8B", "\xCC" => "\xC3\x8C", "\xCD" => "\xC3\x8D", "\xCE" => "\xC3\x8E", "\xCF" => "\xC3\x8F", "\xD0" => "\xC3\x90", "\xD1" => "\xC3\x91", "\xD2" => "\xC3\x92", "\xD3" => "\xC3\x93", "\xD4" => "\xC3\x94", "\xD5" => "\xC3\x95", "\xD6" => "\xC3\x96", "\xD7" => "\ +xC3\x97", "\xD8" => "\xC3\x98", "\xD9" => "\xC3\x99", "\xDA" => "\xC3\x9A", "\xDB" => "\xC3\x9B", "\xDC" => "\xC3\x9C", "\xDD" => "\xC3\x9D", "\xDE" => "\xC3\x9E", "\xDF" => "\xC3\x9F", "\xE0" => "\xC3\xA0", "\xE1" => "\xC3\xA1", "\xE2" => "\xC3\xA2", "\xE3" => "\xC3\xA3", "\xE4" => "\xC3\xA4", "\xE5" => "\xC3\xA5", "\xE6" => "\xC3\xA6", "\xE7" => "\xC3\xA7", "\xE8" => "\xC3\xA8", "\xE9" => "\xC3\xA9", "\xEA" => "\xC3\xAA", "\xEB" => "\xC3\xAB", "\xEC" => "\xC3\xAC", "\xED" => "\xC3\xAD", "\xEE" => "\xC3\xAE", "\xEF" => "\xC3\xAF", "\xF0" => "\xC3\xB0", "\xF1" => "\xC3\xB1", "\xF2" => "\xC3\xB2", "\xF3" => "\xC3\xB3", "\xF4" => "\xC3\xB4", "\xF5" => "\xC3\xB5", "\xF6" => "\xC3\xB6", "\xF7" => "\xC3\xB7", "\xF8" => "\xC3\xB8", "\xF9" => "\xC3\xB9", "\xFA" => "\xC3\xBA", "\xFB" => "\xC3\xBB", "\xFC" => "\xC3\xBC", "\xFD" => "\xC3\xBD", "\xFE" => "\xC3\xBE", "\xFF" => "\xC3\xBF"); return strtr($string, $convert_table); } diff --git a/ajax/importopml.php b/ajax/importopml.php index 7911a4db9..b21939b29 100644 --- a/ajax/importopml.php +++ b/ajax/importopml.php @@ -41,10 +41,9 @@ if ($parsed == null) { bailOut($l->t('An error occurred while parsing the file.')); } - $data = $parsed->getData(); -function createFeed($feedurl, $folderid) { +function importFeed($feedurl, $folderid) { $feedmapper = new OCA\News\FeedMapper(); $feedid = $feedmapper->findIdFromUrl($feedurl); @@ -57,71 +56,64 @@ function createFeed($feedurl, $folderid) { $feedid = $feedmapper->save($feed, $folderid); } } else { - OCP\Util::writeLog('news','ajax/createfeed.php: Error adding feed: '. $feedurl, OCP\Util::ERROR); + OCP\Util::writeLog('news','ajax/importopml.php: Error adding feed: '. $feedurl, OCP\Util::ERROR); return false; } if($feed === null || !$feedid) { - OCP\Util::writeLog('news','ajax/createfeed.php: Error adding feed: '. $feedurl, OCP\Util::ERROR); + OCP\Util::writeLog('news','ajax/importopml.php: Error adding feed: '. $feedurl, OCP\Util::ERROR); return false; } return true; } -$countadded = 0; -foreach($data as $collection) { - if ($collection instanceOf Feed) { - $feedurl = $collection->getUrl(); - $folderid = 0; - if (createFeed($feedurl, $folderid)) { - $countadded++; - } +function importFolder($name, $parentid) { + $foldermapper = new OCA\News\FolderMapper(); + + if($parentid != 0) { + $folder = new OCA\News\Folder($name, NULL, $foldermapper->find($parentid)); + } else { + $folder = new OCA\News\Folder($name); + } + + $folderid = $foldermapper->save($folder); + + $l = OC_L10N::get('news'); + + if(!$folderid) { + OCP\Util::writeLog('news','ajax/importopml.php: Error adding folder' . $name, OCP\Util::ERROR); + return null; } + + return $folderid; } +function importList($data, $parentid) { + $countsuccess = 0; + foreach($data as $collection) { + if ($collection instanceOf OCA\News\Feed) { + $feedurl = $collection->getUrl(); + if (importFeed($feedurl, $parentid)) { + $countsuccess++; + } + } + else if ($collection instanceOf OCA\News\Folder) { + $folderid = importFolder($collection->getName(), $parentid); + if ($folderid) { + $children = $collection->getChildren(); + $countsuccess += importList($children, $folderid); + } + } + else { + OCP\Util::writeLog('news','ajax/importopml.php: Error importing OPML',OCP\Util::ERROR); + } + } + return $countsuccess; +} -// // $ch is the handler for the curl connection -// function addFeed($feedurl, $folderid, $ch) { -// -// $data = array('feedurl' => $feedurl, 'folderid' => $folderid); -// curl_setopt($ch, CURLOPT_POSTFIELDS, $data); -// $result = curl_exec($ch); -// $status = curl_getinfo($ch); -// -// if($result === false) { -// bailOut(curl_error($ch)); -// } else { -// bailOut($status['http_code'] . $status['url']); -// } -// } - -// $url = OCP\Util::linkToAbsolute('news', 'ajax/createfeed.php'); -// $ch = curl_init($url); -// if ($ch != false) { -// curl_setopt($ch, CURLOPT_POST, TRUE); -// curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); -// curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); -// curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE); -// curl_setopt($ch, CURLOPT_USERPWD, 'acosenti:nopass'); -// -// -// foreach($data as $collection) { -// if ($collection instanceOf OC_News_Feed) { -// $feedurl = $collection->getUrl(); -// $folderid = 0; -// addFeed($feedurl, $folderid, $ch); -// } -// } -// -// addFeed(null, null, $ch); -// $result = curl_exec($ch); -// -// curl_close($ch); -// } else { -// bailOut($l->t('An error occurred while adding the feeds.')); -// } +$countsuccess = importList($data, 0); OCP\JSON::success(array('data' => array('title'=>$parsed->getTitle(), 'count'=>$parsed->getCount(), - 'countsuccess'=>$countadded))); + 'countsuccess'=>$countsuccess))); |