/**
  * Custom install method
  * @param boolean True if installing from directory
  */
 function install($p_fromdir = null)
 {
     josSpoofCheck();
     global $mosConfig_absolute_path, $database;
     if (!$this->preInstallCheck($p_fromdir, 'mambot')) {
         return false;
     }
     $xmlDoc = $this->xmlDoc();
     $mosinstall =& $xmlDoc->documentElement;
     // Set some vars
     $e =& $mosinstall->getElementsByPath('name', 1);
     $this->elementName($e->getText());
     $folder = $mosinstall->getAttribute('group');
     $this->elementDir(mosPathName($mosConfig_absolute_path . '/mambots/' . $folder));
     if (!file_exists($this->elementDir()) && !mosMakePath($this->elementDir())) {
         $this->setError(1, 'Failed to create directory "' . $this->elementDir() . '"');
         return false;
     }
     if ($this->parseFiles('files', 'mambot', 'Não existem arquivos definidos como Plugin') === false) {
         return false;
     }
     // Insert mambot in DB
     $query = "SELECT id" . "\n FROM #__mambots" . "\n WHERE element = " . $database->Quote($this->elementName());
     $database->setQuery($query);
     if (!$database->query()) {
         $this->setError(1, 'Erro SQL: ' . $database->stderr(true));
         return false;
     }
     $id = $database->loadResult();
     if (!$id) {
         $row = new mosMambot($database);
         $row->name = $this->elementName();
         $row->ordering = 0;
         $row->folder = $folder;
         $row->iscore = 0;
         $row->access = 0;
         $row->client_id = 0;
         $row->element = $this->elementSpecial();
         if ($folder == 'editors') {
             $row->published = 1;
         }
         if (!$row->store()) {
             $this->setError(1, 'Erro SQL: ' . $row->getError());
             return false;
         }
     } else {
         $this->setError(1, 'O plugin "' . $this->elementName() . '" já existe!');
         return false;
     }
     if ($e =& $mosinstall->getElementsByPath('description', 1)) {
         $this->setError(0, $this->elementName() . '<p>' . $e->getText() . '</p>');
     }
     return $this->copySetupFile('front');
 }
Example #2
0
function create_folder($folder_name, $dirPath)
{
    global $mosConfig_absolute_path;
    if (strlen($folder_name) > 0) {
        if (eregi("[^0-9a-zA-Z_]", $folder_name)) {
            mosRedirect("index2.php?option=com_media&listdir=" . $_POST['dirPath'], T_("Directory name must only contain alphanumeric characters and no spaces please."));
        }
        $folder = $mosConfig_absolute_path . "/images/stories" . $dirPath . "/" . $folder_name;
        if (!is_dir($folder) && !is_file($folder)) {
            mosMakePath($folder);
            $fp = fopen($folder . "/index.html", "w");
            fwrite($fp, "<html>\n<body bgcolor=\"#FFFFFF\">\n</body>\n</html>");
            fclose($fp);
            mosChmod($folder . "/index.html");
            $refresh_dirs = true;
        }
    }
}
Example #3
0
 /**
  * Custom install method
  * @param boolean True if installing from directory
  */
 function install($p_fromdir = null)
 {
     josSpoofCheck();
     global $mosConfig_absolute_path, $database;
     if (!$this->preInstallCheck($p_fromdir, 'template')) {
         return false;
     }
     $xmlDoc =& $this->xmlDoc();
     $mosinstall =& $xmlDoc->documentElement;
     $client = '';
     if ($mosinstall->getAttribute('client')) {
         $validClients = array('administrator');
         if (!in_array($mosinstall->getAttribute('client'), $validClients)) {
             $this->setError(1, 'Unknown client type [' . $mosinstall->getAttribute('client') . ']');
             return false;
         }
         $client = 'admin';
     }
     // Set some vars
     $e =& $mosinstall->getElementsByPath('name', 1);
     $this->elementName($e->getText());
     $this->elementDir(mosPathName($mosConfig_absolute_path . ($client == 'admin' ? '/administrator' : '') . '/templates/' . strtolower(str_replace(" ", "_", $this->elementName()))));
     if (!file_exists($this->elementDir()) && !mosMakePath($this->elementDir())) {
         $this->setError(1, 'Failed to create directory "' . $this->elementDir() . '"');
         return false;
     }
     if ($this->parseFiles('files') === false) {
         return false;
     }
     if ($this->parseFiles('images') === false) {
         return false;
     }
     if ($this->parseFiles('css') === false) {
         return false;
     }
     if ($this->parseFiles('media') === false) {
         return false;
     }
     if ($e =& $mosinstall->getElementsByPath('description', 1)) {
         $this->setError(0, $this->elementName() . '<p>' . $e->getText() . '</p>');
     }
     return $this->copySetupFile('front');
 }
Example #4
0
 /**
  * @param string Source directory
  * @param string Destination directory
  * @param array array with filenames
  * @param boolean True is existing files can be replaced
  * @return boolean True on success, False on error
  */
 function copyFiles($p_sourcedir, $p_destdir, $p_files, $overwrite = false)
 {
     if (is_array($p_files) && count($p_files) > 0) {
         foreach ($p_files as $_file) {
             $filesource = mosPathName(mosPathName($p_sourcedir) . $_file, false);
             $filedest = mosPathName(mosPathName($p_destdir) . $_file, false);
             if (!file_exists($filesource)) {
                 $this->setError(1, "File {$filesource} does not exist!");
                 return false;
             } else {
                 if (file_exists($filedest) && !$overwrite) {
                     $this->setError(1, "There is already a file called {$filedest} - Are you trying to install the same CMT twice?");
                     return false;
                 } else {
                     $path_info = pathinfo($_file);
                     if (!is_dir($path_info['dirname'])) {
                         mosMakePath($p_destdir, $path_info['dirname']);
                     }
                     if (!(copy($filesource, $filedest) && mosChmod($filedest))) {
                         $this->setError(1, "Failed to copy file: {$filesource} to {$filedest}");
                         return false;
                     }
                 }
             }
         }
     } else {
         return false;
     }
     return count($p_files);
 }
 /**
  * Custom install method
  * @param boolean True if installing from directory
  */
 function install($p_fromdir = null)
 {
     global $mosConfig_absolute_path, $database;
     josSpoofCheck();
     if (!$this->preInstallCheck($p_fromdir, 'component')) {
         return false;
     }
     // aje moved down to here. ??  seemed to be some referencing problems
     $xmlDoc = $this->xmlDoc();
     $mosinstall =& $xmlDoc->documentElement;
     // Set some vars
     $e =& $mosinstall->getElementsByPath('name', 1);
     $this->elementName($e->getText());
     $this->elementDir(mosPathName($mosConfig_absolute_path . "/components/" . strtolower("com_" . str_replace(" ", "", $this->elementName())) . "/"));
     $this->componentAdminDir(mosPathName($mosConfig_absolute_path . "/administrator/components/" . strtolower("com_" . str_replace(" ", "", $this->elementName()))));
     if (file_exists($this->elementDir())) {
         $this->setError(1, 'Another component is already using directory: "' . $this->elementDir() . '"');
         return false;
     }
     if (!file_exists($this->elementDir()) && !mosMakePath($this->elementDir())) {
         $this->setError(1, 'Failed to create directory "' . $this->elementDir() . '"');
         return false;
     }
     if (!file_exists($this->componentAdminDir()) && !mosMakePath($this->componentAdminDir())) {
         $this->setError(1, 'Failed to create directory "' . $this->componentAdminDir() . '"');
         return false;
     }
     // Find files to copy
     if ($this->parseFiles('files') === false) {
         return false;
     }
     $this->parseFiles('images');
     $this->parseFiles('administration/files', '', '', 1);
     $this->parseFiles('administration/images', '', '', 1);
     // Are there any SQL queries??
     $query_element =& $mosinstall->getElementsByPath('install/queries', 1);
     if (!is_null($query_element)) {
         $queries = $query_element->childNodes;
         foreach ($queries as $query) {
             $database->setQuery($query->getText());
             if (!$database->query()) {
                 $this->setError(1, "SQL Error " . $database->stderr(true));
                 return false;
             }
         }
     }
     // Is there an installfile
     $installfile_elemet =& $mosinstall->getElementsByPath('installfile', 1);
     if (!is_null($installfile_elemet)) {
         // check if parse files has already copied the install.component.php file (error in 3rd party xml's!)
         if (!file_exists($this->componentAdminDir() . $installfile_elemet->getText())) {
             if (!$this->copyFiles($this->installDir(), $this->componentAdminDir(), array($installfile_elemet->getText()))) {
                 $this->setError(1, 'Could not copy PHP install file.');
                 return false;
             }
         }
         $this->hasInstallfile(true);
         $this->installFile($installfile_elemet->getText());
     }
     // Is there an uninstallfile
     $uninstallfile_elemet =& $mosinstall->getElementsByPath('uninstallfile', 1);
     if (!is_null($uninstallfile_elemet)) {
         if (!file_exists($this->componentAdminDir() . $uninstallfile_elemet->getText())) {
             if (!$this->copyFiles($this->installDir(), $this->componentAdminDir(), array($uninstallfile_elemet->getText()))) {
                 $this->setError(1, 'Could not copy PHP uninstall file');
                 return false;
             }
         }
     }
     // Is the menues ?
     $adminmenu_element =& $mosinstall->getElementsByPath('administration/menu', 1);
     if (!is_null($adminmenu_element)) {
         $adminsubmenu_element =& $mosinstall->getElementsByPath('administration/submenu', 1);
         $com_name = strtolower("com_" . str_replace(" ", "", $this->elementName()));
         $com_admin_menuname = $adminmenu_element->getText();
         if (!is_null($adminsubmenu_element)) {
             $com_admin_menu_id = $this->createParentMenu($com_admin_menuname, $com_name);
             if ($com_admin_menu_id === false) {
                 return false;
             }
             $com_admin_submenus = $adminsubmenu_element->childNodes;
             $submenuordering = 0;
             foreach ($com_admin_submenus as $admin_submenu) {
                 $com = new mosComponent($database);
                 $com->name = $admin_submenu->getText();
                 $com->link = '';
                 $com->menuid = 0;
                 $com->parent = $com_admin_menu_id;
                 $com->iscore = 0;
                 if ($admin_submenu->getAttribute("act")) {
                     $com->admin_menu_link = "option={$com_name}&act=" . $admin_submenu->getAttribute("act");
                 } else {
                     if ($admin_submenu->getAttribute("task")) {
                         $com->admin_menu_link = "option={$com_name}&task=" . $admin_submenu->getAttribute("task");
                     } else {
                         if ($admin_submenu->getAttribute("link")) {
                             $com->admin_menu_link = $admin_submenu->getAttribute("link");
                         } else {
                             $com->admin_menu_link = "option={$com_name}";
                         }
                     }
                 }
                 $com->admin_menu_alt = $admin_submenu->getText();
                 $com->option = $com_name;
                 $com->ordering = $submenuordering++;
                 $com->admin_menu_img = "js/ThemeOffice/component.png";
                 if (!$com->store()) {
                     $this->setError(1, $database->stderr(true));
                     return false;
                 }
             }
         } else {
             $this->createParentMenu($com_admin_menuname, $com_name);
         }
     }
     $desc = '';
     if ($e =& $mosinstall->getElementsByPath('description', 1)) {
         $desc = $this->elementName() . '<p>' . $e->getText() . '</p>';
     }
     $this->setError(0, $desc);
     if ($this->hasInstallfile()) {
         if (is_file($this->componentAdminDir() . '/' . $this->installFile())) {
             require_once $this->componentAdminDir() . "/" . $this->installFile();
             $ret = com_install();
             if ($ret != '') {
                 $this->setError(0, $desc . $ret);
             }
         }
     }
     return $this->copySetupFile();
 }
Example #6
0
 /**
  * @param string The tag name to parse
  * @param string An attribute to search for in a filename element
  * @param string The value of the 'special' element if found
  * @param boolean True for Administrator components
  * @return mixed Number of file or False on error
  */
 function parseFiles($tagName = 'files', $special = '', $specialError = '', $adminFiles = 0)
 {
     global $mosConfig_absolute_path;
     // Find files to copy
     $xml =& $this->xmlDoc();
     $files_element =& $xml->getElementsByPath($tagName, 1);
     if (is_null($files_element)) {
         return 0;
     }
     if (!$files_element->hasChildNodes()) {
         // no files
         return 0;
     }
     $files = $files_element->childNodes;
     $copyfiles = array();
     if (count($files) == 0) {
         // nothing more to do
         return 0;
     }
     foreach ($files as $file) {
         if (basename($file->getText()) != $file->getText()) {
             $newdir = dirname($file->getText());
             if ($adminFiles) {
                 if (!mosMakePath($this->componentAdminDir(), $newdir)) {
                     $this->setError(1, 'Failed to create directory "' . $this->componentAdminDir() . $newdir . '"');
                     return false;
                 }
             } else {
                 if (!mosMakePath($this->elementDir(), $newdir)) {
                     $this->setError(1, 'Failed to create directory "' . $this->elementDir() . $newdir . '"');
                     return false;
                 }
             }
         }
         $copyfiles[] = $file->getText();
         // check special for attribute
         if ($file->getAttribute($special)) {
             $this->elementSpecial($file->getAttribute($special));
         }
     }
     if ($specialError) {
         if ($this->elementSpecial() == '') {
             $this->setError(1, $specialError);
             return false;
         }
     }
     if ($tagName == 'media') {
         // media is a special tag
         $mediaDir = mosPathName($mosConfig_absolute_path . '/images/stories');
         $result = $this->copyFiles($this->installDir(), $mediaDir, $copyfiles);
     } else {
         if ($adminFiles) {
             $result = $this->copyFiles($this->installDir(), $this->componentAdminDir(), $copyfiles);
         } else {
             $result = $this->copyFiles($this->installDir(), $this->elementDir(), $copyfiles);
         }
     }
     return $result;
 }
function create_folder($dirPath)
{
    josSpoofCheck();
    $folder_name = mosGetParam($_POST, 'foldername', '');
    if (strlen($folder_name) > 0) {
        if (eregi("[^0-9a-zA-Z_]", $folder_name)) {
            mosRedirect("index2.php?option=com_media&listdir=" . $_POST['dirPath'], "O nome de diretório apenas pode conter caracteres alfanuméricos e não pode ter espaços.");
        }
        $folder = COM_MEDIA_BASE . $dirPath . DIRECTORY_SEPARATOR . $folder_name;
        if (!is_dir($folder) && !is_file($folder)) {
            mosMakePath($folder);
            $fp = fopen($folder . "/index.html", "w");
            fwrite($fp, "<html>\n<body bgcolor=\"#FFFFFF\">\n</body>\n</html>");
            fclose($fp);
            mosChmod($folder . "/index.html");
            $refresh_dirs = true;
        }
    }
}
Example #8
0
function create_folder($dirPath)
{
    josSpoofCheck();
    $folder_name = mosGetParam($_POST, 'foldername', '');
    if (strlen($folder_name) > 0) {
        if (preg_match("/[^0-9a-zA-Z_]/i", $folder_name)) {
            mosRedirect("index2.php?option=com_media&listdir=" . $_POST['dirPath'], "Directory name must only contain alphanumeric characters and no spaces please.");
        }
        $folder = COM_MEDIA_BASE . $dirPath . DIRECTORY_SEPARATOR . $folder_name;
        if (!is_dir($folder) && !is_file($folder)) {
            mosMakePath($folder);
            $fp = fopen($folder . "/index.html", "w");
            fwrite($fp, "<html>\n<body bgcolor=\"#FFFFFF\">\n</body>\n</html>");
            fclose($fp);
            mosChmod($folder . "/index.html");
            $refresh_dirs = true;
        }
    }
}
Example #9
0
function jTipsExtractLegacy($filepath = "")
{
    global $mosConfig_absolute_path, $jLicence;
    //$filepath = $mosConfig_absolute_path. '/administrator/components/com_jtips/updates/test.zip';
    $writefile = $mosConfig_absolute_path . '/administrator/components/com_jtips/updates/pilot.php';
    $zip = new dUnzip2($filepath);
    $zip->getList();
    $zip->unzip('pilot.php', $writefile);
    $updates = null;
    include $writefile;
    $failed = false;
    if (is_array($updates)) {
        foreach ($updates as $key => $files) {
            $path = $mosConfig_absolute_path . ($key == 'admin' ? '/administrator' : '') . '/components/com_jtips/';
            foreach ($files as $file) {
                //					if (makeDirectories($path, $file)) {
                //						jTipsLogger::_log("unzipping file $key/" .$file. " => " .$path.$file);
                //						$res = $zip->unzip("$key/$file", $path.$file);
                //						if ($res === false) {
                //							$failed = true;
                //						}
                //					}
                //BUG 255 - Legacy create directories
                if (mosMakePath($path, dirname($file))) {
                    jTipsLogger::_log("unzipping file {$key}/" . $file . " => " . $path . $file);
                    $res = $zip->unzip("{$key}/{$file}", $path . $file);
                    if ($res === false) {
                        $failed = true;
                    }
                }
            }
        }
    } else {
        jTipsLogger::_log("No files to update");
    }
    jTipsLogger::_log("Update result (failed = 1): " . intval($failed));
    $jLicence->revalidate(true);
    return intval(!$failed);
}
 /**
  * @param string Source directory
  * @param string Destination directory
  * @param array array with filenames
  * @param boolean True is existing files can be replaced
  * @return boolean True on success, False on error
  */
 function copyFiles($p_sourcedir, $p_destdir, $p_files, $overwrite = false)
 {
     if (is_array($p_files) && count($p_files) > 0) {
         foreach ($p_files as $_file) {
             $filesource = mosPathName(mosPathName($p_sourcedir) . $_file, false);
             $filedest = mosPathName(mosPathName($p_destdir) . $_file, false);
             if (!file_exists($filesource)) {
                 $this->setError(1, "Arquivo {$filesource} não existe!");
                 return false;
             } else {
                 if (file_exists($filedest) && !$overwrite) {
                     $this->setError(1, "Já existe um arquivo chamado {$filedest} - Está a tentar instalar a mesma extensão duas vezes?");
                     return false;
                 } else {
                     $path_info = pathinfo($_file);
                     if (!is_dir($path_info['dirname'])) {
                         mosMakePath($p_destdir, $path_info['dirname']);
                     }
                     if (!(copy($filesource, $filedest) && mosChmod($filedest))) {
                         $this->setError(1, "Falha ao copiar o arquivo: {$filesource} to {$filedest}");
                         return false;
                     }
                 }
             }
         }
     } else {
         return false;
     }
     return count($p_files);
 }