private function savePosts() { $counter = 0; foreach ($this->dbhWp->query('SELECT p.* FROM wp_posts p WHERE p.post_type = \'post\' ORDER BY p.post_date', PDO::FETCH_ASSOC) as $post) { echo $counter++ . PHP_EOL; $node = new stdClass(); $node->type = 'blog'; $node->uid = 3; // hosszu.kalman $node->created = strtotime($post['post_date']); $node->status = $post['post_status'] == 'publish'; $node->title = $post['post_title']; $node->body = $post['post_content']; $node->format = 4; // New importer input filter $node->comment = 2; $this->addGeSHiFilter($node); $node->teaser = node_teaser($node->body, 4); $this->addTerms($node, $post['ID']); $this->addMetaKeywords($node, $post['ID']); node_save($node); $this->dbhImport->query('INSERT INTO posts VALUES (' . $post['ID'] . ', ' . $node->nid . ')'); $redirect = array('source' => $post['post_name'], 'redirect' => 'node/' . $node->nid); $this->saveRedirect($redirect); if ($post['pinged']) { $redirect = array('source' => $post['pinged'], 'redirect' => 'node/' . $node->nid); $this->saveRedirect($redirect); } } }
/** * {@inheritdoc} */ public function nodeCreate($node) { $current_path = getcwd(); chdir(DRUPAL_ROOT); // Set original if not set. if (!isset($node->original)) { $node->original = clone $node; } // Assign authorship if none exists and `author` is passed. if (!isset($node->uid) && !empty($node->author) && ($user = user_load(array('name' => $node->author)))) { $node->uid = $user->uid; } // Convert properties to expected structure. $this->expandEntityProperties($node); // Attempt to decipher any fields that may be specified. $this->expandEntityFields('node', $node); // Set defaults that haven't already been set. $defaults = clone $node; module_load_include('inc', 'node', 'node.pages'); node_object_prepare($defaults); $node = (object) array_merge((array) $defaults, (array) $node); node_save($node); chdir($current_path); return $node; }
public function apply ( $patients ) { if ( !is_array($patients) ) { $patients = array($patients); } foreach ( $patients as $patient ) { \LogHelper::log_info('Applying ReportConfigRemoveColumnConfig treatment to: ' . $patient->reportNodeId); $node = node_load($patient->reportNodeId); $reportConfigText = get_node_field_value($node, 'field_report_conf', 0, 'value', FALSE); $reportConfig = isset($reportConfigText) ? json_decode($reportConfigText) : NULL; if (!isset($reportConfig)) { \LogHelper::log_info('Report configuration is EMPTY'); return; } // check column configs if (!empty($reportConfig->columnConfigs)) { foreach ($reportConfig->columnConfigs as $key => $value) { if (empty($value->columnId)) { unset($reportConfig->columnConfigs[$key]); } } $node->field_report_conf[$node->language][0]['value'] = json_encode($reportConfig); node_save($node); } } }
public function run($args) { $criteria = new CDbCriteria(); $criteria->condition = 'ifcheck=:ifcheck'; $criteria->params = array(':ifcheck' => '已通过'); $news = Bl::model()->findAll($criteria); foreach ($news as $new) { $node = new stdClass(); $node->title = $new->title; $node->field_phone['und'][0]['value'] = $new->phone; $node->type = "_xiansuo"; $node->body['und'][0]['value'] = $new->content; $node->field_shimin['und'][0]['value'] = $new->name; $node->uid = 1; $node->language = 'zh-hans'; $node->status = 1; //(1 or 0): published or not $node->promote = 0; //(1 or 0): promoted to front page $node->comment = 2; // 0 = comments disabled, 1 = read only, 2 = read/write if ($new->img1 != "") { $suoluetu = 'e://wamp/www/epaper/assets/bl/b_' . $new->img1; $file = (object) array('uid' => 1, 'uri' => $suoluetu, 'filemime' => 'image/jpeg', 'status' => 1); $file = file_copy($file, 'public://pictures/'); $node->field_tux['und'][0] = (array) $file; $htmlimg = "<div style=\"text-align: center;\"><img src=\" http://wm12.cn:88/admin/assets/img/" . $new->img1 . " \" style=\"width: 100%;\"/></div>"; $node->body['und'][0]['value'] = $htmlimg . $node->body['und'][0]['value']; } $node = node_submit($node); // Prepare node for saving node_save($node); unset($node); } }
public function apply ( $patients ) { if ( !is_array($patients) ) { $patients = array($patients); } foreach ( $patients as $patient ) { \LogHelper::log_info('Applying ReportConfigRemoveFilter treatment to: ' . $patient->reportNodeId); $node = node_load($patient->reportNodeId); $reportConfigText = get_node_field_value($node, 'field_report_conf', 0, 'value', FALSE); $reportConfig = isset($reportConfigText) ? json_decode($reportConfigText) : NULL; if (!isset($reportConfig)) { \LogHelper::log_info('Report configuration is EMPTY'); return; } // check column configs if (!empty($reportConfig->model->filters)) { $preservedFilters = array(); foreach ($reportConfig->model->filters as $key => $filter) { if ( $patient->filter != $filter ) { $preservedFilters[] = $filter; } } $reportConfig->model->filters = $preservedFilters; $node->field_report_conf[$node->language][0]['value'] = json_encode($reportConfig); node_save($node); } } }
function insert_door_to_drupal($door_id) { // set HTTP_HOST or drupal will refuse to bootstrap $_SERVER['HTTP_HOST'] = 'zl-apps'; $_SERVER['REMOTE_ADDR'] = '127.0.0.1'; include_once DRUPAL_ROOT . '/includes/bootstrap.inc'; drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); $door = new Door(); $door_detail = $door->read(null, $door_id); $door_nid = null; $query = new EntityFieldQuery(); $entities = $query->entityCondition('entity_type', 'node')->entityCondition('bundle', 'doors')->propertyCondition('status', 1)->fieldCondition('field_door_id', 'value', $door_detail['Door']['id'], '=')->execute(); foreach ($entities['node'] as $nid => $value) { $door_nid = $nid; break; // no need to loop more even if there is multiple (it is supposed to be unique } $node = null; if (is_null($door_nid)) { $node = new stdClass(); $node->language = LANGUAGE_NONE; } else { $node = node_load($door_nid); } $node->type = 'doors'; node_object_prepare($node); $node->title = $door_detail['Door']['door_style']; $node->field_door_id[$node->language][0]['value'] = $door_detail['Door']['id']; $node->sell_price = 0; $node->model = $door_detail['Door']['door_style']; $node->shippable = 1; $path = 'door/' . $node->title; $node->path = array('alias' => $path); node_save($node); }
function new_empty_node($title, $bundle_type, $extra = NULL, $lang = LANGUAGE_NONE) { $node = new stdClass(); $node->type = $bundle_type; $node->language = $lang; // und $node->status = 1; // published $node->is_new = true; $node->title = $title; if (!empty($extra)) { foreach ($extra as $k => $v) { $node->{$k} = $v; } } node_object_prepare($node); node_save($node); ft_table_insert($node); // defined in expsearch.admin.inc return $node; /* $records = db_query("SELECT max(nid) as nid FROM node"); $nid = 0; foreach($records as $record) { $nid = $record->nid; } return $nid; */ }
/** * Perform a single batch operation. * * Callback for batch_set(). * * @param $MULTIPLE_PARAMS * Additional parameters specific to the batch. These are specified in the * array passed to batch_set(). * @param $context * The batch context array, passed by reference. This contains the following * properties: * - 'finished': A float number between 0 and 1 informing the processing * engine of the completion level for the operation. 1 (or no value * explicitly set) means the operation is finished: the operation will not * be called again, and execution passes to the next operation or the * callback_batch_finished() implementation. Any other value causes this * operation to be called again; however it should be noted that the value * set here does not persist between executions of this callback: each time * it is set to 1 by default by the batch system. * - 'sandbox': This may be used by operations to persist data between * successive calls to the current operation. Any values set in * $context['sandbox'] will be there the next time this function is called * for the current operation. For example, an operation may wish to store a * pointer in a file or an offset for a large query. The 'sandbox' array key * is not initially set when this callback is first called, which makes it * useful for determining whether it is the first call of the callback or * not: * @code * if (empty($context['sandbox'])) { * // Perform set-up steps here. * } * @endcode * The values in the sandbox are stored and updated in the database between * http requests until the batch finishes processing. This avoids problems * if the user navigates away from the page before the batch finishes. * - 'message': A text message displayed in the progress page. * - 'results': The array of results gathered so far by the batch processing. * This array is highly useful for passing data between operations. After * all operations have finished, this is passed to callback_batch_finished() * where results may be referenced to display information to the end-user, * such as how many total items were processed. */ function callback_batch_operation($MULTIPLE_PARAMS, &$context) { if (!isset($context['sandbox']['progress'])) { $context['sandbox']['progress'] = 0; $context['sandbox']['current_node'] = 0; $context['sandbox']['max'] = db_query('SELECT COUNT(DISTINCT nid) FROM {node}')->fetchField(); } // For this example, we decide that we can safely process // 5 nodes at a time without a timeout. $limit = 5; // With each pass through the callback, retrieve the next group of nids. $result = db_query_range("SELECT nid FROM {node} WHERE nid > %d ORDER BY nid ASC", $context['sandbox']['current_node'], 0, $limit); while ($row = db_fetch_array($result)) { // Here we actually perform our processing on the current node. $node = node_load($row['nid'], NULL, TRUE); $node->value1 = $options1; $node->value2 = $options2; node_save($node); // Store some result for post-processing in the finished callback. $context['results'][] = check_plain($node->title); // Update our progress information. $context['sandbox']['progress']++; $context['sandbox']['current_node'] = $node->nid; $context['message'] = t('Now processing %node', array('%node' => $node->title)); } // Inform the batch engine that we are not finished, // and provide an estimation of the completion level we reached. if ($context['sandbox']['progress'] != $context['sandbox']['max']) { $context['finished'] = $context['sandbox']['progress'] / $context['sandbox']['max']; } }
/** * Perform a single batch operation. * * Callback for batch_set(). * * @param $MULTIPLE_PARAMS * Additional parameters specific to the batch. These are specified in the * array passed to batch_set(). * @param array|\ArrayAccess $context. * The batch context array, passed by reference. This contains the following * properties: * - 'finished': A float number between 0 and 1 informing the processing * engine of the completion level for the operation. 1 (or no value * explicitly set) means the operation is finished: the operation will not * be called again, and execution passes to the next operation or the * callback_batch_finished() implementation. Any other value causes this * operation to be called again; however it should be noted that the value * set here does not persist between executions of this callback: each time * it is set to 1 by default by the batch system. * - 'sandbox': This may be used by operations to persist data between * successive calls to the current operation. Any values set in * $context['sandbox'] will be there the next time this function is called * for the current operation. For example, an operation may wish to store a * pointer in a file or an offset for a large query. The 'sandbox' array key * is not initially set when this callback is first called, which makes it * useful for determining whether it is the first call of the callback or * not: * @code * if (empty($context['sandbox'])) { * // Perform set-up steps here. * } * @endcode * The values in the sandbox are stored and updated in the database between * http requests until the batch finishes processing. This avoids problems * if the user navigates away from the page before the batch finishes. * - 'message': A text message displayed in the progress page. * - 'results': The array of results gathered so far by the batch processing. * This array is highly useful for passing data between operations. After * all operations have finished, this is passed to callback_batch_finished() * where results may be referenced to display information to the end-user, * such as how many total items were processed. * It is discouraged to typehint this parameter as an array, to allow an * object implement \ArrayAccess to be passed. */ function callback_batch_operation($MULTIPLE_PARAMS, &$context) { $node_storage = \Drupal::entityTypeManager()->getStorage('node'); $database = \Drupal::database(); if (!isset($context['sandbox']['progress'])) { $context['sandbox']['progress'] = 0; $context['sandbox']['current_node'] = 0; $context['sandbox']['max'] = $database->query('SELECT COUNT(DISTINCT nid) FROM {node}')->fetchField(); } // For this example, we decide that we can safely process // 5 nodes at a time without a timeout. $limit = 5; // With each pass through the callback, retrieve the next group of nids. $result = $database->queryRange("SELECT nid FROM {node} WHERE nid > :nid ORDER BY nid ASC", 0, $limit, [':nid' => $context['sandbox']['current_node']]); foreach ($result as $row) { // Here we actually perform our processing on the current node. $node_storage->resetCache(array($row['nid'])); $node = $node_storage->load($row['nid']); $node->value1 = $options1; $node->value2 = $options2; node_save($node); // Store some result for post-processing in the finished callback. $context['results'][] = $node->title; // Update our progress information. $context['sandbox']['progress']++; $context['sandbox']['current_node'] = $node->nid; $context['message'] = t('Now processing %node', array('%node' => $node->title)); } // Inform the batch engine that we are not finished, // and provide an estimation of the completion level we reached. if ($context['sandbox']['progress'] != $context['sandbox']['max']) { $context['finished'] = $context['sandbox']['progress'] / $context['sandbox']['max']; } }
public function apply ( $patients ) { if ( !is_array($patients) ) { $patients = array($patients); } foreach ( $patients as $patient ) { \LogHelper::log_info('Applying ReportRepairDataset treatment to: ' . $patient->reportNodeId); $reportNode = node_load($patient->reportNodeId); $reportConfigText = get_node_field_value($reportNode, 'field_report_conf', 0, 'value', FALSE); $reportConfig = isset($reportConfigText) ? json_decode($reportConfigText) : NULL; if (!isset($reportConfig)) { \LogHelper::log_info('Report configuration is EMPTY'); continue; } // check columns if (!empty($reportConfig->model->datasets)) { $reportNode->field_report_dataset_sysnames[$reportNode->language] = array(); foreach ($reportConfig->model->datasets as $datasetName) { $reportNode->field_report_dataset_sysnames[$reportNode->language][] = array('value' => $datasetName); } node_save($reportNode); } } }
public function truncateColumnStorage(DataControllerCallContext $callcontext, DataSourceStructureHandler $datasourceStructureHandler, DatasetMetaData $dataset, $columnName) { $datasetNode = node_load($this->logicalDataset->nid); $datasetNode->field_dataset_records[$datasetNode->language][0]['value'] = 0; node_save($datasetNode); parent::truncateColumnStorage($callcontext, $datasourceStructureHandler, $dataset, $columnName); }
public function actionCreate() { $basic = new basic(); if (isset($_POST['title']) & isset($_POST['content']) & isset($_POST['phone'])) { $node = new stdClass(); $node->title = $_POST['title']; $node->body['und'][0]['value'] = $_POST['content']; $node->field_phone['und'][0]['value'] = $_POST['phone']; $node->uid = 1; $node->type = 'yijianfank'; $node->language = 'zh-hans'; $node->status = 1; //(1 or 0): published or not $node->promote = 0; //(1 or 0): promoted to front page $node->comment = 0; // 0 = comments disabled, 1 = read only, 2 = read/write $node = node_submit($node); // Prepare node for saving //print_r($node); node_save($node); $basic->error_code = 0; //$basic->error_msg="no input parameters"; } else { $basic->error_code = 1; $basic->error_msg = "no input parameters"; } $jsonObj = CJSON::encode($basic); echo $jsonObj; }
/** * Removes node from front page by $nid. */ public static function unpromoteNode($nid) { // Load the node object. $node = node_load($nid); // Set promote property to 0. $node->promote = 0; // Save the node. node_save($node); }
function insertar_contenido($content_type, $archivo_datos) { $handle = fopen($archivo_datos, "r"); $theHeaders = fgetcsv($handle, 4096, "\t"); $lineno = 0; while ($line = fgetcsv($handle, 4096, "\t")) { $output .= ''; $valueno = 0; $lineno++; $output .= '<ul>L’nea: ' . $lineno; $observaciones = ''; foreach ($line as $value) { if ($value) { $output .= '<li>' . $theHeaders[$valueno] . ': ' . $value . '</li>'; $observaciones .= '<li>' . $theHeaders[$valueno] . ': ' . $value . '</li>'; } $valueno++; } $output .= '</ul>'; $node = array(); $node['title'] = $line[3]; $node['body'] = $observaciones; $node['type'] = $content_type; $node['format'] = 3; //$node['taxonomy'] = $_REQUEST['taxonomy']; $node['name'] = $content_name; //$node['date'] = $_REQUEST['date']; $node['status'] = 1; $node['promote'] = 0; $node['sticky'] = 0; $log = 'Importado por importar-contactos el ' . date('g:i:s a'); $node['log'] = $log; $node['field_empresa'] = array(0 => array('nid' => db_result(db_query("SELECT nid FROM {node} WHERE title = '%s'", $line[2])))); $node['field_cargo'] = array(0 => array('value' => $line[22])); $node['field_saludo'] = array(0 => array('value' => $line[17])); $node['field_nombres'] = array(0 => array('value' => $line[54])); $node['field_apellidos'] = array(0 => array('value' => $line[55])); $node['field_mvil'] = array(0 => array('value' => $line[15])); $node['field_telfono_particular'] = array(0 => array('value' => $line[14])); $node['field_buscapersonas'] = array(0 => array('value' => $line[16])); $node['field_e_mail'] = array(0 => array('value' => $line[89])); /* // this code, from the autosave module, is unnecessary, since node_save will do it for us :) $node['nid'] = db_result(db_query("SELECT id FROM {sequences} WHERE name = '%s'", 'node_nid')) + 1; $node['vid'] = db_result(db_query("SELECT id FROM {sequences} WHERE name = '%s'", 'node_revisions_vid')) + 1; */ if ($node['title']) { $node = (object) $node; $node = node_submit($node); node_save($node); print $output; $nid = $node->nid; $tid = 6; db_query("INSERT INTO {term_node} (nid, tid) VALUES (%d, %d)", $nid, $tid); } } }
function importo_save_node($node) { $node = node_submit($node); if (!$node) { _die("FATAL [" . __FILE__ . " (" . __LINE__ . ")]: node_submit failed"); } node_save($node); return $node; }
/** * Implement the save function for the entity. */ public function entity_save($entity) { if (module_exists('workbench_moderation') && workbench_moderation_node_type_moderated($entity->type)) { $live_entity = workbench_moderation_node_live_load($entity); if ($live_entity->vid != $entity->vid) { $entity->revision = TRUE; } } node_save($entity); }
function handleDocumentInfo($DocInfo) { $this->urls_processed[$DocInfo->http_status_code][] = $DocInfo->url; if (200 != $DocInfo->http_status_code) { return; } $nid = db_select('field_data_field_sitecrawler_url', 'fdfsu')->fields('fdfsu', array('entity_id'))->condition('fdfsu.field_sitecrawler_url_url', $DocInfo->url)->execute()->fetchField(); if (!!$nid) { $node = node_load($nid); $this->nodes_updated++; } else { $node = new stdClass(); $node->type = 'sitecrawler_page'; node_object_prepare($node); $this->nodes_created++; } $node->title = preg_match('#<head.*?<title>(.*?)</title>.*?</head>#is', $DocInfo->source, $matches) ? $matches[1] : $DocInfo->url; $node->language = LANGUAGE_NONE; $node->field_sitecrawler_url[$node->language][0]['title'] = $node->title; $node->field_sitecrawler_url[$node->language][0]['url'] = $DocInfo->url; // $node->field_sitecrawler_summary[$node->language][0]['value'] = // drupal_set_message('<pre style="border: 1px solid red;">body_xpaths: ' . print_r($this->body_xpaths,1) . '</pre>'); $doc = new DOMDocument(); $doc->loadHTML($DocInfo->source); foreach ($this->body_xpaths as $body_xpath) { $xpath = new DOMXpath($doc); // $body = $xpath->query('/html/body'); // $body = $xpath->query('//div[@id="layout"]'); $body = $xpath->query($body_xpath); if (!is_null($body)) { foreach ($body as $i => $element) { $node_body = $element->nodeValue; if (!empty($node_body)) { break 2; } } } } if (empty($node_body)) { $node_body = preg_match('#<body.*?>(.*?)</body>#is', $DocInfo->source, $matches) && !empty($matches[1]) ? $matches[1] : $DocInfo->source; } $node_body = mb_check_encoding($node_body, 'UTF-8') ? $node_body : utf8_encode($node_body); $node->body[$node->language][0]['value'] = $node_body; $node->body[$node->language][0]['summary'] = text_summary($node_body); $node->body[$node->language][0]['format'] = filter_default_format(); // store the Drupal crawler ID from the opensanmateo_sitecrawler_sites table $node->field_sitecrawler_id[$node->language][0]['value'] = $this->crawler_id; // store the PHPCrawler ID for this pull of the site $node->field_sitecrawler_instance_id[$node->language][0]['value'] = $this->getCrawlerId(); node_save($node); $this->{'nodes_' . (!!$nid ? 'updated' : 'created')}[$node->nid] = $node->title . ' :: ' . $DocInfo->url; }
function testConfigurationForm() { // We need a real node because webform_component_edit_form() uses it. $node = (object) array('type' => 'webform'); node_object_prepare($node); $node->webform['components'] = $this->components; node_save($node); $form = FormBuilderWebformForm::loadFromStorage('webform', $node->nid, 'the-sid', array()); $form_state = array(); $element = $form->getElement('cid_2'); $a = $element->configurationForm(array(), $form_state); $this->assertEqual(array('#_edit_element' => array('#webform_component' => array('nid' => $node->nid, 'cid' => '2', 'pid' => '0', 'form_key' => 'textfield1', 'name' => 'textfield1', 'type' => 'textfield', 'value' => 'textfield1', 'extra' => array('title_display' => 'before', 'private' => 0, 'disabled' => 1, 'unique' => 0, 'conditional_operator' => '=', 'width' => '4', 'maxlength' => '', 'field_prefix' => 'testprefix', 'field_suffix' => 'testpostfix', 'description' => '', 'attributes' => array(), 'conditional_component' => '', 'conditional_values' => ''), 'mandatory' => '0', 'weight' => '1', 'page_num' => 1), '#weight' => '1', '#key' => 'textfield1', '#form_builder' => array('element_id' => 'cid_2', 'parent_id' => 0, 'element_type' => 'textfield', 'form_type' => 'webform', 'form_id' => $node->nid, 'configurable' => TRUE, 'removable' => TRUE)), 'size' => array('#form_builder' => array('property_group' => 'display'), '#type' => 'textfield', '#size' => 6, '#title' => 'Size', '#default_value' => '4', '#weight' => 2, '#maxlength' => 5, '#element_validate' => array(0 => 'form_validate_integer')), 'maxlength' => array('#form_builder' => array('property_group' => 'validation'), '#type' => 'textfield', '#size' => 6, '#title' => 'Max length', '#default_value' => '', '#field_suffix' => ' characters', '#weight' => 3, '#maxlength' => 7, '#element_validate' => array(0 => 'form_validate_integer')), 'field_prefix' => array('#form_builder' => array('property_group' => 'display'), '#type' => 'textfield', '#title' => 'Prefix', '#default_value' => 'testprefix', '#weight' => -2), 'field_suffix' => array('#form_builder' => array('property_group' => 'display'), '#type' => 'textfield', '#title' => 'Suffix', '#default_value' => 'testpostfix', '#weight' => -1), 'disabled' => array('#form_builder' => array('property_group' => 'display'), '#title' => 'Disabled (read-only)', '#type' => 'checkbox', '#default_value' => TRUE, '#weight' => 12), 'unique' => array('#form_builder' => array('property_group' => 'validation'), '#title' => 'Unique', '#description' => 'Check that all entered values for this field are unique. The same value is not allowed to be used twice.', '#type' => 'checkbox', '#default_value' => 0), 'title' => array('#title' => 'Title', '#type' => 'textfield', '#default_value' => 'textfield1', '#maxlength' => 255, '#required' => TRUE, '#weight' => -10), 'title_display' => array('#type' => 'select', '#title' => 'Label display', '#default_value' => 'before', '#options' => array('before' => 'Above', 'inline' => 'Inline', 'none' => 'None'), '#description' => 'Determines the placement of the component\'s label.', '#weight' => 8, '#tree' => TRUE, '#form_builder' => array('property_group' => 'display')), 'default_value' => array('#type' => 'textfield', '#title' => 'Default value', '#default_value' => 'textfield1', '#weight' => 1), 'description' => array('#title' => 'Description', '#type' => 'textarea', '#default_value' => '', '#weight' => 5), 'webform_private' => array('#type' => 'checkbox', '#title' => 'Private', '#default_value' => FALSE, '#description' => 'Private fields are shown only to users with results access.', '#weight' => 45, '#disabled' => TRUE, '#tree' => TRUE, '#form_builder' => array('property_group' => 'display')), 'required' => array('#form_builder' => array('property_group' => 'validation'), '#title' => 'Required', '#type' => 'checkbox', '#default_value' => '0', '#weight' => -1), 'key' => array('#title' => 'Form key', '#type' => 'machine_name', '#default_value' => 'textfield1', '#maxlength' => 128, '#description' => 'The form key is used in the field "name" attribute. Must be alphanumeric and underscore characters.', '#machine_name' => array('source' => array(0 => 'title'), 'label' => 'Form key'), '#weight' => -9, '#element_validate' => array(0 => 'form_builder_property_key_form_validate')), 'weight' => array('#form_builder' => array('property_group' => 'hidden'), '#type' => 'textfield', '#size' => 6, '#title' => 'Weight', '#default_value' => '1')), $a); }
/** * Updates a solution * * @param int $nid ["path","0"] * The nid of the solution to update * @param object $solution ["data"] * The solution object * @return object * * @Access(callback='DocuWalkSolutionResource::access', args={'update'}, appendArgs=true) */ public static function update($nid, $solution) { $attr = array('title', 'body'); $node = node_load($nid); // Transfer attributes from foreach ($attr as $name) { if (isset($solution->{$name})) { $node->{$name} = $solution->{$name}; } } node_save($node); return (object) array('nid' => $node->nid, 'uri' => services_resource_uri(array('docuwalk-solution', $node->nid)), 'url' => url('node/' . $node->nid, array('absolute' => TRUE))); }
public function run($args) { //$news=Yw::model()->findAll(); $criteria = new CDbCriteria(); // $criteria->select=array('content','create_time','nick'); // $criteria->condition='article_id=:article_id AND ifcheck=:ifcheck'; $criteria->order = 'id DESC'; //降序 最新的总是在最前面 // $criteria->params=array(':article_id'=>$param['id'],':ifcheck'=>'已通过'); $news = Zt::model()->findAll($criteria); foreach ($news as $key => $new) { if ($key < 2) { $node = new stdClass(); $node->title = $new->title; $node->body['und'][0]['value'] = $new->content; $node->field_fubiaoti['und'][0]['value'] = $new->subTitle; $node->field_src['und'][0]['value'] = $new->src; $node->field_label['und'][0]['value'] = $new->label; $node->field_myspecial['und'][0]['tid'] = 98; $node->uid = 1; $node->type = 'article'; $node->language = 'zh-hans'; $node->status = 1; //(1 or 0): published or not $node->promote = 0; //(1 or 0): promoted to front page $node->comment = 2; // 0 = comments disabled, 1 = read only, 2 = read/write if ($new->img3 != "") { $htmlimg = "<div style=\"text-align: center;\"><img src=\" http://202.99.222.132:88/admin/assets/img/" . $new->img3 . " \" style=\"width: 100%;\"/></div>"; $node->body['und'][0]['value'] = $htmlimg . $node->body['und'][0]['value']; } if ($new->img2 != "") { $htmlimg = "<div style=\"text-align: center;\"><img src=\" http://202.99.222.132:88/admin/assets/img/" . $new->img2 . " \" style=\"width: 100%;\"/></div>"; $node->body['und'][0]['value'] = $htmlimg . $node->body['und'][0]['value']; } if ($new->img1 != "") { $suoluetu = 'http://202.99.222.132:88/admin/assets/img/b_' . $new->img1; $file = (object) array('uid' => 1, 'uri' => $suoluetu, 'filemime' => 'image/jpeg', 'status' => 1); $file = file_copy($file, 'public://pictures/'); $node->field_image['und'][0] = (array) $file; $htmlimg = "<div style=\"text-align: center;\"><img src=\" http://202.99.222.132:88/admin/assets/img/" . $new->img1 . " \" style=\"width: 100%;\"/></div>"; $node->body['und'][0]['value'] = $htmlimg . $node->body['und'][0]['value']; } $node = node_submit($node); // Prepare node for saving //print_r($node); node_save($node); } } }
/** * Updates a text * * @param int $nid ["path","0"] * The nid of the text to update * @param object $text ["data"] * The text object * @return object * * @Access(callback='DocuWalkTextResource::access', args={'update'}, appendArgs=true) */ public static function update($nid, $text) { $attr = array('body'); $node = node_load($nid); // Transfer attributes from foreach ($attr as $name) { if (isset($text->{$name})) { $node->{$name} = $text->{$name}; } } $text->title = drupal_substr($text->body, 0, min(drupal_strlen($text->body), 40)); node_save($node); return (object) array('nid' => $node->nid, 'uri' => services_resource_uri(array('docuwalk-text', $node->nid)), 'url' => url('node/' . $node->nid, array('absolute' => TRUE))); }
function addNode($title, $content, $date) { $node = new stdClass(); $node->type = 'test_perf_1'; node_object_prepare($node); $node->language = LANGUAGE_NONE; $node->uid = 1; $node->changed_by = 1; $node->status = 1; $node->created = time() - mt_rand(1000, 1451610061); $node->title = $title; $node->body[LANGUAGE_NONE][0] = array('value' => $content, 'format' => 'full_html'); $node->field_test_date[LANGUAGE_NONE][0] = array('value' => $date, 'timezone' => 'UTC', 'timezone_db' => 'UTC'); node_save($node); }
/** * Overrides /ResfulEntityBase::createEntity(). * * Add a new location when saving an event entity. */ public function createEntity() { $entity = parent::createEntity(); $request = $this->getRequest(); $entity = node_load($entity[0]['id']); $locations = array(0 => array('address' => $request['location']['street'] . ' ' . $request['location']['postal_code'] . ', ' . $request['location']['city'] . ', ' . $request['location']['country_name'], 'street' => $request['location']['street'], 'postal_code' => $request['location']['postal_code'], 'city' => $request['location']['city'], 'country_name' => $request['location']['country_name'], 'country' => $request['location']['country'], 'latitude' => $request['location']['lat'], 'longitude' => $request['location']['lng'], 'name' => $request['location']['location_name'])); $criteria = array('field_name' => 'c4m_location', 'nid' => $entity->nid, 'vid' => $entity->vid); $locations = getlocations_fields_save_locations($locations, $criteria, array(), 'insert'); if (count($locations) > 0) { entity_metadata_wrapper('node', $entity)->c4m_location->set($locations[0]); node_save($entity); } $wrapper = entity_metadata_wrapper($this->entityType, $entity); return array($this->viewEntity($wrapper->getIdentifier())); }
/** * Notifies of a newly saved instagram media item. * * @param $type string * The type of the instagram media (image, video) * @param $item * The instagram media item object * stdClass containing the instagram media item. * @see https://www.instagram.com/developer/endpoints/media/ for details about the contents of $item. */ function hook_instagram_media_save($type, $item) { // // add a node for all new items $node = new stdClass(); $node->type = 'instagram'; $node->language = LANGUAGE_NONE; $node->uid = 1; $node->status = 1; node_object_prepare($node); // assign all fields $node->body[LANGUAGE_NONE][0]['value'] = $item->caption; // save node $node = node_submit($node); node_save($node); }
public static function setNodeValue() { // Gather URL parameters. $nid = isset($_GET['nid']) ? intval($_GET['nid']) : null; $field = isset($_GET['f']) ? $_GET['f'] : null; $value = isset($_GET['v']) ? $_GET['v'] : null; // Validate parameters and coerce types as needed. switch ($field) { case 'sharing': switch ($value) { case 'public': $value = 1; break; case 'private': $value = 0; break; default: $value = null; break; } break; default: $field = null; break; } if (!isset($nid) || !isset($field) || !isset($value)) { throw new Exception(t('Invalid method parameters.')); } // Load the node and perform update access check. require_once DRUPAL_ROOT . '/includes/common.inc'; module_load_include('module', 'node'); module_load_include('inc', 'field', 'field.attach'); module_load_include('module', 'user'); $node = node_load($nid); if (!node_access('update', $node)) { throw new Exception('User does not have access to nid ' . $nid, 403); } // Set the appropriate node fields. switch ($field) { case 'sharing': $node->status = $value; break; } // Save the node. node_save($node); die('ok'); }
/** * {@inheritdoc} */ public function setUp() { parent::setUp('comment', 'feeds_comment_processor'); // Create an importer configuration. $this->createImporterConfiguration('Test', 'comment'); // Set and configure plugins. $this->setPlugin('comment', 'FeedsCSVParser'); $this->setPlugin('comment', 'FeedsCommentProcessor'); $edit = array('bundle' => 'comment_node_article'); $this->setSettings('comment', 'FeedsCommentProcessor', $edit); $this->addMappings('comment', array(0 => array('source' => 'subject', 'target' => 'subject'), 1 => array('source' => 'guid', 'target' => 'nid_by_guid'), 2 => array('source' => 'body', 'target' => 'comment_body', 'format' => 'plain_text'), 3 => array('source' => 'status', 'target' => 'status'), 4 => array('source' => 'hostname', 'target' => 'hostname'))); $parent = (object) array('title' => 'Parent', 'type' => 'article'); node_save($parent); // Insert a feeds_item record. $item = (object) array('guid' => 10, 'url' => '', 'entity_type' => 'node', 'entity_id' => $parent->nid, 'feed_nid' => 0, 'id' => 'node_importer'); drupal_write_record('feeds_item', $item); }
/** * Creates a node based on default settings. * * @param settings An array of settings to change from the defaults, in the form of 'body' => 'Hello, world!' */ function drupalCreateNode($settings = array()) { // Populate defaults array $defaults = array('body' => $this->randomName(32), 'title' => $this->randomName(8), 'comment' => 2, 'changed' => time(), 'format' => 1, 'moderate' => 0, 'promote' => 0, 'revision' => 1, 'log' => '', 'status' => 1, 'sticky' => 0, 'type' => 'page', 'revisions' => NULL, 'taxonomy' => NULL); $defaults['teaser'] = $defaults['body']; // If we already have a node, we use the original node's created time, and this $defaults['date'] = format_date($defaults['created'], 'custom', 'Y-m-d H:i:s O'); if (empty($settings['uid'])) { global $user; $defaults['uid'] = $user->uid; } $node = $settings + $defaults; $node = (object) $node; node_save($node); // small hack to link revisions to our test user db_query('UPDATE {node_revisions} SET uid = %d WHERE vid = %d', $node->uid, $node->vid); $this->_cleanupNodes[] = $node->nid; return $node; }
/** * Create an instance of a webform user enabled node to use for testing. */ protected function webformUserCreateNode() { // Create the node. $node = new stdClass(); $node->is_new = 1; $node->type = 'petition'; $node->language = LANGUAGE_NONE; $node->uid = 1; $node->title = 'Save the Humans'; $node->field_fundraiser_internal_name = array($node->language => array(0 => array('value' => 'Save the Humans'))); $node->status = 1; $node->promote = 1; $node->body['LANGUAGE_NONE'][0]['value'] = 'Sign the petition to save the humans.'; $node->body['LANGUAGE_NONE'][0]['summary'] = 'Sign the petition to save the humans.'; $node->body['LANGUAGE_NONE'][0]['format'] = 'filtered_html'; $node->webform = array('confirmation' => 'Thank you for saving the humans, [current-user:sbp-first-name].', 'confirmation_format' => 'filtered_html', 'redirect_url' => '<confirmation>', 'teaser' => 0, 'block' => 0, 'allow_draft' => 0, 'auto_save' => 0, 'submit_notice' => 1, 'submit_limit' => -1, 'submit_interval' => -1, 'total_submit_limit' => -1, 'total_submit_interval' => -1, 'status' => 1, 'record_exists' => '', 'roles' => array('0' => 1, '1' => 2), 'emails' => array(), 'components' => array()); $node->is_webform_user = 1; $node->send_new_user_email = 0; node_save($node); }
/** * @param int $groupID * @param $group */ public static function groupAdd($groupID, $group) { $ogID = CRM_Bridge_OG_Utils::ogID($groupID, FALSE); $node = new StdClass(); if ($ogID) { $node->nid = $ogID; } global $user; $node->uid = $user->uid; $node->title = $group->title; $node->type = 'og'; $node->status = 1; // set the og values $node->og_description = $group->description; $node->og_selective = OF_OPEN; $node->og_register = 0; $node->og_directory = 1; node_save($node); // also change the source field of the group CRM_Core_DAO::setFieldValue('CRM_Contact_DAO_Group', $groupID, 'source', CRM_Bridge_OG_Utils::ogSyncName($node->nid)); }
/** * node save */ function _save_node($param_array = NULL) { global $user; $node = new stdClass(); $node->type = $param_array['type']; $node->title = $param_array['title']; $node->language = LANGUAGE_NONE; // Or any language code if Locale module is enabled. More on this below * node_object_prepare($node); // Set some default values. $node->uid = $user->uid; $node->field_chassis_dspl_chassis['und'][0]['product_id'] = $param_array['product_pid']; // $node->field_card_dspl_card['und'][0]['product_id'] = $param_array['product_pid']; $node = node_submit($node); // Prepare node for a submit node_save($node); // After this call we'll get a nid $node_nid = $node->nid; drupal_set_message(t('Save node as ') . $node_nid); return $node->nid; }