示例#1
0
 /**
  * Convert opml array into more convenient array with xmlUrl as key
  *
  * @param array $array       Array obtained from Opml file
  * @param array $listFolders List of current folders
  *
  * @return array             New formated array
  */
 public static function convertOpmlArray($array, $listFolders = array())
 {
     $newArray = array();
     for ($i = 0, $len = count($array); $i < $len; $i++) {
         if (isset($array[$i]['outline']) && (isset($array[$i]['text']) || isset($array[$i]['title']))) {
             // here is a folder
             if (isset($array[$i]['text'])) {
                 $listFolders[] = $array[$i]['text'];
             } else {
                 $listFolders[] = $array[$i]['title'];
             }
             $newArray = array_merge($newArray, Opml::convertOpmlArray($array[$i]['outline'], $listFolders));
             array_pop($listFolders);
         } else {
             if (isset($array[$i]['xmlUrl'])) {
                 // here is a feed
                 $xmlUrl = MyTool::smallHash($array[$i]['xmlUrl']);
                 if (isset($newArray[$xmlUrl])) {
                     //feed already exists
                     foreach ($listFolders as $val) {
                         // add folder to the feed
                         if (!in_array($val, $newArray[$xmlUrl]['folders'])) {
                             $newArray[$xmlUrl]['folders'][] = $val;
                         }
                     }
                 } else {
                     // here is a new feed
                     foreach ($array[$i] as $attr => $val) {
                         $newArray[$xmlUrl][$attr] = $val;
                     }
                     $newArray[$xmlUrl]['folders'] = $listFolders;
                 }
             }
         }
     }
     return $newArray;
 }