Exemplo n.º 1
0
/**
 * формирует превью проекта на главной странице.
 */
function GetPreview($data)
{
    $objResponse = new xajaxResponse();
    require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/projects.php';
    require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/attachedfiles.php';
    require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/CFile.php';
    require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/HTML/projects_lenta.php';
    require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/project_exrates.php';
    require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/memBuff2.php';
    $kind = 1;
    $memBuff = new memBuff();
    $htmlLenta = $memBuff->get('projectsLentaHTML');
    if (!$htmlLenta) {
        $prj = new new_projects();
        $prjs = $prj->getProjects($num_prjs, -1, 1, false, null, true);
        foreach ($prjs as &$proj) {
            // стираем принадлежность проекта к пользователю, чтобы не появилось кнопок РЕДАКТИРОВАТЬ и пр.
            unset($proj['user_id']);
        }
        unset($proj);
        $htmlPrj = new HTMLProjects();
        $htmlPrj->template = '/projects/tpl.lenta.new.php';
        $prj_content = $htmlPrj->ShowProjects($num_prjs, $prjs, 1, 1, null, true);
        $prfs = new professions();
        $profs = $prfs->GetAllProfessions('', 0, 1);
        // подложка с лентой проектов
        ob_start();
        include $_SERVER['DOCUMENT_ROOT'] . '/templates/main.php';
        $htmlLenta = ob_get_clean();
        // кэшируем ленту проектов
        $memBuff->set('projectsLentaHTML', $htmlLenta, 1800);
    }
    // подготавливаем данные для шаблона в ленту проектов
    $row = array();
    $row['kind'] = __paramValue('int', $data['kind']);
    $row['cost'] = __paramValue('int', $data['cost']);
    $row['currency'] = __paramValue('int', $data['currency_db_id']);
    $row['priceby'] = __paramValue('int', $data['priceby_db_id']);
    $row['name'] = stripslashes(__paramValue('html', $data['name'], null, true));
    $contacts = array('phone' => array('name' => 'Телефон', 'value' => ''), 'site' => array('name' => 'Сайт', 'value' => ''), 'icq' => array('name' => 'ICQ', 'value' => ''), 'skype' => array('name' => 'Skype', 'value' => ''), 'email' => array('name' => 'E-mail', 'value' => ''));
    if (isset($data['contacts'])) {
        foreach ($data['contacts'] as $name => $value) {
            if (!isset($contacts[$name])) {
                continue;
            }
            switch ($name) {
                case 'site':
                    if (!url_validate(ltrim(ltrim($value, 'http://'), 'https://')) && trim($value) != '') {
                        $error["contact_{$name}"] = 'Поле заполнено некорректно';
                    }
                    if (strpos($value, 'htt') === false && trim($value) != '') {
                        $value = 'http://' . $value;
                    }
                    break;
                case 'email':
                    if (!is_email($value) && trim($value) != '') {
                        $error["contact_{$name}"] = 'Поле заполнено некорректно';
                    }
                    break;
            }
            $contacts[$name]['value'] = __paramValue('htmltext', stripslashes($value));
        }
        $row['contacts'] = serialize($contacts);
    }
    $descrFull = stripslashes(__paramValue('html', $data['descr'], null, true));
    $descr = preg_replace('/^ /', "", $descrFull);
    $descr = preg_replace("/(\n) /", "\$1", $descr);
    $descr = reformat(strip_tags(htmlspecialchars(LenghtFormatEx(htmlspecialchars_decode($descr, ENT_QUOTES), 180), ENT_QUOTES), '<br />'), 50, 1, 0, 1);
    $descr = preg_replace("//", '&nbsp;', $descr);
    $row['descr'] = $descr;
    $row['t_is_payed'] = $data['logo_ok'] || $data['top_ok'];
    $row['t_is_ontop'] = __paramValue('bool', $data['top_ok']);
    $row['t_pro_only'] = $data['pro_only'] ? 't' : 'f';
    $row['t_verify_only'] = $data['verify_only'] ? 't' : 'f';
    $row['t_urgent'] = $data['urgent'] ? 't' : 'f';
    $row['t_hide'] = $data['hide'] ? 't' : 'f';
    $row['create_date'] = date('Y-m-d H:i', strtotime(date('Y-m-d H:i:s')) - 120);
    // делаем дату публикации 2 минуты назад
    $row['end_date'] = __paramValue('string', $data['end_date']);
    $row['win_date'] = __paramValue('string', $data['win_date']);
    $row['country'] = __paramValue('int', $data['project_location_columns'][0]);
    $row['city'] = __paramValue('int', $data['project_location_columns'][1]);
    list($row['country_name'], $row['city_name']) = explode(': ', __paramValue('string', $data['location']));
    $logoOK = __paramValue('bool', $data['logo_ok']);
    $topOK = __paramValue('bool', $data['top_ok']);
    $row['link'] = __paramValue('string', $data['link']);
    if ($logoOK) {
        $logoAttach = new attachedfiles($data['logo_attachedfiles_session']);
        $logoFiles = $logoAttach->getFiles(array(1));
        if (count($logoFiles)) {
            $logoFile = array_pop($logoFiles);
            // загружено может быть несколько файлов, берем последний
            $logoCFile = new CFile($logoFile['id']);
        } elseif (__paramValue('int', $data['logo_file_id'])) {
            $logoCFile = new CFile(__paramValue('int', $data['logo_file_id']));
        }
        $row['logo_name'] = $logoCFile->name;
        $row['logo_path'] = $logoCFile->path;
    }
    $is_ajax = true;
    // подготовка данных для подробной страницы проекта
    $project = $row;
    $categories = array();
    for ($i = 0; $i < 3; ++$i) {
        $categoryID = __paramValue('int', $data['project_profession' . $i . '_columns'][0]);
        $subcategoryID = __paramValue('int', $data['project_profession' . $i . '_spec_columns'][0]);
        if ($categoryID || $subcategoryID) {
            $categories[] = array('category_id' => $categoryID, 'subcategory_id' => $subcategoryID);
        }
    }
    $project['spec_txt'] = projects::_getSpecsStr($categories, ' / ', ', ', true);
    $project['ico_payed'] = $logoOK;
    $project['is_upped'] = $topOK;
    $project['descr'] = $descrFull;
    $project['logo_id'] = $logoCFile->id;
    $project['prefer_sbr'] = __paramValue('bool', $data['prefer_sbr']) ? 't' : 'f';
    $project['urgent'] = __paramValue('bool', $data['urgent']) ? 't' : 'f';
    $project['hide'] = __paramValue('bool', $data['hide']) ? 't' : 'f';
    if (trim($project['contacts']) != '') {
        $contacts_employer = unserialize($project['contacts']);
        $empty_contacts_employer = 0;
        foreach ($contacts_employer as $name => $contact) {
            if (trim($contact['value']) == '') {
                $empty_contacts_employer++;
            }
        }
        $is_contacts_employer_empty = count($contacts_employer) == $empty_contacts_employer;
    }
    $isPreview = true;
    $project_exRates = project_exrates::GetAll();
    $translate_exRates = array(0 => 2, 1 => 3, 2 => 4, 3 => 1);
    ob_start();
    include $_SERVER['DOCUMENT_ROOT'] . '/public/new/tpl.preview.php';
    ?>
    <?php 
    $htmlProject = ob_get_clean();
    $objResponse->assign('project_preview_lenta', 'innerHTML', $htmlLenta);
    $objResponse->assign('project_preview_content', 'innerHTML', $htmlProject);
    $objResponse->script('Public.showPreview()');
    return $objResponse;
}
Exemplo n.º 2
0
 /**
  * Поиск проектов, для выдачи на главную страницу (по фильтрам по специализации и тд)
  *
  * @param integer $prj_kind   Проект
  * @param integer $page       Страница
  * @param integer $from_cache Из кеша или нет
  * @param integer $filter     Фильтр
  * @param inetger $is_ajax    если функция вызвана через ajax @see JS seo_print();
  * @return string HTML-code
  */
 function SearchDB($prj_kind, $page = 1, $from_cache = 0, $filter = NULL, $is_ajax = false, $new = false)
 {
     $pro_last = $_SESSION['pro_last'];
     $edit_mode = hasPermissions('projects');
     $uid = $_SESSION['uid'];
     $page = intval($page);
     if ($page == 0) {
         $page = 1;
     }
     if (!$out_HTML) {
         $prjs = $this->getProjects($num_prjs, $prj_kind, $page, true, $filter, true, $is_ajax);
         // выполняется new_projects::getProjects().
         //считаем количество платных проектоы
         $_SESSION['top_payed'] = 0;
         $_SESSION['hidetopprjlenta_more'] = 0;
         if ($prjs) {
             foreach ($prjs as $p) {
                 if ($p['top_payed'] > 1970) {
                     $_SESSION['top_payed']++;
                 }
                 if (strtotime($p['top_to']) >= time() && !$p['strong_top'] && isset($_COOKIE['hidetopprjlenta']) && $_COOKIE['hidetopprjlenta'] == 1 && $_COOKIE['hidetopprjlenta_time'] < strtotime($p['create_date'])) {
                     $_SESSION['hidetopprjlenta_more'] = 1;
                 }
             }
         }
         if (!$_SESSION['top_payed']) {
             unset($_SESSION['top_payed']);
         }
         require_once ABS_PATH . '/classes/HTML/projects_lenta.php';
         $htmlPrj = new HTMLProjects();
         if ($new) {
             $htmlPrj->template = "/projects/tpl.lenta.new.php";
         }
         $out_HTML = $htmlPrj->ShowProjects($num_prjs, $prjs, $prj_kind, $page, $filter, $is_ajax);
     }
     return $out_HTML;
 }