deeemm-cms /includes/build_media_content.php

Language PHP Lines 325
MD5 Hash 900f7efcf1b5dec01fa529d4670a01eb Estimated Cost $5,195 (why?)
Repository https://bitbucket.org/mpercy/deeemm-cms View Raw File View Project SPDX
  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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
<?php

defined( '_INDM' ) or die( 'POSSIBLE HACK ATTEMPT!' );

/*===========================================================================
Get last modified date
===========================================================================*/
$media_library_last_modified = @mysql_result(mysql_query("SELECT max(date) FROM " . $db_table_prefix . 'cat_' . $page),0);
$media_library_last_modified = strftime("%a %d %b  %Y", strtotime($media_library_last_modified));


/*===========================================================================
Get number of files in library
===========================================================================*/
$sql_result = mysql_query("select count(*) from `" . $db_table_prefix . 'cat_' . $page . "`");
$media_library_num_images = @mysql_result($sql_result,0);


/*===========================================================================
Get navigation id info

 PLEASE NOTE!!

 id values are unique but may not be concurrent so we need to get actual
 values from database and not simply increment / decrement current id value!!!
===========================================================================*/

//create array of all id's
$file_id_array = array();
$sql_query = mysql_query("SELECT * FROM `" . $db_table_prefix . 'cat_' . $page . "` ORDER BY `id`");
while($sql_result = mysql_fetch_array($sql_query)){
	$file_id_array[] .= $sql_result[id];
}

//get position of current id in array
$position = array_search($id, $file_id_array);

//get value of first id
$file_first = $file_id_array[0];

//get value of last id
$file_last = end($file_id_array);
//$media_library_num_images - $media_library_thumbs_per_page + 1

//get id for previous file
$index = $position - 1;
if ($index < 0) {
	$file_prev = $file_first;
} else {
	$file_prev = $file_id_array[$index];
}

//get id for next file
$index = $position + 1;
if ($index >= count($file_id_array)) {
	$file_next = $file_last;
} else {
	$file_next = $file_id_array[$index];
}

//get id for first thumbnail file on page
$a = $id-1;

$media_library_index_first_image = ($a - ($a % $media_library_thumbs_per_page) + 1);
if ($media_library_index_first_image <= 0) $media_library_index_first_image = 1;
if ($media_library_index_first_image > $media_library_num_images) $media_library_index_first_image = $media_library_num_images;

//create general nav links
$media_nav = "<A href='./index.php?page=$page&amp;action=thumbnails' alt='[var]MEDIA[/var]' title='[var]MEDIA_TITLE[/var]'>$lan[thumbnails]</A><BR />";
$media_nav .= "<A href='./index.php?page=$page&amp;action=list' alt='[var]MEDIA[/var]' title='[var]MEDIA_TITLE[/var]'>$lan[filelist]</A><BR />";

/*===========================================================================
Get selection for default view for media library
===========================================================================*/
if ($action == '' && $id == '') {
	$sql_result = mysql_query("select count(*) from `" . $db_table_prefix . 'cat_' . $page . "`");
	$media_library_num_images = @mysql_result($sql_result,0);

	$sql_query = mysql_query("SELECT * FROM `" . $db_table_prefix . "core_structure` WHERE `table` = '$page'");
	while($sql_result = mysql_fetch_array($sql_query)){
		$action = $sql_result['media_library_default_view'];
	}

	switch ($action) {

		case 'thumbnails';
		$id = NULL;
		break;

		case 'list';
		break;

		case 'first';
		//get value of first id
		$id = $file_first;
		$action = NULL;
		break;

		case 'last';
		//get value of last id
		$id = $file_last;
		$action = NULL;
		break;

	}//end switch $action
}//endif

/*===========================================================================
Display image
===========================================================================*/
	IF ($id <> '' && !$action) {

		$media_library_image_nav = $media_library_image_edit . "<A href='$default_url" . "index.php?page=$page&amp;id=$file_prev'><img class='icon' title='Previous' src='$default_url".$templates_dir."images/icons/previous.gif'></A> <A href='$default_url" . "index.php?page=$page&amp;action=thumbnails&amp;id=$media_library_index_first_image'><img class='icon' title='View Thumbnails' src='$default_url".$templates_dir."images/icons/view_thumbnails.gif'></A> <A href='$default_url" . "index.php?page=$page&amp;action=list'><img class='icon' title='View as List' src='$default_url".$templates_dir."images/icons/view_list.gif'></A> <A href='$default_url" . "index.php?page=$page&amp;id=$file_next'><img class='icon' title='Next' src='$default_url".$templates_dir."images/icons/next.gif'></A>" . $lf;

		$media_library_image_name = NULL;
		$sql_query = mysql_query("SELECT * FROM `" . $db_table_prefix . 'cat_' . $page . "` WHERE `id` = $id");
		while($sql_result = mysql_fetch_array($sql_query)){
			$sql_query2 = mysql_query("SELECT * FROM `" . $db_table_prefix . "core_structure` WHERE `table` = '$sql_result[category]'");
			while($sql_result2 = mysql_fetch_array($sql_query2)){
				$media_library_image_category = $sql_result2[category_lan_ . $language];
			}

			$media_library_image_title = $sql_result[title_lan_.$language];
			$media_library_image_description = $sql_result[description_lan_.$language];
			$media_library_image_date = $sql_result[date];
			$media_library_image_date = strftime("%a %d %b  %Y", strtotime($media_library_image_date));
			$media_library_image_name = $sql_result[image];
			$media_library_image_src = $media_dir . $sql_result[image];
		}

		//check if name exists
		if (!isset($media_library_image_name)){
			$media_library_image_src = $media_dir . 'image_unavailable.jpg';
		}

		//		if (stristr($media_library_image_name,".mpg")) $media_library_image_src = $media_dir . 'mpeg.jpg';
		//		if (stristr($media_library_image_name,".mov")) $media_library_image_src = $media_dir . 'quicktime.jpg';
		if (stristr($media_library_image_name,".zip")) $media_library_image_src = $media_dir . 'zip_file.jpg';
		if (stristr($media_library_image_name,".pdf")) $media_library_image_src = $media_dir . 'pdf_file.jpg';

		//limit image size to max size
		list($src_width, $src_height) = getimagesize($media_library_image_src);
		if ($src_width < $media_library_max_image_width) $media_library_max_image_width = $src_width;

		//get file extension
		$media_library_image_extension = strrchr($media_library_image_src, '.');

		//select template based on extension
		switch ($media_library_image_extension) {

			case '';
			case '.jpg';
			case '.gif';
			case '.png';
			case '.tif';
			case '.bmp';
			$content = $default_url . $templates_dir  ."media_display_image.tpl";
			break;

			case '.mpg';
			$content = $default_url . $templates_dir  ."media_display_mpeg.tpl";
			break;

			case '.mov';
			$content = $default_url . $templates_dir  ."media_display_mov.tpl";
			break;

			case '.pdf';
			$content = $default_url . $templates_dir  ."media_display_pdf.tpl";
			break;

			case '.zip';
			$content = $default_url . $templates_dir  ."media_display_image.tpl";
			break;

		}//end switch $media_library_image_extension

		//read template file
		$main = read_file($content);

		$media_library_image_num = $id;
		if ($media_library_image_category == '') $media_library_image_category = $lan[general];
		$page_title .= $cookie_trial_seperator .  $media_library_image_category . $cookie_trial_seperator . $media_library_image_title;
		$cookie_trial .= $cookie_trial_seperator .  $media_library_image_category . $cookie_trial_seperator . $media_library_image_title;
	}

/*===========================================================================
Display as list
===========================================================================*/
	IF ($action == 'list') {
		$last_media_library_category = '~!nothing!~';
		$main = read_file($default_url . $templates_dir  . "media_index.tpl");

		$media_library_index_nav = "<A href='$default_url" . "index.php?page=$page&amp;action=thumbnails&amp;id=$media_library_index_first_image'><img class='icon' title='View Thumbnails' src='$default_url".$templates_dir."images/icons/view_thumbnails.gif'></A>" . $lf;


		$sql_query = mysql_query("SELECT * FROM `" . $db_table_prefix . 'cat_' . $page . "` ORDER BY `category`");
		while($sql_result = mysql_fetch_array($sql_query)){
			$media_library_image_name = $sql_result[image];

			$media_library_image_extension = strrchr($media_library_image_name, '.');

			switch ($media_library_image_extension) {

				case '.jpg';
				case '.gif';
				case '.png';
				case '.bmp';
				$media_library_image_title = $lan[picture] . ' - ';
				break;

				case '.mpg';
				$media_library_image_title = $lan[video] . ' - ';
				break;

				case '.mov';
				$media_library_image_title = $lan[video] . ' - ';
				break;

				case '.pdf';
				$media_library_image_title = $lan[pdf] . ' - ';
				break;

				case '.zip';
				$media_library_image_title = $lan[zip] . ' - ';
				break;

			}

			$media_library_image_title .= $sql_result[title_lan_.$language];
			$media_library_image_description = $sql_result[description_lan_.$language];
			$media_library_image_num = $sql_result[id];
			$media_library_image_date = $sql_result[date];
			$media_library_image_date = strftime("%a %d %b  %Y", strtotime($media_library_image_date));
			$media_library_category = $sql_result[category];



			//   	  $sql_query2 = mysql_query("SELECT * FROM `" . $db_table_prefix . "core_structure` WHERE `table` = '$sql_result[category]'");
			//
			//	    while($sql_result2 = mysql_fetch_array($sql_query2)){
			//  	    $media_library_category = $sql_result2[category_lan_ . $language];
			//	    }

			if ($last_media_library_category != $media_library_category) {
				if ($last_media_library_category <> '~!nothing!~') $main .= '	</DIV><BR>' . $lf;
				$main .= '	<DIV>' . $lf;

				if ($media_library_category == ''){
					$main .= "<H2>$lan[general]</H2>" . $lf;
				} ELSE {
					$main .= "<H2>$media_library_category</H2>" . $lf;
				}
			}
			$last_media_library_category = $media_library_category;
			$main .= "<small><a href='$default_url" . "index.php?page=$page&amp;id=$media_library_image_num'><span class='float_right'>$media_library_image_date</span>$media_library_image_title </A></small><br>";
			$media_library_image_description = truncate($media_library_image_description, 80);
	  }
	  if (isset($media_library_image_title) && $media_library_image_title <> '') {
	  	$main .= '  </DIV>' . $lf;
	  } else {
	  	$main .= '<br>';
	  	$main .= '<br>';
	  	$main .= '<center>' . $lan[no_media] . '<center>';
	  }
	  $main .= '</DIV>' . $lf;
		}

/*===========================================================================
Display as thumbnails
===========================================================================*/
		IF ($action == 'thumbnails') {
	  $main = read_file($default_url . $templates_dir . "media_thumbs.tpl");
	  IF (!isset($id)){
	  	$curr_image = $media_library_num_images - $media_library_thumbs_per_page + 1;
	  	if ($curr_image <= 0) $curr_image = 1;
	  } ELSE {
	  	$curr_image = $id;
	  }
	  $media_library_first_thumb = $curr_image;
	  $media_library_last_thumb = $media_library_first_thumb + $media_library_thumbs_per_page -1 ;
	  if ($media_library_last_thumb > $media_library_num_images) $media_library_last_thumb = $media_library_num_images;
	  $media_library_page_prev = $curr_image - $media_library_thumbs_per_page;
	  if ($media_library_page_prev <= 0)$media_library_page_prev = 1;
	  $media_library_page_next = $curr_image + $media_library_thumbs_per_page;
	  if ($media_library_page_next >= $media_library_num_images)$media_library_page_next = $media_library_num_images - $media_library_thumbs_per_page;
	  if ($media_library_page_next <= 0)$media_library_page_next = 1;

    	$media_library_index_nav = "$media_library_index_edit  <A href='$default_url" . "index.php?page=$page&amp;action=thumbnails&amp;id=1'><img class='icon' title='First' src='$default_url".$templates_dir."images/icons/first.gif'></A> <A href='$default_url" . "index.php?page=$page&amp;action=thumbnails&amp;id=$media_library_page_prev'><img class='icon' title='Previous' src='$default_url".$templates_dir."images/icons/previous.gif'></A> <A href='$default_url" . "index.php?page=$page&amp;action=list'><img class='icon' title='List' src='$default_url".$templates_dir."images/icons/view_list.gif'></A>  <A href='$default_url" . "index.php?page=$page&amp;action=thumbnails&amp;id=$media_library_page_next'><img class='icon' title='Next' src='$default_url".$templates_dir."images/icons/next.gif'></A> <A href='$default_url" . "index.php?page=$page&amp;action=thumbnails&amp;id=".($media_library_num_images - $media_library_thumbs_per_page + 1)."'><img class='icon' title='Last' src='$default_url".$templates_dir."images/icons/last.gif'></A>";

	  for($count=$curr_image;$count<$curr_image+$media_library_thumbs_per_page;$count++) {
	  	$id = $count-1;
	  	$sql_query = mysql_query("SELECT * FROM `" . $db_table_prefix . 'cat_' . $page . "` WHERE `id` = '$file_id_array[$id]'");
	  	while($sql_result = mysql_fetch_array($sql_query)) {
	  		$media_library_image_title = $sql_result[title_lan_.$language];
	  		$media_library_image_description = $sql_result[description_lan_.$language];
	  		$media_library_image_num = $sql_result[id];
	  		$media_library_image_name = $sql_result[image];
	  		//check if image name exists
	  		if ($media_library_image_name == ''){
	  			$media_library_image_name = 'image_unavailable.jpg';
	  		}

	  		if (stristr($media_library_image_name,".mpg")) $media_library_image_name = 'mpeg.jpg';
	  		if (stristr($media_library_image_name,".mov")) $media_library_image_name = 'quicktime.jpg';
	  		if (stristr($media_library_image_name,".zip")) $media_library_image_name = 'zip_file.jpg';
	  		if (stristr($media_library_image_name,".pdf")) $media_library_image_name = 'pdf_file.jpg';
	  		$media_library_thumbs .= '<DIV class="media_thumb">' . $lf;
	  		$media_library_thumbs .= "	<center><a href='$default_url" . "index.php?page=$page&amp;id=$media_library_image_num'><img src='" . $default_url . $media_dir . "thumbnail.php?height=" . $media_library_thumb_height ."&amp;width=" . $media_library_thumb_width . "&amp;filename=$media_library_image_name' border=0></A></center><BR />" . $lf;
	  		$media_library_thumbs .= "	<small><center><span>$media_library_image_title</span></center></small>" . $lf;
	  		$media_library_thumbs .= "</DIV>\r\n" . $lf;
	  		//ROW CONTROL!!???
	  		//       if ($count == ($media_library_thumbs_per_page / $media_library_thumb_rows_per_page)) {
	  		if ((($count + 1) % $media_library_thumb_rows_per_page) == 1) {
	  			//         $media_library_thumbs .= "</br>";
	  		}
	    }
	  	}
	  	if (!isset($media_library_image_title) || $media_library_image_title == '') {
	  		$media_library_thumbs .= '<br>';
	  		$media_library_thumbs .= '<br>';
	  		$media_library_thumbs .= '<center>' . $lan[no_media] . '<center>';
	  	}
	  }
?>
Back to Top