- added materio_user.module (add permission to view the profile page)
- materio_serach_api.pages : limit actu items for anonymous
- materio_search_api_ajax.pages & materio_flag.pages : redirect to real page if current page not corresponding on ajax request (solve the view mode block visibility on user edit profile page)
- materio_flag : added edit lists functionalities ++ get_list_page_title func

Signed-off-by: bachy <git@g-u-i.net>
This commit is contained in:
bachy
2012-11-21 10:06:34 +01:00
parent 61c83b5a75
commit 2601c718c2
15 changed files with 628 additions and 76 deletions
+208 -3
View File
@@ -70,7 +70,7 @@ function materio_flag_createlist_form($type){
// }
// } elseif (isset($return)) {
$form_state['build_info']['args'] = array(NULL, 'breve');
// $form_state['build_info']['args'] = array(NULL, 'breve');
// $f = drupal_get_form('flag_lists_form', $form_state);
// dsm($f);
@@ -130,6 +130,187 @@ function materio_flag_createlist_form($type){
}
/**
* materio_flag_editlist_form()
*/
function materio_flag_editlist_form($type, $fid){
$debug = false;
$path = 'flags/lists/edit/' . $fid;
// check if request is ajax, if not rediret
if (!$debug && (!isset($_SERVER['HTTP_X_REQUESTED_WITH']) || strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) != 'xmlhttprequest')) {
drupal_goto($path);
exit ;
}
// If name is numeric, then we have the fid, so get the name.
if (is_numeric($fid)) {
$name = db_select('flag_lists_flags', 'f')
->fields('f', array('name'))
->condition('fid', $fid)
->execute()
->fetchField();
}
if(flag_lists_is_owner('edit', $fid)){
$flag = flag_lists_get_flag($name);
$form = array(
'#type' => 'form',
'#id' => 'materio-flag-edit-list-form',
);
$form['type'] = array(
'#type' => 'hidden',
'#value' => $type,
'#name' => 'type',
);
$form['fid'] = array(
'#type' => 'hidden',
'#value' => $fid,
'#name' => 'fid',
);
$form['name'] = array(
'#type' => 'hidden',
'#value' => $name,
'#name' => 'name',
);
$form['listtitle'] = array(
'#type' => 'textfield',
'#title' => t('Edit this '.variable_get('flag_lists_name', 'list')),
'#value' => $flag->title,
// '#size' => 100,
'#maxlength' => 255,
'#name' => 'flag-lists-title',
'#description' => t('A short, descriptive title for this Folder list. Limit to 255 characters.'),
);
$form['actions'] = array(
'#prefix' => '<div class="actions">',
'#suffix' => '</div>',
);
$form['actions']['save'] = array(
'#type' => 'submit',
'#value' => t('save'),
'#name' => 'save',
);
$form['actions']['delete'] = array(
'#type' => 'submit',
'#value' => t('delete'),
'#name' => 'delete',
);
$form['actions']['cancel'] = array(
'#type' => 'button',
'#value' => t('cancel'),
'#name' => 'cancel',
);
// dsm($form, 'form');
$return = drupal_render($form);
$rep = array(
'return'=>$return,
);
}else{
$rep = array(
'status' => 'error',
'message' => t('you do not have rights to edit this '.variable_get('flag_lists_name', 'list')),
);
}
if ($debug) {
dsm($rep, 'rep');
return "debug display";
}else{
drupal_json_output($rep);
}
}
function materio_flag_edit_list($fid, $name, $title){
$path = 'flags/lists/edit/' . $fid;
// check if request is ajax, if not rediret
if (!isset($_SERVER['HTTP_X_REQUESTED_WITH']) || strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) != 'xmlhttprequest') {
drupal_goto($path);
exit ;
}
if(!flag_lists_is_owner('edit', $fid)){
$rep = array(
'error' => true,
'message' => t('You have not enough rights to edit this @name.', array('@name' => variable_get('flag_lists_name', t('list'))))
);
}else if (flag_lists_title_exists($title, 'materiau') || flag_lists_title_exists($title, 'breve')){
$rep = array(
'error' => true,
'message' => t('You already have a @name with this name.', array('@name' => variable_get('flag_lists_name', t('list'))))
);
}else{
$flag = flag_lists_get_flag($name);
$flag->title = $title;
flag_lists_set_messages($flag);
flag_lists_save($flag);
_flag_lists_clear_cache();
$rep = array(
'status' => 'saved',
'listname' => $name,
'listtitle' => $title,
);
}
drupal_json_output($rep);
}
function materio_flag_delete_list($fid){
$path = 'flags/lists/delete/' . $fid;
// check if request is ajax, if not rediret
if (!isset($_SERVER['HTTP_X_REQUESTED_WITH']) || strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) != 'xmlhttprequest') {
drupal_goto($path);
exit ;
}
if(!flag_lists_is_owner('delete', $fid)){
$rep = array(
'error' => true,
'message' => t('You have not enough rights to delete this @name.', array('@name' => variable_get('flag_lists_name', t('list'))))
);
}else{
// If name is numeric, then we have the fid, so get the name.
if (is_numeric($fid)) {
$name = db_select('flag_lists_flags', 'f')
->fields('f', array('name'))
->condition('fid', $fid)
->execute()
->fetchField();
}
$flag = flag_lists_get_flag($name);
flag_lists_fl_delete($flag);
$rep = array(
'status' => 'saved',
);
}
drupal_json_output($rep);
}
function materio_flag_nodelinks(){
$nids = explode(';', $_REQUEST['nids']);
@@ -157,7 +338,7 @@ function materio_flag_user_lists($fid){
$flag = flag_lists_get_flag($fid);
// dsm($flag, 'flag');
drupal_set_title('<i class="icon-materio-folder"></i>'.check_plain($flag->title), PASS_THROUGH);
drupal_set_title(_materio_flag_get_listpagetitle($flag), PASS_THROUGH);
$flaged_content = flag_lists_get_flagged_content($fid, $user->uid);
// dsm($flaged_content, 'flaged_content');
@@ -195,7 +376,9 @@ function materio_flag_ajax_list($fid, $page = 0){
$_GET['page'] = $page;
$path = 'lists/'.$fid;
$list_path = 'lists';
$path = $list_path.'/'.$fid;
// check if request is ajax, if not rediret to search_api_page page with right keys
if (!$debug && (!isset($_SERVER['HTTP_X_REQUESTED_WITH']) || strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) != 'xmlhttprequest')) {
@@ -203,6 +386,28 @@ function materio_flag_ajax_list($fid, $page = 0){
exit;
}
if(isset($_GET['current_path'])){
// dsm($_GET['current_path'], '$_GET[current_path]');
// url() generates the prefix using hook_url_outbound_alter(). Instead of
// running the hook_url_outbound_alter() again here, extract the prefix
// from url().
url('', array('prefix' => &$prefix));
$cur_path = str_replace($base_url.base_path().$prefix, '', $_GET['current_path']);
// dsm($cur_path, 'cur_path');
$cur_is_list_path = strpos($cur_path, $list_path);
// dsm($matches, '$matches');
if($cur_is_list_path === false){
$rep = array(
"redirect" => $base_url.base_path().$prefix.$path,
);
drupal_json_output($rep);
exit;
}
}
// get results
menu_set_active_item($path);
$return = menu_execute_active_handler($path, FALSE);