public function __construct($cid) { $this->comment = comment_load($cid); if ($this->comment) { $this->includeFile('inc', 'comment', 'comment.admin'); parent::__construct('comment_confirm_delete', $this->comment); } }
/** * Check view and edit permissions. * * @param $op * The type of operation. Either 'view' or 'edit'. */ function have_access($op) { global $user; $db = DBConnection::instance(); $field_id = (int) _post('fid'); if (!$field_id) { $field_id = (int) _get('fid'); } $field = (object) $db->dq("SELECT entity_id, entity_type, delta FROM {mytinytodo_fields} WHERE id = ?", $field_id)->fetch_assoc(); $field_info = field_info_field_by_id($field->delta); if ($field->entity_type == 'node') { if (!($node = node_load($field->entity_id))) { return false; } $node_access = $op == 'edit' ? 'update' : $op; if (node_access($node_access, $node, $user) && field_access($op, $field_info, $field->entity_type, $node, $user)) { return true; } } else { if ($field->entity_type == 'user') { if (!($account = user_load($field->entity_id))) { return false; } if (field_access($op, $field_info, $field->entity_type, $account, $user)) { return true; } } else { if ($field->entity_type == 'comment') { if (!($comment = comment_load($field->entity_id))) { return false; } if ($op == 'view' && !user_access('access comments')) { return false; } else { if ($op == 'edit' && !comment_access($op, $comment)) { return false; } } if (field_access($op, $field_info, $field->entity_type, $comment, $user)) { return true; } } else { if (module_exists('entity')) { if (!($entity = entity_load($field_id))) { return false; } $entity_access = $op == 'edit' ? 'update' : $op; if (entity_access($entity_access, $field->entity_type, $entity, $user) && field_access($op, $field_info, $field->entity_type, $entity, $user)) { return true; } } } } } return false; }
/** * Default constructor for the comment object. * * @param int|null $cid * Cid if an existing comment is to be loaded and null if a new comment is * to be loaded. */ public function __construct($cid = NULL) { $args = func_get_args(); array_shift($args); $nid = array_shift($args); $pid = array_shift($args); if (is_null($cid)) { if (!isset($nid) || !is_numeric($nid)) { $this->setErrors('Provide nid for a comment add form.'); $this->setInitialized(FALSE); return; } $node = node_load($nid); $comment = (object) array('nid' => $nid); } else { $comment = comment_load($cid); $comment_nid = $comment->nid; if (!is_null($nid) && $comment_nid != $nid) { $this->setErrors('Id of the node associated with the comment and provided node id do not match.'); $this->setInitialized(FALSE); return; } $node = node_load($comment_nid); } if (!$node) { $this->setErrors("Node {$nid} doesn't exist."); $this->setInitialized(FALSE); return; } if (!is_null($pid)) { $parent_comment = comment_load($pid); if (!$parent_comment) { $this->setInitialized(FALSE); $this->setErrors("Comment {$pid} does not exist."); return; } if ($parent_comment->nid != $node->nid) { $this->setInitialized(FALSE); $this->setErrors("Node id associated with the parent comment and the one that is provided do not match."); return; } $comment->pid = $pid; } $classname = get_called_class(); $class = new \ReflectionClass($classname); $class_shortname = $class->getShortName(); $type = Utils::makeSnakeCase(substr($class_shortname, 0, -7)); if ($node->type != $type) { $this->setErrors("Classes of comment and the node do not match. Class of comment is {$type} while that of node is " . $node->type . "."); $this->setInitialized(TRUE); return; } parent::__construct($comment); }
protected function createForumCommentWithText($node, $text) { static $cid = 0; $this->drupalPost("node/{$node->nid}", array('comment_body[' . LANGUAGE_NONE . '][0][value]' => $text), t('Save')); $this->assertResponse(200); $this->assertText($text, "Comment '{$text}' found, too."); return comment_load(++$cid); }
public function actionAddPraise() { if (isset($_POST['uid']) & isset($_POST['cid'])) { $comment = comment_load($_POST['cid']); $praise['value'] = $_POST['uid']; if (in_array($praise, $comment->field_praise['und'])) { $res['error_code'] = 1; $res['error_msg'] = "您已点赞"; } else { array_push($comment->field_praise['und'], $praise); comment_save($comment); $res['error_code'] = 0; $res['error_msg'] = null; } $jsonObj = CJSON::encode($res); echo $jsonObj; } else { $basic = new basic(); $basic->error_code = 1; $basic->error_msg = "no input parameters"; $jsonObj = CJSON::encode($basic); echo $jsonObj; die(0); } }
/** * Updates the local content with data from a Lingotek Document. * * @return bool * TRUE if the content updates succeeded, FALSE otherwise. */ public function updateLocalContent() { $success = TRUE; $metadata = $this->metadata(); if (!empty($metadata['document_id'])) { $document_id = $metadata['document_id']; $api = LingotekApi::instance(); $document = $api->getDocument($document_id); foreach ($document->translationTargets as $target) { $document_xml = $api->downloadDocument($metadata['document_id'], $target->language); $target_language = Lingotek::convertLingotek2Drupal($target->language); foreach ($document_xml as $drupal_field_name => $content) { // Figure out which subkey of the field data we're targeting. // "value" for standard text fields, or some other key for // compound text fields (text with summary, for example). $target_key = 'value'; $subfield_parts = explode('__', $drupal_field_name); if (count($subfield_parts) == 2) { $drupal_field_name = $subfield_parts[0]; $target_key = $subfield_parts[1]; } $field = field_info_field($drupal_field_name); if (!empty($field['lingotek_translatable'])) { $comment_field =& $this->comment->{$drupal_field_name}; $index = 0; foreach ($content as $text) { $comment_field[$target_language][$index][$target_key] = decode_entities(lingotek_xml_decode($text)); // Copy filter format from source language field. if (!empty($comment_field[$this->comment->language][0]['format'])) { $comment_field[$target_language][$index]['format'] = $comment_field[$this->comment->language][0]['format']; } $index++; } } } $comment_node = LingotekNode::loadById($this->comment->nid); $comment_fields = array_keys(field_info_instances('comment', 'comment_node_' . $comment_node->type)); foreach ($comment_fields as $field) { // Copy any untranslated fields from the default language into this target. if (isset($this->comment->{$field}[$this->comment->language]) && !isset($this->comment->{$field}[$target_language])) { $this->comment->{$field}[$target_language] = $this->comment->{$field}[$this->comment->language]; } // Ensure that all fields get their LANGUAGE_NONE field data populated with the // comment's default language data, to support toggling off of comment translation // at some point in the future. if (!empty($this->comment->{$field}[$this->comment->language])) { $this->comment->{$field}[LANGUAGE_NONE] = $this->comment->{$field}[$this->comment->language]; } } } // This avoids an infitinite loop when hooks resulting from comment_save() are invoked. self::$content_update_in_progress = TRUE; comment_save($this->comment); self::$content_update_in_progress = FALSE; $this->comment = comment_load($this->comment->cid); } else { LingotekLog::error('Unable to refresh local contents for comment @cid. Could not find Lingotek Document ID.', array('@cid' => $this->comment->cid)); $success = FALSE; } return $success; }
/** * Preprocess variables for Rate module likeme widget */ function opbamboo_preprocess_rate_widget(&$vars) { global $user; if ($vars['display_options']['title'] != 'likeme') { return; } $class = 'rate-btn'; $text = 'Like'; if (empty($vars['results']['user_vote'])) { $class .= ' vh-not-voted user-not-voted'; } else { $class .= ' vh-voted user-voted'; $text = 'Unlike'; } $process_anon = false; if (empty($user->uid)) { if (opbamboo_rate_widget_closed($vars['content_type'], $vars['content_id'])) { $vars['mode'] = RATE_CLOSED; } else { $class .= ' vh-vote-anon clicktext-right'; $process_anon = true; } } switch ($vars['mode']) { case RATE_CLOSED: // you could change the button here as well // $vars['info'] = format_plural($vars['results']['count'], '@count Like', '@count Likes'); $text = ''; $vars['info'] = '<span>' . $vars['results']['count'] . '</span>'; $class .= ' vh-vote-closed'; break; case RATE_COMPACT: case RATE_COMPACT_DISABLED: break; default: // $vars['info'] = format_plural($vars['results']['count'], '@count Like', '@count Likes'); $vars['info'] = '<span>' . $vars['results']['count'] . '</span>'; break; } foreach ($vars['links'] as $link) { $link['text'] = $text; $button = theme('rate_button', array('text' => $text, 'href' => $link['href'], 'class' => $class)); } if ($vars['content_type'] == 'node' and $node = node_load($vars['content_id'])) { $node->votecount = $vars['results']['count']; } elseif ($vars['content_type'] == 'comment' and $comment = comment_load($vars['content_id'])) { $comment->votecount = $vars['results']['count']; $node = node_load($comment->nid); } if ($process_anon and $node) { $button = str_replace(array('<span', 'span>'), array('<a', 'a>'), $button); $options = array(); if ($group = opg_core_node_in_group($node)) { $opg = opg_core_load_opg($group); $login_type = $opg['login_type']; $options['op_login'] = $options['login'] = $opg['login']; } elseif ($op_forum = op_common_op_forum_load($node->type)) { $options['op_login'] = $op_forum->login; } else { $login_type = op_common_get_login_type($node->type); $options['op_login'] = op_common_op_login_load($login_type); } $login_text = theme('op_login_text', $options); $button .= <<<EOT <span class="clicktextlong" style="display:none;"> {$login_text} and click again to Like </span> EOT; } $vars['buttons'] = array($button); $vars['button'] = $button; }
public function actionView($id) { date_default_timezone_set("Asia/Shanghai"); $article = node_load($id); if ($article) { $complexNews = new ArticleImage(); $newsView = new NewsView(); $newsView->id = $article->nid; $newsView->title = $article->title; $newsView->label = $article->field_status['und'][0]['value']; $newsView->subTitle = $article->field_src['und'][0]['value']; //$newsView->create_time=date('Y年m月d日 H:i:s',$article->changed); if ($article->field_riq['und'][0]) { $time = strtotime($article->field_riq['und'][0]['value']); $newsView->create_time = date('Y年m月d日 H:i:s', $time); } else { $newsView->create_time = date('Y年m月d日 H:i:s', $article->changed); } //$newsView->create_time=$article->field_riq['und'][0]['value']; $newsView->content = nl2br($article->body['und'][0]['value']); $newsView->src = '市民 ' . $article->field_shimin['und'][0]['value']; $complexNews->article = $newsView; $easys = array(); $easyImg = new EasyImg(); $easyImg->url = str_replace("public://", BigImg, $article->field_tux['und'][0]['uri']); if ($easyImg->url) { array_push($easys, $easyImg); } $complexNews->imgs = $easys; $complexNews->ccount = $article->comment_count; $easyComment = new EasyComment(); $query = new EntityFieldQuery(); $query->entityCondition('entity_type', 'comment')->propertyCondition('nid', $article->nid)->propertyOrderBy('changed', 'DESC')->range(0, 1); $result = $query->execute(); if (isset($result['comment'])) { $news_items_nids = array_keys($result['comment']); $comment = comment_load($news_items_nids[0]); } if ($comment) { $easyComment->content = $comment->comment_body['und'][0]['value']; $easyComment->create_time = date('Y年m月d日 H:i:s', $comment->changed); $easyComment->nick = $comment->subject; } else { $easyComment->content = ""; $easyComment->create_time = ""; $easyComment->nick = ""; } $complexNews->comment = $easyComment; //$complexNews->share=ShareRoot.'share/share&i='.$id.'&t=2&n='.'Bl'; $jsonObj = CJSON::encode($complexNews); echo $jsonObj; } else { echo ""; } }
/** * Tests mapping to node by title. */ public function testMappingByTitle() { $this->removeMappings('comment', array(1 => array('source' => 'guid', 'target' => 'nid_by_guid'))); $this->addMappings('comment', array(4 => array('source' => 'title', 'target' => 'nid_by_title'))); $url = $GLOBALS['base_url'] . '/' . drupal_get_path('module', 'feeds_comment_processor') . '/tests/test.csv'; $nid = $this->createFeedNode('comment', $url, 'Comment test'); $this->assertText('Created 1 comment'); $comment = comment_load(1); $this->assertEqual(1, $comment->nid); $this->assertEqual('test subject', $comment->subject); $this->assertEqual('example.com', $comment->hostname); $this->assertEqual('test body text', $comment->comment_body[LANGUAGE_NONE][0]['value']); $this->assertEqual('plain_text', $comment->comment_body[LANGUAGE_NONE][0]['format']); }
<?php require_once '../includes/functions.inc.php'; require_once '../includes/admin.inc.php'; if (isset($_POST['comid'])) { $comid = $_POST['comid']; $comment = comment_load($comid); if ($comment['Comment_Hide_Name'] == 0) { hide_comment($comid); } elseif ($comment['Comment_Hide_Name'] == 1) { unhide_comment($comid); } }
public function post($route, $form) { global $user; if ($route == 'comments.json') { $options = $this->getOptions(); $node = node_load($options['nid']); if ($options['uid'] != $user->uid || !is_object($node)) { return false; } // Should we let the comment pass ? if ($node->comment != COMMENT_NODE_OPEN || !user_access('post comments')) { // Access denied. return false; } if (!empty($form->values['cid'])) { $comment = comment_load($form->values['cid']); if (!is_object($comment)) { // Not existent CID.. Access denied return false; } $nodeSubmittedComment = node_load($comment->nid); if (!is_object($nodeSubmittedComment) || $nodeSubmittedComment->nid != $node->nid) { return FALSE; // BAD nid.. Or node non existent } // Publish if ($form->values['toPublish']) { if (user_access('administer comments') && user_access('post comments')) { $comment->status = COMMENT_PUBLISHED; comment_save($comment); } return; } // Deletion if ($form->values['toDelete']) { if (user_access('administer comments') && user_access('post comments')) { comment_delete($comment->cid); } return; } if (!comment_access('edit', $comment)) { return FALSE; // No access to edit the comment. } } if (empty($comment)) { $pid = NULL; if (!empty($form->values['pid'])) { if ($form->values['pid'] == (int) $form->values['pid']) { if ($comment_parent = comment_load((int) $form->values['pid'])) { $pid = $form->values['pid']; } } } $comment = new stdClass(); $comment->nid = $node->nid; $comment->pid = $pid; $comment->uid = $user->uid; $comment->name = check_plain($form->values['author']); } $comment->subject = check_plain($form->values['subject']); $field = field_info_field('comment_body'); $langcode = field_is_translatable('comment', $field) ? entity_language('comment', $comment) : LANGUAGE_NONE; $field_infos = field_info_instance('comment', 'comment_body', 'comment_node_' . $node->type); $format = $options['comment-body-format']; $text_processing = $field_infos['settings']['text_processing']; $body = $form->values['body']; $body = $format != 'plain_text' && $text_processing ? check_markup($body, $format) : check_plain($body); if ($text_processing) { $comment->comment_body[$langcode][0]['format'] = $format; } $comment->comment_body = array($langcode => array()); $comment->comment_body[$langcode][0]['value'] = $body; comment_submit($comment); comment_save($comment); cache_clear_all(); } }
function _bootstrap_theme_comments_view($node) { $comments = _bootstrap_theme_get_comments($node); $output = ''; $header = array('Avatar', 'Comments'); $rows = array(); $comment_cnt = 0; foreach ($comments as $comment) { $comment = comment_load($comment->cid); $row = array(); $account = user_load($comment->uid); $row[] = array('data' => '<a href="' . url('user/' . $account->uid) . '"><img src="' . bootstrap_theme_get_user_picture($account) . '" alt="' . format_username($account) . '" /></a>', 'class' => array('cell-comment-avatar')); $html = '<div class="comment-info">'; $html .= '<a href="' . url('user/' . $account->uid) . '" class="comment-user">' . format_username($account) . '</a>'; $html .= '<span class="comment-date">' . format_interval(time() - $comment->created) . ' ago</span>'; $html .= '<div class="comment-body"">' . $comment->comment_body[LANGUAGE_NONE][0]['value'] . '</comment>'; $html .= '</div>'; $row[] = array('data' => $html, 'class' => 'cell-comment-data'); $rows[] = $row; $comment_cnt++; } $output .= '<div class="comment-list ' . ($comment_cnt == 0 ? 'no-comment' : '') . '">'; if ($comment_cnt == 0) { $output .= 'No Comments'; } else { $output .= theme('table', array('header' => $header, 'rows' => $rows, 'attributes' => array('class' => array('data-table-comments')), 'sticky' => FALSE)); $output .= theme('pager'); } $output .= '</div>'; $form = drupal_get_form('bootstrap_theme_create_comment_form', $node); $output .= '<div id="comment_form_container">'; if (user_is_logged_in()) { $output .= '' . drupal_render($form) . '</div>'; $output .= '<a id="write-comments" href="#" class="element-invisible">Write Comments</a>'; } else { $output .= '<div class="comment-not-logged-in">'; $output .= '<a href="' . url('user/login') . '?destination=' . urlencode(url('node/' . $node->nid)) . '">log in to submit a comment</a>'; $output .= '<div class="clear"></div>'; $output .= '</div>'; } $output .= '</div>'; return $output; }
* - $field->class: The safe class id to use. * - $field->handler: The Views field handler object controlling this field. Do not use * var_export to dump this object, as it can't handle the recursion. * - $field->inline: Whether or not the field should be inline. * - $field->inline_html: either div or span based on the above flag. * - $field->wrapper_prefix: A complete wrapper containing the inline_html to use. * - $field->wrapper_suffix: The closing tag for the wrapper. * - $field->separator: an optional separator that may appear before a field. * - $field->label: The wrap label text to use. * - $field->label_html: The full HTML of the label to use including * configured element type. * - $row: The raw result object from the query, with all data it fetched. * * @ingroup views_templates */ $comment = comment_load($row->cid); $date = format_date($row->comment_created, 'custom', 'F d, Y'); //$date = date('F d, Y',$row->comment_created ); ?> <li> <div class="widget-comment"> <h4 class="widget-comment-title"> <a href="<?php print $fields['path']->content; ?> " title=""><?php print $comment->subject; ?> </a> </h4>