Exemplo n.º 1
0
	/**
	 * Return the info XML for a plugin based on a filename
	 *
	 * @param string $file The filename of the plugin file
	 * @return SimpleXMLElement The info structure for the plugin, or null if no info could be loaded
	 */
	public static function load_info( $file )
	{
		$info = null;
		$xml_file = preg_replace( '%\.plugin\.php$%i', '.plugin.xml', $file );
		
		if ( file_exists( $xml_file ) && $xml_content = file_get_contents( $xml_file ) ) {
			
			// tell libxml to throw exceptions and let us check for errors
			$old_error = libxml_use_internal_errors( true );
			
			try {
				$info = new SimpleXMLElement( $xml_content );
				
				// if the xml file uses a theme element name instead of pluggable, it's old
				if ( $info->getName() != 'pluggable' ) {
					$info = 'legacy';
				}

				// Translate the plugin description
				HabariLocale::translate_xml( $info, $info->description );

				// Translate the plugin help
				foreach( $info->help as $help ) {
					HabariLocale::translate_xml( $help, $help->value );
				}
				
			}
			catch ( Exception $e ) {
				
				EventLog::log( _t( 'Invalid plugin XML file: %1$s', array( $xml_file ) ), 'err', 'plugin' );
				$info = 'broken';
				
			}
			
			// restore the old error level
			libxml_use_internal_errors( $old_error );
			
		}
		
		return $info;
	}