Exemple #1
0
 protected function _gridRead($params)
 {
     switch ($_POST['action']) {
         case 'delete-file':
             return $this->_deleteFile($_POST);
         case 'remove-installer':
             $result = iaUtil::deleteFile(IA_HOME . 'install/modules/module.install.php');
             return array('error' => !$result, 'message' => iaLanguage::get($result ? 'deleted' : 'error'));
         default:
             $result = array();
             $this->_iaCore->startHook('phpAdminActionsJsonHandle', array('action' => $_POST['action'], 'output' => &$result));
             return $result;
     }
 }
Exemple #2
0
 private function _save(&$iaView)
 {
     $iaAcl = $this->_iaCore->factory('acl');
     if (!$iaAcl->checkAccess($iaView->name() . iaAcl::SEPARATOR . iaCore::ACTION_EDIT)) {
         return iaView::accessDenied();
     }
     $where = "`type` != 'hidden' " . ($this->_type ? 'AND `custom` = 1' : '');
     $params = $this->_iaDb->keyvalue(array('name', 'type'), $where, iaCore::getConfigTable());
     // correct admin dashboard URL generation
     $adminPage = $this->_iaCore->get('admin_page');
     iaUtil::loadUTF8Functions('ascii', 'validation', 'bad', 'utf8_to_ascii');
     $messages = array();
     $error = false;
     if ($_POST['v'] && is_array($_POST['v'])) {
         $values = $_POST['v'];
         $this->_iaCore->startHook('phpConfigurationChange', array('configurationValues' => &$values));
         $this->_iaDb->setTable(iaCore::getConfigTable());
         foreach ($values as $key => $value) {
             $s = strpos($key, '_items_enabled');
             if ($s !== false) {
                 $p = $this->_iaCore->get($key, '', !is_null($this->_type));
                 $array = $p ? explode(',', $p) : array();
                 $data = array();
                 array_shift($value);
                 if ($diff = array_diff($value, $array)) {
                     foreach ($diff as $item) {
                         array_push($data, array('action' => '+', 'item' => $item));
                     }
                 }
                 if ($diff = array_diff($array, $value)) {
                     foreach ($diff as $item) {
                         array_push($data, array('action' => '-', 'item' => $item));
                     }
                 }
                 $extra = substr($key, 0, $s);
                 $this->_iaCore->startHook('phpPackageItemChangedForPlugin', array('data' => $data), $extra);
             }
             if (is_array($value)) {
                 $value = implode(',', $value);
             }
             if (!utf8_is_valid($value)) {
                 $value = utf8_bad_replace($value);
                 trigger_error('Bad UTF-8 detected (replacing with "?") in configuration', E_USER_NOTICE);
             }
             if (self::TYPE_IMAGE == $params[$key]) {
                 if (isset($_POST['delete'][$key])) {
                     $value = '';
                 } elseif (!empty($_FILES[$key]['name'])) {
                     if (!(bool) $_FILES[$key]['error']) {
                         if (@is_uploaded_file($_FILES[$key]['tmp_name'])) {
                             $ext = strtolower(utf8_substr($_FILES[$key]['name'], -3));
                             // if jpeg
                             if ($ext == 'peg') {
                                 $ext = 'jpg';
                             }
                             if (!array_key_exists(strtolower($_FILES[$key]['type']), $this->_imageTypes) || !in_array($ext, $this->_imageTypes, true) || !getimagesize($_FILES[$key]['tmp_name'])) {
                                 $error = true;
                                 $messages[] = iaLanguage::getf('file_type_error', array('extension' => implode(', ', array_unique($this->_imageTypes))));
                             } else {
                                 if ($this->_iaCore->get($key) && file_exists(IA_UPLOADS . $this->_iaCore->get($key))) {
                                     iaUtil::deleteFile(IA_UPLOADS . $this->_iaCore->get($key));
                                 }
                                 $value = $fileName = $key . '.' . $ext;
                                 @move_uploaded_file($_FILES[$key]['tmp_name'], IA_UPLOADS . $fileName);
                                 @chmod(IA_UPLOADS . $fileName, 0777);
                             }
                         }
                     }
                 } else {
                     $value = $this->_iaCore->get($key, '', !is_null($this->_type));
                 }
             }
             if ($this->_type) {
                 $where = sprintf("`name` = '%s' AND `type` = '%s' AND `type_id` = %d", $key, $this->_type, $this->_typeId);
                 $this->_iaDb->setTable(iaCore::getCustomConfigTable());
                 if ($_POST['c'][$key]) {
                     $values = array('name' => $key, 'value' => $value, 'type' => $this->_type, 'type_id' => $this->_typeId);
                     if ($this->_iaDb->exists($where)) {
                         unset($values['value']);
                         $this->_iaDb->bind($where, $values);
                         $this->_iaDb->update(array('value' => $value), $where);
                     } else {
                         $this->_iaDb->insert($values);
                     }
                 } else {
                     $this->_iaDb->delete($where);
                 }
                 $this->_iaDb->resetTable();
             } else {
                 $this->_iaDb->update(array('value' => $value), iaDb::convertIds($key, 'name'));
             }
         }
         $this->_iaDb->resetTable();
         $this->_iaCore->iaCache->clearAll();
     }
     if (!$error) {
         $iaView->setMessages(iaLanguage::get('saved'), iaView::SUCCESS);
         if (isset($_POST['param']['admin_page']) && $_POST['param']['admin_page'] != $adminPage) {
             iaUtil::go_to(IA_URL . $_POST['param']['admin_page'] . '/configuration/general/');
         }
     } elseif ($messages) {
         $iaView->setMessages($messages);
     }
 }
 protected function _processQueries(array $entries)
 {
     $iaDb =& $this->iaDb;
     $iaDbControl = $this->iaCore->factory('dbcontrol', iaCore::ADMIN);
     require_once IA_INCLUDES . 'utils' . IA_DS . 'pclzip.lib.php';
     $mysqlOptions = 'ENGINE=MyISAM DEFAULT CHARSET=utf8';
     $pathsMap = array(self::TYPE_PLUGIN => IA_PLUGINS, self::TYPE_PACKAGE => IA_PACKAGES);
     $path = isset($pathsMap[$this->itemData['type']]) ? $pathsMap[$this->itemData['type']] : IA_HOME;
     $versionInstalled = $iaDb->one_bind('version', '`name` = :name', array('name' => $this->itemData['name']), self::getTable());
     foreach ($entries as $version => $entry) {
         if ($versionInstalled && version_compare($versionInstalled, $version, '>')) {
             continue;
         }
         foreach ($entry as $data) {
             if ($data['external']) {
                 $filePath = str_replace(array('{DIRECTORY_SEPARATOR}', '{DS}'), IA_DS, $data['query']);
                 $fileFullPath = $path . $this->itemData['name'] . IA_DS . $filePath;
                 if (iaUtil::isZip($fileFullPath)) {
                     $archive = new PclZip($fileFullPath);
                     $files = $archive->extract(PCLZIP_OPT_PATH, IA_TMP);
                     if (0 == $files) {
                         continue;
                     }
                     foreach ($files as $file) {
                         $iaDbControl->splitSQL($file['filename']);
                         iaUtil::deleteFile($file['filename']);
                     }
                 } else {
                     $iaDbControl->splitSQL($fileFullPath);
                 }
             } else {
                 if ($data['query']) {
                     $iaDb->query(str_replace(array('{prefix}', '{mysql_version}'), array($iaDb->prefix, $mysqlOptions), $data['query']));
                 }
             }
         }
     }
 }
 public function delete($itemId)
 {
     $result = false;
     if ($entryData = $this->iaDb->row(iaDb::ALL_COLUMNS_SELECTION, iaDb::convertIds($itemId), self::getTable())) {
         $result = (bool) $this->iaDb->delete(iaDb::convertIds($itemId), self::getTable());
         if ($result) {
             $iaField = $this->iaCore->factory('field');
             // delete images field values
             if ($imageFields = $iaField->getImageFields($this->getItemName())) {
                 $iaPicture = $this->iaCore->factory('picture');
                 foreach ($imageFields as $imageFieldName) {
                     if (isset($entryData[$imageFieldName]) && $entryData[$imageFieldName]) {
                         $iaPicture->delete($entryData[$imageFieldName]);
                     }
                 }
             }
             // delete storage field values
             if ($storageFields = $iaField->getStorageFields($this->getPackageName())) {
                 foreach ($storageFields as $storageFieldName) {
                     if (isset($entryData[$storageFieldName]) && $entryData[$storageFieldName]) {
                         if (':' == $entryData[$storageFieldName][1]) {
                             $unpackedData = unserialize($entryData[$storageFieldName]);
                             if (is_array($unpackedData) && $unpackedData) {
                                 foreach ($unpackedData as $oneFile) {
                                     iaUtil::deleteFile(IA_UPLOADS . $oneFile['path']);
                                 }
                             }
                         }
                     }
                 }
             }
             $this->_writeLog(iaCore::ACTION_DELETE, $entryData, $itemId);
             $this->updateCounters($itemId, $entryData, iaCore::ACTION_DELETE);
             $this->iaCore->startHook('phpListingRemoved', array('itemId' => $itemId, 'itemName' => $this->getItemName(), 'itemData' => $entryData));
         }
     }
     return $result;
 }
 public function _cascadeRemoveFiles($directory, $removeDirectories = true)
 {
     if (substr($directory, -1) == IA_DS) {
         $directory = substr($directory, 0, -1);
     }
     if (!file_exists($directory) || !is_dir($directory)) {
         return false;
     } elseif (is_readable($directory)) {
         $handle = opendir($directory);
         while ($item = readdir($handle)) {
             if ($item != '.' && $item != '..' && $item != '.htaccess') {
                 $path = $directory . IA_DS . $item;
                 if (is_dir($path)) {
                     $this->_cascadeRemoveFiles($path, true);
                 } else {
                     iaUtil::deleteFile($path);
                 }
             }
         }
         closedir($handle);
         if ($removeDirectories) {
             $objects = scandir($directory);
             foreach ($objects as $object) {
                 if ($object != '.' && $object != '..') {
                     if (filetype($directory . IA_DS . $object) == 'dir') {
                         rmdir($directory . IA_DS . $object);
                     }
                 }
             }
             reset($objects);
         }
     }
     return true;
 }
 protected function _processQueries($type, $stage, $ignoreNonVersionedQueries = false)
 {
     if (!isset($this->itemData['sql'][$type][$stage])) {
         return;
     }
     $iaDb =& $this->iaDb;
     $iaDbControl = $this->iaCore->factory('dbcontrol', iaCore::ADMIN);
     require_once IA_INCLUDES . 'utils' . IA_DS . 'pclzip.lib.php';
     $mysqlOptions = 'ENGINE=MyISAM DEFAULT CHARSET=utf8';
     $path = isset($this->_extrasTypePaths[$this->itemData['type']]) ? $this->_extrasTypePaths[$this->itemData['type']] : IA_HOME;
     $extrasVersion = $this->itemData['info']['version'];
     foreach ($this->itemData['sql'][$type][$stage] as $version => $entries) {
         if ($ignoreNonVersionedQueries && self::VERSION_EMPTY == $version) {
             continue;
         }
         if (self::VERSION_EMPTY != $version && version_compare($version, $extrasVersion) > 0) {
             continue;
         }
         foreach ($entries as $entry) {
             if ($entry['external']) {
                 $filePath = str_replace('{DS}', IA_DS, $entry['query']);
                 $fileFullPath = $path . $this->itemData['name'] . IA_DS . $filePath;
                 if (iaUtil::isZip($fileFullPath)) {
                     $archive = new PclZip($fileFullPath);
                     $files = $archive->extract(PCLZIP_OPT_PATH, IA_TMP);
                     if (0 == $files) {
                         continue;
                     }
                     foreach ($files as $file) {
                         $iaDbControl->splitSQL($file['filename']);
                         iaUtil::deleteFile($file['filename']);
                     }
                 } else {
                     $iaDbControl->splitSQL($fileFullPath);
                 }
             } else {
                 if ($entry['query']) {
                     $query = str_replace(array('{prefix}', '{mysql_version}'), array($iaDb->prefix, $mysqlOptions), $entry['query']);
                     $iaDb->query($query);
                 }
             }
         }
     }
 }
 protected function _entryDelete($entryId)
 {
     $result = false;
     if ($entryData = $this->getById($entryId)) {
         $result = $this->_delete($entryId);
         if ($result) {
             $iaField = $this->_iaCore->factory('field');
             // we have to check for uploaded images of this listing
             if ($imageFields = $iaField->getImageFields($this->getItemName())) {
                 $iaPicture = $this->_iaCore->factory('picture');
                 foreach ($imageFields as $imageFieldName) {
                     if (!empty($entryData[$imageFieldName])) {
                         $iaPicture->delete($entryData[$imageFieldName]);
                     }
                 }
             }
             // delete storage field values
             if ($storageFields = $iaField->getStorageFields($this->getPackageName())) {
                 foreach ($storageFields as $storageFieldName) {
                     if (isset($entryData[$storageFieldName]) && $entryData[$storageFieldName]) {
                         if (':' == $entryData[$storageFieldName][1]) {
                             $unpackedData = unserialize($entryData[$storageFieldName]);
                             if (is_array($unpackedData) && $unpackedData) {
                                 foreach ($unpackedData as $oneFile) {
                                     iaUtil::deleteFile(IA_UPLOADS . $oneFile['path']);
                                 }
                             }
                         }
                     }
                 }
             }
             $this->_writeLog(iaCore::ACTION_DELETE, $entryData, $entryId);
             $this->updateCounters($entryId, $entryData, iaCore::ACTION_DELETE);
             $this->_iaCore->startHook('phpListingRemoved', array('itemId' => $entryId, 'itemName' => $this->getItemName(), 'itemData' => $entryData));
         }
     }
     return $result;
 }