enable_search) { $this->search = SiteMap::getObj('Search/Search.php'); $this->search->app='cms'; } $this->DLang = new DLang(); $this->lang= $this->DLang->validName($lang); } function getDocContIds($id_doc) { $details = parent::getFromDB($id_doc); $details = $this->_prepPage($details); $items = array_keys($details['items']); $ids = array(); $HTMLBlock = SiteMap::getObj('HTMLBlock/HTMLBlock.php'); foreach ($items As $item){ list($type, $name) = explode($this->item->getDelimiter(), $item); $ids[] = $HTMLBlock->getIdByName($name); } return $ids; } function getFromDB($id, $field = false) { $details = parent::getFromDB($id); $HTMLBlock = SiteMap::getObj('HTMLBlock/HTMLBlock.php'); foreach ($this->getDocContIds($id) AS $contId){ $details["content_$contId"] = $HTMLBlock->getFromDB($contId, 'content'); } return $this->getSubElem($details, $field); } function insert($data = null, $files = null) { if (!is_null($data)) { $this->initFromArray($data, $files); } $this->_initTable(); $data = $this->_data; unset($data['id']); $this->id = $this->table->insert($data); $this->_setSorter4Ins(); $this->_initContent(); $this->title->save($this->_data); $this->_initItem(); $this->item->save( array('HTMLBlock/Show:'.$this->_insCont()) ); $this->CMS_cacheAll(); return $this->id; } function _insCont() { $HTMLBlock = SiteMap::getObj('HTMLBlock/HTMLBlock.php'); $nameSuffix = ''; $i = 0; $name = $this->_getPath2Doc($this->id); while ( !$HTMLBlock->isNameUnique($name.$nameSuffix) ) { $i++; $nameSuffix = '_'.$i; } $arr = array('name' => $name.$nameSuffix, 'content' => $this->_data['content'], ); $HTMLBlock->insert($arr); return $name.$nameSuffix; } function delete() { foreach ($this->getDocContIds($this->id) AS $contId){ $HTMLBlock = SiteMap::getObj('HTMLBlock/HTMLBlock.php', $contId); $HTMLBlock->delete(); } return parent::delete(); } function update($data = null, $files = null) { if (!is_null($data)) { $this->initFromArray($data, $files); } $this->_initTable(); $this->table->update($this->_data, 'id = '. $this->db->quote($this->id, 'integer') ); $this->_initContent(); $this->title->save($this->_data); foreach ($this->getDocContIds($this->id) AS $contId){ $HTMLBlock = SiteMap::getObj('HTMLBlock/HTMLBlock.php', $contId ); $HTMLBlock->initFromArray(array('content' => $this->_data["content_$contId"])); $HTMLBlock->update(); } $this->CMS_cacheAll(); return true; } function CMS_cacheAll($id_parent = 0, $pref = '', $prefTitle= '') { if (!$this->enable_search) { return false; } if (0 == $id_parent){ $res=$this->db->query("DELETE FROM {$this->search->tableNameDB} WHERE `app`='{$this->search->app}'"); //vdie("DELETE FROM {$this->search->tableNameDB} WHERE `app`='{$this->search->app}'", $res); //$this->DocObj->db->query("ALTER TABLE {$this->DocObj->db->tblDocCache} DROP INDEX `data`"); }else { $prefTitle .= ' :: '; } if ($pref != ''){ $pref .= '/'; } $id_parentOld = $this->id_parent; //vdie($this->DocObj); $this->id_parent = intval($id_parent); $list = $this->getList4Grid(array('addonWhere' => array('zz_Doc.system' => 'n') )); $pagesCnt = count($list['list']); //vdie($list); foreach ($list['list'] as $page){ $this->CMS_cacheItem($page['id'], $pref.$page['alias'], $prefTitle.$page['title']); $pagesCnt += $this->CMS_cacheAll($page['id'], $pref.$page['alias'], $page['title']); } return $pagesCnt; } function CMS_cacheItem($id, $url, $title) { if (!$this->enable_search) { return false; } foreach ($this->DLang->getList() as $lang) { $contentPage = ''; foreach ($this->_getFileContents($id) as $key => $content){ $contentPage .= strip_tags($content[$lang['name']]); }; $arr = array('url' => $lang['name'].'/'.$url, 'title' => $title, 'data' => $contentPage, ); $this->search->insert($arr); } return 1; } function _getFileContents($id) { $contents = array(); $docArr = $this->getFromDB($id); foreach ($docArr as $key => $content){ if (substr($key, 0, 7) == 'content'){ $contents[] = $content; } } return $contents; } }