View source
<?php
define('WP_BLOG_DEFAULT_NODE_PATH', 'blog/[node:created:custom:Y]/[node:created:custom:m]/[node:created:custom:d]/[node:title]');
function wp_blog_requirements($phase) {
$t = get_t();
$requirements = array();
if ($phase == 'runtime') {
$has_pathauto = module_exists('pathauto');
$has_correct_path = variable_get('pathauto_node_wp_blog_pattern', '') == WP_BLOG_DEFAULT_NODE_PATH;
if (!$has_pathauto) {
$requirements['wp_blog'] = array(
'title' => $t('WP Blog'),
'description' => $t("Pathauto is recommended to provide WP Blog's recommended URL structure. Download pathauto from the <a href='@pathauto_url'>pathauto project page</a>.", array(
'@pathauto_url' => 'http://drupal.org/project/pathauto',
)),
'value' => $t('Missing pathauto'),
'severity' => REQUIREMENT_WARNING,
);
}
elseif (!$has_correct_path) {
$requirements['wp_blog'] = array(
'title' => $t('WP Blog'),
'description' => $t("The pattern for all WP blog post paths is not set to the recommended pattern.<br />It's currently %current_pattern and should be %recommended_pattern. This can be changed on the <a href='@url_patterns_url'>URL aliases' patterns page</a>.", array(
'%current_pattern' => variable_get('pathauto_node_wp_blog_pattern', $t('not set')),
'%recommended_pattern' => $recommended_url_path,
'@url_patterns_url' => url('admin/config/search/path/patterns'),
)),
'value' => $t('Incorrect URL alias pattern'),
'severity' => REQUIREMENT_WARNING,
);
}
else {
$requirements['wp_blog'] = array(
'title' => $t('WP Blog'),
'description' => $t("Pathauto is enabled and the WP Blog path is correctly set."),
'value' => $t('Configuration correct'),
'severity' => REQUIREMENT_OK,
);
}
}
return $requirements;
}
function wp_blog_install() {
require_once dirname(__FILE__) . '/wp_blog.module';
$t = get_t();
node_types_rebuild();
$types = node_type_get_types();
node_add_body_field($types[WP_BLOG_DEFAULT_CTYPE], $t('Body'));
_wp_blog_create_vocabulary();
variable_set('pathauto_node_wp_blog_pattern', WP_BLOG_DEFAULT_NODE_PATH);
}
function _wp_blog_create_vocabulary() {
$t = get_t();
field_associate_fields('taxonomy');
$vocabulary = taxonomy_vocabulary_load(variable_get('wp_blog_vocabulary', 0));
if (!$vocabulary) {
$edit = array(
'name' => $t('Blog tags'),
'machine_name' => 'wp_blog_tags',
'description' => t('Tags to categorise blog posts'),
'hierarchy' => 1,
'module' => 'wp_blog',
);
$vocabulary = (object) $edit;
taxonomy_vocabulary_save($vocabulary);
variable_set('wp_blog_vocabulary', $vocabulary->vid);
}
if (!field_info_field('taxonomy_wp_blog_tags')) {
$field = array(
'field_name' => 'taxonomy_' . $vocabulary->machine_name,
'type' => 'taxonomy_term_reference',
'settings' => array(
'allowed_values' => array(
array(
'vocabulary' => $vocabulary->machine_name,
'parent' => 0,
),
),
),
'cardinality' => FIELD_CARDINALITY_UNLIMITED,
);
field_create_field($field);
$instance = array(
'field_name' => 'taxonomy_' . $vocabulary->machine_name,
'entity_type' => 'node',
'label' => $vocabulary->name,
'bundle' => 'wp_blog',
'required' => FALSE,
'widget' => array(
'type' => 'taxonomy_autocomplete',
),
'display' => array(
'default' => array(
'type' => 'taxonomy_term_reference_link',
'weight' => 10,
),
'teaser' => array(
'type' => 'taxonomy_term_reference_link',
'weight' => 10,
),
),
);
field_create_instance($instance);
}
}