|
@@ -19,10 +19,10 @@ function materio_flag_permission() {
|
|
|
* 'description' => t('Perform administration tasks for my module.'),
|
|
|
*),
|
|
|
*/
|
|
|
- 'access mybookmarks block' => array(
|
|
|
- 'title' => t('Show my bookmarks block'),
|
|
|
- 'description' => t('access own bookmarks block'),
|
|
|
- ),
|
|
|
+ // 'access mybookmarks block' => array(
|
|
|
+ // 'title' => t('Show my bookmarks block'),
|
|
|
+ // 'description' => t('access own bookmarks block'),
|
|
|
+ // ),
|
|
|
);
|
|
|
}
|
|
|
|
|
@@ -39,11 +39,25 @@ function materio_flag_menu() {
|
|
|
|
|
|
|
|
|
$items['materioflag/refresh/block/bookmarks'] = $base+array(
|
|
|
- 'access arguments' => array('access mybookmarks block'),
|
|
|
- 'page callback' => 'materio_flag_refresh_block_bookmarks',
|
|
|
- // 'page arguments' => array(),
|
|
|
+ 'access arguments' => array('flag bookmarks'),
|
|
|
+ 'page callback' => 'materio_flag_refresh_block',
|
|
|
+ 'page arguments' => array(3),
|
|
|
+ );
|
|
|
+
|
|
|
+ $items['materioflag/refresh/block/mylists'] = $base+array(
|
|
|
+ 'access arguments' => array('create flag lists'),
|
|
|
+ 'page callback' => 'materio_flag_refresh_block',
|
|
|
+ 'page arguments' => array(3),
|
|
|
);
|
|
|
|
|
|
+ $items['materioflag/createlist/%/%/%ctools_js'] = $base+array(
|
|
|
+ 'access arguments' => array('create flag lists'),
|
|
|
+ 'access callback' => 'user_access',
|
|
|
+ 'page callback' => 'materio_flag_createlist',
|
|
|
+ 'page arguments' => array(2,3,4),
|
|
|
+ 'delivery callback' => 'ajax_deliver',
|
|
|
+ 'theme callback' => 'ajax_base_page_theme',
|
|
|
+ );
|
|
|
|
|
|
return $items;
|
|
|
}
|
|
@@ -68,7 +82,6 @@ function materio_flag_block_info() {
|
|
|
return $blocks;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
* Implements hook_block_view().
|
|
|
*/
|
|
@@ -79,9 +92,9 @@ function materio_flag_block_view($delta = '') {
|
|
|
|
|
|
switch ($delta) {
|
|
|
case 'materio_flag_mybookmarks':
|
|
|
- if(user_access('access own bookmarks block')){
|
|
|
+ if(user_access('access mybookmarks block')){
|
|
|
$userflags = flag_get_user_flags('node');
|
|
|
- // dsm($userflags, 'userflags');
|
|
|
+ //dsm($userflags, 'userflags');
|
|
|
if(isset($userflags['bookmarks'])){
|
|
|
$userbookmarks = array();
|
|
|
foreach ($userflags['bookmarks'] as $nid => $flag) {
|
|
@@ -109,7 +122,11 @@ function materio_flag_block_view($delta = '') {
|
|
|
$fcn = array();
|
|
|
foreach ($flaged_content as $entity) {
|
|
|
if($entity->entity_type == 'node'){
|
|
|
- $fcn[] = node_load($entity->entity_id);
|
|
|
+ $node = node_load($entity->entity_id);
|
|
|
+ // dsm($node, 'node');
|
|
|
+
|
|
|
+ $node->flag_names[] = $name;
|
|
|
+ $fcn[] = $node;
|
|
|
}
|
|
|
}
|
|
|
$lists[$name] = array(
|
|
@@ -119,54 +136,29 @@ function materio_flag_block_view($delta = '') {
|
|
|
}
|
|
|
|
|
|
if(isset($lists)){
|
|
|
- $block['subject'] = t('My !listname', array('!listname'=>variable_get('flag_lists_name', 'list')));
|
|
|
+ $block['subject'] = t('My !listname'.'s', array('!listname'=>variable_get('flag_lists_name', 'list')));
|
|
|
$block['content'] = theme('materio_flag_mylists_block', array("lists"=>$lists, "viewmode"=>"bookmark"));
|
|
|
// $block['content'] = theme('flag_lists_user_page', array('uid' => $user->uid));
|
|
|
}else{
|
|
|
|
|
|
- $block['subject'] = t('My !listname', array('!listname'=>variable_get('flag_lists_name', 'list')));
|
|
|
+ $block['subject'] = t('My !listname'.'s', array('!listname'=>variable_get('flag_lists_name', 'list')));
|
|
|
$block['content'] = t('No !listname yet. Add !listname on clicking on results star', array('!listname'=>variable_get('flag_lists_name', 'list')));
|
|
|
}
|
|
|
-
|
|
|
+ drupal_add_js(drupal_get_path('module', 'materio_flag').'/js/materio_flag-ck.js');
|
|
|
}
|
|
|
break;
|
|
|
}
|
|
|
return $block;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
* Implements hook_entity_info_alter().
|
|
|
*/
|
|
|
function materio_flag_entity_info_alter(&$entity_info) {
|
|
|
- // Set the controller class for nodes to an alternate implementation of the
|
|
|
- // DrupalEntityController interface.
|
|
|
- /*
|
|
|
- *$entity_info['node']['controller class'] = 'MyCustomNodeController';
|
|
|
- */
|
|
|
- /* Your code here */
|
|
|
$entity_info['node']['view modes']['bookmark'] = array(
|
|
|
'label' => t('Bookmark'),
|
|
|
'custom settings' => TRUE,
|
|
|
);
|
|
|
-
|
|
|
-}
|
|
|
-
|
|
|
-/**
|
|
|
- * Implements hook_entity_prepare_view().
|
|
|
- */
|
|
|
-function materio_flag_entity_prepare_view($entities, $type) {
|
|
|
- // Load a specific node into the user object for later theming.
|
|
|
- /*
|
|
|
- *if ($type == 'user') {
|
|
|
- * $nodes = mymodule_get_user_nodes(array_keys($entities));
|
|
|
- * foreach ($entities as $uid => $entity) {
|
|
|
- * $entity->user_node = $nodes[$uid];
|
|
|
- * }
|
|
|
- *}
|
|
|
- */
|
|
|
- /* Your code here */
|
|
|
-
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -176,41 +168,200 @@ function materio_flag_entity_prepare_view($entities, $type) {
|
|
|
*/
|
|
|
function materio_flag_entity_view($entity, $type, $view_mode, $langcode) {
|
|
|
if($type == 'node'){
|
|
|
- // dsm($entity, 'entity');
|
|
|
- // $userlists = flag_lists_get_user_flags();
|
|
|
- // if (isset($userlists)) {
|
|
|
- // $entity->content['links']['flaglists'] = array(
|
|
|
- // '#theme' => 'links',
|
|
|
- // '#links' => $userlists,
|
|
|
- // '#attributes' => array('class' => array('links', 'inline')),
|
|
|
- // );
|
|
|
- // }
|
|
|
-
|
|
|
- // $create = theme('flag_lists_list', array(
|
|
|
- // 'node' => $entity,
|
|
|
- // 'create' => 0,
|
|
|
- // 'ops' => 0,
|
|
|
- // 'use_flags' => 1)
|
|
|
- // );
|
|
|
- // dsm($create, 'create');
|
|
|
-
|
|
|
- $flaglists_links = theme('materio_flag_mylists_entity_links', array(
|
|
|
- 'node' => $entity,
|
|
|
- 'create' => 0,
|
|
|
- 'ops' => 0,
|
|
|
- 'use_flags' => 1)
|
|
|
- );
|
|
|
|
|
|
- $entity->content['links']['flaglistslinks'] = array('#markup' => $flaglists_links,"#html"=>true);
|
|
|
-
|
|
|
// 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 ($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,// . '/js',
|
|
|
+ // 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'))))
|
|
|
+ // )
|
|
|
+ // )
|
|
|
+ // );
|
|
|
+
|
|
|
+ _materio_flag_include_modal();
|
|
|
+
|
|
|
+ $linktext = t('New @name', array('@name' => variable_get('flag_lists_name', t('list'))));
|
|
|
+ $link = ctools_modal_text_button(
|
|
|
+ $linktext,
|
|
|
+ 'materioflag/createlist/'.$entity->type.'/'.$entity->nid.'/nojs',
|
|
|
+ t('Create a new @name and use it.', array('@name'=>variable_get('flag_lists_name', t('list')))),
|
|
|
+ 'ctools-modal-ctools-materio-flag-style'
|
|
|
+ );
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ $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;
|
|
|
+
|
|
|
+
|
|
|
+ $flaglists_links = theme('materio_flag_mylists_entity_links', $ops);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ $entity->content['links']['flaglistslinks'] = array('#markup' => $flaglists_links,"#html"=>true);
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * Add css and javascript for modal dialog.
|
|
|
+ */
|
|
|
+function _materio_flag_include_modal() {
|
|
|
+ static $added = FALSE;
|
|
|
+ if ($added == FALSE) {
|
|
|
+
|
|
|
+ // Do not add css and scripts again.
|
|
|
+ $added = TRUE;
|
|
|
+
|
|
|
+ // Include the CTools tools that we need.
|
|
|
+ ctools_include('modal');
|
|
|
+ ctools_include('ajax');
|
|
|
+ ctools_modal_add_js();
|
|
|
+
|
|
|
+ // Create our own javascript that will be used to theme a modal.
|
|
|
+ $materio_flag_style = array(
|
|
|
+ 'ctools-materio-flag-style' => array(
|
|
|
+ 'modalSize' => array(
|
|
|
+ 'type' => 'fixed',
|
|
|
+ 'width' => 400,
|
|
|
+ 'height' => 160,
|
|
|
+ 'contentRight' => 30,
|
|
|
+ 'contentBottom' => 0,
|
|
|
+ ),
|
|
|
+ 'modalOptions' => array(
|
|
|
+ 'opacity' => 0.8,
|
|
|
+ 'background-color' => '#FFF',
|
|
|
+ ),
|
|
|
+ 'closeText' => '',
|
|
|
+ 'throbber' => theme('image', array('path' => ctools_image_path('ajax-loader.gif', 'ajax_register'))),
|
|
|
+ 'animation' => 'fadeIn',
|
|
|
+ 'animationSpeed' => 'fast',
|
|
|
+ ),
|
|
|
+ );
|
|
|
+ drupal_add_js($materio_flag_style, 'setting');
|
|
|
+
|
|
|
+ // Add module css and js.
|
|
|
+ //ctools_add_css('ajax-register', 'ajax_register');
|
|
|
+ //ctools_add_js('ajax-register', 'ajax_register');
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ * Executes form.
|
|
|
+ *
|
|
|
+ * see _ajax_register_execute_form()
|
|
|
+ */
|
|
|
+function _materio_flag_addlists_execute_form($form_state, $nid){
|
|
|
+
|
|
|
+ $node = node_load($nid);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ // Include additional ajax commands.
|
|
|
+ ctools_include('ajax');
|
|
|
+ ctools_include('modal');
|
|
|
+ $message = t('@node has been added to newly created @name @title. The current page will be reloaded.', array(
|
|
|
+ '@node' => $node->title,
|
|
|
+ '@name' => variable_get('flag_lists_name', 'list'),
|
|
|
+ '@title' => $form_state['values']['title'])
|
|
|
+ );
|
|
|
|
|
|
+ $commands[] = ctools_modal_command_display(t('@title created', array('@title' => $form_state['values']['title'])), '<div>'.$message.'</div>'.theme('status_messages'));
|
|
|
+ // $commands[] = ctools_ajax_command_reload();
|
|
|
+ // dsm($form_state);
|
|
|
+ return $commands;
|
|
|
+}
|
|
|
|
|
|
/**
|
|
|
* Implements hook_theme().
|
|
@@ -228,7 +379,7 @@ function materio_flag_theme($existing, $type, $theme, $path) {
|
|
|
'path' => drupal_get_path('module', 'materio_flag').'/templates',
|
|
|
),
|
|
|
'materio_flag_mylists_entity_links' => array(
|
|
|
- 'variables' => array('node' => NULL, 'create' => NULL, 'ops' => NULL, 'use_flags' => NULL),
|
|
|
+ 'variables' => array('node' => NULL, 'create' => NULL, 'items' => array()),
|
|
|
),
|
|
|
);
|
|
|
}
|
|
@@ -242,58 +393,21 @@ function template_preprocess_materio_flag_mylists_block($vars){
|
|
|
// dsm($vars, 'vars');
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ * theme_materio_flag_mylists_entity_links()
|
|
|
+ *
|
|
|
+ * see theme_flag_lists_list()
|
|
|
+ */
|
|
|
function theme_materio_flag_mylists_entity_links($vars){
|
|
|
- // dsm($vars, 'vars');
|
|
|
- return;
|
|
|
|
|
|
- $node = $vars['node'];
|
|
|
- $create = $vars['create'];
|
|
|
- $ops = $vars['ops'];
|
|
|
- $use_flags = $vars['use_flags'];
|
|
|
-
|
|
|
- $items = array();
|
|
|
-
|
|
|
- // Make sure we have a node.
|
|
|
- if (is_object($node) && user_access('create flag lists')) {
|
|
|
- $content_type = $node->type;
|
|
|
- $entity_id = $node->nid;
|
|
|
- }
|
|
|
- else {
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- // Do we have a list template for this node type, or are we s
|
|
|
- if (!flag_lists_template_exists($content_type) && !$use_flags) {
|
|
|
- return;
|
|
|
- }
|
|
|
+ // $node = $vars['node'];
|
|
|
+ $items = $vars['items'];
|
|
|
|
|
|
+ // dsm($vars, 'vars HO');
|
|
|
|
|
|
- global $user;
|
|
|
- if ($flags = flag_lists_get_user_flags($content_type, $user, $use_flags)) {
|
|
|
- // Build the list of lists for this node.
|
|
|
- foreach ($flags as $flag) {
|
|
|
- if ($flag->module == 'flag_lists') {
|
|
|
- $action = _flag_lists_is_flagged($flag, $entity_id, $user->uid, 0) ? 'unflag' : 'flag';
|
|
|
- }
|
|
|
- else {
|
|
|
- $action = $flag->is_flagged($entity_id) ? 'unflag' : 'flag';;
|
|
|
- }
|
|
|
-
|
|
|
- // Do we need the ops?
|
|
|
- if ($ops && $flag->module == 'flag_lists') {
|
|
|
- $ops_links = theme('flag_lists_ops', array('flag' => $flag));
|
|
|
- $link = $flag->theme($action, $entity_id) . $ops_links;
|
|
|
- }
|
|
|
- else {
|
|
|
- $link = $flag->theme($action, $entity_id);
|
|
|
- }
|
|
|
-
|
|
|
- // If it's a list, fix the link.
|
|
|
- if ($flag->module == 'flag_lists') {
|
|
|
- flag_lists_fix_link($link, $action);
|
|
|
- }
|
|
|
- $items[] = $link;
|
|
|
- }
|
|
|
- }
|
|
|
+ if(isset($vars['create']))
|
|
|
+ $items[] = $vars['create'];
|
|
|
+
|
|
|
+ return theme('item_list', array('items' => $items, 'type' => 'ul', 'attributes' => array('class' => 'flag-lists-entity-links')));
|
|
|
|
|
|
-}
|
|
|
+}
|