function generatefile() { jimport('joomla.filesystem.file'); jimport('joomla.filesystem.folder'); $lang = JRequest::getVar('tlang', ''); $tr_from = JRequest::getVar('tr_from', 'en-GB'); $user = JRequest::getVar('nickname', ''); $component = JRequest::getVar('tcomponent', ''); $type = JRequest::getVar('ttype', 'site'); $path = JPATH_ROOT . DS . 'components' . DS . 'com_onepage' . DS . 'translations'; $relpath = JURI::root() . 'components/com_onepage/translations'; if ($type == 'site') { $path = JPATH_ROOT . DS . 'language'; } else { $path = JPATH_ADMINISTRATOR . DS . 'language'; } // basic security if (strpos($lang, '..') !== false) { die('edit.php: hacking attempt'); } if (strpos($component, '..') !== false) { die('edit.php: hacking attempt'); } if (strpos($user, '..') !== false) { die('edit.php: hacking attempt'); } if (strpos($type, '..') !== false) { die('edit.php: hacking attempt'); } $lang = JFile::makeSafe($lang); $user = JFile::makeSafe($user); $component = JFile::makeSafe($component); $type = JFile::makeSafe($type); $tr_from = JFile::makeSafe($tr_from); if (!file_exists($path)) { if (JFolder::create($path) === false) { echo JText::sprinf('COM_ONEPAGE_CANNOT_CREATE_DIRECTORY', $path); } } // sk-SK $path .= DS . $lang; $relpath .= '/' . $lang; if (!file_exists($path)) { if (JFolder::create($path) === false) { echo JText::sprinf('COM_ONEPAGE_CANNOT_CREATE_DIRECTORY', $path); } } /* // sk-SK/site $path .= DS.$type; $relpath .= '/'.$type; if (!file_exists($path)) if (JFolder::create($path) === false) echo 'Cannot create directory: '.$path; $path .= DS.$user; $relpath .= '/'.$user; if (!file_exists($path)) if (JFolder::create($path) === false) echo 'Cannot create directory: '.$path; */ $filename = $path . DS . $lang . '.' . $component . '.ini'; if (file_exists($filename)) { $x = rand(100000, 999999); // will create a random filename $filename2 = $path . DS . $lang . '.' . $component . '_bck_opc' . $x . '.ini'; if (JFile::copy($filename, $filename2) === false) { echo JText::sprintf('COM_ONEPAGE_CANNOT_CREATE_BACKUP', $filename) . '<br />'; } //echo 'Cannot create a backup of '.$filename.'<br />'; } $relpath .= '/' . $lang . '.' . $component . '.ini'; $this->createtable(); $arr1 = $this->getIni($tr_from, $type, $component); if (empty($arr1)) { echo '<b style="color: red;">' . JText::_('COM_ONEPAGE_CANNOT_SAVE_LANG') . '</b><br />'; return; } $arr_orig = $arr1; $arr2 = $this->getIni($lang, $type, $component); foreach ($arr1 as $key => $v) { if (!empty($arr2[$key])) { $arr1[$key] = $arr2[$key]; } } $db = JFactory::getDBO(); echo JText::sprintf('COM_ONEPAGE_FETCHING_TRANSLATIONS_PERUSER', $user, $component, $type, $lang) . '<br />'; foreach ($arr1 as $key => $val) { $translation = $val; $q = "select * from #__vmtranslator_translations where user = '******' and var = '" . $db->escape(urlencode($key)) . "' and entity = '" . $db->escape($component) . "' and lang = '" . $db->escape($lang) . "' and type = '" . $db->escape($type) . "' order by id asc limit 0, 1"; $db->setQuery($q); $res = $db->loadAssoc(); $err = $db->getErrorMsg(); if (!empty($err)) { var_dump($err); die; } if (!empty($res)) { $translation = urldecode($res['translation']); } else { // if user has no entry, get the latest id $q = "select * from #__vmtranslator_translations where var = '" . $db->escape(urlencode($key)) . "' and lang = '" . $db->escape($lang) . "' and entity = '" . $db->escape($component) . "' and type = '" . $db->escape($type) . "' order by id asc limit 0, 1"; $db->setQuery($q); $res = $db->loadAssoc(); $translation = urldecode($res['translation']); $err = $db->getErrorMsg(); if (!empty($err)) { var_dump($err); die; } } if ($arr_orig[$key] != $translation || empty($arr2[$key])) { $arr1[$key] = $translation; } } // vm2.0.22+ new lang files: if (stripos($component, 'com_virtuemart') !== false) { $arr3 = $this->getIni($lang, $type, 'com_virtuemart'); } /* foreach ($arr1o as $k=>$a2) { if (empty($arr3)) break; //var_dump($arr1o); //var_dump($arr3); die(); var_dump($arr1[$k]); die('here'); if (empty($arr1[$k]) || ($arr1[$k] == $arr_orig[$key])) if (!empty($arr3[$k])) { $arr2[$k] = $arr3[$k]; //$arr1[$k] = $arr3[$k]; } } */ $this->write_ini_file($filename, $arr1); return $relpath; }
function batchImportHandler() { jimport('joomla.filesystem.*'); jimport('joomla.filesystem.archive'); $app = JFactory::getApplication('administrator'); $catid = JRequest::getVar('catid', 0, 'post', 'int'); @ini_set('max_execution_time', '240'); $time_start = getmicrotime(); $max_wait = @ini_get('max_execution_time') - 2; $filelist = array(); require JPATH_COMPONENT . DS . 'config.datsogallery.php'; require_once JPATH_COMPONENT . DS . 'images.datsogallery.php'; $dir = JPATH_SITE . DS . 'zipimport'; dgChmod($dir, 0777); $directory_zip = opendir($dir); while ($file_name = readdir($directory_zip)) { $ext = strtolower(substr($file_name, -4)); if ($ext == ".zip") { if (JArchive::extract($dir . DS . $file_name, $dir) == TRUE) { JFile::delete($dir . DS . $file_name); } } } closedir($directory_zip); $directory_zip = opendir($dir); while (false !== ($file = readdir($directory_zip))) { $files[] = $file; } sort($files); $i = 0; foreach ($files as $file) { if ($file != '.' && $file != '..' && strcasecmp($file, 'index.html') != 0 && strcasecmp($file, '__MACOSX') != 0) { $i++; $count = $i > 1 ? ' ' . $i : ''; $origfilename = $file; $imagetype = array(1 => 'GIF', 2 => 'JPG', 3 => 'PNG'); $imginfo = getimagesize($dir . DS . $origfilename); $ext = strtolower($imagetype[$imginfo[2]]); if (is_dir($dir . DS . $origfilename)) { JFolder::delete($dir . DS . $origfilename); $msg = JText::sprintf('COM_DATSOGALLERY_ZIP_PACKAGE_ERROR', '<a href="http://www.datso.fr/en/video-guidelines.html" target="_blank">', '</a>'); $app->redirect('index.php?option=com_datsogallery&task=pictures', $msg); } if (!$ext) { JFile::delete($dir . DS . $origfilename); } else { $newfilename = $ad_fname ? $origfilename : dgImgId($catid, $ext); JFile::copy($dir . DS . $origfilename, JPath::clean(JPATH_SITE . $ad_pathoriginals . DS . $newfilename)); JFile::delete($dir . DS . $origfilename); $db = JFactory::getDBO(); $user = JFactory::getUser(); $row = new DatsoImages($db); if (!$row->bind(JRequest::get('post'))) { return JError::raiseWarning(500, $row->getError()); } $row->ordering = $row->getNextOrder('catid = ' . (int) $catid); $row->imgtitle = JRequest::getVar('gentitle') . $count; $row->imgtext = JRequest::getVar('gendesc'); $row->imgauthor = JRequest::getVar('genimgauthor'); $row->imgauthorurl = JRequest::getVar('genimgauthorurl'); $row->imgdate = mktime(); $row->owner_id = $user->id; $row->published = 1; $row->approved = 1; $row->imgoriginalname = $newfilename; $row->useruploaded = 0; if (!$row->store()) { JError::raiseError(500, $row->getError()); } $time_end = getmicrotime(); if ($max_wait < $time_end - $time_start) { $time = $time_end - $time_start; $timelimit = ini_get('max_execution_time'); closedir($directory_zip); dgChmod($dir, 0755); $msg = JText::sprinf('COM_DATSOGALLERY_TIME_LIMIT_MSG', $timelimit); $app->redirect('index.php?option=com_datsogallery&task=pictures', $msg); } } } } closedir($directory_zip); dgChmod($dir); $msg = 'Зашибись!'; $app->redirect('index.php?option=com_datsogallery&task=pictures', $msg); }