@@ -44,7 +44,7 @@ function materio_flag_menu() {
|
||||
'page arguments' => array(3),
|
||||
);
|
||||
|
||||
$items['materioflag/refresh/block/mylists'] = $base+array(
|
||||
$items['materioflag/refresh/block/lists'] = $base+array(
|
||||
'access arguments' => array('create flag lists'),
|
||||
'page callback' => 'materio_flag_refresh_block',
|
||||
'page arguments' => array(3),
|
||||
@@ -57,11 +57,26 @@ function materio_flag_menu() {
|
||||
'page arguments' => array(3),
|
||||
);
|
||||
|
||||
$items['materioflag/createlist/%'] = $base+array(
|
||||
|
||||
$items['materioflag/nodelinks'] = $base+array(
|
||||
'access arguments' => array('create flag lists'),
|
||||
'access callback' => 'user_access',
|
||||
'page callback' => 'materio_flag_createlist',
|
||||
'page arguments' => array(2, 3),
|
||||
'page callback' => 'materio_flag_nodelinks',
|
||||
// 'page arguments' => array(3),
|
||||
);
|
||||
|
||||
$items['lists/%'] = $base+array(
|
||||
'access arguments' => array('create flag lists'),
|
||||
'access callback' => 'user_access',
|
||||
'page callback' => 'materio_flag_user_lists',
|
||||
'page arguments' => array(1),
|
||||
);
|
||||
|
||||
$items['materioflag/ajax/list/%'] = $base+array(
|
||||
'page callback' => 'materio_flag_ajax_list',
|
||||
'access arguments' => array('create flag lists'),
|
||||
'access callback' => 'user_access',
|
||||
'page arguments' => array(3, 4),
|
||||
);
|
||||
|
||||
return $items;
|
||||
@@ -83,6 +98,10 @@ function materio_flag_block_info() {
|
||||
'cache' => DRUPAL_NO_CACHE
|
||||
);
|
||||
|
||||
$blocks['materio_flag_mylists_nav'] = array(
|
||||
'info' => t('My Materio flag lists navigation'),
|
||||
'cache' => DRUPAL_NO_CACHE
|
||||
);
|
||||
|
||||
return $blocks;
|
||||
}
|
||||
@@ -122,6 +141,7 @@ function materio_flag_block_view($delta = '') {
|
||||
// dsm($flags, 'flags');
|
||||
|
||||
foreach ($flags as $name => $flag) {
|
||||
$flag->path = url('lists/'.$flag->fid);
|
||||
$flaged_content = flag_lists_get_flagged_content($flag->fid, $user->uid);
|
||||
// dsm($flaged_content, 'flaged_content');
|
||||
$fcn = array();
|
||||
@@ -134,6 +154,7 @@ function materio_flag_block_view($delta = '') {
|
||||
$fcn[] = $node;
|
||||
}
|
||||
}
|
||||
|
||||
$lists[$name] = array(
|
||||
'list' => $flag,
|
||||
'content' => $fcn,
|
||||
@@ -152,6 +173,19 @@ function materio_flag_block_view($delta = '') {
|
||||
drupal_add_js(drupal_get_path('module', 'materio_flag').'/js/materio_flag-ck.js');
|
||||
}
|
||||
break;
|
||||
case 'materio_flag_mylists_nav':
|
||||
if(user_access('create flag lists')){
|
||||
$flags = flag_lists_get_user_flags(NULL, $user);
|
||||
// foreach ($flags as $name => $flag) {
|
||||
// # code...
|
||||
// }
|
||||
|
||||
|
||||
$block['subject'] = t('My !listname'.'s', array('!listname'=>variable_get('flag_lists_name', 'list')));
|
||||
$block['content'] = theme('materio_flag_mylists_nav_block', array("flags"=>$flags));
|
||||
// $block['content'] = theme('flag_lists_user_page', array('uid' => $user->uid));
|
||||
}
|
||||
break;
|
||||
}
|
||||
return $block;
|
||||
}
|
||||
@@ -174,120 +208,136 @@ function materio_flag_entity_info_alter(&$entity_info) {
|
||||
function materio_flag_entity_view($entity, $type, $view_mode, $langcode) {
|
||||
if($type == 'node'){
|
||||
|
||||
// dsm($entity, 'entity');
|
||||
// Do we have a list template for this node type, or are we s
|
||||
if (!flag_lists_template_exists($entity->type)) {
|
||||
return;
|
||||
}
|
||||
$flaglists_links = materio_flag_get_entity_links($entity, $type, $view_mode);
|
||||
// dsm($flaglists_links, 'flaglists_links');
|
||||
|
||||
global $user;
|
||||
$entity->content['links']['flaglistslinks'] = array('#markup' => $flaglists_links,"#html"=>true);
|
||||
|
||||
if ($flags = flag_lists_get_user_flags($entity->type, $user)) {
|
||||
// dsm($flags, 'flags');
|
||||
# if flag name is provided we are on flaglists content list (block mylists)
|
||||
if(isset($entity->flag_names)){
|
||||
// TODO: limit flag link by current flag list
|
||||
foreach ($flags as $flag) {
|
||||
//dsm($flag->name, 'flag');
|
||||
if(in_array($flag->name, $entity->flag_names)){
|
||||
if ($flag->module == 'flag_lists') {
|
||||
$action = _flag_lists_is_flagged($flag, $entity->nid, $user->uid, 0) ? 'unflag' : 'flag';
|
||||
} else {
|
||||
$action = $flag->is_flagged($entity->nid) ? 'unflag' : 'flag';
|
||||
}
|
||||
$flag->module = 'materio_flag';
|
||||
$link = $flag->theme($action, $entity->nid);
|
||||
|
||||
// If it's a list, fix the link.
|
||||
if ($flag->module == 'flag_lists') {
|
||||
flag_lists_fix_link($link, $action);
|
||||
}
|
||||
|
||||
$items[] = array(
|
||||
'data' => $link,
|
||||
'class' => array('flag-lists-link', $action.'-action'),
|
||||
);
|
||||
|
||||
// array_splice($entity->flag_names, array_search($flag->name, $entity->flag_names), 1);
|
||||
|
||||
// dsm($entity->flag_names, 'entity->flag_name');
|
||||
|
||||
// break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#normal display
|
||||
}else{
|
||||
// Build the list of lists for this node.
|
||||
foreach ($flags as $flag) {
|
||||
if ($flag->module == 'flag_lists') {
|
||||
$action = _flag_lists_is_flagged($flag, $entity->nid, $user->uid, 0) ? 'unflag' : 'flag';
|
||||
}
|
||||
else {
|
||||
$action = $flag->is_flagged($entity->nid) ? 'unflag' : 'flag';;
|
||||
}
|
||||
|
||||
// dsm($flag, 'flag');
|
||||
|
||||
// $flag->module = 'materio_flag';
|
||||
|
||||
$link = $flag->theme($action, $entity->nid);
|
||||
|
||||
// If it's a list, fix the link.
|
||||
if ($flag->module == 'flag_lists') {
|
||||
flag_lists_fix_link($link, $action);
|
||||
}
|
||||
|
||||
$items[] = array(
|
||||
'data' => $link,
|
||||
'class' => array('flag-lists-link', $action.'-action'),
|
||||
);
|
||||
}
|
||||
|
||||
#create new list
|
||||
$link = l(
|
||||
t('New @name', array('@name' => variable_get('flag_lists_name', t('list')))),
|
||||
'flag-lists/add/' . $entity->type,
|
||||
array(
|
||||
// 'query' => drupal_get_destination(),
|
||||
'attributes' => array(
|
||||
'class' => array('flag-lists-create'),
|
||||
'title' => t('create a new @name and use it.', array('@name'=>variable_get('flag_lists_name', t('list'))))
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$create = array(
|
||||
'data' => $link,// . '<i class="icon-plus"></i>',
|
||||
'class' => array('flag-lists-create'),
|
||||
);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
if( (!isset($items) || !count($items)) && !isset($create))
|
||||
return;
|
||||
|
||||
$ops = array(
|
||||
'node' => $entity,
|
||||
'items' => $items,
|
||||
);
|
||||
|
||||
if(isset($create))
|
||||
$ops['create'] = $create;
|
||||
|
||||
drupal_add_js(drupal_get_path('module', 'materio_flag').'/js/materio_flag-ck.js');
|
||||
|
||||
$flaglists_links = theme('materio_flag_mylists_entity_links', $ops);
|
||||
|
||||
$entity->content['links']['flaglistslinks'] = array('#markup' => $flaglists_links,"#html"=>true);
|
||||
|
||||
}
|
||||
drupal_add_css(drupal_get_path('module', 'flag') . '/theme/flag.css');
|
||||
drupal_add_js(drupal_get_path('module', 'flag') . '/theme/flag.js');
|
||||
}
|
||||
}
|
||||
|
||||
function materio_flag_get_entity_links($entity, $type, $view_mode = null){
|
||||
// dsm($entity, 'entity');
|
||||
|
||||
// Do we have a list template for this node type, or are we s
|
||||
if (!flag_lists_template_exists($entity->type)) {
|
||||
return;
|
||||
}
|
||||
|
||||
global $user;
|
||||
|
||||
# if flag name is provided we are on flaglists content list (block mylists)
|
||||
if($view_mode == 'bookmark'){
|
||||
// TODO: define view mode in settings
|
||||
// if (isset($entity->flag_names) && $flags = flag_lists_get_user_flags($entity->type, $user)) {
|
||||
// // dsm($flags, 'flags');
|
||||
// // TODO: limit flag link by current flag list
|
||||
// foreach ($flags as $flag) {
|
||||
// //dsm($flag->name, 'flag');
|
||||
// if(in_array($flag->name, $entity->flag_names)){
|
||||
// if ($flag->module == 'flag_lists') {
|
||||
// $action = _flag_lists_is_flagged($flag, $entity->nid, $user->uid, 0) ? 'unflag' : 'flag';
|
||||
// } else {
|
||||
// $action = $flag->is_flagged($entity->nid) ? 'unflag' : 'flag';
|
||||
// }
|
||||
// $flag->module = 'materio_flag';
|
||||
// $link = $flag->theme($action, $entity->nid);
|
||||
|
||||
// // If it's a list, fix the link.
|
||||
// if ($flag->module == 'flag_lists') {
|
||||
// flag_lists_fix_link($link, $action);
|
||||
// }
|
||||
|
||||
// $items[] = array(
|
||||
// 'data' => $link,
|
||||
// 'class' => array('flag-lists-link', $action.'-action'),
|
||||
// );
|
||||
|
||||
// // array_splice($entity->flag_names, array_search($flag->name, $entity->flag_names), 1);
|
||||
// // dsm($entity->flag_names, 'entity->flag_name');
|
||||
// // break;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
#normal display
|
||||
}else{
|
||||
if ($flags = flag_lists_get_user_flags($entity->type, $user)) {
|
||||
// dsm($flags, 'flags');
|
||||
// Build the list of lists for this node.
|
||||
foreach ($flags as $flag) {
|
||||
// dsm($flag, 'flag');
|
||||
if ($flag->module == 'flag_lists') {
|
||||
$action = _flag_lists_is_flagged($flag, $entity->nid, $user->uid, 0) ? 'unflag' : 'flag';
|
||||
}
|
||||
else {
|
||||
$action = $flag->is_flagged($entity->nid) ? 'unflag' : 'flag';;
|
||||
}
|
||||
|
||||
$link = $flag->theme($action, $entity->nid);
|
||||
|
||||
// If it's a list, fix the link.
|
||||
if ($flag->module == 'flag_lists') {
|
||||
flag_lists_fix_link($link, $action);
|
||||
}
|
||||
|
||||
$items[] = array(
|
||||
'data' => $link,
|
||||
'class' => array('flag-lists-link', $action.'-action'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#create new list
|
||||
$link = l(
|
||||
'<span>' . t('New @name', array('@name' => variable_get('flag_lists_name', t('list')))) . '</span> <i class="icon-plus"></i>',
|
||||
'flag-lists/add/' . $entity->type,
|
||||
array(
|
||||
// 'query' => drupal_get_destination(),
|
||||
'attributes' => array(
|
||||
'class' => array('flag-lists-create'),
|
||||
'title' => t('create a new @name and use it.', array('@name'=>variable_get('flag_lists_name', t('list')))),
|
||||
'nid' => $entity->nid,
|
||||
'token' => flag_get_token($entity->nid),
|
||||
),
|
||||
'html' => TRUE,
|
||||
)
|
||||
);
|
||||
|
||||
$create = array(
|
||||
'data' => $link,
|
||||
'class' => array('flag-lists-create'),
|
||||
);
|
||||
}
|
||||
|
||||
// if( (!isset($items) || !count($items)) && !isset($create))
|
||||
// return;
|
||||
|
||||
if(isset($items)){
|
||||
$ops = array(
|
||||
'node' => $entity,
|
||||
'items' => $items,
|
||||
);
|
||||
}
|
||||
|
||||
if(isset($create)){
|
||||
$ops['create'] = $create;
|
||||
// drupal_add_css(drupal_get_path('module', 'flag') . '/theme/flag.css');
|
||||
// drupal_add_js(drupal_get_path('module', 'flag') . '/theme/flag.js');
|
||||
}
|
||||
|
||||
if(isset($ops)){
|
||||
// dsm($ops, 'ops');
|
||||
drupal_add_js(drupal_get_path('module', 'materio_flag').'/js/materio_flag-ck.js');
|
||||
|
||||
return theme('materio_flag_mylists_entity_links', $ops);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Implements hook_theme().
|
||||
*/
|
||||
@@ -303,18 +353,40 @@ function materio_flag_theme($existing, $type, $theme, $path) {
|
||||
'template' => 'materio-flag-mylists-block',
|
||||
'path' => drupal_get_path('module', 'materio_flag').'/templates',
|
||||
),
|
||||
'materio_flag_mylists_nav_block' => array(
|
||||
'arguments' => array(),
|
||||
'template' => 'materio-flag-mylists-nav-block',
|
||||
'path' => drupal_get_path('module', 'materio_flag').'/templates',
|
||||
),
|
||||
'materio_flag_mylists_entity_links' => array(
|
||||
'variables' => array('node' => NULL, 'create' => NULL, 'items' => array()),
|
||||
),
|
||||
'materio_flag_mylists_list' => array(
|
||||
'template' => 'materio-flag-mylists-list',
|
||||
'path' => drupal_get_path('module', 'materio_flag').'/templates',
|
||||
'variables' => array(
|
||||
'count' => 0,
|
||||
'items' => array(),
|
||||
'view_mode' => 'teaser',
|
||||
'pager' => NULL,
|
||||
'fid' => null,
|
||||
'name' => null,
|
||||
'title' => null,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
function template_preprocess_materio_flag_mybookmarks_block($vars){
|
||||
function template_preprocess_materio_flag_mybookmarks_block(&$vars){
|
||||
// dsm($vars, 'vars');
|
||||
}
|
||||
|
||||
|
||||
function template_preprocess_materio_flag_mylists_block($vars){
|
||||
function template_preprocess_materio_flag_mylists_block(&$vars){
|
||||
// dsm($vars, 'vars');
|
||||
}
|
||||
|
||||
function template_preprocess_materio_flag_mylists_nav_block(&$vars){
|
||||
// dsm($vars, 'vars');
|
||||
}
|
||||
|
||||
@@ -335,4 +407,20 @@ function theme_materio_flag_mylists_entity_links($vars){
|
||||
|
||||
return theme('item_list', array('items' => $items, 'type' => 'ul', 'attributes' => array('class' => 'flag-lists-entity-links')));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
function template_preprocess_materio_flag_mylists_list(&$vars) {
|
||||
|
||||
$vars['list_count'] = format_plural(
|
||||
$vars['count'],
|
||||
'@name @title contains 1 item.', // in @sec seconds
|
||||
'@name @title contains @count items.', // in @sec seconds
|
||||
array(
|
||||
'@name' => $vars['name'],
|
||||
'@title' => $vars['title'],
|
||||
)
|
||||
);
|
||||
|
||||
// dsm($vars, '$vars');
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user