It looks like you're new here. If you want to get involved, click one of these buttons!
function form_fields($values = array(), $related = array())
{
$fields = parent::form_fields($values, $related);
$fields['slug']['type'] = 'hidden';
$fields['content']['img_folder'] = 'articles/';
$fields['keywords']['type'] = 'hidden';
$fields['featured_image'] = array('ignore_representative' => TRUE);
$fields['featured_image_upload'] = array('type' => 'file', 'file_name' => '{new_file_name}', 'folder' => 'images/articles/', 'overwrite' => TRUE, 'display_overwrite' => TRUE, 'multiple' => FALSE, 'order' => 9);
return $fields;
}
function on_before_post($values)
{
$post_date = (empty($_POST['post_date'])) ? date('Y-m-d') : $_POST['post_date'];
$_POST['new_file_name'] = url_title(date('Y-m-d', strtotime($post_date)).'-'.$_POST['title'], 'dash', TRUE).'-featured';
return $values;
}
function on_after_post($values)
{
$CI =& get_instance();
$CI->load->library('image_lib');
if (!empty($CI->upload))
{
$data = $CI->upload->data();
if (!empty($data['full_path']))
{
$config = array();
$config['source_image'] = $data['full_path'];
$config['create_thumb'] = FALSE;
$config['width'] = 1024;
$config['height'] = 768;
$config['maintain_ratio'] = TRUE;
$CI->image_lib->clear();
$CI->image_lib->initialize($config);
if (!$CI->image_lib->resize())
{
$this->add_error($CI->image_lib->display_errors());
}
}
}
return $values;
}
function on_before_delete($where)
{
$id = $this->_determine_key_field_value($where);
$data = $this->find_by_key($id);
$files[] = assets_server_path('articles/'.$data->featured_image, 'images');
foreach($files as $file)
{
if (file_exists($file))
{
@unlink($file);
}
}
}
Comments
CREATE TABLE IF NOT EXISTS `articles` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `title` varchar(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT '', `subtitle` varchar(1020) COLLATE utf8_unicode_ci NOT NULL DEFAULT '', `slug` varchar(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT '' COMMENT 'This is the last part of the url string.', `author_id` tinyint(3) unsigned NOT NULL DEFAULT '0', `content` text COLLATE utf8_unicode_ci NOT NULL, `excerpt` text COLLATE utf8_unicode_ci NOT NULL COMMENT 'A condensed version of the content. If left blank, the excerpt will automatically be created for you.', `keywords` varchar(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT '' COMMENT '15 keywords generated from the content.', `featured` enum('yes','no') COLLATE utf8_unicode_ci NOT NULL DEFAULT 'no' COMMENT 'Yes, if you want this article featured on the home page.', `featured_image` varchar(510) COLLATE utf8_unicode_ci NOT NULL DEFAULT '' COMMENT 'Featured image must be landscape orientation, such as 1024 x 768.', `featured_caption` varchar(2550) COLLATE utf8_unicode_ci NOT NULL DEFAULT '' COMMENT 'Caption for the featured image.', `post_date` datetime NOT NULL DEFAULT '0000-00-00 00:00:00' COMMENT 'If left blank, the date will default to today.', `date_added` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', `last_modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `published` enum('yes','no') COLLATE utf8_unicode_ci NOT NULL DEFAULT 'yes' COMMENT 'Yes, if you want this article on the website.', PRIMARY KEY (`id`), UNIQUE KEY `permalink` (`slug`), FULLTEXT KEY `keywords` (`keywords`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
$fields['featured_image'] = array('type' => 'file', 'ignore_representative' => TRUE, 'display_preview' => TRUE, 'display_input' => TRUE, 'file_name' => '{new_file_name}', 'folder' => 'images/articles/', 'overwrite' => TRUE, 'display_overwrite' => TRUE, 'multiple' => FALSE, 'order' => 9); // $fields['featured_image_upload'] = array('type' => 'file', 'file_name' => '{new_file_name}', 'folder' => 'images/articles/', 'overwrite' => TRUE, 'display_overwrite' => TRUE, 'multiple' => FALSE, 'order' => 9);