<commit_before><?php
/**
* $Id: Comment.php,v 1.1 2006-07-23 16:40:54 matteo Exp $
*
* The main Comment class
*
* @author       <NAME> <<EMAIL>>
* @package      phpMyFAQ
* @since        2006-07-23
* @copyright    (c) 2006 phpMyFAQ Team
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*/

// {{{ Constants
/**#@+
  * Comment type
  */
define('PMF_COMMENT_TYPE_FAQ', 'faq');
define('PMF_COMMENT_TYPE_NEWS', 'news');
/**#@-*/
// }}}

// {{{ Classes
class PMF_Comment
{
    /**
    * DB handle
    *
    * @var  object
    */
    var $db;

    /**
    * Language
    *
    * @var  string
    */
    var $language;

    /**
    * Language strings
    *
    * @var  string
    */
    var $pmf_lang;

    /**
    * Constructor
    *
    */
    function PMF_Comment(&$db, $language)
    {
        global $PMF_LANG;

        $this->db = &$db;
        $this->language = $language;
        $this->pmf_lang = $PMF_LANG;
    }

    //
    //
    // PUBLIC METHODS
    //
    //

    /**
    * getCommentDataById()
    *
    * Returns a user comment
    *
    * @param    integer     comment id
    * @return   string
    * @access   public
    * @since    2006-07-13
    * @author   <NAME> <<EMAIL>>
    * @author   <NAME> <<EMAIL>>
    */
    function getCommentDataById($id)
    {
        $item = array();

        $query = sprintf(
                    "SELECT
                        id_comment, id, type, usr, email, comment, datum
                    FROM
                        %sfaqcomments
                    WHERE
                        id_comment = %d",
                    SQLPREFIX,
                    $id
                );

        $output = '';
        $result = $this->db->query($query);
        if (($this->db->num_rows($result) > 0) && ($row = $this->db->fetch_object($result))) {
            $item = array(
                    'id'        => $row->id_comment,
                    'recordId'  => $row->id,
                    'type'      => $row->type,
                    'content'   => $row->comment,
                    'date'      => $row->datum,
                    'user'      => $row->usr,
                    'email'     => $row->email
                    );
        }

        return $item;
    }

    /**
    * getCommentsData()
    *
    * Returns all user comments from a record by type
    *
    * @param    integer     record id
    * @param    integer     record type: {faq|news}
    * @return   string
    * @access   public
    * @since    2002-08-29
    * @author   <NAME> <<EMAIL>>
    * @author   <NAME> <<EMAIL>>
    */
    function getCommentsData($id, $type)
    {
        $comments = array();

        $query = sprintf(
                    "SELECT
                        id_comment, usr, email, comment, datum
                    FROM
                        %sfaqcomments
                    WHERE
                        type = '%s'
                        AND id = %d",
                    SQLPREFIX,
                    $type,
                    $id
                );


        $result = $this->db->query($query);
        if ($this->db->num_rows($result) > 0) {
            while ($row = $this->db->fetch_object($result)) {
                $item = array(
                        'id'        => $row->id_comment,
                        'content'   => $row->comment,
                        'date'      => $row->datum,
                        'user'      => $row->usr,
                        'email'     => $row->email
                        );
                $comments[] = $item;
            }
        }

        return $comments;
    }

    /**
    * getComments()
    *
    * Returns all user comments (HTML formatted) from a record by type
    *
    * @param    integer     record id
    * @param    integer     record type: {faq|news}
    * @return   string
    * @access   public
    * @since    2002-08-29
    * @author   <NAME> <<EMAIL>>
    */
    function getComments($id, $type)
    {
        $comments = $this->getCommentsData($id, $type);

        $output = '';
        foreach ($comments as $item) {
            $output .= '<p class="comment">';
            $output .= sprintf('<strong>%s<a href="mailto:%s">%s</a>:</strong><br />%s<br />%s</p>',
                                $this->pmf_lang['msgCommentBy'],
                                safeEmail($item['email']),
                                $item['user'],
                                PMF_htmlentities($item['content '], ENT_QUOTES, $this->pmf_lang['metaCharset']),
                                $this->pmf_lang['newsCommentDate'].makeDateByFormat($item['date'], 'Y-m-d H:i', false)
                        );
        }

        return $output;
    }

    /**
     * addComment()
     *
     * Adds a comment
     *
     * @param   array       $commentData
     * @return  boolean
     * @access  public
     * @since   2006-06-18
     * @author  <NAME> <<EMAIL>>
     */
    function addComment($commentData)
    {
        if (!is_array($commentData)) {
            return false;
        }

        $query = sprintf(
                    "INSERT INTO
                        %sfaqcomments
                    VALUES
                        (%d, %d, '%s', '%s', '%s', '%s', %d, '%s')",
                    SQLPREFIX,
                    $this->db->nextID(SQLPREFIX.'faqcomments', 'id_comment'),
                    $commentData['record_id'],
                    $commentData['type'],
                    $commentData['username'],
                    $commentData['usermail'],
                    $commentData['comment'],
                    $commentData['date'],
                    $commentData['helped']
                );
        $this->db->query($query);

        return true;
    }

    /**
     * deleteComment()
     *
     * Deletes a comment
     *
     * @param   integer     $record_id
     * @param   integer     $comment_id
     * @return  boolean
     * @access  public
     * @since   2006-06-18
     * @author  <NAME> <<EMAIL>>
     */
    function deleteComment($record_id, $comment_id)
    {
        if (!is_int($record_id) && !is_int($comment_id)) {
            return false;
        }

        $query = sprintf(
                    'DELETE FROM
                        %sfaqcomments
                    WHERE
                        id = %d
                        AND id_comment = %d',
                    SQLPREFIX,
                    $record_id,
                    $comment_id
                );
        $this->db->query($query);

        return true;
    }
}
// }}}
<commit_msg>Fix: (minor) Typo<commit_after><?php
/**
* $Id: Comment.php,v 1.2 2006-07-23 16:44:13 matteo Exp $
*
* The main Comment class
*
* @author       <NAME> <<EMAIL>>
* @package      phpMyFAQ
* @since        2006-07-23
* @copyright    (c) 2006 phpMyFAQ Team
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*/

// {{{ Constants
/**#@+
  * Comment type
  */
define('PMF_COMMENT_TYPE_FAQ', 'faq');
define('PMF_COMMENT_TYPE_NEWS', 'news');
/**#@-*/
// }}}

// {{{ Classes
class PMF_Comment
{
    /**
    * DB handle
    *
    * @var  object
    */
    var $db;

    /**
    * Language
    *
    * @var  string
    */
    var $language;

    /**
    * Language strings
    *
    * @var  string
    */
    var $pmf_lang;

    /**
    * Constructor
    *
    */
    function PMF_Comment(&$db, $language)
    {
        global $PMF_LANG;

        $this->db = &$db;
        $this->language = $language;
        $this->pmf_lang = $PMF_LANG;
    }

    //
    //
    // PUBLIC METHODS
    //
    //

    /**
    * getCommentDataById()
    *
    * Returns a user comment
    *
    * @param    integer     comment id
    * @return   string
    * @access   public
    * @since    2006-07-13
    * @author   <NAME> <<EMAIL>>
    * @author   <NAME> <<EMAIL>>
    */
    function getCommentDataById($id)
    {
        $item = array();

        $query = sprintf(
                    "SELECT
                        id_comment, id, type, usr, email, comment, datum
                    FROM
                        %sfaqcomments
                    WHERE
                        id_comment = %d",
                    SQLPREFIX,
                    $id
                );

        $output = '';
        $result = $this->db->query($query);
        if (($this->db->num_rows($result) > 0) && ($row = $this->db->fetch_object($result))) {
            $item = array(
                    'id'        => $row->id_comment,
                    'recordId'  => $row->id,
                    'type'      => $row->type,
                    'content'   => $row->comment,
                    'date'      => $row->datum,
                    'user'      => $row->usr,
                    'email'     => $row->email
                    );
        }

        return $item;
    }

    /**
    * getCommentsData()
    *
    * Returns all user comments from a record by type
    *
    * @param    integer     record id
    * @param    integer     record type: {faq|news}
    * @return   string
    * @access   public
    * @since    2002-08-29
    * @author   <NAME> <<EMAIL>>
    * @author   <NAME> <<EMAIL>>
    */
    function getCommentsData($id, $type)
    {
        $comments = array();

        $query = sprintf(
                    "SELECT
                        id_comment, usr, email, comment, datum
                    FROM
                        %sfaqcomments
                    WHERE
                        type = '%s'
                        AND id = %d",
                    SQLPREFIX,
                    $type,
                    $id
                );


        $result = $this->db->query($query);
        if ($this->db->num_rows($result) > 0) {
            while ($row = $this->db->fetch_object($result)) {
                $item = array(
                        'id'        => $row->id_comment,
                        'content'   => $row->comment,
                        'date'      => $row->datum,
                        'user'      => $row->usr,
                        'email'     => $row->email
                        );
                $comments[] = $item;
            }
        }

        return $comments;
    }

    /**
    * getComments()
    *
    * Returns all user comments (HTML formatted) from a record by type
    *
    * @param    integer     record id
    * @param    integer     record type: {faq|news}
    * @return   string
    * @access   public
    * @since    2002-08-29
    * @author   <NAME> <<EMAIL>>
    */
    function getComments($id, $type)
    {
        $comments = $this->getCommentsData($id, $type);

        $output = '';
        foreach ($comments as $item) {
            $output .= '<p class="comment">';
            $output .= sprintf('<strong>%s<a href="mailto:%s">%s</a>:</strong><br />%s<br />%s</p>',
                                $this->pmf_lang['msgCommentBy'],
                                safeEmail($item['email']),
                                $item['user'],
                                PMF_htmlentities($item['content'], ENT_QUOTES, $this->pmf_lang['metaCharset']),
                                $this->pmf_lang['newsCommentDate'].makeDateByFormat($item['date'], 'Y-m-d H:i', false)
                        );
        }

        return $output;
    }

    /**
     * addComment()
     *
     * Adds a comment
     *
     * @param   array       $commentData
     * @return  boolean
     * @access  public
     * @since   2006-06-18
     * @author  <NAME> <<EMAIL>>
     */
    function addComment($commentData)
    {
        if (!is_array($commentData)) {
            return false;
        }

        $query = sprintf(
                    "INSERT INTO
                        %sfaqcomments
                    VALUES
                        (%d, %d, '%s', '%s', '%s', '%s', %d, '%s')",
                    SQLPREFIX,
                    $this->db->nextID(SQLPREFIX.'faqcomments', 'id_comment'),
                    $commentData['record_id'],
                    $commentData['type'],
                    $commentData['username'],
                    $commentData['usermail'],
                    $commentData['comment'],
                    $commentData['date'],
                    $commentData['helped']
                );
        $this->db->query($query);

        return true;
    }

    /**
     * deleteComment()
     *
     * Deletes a comment
     *
     * @param   integer     $record_id
     * @param   integer     $comment_id
     * @return  boolean
     * @access  public
     * @since   2006-06-18
     * @author  <NAME> <<EMAIL>>
     */
    function deleteComment($record_id, $comment_id)
    {
        if (!is_int($record_id) && !is_int($comment_id)) {
            return false;
        }

        $query = sprintf(
                    'DELETE FROM
                        %sfaqcomments
                    WHERE
                        id = %d
                        AND id_comment = %d',
                    SQLPREFIX,
                    $record_id,
                    $comment_id
                );
        $this->db->query($query);

        return true;
    }
}
// }}}

{'fraction_non_alphanumeric': 0.137229530587305, 'fraction_numerical': 0.010351520379555747, 'mean_word_length': 1.2110616656071203, 'pattern_counts': {'":': 0, '<': 69, '<?xml version=': 0, '>': 169, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5866940', 'n_tokens_mistral': 4227, 'n_tokens_neox': 3923, 'n_words': 880}