A couple of items and only the first one is a bug or at least seems to be.
Two things happen in the asset upload area.
1. The index.html file which I think is to not allow direct access to the folder is showing up in the list of assets which means a client can delete it and thus expose the directory.
2. If you delete all the files in a asset directory including the index.html the directory is deleted as well.
As for the non bug items, I am preparing to build a site with Fuel and there are a few features I am needing pointers on. I would know how to do these in a plain CodeIgniter install but am struggling with the best approach with Fuel.
1. I have a set of pages on the front end of the site that I need to secure with a username a password. I may need an admin feature for administering these accounts as well.
2. I need a text search of the site for both secure and non secure pages.
Both of these sound like modules to me is that correct? Also, would you recommend a simple of advanced modules? Do I need to write my own controllers for these?
Also, the client is planning on uploading media such mp3s and video. I tested Fuel's upload capability on my test site and it seems to be fine, it uploaded a 75MB file just fine but it did look like it was just sitting there. I was wondering is Fuel's upload ability dependent on the servers php settings? Also, I was wondering if you have used anything like
http://www.uploadify.com/ with file uploading in Fuel before? If so any pointers on how to best implement something like that?
Thank you in advance for any assistance you can provide.
Comments
2. The deletion of the folder was put in place to cleanup empty directories when assets are deleted. Is this causing issues on your end?
With regards to your questions, I would maybe suggest doing it how you know best using CodeIgniter first and extracting your database functionality into FUEL models that you could leverage as modules later on. For example, you could create your accounts_model.php and get that working with your controllers and views on the front end like you would normally in CI, then you could create a simple module based on that model which can be administered in the FUEL admin. You could also, import those view files as pages if you wanted to make them editable later on. Does that make sense?
With regards to the text search, this may be a bit trickier depending on how you are indexing the pages for searching (we've been looking into creating a good module for this too). If the administration functionality needed to manage the search isn't based on single model (table) and requires it's own form options, then that would probably need to be it's own module with views, controllers, etc.
I tend to use "advanced" modules when a specific controller is needed or multiple models are needed for administering the backend (e.g. blog) and "simple" modules when it is more table focused.
With regards to file uploading, FUEL is limited by server settings as well as $config['assets_upload_max_size'] option you can set in the FUEL configuration.(http://www.getfuelcms.com/user_guide/general/configuration). We actually haven't looked at uploadify.com (looks interesting), however, we do have on the list, ways to better support multiple file uploads, in particular, when you can select multiple files at once from the file upload window (Safari let's you do this). The $_FILES array for that is slightly different and FUEL currently doesn't properly upload files like that.
Let me know if this helps.
$this->load->module_library(FUEL_FOLDER, 'fuel_page'); $config = array(); $config['location'] = uri_path(); $config['render_mode'] = 'auto'; $this->fuel_page->initialize($config); $this->fuel_page->render();
https://github.com/daylightstudio/FUEL-CMS/tree/demo
Another method may be to periodically build a search index. You can grab a list of the pages (there is a method on the pages_model to do this), and use curl to parse the page contents. You could perhaps put in some sort of comment or markup trigger in the HTML to identify a part you want searchable so it doesn't index the whole page.
We've actually thought about implementing a site search module, but haven't had the time to really flesh it out. So I'd be interested how things work out.
$this->load->module_model(FUEL_FOLDER, 'pagevariables_model');
but when I would use the object I was getting db errors. I added this to the model constructor after line 10 and that seems to have fixed the issue.
$CI->config->module_load(FUEL_FOLDER, 'fuel', TRUE);
does that make sense and seem right?
$this->load->module_model(FUEL_FOLDER, 'pagevariables_model'); $pages = $this->pagevariables_model->find_all_by_location('home');
Produces:
A Database Error Occurred
Error Number: 1064
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '.`page_id` WHERE `.`location` = 'home'' at line 3
SELECT `pagevariables_model`.* FROM (`pagevariables_model`) LEFT JOIN ` ON `.`id` = .`page_id` WHERE `.`location` = 'home'
Filename: core/MY_Model.php
Line Number: 260
<?php if (!defined('BASEPATH')) exit('No direct script access allowed'); class Search_model extends MY_Model { private $_tables; function __construct() { $CI =& get_instance(); $CI->config->module_load(FUEL_FOLDER, 'fuel', TRUE); $this->_tables = $CI->config->item('tables', 'fuel'); $CI->config->module_load('blog', 'blog'); $this->_tables = array_merge($this->_tables, $CI->config->item('tables')); parent::__construct(); } function search($keywords = '') { $keywords = ($keywords != '') ? '%' . $this->db->escape_str($keywords) . '%' : '%'; // search blog posts $select_params_a = array(); $select_params_a[] = $this->_tables['blog_posts'] . ".permalink AS permalink"; $select_params_a[] = $this->_tables['blog_posts'] . ".title AS title"; $select_params_a[] = "'' AS page_id"; $select_params_a[] = "'' AS location"; $select_params_a[] = $this->_tables['blog_posts'] . ".date_added AS sort_date"; $from_params_a = array(); $from_params_a[] = $this->_tables['blog_posts']; $where_params_a = array(); $where_params_a[] = $this->_tables['blog_posts'] . ".title LIKE '" . $keywords . "'"; $where_params_a[] = $this->_tables['blog_posts'] . ".content LIKE '" . $keywords . "'"; $where_params_a[] = $this->_tables['blog_posts'] . ".content_filtered LIKE '" . $keywords . "'"; $sql_a = "SELECT " . implode(', ', $select_params_a) . " FROM " . implode(', ', $from_params_a) . " WHERE (" . $this->_tables['blog_posts'] . ".published = 'yes') AND (" . implode(' OR ', $where_params_a) . ")"; // search page variables $select_params_b = array(); $select_params_b[] = "'' AS permalink"; $select_params_b[] = "'' AS title"; $select_params_b[] = $this->_tables['pagevars'] . ".page_id AS page_id"; $select_params_b[] = $this->_tables['pages'] . ".location AS location"; $select_params_b[] = $this->_tables['pages'] . ".last_modified AS sort_date"; $from_params_b = array(); $from_params_b[] = $this->_tables['pages']; $from_params_b[] = $this->_tables['pagevars']; $where_params_b = array(); $where_params_b[] = $this->_tables['pages'] . ".id = " . $this->_tables['pagevars'] . ".page_id"; $where_params_b[] = $this->_tables['pages'] . ".published = 'yes'"; $where_params_b[] = $this->_tables['pages'] . ".location != 'sitemap.xml'"; $where_params_b[] = $this->_tables['pages'] . ".location != 'search'"; $where_params_b[] = $this->_tables['pagevars'] . ".active = 'yes'"; $where_params_b[] = $this->_tables['pagevars'] . ".name != 'copy'"; $where_params_b[] = $this->_tables['pagevars'] . ".name != 'section_header'"; $where_params_b[] = $this->_tables['pagevars'] . ".value LIKE '" . $keywords . "'"; $sql_b = "SELECT " . implode(', ', $select_params_b) . " FROM " . implode(', ', $from_params_b) . " WHERE " . implode(' AND ', $where_params_b) . " GROUP BY page_id"; // union queries $sql = "(" . $sql_a . ") UNION (" . $sql_b . ") ORDER BY sort_date desc"; $query = $this->db->query($sql); <?php class Search extends CI_Controller { function __construct() { parent::__construct(); } function _remap() { $this->load->helper('inflector'); $this->load->model('search_model'); $this->load->module_library(FUEL_FOLDER, 'fuel_page'); $keywords = ($this->input->post('keywords') == FALSE) ? '' : $this->input->post('keywords'); $results = $this->search_model->search($keywords); $search_results = array(); foreach ($results as $result) { if ($result['permalink'] != '') { $year = date('Y', strtotime($result['sort_date'])); $month = date('m', strtotime($result['sort_date'])); $day = date('d', strtotime($result['sort_date'])); $url = 'news/' . $year . '/' . $month . '/' . $day . '/' . $result['permalink']; $search_results[] = '<li>' . anchor($url, $result['title']) . '</li>'; } else { $search_results[] = '<li>' . anchor($result['location'], humanize(str_replace("/", " - ", $result['location']))) . '</li>'; } } if (!empty($search_results)) { $variable = array('section_interactive' => '<ol>' . implode('', $search_results) . '</ol>'); } else { $variable = array('section_interactive' => '<em>No results were found using the keywords you entered, please try again.</em>'); } $this->fuel_page->add_variables($variable); $config = array(); $config['location'] = uri_path(); $config['render_mode'] = 'auto'; $this->fuel_page->initialize($config); $this->fuel_page->render(); } }
With regards to the blog posts showing up in the sitemap.xml, try adding this to the file:
/*************************************************************** Add any dynamic pages and associate them to the $nav array here: **************************************************************/ $CI->load->module_library(BLOG_FOLDER, 'fuel_blog'); $posts = $CI->fuel_blog->get_posts(); // add project pages foreach($posts as $post) { $key = 'blog/'.$post->get_url(FALSE); $nav[$key] = array('location' => $key); }
I tried to use the code example of thisisflashpoint:
$this->load->module_library(FUEL_FOLDER, 'fuel_page'); $config = array(); $config['location'] = uri_path(); $config['render_mode'] = 'auto'; $this->fuel_page->initialize($config); $this->fuel_page->render();
I also tried to route the location to the right position like: $route['activities/(:any)'] = "activities/subpage"; but this is also not working.
I know its mapping to the subpage method because I can echo text. But it's not showing my template and text from the CMS.
Maby it's a simple thing. But I'm not seeing it.
1. What do you mean by it "crashes"?
2. What is uri_path() echoing out (e.g. 'activities/activity')?
2. What is your controller's name and what is the methods on it that you are trying to use (e.g. controller name is 'activities' and a method name of 'activity')?
My controller name is Activities. So when I visit www.site.com/activities then it loading the index(). the problem was that the uri segments were coming from the CMS. So when you visit www.site.com/activities/contact you need to have the method contact() in de activities controller. But because it's dynamic this is not possible.
But I found the solution. Now I use _remap() as a method in the activities controller. And that's working great!
I modified the model from 'thisisflashpoint' to suit my needs (no blog, individual terms), maybe helps someone else..
function search($keywords) { # Key words $keywords = explode(' ', $keywords); # Short cuts $pages = $this->_tables['pages']; $page_vars = $this->_tables['pagevars']; # Select $select = array( $page_vars.'.page_id AS page_id', $pages.'.location AS location', $pages.'.last_modified AS sort_date', 'fpv.value AS title', 'fpv1.value AS body' ); # From $from = array($pages, $page_vars); # Where $where = array( $pages.'.id = '.$page_vars.'.page_id', $pages.'.published = "yes"', $pages.'.location != "sitemap.xml"', $pages.'.location != "search"', $page_vars.'.active = "yes"', $page_vars.'.name != "copy"', $page_vars.'.name = "body"' ); # Build like $str = '('; foreach ($keywords as $keyword) { $str .= $page_vars.'.value LIKE "%'.$this->db->escape_str($keyword).'%" OR '; } # Remove last OR $where[] = substr($str, 0, -4).')'; $sql = "SELECT ".implode(', ', $select). " FROM ".implode(', ', $from). " JOIN ".$page_vars." fpv ON (fpv.page_id = ".$page_vars.".page_id AND fpv.name = 'h1')". " JOIN ".$page_vars." fpv1 ON (fpv1.page_id = ".$page_vars.".page_id AND fpv1.name = 'body')". " WHERE ".implode(' AND ', $where); return $this->db->query($sql)->result_array(); }
Outputs a query like
SELECT fuel_page_variables.page_id AS page_id , fuel_pages.location AS location , fuel_pages.last_modified AS sort_date , fpv.value AS title , fpv1.value AS body FROM fuel_pages , fuel_page_variables JOIN fuel_page_variables fpv ON ( fpv.page_id = fuel_page_variables.page_id AND fpv.name = 'h1' ) JOIN fuel_page_variables fpv1 ON ( fpv1.page_id = fuel_page_variables.page_id AND fpv1.name = 'body' ) WHERE fuel_pages.id = fuel_page_variables.page_id AND fuel_pages.published = "yes" AND fuel_pages.location != "sitemap.xml" AND fuel_pages.location != "search" AND fuel_page_variables.active = "yes" AND fuel_page_variables.name != "copy" AND fuel_page_variables.name = "body" AND ( fuel_page_variables.value LIKE "%the%" OR fuel_page_variables.value LIKE "%and%" )
Heh, that's some sweet indenting..