jfox015 / Bonfire-News

Create, manage and publish news articles for the Bonfire Admin Library
15 stars 7 forks source link

hacking installation... #24

Closed TurtleWolfe closed 10 years ago

TurtleWolfe commented 10 years ago

ok, I'm getting it to work now I thought I tried that one first... I'm still hacking the installation. I'll post what I'm doing differently to make it work, but following your wiki I'm posting public function index() { $this->load->library('installer_lib');

    if (!$this->installer_lib->is_installed())
    {
        redirect( site_url('install') );
    }

    $this->load->library('users/auth');
    $this->set_current_user();

$count = 7; $startIndex = 0; $data['articles'] = modules::run('news/get_article_list',$count,$startIndex); Template::set('news_list',$this->load->view('news/news_list',$data, true)); Template::render(); }//end index() into the home controller, but getting the following 2 errors. at line 168 it looks like it's looking for the users ID, but if they are not signed in, there is nothing to return as the object... this is probably effecting the session variable as well. But I'm getting the same errors even if I'm still signed in... I'll post my hack in a few, probably just copy what worked last time, but trying to find the differences along the way, to help installation in the future and make sure it's all correct and smooth.

A PHP Error was encountered

Severity: Notice

Message: Trying to get property of non-object

Filename: controllers/news.php

Line Number: 168

A PHP Error was encountered

Severity: Warning

Message: Cannot modify header information - headers already sent by (output started at /hermes/waloraweb035/b1597/moo.turtlewolf/ace/bonfire/core/Loader.php:659)

Filename: libraries/Session.php

Line Number: 675

TurtleWolfe commented 10 years ago

ok, I'll try to follow your local work around next time... just for reference, I'm not using "git", I'm unzipping them to my server and copying the directory structure as closely as I can guess... some things like css and themes I assume it will find it if it can, but I'm still not sure I'm loading the css, but I finally like the way the 2 column filled in this time. but I'm copying most of the controller into the home.php and it feels like i'm breaking "best practices" at least for this template. and then copying helpers, models and css to the first place it can see them...

In retrospect, I may try to take out these 2 lines around 68 & 69 and see if it still works, but I hate to tamper with an installation that's looking so good right now... , $this->load->model('news_model'); $this->lang->load('news');

class Home extends CI_Controller { public function construct() { parent::construct();

    $this->load->helper('application');
    $this->load->library('Template');
    $this->load->library('Assets');
    $this->lang->load('application');
    $this->load->library('events');

    // Make the requested page var available, since
    // we're not extending from a Bonfire controller
    // and it's not done for us.
    $this->requested_page = isset($_SESSION['requested_page']) ? $_SESSION['requested_page'] : null;
}

//--------------------------------------------------------------------

/**
 * Displays the homepage of the Bonfire app
 *
 * @return void
 */
public function index()
{
    $this->load->library('installer_lib');

    if (!$this->installer_lib->is_installed())
    {
        redirect( site_url('install') );
    }

    $this->load->library('users/auth');
    $this->set_current_user();

    $this->load->model('news_model');
    $this->lang->load('news');

    $this->_settings = $this->settings_model->select('name,value')->find_all_by('module', 'news');

    $articles = $this->get_articles($this->_settings['news.default_article_count']);
    Template::set('articles', $articles);
    Template::set('settings', $this->_settings);
    Template::set('single', false);

    Template::render();
}//end index()

//--------------------------------------------------------------------

/**
 * If the Auth lib is loaded, it will set the current user, since users
 * will never be needed if the Auth library is not loaded. By not requiring
 * this to be executed and loaded for every command, we can speed up calls
 * that don't need users at all, or rely on a different type of auth, like
 * an API or cronjob.
 *
 * Copied from Base_Controller
 */
protected function set_current_user()
{
    if (class_exists('Auth'))
    {
        // Load our current logged in user for convenience
        if ($this->auth->is_logged_in())
        {
            $this->current_user = clone $this->auth->user();

            $this->current_user->user_img = gravatar_link($this->current_user->email, 22, $this->current_user->email, "{$this->current_user->email} Profile");

            // if the user has a language setting then use it
            if (isset($this->current_user->language))
            {
                $this->config->set_item('language', $this->current_user->language);
            }
        }
        else
        {
            $this->current_user = null;
        }

        // Make the current user available in the views
        if (!class_exists('Template'))
        {
            $this->load->library('Template');
        }
        Template::set('current_user', $this->current_user);
    }
}

//--------------------------------------------------------------------

/**
 *  add_news.
 *
 *  Displays a default list of news articles. The nbumber of articles displayed is managed via
 *  the news.default_article_count setting.
 *
 *  @return                 <void>  This function outputs to the Template::render() function
 *
 */
public function add_news()
{
    $settings = $this->_settings;

    if ($this->input->post('submit'))
    {
        $this->load->module('news/content'); 

        $uploadData = array();
        $upload = true;
        if (isset($_FILES['attachment']) && is_array($_FILES['attachment']) && $_FILES['attachment']['error'] != 4)
        {
            $uploadData = $this->content->handle_upload( );
            if (isset($uploadData['error']) && !empty($uploadData['error']))
            {
                $upload = false;
            }
        }
        if ((count($uploadData) > 0 && $upload) || (count($uploadData) == 0 && $upload))
        {
            if ($id = $this->content->save_article($uploadData))
            {
                $article = $this->news_model->find($id);

                $this->load->model('activities/activity_model');
                $this->activity_model->log_activity($this->current_user->id, 'Created Article: '. $article->id, 'news');

                Template::set_message('Article successfully submitted. It will be reviewed by the news moderator.', 'success');
                Template::set_view('index');
                Template::render();
            }
            else
            {
                Template::set_message('There was a problem creating the article: '. $this->news_model->error);
            }
        }
        else
        {
            Template::set_message('There was a problem saving the file attachment: '. $uploadData['error']);
        }
    }

    if ($settings['news.public_submissions'] == 1) 
    {
        $showForm = true;

        if ($settings['news.public_submitters'] == 1) 
        {
            $cookie = unserialize($this->input->cookie($this->config->item('sess_cookie_name')));
            $showForm = isset ($cookie['logged_in']);
            $error = 'You must be <a href="'.site_url('/login/').'">logged in</a> to post news to this site.';
            unset ($cookie);
        }
        if ($showForm) 
        {
            $this->load->helper('form');
            Assets::add_css( array(
                Template::theme_url('js/editors/markitup/skins/markitup/style.css'),
                Template::theme_url('js/editors/markitup/sets/default/style.css'),
                css_path() . 'chosen.css',
                css_path() . 'bootstrap-datepicker.css'

            ));

            Assets::add_js( array(
                Template::theme_url('js/editors/markitup/jquery.markitup.js'),
                Template::theme_url('js/editors/markitup/sets/default/set.js'),
                js_path() . 'chosen.jquery.min.js',
                js_path() . 'bootstrap-datepicker.js'
            ));
            Template::set('public', true);
            Template::set('settings', $settings);
            Template::set('toolbar_title', lang('us_create_news'));
            Template::set_view('content/news_form');
            Template::render();
        } 
        else 
        {
            show_error($error,501,'Form Access Error');
        }
    } 
    else 
    {
        show_error('<h2>Sorry</h2><br />Public news submissions are not currently available.<br /><a href="'.site_url().'">Return to the site</a>.',501,'Public News Submission not available');
    }
}
//--------------------------------------------------------------------

/**
 *  get_article_list.
 *
 *  This function assembles a few variables and then queries the database for a list 
 *  of articles. 
 *
 *  @param  $limit  int     Max number of articles to return. Default is -1 (no limit)
 *  @param  $offset int     Index of the first item to return
 *  @return         array   Array of article objects
 *
 */
public function get_article_list($limit=-1, $offset=0)
    {

        Assets::add_module_css('news','assets/css/news.css');

        $this->load->model('activities/Activity_model', 'activity_model', true);

        if ($limit != -1 && $offset == 0)
        {
            $this->db->limit($limit);
        } else if ($limit != -1 && $offset > 0) {
            $this->db->limit($limit, $offset);
        }

        $this->db->order_by('date', 'desc');
        $articles = $this->news_model->find_all_by('status_id',3);

        if (!is_array($articles) || !count($articles))
        {
            $this->activity_model->log_activity($this->current_user->id, 'Get Articles: failed. No articles were found.', 'news');
        }

        return $articles;
}

//--------------------------------------------------------------------

/**
 *  get_articles.
 *
 *  A function that returns a HTML block of published article content. This function runs each 
 *  article returned through the load view and applies the article content against the article
 *  view template. 
 *
 *  @param  $limit  int     Max number of articles to return. Default is -1 (no limit)
 *  @param  $offset int     Index of the first item to return
 *  @return         varchar Formatted HTML article blocks
 *
 */
public function get_articles($limit=-1, $offset=0)
{

    Assets::add_module_css('news','news.css');

    $this->load->model('activities/Activity_model', 'activity_model', true);

    $output = '';
    $articles = $this->news_model->get_articles(true,$limit,$offset);

    if (is_array($articles) && count($articles))
    {
        $settings = $this->_settings;
        $this->load->helper('author');

        foreach ($articles as $article)
        {
            $article->asset_url = $settings['news.upload_dir_url'];
            $article->author_name = find_author_name($article->author);
            // COMMENTS
            $comment_count = (in_array('comments',module_list(true)) && $settings['news.comments_enabled'] == 1) ? modules::run('comments/count_comments',$article->comments_thread_id) : 0;
            $output .= $this->load->view('news/articlone',array('comment_count' => $comment_count, 'article'=>$article,'settings'=>$settings,'single'=>false),true);
        }
    } else {
        $output = 'No Articles found.';
        $this->activity_model->log_activity($this->current_user->id, 'Get Articles: failed. No article were found.', 'news');
    }
    return $output;
}

//--------------------------------------------------------------------

/**
 *  article.
 *
 *  A function that renders an article using the news article template via the Bonire Template::render() function. 
 *  Unlike get_articles, this function also includes the News social sharing bar if that options is enabled.
 *
 *  @param  $article_id     int     The News article ID
 *  @return                 <void>  This function outputs to the Template::render() function
 *
 */
public function article($article_id = false)
{

    if ($article_id === false)
    {
        return false;
    }

    $settings = $this->_settings;
    Assets::add_module_css('news','news.css');

    if ( ($article = $this->news_model->get_article($article_id)) !== false)
    {
        $this->load->helper('author');
        $article->author_name = find_author_name($article->author);
        $article->asset_url = $settings['news.upload_dir_url'];
        Template::set('article',$article);
        if ( isset ($settings['news.sharing_enabled']) && $settings['news.sharing_enabled'] == 1) {
            Template::set('settings',$settings);
            Template::set('single',true);
            Template::set('scripts',$this->load->view('news/news_articles_js',null,true));
        }
        // COMMENTS
        $comments = (in_array('comments',module_list(true)) && $settings['news.comments_enabled'] ==1) ? modules::run('comments/thread_view_with_form',$article->comments_thread_id) : '';
        Template::set('comment_form', $comments);

    } else {
        $this->activity_model->log_activity($this->current_user->id, 'Get Article: '. $article_id .' failed. no article found.', 'news');
    }

    Template::set_view('news/article');
    Template::render();
}

//--------------------------------------------------------------------

}//end class

jfox015 commented 10 years ago

What I did fro my Fox Open Sports Platform site was make my own home controller and use a custom theme. But what you did should work.