Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 16.16 KB | None | 0 0
  1. <?php
  2. // $Id$
  3.  
  4. /**
  5.  * @file
  6.  * Build and display the Gallery Assist Container.
  7.  * This file will be included if the parameter "show_layout" is setted to "list"
  8.  *
  9.  * @see gallery_assist_include_display().
  10.  */
  11.  
  12. /**
  13.  * Display the Gallery Assist Container as list.
  14.  */
  15. function gallery_assist_display_list($node, $opt='', $owner='') {
  16.   global $user;
  17.  
  18.   $conf = $node->gallconf[$node->type];
  19.   $conf['show_title'] = 0;
  20.  
  21.   $my_teaser_count = 1;
  22.  
  23.   $my_page_count = $conf['items_per_row'] == 'unlimited' ? count($node->gallitems) : $conf['items_per_row'] * $conf['rows_per_page'];
  24.   if ($conf['items_per_row'] == 'unlimited' && $opt == 'teaser') {
  25.     $my_teaser_count = 3;
  26.   }
  27.   $my_previous = '‹ previous';
  28.   $my_next = 'next ›';
  29.  
  30.   if (count($node->gallitems) == 0) {
  31.     return;
  32.   }
  33.  
  34.   $e = 0;
  35.   foreach ($node->gallitems as $pid => $item) {
  36.     $img_obj = image_get_info($item->tpath);
  37.     if ($img_obj['width'] > $img_obj['height']) {
  38.       $img_obj['layout'] = 'h';
  39.     }
  40.     else {
  41.       $img_obj['layout'] = 'v';
  42.     }
  43.  
  44.     foreach ($img_obj as $k => $v) {
  45.       $node->gallitems[$pid]->$k = $v;
  46.       $node->gallitems[$pid]->show_title = 0;
  47.     }
  48.    
  49.     $node->gallitems[$pid]->row = $i&1 ? 'odd' : 'even';
  50.  
  51.     $node->gallitems[$pid]->my_nid = $node->nid;
  52.     $my_item_box = gallery_assist_item_box_list($node->type, $node->gallitems[$pid], $conf, $img_obj);
  53.     $my_boxes[] = $my_item_box;
  54.     ++$i;
  55.   }
  56.  
  57.   // Prepare the pager OLD VARIANT OF gallery_assist.
  58.   $node->gall_pager->show = $my_page_count;
  59.  
  60.   $node->gall_pager->cshow = $node->gall_pager->show;
  61.  
  62.   $theme = $user->theme ? $user->theme : variable_get('theme_default', FALSE);
  63.   $my_pager_layout = $conf['pager_layout'];
  64.  
  65.   $my_grafic_next_path = file_exists(drupal_get_path('theme', $theme) .'/ga_pager/'. $my_pager_layout .'/next.png') ? drupal_get_path('theme', $theme) .'/ga_pager/'. $my_pager_layout .'/next.png' : drupal_get_path('module', 'gallery_assist') .'/ga_pager/default/next.png';
  66.   $my_grafic_next = theme('image', $my_grafic_next_path, '', 'go to the next');
  67.   $my_next = $conf['pager_symbol'] == 0 ? t('next ›') : $my_grafic_next;
  68.   $my_grafic_previous_path = file_exists(drupal_get_path('theme', $theme) .'/ga_pager/'. $my_pager_layout .'/previous.png') ? drupal_get_path('theme', $theme) .'/ga_pager/'. $my_pager_layout .'/previous.png' : drupal_get_path('module', 'gallery_assist') .'/ga_pager/default/previous.png';
  69.   $my_grafic_previous = theme('image', $my_grafic_previous_path, '', 'go to the previous');
  70.   $my_previous = $conf['pager_symbol'] == 0 ? t('‹ previous') : $my_grafic_previous;
  71.  
  72.   $my_separator = $conf['pager_symbol'] == 0 ? ' | ' : '&nbsp;&nbsp;&nbsp;';
  73.  
  74.   if ($_GET['page'] == '' || $_GET['page'] == 1) {
  75.     $pages = 0;
  76.     $page = 2;
  77.     $preview = '';
  78.     if (count($my_boxes) <= $node->gall_pager->show) {
  79.       $next = "";
  80.     }
  81.     else {
  82.       $next = l($my_next, $_GET['q'], array('html' => TRUE, 'attributes' => array('class' => $node->type .' pager-next'), 'query' => array('page' => $page, 'titles' => $_GET['titles'])));
  83.     }
  84.   }
  85.   else {
  86.     $pages = $node->gall_pager->show * ($_GET['page'] - 1);
  87.     $page = $_GET['page'];
  88.     $node->gall_pager->cshow = $node->gall_pager->show * $_GET['page'];
  89.  
  90.     $preview = l($my_previous, $_GET['q'], array('html' => TRUE, 'attributes' => array('class' => $node->type .' pager-previous'), 'query' => array('page' => ($_GET['page'] - 1), 'titles' => $_GET['titles'])));
  91.     if ($node->gall_pager->cshow < count($my_boxes)) {
  92.       $next = l($my_next, $_GET['q'], array('html' => TRUE, 'query' => array('page' => ($_GET['page'] + 1), 'titles' => $_GET['titles'])));
  93.     }
  94.     else {
  95.       $next = "";
  96.     }
  97.   }
  98.  
  99.   if (!empty($preview)) {
  100.     $link[] = $preview;
  101.   }
  102.   if (!empty($next)) {
  103.     $link[] = $next;
  104.   }
  105.  
  106.   $my_attr_array = array(
  107.     'style' => 'max-width:'. $node->gallconf[$node->type]['container_width'] .'px;',
  108.   );
  109.   $stl = array();
  110.   $pstl = array();
  111.  
  112.   switch ($opt) {
  113.     case 'teaser':
  114.     for ($i = 0; $i < $my_teaser_count; $i++) {
  115.       $boxes .= $my_boxes[$i];
  116.     }
  117.     $node->gallconf[$node->type]['op'] = 'teaser';
  118.  
  119.     if ($conf['ga_align'] != 'none' || $conf['t_ga_float'] != 'none') {
  120.      
  121.       //ALIGN TEASER
  122.       switch ($conf['ga_align']) {
  123.         case 'center':
  124.         case 'left':
  125.           $stl['l'] = 'margin-right:auto';
  126.           break;
  127.  
  128.         case 'right':
  129.           $stl['r'] = 'margin-left:auto';
  130.           break;
  131.  
  132.       }
  133.  
  134.       //FLOAT TEASER
  135.       switch ($conf['t_ga_float']) {
  136.         case 'left':
  137.           $stl['l'] = 'float:left';
  138.           $stl['mr'] = 'margin-right:10px';
  139.           unset($stl['ml']);
  140.           break;
  141.  
  142.         case 'right':
  143.           $stl['l'] = 'float:right';
  144.           $stl['ml'] = 'margin-left:10px';
  145.           unset($stl['mr']);
  146.           break;
  147.  
  148.       }
  149.     } // end (styles)
  150.     break;
  151.  
  152.     case 'page':
  153.     for ($i=$pages; $i < $node->gall_pager->cshow; $i++) {
  154.       if (drupal_strlen($my_boxes[$i]) > 0) {
  155.         $count[] =  1;
  156.       }
  157.       $boxes .= $my_boxes[$i];
  158.     }
  159.     $node->gallconf[$node->type]['op'] = 'page';
  160.    
  161.     if ($conf['gap_align'] != 'none' || $conf['p_ga_float'] != 'none') { //(styles)
  162.  
  163.       //ALIGN PAGE
  164.       switch ($conf['gap_align']) {
  165.         case 'center':
  166.         case 'left':
  167.           $stl['l'] = 'margin-right:auto';
  168.           $pstl['pl'] = 'text-align:left;';
  169.           break;
  170.  
  171.         case 'right':
  172.           $stl['r'] = 'margin-left:auto';
  173.           $pstl['pl'] = 'text-align:right;';
  174.           break;
  175.       }
  176.  
  177.       //FLOAT PAGE
  178.       switch ($conf['p_ga_float']) {
  179.         case 'left':
  180.           $stl['l'] = 'float:left';
  181.           $stl['mr'] = 'margin-right:10px';
  182.           unset($stl['ml']);
  183.           break;
  184.  
  185.         case 'right':
  186.           $stl['l'] = 'float:right';
  187.           $stl['ml'] = 'margin-left:10px';
  188.           unset($stl['mr']);
  189.           break;
  190.  
  191.       }
  192.     } // end (styles)
  193.     break;
  194.   }
  195.  
  196.   $my_attr_array['style'] .= implode(';', $stl);
  197.  
  198.   $extras['container_width'] = $conf['container_width'];
  199.   $extras['pager_position'] = $conf['pager_position'];
  200.   $extras['pager_style'] = implode(';', $pstl);
  201.  
  202.   if (count($my_boxes) > $node->gall_pager->show && $opt == 'page') {
  203.     $links = implode($my_separator, $link);
  204.     $node_light = new stdClass();
  205.     $pager .= theme('gallery_assist_pager', $node_light, $links, $extras);
  206.   }
  207.  
  208.   $node->gallconf[$node->type]['my_attr'] = $node->gallconf[$node->type]['items_per_row'] == 'unlimited' ? '' : drupal_attributes($my_attr_array);
  209.   $node->gallconf[$node->type]['nid'] = $node->nid;
  210.  
  211.   if ($owner == 'block') {
  212.     $num = count($my_boxes) < $conf['block_gallery_visibles'] ? count($my_boxes) :  $conf['block_gallery_visibles'];
  213.  
  214.     $rand_boxes = array_rand($my_boxes, $num);
  215.    
  216.     foreach ($rand_boxes as $ks => $divs) {
  217.       $b_boxes .= $my_boxes[$ks];
  218.     }
  219.    
  220.     $b_invlisten = count($my_boxes) ? implode($my_boxes) : '';
  221.     return theme('gallery_assist_block_display', $b_boxes . $b_invlisten, $node->gallconf[$node->type], $node->type);
  222.   }
  223.   else {
  224.     return theme('gallery_assist_display_list', $pager, $boxes, $node->gallconf[$node->type], $node->type);
  225.   }
  226. }
  227.  
  228. /**
  229.  * Build and return the gallery item box.
  230.  */
  231. function gallery_assist_item_box_list($type, $item, $conf, $img) {
  232.   global $user;
  233.  
  234.   $item->nodetype = $type;
  235.   $my_title_height = 0;
  236.   $my_item_width = $conf['thumbnail_size'] + $conf['thumbnail_size_plus'] + ($conf['item_padding'] * 2) + ($conf['item_border'] * 2);
  237.  
  238.   if (variable_get('gallery_assist_use_imagecache', 0) == 1 && $conf['force_image_height'] == 1) {
  239.     $my_item_height = $conf['thumbnail_height_size'] + ($conf['item_padding'] * 2) + ($conf['item_border'] * 2) + $my_title_height;
  240.   }
  241.   else {
  242.     $my_item_height = $conf['thumbnail_size'] + ($conf['item_padding'] * 2) + ($conf['item_border'] * 2) + $my_title_height;
  243.   }
  244.  
  245.   $my_item_list_box = array(
  246.     'id' => 'item-box-row-'. $item->pid,
  247.     'class' => $type .' item-box-row '. $item->row,
  248.     'style' => 'height:'. ($my_item_height + 10) .'px;display:block;clear:left;',
  249.   );
  250.  
  251.   $my_item_attr = array(
  252.     'id' => 'item-box-'. $item->pid,
  253.     'class' => $type .' item-box',
  254.     'style' => 'width:'. $my_item_width .'px;',
  255.   );
  256.   $my_item_attr['style'] .= 'position:relative;';
  257.  
  258.   if ($conf['item_margin'] > 0) {
  259.     $top_margin = $conf['item_margin'] / 2;
  260.   }  
  261.     $right_margin = $conf['item_margin'] > 10 ? $conf['item_margin'] : 10;
  262.     $my_item_attr['style'] .= 'margin-right:'. $right_margin .'px;margin-top:'. $top_margin .'px;';
  263.  
  264.   //$link = l('edit', 'node/gallery_assist/'. $item->nid .'/'. $item->pid);
  265.   //$a_link = '<div id="image-box-'. $item->pid .'-links" class="'. $type .' image-box-links">[ '. $link .' ]</div>';
  266.   //$link = l('edit', 'node/gallery_assist/'. $item->nid .'/'. $item->pid);
  267.   //$a_link = '<div id="image-box-'. $item->pid .'-links" class="'. $type .' image-box-links">[ '. $link .' ]</div>'."\n";
  268.  
  269.   $ga_item_attr  = drupal_attributes($my_item_attr);
  270.   $ga_item_list_attr  = drupal_attributes($my_item_list_box);
  271.   //$edit_link  = $user->uid == $item->uid ? $a_link : '';
  272.   //$edit_link  = $user->uid == $item->uid ? $a_link : '';
  273.   $ga_item_box   = gallery_assist_image_box_list($type, $item, $conf, $img);
  274.   $ga_item_desc = '<div class="list-desc-container" style="padding-left:'. ($my_item_width + $right_margin) .'px;">'. $item->pdescription .'</div>';
  275.   //$ga_edit_link  = $_GET['links'] = 'off' ? $edit_link : '';
  276.   $ga_item_copyright = _filter_html(_filter_url($item->copyright, 1), 1);
  277.  
  278.   $output = theme('gallery_assist_item_box_list', $ga_item_list_attr, $ga_item_box, $item->ptitle, $ga_item_copyright, $ga_item_desc, $ga_edit_link, $ga_item_attr);
  279.  
  280.   return $output;
  281. }
  282.  
  283. /**
  284.  * Theme the Gallery Assist Item-Box.
  285.  *
  286.  * @ingroup themeable
  287.  */
  288. function theme_gallery_assist_item_box_list($ga_item_list_attr, $ga_item_box, $ga_item_title, $ga_item_copyright, $ga_item_desc, $ga_edit_link = '', $ga_item_attr = '') {
  289.   $output  = '      <!-- Gallery Assist Item -->'."\n";
  290.   $output .= '      <div'. $ga_item_list_attr .'>'."\n";
  291.   $output .= '        <div'. $ga_item_attr .'>'."\n";
  292.   $output .= $ga_edit_link;
  293.   $output .= $ga_item_box;
  294.   $output .= '        </div>'."\n";
  295.   $output .= '        <div class="title-box-on-list">'. $ga_item_title .'</div>'."\n";
  296.   $output .= !empty($ga_item_copyright) ? '        <div id="gallery-item-copyright" class="gallery-item-copyright">&copy; '. $ga_item_copyright .'</div>'."\n" : '';
  297.   $output .= $ga_item_desc ."\n";
  298.   $output .= '      </div>'."\n";
  299.  
  300.   return $output;
  301. }
  302.  
  303. /**
  304.  * Build and return the image box.
  305.  */
  306. function gallery_assist_image_box_list($type, $item, $conf, $img) {
  307.   if ($conf['shadow'] == 1) {
  308.     $withshadow = ' shadow3';
  309.     drupal_add_css(drupal_get_path('module', 'gallery_assist') .'/css/gallery_assist_shadow.css', 'module', 'all', FALSE);
  310.   }
  311.  
  312.   if (variable_get('gallery_assist_use_imagecache', 0) == 1 && $conf['force_image_height'] == 1) {
  313.     $my_image_height = $conf['thumbnail_height_size'];
  314.  
  315.     $my_box_attr = array(
  316.       'id' => 'image-box-'. $item->pid,
  317.       'class' => $type .' image-box'. $withshadow,
  318.       'style' => 'height:'. $my_image_height .'px;'.
  319.                  'width:'. $conf['thumbnail_size'] + ($conf['item_padding'] * 2) .'px;',
  320.     );
  321.  
  322.     if ($conf['item_padding'] > 0) {
  323.       $my_box_attr['style'] .= 'padding:'. $conf['item_padding'] .'px;';
  324.     }
  325.  
  326.     if ($conf['item_border'] > 0) {
  327.       $my_box_attr['style'] .= 'border:'. $conf['item_border'] .'px solid '. $conf['item_border_color'] .';';
  328.     }
  329.  
  330.     $my_sheet_attr = array(
  331.       'id' => 'image-sheet-'. $item->pid,
  332.       'class' => $type .' image-sheet'. $my_img_behavior,
  333.       'style' => 'height:'. $my_image_height .'px;'.
  334.                  'width:'. $conf['thumbnail_size'] .'px;',
  335.     );
  336.  
  337.     $img = gallery_assist_image_more_info($type, $img, $conf, $my_image_height);
  338.  
  339.     $my_layout = $img['pos'] == 'v' ? 'height' : 'width';
  340.     $my_img_attr = array(
  341.       $my_layout => $conf['thumbnail_size'],
  342.       'style' => 'margin-top:'. $img['top'] .'px;',
  343.     );
  344.   }
  345.   else {
  346.     $my_box_attr = array(
  347.       'id' => 'image-box-'. $item->pid,
  348.       'class' => $type .' image-box'. $withshadow,
  349.       'style' => 'height:'. $conf['thumbnail_size'] + ($conf['item_padding'] * 2) .'px;'.
  350.                  'width:'. $conf['thumbnail_size'] + ($conf['item_padding'] * 2) .'px;',
  351.     );
  352.  
  353.     if ($conf['item_padding'] > 0) {
  354.       $my_box_attr['style'] .= 'padding:'. $conf['item_padding'] .'px;';
  355.     }
  356.  
  357.     if ($conf['item_border'] > 0) {
  358.       $my_box_attr['style'] .= 'border:'. $conf['item_border'] .'px solid '. $conf['item_border_color'] .';';
  359.     }
  360.  
  361.     $my_sheet_attr = array(
  362.       'id' => 'image-sheet-'. $item->pid,
  363.       'class' => $type .' image-sheet'. $my_img_behavior,
  364.       'style' => 'height:'. $conf['thumbnail_size'] .'px;'.
  365.                  'width:'. $conf['thumbnail_size'] .'px;',
  366.     );
  367.  
  368.     $edit_link_attr = array(
  369.       'class' => $type .' ga-item-edit-link',
  370.       'style' => 'position:absolute;top:0px;left:0px;width:100%;',
  371.     );
  372.  
  373.     $img = gallery_assist_image_more_info($type, $img, $conf);
  374.  
  375.     $my_layout = $img['pos'] == 'v' ? 'height' : 'width';
  376.     $my_img_attr = array(
  377.       $my_layout => $conf['thumbnail_size'],
  378.       'style' => 'margin-top:'. $img['top'] .'px;',
  379.     );
  380.   } // Without force.
  381.  
  382.   $item->my_img_attr = $my_img_attr;
  383.   $my_img = gallery_assist_prepare_thms($item, $conf);
  384.  
  385.   $get_values = $_GET;
  386.   unset($get_values['q']);
  387.   $edit_text = t('[edit]');
  388.   $delete_text = t('[delete]');
  389.   $elink = l($edit_text, 'node/ga_edit_one/'. $item->my_nid .'/'. $item->pid, array('query' => $get_values));
  390.   $elink .= l($delete_text, 'node/ga_del_one/'. $item->my_nid .'/'. $item->pid, array('query' => $get_values));
  391. //  $a_link = '<div id="image-box-'. $item->pid .'-links" class="'. $type .' image-box-links">[ '. $elink .' ]</div>'."\n";
  392.   $node = new stdClass;
  393.   $node->nid = $item->my_nid;
  394.   $node->uid = $item->uid;
  395.   $node->type = $type;
  396.   $edit_link  = $user->uid == 1 || $user->uid == $item->uid || gallery_assist_check_access($node, 'edit') ? $elink : '';
  397.  
  398.   $output  = '<div'. drupal_attributes($my_box_attr) .'>'."\n";
  399.   $output .= '  <div'. drupal_attributes($my_sheet_attr) .'>'."\n";
  400.   $output .= '    '. l($my_img, 'node/'. $item->my_nid .'/'. $item->pid, array('html' => TRUE));
  401.   $output .= '  </div>'."\n";
  402.   $output .= '</div>'."\n";
  403.  
  404.   $output2  = '<div'. drupal_attributes($my_box_attr) .'>'."\n";
  405.   $output2 .= '<div'. drupal_attributes($my_sheet_attr) .'>'."\n";
  406.   $output2 .= '    '. l($my_img, 'node/'. $item->my_nid .'/'. $item->pid, array('html' => TRUE));
  407.   $output2 .= '</div>'."\n";
  408.   $output2 .= '</div>'."\n";
  409.   $output2 .= '<div'. drupal_attributes($edit_link_attr) .'>'. $edit_link .'</div>'."\n";
  410.  
  411.   return $output2;
  412. }
  413.  
  414. /**
  415.  * Build and return the item title box.
  416.  */
  417. function gallery_assist_title_box_list($item, $conf) {
  418.   $points = drupal_strlen($item->ptitle) > $conf['title_substr'] ? "..." : '';
  419.   $title = drupal_substr($item->ptitle, 0, $conf['title_substr']) . $points;
  420.   $op = empty($conf['ga_item_title_type']) ? 0 : $conf['ga_item_title_type'];
  421.  
  422.   switch ($op) {
  423.     case 0:
  424.       $output  = '<div id="title-box-'. $item->pid .'" class="'. $item->nodetype .' title-box-on-list">'."\n";
  425.       $output .= l($title, 'node/'. $item->my_nid .'/'. $item->pid, array('html' => TRUE, 'attributes' => array('title' => $item->ptitle)));
  426.       $output .= '</div>'."\n";
  427.     break;
  428.  
  429.       case 1:
  430.       $output  = '<div id="title-box-'. $item->pid .'" class="'. $item->nodetype .' title-box-on-list">'."\n";
  431.       $output .= $title;
  432.       $output .= '</div>'."\n";
  433.     break;
  434.   }
  435.  
  436.   return $output;
  437. }
  438.  
  439. /**
  440.  * Theme the Gallery Assist Container as list.
  441.  *
  442.  * @ingroup themeable
  443.  */
  444. function theme_gallery_assist_display_list($pager, $boxes, $conf, $type = 'gallery_assist') {
  445.   die(var_dump($boxes));
  446.   $output  = '<!-- Gallery Assist container -->'."\n";
  447.   $output .= '    <div id="gallery-container-'. $conf['nid'] .'" class="'. $type .' gallery-container '. $conf['op'] .'  container-justify-'. $conf['container_justify'] .' container-justify-'. $conf['container_justify'] .' clear-block"'. $conf['$my_attr'] .'>'."\n";
  448.   $output .= $conf['pager_position'] == 'top' || $conf['pager_position'] == 'both' ? $pager : '';
  449.   $output .= $boxes;
  450.   $output .= $conf['pager_position'] == 'bottom' || $conf['pager_position'] == 'both' ? $pager : '';
  451.   $output .= '    </div>'."\n";
  452.   $output .= '    <!-- End of Gallery Assist container -->'."\n";
  453.  
  454.   return  $output;
  455. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement