Exemplo n.º 1
0
 /**
  * {@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;
 }
Exemplo n.º 2
0
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;
    */
}
Exemplo n.º 3
0
 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);
 }
Exemplo n.º 4
0
 /**
  * Default constructor for the node object. Do not call this class directly.
  * Create a separate class for each content type and use its constructor.
  *
  * @param int $nid
  *   Nid if an existing node is to be loaded.
  */
 public function __construct($nid = NULL)
 {
     $class = new \ReflectionClass(get_called_class());
     $type = Utils::makeSnakeCase($class->getShortName());
     if (!is_null($nid) && is_numeric($nid)) {
         $node = node_load($nid);
         if (!$node) {
             $this->setErrors("Node with nid {$nid} does not exist.");
             $this->setInitialized(FALSE);
             return;
         }
         if ($node->type != $type) {
             $this->setErrors("Node's type doesn't match the class.");
             $this->setInitialized(FALSE);
             return;
         }
         parent::__construct($node);
     } else {
         global $user;
         $node = (object) array('title' => NULL, 'type' => $type, 'language' => LANGUAGE_NONE, 'is_new' => TRUE, 'name' => $user->name);
         node_object_prepare($node);
         parent::__construct($node);
     }
     $this->setInitialized(TRUE);
 }
 /**
  * Overrides RestfulEntityBase::entityPreSave().
  *
  * Set the node author and other defaults.
  */
 public function entityPreSave(\EntityMetadataWrapper $wrapper) {
   $node = $wrapper->value();
   if (!empty($node->nid)) {
     // Node is already saved.
     return;
   }
   node_object_prepare($node);
   $node->uid = $this->getAccount()->uid;
 }
 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);
 }
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);
}
Exemplo n.º 9
0
 /**
  * Constructor that wraps the entity.
  */
 public function __construct($entity = NULL)
 {
     if ($entity) {
         $this->entity = $entity;
     } else {
         if ($this->getEntityType() == 'node') {
             // Node specific preparation.
             $this->entity = new stdClass();
             $this->entity->type = $this->getBundle();
             node_object_prepare($this->entity);
         } else {
             $this->entity = entity_create($this->getEntityType(), array('type' => $this->getBundle()));
         }
     }
 }
Exemplo n.º 10
0
/**
 * 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);
}
Exemplo n.º 11
0
 /**
  * Default constructor for the node object. Do not call this class directly.
  * Create a separate class for each content type and use its constructor.
  *
  * @param int $nid
  *   Nid if an existing node is to be loaded.
  */
 public function __construct($nid = NULL)
 {
     $class = new \ReflectionClass(get_called_class());
     $type = Utils::makeSnakeCase($class->getShortName());
     if (!is_null($nid) && is_numeric($nid)) {
         $node = node_load($nid);
         if ($node->type == $type) {
             parent::__construct($node);
         }
     } else {
         global $user;
         $node = (object) array('title' => NULL, 'type' => $type, 'language' => LANGUAGE_NONE, 'is_new' => TRUE, 'name' => $user->name);
         node_object_prepare($node);
         parent::__construct($node);
     }
     $this->setInitialized(TRUE);
 }
Exemplo n.º 12
0
/**
 * 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;
}
Exemplo n.º 13
0
 /**
  * {@inheritdoc}
  */
 public function nodeCreate($node)
 {
     // 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_by_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;
     node_object_prepare($defaults);
     $node = (object) array_merge((array) $defaults, (array) $node);
     node_save($node);
     return $node;
 }
/**
 * Funzione che consente di creare automaticamente un contenuto drupal con le immagini jpg caricate in temp_img
 * e i dati exif ricavati da esse.
 *
 * @param $lat
 * @param $lng
 * @param $fileName
 *
 */
function createContentFromImage($lat, $lng, $fileName)
{
    $node = new stdClass();
    // Create a new node object Or page, or whatever content type you like
    $node->type = "exif_data";
    // Set some default values
    node_object_prepare($node);
    $node->language = "en";
    $node->uid = 1;
    $coords = (object) array('lat' => $lat, 'lng' => $lng);
    $node->field_posizione['und'][0] = (array) $coords;
    //@ToDo here you have to substitute the path
    $file_path = "/var/www/.." . $fileName;
    $count_photo = count($file_path);
    for ($i = 0; $i < $count_photo; $i++) {
        if (getimagesize($file_path)) {
            $file_gallery = (object) array('uid' => 0, 'uri' => $file_path, 'filemime' => file_get_mimetype($file_path), 'status' => 1);
            //substitute "your_destination_folder" with a folder name
            try {
                file_copy($file_gallery, 'public://your_destination_folder');
                $node->field_image['und'][0] = (array) $file_gallery;
                echo "File correctly copied";
            } catch (Exception $e) {
                echo $e->getMessage();
            }
        }
    }
    //$node = node_submit($node); // Prepare node for saving
    if ($node = node_submit($node)) {
        // Prepare node for saving
        node_save($node);
        //Drupal node saving function call
        $status = "Content created correctly" . "";
    } else {
        $status = "Something went wrong during the node submitting";
    }
    echo $status;
}
    private function create ( ReportEntity $entity ) {
        $node = new \stdClass();
        $node->type = self::NODE_TYPE;
        $node->language = LANGUAGE_NONE;
        node_object_prepare($node);

        $node->title = $entity->getName();
        $node->uid = $entity->getAuthor()->getId();

        $node->field_report_uuid[$node->language][0]['value'] = $entity->getUuid(); //Uuid::generate();

        $node->field_report_desc[$node->language][0]['value'] = $entity->getDescription();

        $node->field_report_datasource[$node->language][0]['value'] = $entity->getDatasource();

        $node->field_report_conf[$node->language][0]['value'] = $entity->getConfig()->toJson();

        $node->field_report_dataset_sysnames[$node->language] = array();
        foreach ( $entity->getDatasets() as $dataset ) {
            $node->field_report_dataset_sysnames[$node->language][] = array('value' => $dataset->name);
        }

        $node->field_report_custom_view[$node->language][0]['value'] = $entity->getCustomCode();

        $node->field_report_tags[$node->language] = array();
        foreach ( $entity->getTags() as $tag ) {
            $node->field_report_tags[$node->language][] = array('tid' => $tag->tid);
        }

        node_save($node);

        // update the entity object

        // created, updated, uuid, etc.

    }
Exemplo n.º 16
0
 private function build_new_node($CTname, $elem)
 {
     $node = new stdClass();
     $node->type = $CTname;
     node_object_prepare($node);
     $node->title = $CTname;
     $node->language = 'it';
     $node->uid = $elem['uid'];
     $body_text = '';
     $node->body[$node->language][0]['value'] = '';
     $node->body[$node->language][0]['summary'] = text_summary($body_text);
     $node->body[$node->language][0]['format'] = 'filtered_html';
     $path = 'content/programmatically_created_node_' . date('YmdHis');
     $node->path = array('alias' => $path);
     $node->title = 'pagamento cliente';
     /**
      * custom  
      */
     $node = $this->set_CT_data($node, $elem);
     /**/
     node_save($node);
     $result = $node->nid;
     return $result;
 }
 /**
  * Create and return test node.
  *
  * @return \stdClass
  *    Return node object.
  */
 protected function getTestNode()
 {
     $content_type = $this->getTestContentType();
     $node = new \stdClass();
     $node->title = self::randomName(8);
     $node->type = $content_type->name;
     node_object_prepare($node);
     node_save($node);
     $this->entities['node'][] = $node->nid;
     return $node;
 }
Exemplo n.º 18
0
/**
 * Creating dummy content during the installation process.
 */
function inject_data()
{
    global $base_url;
    $tmp_base_url = variable_get("tmp_base_url");
    // Populate users fields of dummy users.
    $account = user_load(1);
    $account1 = user_load_by_name("user_administrator");
    $account2 = user_load_by_name("user_contributor");
    $account3 = user_load_by_name("user_editor");
    $account->field_firstname['und'][0]['value'] = 'John';
    $account->field_lastname['und'][0]['value'] = 'Doe';
    user_save($account);
    $account1->field_firstname['und'][0]['value'] = 'John';
    $account1->field_lastname['und'][0]['value'] = 'Smith';
    user_save($account1);
    $account2->field_firstname['und'][0]['value'] = 'John';
    $account2->field_lastname['und'][0]['value'] = 'Name';
    user_save($account2);
    $account3->field_firstname['und'][0]['value'] = 'John';
    $account3->field_lastname['und'][0]['value'] = 'Blake';
    user_save($account3);
    // Create content.
    $node = new stdClass();
    $node->type = 'page';
    node_object_prepare($node);
    $node->title = 'Welcome to your site !';
    $node->language = LANGUAGE_NONE;
    $node->path = array('alias' => 'content/welcome-your-site');
    $node->status = '1';
    $node->uid = '1';
    $node->promote = '0';
    $node->sticky = '0';
    $node->created = '1330594184';
    $node->comment = '1';
    $node->translate = '0';
    $node->revision = 1;
    $node->body[$node->language][0]['value'] = '<p>Notice:</p>
    <p>You have to login in order to perform any of the action described below &gt;&gt; ' . l(t('Login'), $tmp_base_url . '/user') . '</p>
    <p>&nbsp;</p>
    <p>To complete the configuration of your site, here are&nbsp;some additional&nbsp;steps :</p>
    <p>- to access the <strong>Feature set</strong> configuration page which helps you to choose the features you wish to install on your site &gt;&gt; ' . l(t('click here'), $tmp_base_url . '/admin/structure/feature-set') . '</p>
    <p>- to access the <strong>user creation</strong> page in order to add some users and to choose the role you wish to give them &gt;&gt; ' . l(t('click here'), $tmp_base_url . '/admin/people') . '</p>
    <p>&nbsp;</p>
    <p>Some information about&nbsp;roles&nbsp;:</p>
    <p>- admin user can do everything on the site, but will mainly be used to approve/refuse user account creation or community creation</p>
    <p>- community manager will act as admin in its community to approve/refuse membership requests and creation of contents inside the community</p>
    <p>Management will be done through the <strong>Workbench </strong>you can access thru this ' . l(t('link'), $tmp_base_url . '/admin/workbench') . '.</p>
    <p>For more information about the various functionalities,&nbsp;a contextual help exists and can be accessed&nbsp;thru the &quot;Help&quot; link.&nbsp;The help section depends on your localisation on the site and gives details about the page.</p>
    ';
    $node->body[$node->language][0]['summary'] = '';
    $node->body[$node->language][0]['format'] = 'full_html';
    $path = 'content/welcome-your-site';
    $node->path = array('alias' => $path);
    // Prepare node for saving.
    if ($node = node_submit($node)) {
        node_save($node);
        echo "Node saved!\n";
    }
    // Delete mails from the update manager module.
    variable_del("update_notify_emails");
    // Manually insert the password policy in database.
    // This process is temporary since the module password_policy.
    $exports = cce_basic_config_default_password_policy();
    db_delete('password_policy')->execute();
    db_insert('password_policy')->fields(array('name' => 'Example policy', 'config' => $exports['Example policy']->config))->execute();
}
Exemplo n.º 19
0
function save_item($title, $body_text = false, $sidebar_text = false, $tids = array())
{
    return;
    $node = new stdClass();
    $node->type = 'sidebar_snippet';
    node_object_prepare($node);
    $node->title = $title;
    $node->language = LANGUAGE_NONE;
    $node->uid = 1;
    $node->status = 1;
    if ($body_text !== false) {
        $node->body[$node->language][0]['value'] = $body_text;
        $node->body[$node->language][0]['format'] = 'full_html';
    }
    if ($sidebar_text !== false) {
        $node->body[$node->language][0]['field_sidebar_body']['value'] = $sidebar_snippet;
        $node->body[$node->language][0]['field_sidebar_body']['format'] = 'full_html';
    }
    foreach ($tids as $k => $v) {
        $node->field_tags[$node->language][]['tid'] = $v;
    }
    // $path = 'content/programmatically_created_node_' . date('YmdHis');
    // $node->path = array('alias' => $path);
    node_save($node);
}
Exemplo n.º 20
0
 /**
  * @When /^I create a "(?P<content_type>(?:[^"]|\\")*)" node with the title "(?P<title>(?:[^"]|\\")*)"$/
  */
 public function imAtAWithTheTitle($content_type, $title)
 {
     // Create Node.
     $node = new stdClass();
     $node->title = $title;
     $node->type = $content_type;
     node_object_prepare($node);
     node_save($node);
     // Go to node page.
     // Using vistPath() instead of visit() method since it adds base URL to relative path.
     $this->visitPath('node/' . $node->nid);
 }
Exemplo n.º 21
0
 public function testDrupalNodeAccessVoter()
 {
     $voter = new DrupalNodeAccessVoter();
     // Pollute the module_implements cache to only let the 'node' module
     // to be in there.
     module_implements('node_access');
     $cache =& drupal_static('module_implements');
     $cache['node_access'] = ['node' => null, 'sf_acl' => null];
     // Create an awesome volume of random data to test, inject pretty
     // much everything, and just ensure that node_access() and the
     // voter will return the same, using the rule we determined. We will
     // add special tests for later failures or bug found, if we find any.
     foreach (range(0, 50) as $nodeId) {
         $node = new Node();
         $node->type = 'page';
         node_object_prepare($node);
         $node->nid = $nodeId;
         $node->vid = $nodeId;
         foreach (range(0, 50) as $userId) {
             $account = new Account();
             $account->uid = $userId;
             $account->roles = [1 => 1];
             // This gives more or less 5% chances  that the current user
             // is the current node owner.
             $owner = rand($userId - 10, $userId + 10);
             // Give an arbitrary status
             $node->status = rand(0, 1);
             $node->uid = $owner;
             $drupalAccessView = node_access('view', $node, $account);
             $drupalAccessUpdate = node_access('update', $node, $account);
             $drupalAccessDelete = node_access('delete', $node, $account);
             $token = new SecurityToken();
             $token->setUser(new DrupalUser($account));
             $canView = $voter->vote($token, $node, ['view']);
             $canUpdate = $voter->vote($token, $node, ['update']);
             $canDelete = $voter->vote($token, $node, ['delete']);
             $canAnything = $voter->vote($token, $node, ['non existing permission']);
             // Sad Drupal is sad, but UID 1 will always have all rights
             // node_access() legacy function will filter out anything that's
             // not 'view', 'update' or 'delete', but we won't: so UID 1 has
             // always all rights on the non existing permission.
             if (1 !== (int) $userId) {
                 $this->assertSame(VoterInterface::ACCESS_ABSTAIN, $canAnything);
             } else {
                 $this->assertSame(VoterInterface::ACCESS_GRANTED, $canAnything);
             }
             if ($drupalAccessView) {
                 $this->assertSame(VoterInterface::ACCESS_GRANTED, $canView);
             } else {
                 $this->assertContains($canView, [VoterInterface::ACCESS_DENIED, VoterInterface::ACCESS_ABSTAIN]);
             }
             if ($drupalAccessUpdate) {
                 $this->assertSame(VoterInterface::ACCESS_GRANTED, $canUpdate);
             } else {
                 $this->assertContains($canUpdate, [VoterInterface::ACCESS_DENIED, VoterInterface::ACCESS_ABSTAIN]);
             }
             if ($drupalAccessDelete) {
                 $this->assertSame(VoterInterface::ACCESS_GRANTED, $canDelete);
             } else {
                 $this->assertContains($canDelete, [VoterInterface::ACCESS_DENIED, VoterInterface::ACCESS_ABSTAIN]);
             }
         }
     }
 }
Exemplo n.º 22
0
 protected function createDrupalCT($CTname)
 {
     $body_text = 'nodo parkauto';
     $node = new stdClass();
     $node->type = $CTname;
     node_object_prepare($node);
     $node->title = "{$this->rs_parkauto['rc_cognome_cliente']}  {$this->rs_parkauto['rc_nome_cliente']}";
     $node->language = 'it';
     $node->uid = $this->user->uid;
     // Da modificare
     $node->body[$node->language][0]['value'] = $body_text;
     $node->body[$node->language][0]['summary'] = text_summary($body_text);
     $node->body[$node->language][0]['format'] = 'filtered_html';
     $path = 'content/programmatically_created_node_' . date('YmdHis');
     $node->path = array('alias' => $path);
     /**
      * custom  
      */
     $node = $this->set_CT_data($node);
     /**/
     node_save($node);
     $result = $node->nid;
     if ($result) {
         $this->save_servizi_opzionali($node->nid);
         $this->ar_pagamenti_effettuati['nid_parkaauto'] = $node->nid;
         $this->pagamenti_cliente->save($this->ar_pagamenti_effettuati);
     }
     return $result;
 }
<?php

// $Id: views-view-unformatted.tpl.php,v 1.6 2008/10/01 20:52:11 merlinofchaos Exp $
/**
 * @file views-view-unformatted.tpl.php
 * Default simple view template to display a list of rows.
 *
 * @ingroup views_templates
 */
?>

<?php 
module_load_include('inc', 'node', 'node.pages');
$node_type = 'blog';
$form_id = $node_type . '_node_form';
global $user;
$new_node = new stdClass();
$new_node->uid = $user->uid;
$new_node->name = isset($user->name) ? $user->name : '';
$new_node->type = $node_type;
node_object_prepare($new_node);
// Invoke hook_nodapi and hook_node
$output = drupal_get_form($form_id, $new_node);
print $output;
Exemplo n.º 24
0
function bootstrap_theme_change_collection_form_submit(&$form, &$form_state)
{
    $collection_form = $form_state['values'];
    $contribution = node_load($collection_form['nid']);
    $contribution->field_cnob_collections[$contribution->language][0]['nid'] = $collection_form['collection_id'];
    $contribution->og_group_ref[$contribution->language][0]['target_id'] = $collection_form['collection_id'];
    $contribution->group_content_access[$contribution->language][0]['value'] = OG_CONTENT_ACCESS_PRIVATE;
    node_object_prepare($contribution);
    node_save($contribution);
    drupal_set_message('Successfully added to this collection.');
    $form_state['no_redirect'] = TRUE;
    $form_state['rebuild'] = TRUE;
    $form_state['programmed'] = FALSE;
}
    protected function createReferencePoint ( $referencePoint ) {
        $node = new stdClass();
        $node->type = NODE_TYPE_REFERENCE_POINT;
        $node->language = LANGUAGE_NONE;
        $node->status = NODE_PUBLISHED;
        node_object_prepare($node);

        $node->title = $referencePoint->title;
        $node->originalNid = $referencePoint->id;

        $node->field_ref_point_dataset_sysname[$node->language][0]['value'] = $referencePoint->dataset;

        // update column sysname to reflect new dataset name
        foreach ( $referencePoint->columns as $ref_point_column ) {
            $node->field_ref_point_column_sysname[$node->language][] = array('value' => $ref_point_column);
        }

        // create it
        node_save($node);
        return $node;
    }
Exemplo n.º 26
0
/**
 * Creating dummy content during the installation process.
 */
function inject_data()
{
    global $base_path;
    $tmp_base_url = variable_get("tmp_base_url");
    $base_path = $tmp_base_url;
    // Populate users fields of dummy users.
    $account = user_load(1);
    $account1 = user_load_by_name("user_administrator");
    $account2 = user_load_by_name("user_contributor");
    $account3 = user_load_by_name("user_editor");
    $account->field_firstname['und'][0]['value'] = 'John';
    $account->field_lastname['und'][0]['value'] = 'Doe';
    user_save($account);
    $account1->field_firstname['und'][0]['value'] = 'John';
    $account1->field_lastname['und'][0]['value'] = 'Smith';
    user_save($account1);
    $account2->field_firstname['und'][0]['value'] = 'John';
    $account2->field_lastname['und'][0]['value'] = 'Name';
    user_save($account2);
    $account3->field_firstname['und'][0]['value'] = 'John';
    $account3->field_lastname['und'][0]['value'] = 'Blake';
    user_save($account3);
    module_enable(array("i18n_taxonomy"));
    // Create content.
    $node = new stdClass();
    $node->type = 'page';
    node_object_prepare($node);
    $node->title = 'Welcome to your site !';
    $node->language = LANGUAGE_NONE;
    $node->path = array('alias' => 'content/welcome-your-site');
    $node->status = '1';
    $node->uid = '1';
    $node->promote = '0';
    $node->sticky = '0';
    $node->created = '1330594184';
    $node->comment = '1';
    $node->translate = '0';
    $node->revision = 1;
    $node->body[$node->language][0]['value'] = '<p>Notice:</p>
    <p>You have to login in order to perform any of the action described below &gt;&gt; ' . l(t('Login'), 'user') . '</p>
    <p>&nbsp;</p>
    <p>To complete the configuration of your site, here are&nbsp;some additional&nbsp;steps :</p>
    <p>- to access the <strong>Feature set</strong> configuration page which helps you to choose the features you wish to install on your site &gt;&gt; ' . l(t('click here'), 'admin/structure/feature-set') . '</p>
    <p>- to access the <strong>user creation</strong> page in order to add some users and to choose the role you wish to give them &gt;&gt; ' . l(t('click here'), 'admin/people') . '</p>
    <p>&nbsp;</p>
    <p>Some information about&nbsp;roles&nbsp;:</p>
    <p>- admin user can do everything on the site, but will mainly be used to approve/refuse user account creation or community creation</p>
    <p>- community manager will act as admin in its community to approve/refuse membership requests and creation of contents inside the community</p>
    <p>Management will be done through the <strong>Workbench </strong>you can access through this ' . l(t('link'), 'admin/workbench') . '.</p>
    <p>For more information about the various functionalities,&nbsp;a contextual help exists and can be accessed&nbsp;thru the &quot;Help&quot; link.&nbsp;The help section depends on your localisation on the site and gives details about the page.</p>
    ';
    $node->body[$node->language][0]['summary'] = '';
    $node->body[$node->language][0]['format'] = 'full_html';
    $path = 'content/welcome-your-site';
    $node->path = array('alias' => $path);
    if ($node = node_submit($node)) {
        // Prepare node for saving.
        node_save($node);
        echo "Node saved!\n";
    }
    // Delete mails from the update manager module.
    variable_del("update_notify_emails");
    // Manually insert the password policy in database.
    // This process is temporary since the module password_policy.
    $exports = cce_basic_config_default_password_policy();
    db_delete('password_policy')->execute();
    db_insert('password_policy')->fields(array('name' => 'Example policy', 'config' => $exports['Example policy']->config))->execute();
    // Add solr facet blocks to the search context.
    global $theme_key;
    if ($theme_key == 'ec_resp') {
        $region = 'sidebar_left';
    } else {
        $region = 'sidebar_first';
    }
    multisite_drupal_toolbox_add_block_context('search', $value['info'], 'facetapi', $key, $region);
    multisite_drupal_toolbox_add_block_context('search', 'facetapi-8o8kdtP8CKjahDIu1Wy5LGxnDHg3ZYnT', 'facetapi', '8o8kdtP8CKjahDIu1Wy5LGxnDHg3ZYnT', $region, -14);
    multisite_drupal_toolbox_add_block_context('search', 'facetapi-wWWinJ0eOefOtAMbjo2yl86Mnf1rO12j', 'facetapi', 'wWWinJ0eOefOtAMbjo2yl86Mnf1rO12j', $region, -15);
    multisite_drupal_toolbox_add_block_context('search', 'facetapi-odQxTWyhGW1WU7Sl00ISAnQ21BCdJG3A', 'facetapi', 'odQxTWyhGW1WU7Sl00ISAnQ21BCdJG3A', $region, -17);
    multisite_drupal_toolbox_add_block_context('search', 'facetapi-GiIy4zr9Gu0ZSa0bumw1Y9qIIpIDf1wu', 'facetapi', 'GiIy4zr9Gu0ZSa0bumw1Y9qIIpIDf1wu', $region, -16);
}
Exemplo n.º 27
0
function _create_node_from_normalized_json($normalized_json, $bundle_name, $title)
{
    $node = new stdClass();
    //$node->type = $bundle_name;
    //$node->title = $title;
    //$node->language = LANGUAGE_NONE; // == 'und'
    //$node->status = 1; // published
    foreach ($normalized_json as $name => $field) {
        $type = $field['type'];
        unset($field['type']);
        switch ($type) {
            case 'text':
                foreach ($field as $k => $v) {
                    $node->{$name}[LANGUAGE_NONE][$k]['value'] = $v;
                    //$node->$name = array(LANGUAGE_NONE => array($k => array('value' => $v)));
                }
                break;
            case 'property':
                $node->{$name} = $field[0];
                break;
            case 'taxonomy':
                foreach ($field as $k => $v) {
                    $tid = $v['id'];
                    if ($v['id'] == $v['text']) {
                        $tid = _create_new_term_for_taxon_field($bundle_name, $name, $v['text']);
                    }
                    $node->{$name}[LANGUAGE_NONE][$k]['tid'] = $tid;
                    //$node->$name = array(LANGUAGE_NONE => array( $k => array('tid' => $tid)));
                }
                break;
            default:
                break;
        }
    }
    node_object_prepare($node);
    return $node;
}
Exemplo n.º 28
0
 /**
  * Create a new node for a folder (which will then trigger the folder to be added as a new - do not call createFolder as this is triggered on node create)
  * @param type $in_foldername                     Name of the folder to create
  * @param type $in_description                    Description for the folder
  * @param type $in_parentfolder                   Parent folder ID
  * @param type $out_node                          Populated Node stdClass will be stored here
  * @param type $out_cid                           Newly created category id will be stored here
  * @param type $in_inherit_permissions            [Optional] True to inherit parent permissions
  * @return                                        TRUE on success, FALSE on failure
  */
 public static function createFolderNode($in_foldername, $in_description, $in_parentfolder, &$out_node, &$out_cid, $in_inherit_permissions = TRUE)
 {
     global $user;
     $node = new stdClass();
     $node->type = 'filedepot_folder';
     node_object_prepare($node);
     $node->language = LANGUAGE_NONE;
     $node->uid = $user->uid;
     $node->name = $user->name;
     $node->title = check_plain($in_foldername);
     $node->description = check_plain($in_foldername);
     $node->filedepot_folder_desc[LANGUAGE_NONE][0]['value'] = $in_description;
     $node->parentfolder = $in_parentfolder;
     $node->inherit = $in_inherit_permissions === TRUE ? 1 : 0;
     node_save($node);
     $out_node = $node;
     $out_cid = db_query("SELECT cid FROM {filedepot_categories} WHERE nid=:nid", array(':nid' => $node->nid))->fetchField();
     if ($node->nid) {
         return TRUE;
     } else {
         return FALSE;
     }
 }
Exemplo n.º 29
0
$otherproblems = $_POST['otherproblems'];
$medicalMore = $_POST['extraInfoArea'];
$dietaryrequirements = $_POST['dietaryrequirements'];
$diet_other = $_POST['diet-other'];
$clinicaltrial2 = $_POST['clinicaltrial2'];
$newsletter = $_POST['newsletter'];
*/
//define('DRUPAL_ROOT', "/var/www/vhosts/vps-555798.vps-10.com/admin");
define('DRUPAL_ROOT', "/home/weneedyou/public_html/admindev");
require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
$node = new stdClass();
// Create a new node object
$node->type = "full";
// Or page, or whatever content type you like
node_object_prepare($node);
// Set some default values
// If you update an existing node instead of creating a new one,
// comment out the three lines above and uncomment the following:
// $node = node_load($nid); // ...where $nid is the node id
$node->title = "Application from: {$firstname} {$lastname}";
$node->language = LANGUAGE_NONE;
// Or e.g. 'en' if locale is enabled
$node->uid = 1;
// UID of the author of the node; or use $node->name
#$node->body[$node->language][0]['value']   = $bodytext;
#$node->body[$node->language][0]['summary'] = text_summary($bodytext);
#$node->body[$node->language][0]['format']  = 'filtered_html';
/* Others variables to be inserted */
function protect($inp)
{
    protected function createReport ( $report ) {
        $node = new stdClass();
        $node->type = NODE_TYPE_REPORT;
        $node->language = LANGUAGE_NONE;
        $node->status = NODE_PUBLISHED;
        node_object_prepare($node);

        $node->originalNid = $report->id;
        $node->title = $report->title;

        $node->field_report_uuid[$node->language][0]['value'] = $report->uuid;
        $node->field_report_datasource[$node->language][0]['value'] = $this->datasourceName;

        if ( !empty($report->description) ) {
            $node->field_report_desc[$node->language][0]['value'] = $report->description;
        }

        if ( !empty($report->custom_view) ) {
            $node->field_report_custom_view[$node->language][0]['value'] = $report->custom_view;
        }

        $node->field_report_tags[$node->language] = array();
        if (!empty($report->tags)) {
            foreach ($report->tags as $tid) {
                $node->field_report_tags[$node->language][] = array('tid' => $tid);
            }
        }

        // update dataset references
        $node->field_report_dataset_sysnames[$node->language] = array();
        $metamodel = data_controller_get_metamodel();
        foreach ( $report->datasets as $datasetIdentifier ) {
            $dataset = GD_DatasetMetaModelLoaderHelper::findDatasetByUUID($this->datasets,$datasetIdentifier);
            if (!isset($dataset)) {
                $datasetName = NameSpaceHelper::addNameSpace(gd_datasource_get_active(), $datasetIdentifier);
                $dataset = $metamodel->getDataset($datasetName);
            }
            $node->field_report_dataset_sysnames[$node->language][] = array('value'=>$dataset->name);
        }

        // update dataset references
        $this->processConfig($report->config);
        $node->field_report_conf[$node->language][0]['value'] = json_encode($report->config);

        gd_report_save($node);

        if (isset($node->nid)) {
            $event = new DefaultEvent();
            $event->type = 100; // see gd_health_monitoring_database_install() for more details
            $event->owner = $node->nid;
            EventRecorderFactory::getInstance()->record($event);
        }

        return $node;
    }