return $outFile; } /** * Unpack the archive * * @param string $archiveFile The path of the archive to be extracted * * @return void */ function extractArchive($archiveFile) { echo "Unpacking archive ...\n"; $cmd = "tar -zxf {$archiveFile} --strip 2 --wildcards */src"; $test = shell_exec($cmd); echo "Unpacked finished."; } $releases = getReleases(); // Use master release by default $selectedRelease = 'master'; // Check if a release as been selected manually if (isset($argv[1])) { $selectedRelease = $argv[1]; } // Fails if selected release does not exists if (!isset($releases[$selectedRelease])) { echo "Error : Release {$selectedRelease} does not exist\n"; die; } $archiveFile = downloadRelease($releases[$selectedRelease]); extractArchive($archiveFile); echo "MongoGento sucessfully installed.\n";
function installDefaultPlugin($sourcePath) { $db = DBHelper::db(); $pluginFolder = $sourcePath . DS . 'default_plugin'; $plugins = new stdClass(); $joomlaVersion = getJoomlaVersion(); //set plugin details $plugins->deleteuser = new stdClass(); $plugins->deleteuser->zip = $pluginFolder . DS . 'plg_easyblogusers.zip'; if ($joomlaVersion >= '1.6') { $plugins->deleteuser->path = JPATH_ROOT . DS . 'plugins' . DS . 'user' . DS . 'easyblogusers'; } else { $plugins->deleteuser->path = JPATH_ROOT . DS . 'plugins' . DS . 'user'; } $plugins->deleteuser->name = 'User - EasyBlog Users'; $plugins->deleteuser->element = 'easyblogusers'; $plugins->deleteuser->folder = 'user'; $plugins->deleteuser->params = ''; $plugins->deleteuser->lang = ''; foreach ($plugins as $plugin) { if (!JFolder::exists($plugin->path)) { JFolder::create($plugin->path); } if (extractArchive($plugin->zip, $plugin->path)) { if ($joomlaVersion >= '1.6') { //delete old plugin entry before install $sql = 'DELETE FROM ' . $db->nameQuote('#__extensions') . ' ' . 'WHERE ' . $db->nameQuote('element') . '=' . $db->quote($plugin->element) . ' AND ' . $db->nameQuote('folder') . '=' . $db->quote($plugin->folder) . ' AND ' . $db->nameQuote('type') . '=' . $db->quote('plugin') . ' '; $db->setQuery($sql); $db->Query(); //insert plugin again $sql = 'INSERT INTO ' . $db->nameQuote('#__extensions') . '(' . $db->nameQuote('name') . ', ' . $db->nameQuote('type') . ', ' . $db->nameQuote('element') . ', ' . $db->nameQuote('folder') . ', ' . $db->nameQuote('client_id') . ', ' . $db->nameQuote('enabled') . ', ' . $db->nameQuote('access') . ', ' . $db->nameQuote('protected') . ', ' . $db->nameQuote('params') . ', ' . $db->nameQuote('ordering') . ' ' . ') ' . 'VALUES(' . $db->quote($plugin->name) . ', ' . $db->quote('plugin') . ', ' . $db->quote($plugin->element) . ', ' . $db->quote($plugin->folder) . ', ' . $db->quote('0') . ', ' . $db->quote('1') . ', ' . $db->quote('1') . ', ' . $db->quote('0') . ', ' . $db->quote($plugin->params) . ', ' . $db->quote('0') . ' ' . ') '; } else { //delete old plugin entry before install $sql = 'DELETE FROM ' . $db->nameQuote('#__plugins') . ' ' . 'WHERE ' . $db->nameQuote('element') . '=' . $db->quote($plugin->element) . ' AND ' . $db->nameQuote('folder') . '=' . $db->quote($plugin->folder); $db->setQuery($sql); $db->Query(); //insert plugin again $sql = 'INSERT INTO ' . $db->nameQuote('#__plugins') . '(' . $db->nameQuote('name') . ', ' . $db->nameQuote('element') . ', ' . $db->nameQuote('folder') . ', ' . $db->nameQuote('access') . ', ' . $db->nameQuote('ordering') . ', ' . $db->nameQuote('published') . ', ' . $db->nameQuote('iscore') . ', ' . $db->nameQuote('client_id') . ', ' . $db->nameQuote('params') . ' ' . ') ' . 'VALUES(' . $db->quote($plugin->name) . ', ' . $db->quote($plugin->element) . ', ' . $db->quote($plugin->folder) . ', ' . $db->quote('0') . ', ' . $db->quote('0') . ', ' . $db->quote('1') . ', ' . $db->quote('0') . ', ' . $db->quote('0') . ', ' . $db->quote($plugin->params) . ' ' . ') '; } $db->setQuery($sql); $db->Query(); if ($db->getErrorNum()) { JError::raiseError(500, $db->stderr()); return false; } else { return true; } } else { return false; } } }
function uploadPackage() { $absolute_path = JPATH_ROOT; //echo $absolute_path; $userfile = JRequest::getVar('userfile', null, 'files', 'array'); if (!$userfile) { exit; } //echo $userfile_name; $msg = ''; move_uploaded_file($userfile['tmp_name'], $absolute_path . '/tmp/' . $userfile['name']); //$resultdir = uploadFile( $userfile['tmp_name'], $userfile['name'], $msg ); $msg = extractArchive($userfile['name']); if (file_exists($msg . "/swmenufree.xml")) { $upload_version = get_Version($msg . "/swmenufree.xml"); } else { $upload_version = 0; } // echo $msg; $current_version = get_Version($absolute_path . '/administrator/components/com_swmenufree/swmenufree.xml'); //echo $upload_version; if ($current_version < $upload_version) { if (copydirr($msg . "/admin/", $absolute_path . '/administrator/components/com_swmenufree', false)) { unlink($absolute_path . '/administrator/components/com_swmenufree/swmenufree.xml'); unlink($absolute_path . '/administrator/components/com_swmenufree/admin.swmenufree.php'); copy($msg . "/swmenufree.xml", $absolute_path . '/administrator/components/com_swmenufree/swmenufree.xml'); $message = _SW_COMPONENT_SUCCESS; } else { $message = _SW_COMPONENT_FAIL; } } else { $message = _SW_INVALID_FILE; } sw_deldir($msg); unlink($absolute_path . "/tmp/" . $userfile['name']); echo "<dl id=\"system-message\"><dt class=\"message\">Message</dt>\n\t\t<dd class=\"message message fade\"><ul><li>" . $message . "</li>\n\t </ul></dd></dl>\n"; //editCSS($id, $option); upgrade('com_swmenufree'); }
/** * Обработчик действия: Импорт каталога. */ function Import() { @set_time_limit(0); require_once "Structures/DataGrid.php"; require_once "Structures/DataGrid/DataSource/Excel.php"; require_once "Structures/DataGrid/DataSource/CSV.php"; require_once 'Image/Transform.php'; mk_dir("files/" . DOMAIN . "/tmp"); clearDir("files/" . DOMAIN . "/tmp"); if (isset($_FILES['file']['tmp_name']) && file_exists($_FILES['file']['tmp_name'])) { $path_parts = pathinfo($_FILES['file']['name']); $ext = preg_replace("/[^a-z0-9]+/i", "", mb_strtolower($path_parts['extension'])); if ($ext == 'xls' || $ext == 'csv' || $ext == 'gz') { if ($ext == 'gz') { if (extractArchive($_FILES['file']['tmp_name'], "files/" . DOMAIN . "/tmp")) { $sourcefile1 = preg_replace("/tar\\.gz\$/i", "xls", $_FILES['file']['name']); $sourcefile2 = preg_replace("/tar\\.gz\$/i", "csv", $_FILES['file']['name']); if (is_file("files/" . DOMAIN . "/tmp/{$sourcefile1}")) { $sourcefile = "files/" . DOMAIN . "/tmp/{$sourcefile1}"; $ext = "xls"; } elseif (is_file("files/" . DOMAIN . "/tmp/{$sourcefile2}")) { $sourcefile = "files/" . DOMAIN . "/tmp/{$sourcefile2}"; $content = @file_get_contents($sourcefile); if ($content && !mb_check_encoding($content, 'UTF-8')) { file_put_contents($sourcefile, mb_convert_encoding($content, 'UTF-8', 'Windows-1251')); } $ext = "csv"; } else { return false; } } else { return false; } } elseif ($ext == 'csv') { $sourcefile = $_FILES['file']['tmp_name']; $content = @file_get_contents($sourcefile); if ($content && !mb_check_encoding($content, 'UTF-8')) { file_put_contents($sourcefile, mb_convert_encoding($content, 'UTF-8', 'Windows-1251')); } } else { $sourcefile = $_FILES['file']['tmp_name']; } if (!empty($_REQUEST['clear'])) { switch ($_REQUEST['clear']) { case 1: A::$DB->execute("TRUNCATE " . SECTION . "_categories"); case 2: A::$DB->execute("TRUNCATE " . SECTION . "_catalog"); A::$DB->execute("DELETE FROM " . DOMAIN . "_images WHERE idsec=" . SECTION_ID . " AND iditem>0"); A::$DB->execute("DELETE FROM " . DOMAIN . "_files WHERE idsec=" . SECTION_ID . " AND iditem>0"); A::$DB->execute("DELETE FROM " . DOMAIN . "_comments WHERE idsec=" . SECTION_ID); A_SearchEngine::getInstance()->deleteSection(SECTION_ID); break; } } A::$OPTIONS['imgpath'] = !empty(A::$OPTIONS['imgpath']) ? preg_replace("/[^a-zA-Z0-9-_\\/]/i", "", A::$OPTIONS['imgpath']) : "ifiles"; A::$OPTIONS['filepath'] = !empty(A::$OPTIONS['filepath']) ? preg_replace("/[^a-zA-Z0-9-_\\/]/i", "", A::$OPTIONS['filepath']) : "ifiles"; $categories = array(); $fields = array(); $cfiles = array(); A::$DB->query("SELECT * FROM " . SECTION . "_cols ORDER BY sort"); $i = 0; while ($row = A::$DB->fetchRow()) { if ($row['type'] == 'select' || $row['type'] == 'mselect') { if ($row['idvar'] = A::$DB->getOne("SELECT property FROM " . DOMAIN . "_fields WHERE item='" . SECTION . "' AND field='{$row['field']}'")) { if (isset($vars[$row['idvar']])) { $row['vars'] =& $vars[$row['idvar']]; } else { $row['vars'] = array(); $_vars = loadList($row['idvar']); foreach ($_vars as $key => $name) { $row['vars'][$key] = is_array($name) ? $name['name'] : $name; } $vars[$row['idvar']] =& $row['vars']; } } } $row['id'] = $i++; if (preg_match("/^category[0-9]{1}\$/i", $row['field'])) { $categories[$row['field']] = $row; } elseif ($row['type'] == 'image' || $row['type'] == 'file') { $cfiles[$row['field']] = $row; } else { $fields[$row['field']] = $row; } } A::$DB->free(); if ($ext == 'xls') { $datasource = new Structures_DataGrid_DataSource_Excel(); $datasource->bind($sourcefile); } elseif ($ext == 'csv') { $datasource = new Structures_DataGrid_DataSource_CSV(); $datasource->bind($sourcefile, array('delimiter' => ';', 'enclosure' => '"')); } else { return false; } $datagrid = new Structures_DataGrid(); $datagrid->bindDataSource($datasource); A::$DB->caching = false; $prevgoods = A::$DB->getCount(SECTION . "_catalog", "active='Y'"); $curgoods = 0; $arts = array(); $catn = array(); $catr = array(); $cats = array(); $i = 0; $gsort = A::$DB->getOne("SELECT MAX(sort) FROM " . SECTION . "_catalog") + 1; foreach ($datagrid->recordSet as $row) { $i++; if ($i == 1) { continue; } if (empty($row)) { continue; } if ($ext == 'xls') { $trow = array(); foreach ($row as $j => $value) { if (!empty($value)) { $trow[$j - 1] = $value; } } $row = $trow; } $idcat = 0; for ($j = 0; $j < 3; $j++) { if (isset($categories['category' . $j]) && !empty($row[$categories['category' . $j]['id']])) { if ($cname = strip_tags(trim($row[$categories['category' . $j]['id']]))) { $ch = md5($idcat . '|' . $cname); if (isset($catn[$ch])) { $idcat = $catn[$ch]; } elseif ($_idcat = A::$DB->getOne("SELECT id FROM " . SECTION . "_categories WHERE idker={$idcat} AND name=?", $cname)) { $idcat = $catn[$ch] = $_idcat; } else { if (!isset($catr[$idcat])) { $catr[$idcat] = A::$DB->getRowById($idcat, SECTION . "_categories"); } $category = array(); $category['name'] = $cname; $category['urlname'] = getURLName($cname); $category['idker'] = $idcat; $category['level'] = isset($catr[$idcat]['level']) ? $catr[$idcat]['level'] + 1 : 0; $category['sort'] = A::$DB->getOne("SELECT MAX(sort) FROM " . SECTION . "_categories WHERE idker={$idcat}") + 1; $idcat = $catn[$ch] = A::$DB->Insert(SECTION . "_categories", $category); } } } } if ($idcat == 0 && empty($row[$fields['art']['id']])) { continue; } $data = array(); $data['date'] = time(); if ($idcat > 0) { $data['idcat'] = $idcat; if (!isset($cats[$idcat])) { $cats[$idcat] = 1; } else { $cats[$idcat]++; } } $data['idcat1'] = 0; $data['idcat2'] = 0; foreach ($fields as $field => $frow) { if (!isset($_REQUEST['iempty']) || !empty($row[$frow['id']])) { switch ($frow['type']) { default: $data[$field] = !empty($row[$frow['id']]) ? trim($row[$frow['id']]) : ""; break; case 'int': $data[$field] = !empty($row[$frow['id']]) ? (int) $row[$frow['id']] : 0; break; case 'float': $data[$field] = !empty($row[$frow['id']]) ? (double) str_replace(',', '.', $row[$frow['id']]) : 0; break; case 'select': if (!empty($row[$frow['id']])) { if (isset($frow['vars'])) { $row[$frow['id']] = trim($row[$frow['id']]); $key = array_search($row[$frow['id']], $frow['vars']); if (empty($key) && !empty($row[$frow['id']])) { $key = addToList($frow['idvar'], $row[$frow['id']]); $fields[$field]['vars'][$key] = $frow['vars'][$key] = $row[$frow['id']]; } if (!empty($key)) { $data[$field] = $key; } } } break; case 'mselect': if (!empty($row[$frow['id']])) { if (isset($frow['vars'])) { $row[$frow['id']] = explode(',', $row[$frow['id']]); $data[$field] = array(); foreach ($row[$frow['id']] as $value) { $value = trim($value); $key = array_search($value, $frow['vars']); if (empty($key) && !empty($value)) { $key = addToList($frow['idvar'], $value); $fields[$field]['vars'][$key] = $frow['vars'][$key] = $value; } if (!empty($key)) { $data[$field][] = sprintf("%04d", $key); } } $data[$field] = implode(",", $data[$field]); } } break; case 'bool': $data[$field] = !empty($row[$frow['id']]) && $row[$frow['id']] != 'N' ? "Y" : "N"; break; } } } if (isset($data['name'])) { $data['name'] = strip_tags(trim($data['name'])); } if (!empty(A::$OPTIONS['idrule'])) { $_data = $data; prepareValues(SECTION, $_data); $litems = array(); $idrule = A::$OPTIONS['idrule']; $idrule = explode("+", $idrule); foreach ($idrule as $fname) { if (!empty($_data[$fname])) { $litems[] = getURLName($_data[$fname]); } } $data['urlname'] = implode(!empty($GLOBALS['A_URL_SEPARATOR']) ? $GLOBALS['A_URL_SEPARATOR'] : "_", $litems); } elseif (!empty($data['art'])) { $data['urlname'] = getURLName($data['art']); } if (empty($data['urlname'])) { $data['urlname'] = getURLName($data['name']); } if (!empty($data['content']) && empty($data['description'])) { $data['description'] = truncate($data['content'], A::$OPTIONS['anonslen']); } if (!empty($data['art'])) { $grow = A::$DB->getRow("SELECT id,mprices FROM " . SECTION . "_catalog WHERE art=? LIMIT 0,1", $data['art']); if (A::$OPTIONS['usecats']) { if (!empty($arts[$data['art']]) && !empty($data['idcat'])) { if ($arts[$data['art']] < 3) { $data['idcat' . $arts[$data['art']]] = $data['idcat']; unset($data['idcat']); } $arts[$data['art']]++; } else { $arts[$data['art']] = 1; } } } else { $grow = A::$DB->getRow("SELECT id,mprices FROM " . SECTION . "_catalog WHERE idcat=? AND name=? LIMIT 0,1", array($data['idcat'], $data['name'])); } if ($grow) { $id = $grow['id']; $mprices = !empty($grow['mprices']) ? unserialize($grow['mprices']) : array(); } else { $id = 0; } if ($id) { if (isset($fields['mprice']) && !empty($data['mprice'])) { $inm = false; foreach ($mprices as $mp) { if ($mp['name'] == trim($data['mprice'])) { $inm = true; break; } } if (!$inm) { $mprices[] = array('name' => $data['mprice'], 'price' => !empty($data['price']) ? $data['price'] : ''); } $data['mprices'] = serialize($mprices); unset($data['price']); $cats[$idcat]--; $curgoods--; } if (isset($data['mprice'])) { unset($data['mprice']); } A::$DB->Update(SECTION . "_catalog", $data, "id={$id}"); $images = A::$DB->getAssoc("SELECT sort,id,path FROM " . DOMAIN . "_images\r\r\n\t\t\tWHERE idsec=" . SECTION_ID . " AND iditem={$id}"); $images = array_values($images); $files = A::$DB->getAssoc("SELECT sort,id,path FROM " . DOMAIN . "_files\r\r\n\t\t\tWHERE idsec=" . SECTION_ID . " AND iditem={$id}"); $files = array_values($files); $curgoods++; } elseif (!empty($data['idcat'])) { if (isset($fields['mprice']) && !empty($data['mprice'])) { $mprices = array(array('name' => $data['mprice'], 'price' => !empty($data['price']) ? $data['price'] : '')); $data['mprices'] = serialize($mprices); } if (isset($data['mprice'])) { unset($data['mprice']); } if (empty($data['name'])) { continue; } $data['sort'] = $gsort++; $id = A::$DB->Insert(SECTION . "_catalog", $data); $images = array(); $files = array(); $curgoods++; } else { continue; } foreach ($cfiles as $field => $frow) { if (!empty($row[$frow['id']])) { switch ($frow['type']) { case 'image': $row[$frow['id']] = preg_replace("/[^a-zA-Zа-яА-Я0-9-_.]/iu", "", $row[$frow['id']]); $path0 = A::$AUTH->isSuperAdmin() ? "ifiles/" . $row[$frow['id']] : ""; $path1 = "files/" . DOMAIN . "/" . A::$OPTIONS['imgpath'] . "/" . $row[$frow['id']]; $path2 = "files/" . DOMAIN . "/reg_images/" . $row[$frow['id']]; $path = is_file($path0) ? $path0 : (is_file($path1) ? $path1 : (is_file($path2) ? $path2 : "")); if ($path) { preg_match("/^idimg([0-9]+)\$/i", $field, $mathes); $sort = $mathes[1]; if (!isset($images[$sort]) || $images[$sort]['path'] != $path) { $image = array(); $image['path'] = $path; $image['name'] = basename($row[$frow['id']]); $image['mime'] = getMimeByFile($row[$frow['id']]); $image['caption'] = !empty($data['name']) ? $data['name'] : ""; $it = Image_Transform::factory('GD'); $it->load($path); $image['width'] = $it->img_x; $image['height'] = $it->img_y; $image['idsec'] = SECTION_ID; $image['iditem'] = $id; $image['sort'] = $sort; if (isset($images[$sort])) { A::$DB->Update(DOMAIN . "_images", $image, "id=" . $images[$sort]['id']); } else { A::$DB->Insert(DOMAIN . "_images", $image); } } } break; case 'file': $row[$frow['id']] = preg_replace("/[^a-zA-Zа-яА-Я0-9-_.]/iu", "", $row[$frow['id']]); $path0 = A::$AUTH->isSuperAdmin() ? "ifiles/" . $row[$frow['id']] : ""; $path1 = "files/" . DOMAIN . "/" . A::$OPTIONS['filepath'] . "/" . $row[$frow['id']]; $path2 = "files/" . DOMAIN . "/reg_files/" . $row[$frow['id']]; $path = is_file($path0) ? $path0 : (is_file($path1) ? $path1 : (is_file($path2) ? $path2 : "")); if ($path) { preg_match("/^idfile([0-9]+)\$/i", $field, $mathes); $sort = $mathes[1]; if (!isset($files[$sort]) || $files[$sort]['path'] != $path) { $file = array(); $file['path'] = $path; $file['name'] = basename($row[$frow['id']]); $file['mime'] = getMimeByFile($row[$frow['id']]); $file['caption'] = !empty($data['name']) ? $data['name'] : ""; $file['idsec'] = SECTION_ID; $file['iditem'] = $id; $file['sort'] = $sort; $file['size'] = filesize($path); $file['dwnl'] = 0; if (isset($files[$sort])) { A::$DB->Update(DOMAIN . "_files", $file, "id=" . $files[$sort]['id']); } else { A::$DB->Insert(DOMAIN . "_files", $file); } } } break; } } } } if ($prevgoods > 0 && $prevgoods != $curgoods) { $this->updateCItems(); } else { A::$DB->Update(SECTION . "_categories", array('citems' => 0)); foreach ($cats as $id => $count) { A::$DB->Update(SECTION . "_categories", array('citems' => $count), "id={$id}"); } $this->updateCItems(0, true); } A::$CACHE->resetSection(SECTION); delDir("files/" . DOMAIN . "/tmp"); return true; } } return false; }
function uploadPackage() { global $mainframe; $absolute_path = JPATH_ROOT; //echo $absolute_path; $userfile = JRequest::getVar('userfile', null, 'files', 'array'); if (!$userfile) { exit; } $userfile_name = $userfile['name']; //echo $userfile_name; $msg = ''; move_uploaded_file($userfile['tmp_name'], $absolute_path . '/media/' . $userfile['name']); //$resultdir = uploadFile( $userfile['tmp_name'], $userfile['name'], $msg ); $msg = extractArchive($userfile['name']); if (file_exists($msg . "/swmenupro.xml")) { $upload_version = get_Version($msg . "/swmenupro.xml"); } else { $upload_version = 0; } //echo $upload_version; //echo $msg."/swmenupro.xml"; $current_version = get_Version($absolute_path . '/administrator/components/com_swmenupro/swmenupro.xml'); //echo $current_version; if ($current_version < $upload_version) { if (copydirr($msg . "/admin/", $absolute_path . '/administrator/components/com_swmenupro', 0757, false)) { unlink($absolute_path . '/administrator/components/com_swmenupro/swmenupro.xml'); copy($msg . "/swmenupro.xml", $absolute_path . '/administrator/components/com_swmenupro/swmenupro.xml'); $message = _SW_COMPONENT_SUCCESS; } else { $message = _SW_COMPONENT_FAIL; } } else { $message = _SW_INVALID_FILE; } sw_deldir($msg); unlink($absolute_path . "/media/" . $userfile['name']); $mainframe->redirect("index.php?&option=com_swmenupro&task=upgrade", $message); }