コード例 #1
0
ファイル: include.php プロジェクト: procivam/s-mir-new
function catalog_add($item, $name)
{
    $data = array('date' => time(), 'name' => $name, 'urlname' => getURLName($name));
    return A::$DB->Insert("{$item}_catalog", $data);
}
コード例 #2
0
ファイル: shoplite.php プロジェクト: procivam/s-mir-new
 /**
  * Обработчик действия: Импорт каталога.
  */
 function Import()
 {
     @set_time_limit(0);
     require_once "Structures/DataGrid.php";
     require_once "Structures/DataGrid/DataSource/Excel.php";
     require_once "Structures/DataGrid/DataSource/CSV.php";
     require_once 'Image/Transform.php';
     mk_dir("files/" . DOMAIN . "/tmp");
     clearDir("files/" . DOMAIN . "/tmp");
     if (isset($_FILES['file']['tmp_name']) && file_exists($_FILES['file']['tmp_name'])) {
         $path_parts = pathinfo($_FILES['file']['name']);
         $ext = preg_replace("/[^a-z0-9]+/i", "", mb_strtolower($path_parts['extension']));
         if ($ext == 'xls' || $ext == 'csv' || $ext == 'gz') {
             if ($ext == 'gz') {
                 if (extractArchive($_FILES['file']['tmp_name'], "files/" . DOMAIN . "/tmp")) {
                     $sourcefile1 = preg_replace("/tar\\.gz\$/i", "xls", $_FILES['file']['name']);
                     $sourcefile2 = preg_replace("/tar\\.gz\$/i", "csv", $_FILES['file']['name']);
                     if (is_file("files/" . DOMAIN . "/tmp/{$sourcefile1}")) {
                         $sourcefile = "files/" . DOMAIN . "/tmp/{$sourcefile1}";
                         $ext = "xls";
                     } elseif (is_file("files/" . DOMAIN . "/tmp/{$sourcefile2}")) {
                         $sourcefile = "files/" . DOMAIN . "/tmp/{$sourcefile2}";
                         $content = @file_get_contents($sourcefile);
                         if ($content && !mb_check_encoding($content, 'UTF-8')) {
                             file_put_contents($sourcefile, mb_convert_encoding($content, 'UTF-8', 'Windows-1251'));
                         }
                         $ext = "csv";
                     } else {
                         return false;
                     }
                 } else {
                     return false;
                 }
             } elseif ($ext == 'csv') {
                 $sourcefile = $_FILES['file']['tmp_name'];
                 $content = @file_get_contents($sourcefile);
                 if ($content && !mb_check_encoding($content, 'UTF-8')) {
                     file_put_contents($sourcefile, mb_convert_encoding($content, 'UTF-8', 'Windows-1251'));
                 }
             } else {
                 $sourcefile = $_FILES['file']['tmp_name'];
             }
             if (!empty($_REQUEST['clear'])) {
                 switch ($_REQUEST['clear']) {
                     case 1:
                         A::$DB->execute("TRUNCATE " . SECTION . "_categories");
                     case 2:
                         A::$DB->execute("TRUNCATE " . SECTION . "_catalog");
                         A::$DB->execute("DELETE FROM " . DOMAIN . "_images WHERE idsec=" . SECTION_ID . " AND iditem>0");
                         A::$DB->execute("DELETE FROM " . DOMAIN . "_files WHERE idsec=" . SECTION_ID . " AND iditem>0");
                         A::$DB->execute("DELETE FROM " . DOMAIN . "_comments WHERE idsec=" . SECTION_ID);
                         A_SearchEngine::getInstance()->deleteSection(SECTION_ID);
                         break;
                 }
             }
             A::$OPTIONS['imgpath'] = !empty(A::$OPTIONS['imgpath']) ? preg_replace("/[^a-zA-Z0-9-_\\/]/i", "", A::$OPTIONS['imgpath']) : "ifiles";
             A::$OPTIONS['filepath'] = !empty(A::$OPTIONS['filepath']) ? preg_replace("/[^a-zA-Z0-9-_\\/]/i", "", A::$OPTIONS['filepath']) : "ifiles";
             $categories = array();
             $fields = array();
             $cfiles = array();
             A::$DB->query("SELECT * FROM " . SECTION . "_cols ORDER BY sort");
             $i = 0;
             while ($row = A::$DB->fetchRow()) {
                 if ($row['type'] == 'select' || $row['type'] == 'mselect') {
                     if ($row['idvar'] = A::$DB->getOne("SELECT property FROM " . DOMAIN . "_fields WHERE item='" . SECTION . "' AND field='{$row['field']}'")) {
                         if (isset($vars[$row['idvar']])) {
                             $row['vars'] =& $vars[$row['idvar']];
                         } else {
                             $row['vars'] = array();
                             $_vars = loadList($row['idvar']);
                             foreach ($_vars as $key => $name) {
                                 $row['vars'][$key] = is_array($name) ? $name['name'] : $name;
                             }
                             $vars[$row['idvar']] =& $row['vars'];
                         }
                     }
                 }
                 $row['id'] = $i++;
                 if (preg_match("/^category[0-9]{1}\$/i", $row['field'])) {
                     $categories[$row['field']] = $row;
                 } elseif ($row['type'] == 'image' || $row['type'] == 'file') {
                     $cfiles[$row['field']] = $row;
                 } else {
                     $fields[$row['field']] = $row;
                 }
             }
             A::$DB->free();
             if ($ext == 'xls') {
                 $datasource = new Structures_DataGrid_DataSource_Excel();
                 $datasource->bind($sourcefile);
             } elseif ($ext == 'csv') {
                 $datasource = new Structures_DataGrid_DataSource_CSV();
                 $datasource->bind($sourcefile, array('delimiter' => ';', 'enclosure' => '"'));
             } else {
                 return false;
             }
             $datagrid = new Structures_DataGrid();
             $datagrid->bindDataSource($datasource);
             A::$DB->caching = false;
             $prevgoods = A::$DB->getCount(SECTION . "_catalog", "active='Y'");
             $curgoods = 0;
             $arts = array();
             $catn = array();
             $catr = array();
             $cats = array();
             $i = 0;
             $gsort = A::$DB->getOne("SELECT MAX(sort) FROM " . SECTION . "_catalog") + 1;
             foreach ($datagrid->recordSet as $row) {
                 $i++;
                 if ($i == 1) {
                     continue;
                 }
                 if (empty($row)) {
                     continue;
                 }
                 if ($ext == 'xls') {
                     $trow = array();
                     foreach ($row as $j => $value) {
                         if (!empty($value)) {
                             $trow[$j - 1] = $value;
                         }
                     }
                     $row = $trow;
                 }
                 $idcat = 0;
                 for ($j = 0; $j < 3; $j++) {
                     if (isset($categories['category' . $j]) && !empty($row[$categories['category' . $j]['id']])) {
                         if ($cname = strip_tags(trim($row[$categories['category' . $j]['id']]))) {
                             $ch = md5($idcat . '|' . $cname);
                             if (isset($catn[$ch])) {
                                 $idcat = $catn[$ch];
                             } elseif ($_idcat = A::$DB->getOne("SELECT id FROM " . SECTION . "_categories WHERE idker={$idcat} AND name=?", $cname)) {
                                 $idcat = $catn[$ch] = $_idcat;
                             } else {
                                 if (!isset($catr[$idcat])) {
                                     $catr[$idcat] = A::$DB->getRowById($idcat, SECTION . "_categories");
                                 }
                                 $category = array();
                                 $category['name'] = $cname;
                                 $category['urlname'] = getURLName($cname);
                                 $category['idker'] = $idcat;
                                 $category['level'] = isset($catr[$idcat]['level']) ? $catr[$idcat]['level'] + 1 : 0;
                                 $category['sort'] = A::$DB->getOne("SELECT MAX(sort) FROM " . SECTION . "_categories WHERE idker={$idcat}") + 1;
                                 $idcat = $catn[$ch] = A::$DB->Insert(SECTION . "_categories", $category);
                             }
                         }
                     }
                 }
                 if ($idcat == 0 && empty($row[$fields['art']['id']])) {
                     continue;
                 }
                 $data = array();
                 $data['date'] = time();
                 if ($idcat > 0) {
                     $data['idcat'] = $idcat;
                     if (!isset($cats[$idcat])) {
                         $cats[$idcat] = 1;
                     } else {
                         $cats[$idcat]++;
                     }
                 }
                 $data['idcat1'] = 0;
                 $data['idcat2'] = 0;
                 foreach ($fields as $field => $frow) {
                     if (!isset($_REQUEST['iempty']) || !empty($row[$frow['id']])) {
                         switch ($frow['type']) {
                             default:
                                 $data[$field] = !empty($row[$frow['id']]) ? trim($row[$frow['id']]) : "";
                                 break;
                             case 'int':
                                 $data[$field] = !empty($row[$frow['id']]) ? (int) $row[$frow['id']] : 0;
                                 break;
                             case 'float':
                                 $data[$field] = !empty($row[$frow['id']]) ? (double) str_replace(',', '.', $row[$frow['id']]) : 0;
                                 break;
                             case 'select':
                                 if (!empty($row[$frow['id']])) {
                                     if (isset($frow['vars'])) {
                                         $row[$frow['id']] = trim($row[$frow['id']]);
                                         $key = array_search($row[$frow['id']], $frow['vars']);
                                         if (empty($key) && !empty($row[$frow['id']])) {
                                             $key = addToList($frow['idvar'], $row[$frow['id']]);
                                             $fields[$field]['vars'][$key] = $frow['vars'][$key] = $row[$frow['id']];
                                         }
                                         if (!empty($key)) {
                                             $data[$field] = $key;
                                         }
                                     }
                                 }
                                 break;
                             case 'mselect':
                                 if (!empty($row[$frow['id']])) {
                                     if (isset($frow['vars'])) {
                                         $row[$frow['id']] = explode(',', $row[$frow['id']]);
                                         $data[$field] = array();
                                         foreach ($row[$frow['id']] as $value) {
                                             $value = trim($value);
                                             $key = array_search($value, $frow['vars']);
                                             if (empty($key) && !empty($value)) {
                                                 $key = addToList($frow['idvar'], $value);
                                                 $fields[$field]['vars'][$key] = $frow['vars'][$key] = $value;
                                             }
                                             if (!empty($key)) {
                                                 $data[$field][] = sprintf("%04d", $key);
                                             }
                                         }
                                         $data[$field] = implode(",", $data[$field]);
                                     }
                                 }
                                 break;
                             case 'bool':
                                 $data[$field] = !empty($row[$frow['id']]) && $row[$frow['id']] != 'N' ? "Y" : "N";
                                 break;
                         }
                     }
                 }
                 if (isset($data['name'])) {
                     $data['name'] = strip_tags(trim($data['name']));
                 }
                 if (!empty(A::$OPTIONS['idrule'])) {
                     $_data = $data;
                     prepareValues(SECTION, $_data);
                     $litems = array();
                     $idrule = A::$OPTIONS['idrule'];
                     $idrule = explode("+", $idrule);
                     foreach ($idrule as $fname) {
                         if (!empty($_data[$fname])) {
                             $litems[] = getURLName($_data[$fname]);
                         }
                     }
                     $data['urlname'] = implode(!empty($GLOBALS['A_URL_SEPARATOR']) ? $GLOBALS['A_URL_SEPARATOR'] : "_", $litems);
                 } elseif (!empty($data['art'])) {
                     $data['urlname'] = getURLName($data['art']);
                 }
                 if (empty($data['urlname'])) {
                     $data['urlname'] = getURLName($data['name']);
                 }
                 if (!empty($data['content']) && empty($data['description'])) {
                     $data['description'] = truncate($data['content'], A::$OPTIONS['anonslen']);
                 }
                 if (!empty($data['art'])) {
                     $grow = A::$DB->getRow("SELECT id,mprices FROM " . SECTION . "_catalog WHERE art=? LIMIT 0,1", $data['art']);
                     if (A::$OPTIONS['usecats']) {
                         if (!empty($arts[$data['art']]) && !empty($data['idcat'])) {
                             if ($arts[$data['art']] < 3) {
                                 $data['idcat' . $arts[$data['art']]] = $data['idcat'];
                                 unset($data['idcat']);
                             }
                             $arts[$data['art']]++;
                         } else {
                             $arts[$data['art']] = 1;
                         }
                     }
                 } else {
                     $grow = A::$DB->getRow("SELECT id,mprices FROM " . SECTION . "_catalog WHERE idcat=? AND name=? LIMIT 0,1", array($data['idcat'], $data['name']));
                 }
                 if ($grow) {
                     $id = $grow['id'];
                     $mprices = !empty($grow['mprices']) ? unserialize($grow['mprices']) : array();
                 } else {
                     $id = 0;
                 }
                 if ($id) {
                     if (isset($fields['mprice']) && !empty($data['mprice'])) {
                         $inm = false;
                         foreach ($mprices as $mp) {
                             if ($mp['name'] == trim($data['mprice'])) {
                                 $inm = true;
                                 break;
                             }
                         }
                         if (!$inm) {
                             $mprices[] = array('name' => $data['mprice'], 'price' => !empty($data['price']) ? $data['price'] : '');
                         }
                         $data['mprices'] = serialize($mprices);
                         unset($data['price']);
                         $cats[$idcat]--;
                         $curgoods--;
                     }
                     if (isset($data['mprice'])) {
                         unset($data['mprice']);
                     }
                     A::$DB->Update(SECTION . "_catalog", $data, "id={$id}");
                     $images = A::$DB->getAssoc("SELECT sort,id,path FROM " . DOMAIN . "_images\r\r\n\t\t\tWHERE idsec=" . SECTION_ID . " AND iditem={$id}");
                     $images = array_values($images);
                     $files = A::$DB->getAssoc("SELECT sort,id,path FROM " . DOMAIN . "_files\r\r\n\t\t\tWHERE idsec=" . SECTION_ID . " AND iditem={$id}");
                     $files = array_values($files);
                     $curgoods++;
                 } elseif (!empty($data['idcat'])) {
                     if (isset($fields['mprice']) && !empty($data['mprice'])) {
                         $mprices = array(array('name' => $data['mprice'], 'price' => !empty($data['price']) ? $data['price'] : ''));
                         $data['mprices'] = serialize($mprices);
                     }
                     if (isset($data['mprice'])) {
                         unset($data['mprice']);
                     }
                     if (empty($data['name'])) {
                         continue;
                     }
                     $data['sort'] = $gsort++;
                     $id = A::$DB->Insert(SECTION . "_catalog", $data);
                     $images = array();
                     $files = array();
                     $curgoods++;
                 } else {
                     continue;
                 }
                 foreach ($cfiles as $field => $frow) {
                     if (!empty($row[$frow['id']])) {
                         switch ($frow['type']) {
                             case 'image':
                                 $row[$frow['id']] = preg_replace("/[^a-zA-Zа-яА-Я0-9-_.]/iu", "", $row[$frow['id']]);
                                 $path0 = A::$AUTH->isSuperAdmin() ? "ifiles/" . $row[$frow['id']] : "";
                                 $path1 = "files/" . DOMAIN . "/" . A::$OPTIONS['imgpath'] . "/" . $row[$frow['id']];
                                 $path2 = "files/" . DOMAIN . "/reg_images/" . $row[$frow['id']];
                                 $path = is_file($path0) ? $path0 : (is_file($path1) ? $path1 : (is_file($path2) ? $path2 : ""));
                                 if ($path) {
                                     preg_match("/^idimg([0-9]+)\$/i", $field, $mathes);
                                     $sort = $mathes[1];
                                     if (!isset($images[$sort]) || $images[$sort]['path'] != $path) {
                                         $image = array();
                                         $image['path'] = $path;
                                         $image['name'] = basename($row[$frow['id']]);
                                         $image['mime'] = getMimeByFile($row[$frow['id']]);
                                         $image['caption'] = !empty($data['name']) ? $data['name'] : "";
                                         $it = Image_Transform::factory('GD');
                                         $it->load($path);
                                         $image['width'] = $it->img_x;
                                         $image['height'] = $it->img_y;
                                         $image['idsec'] = SECTION_ID;
                                         $image['iditem'] = $id;
                                         $image['sort'] = $sort;
                                         if (isset($images[$sort])) {
                                             A::$DB->Update(DOMAIN . "_images", $image, "id=" . $images[$sort]['id']);
                                         } else {
                                             A::$DB->Insert(DOMAIN . "_images", $image);
                                         }
                                     }
                                 }
                                 break;
                             case 'file':
                                 $row[$frow['id']] = preg_replace("/[^a-zA-Zа-яА-Я0-9-_.]/iu", "", $row[$frow['id']]);
                                 $path0 = A::$AUTH->isSuperAdmin() ? "ifiles/" . $row[$frow['id']] : "";
                                 $path1 = "files/" . DOMAIN . "/" . A::$OPTIONS['filepath'] . "/" . $row[$frow['id']];
                                 $path2 = "files/" . DOMAIN . "/reg_files/" . $row[$frow['id']];
                                 $path = is_file($path0) ? $path0 : (is_file($path1) ? $path1 : (is_file($path2) ? $path2 : ""));
                                 if ($path) {
                                     preg_match("/^idfile([0-9]+)\$/i", $field, $mathes);
                                     $sort = $mathes[1];
                                     if (!isset($files[$sort]) || $files[$sort]['path'] != $path) {
                                         $file = array();
                                         $file['path'] = $path;
                                         $file['name'] = basename($row[$frow['id']]);
                                         $file['mime'] = getMimeByFile($row[$frow['id']]);
                                         $file['caption'] = !empty($data['name']) ? $data['name'] : "";
                                         $file['idsec'] = SECTION_ID;
                                         $file['iditem'] = $id;
                                         $file['sort'] = $sort;
                                         $file['size'] = filesize($path);
                                         $file['dwnl'] = 0;
                                         if (isset($files[$sort])) {
                                             A::$DB->Update(DOMAIN . "_files", $file, "id=" . $files[$sort]['id']);
                                         } else {
                                             A::$DB->Insert(DOMAIN . "_files", $file);
                                         }
                                     }
                                 }
                                 break;
                         }
                     }
                 }
             }
             if ($prevgoods > 0 && $prevgoods != $curgoods) {
                 $this->updateCItems();
             } else {
                 A::$DB->Update(SECTION . "_categories", array('citems' => 0));
                 foreach ($cats as $id => $count) {
                     A::$DB->Update(SECTION . "_categories", array('citems' => $count), "id={$id}");
                 }
                 $this->updateCItems(0, true);
             }
             A::$CACHE->resetSection(SECTION);
             delDir("files/" . DOMAIN . "/tmp");
             return true;
         }
     }
     return false;
 }
コード例 #3
0
ファイル: request.php プロジェクト: procivam/s-mir-new
 /**
  * Обработчик действия: Сохранение страницы.
  */
 function applyPage()
 {
     $this->RESULT['result'] = false;
     $row = A::$DB->getRowById($_REQUEST['id'], SECTION);
     if (!$row) {
         return false;
     }
     $_REQUEST['date'] = time();
     $_REQUEST['name'] = strip_tags($_REQUEST['name']);
     $_REQUEST['urlname'] = getURLName($_REQUEST['name'], $_REQUEST['urlname'], SECTION, "type='page' AND idker={$row['idker']} AND id<>" . $row['id']);
     $_REQUEST['keywords'] = getkeywords($_REQUEST['content']);
     $_REQUEST['description'] = truncate($_REQUEST['content'], 350);
     $_REQUEST['active'] = isset($_REQUEST['active']) ? 'Y' : 'N';
     $_REQUEST['inmap'] = isset($_REQUEST['inmap']) ? 'Y' : 'N';
     $dataset = new A_DataSet(SECTION, true);
     $dataset->fields = array("date", "name", "urlname", "keywords", "description", "content", "tags", "active", "inmap");
     $_REQUEST["template"] = preg_replace("/[^a-zA-Z0-9._-]+/i", "", $_REQUEST["template"]);
     $dataset->fields[] = 'template';
     if ($row = $dataset->Update()) {
         $name = getTreePath(SECTION, $row['level'] == 0 || $row['urlname'] != 'index' ? $row['id'] : $row['idker'], " - ");
         A::$OBSERVER->Event('searchIndexUpdate', SECTION, array('id' => $row['id'], 'name' => $name, 'content' => $_REQUEST['content'], 'tags' => $_REQUEST['tags']));
         if (!empty($_REQUEST["template"])) {
             copyfile("modules/pages/templates/default/pages_page.tpl", "templates/" . DOMAIN . "/" . $_REQUEST["template"]);
         }
         while ($row['idker']) {
             if ($row = A::$DB->getRowById($row['idker'], SECTION)) {
                 A::$DB->Update(SECTION, array('date' => $_REQUEST['date']), "id=" . $row['id']);
             }
         }
         $this->RESULT['date'] = date("d.m.Y H:i", $_REQUEST['date']) . "&nbsp;&nbsp;";
         $this->RESULT['result'] = true;
         return true;
     }
 }
コード例 #4
0
ファイル: pages.php プロジェクト: procivam/s-mir-new
 /**
  * Обработчик действия: Перемещение страницы или подраздела.
  *
  * @param integer $id=0 Идентификатор элемента.
  */
 function Move($id = 0)
 {
     if ($id > 0) {
         $_REQUEST['id'] = $id;
     }
     if (empty($_REQUEST['id'])) {
         return false;
     }
     $row = A::$DB->getRowById($_REQUEST['id'], SECTION);
     if (!$row || $_REQUEST['id'] == $_REQUEST['idto']) {
         return false;
     }
     $update = array();
     if (!empty($_REQUEST['idto'])) {
         $update['level'] = A::$DB->getOne("SELECT level FROM " . SECTION . " WHERE id=" . (int) $_REQUEST['idto']) + 1;
     } else {
         $update['level'] = 0;
     }
     $update['idker'] = (int) $_REQUEST['idto'];
     $update['sort'] = A::$DB->getOne("SELECT MAX(sort) FROM " . SECTION . " WHERE idker=" . (int) $_REQUEST['idto']) + 1;
     $update['urlname'] = getURLName($row['name'], $row['urlname'], SECTION, "idker=" . (int) $_REQUEST['idto']);
     A::$DB->Update(SECTION, $update, "id=" . $row['id']);
     $this->ReLevels($row['id'], $update['level'] + 1);
     $name = getTreePath(SECTION, $row['level'] == 0 || $row['urlname'] != 'index' ? $row['id'] : $row['idker'], " - ");
     if ($row['active'] == 'Y') {
         A::$OBSERVER->Event('searchIndexUpdate', SECTION, array('id' => $row['id'], 'name' => $name, 'content' => $row['content'], 'tags' => $row['tags']));
     }
     return true;
 }
コード例 #5
0
ファイル: catalog.php プロジェクト: procivam/s-mir-new
 /**
  * Обработчик действия: Перемещение группы записей.
  */
 function MoveItems()
 {
     $idto = (int) $_REQUEST['idto'];
     $cats = array();
     if (!empty($_REQUEST['checkitem'])) {
         foreach ($_REQUEST['checkitem'] as $id) {
             if ($data = A::$DB->getRowById($id, SECTION . "_catalog")) {
                 if ($data['idcat'] == $idto) {
                     continue;
                 }
                 $update = array();
                 $update['idcat'] = $idto;
                 $update['urlname'] = getURLName($data['name'], $data['urlname'], SECTION . "_catalog", "idcat={$idto}");
                 A::$DB->Update(SECTION . "_catalog", $update, "id=" . (int) $id);
                 $path = getTreePath(SECTION . "_categories", $idto, " - ");
                 $name = !empty($path) ? $path . ' - ' . $data['name'] : $data['name'];
                 if ($data['active'] == 'Y') {
                     A::$OBSERVER->Event('searchIndexUpdate', SECTION, array('id' => $id, 'name' => $name, 'content' => $data['content'], 'tags' => $data['tags']));
                 }
                 $cats[$data['idcat']] = true;
             }
         }
     }
     $cats = array_keys($cats);
     foreach ($cats as $idcat) {
         self::updateCategoryItems($idcat);
     }
     self::updateCategoryItems($idto);
     return true;
 }