function getFileValue(&$str, $dir)
 {
     $pic = false;
     if ($str != "") {
         $b_file = new CFile("temp/" . $str);
         if ($b_file->id > 0) {
             $b_file->Rename($dir . $str);
             $pic = $str;
         } else {
             $b_file2 = new CFile($dir . $str);
             if ($b_file2->id > 0) {
                 $pic = $str;
             } else {
                 $pic = false;
             }
         }
     }
     return $pic;
 }
예제 #2
0
 $cfile->id = $file['id'];
 $cfile->name = $file['fname'];
 $cfile->path = $file['path'];
 /*
 if (empty($cfile->name) || empty($cfile->path)) {
     $cnt_path_fail++;
     continue;
 }
 */
 //$to = preg_replace('/\/attach\//', '/private/account/', $cfile->path);
 //$to .= $cfile->name;
 $to = "{$cfile->path}private/account/{$cfile->name}";
 //print_r("USER https://www.fl.ru/users/{$file['login']}/setup/finance/\n");
 //print_r("FROM https://st.fl.ru/{$cfile->path}{$cfile->name} TO https://st.fl.ru/{$to}\n\n");
 //exit;
 if (!$cfile->Rename($to)) {
     $cnt_rename_fail++;
     /*            
                 $users_links_fail["https://www.fl.ru/users/{$file['login']}/setup/finance/"][] = array(
             	'from' => "https://st.fl.ru/{$file['path']}{$file['fname']}",
             	'to' => "https://st.fl.ru/{$to}"
                 ); 
     */
     continue;
 }
 unset($cfile);
 $cnt_succes++;
 /*        
         $users_links_ok["https://www.fl.ru/users/{$file['login']}/setup/finance/"][] = array(                                                                                                                                                                                            
                 'from' => "https://st.fl.ru/{$file['path']}{$file['fname']}",                                                                                                                                                                                                                     
                 'to' => "https://st.fl.ru/{$to}"                                                                                                                                                                                                                                               
예제 #3
0
 $cf = new CFile($_FILES['document'], dav_file_upload::FILE_TABLE);
 if ($cf->CheckPath($path)) {
     $destname = dav_file_upload_createDestName($cf);
     //check existing file
     $existingFile = new CFile("{$path}/{$destname}");
     if ($existingFile->id > 0) {
         $ext = $existingFile->getext($existingFile->name);
         $tmp = $existingFile->secure_tmpname($path . '/', '.' . $ext);
         $rename_name = substr_replace($tmp, "", 0, strlen($path) + 1);
         $s = preg_replace("#\\." . $ext . "\$#", "", $destname);
         $length = strlen($s . '_' . $rename_name);
         if ($length > 64 && strlen($rename_name) < 64) {
             $s = substr($s, 0, 63 - strlen($rename_name));
             $rename_name = $s . "_" . $rename_name;
         }
         $existingFile->Rename("{$path}/{$rename_name}");
         $info = 'Файл был заменен';
         $old_link = WDCPREFIX . '/' . $path . '/' . $rename_name;
     }
     $cf->server_root = 1;
     $cf->max_size = dav_file_upload::MAX_FILE_SIZE;
     $cf->MoveUploadedFile($path . '/', true, $destname);
     $err = is_string($cf->error[0]) ? $cf->error : $cf->error[0];
     if ($err == '') {
         $link = WDCPREFIX . '/' . $cf->path . $cf->name;
         $name = WDCPREFIX . '/' . $cf->path . $cf->name;
         $info = 'Файл был загружен';
         //добавляем запись в таблицу replace_file_log
         dav_file_upload::addRecord($cf->id, $cf->name, $rename_name);
     }
 } else {
예제 #4
0
 **/
require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/stdf.php';
require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/CFile.php';
require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/dav_file_upload.php';
if (!hasPermissions('admin')) {
    header('Location: /404.php');
    exit;
}
$srcdir = $_SERVER['DOCUMENT_ROOT'] . '/about';
$ls = scandir($srcdir);
foreach ($ls as $item) {
    if ($item != '.' && $item !== '..' && !is_dir("{$srcdir}/{$item}")) {
        $filedata = array('name' => $item, 'tmp_name' => "{$srcdir}/{$item}", 'size' => filesize("{$srcdir}/{$item}"));
        $srcfile = new CFile($filedata);
        $srcfile->unlinkOff = true;
        $path = 'about/documents';
        $destfile = new CFile("{$path}/{$item}", dav_file_upload::FILE_TABLE);
        $rename_name = '';
        if ($destfile->id) {
            $ext = $destfile->getext($destfile->name);
            $tmp = $destfile->secure_tmpname($path . '/', '.' . $ext);
            $rename_name = substr_replace($tmp, '', 0, strlen($path) + 1);
            $destfile->Rename("{$path}/{$rename_name}");
        }
        $srcfile->server_root = 1;
        $srcfile->max_size = dav_file_upload::MAX_FILE_SIZE;
        $r = $srcfile->MoveUploadedFile($path . '/', true, $item);
        dav_file_upload::addRecord($srcfile->id, $srcfile->name, $rename_name);
        echo "Copy {$srcdir}/{$item} " . WDCPREFIX . '/' . $path . '/' . $item . '<br><br>';
    }
}
예제 #5
0
 /**
  * Выполняется после успешного занесения проекта в БД.
  * Удаляет ненужные файлы с сервера, перемещает новые, формирует RSS-файл.
  * При удалении старых аттачей с сервера и из бызы file_projects, они автоматом удаляются из project_attach.
  */
 private function _postDbSuccess()
 {
     if ($this->_tmpFiles) {
         foreach ($this->_tmpFiles as $name) {
             $cfile = new CFile($this->_tmpAbsDir . $name);
             $cfile->Rename($this->_dstAbsDir . $name);
         }
         $this->_tmpFiles = NULL;
     }
     if ($this->_deletedFiles) {
         //echo '<pre>';
         //print_r($this->_deletedFiles);
         $this->_fixDeletedFilesInHistory();
         //print_r($this->_deletedFiles);
         //echo '</pre>';
         //exit;
         $cfile = new CFile();
         foreach ($this->_deletedFiles as $f) {
             $cfile->Delete(0, $f['path'], $f['name']);
         }
     }
     $_SESSION['isExistProjects'] = true;
     $this->destroy();
 }
예제 #6
0
 function saveAction()
 {
     $db = front::og("db");
     $form = front::$_req["form"];
     $id_comm = front::$_req["comment"];
     $parent = front::$_req["parent"];
     if (!$id_comm) {
         $id_comm = false;
     }
     //    global $session;
     $validate_errors = array();
     $save = array();
     if (($str = trim($form['title'])) && mb_strlen($str) >= 3) {
         $save['title'] = change_q_x_a(antispam($str), 0, 96);
     } else {
         $validate_errors['title'] = 'Заголовок короче 3 символов';
     }
     if (($str = trim($form['msg'])) && mb_strlen($str) >= 3) {
         $save['msg'] = change_q_x_a(antispam($str), false, false);
     } else {
         $validate_errors['msg'] = 'Текст короче 3 символов';
     }
     if (strlen($form['msg']) > blogs::MAX_DESC_CHARS) {
         $validate_errors['msg'] = "Максимальный размер сообщения " . blogs::MAX_DESC_CHARS . " символов!";
     } else {
         $save['msg'] = change_q_x_a(antispam($form['msg']), false, false);
     }
     $yt_link = substr(change_q_x(antispam(str_replace('watch?v=', 'v/', $form['yt_link'])), true), 0, 128);
     if ($yt_link != '') {
         if (strpos($yt_link, 'http://ru.youtube.com/v/') !== 0 && strpos($yt_link, 'http://youtube.com/v/') !== 0 && strpos($yt_link, 'http://www.youtube.com/v/') !== 0) {
             $validate_errors['yt_link'] = "Неверная ссылка.";
         }
     }
     if (sizeof($validate_errors) > 0) {
         echo json_encode(array("success" => 0, "validate" => $validate_errors));
         exit(1);
     }
     $save = front::toWin(array("title" => $form["title"], "msg" => $form["msg"], "yt_link" => $yt_link));
     $id = intval($id = front::$_req["id"]);
     if ($id_comm) {
         // if($parent > 0) {
         //
         //  } else {
         $save["id_blog"] = $parent;
         $save["id_reply"] = $id;
         $save["id_user"] = get_uid();
         $id = $db->insert("corporative_blog", $save);
         //  }
         //if($id_comm && $id > 0) {
         //  $save["id_blog"] = $id;
         //      $save["id_reply"] = $id;
         //                }
     } else {
         if ($id > 0) {
             $save["id_modified"] = get_uid();
             $save["id_deleted"] = 0;
             $save["date_change"] = date("Y-m-d H:i:s");
             $aff = $db->update("UPDATE corporative_blog SET ?s WHERE (id = ?n)", $save, $id);
         } else {
             $save["id_user"] = get_uid();
             $id = $db->insert("corporative_blog", $save);
         }
     }
     if ($form["files_deleted"] != "") {
         $form["files_deleted"] = preg_replace('/\\\\\\"/', '"', $form["files_deleted"]);
         $filesBefore = json_decode($form["files_deleted"]);
         $login = $_SESSION['login'];
         foreach ($filesBefore as $file) {
             if (!$file->db_id) {
                 continue;
             }
             front::og("db")->delete("DELETE FROM corporative_blog_attach WHERE id = ?n", $file->db_id);
         }
     }
     if ($form["files"] != "") {
         //$filesBefore = explode(";", $form["files"]);
         //  vardump($form["files"]);
         $form["files"] = preg_replace('/\\\\\\"/', '"', $form["files"]);
         $filesBefore = json_decode($form["files"]);
         if ($group == 7) {
             $max_image_size = array('width' => 400, 'height' => 600, 'less' => 0);
         } else {
             $max_image_size = array('width' => 470, 'height' => 1000, 'less' => 0);
         }
         $login = $_SESSION["login"];
         if ($filesBefore) {
             foreach ($filesBefore as $file) {
                 if (!$file->temp) {
                     continue;
                 }
                 $b_file = new CFile("temp/" . $file->id);
                 if ($b_file->id > 0) {
                     $b_file->Rename("users/" . substr($login, 0, 2) . "/" . $login . "/upload" . "/" . $file->id);
                     $ext = $b_file->getext();
                     if (in_array($ext, $GLOBALS['graf_array'])) {
                         $is_image = TRUE;
                     } else {
                         $is_image = FALSE;
                     }
                     $b_file->max_size = blogs::MAX_FILE_SIZE;
                     $b_file->proportional = 1;
                     if (!isNulArray($file->error)) {
                         //  $error_flag = 1;
                         //print_r($file->error);
                         $alert[3] = "Один или несколько файлов не удовлетворяют условиям загрузки.";
                         // break;
                     } else {
                         if ($is_image && $ext != 'swf' && $ext != 'flv') {
                             if (!$b_file->image_size['width'] || !$b_file->image_size['height']) {
                                 // $error_flag = 1;
                                 $alert[3] = 'Невозможно уменьшить картинку';
                                 break;
                             }
                             if (!$error_flag && ($b_file->image_size['width'] > $max_image_size['width'] || $b_file->image_size['height'] > $max_image_size['height'])) {
                                 if (!$b_file->img_to_small("sm_" . $file->id, $max_image_size)) {
                                     //  $error_flag = 1;
                                     $alert[3] = 'Невозможно уменьшить картинку.';
                                     break;
                                 } else {
                                     $b_file->tn = 2;
                                     $b_file->p_name = "sm_" . $file->id;
                                 }
                             } else {
                                 $b_file->tn = 1;
                             }
                         } else {
                             if ($ext == 'flv') {
                                 $b_file->tn = 2;
                             } else {
                                 $b_file->tn = 0;
                             }
                         }
                         if ($alert[3]) {
                             $validate_errors['files'] = $alert[3];
                         }
                         $files[] = $b_file;
                     }
                 }
             }
         }
     }
     //global $session;
     if (is_array($files) && sizeof($files)) {
         $asql = '';
         foreach ($files as $file) {
             //currval('corporative_blog_id_seq')
             if ($file->name) {
                 $asql .= ", ({$id}, '{$file->name}', '{$file->tn}')";
             }
         }
         if ($asql) {
             $asql = substr($asql, 2);
         }
     }
     //echo $asql;
     if ($asql) {
         pg_query(DBConnect(), "INSERT INTO corporative_blog_attach(msg_id, \"name\", small) VALUES {$asql}");
     }
     $htmlMode = front::$_req["htmlMode"];
     if ($htmlMode == "inPostPage") {
         front::og("tpl")->blog = front::og("db")->select("SELECT cb.*, u.login, u.uname, u.usurname, u.role, u.is_pro, u.is_pro_test, u.boss_rate FROM corporative_blog as cb, users as u WHERE cb.id = ? AND u.uid = cb.id_user;", $id)->fetchRow();
         $attach_blog = front::og("db")->select("SELECT * FROM corporative_blog_attach WHERE msg_id = ?", $id)->fetchAll();
         if ($attach_blog) {
             front::og("tpl")->attach_blog = $attach_blog;
         }
         // front::og("tpl")->usbank  = $usr;
         //  front::og("tpl")->comment = $comm;
         //front::og("tpl")->blog   = $blog;
         $html = front::og("tpl")->fetch("my_corporative_post_item.tpl");
     } elseif ($htmlMode == "normal") {
         $blog = front::og("db")->select("SELECT * FROM corporative_blog WHERE id_blog = 0 AND (id_deleted IS NULL OR id_deleted = 0) AND id = ?n", $id)->fetchRow();
         $bids = array($id => $id);
         $uids = array($blog["id_user"] => $blog["id_user"]);
         $comm = front::get_hash(front::og("db")->select("SELECT COUNT(id_blog) as count, id_blog FROM corporative_blog WHERE id_blog IN(?a) GROUP BY id_blog", $bids)->fetchAll(), "id_blog", "count");
         $user = front::og("db")->select("SELECT uname, usurname, login, uid, role, is_pro, is_pro_test, boss_rate FROM users WHERE uid IN(?a)", $uids)->fetchAll();
         //, "uid", "usname");
         $cid[$blog['id']] = $blog['id'];
         if ($cid) {
             $attach = front::og("db")->select("SELECT * FROM corporative_blog_attach WHERE msg_id IN(?a)", $cid)->fetchAll();
         }
         if ($attach) {
             foreach ($attach as $key => $val) {
                 $res_attach[$val['msg_id']][] = $val;
             }
             front::og("tpl")->attach = $res_attach;
         }
         foreach ($user as $k => $v) {
             $usr[$v['uid']] = $v;
         }
         front::og("tpl")->usbank = $usr;
         front::og("tpl")->comment = $comm;
         front::og("tpl")->blog = $blog;
         $html = front::og("tpl")->fetch("my_corporative_item.tpl");
     }
     echo json_encode(array("success" => true, "id" => $id, "html" => front::toUtf($html)));
 }
예제 #7
0
 public function saveAction()
 {
     $db = front::og('db');
     $form = front::$_req['form'];
     $id_comm = front::$_req['comment'];
     $parent = front::$_req['parent'];
     if (!$id_comm) {
         $id_comm = false;
     }
     //    global $session;
     $validate_errors = array();
     $save = array();
     if (($str = trim($form['title'])) && mb_strlen($str) >= 3) {
         $save['title'] = change_q_x_a(antispam($str), 0, 96);
     } else {
         $validate_errors['title'] = 'Заголовок короче 3 символов';
     }
     if (($str = trim($form['msg'])) && mb_strlen($str) >= 3) {
         $save['msg'] = change_q_x_a(antispam($str), false, false);
     } else {
         $validate_errors['msg'] = 'Текст короче 3 символов';
     }
     if (strlen($form['msg']) > blogs::MAX_DESC_CHARS) {
         $validate_errors['msg'] = 'Максимальный размер сообщения ' . blogs::MAX_DESC_CHARS . ' символов!';
     } else {
         $save['msg'] = change_q_x_a(antispam($form['msg']), false, false);
     }
     $yt_link = substr(change_q_x(antispam(str_replace('watch?v=', 'v/', $form['yt_link'])), true), 0, 128);
     if ($yt_link != '') {
         if (strpos($yt_link, 'http://ru.youtube.com/v/') !== 0 && strpos($yt_link, 'http://youtube.com/v/') !== 0 && strpos($yt_link, 'http://www.youtube.com/v/') !== 0) {
             $validate_errors['yt_link'] = 'Неверная ссылка.';
         }
     }
     if (sizeof($validate_errors) > 0) {
         echo json_encode(array('success' => 0, 'validate' => $validate_errors));
         exit(1);
     }
     $save = front::toWin(array('title' => $form['title'], 'msg' => $form['msg'], 'yt_link' => $yt_link));
     $id = intval($id = front::$_req['id']);
     if ($id_comm) {
         // if($parent > 0) {
         //
         //  } else {
         $save['id_blog'] = $parent;
         $save['id_reply'] = $id;
         $save['id_user'] = get_uid();
         $id = $db->insert('corporative_blog', $save);
         //  }
         //if($id_comm && $id > 0) {
         //  $save["id_blog"] = $id;
         //      $save["id_reply"] = $id;
         //                }
     } else {
         if ($id > 0) {
             $save['id_modified'] = get_uid();
             $save['id_deleted'] = 0;
             $save['date_change'] = date('Y-m-d H:i:s');
             $aff = $db->update('UPDATE corporative_blog SET ?s WHERE (id = ?n)', $save, $id);
         } else {
             $save['id_user'] = get_uid();
             $id = $db->insert('corporative_blog', $save);
         }
     }
     if ($form['files_deleted'] != '') {
         $form['files_deleted'] = preg_replace('/\\\\\\"/', '"', $form['files_deleted']);
         $filesBefore = json_decode($form['files_deleted']);
         $login = $_SESSION['login'];
         foreach ($filesBefore as $file) {
             if (!$file->db_id) {
                 continue;
             }
             front::og('db')->delete('DELETE FROM corporative_blog_attach WHERE id = ?n', $file->db_id);
         }
     }
     if ($form['files'] != '') {
         //$filesBefore = explode(";", $form["files"]);
         //  vardump($form["files"]);
         $form['files'] = preg_replace('/\\\\\\"/', '"', $form['files']);
         $filesBefore = json_decode($form['files']);
         if ($group == 7) {
             $max_image_size = array('width' => 400, 'height' => 600, 'less' => 0);
         } else {
             $max_image_size = array('width' => 470, 'height' => 1000, 'less' => 0);
         }
         $login = $_SESSION['login'];
         if ($filesBefore) {
             foreach ($filesBefore as $file) {
                 if (!$file->temp) {
                     continue;
                 }
                 $b_file = new CFile('temp/' . $file->id);
                 if ($b_file->id > 0) {
                     $b_file->Rename('users/' . substr($login, 0, 2) . '/' . $login . '/upload' . '/' . $file->id);
                     $ext = $b_file->getext();
                     if (in_array($ext, $GLOBALS['graf_array'])) {
                         $is_image = true;
                     } else {
                         $is_image = false;
                     }
                     $b_file->max_size = blogs::MAX_FILE_SIZE;
                     $b_file->proportional = 1;
                     if (!isNulArray($file->error)) {
                         //  $error_flag = 1;
                         //print_r($file->error);
                         $alert[3] = 'Один или несколько файлов не удовлетворяют условиям загрузки.';
                         // break;
                     } else {
                         if ($is_image && $ext != 'swf' && $ext != 'flv') {
                             if (!$b_file->image_size['width'] || !$b_file->image_size['height']) {
                                 // $error_flag = 1;
                                 $alert[3] = 'Невозможно уменьшить картинку';
                                 break;
                             }
                             if (!$error_flag && ($b_file->image_size['width'] > $max_image_size['width'] || $b_file->image_size['height'] > $max_image_size['height'])) {
                                 if (!$b_file->img_to_small('sm_' . $file->id, $max_image_size)) {
                                     //  $error_flag = 1;
                                     $alert[3] = 'Невозможно уменьшить картинку.';
                                     break;
                                 } else {
                                     $b_file->tn = 2;
                                     $b_file->p_name = 'sm_' . $file->id;
                                 }
                             } else {
                                 $b_file->tn = 1;
                             }
                         } elseif ($ext == 'flv') {
                             $b_file->tn = 2;
                         } else {
                             $b_file->tn = 0;
                         }
                         if ($alert[3]) {
                             $validate_errors['files'] = $alert[3];
                         }
                         $files[] = $b_file;
                     }
                 }
             }
         }
     }
     //global $session;
     if (is_array($files) && sizeof($files)) {
         $asql = '';
         foreach ($files as $file) {
             //currval('corporative_blog_id_seq')
             if ($file->name) {
                 $asql .= ", ({$id}, '{$file->name}', '{$file->tn}')";
             }
         }
         if ($asql) {
             $asql = substr($asql, 2);
         }
     }
     //echo $asql;
     if ($asql) {
         pg_query(DBConnect(), "INSERT INTO corporative_blog_attach(msg_id, \"name\", small) VALUES {$asql}");
     }
     $htmlMode = front::$_req['htmlMode'];
     if ($htmlMode == 'inPostPage') {
         front::og('tpl')->blog = front::og('db')->select('SELECT cb.*, u.login, u.uname, u.usurname, u.role, u.is_pro, u.is_pro_test, u.boss_rate FROM corporative_blog as cb, users as u WHERE cb.id = ? AND u.uid = cb.id_user;', $id)->fetchRow();
         $attach_blog = front::og('db')->select('SELECT * FROM corporative_blog_attach WHERE msg_id = ?', $id)->fetchAll();
         if ($attach_blog) {
             front::og('tpl')->attach_blog = $attach_blog;
         }
         // front::og("tpl")->usbank  = $usr;
         //  front::og("tpl")->comment = $comm;
         //front::og("tpl")->blog   = $blog;
         $html = front::og('tpl')->fetch('my_corporative_post_item.tpl');
     } elseif ($htmlMode == 'normal') {
         $blog = front::og('db')->select('SELECT * FROM corporative_blog WHERE id_blog = 0 AND (id_deleted IS NULL OR id_deleted = 0) AND id = ?n', $id)->fetchRow();
         $bids = array($id => $id);
         $uids = array($blog['id_user'] => $blog['id_user']);
         $comm = front::get_hash(front::og('db')->select('SELECT COUNT(id_blog) as count, id_blog FROM corporative_blog WHERE id_blog IN(?a) GROUP BY id_blog', $bids)->fetchAll(), 'id_blog', 'count');
         $user = front::og('db')->select('SELECT uname, usurname, login, uid, role, is_pro, is_pro_test, boss_rate FROM users WHERE uid IN(?a)', $uids)->fetchAll();
         //, "uid", "usname");
         $cid[$blog['id']] = $blog['id'];
         if ($cid) {
             $attach = front::og('db')->select('SELECT * FROM corporative_blog_attach WHERE msg_id IN(?a)', $cid)->fetchAll();
         }
         if ($attach) {
             foreach ($attach as $key => $val) {
                 $res_attach[$val['msg_id']][] = $val;
             }
             front::og('tpl')->attach = $res_attach;
         }
         foreach ($user as $k => $v) {
             $usr[$v['uid']] = $v;
         }
         front::og('tpl')->usbank = $usr;
         front::og('tpl')->comment = $comm;
         front::og('tpl')->blog = $blog;
         $html = front::og('tpl')->fetch('my_corporative_item.tpl');
     }
     echo json_encode(array('success' => true, 'id' => $id, 'html' => front::toUtf($html)));
 }