- Timestamp:
- 03/08/18 17:58:39 (7 years ago)
- Branch:
- default
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
plugins/blogroll/class.dc.importblogroll.php
r2566 r3730 10 10 # 11 11 # -- END LICENSE BLOCK ----------------------------------------- 12 if (!defined('DC_RC_PATH')) { return;}12 if (!defined('DC_RC_PATH')) {return;} 13 13 14 14 class linksImporter 15 15 { 16 16 protected $entries = null; 17 17 18 public function parse($data) 19 { 20 if (preg_match('!<xbel(\s+version)?!', $data)) { 21 $this->_parseXBEL($data); 22 } 23 elseif (preg_match('!<opml(\s+version)?!', $data)) { 24 $this->_parseOPML($data); 25 } 26 else { 27 throw new Exception(__('You need to provide a XBEL or OPML file.')); 28 } 29 } 18 public function parse($data) 19 { 20 if (preg_match('!<xbel(\s+version)?!', $data)) { 21 $this->_parseXBEL($data); 22 } elseif (preg_match('!<opml(\s+version)?!', $data)) { 23 $this->_parseOPML($data); 24 } else { 25 throw new Exception(__('You need to provide a XBEL or OPML file.')); 26 } 27 } 30 28 29 protected function _parseOPML($data) 30 { 31 $xml = @simplexml_load_string($data); 32 if (!$xml) { 33 throw new Exception(__('File is not in XML format.')); 34 } 31 35 32 protected function _parseOPML($data) 33 { 34 $xml = @simplexml_load_string($data); 35 if (!$xml) throw new Exception(__('File is not in XML format.')); 36 $outlines = $xml->xpath("//outline"); 36 37 37 $outlines = $xml->xpath("//outline"); 38 $this->entries = array(); 39 foreach ($outlines as $outline) { 40 if (isset($outline['htmlUrl'])) { 41 $link = $outline['htmlUrl']; 42 } elseif (isset($outline['url'])) { 43 $link = $outline['url']; 44 } else { 45 continue; 46 } 38 47 39 $this->entries = array(); 40 foreach ($outlines as $outline) { 41 if (isset($outline['htmlUrl'])) { 42 $link = $outline['htmlUrl']; 43 } 44 elseif (isset($outline['url'])) { 45 $link = $outline['url']; 46 } 47 else continue; 48 $entry = new StdClass(); 49 $entry->link = $link; 50 $entry->title = (!empty($outline['title']))?$outline['title']:''; 51 if (empty($entry->title)) { 52 $entry->title = (!empty($outline['text']))?$outline['text']:$entry->link; 53 } 54 $entry->desc = (!empty($outline['description']))?$outline['description']:''; 55 $this->entries[] = $entry; 56 } 57 } 48 $entry = new StdClass(); 49 $entry->link = $link; 50 $entry->title = (!empty($outline['title'])) ? $outline['title'] : ''; 51 if (empty($entry->title)) { 52 $entry->title = (!empty($outline['text'])) ? $outline['text'] : $entry->link; 53 } 54 $entry->desc = (!empty($outline['description'])) ? $outline['description'] : ''; 55 $this->entries[] = $entry; 56 } 57 } 58 58 59 protected function _parseXBEL($data) 60 { 61 $xml = @simplexml_load_string($data); 62 if (!$xml) throw new Exception(__('File is not in XML format.')); 59 protected function _parseXBEL($data) 60 { 61 $xml = @simplexml_load_string($data); 62 if (!$xml) { 63 throw new Exception(__('File is not in XML format.')); 64 } 63 65 64 66 $outlines = $xml->xpath("//bookmark"); 65 67 66 $this->entries = array(); 67 foreach ($outlines as $outline) { 68 if (!isset($outline['href'])) continue; 69 $entry = new StdClass(); 70 $entry->link = $outline['href']; 71 $entry->title = (!empty($outline->title))?$outline->title:''; 72 if (empty($entry->title)) { 73 $entry->title = $entry->link; 74 } 75 $entry->desc = (!empty($outline->desc))?$outline->desc:''; 76 $this->entries[] = $entry; 77 } 78 } 68 $this->entries = array(); 69 foreach ($outlines as $outline) { 70 if (!isset($outline['href'])) { 71 continue; 72 } 79 73 74 $entry = new StdClass(); 75 $entry->link = $outline['href']; 76 $entry->title = (!empty($outline->title)) ? $outline->title : ''; 77 if (empty($entry->title)) { 78 $entry->title = $entry->link; 79 } 80 $entry->desc = (!empty($outline->desc)) ? $outline->desc : ''; 81 $this->entries[] = $entry; 82 } 83 } 80 84 81 public function getAll() 82 { 83 if (!$this->entries) return null; 84 return $this->entries; 85 } 85 public function getAll() 86 { 87 if (!$this->entries) { 88 return; 89 } 90 91 return $this->entries; 92 } 86 93 87 94 } 88 95 89 class dcImportBlogroll { 96 class dcImportBlogroll 97 { 90 98 91 92 93 94 95 96 97 98 99 99 public static function loadFile($file) 100 { 101 if (file_exists($file) && is_readable($file)) { 102 $importer = new linksImporter(); 103 $importer->parse(file_get_contents($file)); 104 return $importer->getAll(); 105 } 106 return false; 107 } 100 108 }
Note: See TracChangeset
for help on using the changeset viewer.