API16

JInstallerHelper/detectType

From Joomla! Documentation

< API16:JInstallerHelper
Revision as of 17:36, 22 March 2010 by Doxiki (talk | contribs) (New page: ===Description=== Method to detect the extension type from a package directory <span class="editsection" style="font-size:76%;"> <nowiki>[</nowiki>[[Description:JInstallerHelper/detec...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

The "API16" namespace is an archived namespace. This page contains information for a Joomla! version which is no longer supported. It exists only as a historical reference, it will not be improved and its content may be incomplete and/or contain broken links.

Description[edit]

Method to detect the extension type from a package directory

[Edit Descripton]

Template:Description:JInstallerHelper/detectType

Syntax[edit]

detectType($p_dir)
Parameter Name Default Value Description
$p_dir $p_dir Path to package directory

Returns[edit]

mixed Extension type string or boolean false on fail

Defined in[edit]

libraries/joomla/installer/helper.php

Importing[edit]

jimport( 'joomla.installer.helper' );

Source Body[edit]

function detectType($p_dir)
{
        // Search the install dir for an xml file
        $files = JFolder::files($p_dir, '\.xml$', 1, true);

        if ( ! count($files))
        {
                JError::raiseWarning(1, JText::_('ERRORNOTFINDXMLSETUPFILE'));
                return false;
        }

        foreach ($files as $file)
        {
                if( ! $xml = JFactory::getXML($file))
                {
                        continue;
                }

                if($xml->getName() != 'install' && $xml->getName() != 'extension')
                {
                        unset($xml);
                        continue;
                }

                $type = (string)$xml->attributes()->type;
                // Free up memory
                unset ($xml);
                return $type;
        }

        JError::raiseWarning(1, JText::_('ERRORNOTFINDJOOMLAXMLSETUPFILE'));
        // Free up memory.
        unset ($xml);
        return false;
}

[Edit See Also] Template:SeeAlso:JInstallerHelper/detectType

Examples[edit]

<CodeExamplesForm />