/** * прикрепить ссылку к посту */ public function action_link($type = 'link', $url = null) { if (empty($_REQUEST['post_id']) || !is_numeric($_REQUEST['post_id']) && $_REQUEST['post_id'] != 'new') { $this->_actions_data['_errors'][] = 'Неверные параметры.'; $this->_actions_data['_ok'] = 0; return; } $post_id = $_REQUEST['post_id']; if ($url == null) { $url = $_REQUEST['url']; } $description = $_REQUEST['description']; if ($post_id == 'new') { $postsCtrl = new Controller_Posts($this->_options, $this->_params); $post_id = $postsCtrl->action_add(true); } $attachment = new posts_attachments(array('post_id' => $post_id, 'type' => strtolower($type), 'url' => $url, 'description' => $description)); $attachment->save(); $this->_actions_data['attachment'] = $attachment->attributes(); }
/** * вернет список атачментов к посту * * результат в $this->_actions_data['attachments'] */ public function action_attachments($post_id = null) { $this->_actions_data['attachments'] = array(); if ($post_id == null) { if (empty($_REQUEST['post_id']) || !is_numeric($_REQUEST['post_id'])) { return; } $post_id = $_REQUEST['post_id']; } foreach (posts_attachments::find_all_by_post_id($post_id) as $attachment) { $this->_actions_data['attachments'][] = $attachment->attributes(); } }