/** * Копирование файла * @param string $from * @param bool|string $to * @return bool */ public function copy($from, $to = false) { try { if (is_dir($from)) { $this->recurse_copy($from, $to); return true; } else { if (copy($from, $to)) { chmod($to, 0777); return true; } } } catch (Exception $exc) { setSystemMessage('error', $e); } return false; }
public function elem($post, $get, $FILES) { require_once sys . '/plugin/class.upload/class.upload.php'; $post = array_merge(array('chpu' => '', 'marker' => '', 'active_path' => ''), $post); $file = isset($FILES['form']) ? $FILES['form'] : array(); $form = isset($post['form']) ? $post['form'] : array(); $activePath = isset($post['active_path']) && $post['active_path'] != '' ? 1 : 0; $updateId = isset($post['id']) && $post['id'] != '' ? (int) $post['id'] : false; if ($updateId !== false) { Fx::db()->update(Fx::service_context()->namespace['construct_db'], array('chpu' => $post['chpu'], 'active_path' => $activePath, 'marker' => $post['marker'], 'date' => time()), array('id' => $updateId)); $ref = Fx::db()->find(Fx::service_context()->namespace['construct_db'], array('ref' => $updateId)); foreach ($ref as $v) { Fx::db()->update(Fx::service_context()->namespace['construct_db'], array('chpu' => $post['chpu'], 'active_path' => $post['active_path'], 'marker' => $post['marker'], 'date' => time()), array('id' => $v['id'])); } $lastId = $updateId; } else { $num = count(Fx::db()->find(Fx::service_context()->namespace['construct_db'], array('parent' => (int) $post['parent']))); Fx::db()->insert(Fx::service_context()->namespace['construct_db'], array('parent' => (int) $post['parent'], 'ref' => '', 'object' => $post['object'], 'chpu' => $post['chpu'], 'num' => $num, 'active_path' => $activePath, 'marker' => $post['marker'], 'date' => time())); $form['id'] = $lastId = Fx::db()->lastID(); } $table = Fx::db()->find(Fx::service_context()->namespace['struct_db'], array('code' => $post['object'])); $table = $table[0]; $row = Fx::db()->find(Fx::service_context()->namespace['struct_td'], array('parent' => $table['id'])); $rows = array(); foreach ($row as $v) { $rows[$v['code']] = array('id' => $v['id'], 'size' => $v['size'], 'type' => $v['type'], 'param' => json_decode($v['param'], true)); } foreach ($form as $k => $v) { if (is_string($v)) { $form[$k] = Fx::db()->esc($v); } } foreach ($rows as $k => $v) { if (!isset($form[$k])) { $form[$k] = ''; } } $path = root . '/' . Fx::service_context()->config['folder']['files'] . '/' . $lastId . '/'; if (isset($file['tmp_name'])) { foreach ($file['tmp_name'] as $k => $v) { $savePath = '/' . Fx::service_context()->config['folder']['files'] . '/' . $lastId . '/'; $fileName = isset($form[$k]['name']) && $form[$k]['name'] != '' ? trim($form[$k]['name']) : $k; $gist = $rows[$k]; $fn = isset($form[$k]['url']) && $form[$k]['url'] != '' ? $form[$k]['url'] : $v['file']; $mime = Fx::io()->mime($file['name'][$k]['file'] != '' ? $file['name'][$k]['file'] : $form[$k]['url']); if (isset($form[$k]['url']) && $form[$k]['url'] !== '') { Fx::io()->create_file(root . '/' . 'temporary.tmp'); Fx::io()->in_file(root . '/' . 'temporary.tmp', file_get_contents($fn)); $fn = root . '/' . 'temporary.tmp'; } if ($fn != '') { if (empty($fn)) { continue; } $IMG = new upload($fn); if ($IMG->uploaded) { $IMG->file_new_name_body = $fileName; $IMG->file_new_name_ext = $mime; $gistParam = $gist['param']; $width = isset($gistParam['width']) && $gistParam['width'] != '' ? $gistParam['width'] : 1000; $height = isset($gistParam['height']) && $gistParam['height'] != '' ? $gistParam['height'] : 1000; // Param if (isset($gist['param']['method'])) { switch ($gist['param']['method']) { case 'scale': // Подгоняем по размеру и пропорциям, без полей $IMG->image_resize = true; $IMG->image_ratio = true; $IMG->image_y = $height; $IMG->image_x = $width; break; case 'crop': // Точно по размеру игнорируя пропорции $IMG->image_resize = true; $IMG->image_ratio_crop = true; $IMG->image_y = $height; $IMG->image_x = $width; break; case 'width': // ресайзим по ширине $IMG->image_resize = true; $IMG->image_ratio_x = true; $IMG->image_y = $height; break; case 'height': // ресайзим по высоте $IMG->image_resize = true; $IMG->image_ratio_y = true; $IMG->image_x = $width; break; } } if (is_file($path . $fileName . '.' . $mime)) { unlink($path . $fileName . '.' . $mime); } $IMG->Process($path); if (!$IMG->processed) { setSystemMessage('error', $IMG->error); } $IMG->clean(); if (isset($gist['param']['zip']) && $gist['param']['zip'] == 1) { $zip = new ZipArchive(); if ($zip->open($path . $fileName . '.zip', ZIPARCHIVE::CREATE) === TRUE) { $zip->addFile($path . $fileName . '.' . $mime, $fileName . '.' . $mime); } $zip->close(); if (file_exists($path . $fileName . '.' . $mime)) { unlink($path . $fileName . '.' . $mime); } $savePath = $savePath . $fileName . '.zip'; } else { $savePath = $savePath . $fileName . '.' . $mime; } } else { setSystemMessage('error', $IMG->error); } $form[$k] = file_exists(root . $savePath) ? $savePath : ''; } if (is_array($form[$k])) { if (isset($form[$k]['remove']) && $form[$k]['remove'] == 1) { if (file_exists(root . $form[$k]['src'])) { unlink(root . $form[$k]['src']); } $form[$k] = ''; } else { if (isset($form[$k]['src']) && isset($form[$k]['name'])) { $imagePath = explode('/', $form[$k]['src']); $imageName = array_pop($imagePath); $imageName = explode('.', $imageName); $imageMime = array_pop($imageName); $imageName = implode('.', $imageName); if ($imageName !== $form[$k]['name']) { $newImageName = implode('/', $imagePath) . '/' . $form[$k]['name'] . '.' . $imageMime; if (is_file(root . $newImageName)) { unlink(root . $newImageName); } rename(root . $form[$k]['src'], root . $newImageName); $form[$k] = $newImageName; } else { $form[$k] = $form[$k]['src']; } } else { $form[$k] = ''; } } } } } foreach ($form as $k => $v) { if (is_array($v)) { $form[$k] = serialize($v); } } if ($updateId !== false) { Fx::db()->update($post['object'], $form, array('id' => $updateId)); } else { Fx::db()->insert($post['object'], $form); } load_url(); }
Fx::context()->selfId = Fx::context()->parent_object; } $pathGist = sys . '/template/tpl/gist-elem/'; $tablParam = array(); $tableName = isset($_GET['name']) ? $_GET['name'] : ''; $objectValue = array(); if (isset($_GET['id']) && (int) $_GET['id'] > 0) { $selfObject = Fx::db()->find(Fx::service_context()->namespace['construct_db'], array('id' => (int) $_GET['id'])); if (count($selfObject)) { $tableName = $selfObject[0]['object']; $objectValue = Fx::db()->find($tableName, array('id' => $selfObject[0]['id'])); $objectValue = $objectValue[0]; } } if ($tableName != '') { $tabl = Fx::db()->find(Fx::service_context()->namespace['struct_db'], array('code' => $tableName)); $tablParam = $tabl[0]; } else { setSystemMessage('error', 'Не заданы параметры для редактирования'); load_url(); } $row = Fx::db()->find(Fx::service_context()->namespace['struct_td'], array('parent' => $tablParam['id'])); $result = array(); foreach ($row as $key => $v) { $result[] = loadParam($key, array('row' => $v, 'value' => isset($objectValue[$v['code']]) ? $objectValue[$v['code']] : ''), $manifest, $pathGist . $v['type'] . '.html'); } // Шаблоны $template = Fx::db()->find(Fx::service_context()->namespace['marker']); // Левое меню require_once sys . '/template/php/project-menu.php'; $isShowSystem = Fx::context()->struct_db[$tableName]['show_sistem'] == '1';