→  Программное сохранение ноды

published 06 August 2011

Для программного создания ноды создаем объект и “заполняем” его необходимыми для ноды полями, после функцией node_save($node) сохраняем, если указать поле $node->nid нода сохраниться под этим номером, если не указать, номер создаться автокриментом.

   global $user;
    $node = new stdClass();
    $node->type = 'bull';
    $node->title = $values['title'];
$node->uid = $user->uid;
$node->language = 'ru';
$node->status = 0;
$node->promote = 0;
$node->comment = 0;
$node->sticky = 0;
$node->created = REQUEST_TIME;
$node->changed = REQUEST_TIME; 
    $node->body['ru']['0'] = $values['description'];
    $node->field_fieldname['ru']['0']['value'] = '';
    node_save($node);

UPD: Вообще оказываеться правильной делать так:

 →  Генерация хэша пароля в Drupal 7

published 06 August 2011

Drupal 7 использует свой алгоритм генерации хэша пароля (не md5 как Drupal 6). Для генерации хэша необходимо выполнить следующую команду в корневой папке друпала:

royaldt# ./scripts/password-hash.sh 12345

которая выдаст следующие:

password: 12345 		hash: $S$C5TLNVghR3WjNiURWVIOwB.YVlRD56sHdBg3Uzl7lkoKQgBG6SmX

 →  Функции модуля Taxonomy 7.x

published 06 August 2011

Получить объект термина по tid

$term = taxonomy_term_load($tid);

Получить дерево словаря

taxonomy_get_tree($vid, $parent = 0, $max_depth = NULL, $load_entities = FALSE)

$vid Which vocabulary to generate the tree for.

$parent The term ID under which to generate the tree. If 0, generate the tree for the entire vocabulary.

$max_depth The number of levels of the tree to return. Leave NULL to return all levels.

$load_entities If TRUE, a full entity load will occur on the term objects. Otherwise they are partial objects queried directly from the {taxonomy_term_data} table to save execution time and memory consumption when listing large numbers of terms. Defaults to FALSE.

 →  Вывод тэгов с количеством нод в блок

published 06 August 2011

t(‘Tags’), ); return $blocks; } function tax_menu_block_view($delta = ‘’) { $block = array( ‘subject’ => ‘’, ‘content’ => ‘’,
); if ($delta == ’tax_menu’) { $block[‘subject’] = ‘Tags’; $block[‘content’] = get_items(); } return $block; } function get_items() { $query = db_select(’node’, ’n’); $query->innerJoin(‘field_revision_field_tags’, ’t’, ’n.nid = t.entity_id’); $query->innerJoin(’taxonomy_term_data’, ’td’, ’t.field_tags_tid = td.tid’); $query->condition(’td.vid’, VOCABULARY. ‘=’); $query->fields(’td’, array(’name’, ’tid’)); $query->groupBy(’td.tid’); $query->addExpression(‘COUNT(*)’, ‘c’); $query->orderBy(’td.name’, ‘ASC’); $result = $query->execute(); foreach ($result as $item) { $items[] = l($item->name . ‘(’ . $item->c . ‘)’, ’taxonomy/term/’ . $item->tid ); } $attributes = array( ‘id’ => ’tax_menu_list’, ); $output = theme(‘item_list’, array(‘items’ => $items, ’type’ => ‘ul’, ‘attrebutes’ => $attributes )); return $output ; }

 →  Настройка виртуальных хостов на апаче

published 01 August 2011

IP addresses / ports to listen on

Include /etc/apache2/listen.conf

VirtualHost: If you want to maintain multiple domains/hostnames on your

machine you can setup VirtualHost containers for them.

Include /etc/apache2/vhosts.d/*.conf

файл listen.conf

NameVirtualHost localhost:80
NameVirtualHost 127.0.0.1:80

файл hosts.conf в /vhosts.d

ServerAdmin 11t@gmail.com
 ServerName newsite
 DocumentRoot /srv/www/htdocs/newsite
 ErrorLog  /srv/www/htdocs/newsite/error_log
 CustomLog  /srv/www/htdocs/newsite/access_log combined    
 
  Options None
  AllowOverride All
  Order deny,allow
  Allow from all

рестарт апача

/etc/init.d/apache2 restart

и не забыть прописать алиас в host

127.0.0.1   newsite

 →  Команды linux

published 30 July 2011

Самые необходимые комманды линуха

Копирование содержимого папки

cp -r ./folder/*  ./folder

Поиск текста в файлах

grep -rl 'text' /path/

Поиск файлов:

find / -name game

Добавить ключ:

ssh-add jeremy_key

 →  Закачка добавленного видео на ютуб

published 30 July 2011

I thought I would share the configuration I came up with, in case it is helpful to anyone else.

My use case: Upload a video, display it on youtube, and then display the video on my site in an emfield.

Setup: (a) Enable and configure these modules: emfield, emvideo media_youtube media_mover_api, media_mover_cck, media_mover_emfield (b) Create a cck node type (“video”) with both a filefield (eg “field_filefield_video) and an emvideo field (eg “field_emvideo”) (c) Create a few video-type nodes. Leave the emvideo field blank, and upload some videos into the filefield.

 →  Вставка views в шаблон

published 29 July 2011

views_embed_view($name, $display_id = ‘default’)

 →  Добавление текста в форму

published 29 July 2011

Drupal 7 $form[’label’] = array( ‘#markup’ => “{”#" * i} Привет!", );

Drupal 6 $form[’label’] = array( ‘#value’ => “{”#" * i} Привет!", );

 →  drupal format_date

published 27 July 2011

function

format_date($timestamp, $type = ‘medium’, $format = ‘’, $timezone = NULL, $langcode = NULL)

example

$date = format_date($timestamp, ‘custom’, ’d F Y’);

« 1 2 3 4 5 6 7 8 9 10 11 »