Welcome Guest, Not a member yet? Register   Sign In
Why HTMLPurifier does not work in inktype
#1

[eluser]Déjà Vu[/eluser]
I am trying to add, HTMLPurifier to blog controller from inktype

Code:
if ($this->validation->run()) {

            $this->mdl_comments->urltitle = $this->urltitle;
            $this->mdl_comments->author = $this->input->post('author');
            $this->mdl_comments->emailaddress = $this->input->post('emailaddress');
            $this->mdl_comments->url = $this->input->post('url');

            $this->load->library('HTMLPurifier');
            $purifier_config = HTMLPurifier_Config::createDefault();
            $this->htmlpurifier->purify($comment, $purifier_config);
            
            $this->mdl_comments->comment = $this->input->post('comment');
            $this->mdl_comments->save();

        }

But every time the page loads HTMLPurifier library, the page does not show anything, and I cannot add simple text to the comments form

How can I add HTMLPurifier support to the blog controller in inktype?

Thanks in advance
#2

[eluser]Ambush Commander[/eluser]
It looks like there might be some fatal error that's stopping HTML Purifier. What happens when you turn error reporting on?
#3

[eluser]Developer13[/eluser]
Yes, I would definitely start with changing error reporting to E_ALL in your index.php file.

Also, keep in mind that the copy of InkType you have is an alpha - so what you're doing is most likely going to be built into a future revision, but I'm glad to see that somebody is tinkering with it!

I'm not sure exactly what HTMLPurifier does or how it works, but if you haven't figured this out by the time I get home tonight, I'll take a look at it and let you know why it's not working.
#4

[eluser]Déjà Vu[/eluser]
Now I set E_ALL at index.php and get this error.

Parse error: syntax error, unexpected T_STATIC, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /home/cienciasm/domains/cienciasmicrobiologicas.org/public_html/system/application/libraries/HTMLPurifier.php on line 216

And Thankyou so much D13, you do a great work for inktype, I really learn so much about CI coding.
#5

[eluser]Ambush Commander[/eluser]
Ah, you're running PHP4 but you're using the PHP5 version of HTML Purifier. Either download the regular version (not E_STRICT version) or get your host to upgrade (PHP4 is being deprecated at the end of this year!)
#6

[eluser]Déjà Vu[/eluser]
Ok, I change the version for PHP4

And see that the previous code does not work, so I decided to do the purify process to the model for get comments (mdl_comments.php)

Code:
function get() {

            $this->load->library('HTMLPurifier');
            $purifier_config = HTMLPurifier_Config::createDefault();
            $purifier_config->set('Core', 'Encoding', 'UTF-8'); // replace with your encoding
            $this->htmlpurifier->purify( $comment , $purifier_config );
            $comment = $clean_comment

But now I get this error

Code:
Parse error: syntax error, unexpected T_VARIABLE in /home/cienciasm/domains/cienciasmicrobiologicas.org/public_html/application/models/mdl_comments.php on line 38

At that line the code is:
Code:
$this->_prep_query();
        $query = $this->db->get("comments");

Why doesn`t works?
Please help me
#7

[eluser]Developer13[/eluser]
Post the entire mdl_comments->get() function. The obvious thing in your example is that $comment = $clean_comment does not have a semicolon at the end of the line, but that's probably just a typo in your example...
#8

[eluser]Déjà Vu[/eluser]
Here is the whole model

Code:
<?

class mdl_comments extends Model {

    var $commentid;
    var $postid;
    var $date;
    var $author;
    var $comment;
    var $emailaddress;
    var $url;
    var $urltitle;

    var $page;
    var $limit;
    var $numpages;
    var $paginate;



    function mdl_comments() {
        parent::Model();
        $this->limit = 20;
    }

    function get() {

            $this->load->library('HTMLPurifier');
            $purifier_config = HTMLPurifier_Config::createDefault();
            $purifier_config->set('Core', 'Encoding', 'UTF-8'); // replace with your encoding
            $clean_comment = $this->htmlpurifier->purify($comment ,$purifier_config);
            $comment = $clean_comment;

        
        // before we set a limit / offset, we should grab all results within defined range of records to form number of pages, etc
        $this->_prep_query();
        $query = $this->db->get("comments");
        $this->numpages = ceil($query->num_rows / $this->limit);

        // if a postid does not exist, then we will set the offset and limit for the query
        if ($this->paginate == true) {
            $offset = ($this->page * $this->limit) - $this->limit;
            $this->db->limit($this->limit, $offset);
        }

        $this->_prep_query();

        $query = $this->db->get("comments");

        if ($this->commentid) {
            return ($query->row());
        }

        else {
            return ($query->result());
        }

    }

    function save() {

        $this->_getPostID();

        $dbArray = array(
        "author"        =>    $this->author,
        "emailaddress"    =>    $this->emailaddress,
        "url"            =>    $this->url,
        "comment"        =>    $this->comment);

        if ($this->commentid) {
            $this->db->where("commentid", $this->commentid);
            $this->db->update("comments", $dbArray);

        }

        else {

            $dbArray["date"] = time();
            $dbArray["postid"] = $this->postid;
            $this->db->insert("comments", $dbArray);

        }

    }

    function delete() {

        $this->db->where("commentid", $this->commentid);

        $this->db->delete("comments");

    }

    function _getPostID() {

        $this->db->select("postid");
        $this->db->where("urltitle", $this->urltitle);
        $query = $this->db->get("posts");
        $result = $query->row();
        $this->postid = $result->postid;

    }

    function _prep_query() {

        if ($this->urltitle) {
            $this->db->where("urltitle", $this->urltitle);
        }

        $this->db->select("
        comments.commentid,
        FROM_UNIXTIME(comments.date, '%m/%d/%Y at %h:%i %p') AS date,
        comments.author,
        comments.emailaddress,
        comments.url,
        comments.comment,
        posts.urltitle,
        posts.title");

        $this->db->join("posts", "posts.postid = comments.postid");

        $this->db->orderby("date DESC");

    }

}

?>

After correct the typo I get this error

Quote:A PHP Error was encountered

Severity: Notice

Message: Undefined variable: comment

Filename: models/mdl_comments.php

Line Number: 31

And that line is:
Code:
$clean_comment = $this->htmlpurifier->purify($comment ,$purifier_config);
#9

[eluser]Developer13[/eluser]
Okay - I think I'm a little confused here with what you're actually trying to do.

Are you trying to:

A) Purify the comments that are being saved into the system?
B) Purify the results of the select query

If the answer is "A", your code should be in the save() function and not the get() function.

If the answer is "B", then you'll have to loop through the results after they have been retrieved by the get() function.

It's giving you that error because at the time you use that line of code, $comment has not been declared or defined.




Theme © iAndrew 2016 - Forum software by © MyBB