コード例 #1
0
ファイル: download.php プロジェクト: k-kalashnikov/forKoda
 public function download()
 {
     $id = $this->fw->get('PARAMS.id');
     $file = \models\Content::getInstance('files');
     $content = $file->getItems($id);
     //		\helpers\Debug::prePrintR($content[0]);
     $fileinfo = $content[0];
     $path = $this->fw->get('ROOT') . '/uploads/files/' . $fileinfo['id'] . '.' . $fileinfo['title'];
     if (file_exists($path)) {
         $res = $file->getOne($id);
         $res->af_downloaded++;
         $res->save();
         header('Content-Type: application/force-download');
         header('Content-Description: File Transfer');
         header('Content-Disposition: attachment; filename="' . $fileinfo['content'] . '"');
         header('Content-Transfer-Encoding: binary');
         header("Accept-Ranges: bytes");
         header("Content-Length: " . filesize($path));
         readfile($path);
         exit;
     } else {
         $this->fw->error(404);
         exit;
     }
 }
コード例 #2
0
ファイル: contentitem.php プロジェクト: k-kalashnikov/forKoda
 /**
  * Заменяет в тексте [link=<type>-<id>]
  * на html-код <a href="..." target="_blank">...</a>
  * @param string $text
  */
 public function makeLinks($text)
 {
     static $pattern = null;
     if (is_null($pattern)) {
         $types = \models\meta\Meta::getInstance()->getTypesNames();
         $pattern = '/\\[link=(' . implode('|', $types) . ')-(\\d+)\\]/';
     }
     if (preg_match_all($pattern, $text, $matches)) {
         if (count($matches) == 3) {
             $text = strip_tags($text);
             //			\helpers\Debug::prePrintR($matches);
             foreach ($matches[0] as $k => $v) {
                 $type = $matches[1][$k];
                 $id = $matches[2][$k];
                 $model = \models\Content::getInstance($type);
                 if ($node = $model->getOne($id)) {
                     $route = $model->getNamedRoute($type);
                     $link = '<a href="' . \Base::instance()->alias($route, 'table=' . $type . ',slug=' . $node->slug) . '">' . $node->title . '</a>';
                     $text = str_replace($v, $link, $text);
                 }
             }
         }
     }
     return $text;
 }
コード例 #3
0
 function prepareNode($node_name, $key_field)
 {
     $var_table_name = 'node_' . $cat_name . '_table';
     $var_list_name = 'node_' . $cat_name . '_list';
     $this->{$var_table_name} = \models\Content::getInstance($node_name);
     $this->{$var_list_name} = $this->{$var_table_name}->getListAll($key_field);
 }
コード例 #4
0
ファイル: content.php プロジェクト: k-kalashnikov/forKoda
 /**
  * Устанавливает значения связанных объектов для селектов
  * для связей 1-ко-многим
  */
 protected function setSingleRelationsSelected()
 {
     foreach ($this->tableMeta->getParents() as $k => $v) {
         //			\helpers\Debug::prePrintR($v); continue;
         $fname = 'fko_' . $v['table'];
         $sel_id = $this->node[$fname];
         if (isset($relations_single[$fname]['options'][$sel_id])) {
             $this->fw->set("ajax_fields.{$fname}.options.{$sel_id}.selected", true);
         }
         if ($this->tableMeta->isTree()) {
             $model = \models\Content::getInstance($v['table']);
             $tmp = $model->getParents($sel_id);
             while ($item = array_shift($tmp)) {
                 $path[$item['pid']] = $item['id'];
             }
             $this->fw->set("ajax_fields.{$fname}.selected", $path);
         }
     }
 }
コード例 #5
0
ファイル: layout.php プロジェクト: k-kalashnikov/forKoda
 /**
  * Устанавливает "хлебные крошки"
  * @todo разобраться с использованием $node_path и $filter
  * @param array $page
  */
 static function setBreadcrumbs($page, $filter = null, $node_path = null)
 {
     $res = array('path' => [], 'active' => '');
     if ($filter) {
         $res['active'] = $filter['af_menu'];
     } else {
         $res['active'] = self::getMenuItemTitle($page);
     }
     if ($page['pid'] != 0) {
         $htmlpage = \models\Content::getInstance('htmlpage');
         $tmp = $htmlpage->getParents($page['pid']);
         if (!empty($tmp)) {
             $alias = array();
             $path = array();
             foreach ($tmp as $v) {
                 if (empty($v['slug']) && $v['pid'] == 0) {
                     $url = '/';
                 } else {
                     $alias[] = $v['slug'];
                     $url = '/' . implode('/', $alias);
                 }
                 $path[$url] = self::getMenuItemTitle($v);
             }
             // TODO: проверить!
             if (!is_null($filter)) {
                 if (empty($page['slug']) && $page['pid'] == 0) {
                     $url = '/';
                 } else {
                     $alias[] = $page['slug'];
                     $url = implode('/', $alias);
                 }
                 $path[$url] = self::getMenuItemTitle($page);
             }
             if (!is_null($node_path)) {
                 $n_path = array();
                 foreach ($node_path as $url => $title) {
                     $n_path[$url] = $title;
                 }
                 $path = array_merge($path, $n_path);
             }
             $res['path'] = $path;
         }
     }
     \Base::instance()->set('breadcrumbs', $res);
 }
コード例 #6
0
ファイル: contentlist.php プロジェクト: k-kalashnikov/forKoda
 /**
  * Формирует необходимую информацию для полей фильтрации
  * Пример фильтра много-ко-много:
  * если надо выбрать все объекты типа контента `objects`, связанные с другим объектом типа контента `categories`,
  * через расшивочную таблицу `or_categories_objects`
  * где <cat_id> - ID записи в таблице <categories>, фильтр будет иметь такой вид:
  * ['field' => <categories>, 'value' => <cat_id>]
  * @param array $filter одно поле для фильтрации в формате array ['field' => 'название поля', 'value' => 'значение']
  * @param string $slug название типа контента для формирования имени таблицы
  * @param boolean $for_admin для админа или нет 
  * @return array дополненный массив одного поля для фильтрации (null, если название поля некорректно)
  * 	[
  * 		'field' => 'название поля', 
  * 		'value' => 'значение'
  * 		'menu'  => 'что писать в меню', 
  * 		'clear_field' => 'Реальное имя поля в таблице', 
  * 		'table' => 'Название таблицы для связи много-ко-многим',
  * 	]
  */
 static function clearFilterFieldName($filter, $slug, $for_admin = false)
 {
     //		\helpers\Debug::prePrintR($filter);
     if (isset($filter['clear_field'])) {
         return $filter;
     }
     $filter['clear_field'] = null;
     $list_base_fields = array('priority', 'created', 'published', 'user_id', 'pid');
     if ($for_admin) {
         $list_base_fields[] = 'moderation';
         $list_base_fields[] = 'deleted';
         $list_base_fields[] = 'edited';
     }
     $list = array();
     $list_obj = array();
     $field_data = array();
     $tableMeta = \models\meta\Meta::getInstance()->getTableMeta($slug);
     foreach ($tableMeta->getFields() as $v) {
         $field_data[$v['name']] = $v;
         if ($v['is_additional']) {
             $list[] = $v['fullname'];
         } elseif (preg_match('/^fko_(.+)$/', $v['fullname'], $m)) {
             $list_obj['po_' . $m[1]] = $m[1];
         } elseif (in_array($v['name'], $list_base_fields)) {
             $list[] = $v['name'];
         }
     }
     // простые поля
     if (in_array($filter['field'], $list) || in_array(preg_replace('/^' . $slug . '\\./', '', $filter['field']), $list)) {
         $filter['clear_field'] = $filter['field'];
         if ($field_data[$filter['field']]['type'] == "enum('0','1')") {
             list($title, $comment) = explode(';', $field_data[$filter['field']]['comment']);
             $filter['menu'] = $title . ' : ' . ($filter['value'] ? 'да' : 'нет');
         } else {
             $filter['menu'] = $filter['value'];
         }
         return $filter;
     }
     // Категории один-ко-много
     if (isset($list_obj[$filter['field']])) {
         $node_manager = \models\Content::getInstance($list_obj[$filter['field']]);
         $node = $node_manager->get($filter['value']);
         $filter['menu'] = $node['title'];
         $filter['clear_field'] = 'fko_' . $list_obj[$filter['field']];
         return $filter;
     }
     //Категории много-ко-много
     $tables = $tableMeta->getPlural();
     foreach ($tables as $t) {
         //$plural_name = RelationsManager::getPluralName($filter['table'], $filter['field']);
         if ($filter['field'] == $t['table']) {
             $filter['clear_field'] = $t['full_table_name'] . '.' . $filter['field'] . '_id';
             $filter['menu'] = $t['comment'];
             $filter['table'] = $t;
             return $filter;
         }
     }
     return null;
 }
コード例 #7
0
 private function checkForeignKey($table, $id)
 {
     $related_node_model = \models\Content::getInstance($table);
     if ($related_node_model->getOne($id)) {
         return true;
     } else {
         return false;
     }
 }
コード例 #8
0
ファイル: imagefield.php プロジェクト: k-kalashnikov/forKoda
 protected function make($crop, $enlarge)
 {
     $model = \models\Content::getInstance($this->table);
     return $model->makeThumbnail($this->id, $this->field, $this->w, $this->h, $crop, $enlarge);
 }
コード例 #9
0
ファイル: frontend.php プロジェクト: k-kalashnikov/forKoda
 /**
  * Выводит страницу/раздел сайта (htmlpage)
  * @param type $this->fw
  */
 public function show()
 {
     if ($this->isPublished()) {
         if ($this->struct_page['af_islink'] && !empty($this->struct_page['af_link'])) {
             // Если ссылка - перенаправляем
             $this->fw->reroute($this->struct_page['af_link'], true);
         } else {
             $this->setLayout();
         }
     } else {
         if (\models\meta\TablesManager::getInstance()->tableExists('_redirect')) {
             $redirect = new \DB\SQL\Mapper($this->db, '_redirect');
             $redirect->load(array('`from`=? ', $this->fw->get('PATH')));
             // Проверить!
             if ($redirect->to_id) {
                 $model = \models\Content::getInstance('htmlpage');
                 $this->fw->reroute('/' . $model->getPath($redirect->to_id), true);
             }
         }
         $this->fw->error(404);
     }
 }
コード例 #10
0
ファイル: content.php プロジェクト: k-kalashnikov/forKoda
 /**
  * Возвращает объект модели для разделов каталога
  * может быть переопределена в наследнике для использования кастомной модели
  * @return \models\Content
  */
 protected function getCategoriesNodeModel()
 {
     return \models\Content::getInstance($this->table_cat);
 }