Last active
April 16, 2018 20:28
-
-
Save lsolesen/cc6b570dd939e7dc210b113421b445e4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Bootstrap Drupal. | |
$drupal_path = $_SERVER['DOCUMENT_ROOT']; | |
define('DRUPAL_ROOT', $drupal_path); | |
require_once DRUPAL_ROOT . '/includes/bootstrap.inc'; | |
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); | |
// Gettting to work | |
$query = new EntityFieldQuery(); | |
$query->entityCondition('entity_type', 'node') | |
->entityCondition('bundle', 'blog_post') | |
->propertyCondition('status', 1) | |
->range(0,100) | |
->propertyOrderBy('created', 'ASC'); | |
$result = $query->execute(); | |
if (!empty($result['node'])) { | |
$redirects = ''; | |
$nids = array_keys($result['node']); | |
foreach ($nids as $nid) { | |
$node = node_load($nid, NULL, TRUE); | |
$wrapper = entity_metadata_wrapper('node', $node); | |
$category = $wrapper->field_blog_category->value()[0]->name; | |
//print_r($category); | |
if ($category != 'Frisbeens historie') { | |
//echo 'Skipping ' . $node->title . "\n"; | |
continue; | |
} | |
$created = $node->created; | |
$title = $node->title; | |
$body = $wrapper->body->value()['safe_value']; | |
$url = drupal_get_path_alias('node/' . $node->nid); | |
$file_uri = $node->field_image['da'][0]['uri']; | |
$url = drupal_get_path_alias('node/' . $node->nid); | |
$image_path = drupal_realpath($file_uri); | |
$www_url = file_create_url($file_uri); | |
$file_name = drupal_basename($file_uri); | |
//echo 'Writing ' . $node->title . " created " . $created . "\n"; | |
//echo " - Extracting " . $www_url . "\n"; | |
$date = format_date($created, 'custom', 'Y-m-d'); | |
$output_file_name = $date . "-" . strtolower(substr($url, 5)). ".md"; | |
$redirects .= $url . ";http://blog.discimport.dk/" . $url . ";0" . "\n"; | |
$data = "--- | |
title: " . $title . " | |
permalink: /" . $url . " | |
layout: article | |
categories: blog, historie, frisbee | |
modified: " . $date . " | |
image: | |
teaser: history/" . $file_name . " | |
feature: history/" . $file_name . " | |
credit: Johnny Lillelund | |
--- | |
" . $body; | |
file_put_contents(__DIR__ . "/history/" . $output_file_name, $data); | |
copy($image_path, __DIR__ . "/history/images/" . $file_name); | |
} | |
file_put_contents(__DIR__ . "/history/redirects.csv", $redirects); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment