/**
  * Parse feeds into an array, ready to pass to the Javascript importer
  *
  * @param string $opml_url URL to parse feed data from, in the OPML standard.
  * @return array Associative array containing feed URL, title and category (if applicable)
  */
 protected function import_opml($opml_url)
 {
     if (empty($opml_url)) {
         MessageHandler::add_error(sprintf(_r('No OPML specified')));
         return false;
     }
     require_once LILINA_INCPATH . '/contrib/simplepie/simplepie.inc';
     $opml = new SimplePie_File($opml_url);
     $opml = new OPML($opml->body);
     if (!empty($opml->error) || empty($opml->data)) {
         MessageHandler::add_error(sprintf(_r('The OPML file could not be read. The parser said: %s'), $opml->error));
         return false;
     }
     $feeds_num = 0;
     foreach ($opml->data as $cat => $feed) {
         if (!isset($feed['xmlurl']) && isset($feed[0]['xmlurl'])) {
             foreach ($feed as $subfeed) {
                 $feeds[] = array('url' => $subfeed['xmlurl'], 'title' => $subfeed['title'], 'cat' => $cat);
                 ++$feeds_num;
             }
             continue;
         }
         $feeds[] = array('url' => $feed['xmlurl'], 'title' => $feed['title'], 'cat' => '');
         ++$feeds_num;
     }
     MessageHandler::add(sprintf(__ngettext('Adding %d feed', 'Adding %d feeds', $feeds_num), $feeds_num));
     return $feeds;
 }
/**
 * Validate a plugin filename
 *
 * Checks that the file exists and {@link validate_file() is valid file}. If
 * it either condition is not met, returns false and adds an error to the
 * {@see MessageHandler} stack.
 *
 * @since 1.0
 *
 * @param $filename Path to plugin
 * @return bool True if file exists and is valid, else false
 */
function validate_plugin($filename)
{
    switch (validate_file($filename)) {
        case 1:
        case 2:
            MessageHandler::add_error(_r('Invalid plugin path.'));
            break;
        default:
            if (file_exists(get_plugin_dir() . $filename)) {
                return true;
            } else {
                MessageHandler::add_error(_r('Plugin file was not found.'));
            }
    }
    return false;
}