Example #1
0
function pagem_moderatecomment()
{
    global $PIVOTX;
    require_once dirname(__FILE__) . '/modules/module_comments.php';
    $PIVOTX['session']->minLevel(PIVOTX_UL_NORMAL);
    // uid should be numeric. (If it's not, someone is hacking ...)
    if (!is_numeric($_GET['uid'])) {
        echo "uid must be numeric";
        die;
    }
    $entry = $PIVOTX['db']->read_entry(intval($_GET['uid']));
    if (isset($entry['comments'][$_GET['key']])) {
        $comment = $entry['comments'][$_GET['key']];
    } else {
        // This should only happen for non-SQL db when editing a comment from
        // the latest comments screen (or similar functions) which uses fake UIDs.
        foreach ($entry['comments'] as $key => $value) {
            if ($_GET['key'] == makeCommentUID($value)) {
                $comment = $value;
                // Setting the key to the array key
                $_GET['key'] = $key;
                break;
            }
        }
    }
    // Flip the moderation, and save it again..
    $comment['moderate'] = 1 - intval($comment['moderate']);
    editComment($entry, $_GET['key'], $comment);
    if ($comment['moderate']) {
        $PIVOTX['messages']->addMessage(__('The Comment was disapproved!'));
    } else {
        $PIVOTX['messages']->addMessage(__('The Comment was approved!'));
    }
    pagem_comments();
}
/**
 * Edits/modifies a comment.
 *
 * @param array $entry The entry containing the comment
 * @param string $comm_key The key for the edited comment
 * @param array $comm_val The (content of the) edited comment
 * @return void
 */
function editComment($entry, $comm_key, $comm_val)
{
    global $PIVOTX;
    // unset unneeded values.
    unset($comm_val['uid']);
    unset($comm_val['entry_uid']);
    // Make sure we don't store negative values..
    $comm_val['registered'] = max($comm_val['registered'], 0);
    $comm_val['notify'] = max($comm_val['notify'], 0);
    $comm_val['discreet'] = max($comm_val['discreet'], 0);
    $comm_val['moderate'] = max($comm_val['moderate'], 0);
    // if we're using SQL, delete the old comment, before saving it again.
    // This is not necesary for 'flat' db's.
    if ($PIVOTX['db']->db_type == "sql") {
        $PIVOTX['db']->delete_comment($comm_key);
    }
    // If we are using a flat file db, we must update the latest comments file.
    // Iterate through the latest comments, updating comment if found.
    if ($PIVOTX['db']->db_type == "flat") {
        $lastcommfile = $PIVOTX['paths']['db_path'] . "ser_lastcomm.php";
        if (file_exists($lastcommfile)) {
            $lastcomm = loadSerialize($lastcommfile, true, true);
        } else {
            $lastcomm = array();
        }
        $olduid = makeCommentUID($entry['comments'][$comm_key]);
        foreach ($lastcomm as $key => $comment) {
            if ($comment['uid'] == $olduid) {
                // Don't add any new keys ...
                foreach ($lastcomm[$key] as $subkey => $value) {
                    if (isset($comm_val[$subkey])) {
                        $lastcomm[$key][$subkey] = $comm_val[$subkey];
                    }
                }
                // Update the UID accounting for any changes.
                $lastcomm[$key]['uid'] = makeCommentUID($lastcomm[$key]);
                break;
            }
        }
        saveSerialize($lastcommfile, $lastcomm);
    }
    $entry['comments'][$comm_key] = $comm_val;
    $PIVOTX['db']->set_entry($entry);
    $PIVOTX['db']->save_entry();
    // Remove the compiled/parsed pages from the cache.
    if ($PIVOTX['config']->get('smarty_cache')) {
        $PIVOTX['template']->clear_cache();
    }
}
Example #3
0
 /**
  * Returns a comment from the current entry.
  *
  * @param int $uid
  * @return array
  */
 function get_comment($uid)
 {
     global $PIVOTX;
     if (isset($this->entry['comments'][$uid])) {
         $comm = $this->entry['comments'][$uid];
     } else {
         // This should only happen when editing a comment from the last
         // comments screen (or similar functions) which uses fake UIDs.
         require_once dirname(__FILE__) . '/module_comments.php';
         foreach ($this->entry['comments'] as $key => $value) {
             if ($uid == makeCommentUID($value)) {
                 $comm = $value;
                 break;
             }
         }
     }
     return $comm;
 }