smartqueue_domain.module in Smartqueue Domain 7
File
smartqueue_domain.module
View source
<?php
function smartqueue_domain_views_api() {
return array(
'api' => 2,
);
}
function smartqueue_domain_init() {
global $_domain;
if (arg(0) == 'admin' && arg(1) == 'structure' && arg(2) == 'nodequeue' && is_numeric(arg(3)) && arg(4) == 'view' && is_numeric(arg(5))) {
if (variable_get('domain_edit_on_primary', 1)) {
domain_check_primary();
}
else {
$subqueue_id = arg(5);
$queue = nodequeue_load_subqueues(array(
$subqueue_id,
));
$queue_info = explode(':', $queue[$subqueue_id]->reference);
$domains = domain_domains();
if (isset($queue_info[3])) {
$domain = $domains[$queue_info[3]];
if (!isset($domain['domain_id'])) {
return;
}
$path = isset($_GET['q']) ? $_GET['q'] : '';
if ($_domain['domain_id'] != $domain['domain_id']) {
drupal_goto($domain['path'] . $path);
}
}
}
}
}
function smartqueue_domain_nodequeue_info() {
return array(
'smartqueue_domain' => array(
'title' => t('Domain smartqueue'),
'description' => t('Domain smartqueue is a queue that has subqueues for each domain inside your site'),
),
);
}
function smartqueue_domain_nodequeue_subqueues(&$queue, $node) {
smartqueue_domain_check_subqueues($queue);
$domain = domain_get_domain();
$domain = domain_lookup($domain['domain_id']);
$refs = array(
$queue->name . ':domain:' . $domain['machine_name'] . ':' . $domain['domain_id'],
);
return $refs;
}
function smartqueue_domain_check_subqueues(&$queue) {
$domains = domain_domains(TRUE);
foreach ($domains as $id => $domain) {
$ref = $queue->name . ':domain:' . $domain['machine_name'] . ':' . $domain['domain_id'];
$subqueue = nodequeue_load_subqueues_by_reference(array(
$queue->qid => array(
$ref,
),
));
if (empty($subqueue)) {
nodequeue_add_subqueue($queue, $queue->title . ' - ' . $domain['sitename'], $ref);
}
}
}
function smartqueue_domain_domain_insert($domain) {
$smartqueue_queues = smartqueue_domain_get_queues();
foreach ($smartqueue_queues as $queue) {
smartqueue_domain_check_subqueues($queue);
}
}
function smartqueue_domain_domain_delete($domain, $form_values = array()) {
$subqueues = smartqueue_domain_get_subqueues_by_domain($domain);
if (!empty($subqueues)) {
foreach ($subqueues as $subqueue) {
nodequeue_remove_subqueue($subqueue->sqid);
}
}
}
function smartqueue_domain_get_queues() {
$smartqueue_queues = array();
$queues = nodequeue_load_queues(nodequeue_get_all_qids());
foreach ($queues as $qid => $queue) {
if ($queue->owner == 'smartqueue_domain') {
$smartqueue_queues[$qid] = $queue;
}
}
return $smartqueue_queues;
}
function smartqueue_domain_get_subqueues_by_domain($domain) {
$smartqueue_queues = smartqueue_domain_get_queues();
$references = array();
foreach ($smartqueue_queues as $queue) {
$references[$queue->qid] = array(
$queue->name . ':domain:' . $domain['machine_name'] . ':' . $domain['domain_id'],
);
}
return nodequeue_load_subqueues_by_reference($references);
}
function smartqueue_domain_nodequeue_form_submit_finish($queue, &$form_state) {
smartqueue_domain_check_subqueues($queue);
}
function smartqueue_domain_views_check_subqueue($queue) {
$domain = domain_get_domain();
$queue_info = explode(':', $queue->reference);
if (isset($queue_info[3])) {
$domain_id = $queue_info[3];
if ($domain['domain_id'] == $domain_id) {
return TRUE;
}
}
return FALSE;
}
function smartqueue_domain_subqueue_access($subqueue, $account, $queue) {
$user_domains = domain_get_user_domains($account);
$subqueue_info = explode(':', $subqueue->reference);
if (isset($user_domains[-1])) {
$user_domains[0] = 0;
unset($user_domains[-1]);
}
if (in_array($subqueue_info[3], $user_domains) && user_access('edit domain content') || user_access('set domain access')) {
return TRUE;
}
return FALSE;
}