| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497 | 
							- <?php
 
- /**
 
-  * materio_flag_refresh_blocks($flag)
 
-  *
 
-  */
 
- function materio_flag_refresh_block($flag){
 
- 	switch ($flag) {
 
- 		case 'bookmarks':
 
- 			$block_name = 'materio_flag_mybookmarks';
 
- 			break;
 
- 	case 'lists':
 
- 		$block_name = 'materio_flag_mylists';
 
-     $block_nav_name = 'materio_flag_mylists_nav';
 
- 		break;
 
- 	}
 
- 	if(!isset($block_name))
 
- 		return;
 
- 	$rep = array("flag"=>$flag);
 
- 	$block = block_load('materio_flag', $block_name);
 
- 	$block_content = _block_render_blocks(array($block));
 
- 	$build = _block_get_renderable_array($block_content);
 
- 	$block_rendered = drupal_render($build);
 
-   $rep['block'] = $block_rendered;
 
-   if(isset($block_nav_name)){
 
-     $block = block_load('materio_flag', $block_nav_name);
 
-     $block_content = _block_render_blocks(array($block));
 
-     $build = _block_get_renderable_array($block_content);
 
-     $block_rendered = drupal_render($build);
 
-     $rep['block_nav'] = $block_rendered;
 
-   }
 
-  	drupal_json_output($rep);
 
- }
 
- /**
 
-  * materio_flag_createlist($type)
 
-  *
 
-  */
 
- function materio_flag_createlist_form($type){
 
-   $debug = false;
 
- 	$path = 'flag-lists/add/' . $type;
 
-   // 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('flag-lists/add/' . $type);
 
-     exit ;
 
-   }
 
-   // menu_set_active_item($path);
 
-   // $return = menu_execute_active_handler($path, FALSE);
 
-   // if (is_int($return)) {
 
-   //   switch ($return) {
 
-   //     case MENU_NOT_FOUND :
 
-   //       drupal_add_http_header('Status', '404 Not Found');
 
-   //       break;
 
-   //     case MENU_ACCESS_DENIED :
 
-   //       drupal_add_http_header('Status', '403 Forbidden');
 
-   //       break;
 
-   //     case MENU_SITE_OFFLINE :
 
-   //       drupal_add_http_header('Status', '503 Service unavailable');
 
-   //       break;
 
-   //   }
 
-   // } elseif (isset($return)) {
 
-   // $form_state['build_info']['args'] = array(NULL, 'breve');
 
-   // $f = drupal_get_form('flag_lists_form', $form_state);
 
-   // dsm($f);
 
-   $form = array(
 
-     '#type' => 'form',
 
-     '#id' => 'materio-flag-create-list-form',
 
-   );
 
-   $form['type'] = array(
 
-     '#type' => 'hidden',
 
-     '#value' => $type,
 
-     '#name' => 'type',
 
-   );
 
-   $form['listname'] = array(
 
-     '#type' => 'textfield',
 
-     '#title' => t('Create new @name', array('@name'=>variable_get('flag_lists_name', 'list'))),
 
-     '#default_value' => '',
 
-     // '#size' => 100,
 
-     '#maxlength' => 255,
 
-     '#name' => 'flag-lists-name',
 
-     '#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']['create'] = array(
 
-     '#type' => 'submit',
 
-     '#value' => t('create'),
 
-     '#name' => 'create',
 
-   );
 
-   $form['actions']['cancel'] = array(
 
-     '#type' => 'button',
 
-     '#value' => t('cancel'),
 
-     '#name' => 'cancel',
 
-   );
 
-   // dsm($form, 'form');
 
-   $return = drupal_render($form);
 
-   $rep = array(
 
-     'rendered_form'=>$return,
 
-   );
 
-   if ($debug) {
 
-     dsm($rep, 'rep');
 
-     return "debug display";
 
-   }else{
 
-     drupal_json_output($rep);
 
-   }
 
- }
 
- /**
 
-  * 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(
 
-       'rendered_form'=>$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']);
 
-   if(count($nids)){
 
-     foreach ($nids as $nid) {
 
-       $node = node_load($nid);
 
-       $lks = render(materio_flag_get_entity_links($node, 'node'));
 
-       $links[$nid] = $lks;
 
-     }
 
-     $rep = array(
 
-       "status" => 1,
 
-       "nids" => $nids,
 
-       'links' => $links,
 
-     );
 
-   }else{
 
-     $rep['status'] = 0;
 
-   }
 
-   drupal_json_output($rep);
 
- }
 
- function materio_flag_user_bookmarks(){
 
-   global $user;
 
-   drupal_set_title(t('My bookmarks'), PASS_THROUGH);
 
-   $flaged = flag_get_user_flags('node');
 
-   // dsm($flaged, 'flaged');
 
-   $flag = flag_get_flag('bookmarks');
 
-   $flaged_content = $flaged['bookmarks'];
 
-   // dsm($flaged_content, 'flaged_content');
 
-   $viewmode = isset($user->data['materiosearchapi_viewmode']) ? $user->data['materiosearchapi_viewmode'] : variable_get('defaultviewmode', 'full');
 
-   $limit = variable_get($viewmode.'_limite', '10');
 
-   $offset = pager_find_page() * $limit;
 
-   $count = count($flaged_content);
 
-   $max = $offset+$limit > $count ? $count : $offset+$limit;
 
-   $i = 0;
 
-   foreach ($flaged_content as $id => $item) {
 
-     if($i >= $offset){
 
-       if($i < $max){
 
-         if($item->entity_type == 'node'){
 
-           $items[] = node_load($id);
 
-         }
 
-       }else{
 
-         break;
 
-       }
 
-     }
 
-   }
 
-   $ret['#items'] = $items;
 
-   $ret['#theme'] = 'materio_flag_mylists_list';
 
-   $ret['#view_mode'] = $viewmode;
 
-   $ret['#fid'] = $flag->fid;
 
-   $ret['#count'] = $count;
 
-   $ret['#name'] = variable_get('flag_lists_name', 'list');
 
-   $ret['#title'] = $flag->title;
 
-   pager_default_initialize($count, $limit);
 
-   $ret['#pager'] = theme('pager');
 
-   drupal_add_js(drupal_get_path('module', 'materio_flag').'/js/materio_flag-ck.js');
 
-   return $ret;
 
- }
 
- function materio_flag_user_lists($fid){
 
-   global $user;
 
-   $flag = flag_lists_get_flag($fid);
 
-   // dsm($flag, 'flag');
 
-   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');
 
-   $viewmode = isset($user->data['materiosearchapi_viewmode']) ? $user->data['materiosearchapi_viewmode'] : variable_get('defaultviewmode', 'full');
 
-   $limit = variable_get($viewmode.'_limite', '10');
 
-   $offset = pager_find_page() * $limit;
 
-   $count = count($flaged_content);
 
-   $max = $offset+$limit > $count ? $count : $offset+$limit;
 
-   for ($i=$offset; $i < $max; $i++) {
 
-     if($flaged_content[$i]->entity_type == 'node'){
 
-       $items[] = node_load($flaged_content[$i]->entity_id);
 
-     }
 
-   }
 
-   $ret['#items'] = $items;
 
-   $ret['#theme'] = 'materio_flag_mylists_list';
 
-   $ret['#view_mode'] = $viewmode;
 
-   $ret['#fid'] = $fid;
 
-   $ret['#count'] = $count;
 
-   $ret['#name'] = variable_get('flag_lists_name', 'list');
 
-   $ret['#title'] = $flag->title;
 
-   pager_default_initialize($count, $limit);
 
-   $ret['#pager'] = theme('pager');
 
-   return $ret;
 
- }
 
- function materio_flag_ajax_list($fid, $page = 0){
 
-   $debug = false;
 
-   $_GET['page'] = $page;
 
-   if($fid == 1){
 
-     $list_path = $path = 'bookmarks';
 
-   }else{
 
-     $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')) {
 
-     drupal_goto($path, array('query'=>array('page'=>$page)), 301);
 
-     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);
 
-   dsm($return, '$return');
 
-   if (is_int($return)) {
 
-     switch ($return) {
 
-       case MENU_NOT_FOUND :
 
-         drupal_add_http_header('Status', '404 Not Found');
 
-         break;
 
-       case MENU_ACCESS_DENIED :
 
-         drupal_add_http_header('Status', '403 Forbidden');
 
-         break;
 
-       case MENU_SITE_OFFLINE :
 
-         drupal_add_http_header('Status', '503 Service unavailable');
 
-         break;
 
-     }
 
-   } elseif (isset($return)) {
 
-     if (is_array($return)) {
 
-       $rendered = drupal_render($return);
 
-     }
 
-     $rep = array(
 
-       'rendered' => $rendered,
 
-       'path' => $path,
 
-       'title' => drupal_get_title(),
 
-     );
 
-     if ($debug) {
 
-       dsm($rep, 'rep');
 
-       return "debug display";
 
-     }else{
 
-       drupal_json_output($rep);
 
-     }
 
-   }
 
- }
 
 
  |