API15

Difference between revisions of "JInstaller/parseMedia"

From Joomla! Documentation

< API15:JInstaller
(New page: ===Description=== Method to parse through a media element of the installation manifest and take appropriate action. <span class="editsection" style="font-size:76%;"> <nowiki>[</nowiki...)
 
m (preparing for archive only)
 
(One intermediate revision by the same user not shown)
Line 3: Line 3:
  
 
<span class="editsection" style="font-size:76%;">
 
<span class="editsection" style="font-size:76%;">
<nowiki>[</nowiki>[[Description:JInstaller/parseMedia|Edit Descripton]]<nowiki>]</nowiki>
+
<nowiki>[<! removed edit link to red link >]</nowiki>
 
</span>
 
</span>
  
{{Description:JInstaller/parseMedia}}
+
<! removed transcluded page call, red link never existed >
  
 
===Syntax===
 
===Syntax===
Line 111: Line 111:
  
 
<span class="editsection" style="font-size:76%;">
 
<span class="editsection" style="font-size:76%;">
<nowiki>[</nowiki>[[SeeAlso:JInstaller/parseMedia|Edit See Also]]<nowiki>]</nowiki>
+
<nowiki>[<! removed edit link to red link >]</nowiki>
 
</span>
 
</span>
{{SeeAlso:JInstaller/parseMedia}}
+
<! removed transcluded page call, red link never existed >
  
 
===Examples===
 
===Examples===
<CodeExamplesForm />
+
=== Code Examples ===
 
<dpl>
 
<dpl>
 
  noresultsheader=\n
 
  noresultsheader=\n
 
  category=parseMedia
 
  category=parseMedia
 
  category=JInstaller
 
  category=JInstaller
  category=CodeExample
+
  namespace=CodeExample
 
  category=MethodExample
 
  category=MethodExample
 
  include=*
 
  include=*
 
  format= ,,,
 
  format= ,,,
 
</dpl>
 
</dpl>
 +
[[Category:Archived pages API15]]

Latest revision as of 19:53, 24 March 2017

The "API15" 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 parse through a media element of the installation manifest and take appropriate action.

[<! removed edit link to red link >]

<! removed transcluded page call, red link never existed >

Syntax[edit]

parseMedia($element, $cid=0)
Parameter Name Default Value Description
$element $element The xml node to process
$cid 0 $cid Application ID of application to install to

Returns[edit]

boolean True on success

Defined in[edit]

libraries/joomla/installer/installer.php

Importing[edit]

jimport( 'joomla.installer.installer' );

Source Body[edit]

function parseMedia($element, $cid=0)
{
        // Initialize variables
        $copyfiles = array ();

        // Get the client info
        jimport('joomla.application.helper');
        $client =& JApplicationHelper::getClientInfo($cid);

        if (!is_a($element, 'JSimpleXMLElement') || !count($element->children())) {
                // Either the tag does not exist or has no children therefore we return zero files processed.
                return 0;
        }

        // Get the array of file nodes to process
        $files = $element->children();
        if (count($files) == 0) {
                // No files to process
                return 0;
        }

        /*
         * Here we set the folder we are going to copy the files to.
         *      Default 'media' Files are copied to the JPATH_BASE/media folder
         */
        $folder = ($element->attributes('destination')) ? DS.$element->attributes('destination') : null;
        $destination = JPath::clean(JPATH_ROOT.DS.'media'.$folder);

        /*
         * Here we set the folder we are going to copy the files from.
         *
         * Does the element have a folder attribute?
         *
         * If so this indicates that the files are in a subdirectory of the source
         * folder and we should append the folder attribute to the source path when
         * copying files.
         */
        if ($folder = $element->attributes('folder')) {
                $source = $this->getPath('source').DS.$folder;
        } else {
                $source = $this->getPath('source');
        }

        // Process each file in the $files array (children of $tagName).
        foreach ($files as $file)
        {
                $path['src']    = $source.DS.$file->data();
                $path['dest']   = $destination.DS.$file->data();

                // Is this path a file or folder?
                $path['type']   = ( $file->name() == 'folder') ? 'folder' : 'file';

                /*
                 * Before we can add a file to the copyfiles array we need to ensure
                 * that the folder we are copying our file to exits and if it doesn't,
                 * we need to create it.
                 */
                if (basename($path['dest']) != $path['dest']) {
                        $newdir = dirname($path['dest']);

                        if (!JFolder::create($newdir)) {
                                JError::raiseWarning(1, 'JInstaller::install: '.JText::_('Failed to create directory').' "'.$newdir.'"');
                                return false;
                        }
                }

                // Add the file to the copyfiles array
                $copyfiles[] = $path;
        }

        return $this->copyFiles($copyfiles);
}

[<! removed edit link to red link >] <! removed transcluded page call, red link never existed >

Examples[edit]

Code Examples[edit]