Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)
Paste
Pasted as Plain Text by Testuyfhyjfhfh ( 12 years ago )
<?php
/**
* @file
* Add colorbox-load class to links with images.
*/
chdir(dirname ( __FILE__ ));
chdir('../');
define('DRUPAL_ROOT', getcwd());
require_once './includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
$batch = colorbox_to_article_images_batch();
batch_set($batch);
batch_process('');
function colorbox_to_article_images_batch() {
$operati
$nids = db_select('node', 'n')
->fields('n', array('nid'))
->condition('n.type', 'article')
->execute()->fetchCol();
$nids_chunks = array_chunk($nids, COLORBOX_ARTICLE_IMAGES_BATCH_SIZE);
foreach ($nids_chunks as $nids_chunk) {
$operations[] = array(
'colorbox_to_article_images_process',
array($nids_chunk),
);
}
$batch = array(
'operations' => $operations,
'finished' => 'colorbox_to_article_images_batch_finished',
// We can define custom messages instead of the default ones.
'title' => t('Обработка статей'),
'init_message' => t('Инициализация обработки статей.'),
'progress_message' => t('Обработано @current из @total статей.'),
'error_message' => t('Возникла ошибка.'),
);
return $batch;
}
function colorbox_to_article_images_process($nids, &$context) {
$a = 'http://4tololo.loc/admin/config/development/colorbox-to-articles-images';
// Use the $context['sandbox'] at your convenience to store the
// information needed to track progression between successive calls.
if (!isset($context['sandbox']['progress'])) {
$c
$context['sandbox']['progress'] = 0;
$context['sandbox']['current_node'] = 0;
$context['sandbox']['max'] = count($nids);
}
$updated = 0;
foreach ($nids as $nid) {
$node = node_load($nid);
try {
$node_wrapper = entity_metadata_wrapper('node', $node);
$body = $node_wrapper->body->value();
$html = new simple_html_dom();
$html->load($body['value']);
foreach ($html->find('a img') as $image_with_link ) {
$link = $image_with_link->parent();
$classes = $link->getAttribute('class');
if (!preg_match('/(^| )colorbox-load($| )/', $classes)) {
$updated++;
$new_classes = $classes ? $classes . ' colorbox-load' : 'colorbox-load';
$link->setAttribute('class', $new_classes);
}
}
$body['value'] = $html->save();
$node_wrapper->body->set($body);
node_save($node);
}
catch(Exception $e) {
// Do nothing.
}
}
$updated = variable_get('colorbox_to_article_images_updated', 0) + $updated;
$context['message'] = $updated . ' изображений исправленно.';
$context['finished'] = 1;
}
function colorbox_to_article_images_batch_finished() {
drupal_set_message(variable_get('colorbox_to_article_images_updated', 0) . ' изображений успешно исправленно.');
}
Revise this Paste