Dotclear


Ignore:
Timestamp:
03/08/18 17:58:39 (7 years ago)
Author:
franck <carnet.franck.paul@…>
Branch:
default
Message:

Code formatting (PSR-2)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • plugins/blogroll/class.dc.importblogroll.php

    r2566 r3730  
    1010# 
    1111# -- END LICENSE BLOCK ----------------------------------------- 
    12 if (!defined('DC_RC_PATH')) { return; } 
     12if (!defined('DC_RC_PATH')) {return;} 
    1313 
    1414class linksImporter 
    1515{ 
    16      protected $entries = null; 
     16    protected $entries = null; 
    1717 
    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    } 
    3028 
     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        } 
    3135 
    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"); 
    3637 
    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            } 
    3847 
    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    } 
    5858 
    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        } 
    6365 
    64           $outlines = $xml->xpath("//bookmark"); 
     66        $outlines = $xml->xpath("//bookmark"); 
    6567 
    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            } 
    7973 
     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    } 
    8084 
    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    } 
    8693 
    8794} 
    8895 
    89 class dcImportBlogroll { 
     96class dcImportBlogroll 
     97{ 
    9098 
    91      public static function loadFile($file) 
    92      { 
    93           if (file_exists($file) && is_readable($file)) { 
    94                $importer = new linksImporter(); 
    95                $importer->parse(file_get_contents($file)); 
    96                return $importer->getAll(); 
    97           } 
    98           return false; 
    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    } 
    100108} 
Note: See TracChangeset for help on using the changeset viewer.

Sites map