aboutsummaryrefslogtreecommitdiffstats
path: root/addon/oembed/oembed.php
blob: f1fb27986744d6e1adafa2a61f8fba74f8b21cc8 (plain) (blame)
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
<?php
/**
 * oembed plugin
 * 
 * oEmbed is a format for allowing an embedded representation of a URL on third party sites
 * http://www.oembed.com/
 * 
 */

require_once('include/oembed.php');

function oembed_install() {
	register_hook('jot_tool', 'addon/oembed/oembed.php', 'oembed_hook_jot_tool');
	register_hook('page_header', 'addon/oembed/oembed.php', 'oembed_hook_page_header');
	register_hook('plugin_settings', 'addon/oembed/oembed.php', 'oembed_settings'); 
	register_hook('plugin_settings_post', 'addon/oembed/oembed.php', 'oembed_settings_post');
}

function oembed_uninstall() {
	unregister_hook('jot_tool', 'addon/oembed/oembed.php', 'oembed_hook_jot_tool');
	unregister_hook('page_header', 'addon/oembed/oembed.php', 'oembed_hook_page_header');
}

function oembed_settings_post(){
    if(! local_user())
		return;
	if (isset($_POST['oembed-submit'])){
		set_pconfig(local_user(), 'oembed', 'use_for_youtube', (isset($_POST['oembed_use_for_youtube'])?1:0));
		notice( t('OEmbed settings updated') . EOL);
	}
}

function oembed_settings(&$a,&$o) {
    if(! local_user())
		return;
	$uofy = get_pconfig(local_user(), 'oembed', 'use_for_youtube' );
	
	$o .='<h3 class="settings-heading">OEmbed</h3>';
	$o.='
	<div id="settings-username-wrapper">
		<label for="oembed_use_for_youtube">'
			.t('Use OEmbed for YouTube videos: ') 
		.'</label><input type="checkbox" id="oembed_use_for_youtube" name="oembed_use_for_youtube"'
		. ($uofy==1?'checked="true"':'')
		.'>
	</div>
	<div id="settings-username-end"></div>
	<div class="settings-submit-wrapper">
		<input type="submit" value="'.t('Submit').'" class="settings-submit" name="oembed-submit">
	</div>';
}


function oembed_hook_page_header($a, &$b){
	$a->page['htmlhead'] .= sprintf('<script src="%s/oembed/oembed.js"></script>', $a->get_baseurl());
}


function oembed_hook_jot_tool($a, &$b) {
	$b .= '
	<div class="tool-wrapper" style="display: $visitor;" >
	  <img class="tool-link" src="addon/oembed/oembed.png" alt="Embed" title="Embed" onclick="oembed();" />
	</div> 
	';
}


function oembed_module() {
	return;
}

function oembed_init(&$a) {
	if ($a->argv[1]=='oembed.js'){
		$tpl = file_get_contents('addon/oembed/oembed.js');
		echo replace_macros($tpl, array(
			'$oembed_message' =>  t('URL to embed:'),
		));
	}
	
	if ($a->argv[1]=='b2h'){
		$url = array( "", trim(hex2bin($_GET['url'])));
		echo oembed_replacecb($url);
	}
	
	if ($a->argv[1]=='h2b'){
		$text = trim(hex2bin($_GET['text']));
		echo oembed_html2bbcode($text);
	}
	
	killme();
	
}

?>