I need to get current user comment details which is commented by him.
please try below code
global $user;
$query = db_select('comments', 'cm');
$query->fields(cm);
$query->condition('cm.uid', $user->uid, '=');
$result = $query->execute();
while ($chunk = $result->fetchObject()) {
print $chunk->subject; // comment title
print $chunk->nid; // on which node user enter comment
print $chunk->mail; // email of user
}
OR you can use view to create listing without using manual query.
goto structure->views->create new view and select comments option in Show Field setting.
Thanks,
Ankush
You Can create a view (view page or view block) of comments and add the RELATIONSHIPS with user (Comment: Author) and add the CONTEXTUAL FILTERS for user (author User: Uid)
$view = new view();
$view->name = 'comments';
$view->description = '';
$view->tag = 'default';
$view->base_table = 'comment';
$view->human_name = 'Comments';
$view->core = 7;
$view->api_version = '3.0';
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
/* Display: Master */
$handler = $view->new_display('default', 'Master', 'default');
$handler->display->display_options['title'] = 'Comments';
$handler->display->display_options['use_more_always'] = FALSE;
$handler->display->display_options['access']['type'] = 'perm';
$handler->display->display_options['access']['perm'] = 'access comments';
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['query']['type'] = 'views_query';
$handler->display->display_options['exposed_form']['type'] = 'basic';
$handler->display->display_options['pager']['type'] = 'full';
$handler->display->display_options['pager']['options']['items_per_page'] = '10';
$handler->display->display_options['style_plugin'] = 'default';
$handler->display->display_options['row_plugin'] = 'comment';
/* Relationship: Comment: Content */
$handler->display->display_options['relationships']['nid']['id'] = 'nid';
$handler->display->display_options['relationships']['nid']['table'] = 'comment';
$handler->display->display_options['relationships']['nid']['field'] = 'nid';
$handler->display->display_options['relationships']['nid']['required'] = TRUE;
/* Relationship: Comment: Author */
$handler->display->display_options['relationships']['uid']['id'] = 'uid';
$handler->display->display_options['relationships']['uid']['table'] = 'comment';
$handler->display->display_options['relationships']['uid']['field'] = 'uid';
/* Field: Comment: Title */
$handler->display->display_options['fields']['subject']['id'] = 'subject';
$handler->display->display_options['fields']['subject']['table'] = 'comment';
$handler->display->display_options['fields']['subject']['field'] = 'subject';
$handler->display->display_options['fields']['subject']['label'] = '';
$handler->display->display_options['fields']['subject']['alter']['word_boundary'] = FALSE;
$handler->display->display_options['fields']['subject']['alter']['ellipsis'] = FALSE;
/* Sort criterion: Comment: Post date */
$handler->display->display_options['sorts']['created']['id'] = 'created';
$handler->display->display_options['sorts']['created']['table'] = 'comment';
$handler->display->display_options['sorts']['created']['field'] = 'created';
$handler->display->display_options['sorts']['created']['order'] = 'DESC';
/* Contextual filter: User: Uid */
$handler->display->display_options['arguments']['uid']['id'] = 'uid';
$handler->display->display_options['arguments']['uid']['table'] = 'users';
$handler->display->display_options['arguments']['uid']['field'] = 'uid';
$handler->display->display_options['arguments']['uid']['relationship'] = 'uid';
$handler->display->display_options['arguments']['uid']['default_argument_type'] = 'fixed';
$handler->display->display_options['arguments']['uid']['summary']['number_of_records'] = '0';
$handler->display->display_options['arguments']['uid']['summary']['format'] = 'default_summary';
$handler->display->display_options['arguments']['uid']['summary_options']['items_per_page'] = '25';
/* Filter criterion: Comment: Approved */
$handler->display->display_options['filters']['status']['id'] = 'status';
$handler->display->display_options['filters']['status']['table'] = 'comment';
$handler->display->display_options['filters']['status']['field'] = 'status';
$handler->display->display_options['filters']['status']['value'] = 1;
$handler->display->display_options['filters']['status']['group'] = 1;
$handler->display->display_options['filters']['status']['expose']['operator'] = FALSE;
/* Filter criterion: Content: Published */
$handler->display->display_options['filters']['status_node']['id'] = 'status_node';
$handler->display->display_options['filters']['status_node']['table'] = 'node';
$handler->display->display_options['filters']['status_node']['field'] = 'status';
$handler->display->display_options['filters']['status_node']['relationship'] = 'nid';
$handler->display->display_options['filters']['status_node']['value'] = 1;
$handler->display->display_options['filters']['status_node']['group'] = 1;
$handler->display->display_options['filters']['status_node']['expose']['operator'] = FALSE;
/* Display: Page */
$handler = $view->new_display('page', 'Page', 'page');
$handler->display->display_options['path'] = 'comments';
Create a view.
View cab get comments and you can add a filter to get only comments added by specific user, by passing (current) user id.
It's not a standard function, but this gives the logged in user's comments. Get the nid from the node table w.r.t to user id.
I get the logged-in user comments without any theme:
$nid_result = db_select('node') -> fields('node', array('nid')) ->
condition('uid', $puser->uid, '=') ->
condition('type', 'user_profile_comment', '=') -> execute();
$nid = $nid_resul t-> fetchCol();
$user_detail = array();
$result = db_select('comment') -> fields('comment', array('cid')) ->
condition('nid', $nid[0], '=') -> orderBy('cid', 'DESC') -> execute();
$cids = $result->fetchCol();
$comments=comment_load_multiple($cids);
print_r($comments);
Related
I am trying to create a wordpress plugin that exports or sends out (through an API) bulk data resource by resource (such as products, orders, customers, etc) of a woocommerce site without affecting the performance of the site.
But I am new to php and finding it difficult.
Also, I was planning to use WP-Cron to build the bulk data on certain time interval in order to avoid the hit in performance. But, from some research, I got to know that WP-Cron is not a reliable solution to my goal as it is not a regular cron and also, it can be disabled easily.
As my idea requires a regular bulk data building approach, I am now looking out for different options such as recursive calling.
I have exposed an endpoint where I will be receiving some required details and will call the class that will take care of the bulk data building.
public function getCCBulkSync( $request )
{
$entity = $_GET['entity'];
$startDate = $_GET['start_date'];
$endDate = $_GET['end_date'];
$delivery_url = $_GET['delivery_url'];
$limit = $_GET['limit'];
if(!$delivery_url) return 'Delivery Url cannot be null';
include 'class-wc-cc-bulk-data-builder.php';
$bulkBuilder = WC_CC_Bulk_Data_Builder::getInstance();
$bulkBuilder = ($bulkBuilder === NULL || $bulkBuilder->getObjectDetails()['entity'] === NULL) ? $bulkBuilder->setObjectDetails($entity, $delivery_url, $startDate, $endDate, $limit) : $bulkBuilder;
return 'Bulk sync initiated! Check later for the completion!!!';
}
The bulk data builder class code is given below
class WC_Bulk_Data_Builder
{
private static $instance = NULL;
protected $entity = NULL;
protected $startDate = NULL;
protected $endDate = NULL;
protected $delivery_url = NULL;
protected $dataCount = 0;
protected $limit = 0;
static public function getInstance()
{
if (self::$instance === NULL)
self::$instance = new WC_Bulk_Data_Builder();
return self::$instance;
}
protected function __construct($entity = NULL, $delivery_url = NULL, $startDate = NULL, $endDate = NULL, $limit = 1000)
{
$this->entity = $entity;
$this->delivery_url = $delivery_url;
$this->startDate = $startDate;
$this->endDate = $endDate;
$this->limit = $limit;
}
public function getObjectDetails() {
$objData = array();
$objData['entity'] = $this->entity;
$objData['startDate'] = $this->startDate;
$objData['endDate'] = $this->endDate;
$objData['deliveryUrl'] = $this->delivery_url;
$objData['dataCount'] = $this->dataCount;
$objData['limit'] = $this->limit;
return $objData;
}
public function setObjectDetails($entity = NULL, $delivery_url = NULL, $startDate = NULL, $endDate = NULL, $limit = 1000) {
$this->entity = $entity;
$this->delivery_url = $delivery_url;
$this->startDate = $startDate;
$this->endDate = $endDate;
$this->limit = $limit;
$this->bulk_data_builder();
return self::$instance;
}
function bulk_data_builder()
{
$entity = $this->entity;
if($entity === 'order') {
$this->build_order_data();
}
sleep(20);
$this->bulk_data_builder();
}
protected function build_order_data()
{
$ordersArray = wc_get_orders( array(
'limit' => 250,
'offset' => $this->dataCount,
'orderby' => 'ID',
'order' => 'ASC',
) );
$this->dataCount += count($ordersArray);
$orders = array();
foreach($ordersArray as $order_index=>$order) {
$orders[$order_index]=$order->get_data();
$orders[$order_index]['refunds'] = $order->get_refunds();
}
$header_args = array_keys($orders[0]);
$output = fopen( 'order_csv_export.csv', 'a+' );
fputcsv($output, $header_args);
foreach($orders AS $order_item){
foreach($header_args AS $ind=>$key) {
if('array' === gettype($order_item[$key])) $order_item[$key] = json_encode($order_item[$key]);
}
fputcsv($output, $order_item);
}
if($dataCount>=$limit)
{
$dataCount = 0;
$req_headers = array();
$req_headers[] = 'Content-Type: text/csv; charset=utf-8';
$req_headers[] = 'Content-Disposition: attachment; filename=order_csv_export.csv';
$cURL = curl_init();
$setopt_array = array(CURLOPT_URL => $delivery_url, CURLOPT_RETURNTRANSFER => true, CURLOPT_HTTPHEADER => $req_headers);
curl_setopt_array($cURL, $setopt_array);
$json_response_data = curl_exec($cURL);
curl_close($cURL);
exit;
}
fclose($output);
}
}
Now, what I am expecting is the recursive calling on same bulk_data_builder() method which should build the data continuously on a 20 seconds interval or any other way to do the same until the record count reaches the limit, so that I can send the bulk data built, to the delivery_url.
But, the mentioned method is not getting called recursively. Only for the first time the method is called and giving back 250 records.
As I am new to php, I am not sure about the async functionality also.
Can someone help me to understand what I am doing wrong or what I am missing?
I'm getting a "The value you selected is not a valid choice." error for an Ajax modified field when I submit a custom altered node/add form. An "Illegal choice error is also written to the log. This a Drupal 9 version of an app that I developed using Drupal 7 which worked. The Ajax functionality is working. Why? How do I fix it?
I believe the error is coming from some Symfony code. I'm dynamically modifying two "select" form elements. The first doesn't appear to have the problem. I'm doing the same thing for both form elements.
function bncreports_form_node_bnc_message_form_alter(&$form, FormStateInterface $form_state, $form_id)
{
$form['actions']['submit']['#submit'][] = 'bncreports_node_bnc_message_form_submit';
$form['#title'] = t('Create Contact Us');
$user = User::load(\Drupal::currentUser()->id());
$district_id = $user->get('field_district')->value;
$form['field_first_name']['widget'][0]['value']['#default_value'] = $user->get('field_first_name')->value;
$form['field_last_name']['widget'][0]['value']['#default_value'] = $user->get('field_last_name')->value;
$form['field_email']['widget'][0]['value']['#default_value'] = $user->getEmail();
$form['field_email']['widget'][0]['value']['#attributes'] = ['onblur' => 'this.value=this.value.toLowerCase();'];
$form['field_phone']['widget'][0]['value']['#default_value'] = $user->get('field_phone')->value;
$form['field_district']['widget'][0]['value']['#default_value'] = $district_id;
if (isset($form['field_district']['widget']['#default_value']))
$form['field_district']['widget']['#default_value'] = $district_id; // wtf?
if ($user->hasRole('administrator') || $user->hasRole('bnc_operator') || $user->hasRole('ao_user')) {
$form['field_office']['#access'] = false;
$form['field_office_name']['#access'] = false;
$form['field_office_names']['#access'] = false;
$form['field_site_codes']['#access'] = false;
$form['field_district']['widget']['#ajax'] = [
'event' => 'change',
'callback' => 'bncreports_ajax_offices_and_user',
'wrapper' => ['ajax-wrapper-field-offices', 'ajax-wrapper-field-user'],
];
$form['field_offices']['#prefix'] = '<div id="ajax-wrapper-field-offices">';
$form['field_offices']['#suffix'] = '</div>';
$form['field_user']['#prefix'] = '<div id="ajax-wrapper-field-user">';
$form['field_user']['#suffix'] = '</div>';
$district_id = $form_state->hasValue('field_district')
? $form_state->getValue('field_district')[0]['value']
: false;
$form['field_offices']['widget']['#options'] = $district_id
? Functions::officeNames($district_id)
: [];
$form['field_user']['widget']['#options'] = $district_id
? ['_none' => '- Select a value -'] + Functions::districtUserLastandFirstNames($district_id)
: ['_none' => '- Select a value -'];
} else { // Alterations for court users only
$form['bnc_prefix']['#markup'] =
'<p>BNC User Support: ' . Constants::BNC_PHONE_NO
. ' ' . Constants::BNC_EMAIL . '</p>'
. '<p>AO Program and CM/ECF Contacts</p>'
. '<h4>Unable to find what you need? Send us a message.</h4>';
$form['bnc_prefix']['#weight'] = -1;
$form['field_offices']['#access'] = false;
$form['field_office_name']['#access'] = false;
$form['field_office_names']['#access'] = false;
$form['field_site_codes']['#access'] = false;
$form['field_user']['#access'] = false;
$form['field_non_user_name']['#access'] = false;
$form['field_non_user_phone']['#access'] = false;
$form['field_assigned_to']['#access'] = false;
$form['revision_information']['#access'] = false;
$office = $user->get('field_office')->value;
$form['field_district']['widget']['#default_value'] = $district_id;
$form['field_office']['widget']['#options'] = Functions::officeNames($district_id);
$form['field_office']['widget']['#default_value'] = $office;
$form['field_office_name']['widget'][0]['value']['#default_value'] = Functions::officeName($district_id, $office);
$form['#attached']['library'][] = 'bncreports/restricted_contact_log';
}
}
function bncreports_ajax_offices_and_user(array $form, FormStateInterface $form_state): AjaxResponse
{
$response = new AjaxResponse();
// Issue a command that replaces the elements 'field_offices' and 'field_user'
$response->addCommand(new ReplaceCommand('#ajax-wrapper-field-office', $form['field_offices']));
$response->addCommand(new ReplaceCommand('#ajax-wrapper-field-user', $form['field_user']));
return $response;
}
Problem is there are no allowed values for the field_user list. Solution is to use an allowed values function callback. This is done in Configuration synchronization for Field Storage. Set the allowed value function property and import. Need to provide uuid to override existing config.
In my hook_form_alter:
$_SESSION['selected_district_id'] = $district_id;
In my xxx.module:
function bncreports_allowed_values_function(FieldStorageConfig $definition, ContentEntityInterface $entity = NULL, $cacheable): array
{
// NOTE: This is defined in Configuation synchronization for Field Storage (see node.field_user)
if ($entity->bundle() == 'bnc_message') { // Add a custom field_user options for BNC Message nodes.
$district_id = $_SESSION['selected_district_id'] ?? null;
return Functions::districtUserLastandFirstNames($district_id);
}
throw new Exception("Allowed values function for {$entity->bundle()} is not allowed.");
}
I got the following problem. As a logged in user and administrator I'm able to see the view, but as anonymous user the view with products inside has disappeared.
In the view I got no permissions set and on the admin/people/permissions everything is normal. Does anybody know where I'm failing?
Here is my export of the VIEW:
$view = new view();
$view->name = 'frontpage';
$view->description = 'Emulates the default Drupal front page; you may set the default home page path to this view to make it your front page.';
$view->tag = 'default';
$view->base_table = 'node';
$view->human_name = 'Front page';
$view->core = 0;
$view->api_version = '3.0';
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
/* Display: Master */
$handler = $view->new_display('default', 'Master', 'default');
$handler->display->display_options['use_more_always'] = FALSE;
$handler->display->display_options['access']['type'] = 'none';
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['query']['type'] = 'views_query';
$handler->display->display_options['query']['options']['query_comment'] = FALSE;
$handler->display->display_options['exposed_form']['type'] = 'basic';
$handler->display->display_options['pager']['type'] = 'full';
$handler->display->display_options['pager']['options']['items_per_page'] = '8';
$handler->display->display_options['pager']['options']['offset'] = '0';
$handler->display->display_options['pager']['options']['id'] = '0';
$handler->display->display_options['pager']['options']['quantity'] = '9';
$handler->display->display_options['style_plugin'] = 'grid';
$handler->display->display_options['row_plugin'] = 'fields';
/* Relationship: Content: Referenced products */
$handler->display->display_options['relationships']['field_product_product_id']['id'] = 'field_product_product_id';
$handler->display->display_options['relationships']['field_product_product_id']['table'] = 'field_data_field_product';
$handler->display->display_options['relationships']['field_product_product_id']['field'] = 'field_product_product_id';
$handler->display->display_options['relationships']['field_product_product_id']['label'] = 'Products';
/* Field: Commerce Product: Images */
$handler->display->display_options['fields']['field_images']['id'] = 'field_images';
$handler->display->display_options['fields']['field_images']['table'] = 'field_data_field_images';
$handler->display->display_options['fields']['field_images']['field'] = 'field_images';
$handler->display->display_options['fields']['field_images']['relationship'] = 'field_product_product_id';
$handler->display->display_options['fields']['field_images']['label'] = '';
$handler->display->display_options['fields']['field_images']['alter']['make_link'] = TRUE;
$handler->display->display_options['fields']['field_images']['element_type'] = 'div';
$handler->display->display_options['fields']['field_images']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['field_images']['element_wrapper_type'] = '0';
$handler->display->display_options['fields']['field_images']['element_default_classes'] = FALSE;
$handler->display->display_options['fields']['field_images']['click_sort_column'] = 'fid';
$handler->display->display_options['fields']['field_images']['settings'] = array(
'image_style' => 'medium',
'image_link' => '',
);
$handler->display->display_options['fields']['field_images']['delta_offset'] = '0';
$handler->display->display_options['fields']['field_images']['field_api_classes'] = TRUE;
/* Field: Content: Title */
$handler->display->display_options['fields']['title']['id'] = 'title';
$handler->display->display_options['fields']['title']['table'] = 'node';
$handler->display->display_options['fields']['title']['field'] = 'title';
/* Field: Commerce Product: Price */
$handler->display->display_options['fields']['commerce_price']['id'] = 'commerce_price';
$handler->display->display_options['fields']['commerce_price']['table'] = 'field_data_commerce_price';
$handler->display->display_options['fields']['commerce_price']['field'] = 'commerce_price';
$handler->display->display_options['fields']['commerce_price']['relationship'] = 'field_product_product_id';
$handler->display->display_options['fields']['commerce_price']['label'] = '';
$handler->display->display_options['fields']['commerce_price']['element_type'] = '0';
$handler->display->display_options['fields']['commerce_price']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['commerce_price']['element_wrapper_type'] = '0';
$handler->display->display_options['fields']['commerce_price']['element_default_classes'] = FALSE;
$handler->display->display_options['fields']['commerce_price']['click_sort_column'] = 'amount';
$handler->display->display_options['fields']['commerce_price']['settings'] = array(
'calculation' => '0',
);
$handler->display->display_options['fields']['commerce_price']['field_api_classes'] = TRUE;
/* Field: Commerce Product: Add to Cart form */
$handler->display->display_options['fields']['add_to_cart_form']['id'] = 'add_to_cart_form';
$handler->display->display_options['fields']['add_to_cart_form']['table'] = 'views_entity_commerce_product';
$handler->display->display_options['fields']['add_to_cart_form']['field'] = 'add_to_cart_form';
$handler->display->display_options['fields']['add_to_cart_form']['relationship'] = 'field_product_product_id';
$handler->display->display_options['fields']['add_to_cart_form']['label'] = '';
$handler->display->display_options['fields']['add_to_cart_form']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['add_to_cart_form']['show_quantity'] = 0;
$handler->display->display_options['fields']['add_to_cart_form']['default_quantity'] = '1';
$handler->display->display_options['fields']['add_to_cart_form']['combine'] = 1;
$handler->display->display_options['fields']['add_to_cart_form']['display_path'] = 0;
$handler->display->display_options['fields']['add_to_cart_form']['line_item_type'] = 'product';
/* Sort criterion: Content: Sticky */
$handler->display->display_options['sorts']['sticky']['id'] = 'sticky';
$handler->display->display_options['sorts']['sticky']['table'] = 'node';
$handler->display->display_options['sorts']['sticky']['field'] = 'sticky';
$handler->display->display_options['sorts']['sticky']['order'] = 'DESC';
/* Sort criterion: Content: Post date */
$handler->display->display_options['sorts']['created']['id'] = 'created';
$handler->display->display_options['sorts']['created']['table'] = 'node';
$handler->display->display_options['sorts']['created']['field'] = 'created';
$handler->display->display_options['sorts']['created']['order'] = 'DESC';
/* Filter criterion: Content: Type */
$handler->display->display_options['filters']['type']['id'] = 'type';
$handler->display->display_options['filters']['type']['table'] = 'node';
$handler->display->display_options['filters']['type']['field'] = 'type';
$handler->display->display_options['filters']['type']['value'] = array(
'product_display' => 'product_display',
);
$handler->display->display_options['filters']['type']['group'] = 1;
/* Filter criterion: Content: Published */
$handler->display->display_options['filters']['status']['id'] = 'status';
$handler->display->display_options['filters']['status']['table'] = 'node';
$handler->display->display_options['filters']['status']['field'] = 'status';
$handler->display->display_options['filters']['status']['value'] = '1';
$handler->display->display_options['filters']['status']['group'] = 1;
$handler->display->display_options['filters']['status']['expose']['operator'] = FALSE;
/* Filter criterion: Content: Promoted to front page */
$handler->display->display_options['filters']['promote']['id'] = 'promote';
$handler->display->display_options['filters']['promote']['table'] = 'node';
$handler->display->display_options['filters']['promote']['field'] = 'promote';
$handler->display->display_options['filters']['promote']['value'] = '1';
$handler->display->display_options['filters']['promote']['group'] = 1;
$handler->display->display_options['filters']['promote']['expose']['operator'] = FALSE;
/* Display: Page */
$handler = $view->new_display('page', 'Page', 'page');
$handler->display->display_options['path'] = 'frontpage';
/* Display: Feed */
$handler = $view->new_display('feed', 'Feed', 'feed');
$handler->display->display_options['defaults']['title'] = FALSE;
$handler->display->display_options['title'] = 'Front page feed';
$handler->display->display_options['pager']['type'] = 'some';
$handler->display->display_options['style_plugin'] = 'rss';
$handler->display->display_options['row_plugin'] = 'node_rss';
$handler->display->display_options['path'] = 'rss.xml';
$handler->display->display_options['displays'] = array(
'default' => 'default',
'page' => 'page',
);
$handler->display->display_options['sitename_title'] = '1';
$translatables['frontpage'] = array(
t('Master'),
t('more'),
t('Apply'),
t('Reset'),
t('Sort by'),
t('Asc'),
t('Desc'),
t('Items per page'),
t('- All -'),
t('Offset'),
t('« first'),
t('‹ previous'),
t('next ›'),
t('last »'),
t('Products'),
t('Title'),
t('Page'),
t('Feed'),
t('Front page feed'),
);
I've had this issue on a site I developed in the past. Drupal Commerce seems to be fussy when it comes to permissions.
I know of two routes you can follow to resolve this:
Edit your view. Under "Advanced", select "Query Settings", and tick "Disable SQL rewriting". Only do this if the view doesn't display sensitive information. Make sure you add a filter that checks to see if "Commerce Product: Status" is true, or you'll display unpublished products
Give the Anonymous user the "View any product of any type" permission.
I try to add new node with unpublished.
I set the status = 0;
but when check this node the status = 1;
this code.
$node = new StdClass();
$node->type = 'article'; //giving it type
$node->title = $article->headline; //gives title
$node->body = $article->body; //gives body
$node->field_abstract[0]['value'] = $article->summary;
$node->field_is_syndigate[0]['value'] = 1;
$node->field_syndigate_first_time[0]['value'] = 1;
$node->language = $language->language; //'en' or 'ar'
$node->comment = 2; //read&write comment
//$node->created = $article->parsed_at;
$node->created = '';
$node->changed = $node->created;
$node->status = 0;
$node->promote = 0;
$node->sticky = 0;
$node->format = 4; // Editor Filtered HTML
$node->uid = $user->uid;
//$node->field_attribution[0]['value'] = $article->copyright; // attribution
$attribution = '';
if($article->logo_path){
$attribution = '<img src="http://pub.syndigate.info/logos/small/'.$article->title_id.'.png" title="'.$article->title_name.'" border="0" />';
if($article->website){
$attribution = ''.$attribution.'';
}
$attribution .= ' ';
}
$attribution .= $article->copyright;
$node->field_attribution[0]['value'] = $attribution; // attribution
$node->field_source[0]['value'] = $article->title_id; // source
node_save($node);
How can save the node as unpublished.
When creating a node programmatically, you need to set
$node->is_new = TRUE;
And if you are setting the $node->created to an empty value, I would suggest to get rid of this line from your script, node_save() will take care of it. Same for $node->changed as you give the same value, just delete this line from your script as well
hope this help
I am using the below code in the block visibilty settings, to only show the block if the user is a member, and not the admin.
What can I add to further filter it down to type of Organic Group Node.
i.o.w Only display if the currnt group being viewed = Organic Group Node Type X
<?php
$in_og = FALSE;
if (module_exists('og')){
$in_og = FALSE;
$group_node = og_get_group_context();
$gid02 = $group_node->nid;
$gid = (int)$gid02;
if ($gid02 == null) $gid = 0;
if (og_is_group_member($group_node)) $in_og = TRUE;
if (og_is_group_admin($group_node)) $in_og = FALSE;
if ($gid == 0) $in_og = FALSE;
}
return $in_og;
thanks
Maybe something like"
<?php
$in_og = FALSE;
$right_group = FALSE;
if (module_exists('og')) {
// get OG $group_node
$group_node = og_get_group_context();
if ($group_node->type == 'type-x') {
// we have the correct group type
$right_group = TRUE;
}
$gid = $group_node->nid;
if (og_is_group_member($group_node)) {
// show to members
$in_og = TRUE;
}
if (og_is_group_admin($group_node)) {
// hide from admins
$in_og = FALSE;
}
}
return $in_og && $right_group;
?>