merged materiobasemod submodule
This commit is contained in:
212
sites/all/modules/gui/materiobasemod/materio_admin.module
Normal file
212
sites/all/modules/gui/materiobasemod/materio_admin.module
Normal file
@@ -0,0 +1,212 @@
|
||||
<?php
|
||||
|
||||
|
||||
/**
|
||||
* Implements hook_permission().
|
||||
*/
|
||||
function materio_admin_permission() {
|
||||
return array(
|
||||
'access default users list' => array(
|
||||
'title' => t('Access default users list'),
|
||||
'description' => t('Access default users list.'),
|
||||
),
|
||||
'access default UC roles expiration list' => array(
|
||||
'title' => t('access default UC roles expiration list'),
|
||||
'description' => t('access default UC roles expiration list.'),
|
||||
),
|
||||
'access duplicate mails list' => array(
|
||||
'title' => t('access duplicate mails list'),
|
||||
'description' => t('access duplicate mails list.'),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_menu().
|
||||
*/
|
||||
function materio_admin_menu() {
|
||||
|
||||
$items['admin/users/duplicatemails'] = array(
|
||||
'title' => "Duplicate mails",
|
||||
'page callback' => 'materio_duplicatemails',
|
||||
'access callback' => 'user_access',
|
||||
'access arguments' => array('access duplicate mails list'),
|
||||
'type' => MENU_LOCAL_TASK
|
||||
);
|
||||
|
||||
|
||||
|
||||
if(module_exists('simplenews')){
|
||||
$cats = simplenews_category_list();
|
||||
// dsm($cats, 'cats');
|
||||
foreach ($cats as $tid => $name) {
|
||||
// $items['node/%node/simplenews'] = array(
|
||||
// 'title' => 'Newsletter',
|
||||
// 'type' => MENU_LOCAL_TASK,
|
||||
// 'access callback' => 'simplenews_node_tab_access',
|
||||
// 'access arguments' => array(1),
|
||||
// 'page callback' => 'simplenews_node_tab_page',
|
||||
// 'page arguments' => array(1),
|
||||
// 'context' => MENU_LOCAL_TASK,
|
||||
// 'file' => 'includes/simplenews.admin.inc',
|
||||
// 'weight' => 2,
|
||||
// );
|
||||
$items['node/add/simplenews/'.$tid] = array(
|
||||
'title' => $name,
|
||||
'title callback' => 'check_plain',
|
||||
'page callback' => 'node_add',
|
||||
'page arguments' => array('simplenews'),
|
||||
'access callback' => 'node_access',
|
||||
'access arguments' => array('create', 'simplenews'),
|
||||
'file path' => drupal_get_path('module', 'node'),
|
||||
'file' => 'node.pages.inc',
|
||||
);
|
||||
}
|
||||
}
|
||||
return $items;
|
||||
}
|
||||
|
||||
function materio_duplicatemails(){
|
||||
$mails = db_query('SELECT mail FROM {users} GROUP BY mail HAVING count(mail) > 1')->fetchCol();
|
||||
|
||||
// Bail out early if there are no duplicates.
|
||||
if (!$mails) {
|
||||
return t('All accounts have unique email addresses.');
|
||||
}
|
||||
|
||||
// Grab all the user data for accounts with addresses identified as
|
||||
// duplicates. This is a little convoluted, but it lets us grab all the user
|
||||
// data in one shot.
|
||||
$uids = db_select('users', 'u')
|
||||
->fields('u', array('uid'))
|
||||
->condition('mail', $mails, 'IN')
|
||||
->orderBy('access', 'DESC')
|
||||
->execute()
|
||||
->fetchCol();
|
||||
$duplicate_users = user_load_multiple($uids);
|
||||
$duplicate_mails = array();
|
||||
foreach ($duplicate_users as $duplicate_user) {
|
||||
$duplicate_mails[$duplicate_user->mail][] = $duplicate_user;
|
||||
}
|
||||
|
||||
// Turn the data we've got into markup.
|
||||
$output = t('Accounts with duplicate email address:') . '<br />';
|
||||
$output = "<ul>";
|
||||
foreach ($duplicate_mails as $mail => $users) {
|
||||
$output .= "<li> <strong>$mail</strong> : <br />";
|
||||
$accounts = array();
|
||||
foreach ($users as $duplicate_user) {
|
||||
$accounts[] = l($duplicate_user->name, "user/{$duplicate_user->uid}") . ' ('. date('Y-m-d', $duplicate_user->access) .')';
|
||||
}
|
||||
$output .= implode(', ', $accounts);
|
||||
|
||||
$output .= '</li>';
|
||||
}
|
||||
$output .= "</ul>";
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_menu_alter().
|
||||
*/
|
||||
function materio_admin_menu_alter(&$items){
|
||||
// dsm($items, 'menu alter items');
|
||||
|
||||
if(isset($items['admin/people'])){
|
||||
$items['admin/people']['access arguments'] = array('access default users list');
|
||||
// dsm($items['admin/people']);
|
||||
}
|
||||
|
||||
if(isset($items['admin/people/expiration'])){
|
||||
$items['admin/people/expiration']['access arguments'] = array('access default UC roles expiration list');
|
||||
// dsm($items['admin/people/expiration']);
|
||||
}
|
||||
|
||||
# deactivate default home page
|
||||
$items['node']['access callback'] = FALSE;
|
||||
|
||||
// if(isset($items['admin/content/add/simplenews'])){
|
||||
// delete($items['admin/content/add/simplenews']);
|
||||
// $cats = simplenews_category_list();
|
||||
// dsm($cats, 'cats');
|
||||
// foreach ($cats as $tid => $name) {
|
||||
// $items['admin/content/add/simplenews/'.$tid]
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_menu_local_tasks_alter().
|
||||
*/
|
||||
function materio_admin_menu_local_tasks_alter(&$data, $router_item, $root_path) {
|
||||
|
||||
if ($root_path == 'admin/people/simplenews') {
|
||||
$item = menu_get_item('admin/content/simplenews');
|
||||
if ($item['access']) {
|
||||
$item['title'] = 'Go to '.$item['title'];
|
||||
$data['actions']['output'][] = array(
|
||||
'#theme' => 'menu_local_task',
|
||||
'#link' => $item,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if ($root_path == 'admin/content/simplenews') {
|
||||
|
||||
$cats = simplenews_category_list();
|
||||
foreach ($cats as $tid => $name) {
|
||||
$item = menu_get_item('node/add/simplenews/'.$tid);
|
||||
$item['title'] = 'Add new '.$name;
|
||||
if ($item['access']) {
|
||||
$data['actions']['output'][] = array(
|
||||
'#theme' => 'menu_local_task',
|
||||
'#link' => $item,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$item = menu_get_item('admin/people/simplenews');
|
||||
if ($item['access']) {
|
||||
$item['title'] = 'Go to '.$item['title'];
|
||||
$data['actions']['output'][] = array(
|
||||
'#theme' => 'menu_local_task',
|
||||
'#link' => $item,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_form_alter().
|
||||
*/
|
||||
function materio_admin_form_simplenews_node_form_alter(&$form, &$form_state, $form_id) {
|
||||
// dsm($form_id, '$form_id');
|
||||
// dsm($form_state, '$form_state');
|
||||
// dsm($form, '$form');
|
||||
// dsm($_GET, 'GET');
|
||||
|
||||
if(!$form['nid']['#value']){
|
||||
$cats = simplenews_category_list();
|
||||
$cats_tids = array_keys($cats);
|
||||
$q = parse_url($_GET['q']);
|
||||
$cat = array_pop(explode('/', $q['path']));
|
||||
// dsm($cat, 'cat');
|
||||
if(in_array($cat, $cats_tids)){
|
||||
// prepopulate type of news
|
||||
$form['field_simplenews_term']['und']['#default_value'] = $cat;
|
||||
$form['field_simplenews_term']['und']['#disabled'] = true;
|
||||
|
||||
// change default template regarding type of news
|
||||
$form['body']['und'][0]['#default_value'] = materio_admin_getSimplenewsNodeBodyTemplate($cat);
|
||||
}
|
||||
}else{
|
||||
$form['field_simplenews_term']['und']['#disabled'] = true;
|
||||
}
|
||||
|
||||
$form['body']['und'][0]['#rows'] = 50;
|
||||
|
||||
}
|
||||
|
||||
function materio_admin_getSimplenewsNodeBodyTemplate($cat){
|
||||
return file_get_contents(drupal_get_path('module', 'materio_admin').'/templates/simplenews_'.$cat.'_node.html');
|
||||
}
|
Reference in New Issue
Block a user