/
vcp.module
79 lines (65 loc) · 2.46 KB
/
vcp.module
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
<?php
// $Id$
/**
* @file
* Provides various VCP-related functionality.
*
* Adds facilities for keeping track of video scores as well as adding
* VCP-specific blocks, theming, and pages.
*/
/*
* Implementation of hook_block()
*/
function vcp_block($op = 'list', $delta = 0, $edit = array()) {
$str_vidnum = 'vcp_block_conf_pending_vids_num';
$str_webdir = 'vcp_block_conf_pending_vids_webdir';
switch( $op ) {
case 'list':
$blocks[0]['info'] = t('VCP Pending Videos');
$blocks[0]['cache'] = BLOCK_NO_CACHE;
return $blocks;
case 'configure':
$form[$str_vidnum] = array(
'#type' => 'textfield',
'#title' => t('Number of pending videos to display'),
'#default_value' =>
variable_get($str_vidnum,5),
);
$form[$str_webdir] = array(
'#type' => 'textfield',
'#title' =>
t('Folder where web documents are stored. (e.g. "htdocs")'),
'#default_value' => variable_get($str_webdir, 'htdocs'),
);
return $form;
case 'save':
variable_set( $str_vidnum, (int)$edit[$str_vidnum] );
variable_set( $str_webdir, (string)$edit[$str_webdir] );
break;
case 'view':
$content = "";
$count = 0;
$num_to_list = (int)variable_get( $str_vidnum, '-1' );
$block['subject'] = t('Pending Videos');
$webdir = variable_get( $str_webdir, '---' );
if( $webdir === '---' || $num_to_list === -1 ) {
$block['content'] =
t('There were some errors in your block config. Please check the block settings.');
return $block;
}
$d = getcwd();
$d = explode($webdir, $d);
$d = $d[0] . "videos/pending/";
$files = file_scan_directory( $d, '.*');
foreach( $files as $file ) {
if( $count == $num_to_list ) break;
$content[$count] = $file->basename;
if( strlen($content[$count]) > 20 ) {
$content[$count] = substr( $content[$count], 0, 20 ) . "…";
}
$count++;
}
$block['content'] = theme('item_list', $content);
return $block;
}
}