aboutsummaryrefslogtreecommitdiff
path: root/mod/embed/views/default/embed/embed.php
blob: f09d76a4bc0aa97e82e7cb6779b4dbf543fa7833 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<?php
/**
 * Embed landing page
 *
 * @todo Yes this is a lot of logic for a view.  A good bit of it can be moved
 * to the page handler
 *
 * @uses string $vars['sections'] Array of section_id => Section Display Name
 * @uses string $vars['active_section'] Currently selected section_id
 */

$sections = elgg_extract('sections', $vars, array());
$active_section = elgg_extract('active_section', $vars, array_shift(array_keys($sections)));
$upload_sections = elgg_extract('upload_sections', $vars, array());
$internal_id = elgg_extract('internal_id', $vars);

if (!$sections) {
	$content = elgg_echo('embed:no_sections');
} else {
	$content = elgg_view_title(elgg_echo('embed:media'));
	$content .= elgg_view('embed/tabs', $vars);

	$offset = max(0, get_input('offset', 0));
	$limit = get_input('limit', 10);

	// build the items and layout.
	if ($active_section == 'upload' || array_key_exists($active_section, $sections)) {
		$section_info = $sections[$active_section];
		$layout = isset($section_info['layout']) ? $section_info['layout'] : 'list';

		$params =  array(
			//'type'	=> $type,
			//'subtype'	=> $subtype,
			'offset' => $offset,
			'limit' => $limit,
			'section' => $active_section,
			'upload_sections' => $upload_sections,
			'internal_id' => $internal_id
		);

		// allow full override for this section
		// check for standard hook
		if ($section_content = elgg_view("embed/$active_section/content", $params)) {
			// handles its own pagination
			$content .= $section_content;
		} elseif ($embed_info = elgg_trigger_plugin_hook('embed_get_items', $active_section, $params, array('items' => array(), 'count' => 0))) {
			// check if we have an override for this section type.
			$view = "embed/$active_section/item/$layout";

			if (!elgg_view_exists($view)) {
				$view = "embed/item/$layout";
			}
			
			if (!isset($embed_info['items']) || !is_array($embed_info['items']) || !count($embed_info['items'])) {
				$content .= elgg_echo('embed:no_section_content');
			} else {
				// pull out some common tests
				// embed requires ECML, but until we have plugin deps working
				// we need to explicitly check and use a fallback.
				if ($ecml_enabled = elgg_is_active_plugin('ecml')){
					$ecml_valid_keyword = ecml_is_valid_keyword($active_section);
				} else {
					$ecml_valid_keyword = FALSE;
				}
				
				$items_content = '<ul class="elgg-list">';
				foreach ($embed_info['items'] as $item) {
					$item_params = array(
						'section' => $active_section,
						'item' => $item,
						'ecml_enabled' => $ecml_enabled,
						'ecml_keyword' => ($ecml_valid_keyword) ? $active_section : 'entity',
						'icon_size' => elgg_extract('icon_size', $section_info, 'tiny'),
					);
	
					$items_content .= '<li class="elgg-list-item">' . elgg_view($view, $item_params) . '</li>';
				}
				$items_content .= '</ul>';
				
				$params['content'] = $items_content;
				$params['count'] = $embed_info['count'];
	
				$content .= elgg_view('navigation/pagination', $params);
				$content .= elgg_view("embed/layouts/$layout", $params);
			}
		} else {
			$content .= elgg_echo('embed:no_section_content');
		}
	} else {
		$content .= elgg_echo('embed:invalid_section');
	}
}

echo '<div class="embed-wrapper">' . $content . '</div>';
?>

<?php //@todo: JS 1.8: ugly ?>
<script type="text/javascript">
$(function() {
	var internal_id = '<?php echo addslashes($internal_id); ?>';

	// Remove any existing "live" handlers
	$('.embed_data').die('click');
	$('.embed_section').die('click');
	$('#facebox .elgg-pagination a').die('click');
	
	// insert embed codes
	$('.embed_data').live('click', function() {
		var embed_code = $(this).data('embed_code');
		elggEmbedInsertContent(embed_code, internal_id);
		
		return false;
	});

	// tabs
	$('.embed_section').live('click', function() {
		var section = $(this).attr('id');
		var url = elgg.config.wwwroot + 'embed/embed?active_section=' + section + '&internal_id=' + internal_id;
		$('#facebox .body .content').load(url);

		return false;
	});

	// pagination
	function elggPaginationClick() {
		$('#facebox .body .content').load($(this).attr('href'));
		return false;
	}

	$('#facebox .elgg-pagination a').live('click', elggPaginationClick);
});

</script>