~costales/simplenewscodeigniter/trunk

« back to all changes in this revision

Viewing changes to application/libraries/Simplenews.php

  • Committer: costales
  • Date: 2012-12-11 19:30:50 UTC
  • Revision ID: costales.marcos@gmail.com-20121211193050-pmj7ezgnhwl2s86j
Added author & date

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
    private $CI;
13
13
    private $url_path = '';
14
14
    // For database
15
 
    private $table       = 'news';
16
 
    private $title_field = 'title';
17
 
    private $url_field   = 'url';
18
 
    private $body_field  = 'body';
19
 
    private $tags_field  = 'tags';
 
15
    private $table        = 'news';
 
16
    private $title_field  = 'title';
 
17
    private $url_field    = 'url';
 
18
    private $body_field   = 'body';
 
19
    private $author_field = 'author';
 
20
    private $date_field   = 'date';
 
21
    private $tags_field   = 'tags';
20
22
    // For template
21
23
    private $open            = '';
22
24
    private $close           = '';
29
31
    private $tag_end         = '';
30
32
    private $all_tags_end    = '';
31
33
    private $set_title_links = '';
 
34
    private $date_template   = 'Y-m-d H:i:s';
32
35
    
33
36
    public function __construct() {
34
37
        $this->CI =& get_instance();
41
44
     * @param  string
42
45
     * @return bool
43
46
     */
44
 
    function add($title = '', $body = '', $tags = '') {
 
47
    function add($title = '', $body = '', $author = '', $tags = '') {
45
48
        // Check data
46
49
        if ($title == '' || $body == '')
47
50
            return FALSE;
52
55
            return FALSE;
53
56
        
54
57
        // Create news into database
55
 
        $data = array($this->title_field=>$title, $this->url_field=>url_title($title), $this->body_field=>$body, $this->tags_field=>$tags);
 
58
        $just_now = time();
 
59
        $data = array($this->title_field=>$title,
 
60
                       $this->url_field=>url_title($title),
 
61
                       $this->body_field=>$body,
 
62
                       $this->author_field=>$author,
 
63
                       $this->tags_field=>$tags);
 
64
        $this->CI->db->set($this->date_field, 'NOW()', FALSE); //No escape date for Active Record
56
65
        if (!$this->CI->db->insert($this->table, $data))
57
66
            return FALSE;
58
67
 
120
129
                echo ($this->set_title_links == TRUE ? '<a href="'.$this->url_path.url_title($row->title).'">' : '');
121
130
                echo $this->title_start.$row->title.$this->title_end;
122
131
                echo ($this->set_title_links == TRUE ? '</a>' : '');
 
132
                echo $this->author_start.$row->author.$this->author_end;
 
133
                echo $this->date_start.date($this->date_template, strtotime($row->date)).$this->date_end;
123
134
                echo $this->body_start.$row->body.$this->body_end;
124
135
                if ($show_tags) {
125
136
                    echo $this->all_tags_start;
150
161
            echo $this->open;
151
162
            foreach ($query->result() as $row) {
152
163
                echo $this->title_start.$row->title.$this->title_end;
 
164
                echo $this->author_start.$row->author.$this->author_end;
 
165
                echo $this->date_start.date($this->date_template, strtotime($row->date)).$this->date_end;
153
166
                echo $this->body_start.$row->body.$this->body_end;
154
167
                if ($show_tags) {
155
168
                    echo $this->all_tags_start;
184
197
        $this->body_start = (array_key_exists('body_start', $template) ? $template['body_start'] : '');
185
198
        $this->body_end   = (array_key_exists('body_end',   $template) ? $template['body_end']   : '');
186
199
 
 
200
        $this->author_start = (array_key_exists('author_start', $template) ? $template['author_start'] : '');
 
201
        $this->author_end   = (array_key_exists('author_end',   $template) ? $template['author_end']   : '');
 
202
 
 
203
        $this->date_start = (array_key_exists('date_start', $template) ? $template['date_start'] : '');
 
204
        $this->date_end   = (array_key_exists('date_end',   $template) ? $template['date_end']   : '');
 
205
 
187
206
        $this->all_tags_start = (array_key_exists('all_tags_start', $template) ? $template['all_tags_start'] : '');
188
207
        $this->tag_start      = (array_key_exists('tag_start',      $template) ? $template['tag_start']      : '');
189
208
        $this->tag_end        = (array_key_exists('tag_end',        $template) ? $template['tag_end']        : '');
190
209
        $this->all_tags_end   = (array_key_exists('all_tags_end',   $template) ? $template['all_tags_end']   : '');
191
210
 
192
211
        $this->set_title_links = (array_key_exists('set_title_links', $template) ? $template['set_title_links'] : FALSE);
 
212
        $this->date_template   = (array_key_exists('date_template',   $template) ? $template['date_template']   : 'Y-m-d H:i:s');
193
213
    }
194
214
    
195
215
    /* 
203
223
        $this->title_end       = '';
204
224
        $this->body_start      = '';
205
225
        $this->body_end        = '';
 
226
        $this->author_start    = '';
 
227
        $this->author_end      = '';
 
228
        $this->date_start      = '';
 
229
        $this->date_end        = '';
206
230
        $this->all_tags_start  = '';
207
231
        $this->tag_start       = '';
208
232
        $this->tag_end         = '';
209
233
        $this->all_tags_end    = '';
210
 
        $this->set_title_links = '';
 
234
        $this->set_title_links = FALSE;
 
235
        $this->date_template   = 'Y-m-d H:i:s';
211
236
    }
212
237
    
213
238
    /*