File: lib.pings.php

package info (click to toggle)
dotclear 2.6.4%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 8,420 kB
  • sloc: php: 54,270; sql: 1,290; sh: 213; xml: 173; makefile: 158
file content (100 lines) | stat: -rw-r--r-- 2,462 bytes parent folder | download
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
<?php
# -- BEGIN LICENSE BLOCK ---------------------------------------
#
# This file is part of Dotclear 2.
#
# Copyright (c) 2003-2013 Olivier Meunier & Association Dotclear
# Licensed under the GPL version 2.0 license.
# See LICENSE file or
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
#
# -- END LICENSE BLOCK -----------------------------------------
if (!defined('DC_RC_PATH')) { return; }

class pingsAPI extends xmlrpcClient
{
	public static function doPings($srv_uri,$site_name,$site_url)
	{
		$o = new self($srv_uri);
		$o->timeout = 3;

		$rsp = $o->query('weblogUpdates.ping',$site_name,$site_url);

		if (isset($rsp['flerror']) && $rsp['flerror']) {
			throw new Exception($rsp['message']);
		}

		return true;
	}
}

class pingsBehaviors
{
	public static function pingJS()
	{
		$res =
		"<script type=\"text/javascript\">\n//<![CDATA[\n".
		dcPage::jsVar('dotclear.msg.check_all',__('Check all'))."\n".
		"</script>\n".dcPage::jsLoad('index.php?pf=pings/post.js');

		return $res;
	}

	public static function pingsFormItems($main,$sidebar,$post)
	{
		$core =& $GLOBALS['core'];
		if (!$core->blog->settings->pings->pings_active) {
			return;
		}

		$pings_uris = @unserialize($core->blog->settings->pings->pings_uris);
		if (empty($pings_uris) || !is_array($pings_uris)) {
			return;
		}

		if (!empty($_POST['pings_do']) && is_array($_POST['pings_do'])) {
			$pings_do = $_POST['pings_do'];
		} else {
			$pings_do = array();
		}

		$item = '<h5 class="ping-services">'.__('Pings').'</h5>';
		$i = 0;
		foreach ($pings_uris as $k => $v)
		{
			$item .=
			'<p class="ping-services"><label for="pings_do-'.$i.'" class="classic">'.
			form::checkbox(array('pings_do[]','pings_do-'.$i),html::escapeHTML($v),in_array($v,$pings_do), 'check-ping-services').' '.
			html::escapeHTML($k).'</label></p>';
			$i++;
		}
		$sidebar['options-box']['items']['pings']=$item;

	}

	public static function doPings($cur,$post_id)
	{
		if (empty($_POST['pings_do']) || !is_array($_POST['pings_do'])) {
			return;
		}

		$core =& $GLOBALS['core'];
		if (!$core->blog->settings->pings->pings_active) {
			return;
		}

		$pings_uris = @unserialize($core->blog->settings->pings->pings_uris);
		if (empty($pings_uris) || !is_array($pings_uris)) {
			return;
		}

		foreach ($_POST['pings_do'] as $uri)
		{
			if (in_array($uri,$pings_uris)) {
				try {
					pingsAPI::doPings($uri,$core->blog->name,$core->blog->url);
				} catch (Exception $e) {}
			}
		}
	}
}