Esempio n. 1
0
/**
 * Takes an xmlrpc value in PHP xmlrpcval object format and translates it into native PHP types.
 *
 * Works with xmlrpc message objects as input, too.
 *
 * Given proper options parameter, can rebuild generic php object instances
 * (provided those have been encoded to xmlrpc format using a corresponding
 * option in php_xmlrpc_encode())
 * PLEASE NOTE that rebuilding php objects involves calling their constructor function.
 * This means that the remote communication end can decide which php code will
 * get executed on your server, leaving the door possibly open to 'php-injection'
 * style of attacks (provided you have some classes defined on your server that
 * might wreak havoc if instances are built outside an appropriate context).
 * Make sure you trust the remote server/client before eanbling this!
 *
 * @author Dan Libby (dan@libby.com)
 *
 * @param xmlrpcval $xmlrpc_val
 * @param array $options if 'decode_php_objs' is set in the options array, xmlrpc structs can be decoded into php objects; if 'dates_as_objects' is set xmlrpc datetimes are decoded as php DateTime objects (standard is
 * @return mixed
 */
function php_xmlrpc_decode($xmlrpc_val, $options = array())
{
    switch ($xmlrpc_val->kindOf()) {
        case 'scalar':
            if (in_array('extension_api', $options)) {
                reset($xmlrpc_val->me);
                list($typ, $val) = each($xmlrpc_val->me);
                switch ($typ) {
                    case 'dateTime.iso8601':
                        $xmlrpc_val->scalar = $val;
                        $xmlrpc_val->xmlrpc_type = 'datetime';
                        $xmlrpc_val->timestamp = iso8601_decode($val);
                        return $xmlrpc_val;
                    case 'base64':
                        $xmlrpc_val->scalar = $val;
                        $xmlrpc_val->type = $typ;
                        return $xmlrpc_val;
                    default:
                        return $xmlrpc_val->scalarval();
                }
            }
            if (in_array('dates_as_objects', $options) && $xmlrpc_val->scalartyp() == 'dateTime.iso8601') {
                // we return a Datetime object instead of a string
                // since now the constructor of xmlrpcval accepts safely strings, ints and datetimes,
                // we cater to all 3 cases here
                $out = $xmlrpc_val->scalarval();
                if (is_string($out)) {
                    $out = strtotime($out);
                }
                if (is_int($out)) {
                    $result = new Datetime();
                    $result->setTimestamp($out);
                    return $result;
                } elseif (is_a($out, 'Datetime')) {
                    return $out;
                }
            }
            return $xmlrpc_val->scalarval();
        case 'array':
            $size = $xmlrpc_val->arraysize();
            $arr = array();
            for ($i = 0; $i < $size; $i++) {
                $arr[] = php_xmlrpc_decode($xmlrpc_val->arraymem($i), $options);
            }
            return $arr;
        case 'struct':
            $xmlrpc_val->structreset();
            // If user said so, try to rebuild php objects for specific struct vals.
            /// @todo should we raise a warning for class not found?
            // shall we check for proper subclass of xmlrpcval instead of
            // presence of _php_class to detect what we can do?
            if (in_array('decode_php_objs', $options) && $xmlrpc_val->_php_class != '' && class_exists($xmlrpc_val->_php_class)) {
                $obj = @new $xmlrpc_val->_php_class();
                while (list($key, $value) = $xmlrpc_val->structeach()) {
                    $obj->{$key} = php_xmlrpc_decode($value, $options);
                }
                return $obj;
            } else {
                $arr = array();
                while (list($key, $value) = $xmlrpc_val->structeach()) {
                    $arr[$key] = php_xmlrpc_decode($value, $options);
                }
                return $arr;
            }
        case 'msg':
            $paramcount = $xmlrpc_val->getNumParams();
            $arr = array();
            for ($i = 0; $i < $paramcount; $i++) {
                $arr[] = php_xmlrpc_decode($xmlrpc_val->getParam($i));
            }
            return $arr;
    }
}
Esempio n. 2
0
print "<PRE>" . htmlentities($v->serialize()) . "</PRE>";
$v = new xmlrpcval(array(new xmlrpcval("ABCDEFHIJ"), new xmlrpcval(1234, 'int'), new xmlrpcval(1, 'boolean')), "array");
print "<PRE>" . htmlentities($v->serialize()) . "</PRE>";
$v = new xmlrpcval(array("thearray" => new xmlrpcval(array(new xmlrpcval("ABCDEFHIJ"), new xmlrpcval(1234, 'int'), new xmlrpcval(1, 'boolean'), new xmlrpcval(0, 'boolean'), new xmlrpcval(true, 'boolean'), new xmlrpcval(false, 'boolean')), "array"), "theint" => new xmlrpcval(23, 'int'), "thestring" => new xmlrpcval("foobarwhizz"), "thestruct" => new xmlrpcval(array("one" => new xmlrpcval(1, 'int'), "two" => new xmlrpcval(2, 'int')), "struct")), "struct");
print "<PRE>" . htmlentities($v->serialize()) . "</PRE>";
$w = new xmlrpcval(array($v, new xmlrpcval("That was the struct!")), "array");
print "<PRE>" . htmlentities($w->serialize()) . "</PRE>";
$w = new xmlrpcval("Mary had a little lamb,\nWhose fleece was white as snow,\nAnd everywhere that Mary went\nthe lamb was sure to go.\n\nMary had a little lamb\nShe tied it to a pylon\nTen thousand volts went down its back\nAnd turned it into nylon", "base64");
print "<PRE>" . htmlentities($w->serialize()) . "</PRE>";
print "<PRE>Value of base64 string is: '" . $w->scalarval() . "'</PRE>";
$f->method('');
$f->addParam(new xmlrpcval("41", "int"));
print "<h3>Testing request serialization</h3>\n";
$op = $f->serialize();
print "<PRE>" . htmlentities($op) . "</PRE>";
print "<h3>Testing ISO date format</h3><pre>\n";
$t = time();
$date = iso8601_encode($t);
print "Now is {$t} --> {$date}\n";
print "Or in UTC, that is " . iso8601_encode($t, 1) . "\n";
$tb = iso8601_decode($date);
print "That is to say {$date} --> {$tb}\n";
print "Which comes out at " . iso8601_encode($tb) . "\n";
print "Which was the time in UTC at " . iso8601_decode($date, 1) . "\n";
print "</pre>\n";
?>
<hr/>
<em>$Id: vardemo.php,v 1.4 2006/12/28 16:10:42 milosch Exp $</em>
</body>
</html>
Esempio n. 3
0
function mweditpost($params)
{
    // ($postid, $user, $pass, $content, $publish)
    $xpostid = $params->getParam(0);
    $xuser = $params->getParam(1);
    $xpass = $params->getParam(2);
    $xcontent = $params->getParam(3);
    $xpublish = $params->getParam(4);
    $ID = intval($xpostid->scalarval());
    $username = $xuser->scalarval();
    $password = $xpass->scalarval();
    $contentstruct = php_xmlrpc_decode($xcontent);
    $postarr['post_status'] = $xpublish->scalarval() ? 'publish' : 'draft';
    // Check login
    if (user_pass_ok($username, $password)) {
        $postdata = wp_get_single_post($ID, ARRAY_A);
        if (!$postdata) {
            return new xmlrpcresp(0, $GLOBALS['xmlrpcerruser'] + 2, "No such post '{$ID}'.");
        }
        $userdata = get_userdatabylogin($username);
        if ($userdata->user_level < 1) {
            return new xmlrpcresp(0, $GLOBALS['xmlrpcerruser'] + 1, 'Sorry, level 0 users can not edit posts');
        }
        if ($userdata->ID != $postdata['post_author'] && $userdata->user_level != 10) {
            $authordata = get_userdata($postdata['post_author']);
            if ($userdata->user_level <= $authordata->user_level) {
                return new xmlrpcresp(0, $GLOBALS['xmlrpcerruser'] + 1, 'Sorry, you do not have the right to edit this post');
            }
        }
        $postarr['ID'] = $ID;
        if (array_key_exists('title', $contentstruct)) {
            $postarr['post_title'] = $contentstruct['title'];
            logIO('O', $contentstruct['title']);
        }
        if (array_key_exists('description', $contentstruct)) {
            $postarr['post_content'] = format_to_post($contentstruct['description']);
            logIO('O', $contentstruct['description']);
        }
        if (array_key_exists('mt_excerpt', $contentstruct)) {
            $postarr['post_excerpt'] = $contentstruct['mt_excerpt'];
        }
        if (array_key_exists('mt_text_more', $contentstruct)) {
            if (trim(format_to_post($contentstruct['mt_text_more']))) {
                $postarr['post_content'] .= "\n<!--more-->\n" . format_to_post($contentstruct['mt_text_more']);
            }
        }
        if (array_key_exists('mt_allow_comments', $contentstruct)) {
            $postarr['comment_status'] = $contentstruct['mt_allow_comments'] ? 'open' : 'closed';
        }
        if (array_key_exists('mt_allow_pings', $contentstruct)) {
            $postarr['ping_status'] = $contentstruct['mt_allow_pings'] ? 'open' : 'closed';
        }
        if (!empty($contentstruct['dateCreated'])) {
            $dateCreated = preg_split('/([+\\-Z])/', $contentstruct['dateCreated'], -1, PREG_SPLIT_DELIM_CAPTURE);
            if (count($dateCreated) == 3) {
                $dateCreated[2] = str_replace(':', '', $dateCreated[2]);
            }
            if ($dateCreated[1] == '+') {
                $dateoffset = intval($dateCreated[2]) * 36;
            } else {
                if ($dateCreated[1] == '-') {
                    $dateoffset = -intval($dateCreated[2]) * 36;
                } else {
                    $dateoffset = 0;
                }
            }
            $dateCreated = iso8601_decode($dateCreated[0], 1) - $dateoffset + get_settings('time_difference') * 3600;
        } else {
            $dateCreated = current_time('timestamp', 0);
        }
        $postarr['post_date'] = date('Y-m-d H:i:s', $dateCreated);
        $postarr['post_category'] = array();
        if (array_key_exists('categories', $contentstruct) && is_array($contentstruct['categories'])) {
            foreach ($contentstruct['categories'] as $cat) {
                $postarr['post_category'][] = get_cat_ID(mb_conv($cat), 'EUC-JP', 'auto');
            }
        } else {
            $postarr['post_category'][] = $GLOBALS['post_default_category'];
        }
        $post_ID = wp_update_post($postarr);
        if (!$post_ID) {
            return new xmlrpcresp(0, $GLOBALS['xmlrpcerruser'] + 2, 'For some strange yet very annoying reason, your entry could not be posted.');
        }
        if (empty($GLOBALS['blog_ID'])) {
            $GLOBALS['blog_ID'] = 1;
        }
        pingWeblogs($GLOBALS['blog_ID']);
        pingback($postarr['post_content'], $post_ID);
        if (array_key_exists('mt_tb_ping_urls', $contentstruct)) {
            trackback_url_list($content_struct['mt_tb_ping_urls'], $post_ID);
        }
        logIO('O', "(MW) Edited ! ID: {$post_ID}");
        $myResp = new xmlrpcval(true, 'boolean');
        return new xmlrpcresp($myResp);
    } else {
        logIO('O', "(MW) Wrong username/password combination <b>{$username} / {$password}</b>");
        return new xmlrpcresp(0, $GLOBALS['xmlrpcerruser'] + 3, 'Wrong username/password combination ' . $username . ' / ' . starify($password));
    }
}
function mweditpost($params)
{
    // ($postid, $user, $pass, $content, $publish)
    global $xmlrpcerruser;
    $xpostid = $params->getParam(0);
    $xuser = $params->getParam(1);
    $xpass = $params->getParam(2);
    $xcontent = $params->getParam(3);
    $xpublish = $params->getParam(4);
    $ID = $xpostid->scalarval();
    $username = $xuser->scalarval();
    $password = $xpass->scalarval();
    $contentstruct = xmlrpc_decode1($xcontent);
    $postdata = wp_get_single_post($ID);
    if (!$postdata) {
        return new xmlrpcresp(0, $xmlrpcerruser + 2, "No such post {$ID}.");
    }
    $userdata = get_userdatabylogin($username);
    $user_ID = $userdata->ID;
    $user_level = $userdata->user_level;
    $post_author_ID = $postdata->post_author;
    $post_authordata = get_userdata($post_author_ID);
    if ($user_ID != $post_author_ID && $user_level <= $post_authordata->user_level) {
        return new xmlrpcresp(0, $xmlrpcerruser + 1, "Sorry, you do not have the right to edit this post.");
    }
    // Check login
    if (user_pass_ok($username, $password)) {
        if ($user_level < 1) {
            return new xmlrpcresp(0, $xmlrpcerruser + 1, "Sorry, level 0 users cannot edit posts");
        }
        extract($postdata);
        $post_title = $contentstruct['title'];
        $post_content = format_to_post($contentstruct['description']);
        $catnames = $contentstruct['categories'];
        logIO("O", "Cat Count" . count($catnames));
        foreach ($catnames as $cat) {
            $post_category[] = get_cat_ID($cat);
        }
        $post_excerpt = $contentstruct['mt_excerpt'];
        $post_more = $contentstruct['mt_text_more'];
        $post_status = $xpublish->scalarval() ? 'publish' : 'draft';
        if ($post_more) {
            $post_content = $post_content . "\n<!--more-->\n" . $post_more;
        }
        $comment_status = 1 == $contentstruct['mt_allow_comments'] ? 'open' : 'closed';
        $ping_status = $contentstruct['mt_allow_pings'] ? 'open' : 'closed';
        $time_difference = get_settings("time_difference");
        $dateCreated = $contentstruct['dateCreated'];
        $dateCreated = $dateCreated ? iso8601_decode($contentstruct['dateCreated']) : time() + $time_difference * 3600;
        $post_date = date("Y-m-d H:i:s", $dateCreated);
        // We've got all the data -- post it:
        $newpost = compact('ID', 'post_content', 'post_title', 'post_category', 'post_status', 'post_excerpt', 'comment_status', 'ping_status', 'post_date');
        $newpost_ID = wp_update_post($newpost);
        if (!$newpost_ID) {
            return new xmlrpcresp(0, $xmlrpcerruser + 2, "For some strange yet very annoying reason, your entry could not be posted.");
        }
        if (!isset($blog_ID)) {
            $blog_ID = 1;
        }
        if (isset($sleep_after_edit) && $sleep_after_edit > 0) {
            sleep($sleep_after_edit);
        }
        pingWeblogs($blog_ID);
        pingCafelog($cafelogID, $post_title, $post_ID);
        pingBlogs($blog_ID);
        pingback($content, $post_ID);
        trackback_url_list($content_struct['mt_tb_ping_urls'], $post_ID);
        logIO("O", "(MW) Edited ! ID: {$post_ID}");
        $myResp = new xmlrpcval($ID, "string");
        return new xmlrpcresp($myResp);
    } else {
        logIO("O", "(MW) Wrong username/password combination <b>{$username} / {$password}</b>");
        return new xmlrpcresp(0, $xmlrpcerruser + 3, 'Wrong username/password combination ' . $username . ' / ' . starify($password));
    }
}
Esempio n. 5
0
	/**
	* Takes an xmlrpc value in PHP xmlrpcval object format and translates it into native PHP types.
	*
	* Works with xmlrpc message objects as input, too.
	*
	* Given proper options parameter, can rebuild generic php object instances
	* (provided those have been encoded to xmlrpc format using a corresponding
	* option in php_xmlrpc_encode())
	* PLEASE NOTE that rebuilding php objects involves calling their constructor function.
	* This means that the remote communication end can decide which php code will
	* get executed on your server, leaving the door possibly open to 'php-injection'
	* style of attacks (provided you have some classes defined on your server that
	* might wreak havoc if instances are built outside an appropriate context).
	* Make sure you trust the remote server/client before eanbling this!
	*
	* @author Dan Libby (dan@libby.com)
	*
	* @param xmlrpcval $xmlrpc_val
	* @param array $options if 'decode_php_objs' is set in the options array, xmlrpc structs can be decoded into php objects
	* @return mixed
	*/
	function php_xmlrpc_decode($xmlrpc_val, $options=array())
	{
		switch($xmlrpc_val->kindOf())
		{
			case 'scalar':
				if (in_array('extension_api', $options))
				{
					reset($xmlrpc_val->me);
					list($typ,$val) = each($xmlrpc_val->me);
					switch ($typ)
					{
						case 'dateTime.iso8601':
							$xmlrpc_val->scalar = $val;
							$xmlrpc_val->xmlrpc_type = 'datetime';
							$xmlrpc_val->timestamp = iso8601_decode($val);
							return $xmlrpc_val;
						case 'base64':
							$xmlrpc_val->scalar = $val;
							$xmlrpc_val->type = $typ;
							return $xmlrpc_val;
						default:
							return $xmlrpc_val->scalarval();
					}
				}
				return $xmlrpc_val->scalarval();
			case 'array':
				$size = $xmlrpc_val->arraysize();
				$arr = array();
				for($i = 0; $i < $size; $i++)
				{
					$arr[] = php_xmlrpc_decode($xmlrpc_val->arraymem($i), $options);
				}
				return $arr;
			case 'struct':
				$xmlrpc_val->structreset();
				// If user said so, try to rebuild php objects for specific struct vals.
				/// @todo should we raise a warning for class not found?
				// shall we check for proper subclass of xmlrpcval instead of
				// presence of _php_class to detect what we can do?
				if (in_array('decode_php_objs', $options) && $xmlrpc_val->_php_class != ''
					&& class_exists($xmlrpc_val->_php_class))
				{
					$obj = @new $xmlrpc_val->_php_class;
					while(list($key,$value)=$xmlrpc_val->structeach())
					{
						$obj->$key = php_xmlrpc_decode($value, $options);
					}
					return $obj;
				}
				else
				{
					$arr = array();
					while(list($key,$value)=$xmlrpc_val->structeach())
					{
						$arr[$key] = php_xmlrpc_decode($value, $options);
					}
					return $arr;
				}
			case 'msg':
				$paramcount = $xmlrpc_val->getNumParams();
				$arr = array();
				for($i = 0; $i < $paramcount; $i++)
				{
					$arr[] = php_xmlrpc_decode($xmlrpc_val->getParam($i));
				}
				return $arr;
			}
	}
Esempio n. 6
0
 function _do_syncwiki(&$request, $args)
 {
     global $charset;
     longer_timeout(240);
     if (!function_exists('wiki_xmlrpc_post')) {
         include_once "lib/XmlRpcClient.php";
     }
     $userid = $request->_user->_userid;
     $dbh = $request->getDbh();
     $merge_point = $dbh->get('mergepoint');
     if (empty($merge_point)) {
         $page = $dbh->getPage("ReleaseNotes");
         // this is usually the latest official page
         $last = $page->getCurrentRevision(false);
         $merge_point = $last->get("mtime");
         // for testing: 1160396075
         $dbh->set('mergepoint', $merge_point);
     }
     //TODO: remote auth, set session cookie
     $pagelist = wiki_xmlrpc_post('wiki.getRecentChanges', iso8601_encode($merge_point, 1), $args['url'], $args);
     $html = HTML();
     //$html->pushContent(HTML::div(HTML::em("check RPC2 interface...")));
     if (gettype($pagelist) === "array") {
         //$request->_deferredPageChangeNotification = array();
         $request->discardOutput();
         StartLoadDump($request, _("Syncing this PhpWiki"));
         PrintXML(HTML::strong(fmt("Download all externally changed sources.")));
         echo "<br />\n";
         PrintXML(fmt("Retrieving from external url %s wiki.getRecentChanges(%s)...", $args['url'], iso8601_encode($merge_point, 1)));
         echo "<br />\n";
         $ouriter = $dbh->mostRecent(array('since' => $merge_point));
         //$ol = HTML::ol();
         $done = array();
         foreach ($pagelist as $ext) {
             $reaction = _("<unknown>");
             // compare existance and dates with local page
             $extdate = iso8601_decode($ext['lastModified']->scalar, 1);
             // TODO: urldecode ???
             $name = utf8_decode($ext['name']);
             $our = $dbh->getPage($name);
             $done[$name] = 1;
             $ourrev = $our->getCurrentRevision(false);
             $rel = '<=>';
             if (!$our->exists()) {
                 // we might have deleted or moved it on purpose?
                 // check date of latest revision if there's one, and > mergepoint
                 if ($ourrev->getVersion() > 1 and $ourrev->get('mtime') > $merge_point) {
                     // our was deleted after sync, and changed after last sync.
                     $this->_addConflict('delete', $args, $our, $extdate);
                     $reaction = _(" skipped") . " (" . "locally deleted or moved" . ")";
                 } else {
                     $reaction = $this->_import($args, $our, $extdate);
                 }
             } else {
                 $ourdate = $ourrev->get('mtime');
                 if ($extdate > $ourdate and $ourdate < $merge_point) {
                     $rel = '>';
                     $reaction = $this->_import($args, $our, $extdate);
                 } elseif ($extdate > $ourdate and $ourdate >= $merge_point) {
                     $rel = '>';
                     // our is older then external but newer than last sync
                     $reaction = $this->_addConflict('import', $args, $our, $extdate);
                 } elseif ($extdate < $ourdate and $extdate < $merge_point) {
                     $rel = '>';
                     $reaction = $this->_export($args, $our);
                 } elseif ($extdate < $ourdate and $extdate >= $merge_point) {
                     $rel = '>';
                     // our is newer and external is also newer
                     $reaction = $this->_addConflict('export', $args, $our, $extdate);
                 } else {
                     $rel = '==';
                     $reaction = _("same date");
                 }
             }
             /*$ol->pushContent(HTML::li(HTML::strong($name)," ",
               $extdate,"<=>",$ourdate," ",
               HTML::strong($reaction))); */
             PrintXML(HTML::strong($name), " ", $extdate, " {$rel} ", $ourdate, " ", HTML::strong($reaction), HTML::br());
             $request->chunkOutput();
         }
         //$html->pushContent($ol);
     } else {
         $html->pushContent("xmlrpc error:  wiki.getRecentChanges returned " . "(" . gettype($pagelist) . ") " . $pagelist);
         trigger_error("xmlrpc error:  wiki.getRecentChanges returned " . "(" . gettype($pagelist) . ") " . $pagelist, E_USER_WARNING);
         EndLoadDump($request);
         return $this->error($html);
     }
     if (empty($args['noexport'])) {
         PrintXML(HTML::strong(fmt("Now upload all locally newer pages.")));
         echo "<br />\n";
         PrintXML(fmt("Checking all local pages newer than %s...", iso8601_encode($merge_point, 1)));
         echo "<br />\n";
         while ($our = $ouriter->next()) {
             $name = $our->getName();
             if ($done[$name]) {
                 continue;
             }
             $reaction = _(" skipped");
             $ext = wiki_xmlrpc_post('wiki.getPageInfo', $name, $args['url']);
             if (is_array($ext)) {
                 $extdate = iso8601_decode($ext['lastModified']->scalar, 1);
                 $ourdate = $our->get('mtime');
                 if ($extdate < $ourdate and $extdate < $merge_point) {
                     $reaction = $this->_export($args, $our);
                 } elseif ($extdate < $ourdate and $extdate >= $merge_point) {
                     // our newer and external newer
                     $reaction = $this->_addConflict($args, $our, $extdate);
                 }
             } else {
                 $reaction = 'xmlrpc error';
             }
             PrintXML(HTML::strong($name), " ", $extdate, " < ", $ourdate, " ", HTML::strong($reaction), HTML::br());
             $request->chunkOutput();
         }
         PrintXML(HTML::strong(fmt("Now upload all locally newer uploads.")));
         echo "<br />\n";
         PrintXML(fmt("Checking all local uploads newer than %s...", iso8601_encode($merge_point, 1)));
         echo "<br />\n";
         $this->_fileList = array();
         $prefix = getUploadFilePath();
         $this->_dir($prefix);
         $len = strlen($prefix);
         foreach ($this->_fileList as $path) {
             // strip prefix
             $file = substr($path, $len);
             $ourdate = filemtime($path);
             $oursize = filesize($path);
             $reaction = _(" skipped");
             $ext = wiki_xmlrpc_post('wiki.getUploadedFileInfo', $file, $args['url']);
             if (is_array($ext)) {
                 $extdate = iso8601_decode($ext['lastModified']->scalar, 1);
                 $extsize = $ext['size'];
                 if (empty($extsize) or $extdate < $ourdate) {
                     $timeout = $oursize * 0.0002;
                     // assume 50kb/sec upload speed
                     $reaction = $this->_upload($args, $path, $timeout);
                 }
             } else {
                 $reaction = 'xmlrpc error wiki.getUploadedFileInfo not supported';
             }
             PrintXML(HTML::strong($name), " ", "{$extdate} ({$extsize}) < {$ourdate} ({$oursize})", HTML::strong($reaction), HTML::br());
             $request->chunkOutput();
         }
     }
     $dbh->set('mergepoint', time());
     EndLoadDump($request);
     return '';
     //$html;
 }
Esempio n. 7
0
function editPage($xmlrpcmsg)
{
    $sql = e107::getDb();
    $blogid = $xmlrpcmsg->getParam(0)->scalarval();
    $pageid = $xmlrpcmsg->getParam(1)->scalarval();
    $username = $xmlrpcmsg->getParam(2)->scalarval();
    $password = $xmlrpcmsg->getParam(3)->scalarval();
    if (userLogin($username, $password, 'H') == true) {
        $content = $xmlrpcmsg->getParam(4);
        $title = $content->structMem('title')->scalarval();
        $description = '[html]' . $content->structMem('description')->scalarval() . '[/html]';
        //if date is null will be replaced with current datetime (wordpress like)
        //check with simplexml for the parameter dateCreated? XMLRPC-PHP seems to not have such functions??
        $tempDate = checkXmlElementS($content->serialize(), 'dateCreated');
        if ($tempDate == 1) {
            $dateCreated = $content->structMem('dateCreated')->serialize();
            // Not all clients send dateCreated info. So add if statement here if you want to use it.
            $timestamp = iso8601_decode($dateCreated);
            // To convert to unix timestamp
        } else {
            $timestamp = time();
        }
        //author from e107
        $query = 'SELECT u.user_id FROM `#user` AS u WHERE u.user_loginname = \'' . $username . '\' AND u.user_password = \'' . md5($password) . '\'';
        $sql->db_Select_gen($query);
        $row = $sql->db_Fetch();
        $author = $row['user_id'];
        //21/08/2009 14.37.49 allow comments
        //add comments flag
        //check if we have something...
        $tempAllowComments = checkXmlElementS($content->serialize(), 'mt_allow_comments');
        if ($tempAllowComments == 1) {
            $comments = $content->structMem('mt_allow_comments')->scalarval();
        }
        $published = $xmlrpcmsg->getParam(5)->scalarval();
        //edit data with new fuctions
        $data['data']['page_id'] = $pageid;
        $data['_FIELD_TYPES']['page_id'] = 'int';
        $data['data']['page_title'] = $title;
        $data['_FIELD_TYPES']['page_title'] = 'todb';
        $data['data']['page_text'] = $description;
        $data['_FIELD_TYPES']['page_text'] = 'todb';
        $data['data']['page_datestamp'] = $timestamp;
        $data['_FIELD_TYPES']['page_datestamp'] = 'int';
        $data['data']['page_author'] = $author;
        $data['_FIELD_TYPES']['page_author'] = 'int';
        $data['data']['page_comment_flag'] = $comments;
        $data['_FIELD_TYPES']['page_comment_flag'] = 'int';
        $data['data']['page_password'] = $wp_password;
        $data['_FIELD_TYPES']['page_password'] = '******';
        $data['data']['page_class'] = 0;
        $data['_FIELD_TYPES']['page_class'] = 'int';
        $pageid = $sql->db_Update('page', $data);
        return new xmlrpcresp(new xmlrpcval(true, 'boolean'));
    } else {
        return new xmlrpcresp(0, $xmlrpcerruser + 1, 'Login Failed');
    }
}
Esempio n. 8
0
/**
 * Request abuse list from central blacklist.
 *
 * @return boolean true = success, false = error
 */
function antispam_poll_abuse()
{
    global $Messages, $Settings, $baseurl, $debug, $antispamsrv_host, $antispamsrv_port, $antispamsrv_uri;
    // Construct XML-RPC client:
    load_funcs('xmlrpc/model/_xmlrpc.funcs.php');
    $client = new xmlrpc_client($antispamsrv_uri, $antispamsrv_host, $antispamsrv_port);
    $client->debug = $debug;
    // Get datetime from last update, because we only want newer stuff...
    $last_update = $Settings->get('antispam_last_update');
    // Encode it in the XML-RPC format
    $Messages->add(T_('Latest update timestamp') . ': ' . $last_update, 'note');
    $startat = mysql2date('Ymd\\TH:i:s', $last_update);
    //$startat = iso8601_encode( mktime(substr($m,11,2),substr($m,14,2),substr($m,17,2),substr($m,5,2),substr($m,8,2),substr($m,0,4)) );
    // Construct XML-RPC message:
    $message = new xmlrpcmsg('b2evo.pollabuse', array(new xmlrpcval(0, 'int'), new xmlrpcval('annonymous', 'string'), new xmlrpcval('nopassrequired', 'string'), new xmlrpcval($startat, 'dateTime.iso8601'), new xmlrpcval(0, 'int')));
    $Messages->add(sprintf(T_('Requesting abuse list from %s...'), $antispamsrv_host), 'note');
    $result = $client->send($message);
    if ($ret = xmlrpc_logresult($result, $Messages)) {
        // Response is not an error, let's process it:
        $response = $result->value();
        if ($response->kindOf() == 'struct') {
            // Decode struct:
            $response = xmlrpc_decode_recurse($response);
            if (!isset($response['strings']) || !isset($response['lasttimestamp'])) {
                $Messages->add(T_('Incomplete reponse.'), 'error');
                $ret = false;
            } else {
                // Start registering strings:
                $value = $response['strings'];
                if (count($value) == 0) {
                    $Messages->add(T_('No new blacklisted strings are available.'), 'note');
                } else {
                    // We got an array of strings:
                    $Messages->add(T_('Adding strings to local blacklist:'), 'note');
                    foreach ($value as $banned_string) {
                        if (antispam_create($banned_string, 'central')) {
                            // Creation successed
                            $Messages->add(T_('Adding:') . ' &laquo;' . $banned_string . '&raquo;: ' . T_('OK.'), 'note');
                        } else {
                            // Was already handled
                            $Messages->add(T_('Adding:') . ' &laquo;' . $banned_string . '&raquo;: ' . T_('Not necessary! (Already handled)'), 'note');
                            antispam_update_source($banned_string, 'central');
                        }
                    }
                    // Store latest timestamp:
                    $endedat = date('Y-m-d H:i:s', iso8601_decode($response['lasttimestamp']));
                    $Messages->add(T_('New latest update timestamp') . ': ' . $endedat, 'note');
                    $Settings->set('antispam_last_update', $endedat);
                    $Settings->dbupdate();
                }
                $Messages->add(T_('Done.'), 'success');
            }
        } else {
            $Messages->add(T_('Invalid reponse.'), 'error');
            $ret = false;
        }
    }
    return $ret;
}
Esempio n. 9
0
	function uploadSession ($xmlrpcmsg)
	 {	
		$dcdb = new Dcdb;
		$return = true;
		
		/*	Get the data */
	    $p1 = $xmlrpcmsg->getParam(0);
	    $p2 = $xmlrpcmsg->getParam(1);
	    $p3 = $xmlrpcmsg->getParam(2);
	    $p4 = $xmlrpcmsg->getParam(3);		
	    $p5 = $xmlrpcmsg->getParam(4);
	    $p6 = $xmlrpcmsg->getParam(5);
	    $p7 = $xmlrpcmsg->getParam(6);
   	    $p8 = $xmlrpcmsg->getParam(7);
		
		$userId = $p1->scalarval();
		$deviceKey = $p2->scalarval();
		$startTime8601 = $p3->scalarval();
		$endTime8601 = $p4->scalarval();
		$pointInterval = $p5->scalarval();
		$totalDist = $p6->scalarval();
		$averageVel = $p7->scalarval();
		$startTimestamp = iso8601_decode($startTime8601);
		$endTimestamp = iso8601_decode($endTime8601);
		$startDatetime = date("Y-m-d H:i:s", $startTimestamp);
		$endDatetime = date("Y-m-d H:i:s", $endTimestamp);
		
		$velPoints = array();
		for ($i = 0; $i < $p8->arraysize(); $i++)
		{
			$val = $p8->arraymem($i);
			$pt = $val->scalarval();
			array_push($velPoints, $pt);
		}
		
		//need to get the device id from the key
		$q = "SELECT `deviceTypeId` from `dcdb_devices` WHERE `key` = '".$deviceKey."'";
		$rslt = $dcdb->query($q);
		$row = mysql_fetch_row($rslt);
		$deviceId = $row[0];
		
		if (mysql_error()){
			$return = false;
		}
		
		/* Add session to db */
		$q = "INSERT INTO `dcdb_sessions` (userId, deviceId, startTime, endTime, "
			."pointResolution, distance, averageVelocity) VALUES('".$userId."','".$deviceId."','"
			.$startDatetime."','".$endDatetime."','".$pointInterval."','".$totalDist."','".$averageVel."')";
		$dcdb->query($q);
		$sessionId = mysql_insert_id();
		
		if (mysql_error()){
			$return = false;
		}
		
		/* Add velocity points to db */
		for ($i=0; $i < count($velPoints); $i++)
		{
			$q = "INSERT INTO `dcdb_sessionVelocityData` (sessionId, pointIndex, velocityPoint) "
				."VALUES('".$sessionId."','".$i."','".$velPoints[$i]."')";
			$dcdb->query($q);
		}
		
		if (mysql_error()){
			$return = false;
		}
						
		return new xmlrpcresp(new xmlrpcval($return, "boolean"));
	}
Esempio n. 10
0
	protected function buildArticle($title, $alias, $intro, $full, $state, $access, $front,$language,$published_up,$published_down,$dateCreated,$created_by, $created_by_alias,$metakey,$metadesc,$metadata)
	{
		$date = JFactory::getDate();
		$created = joooid_toSQL($date);

		$user = JFactory::getUser();
		$userid = intval( $user->get('id') );

		if(!isset($content['description'])){
			$content['description'] = '';
		}
		$content['title'] = $title;
		$content['wp_slug'] = $alias;

		$content['alias'] = $alias;

		$content['articletext'] = $intro.'<hr id="system-readmore" />'.$full;;
		$content['description'] = $intro;
		$content['mt_text_more'] = $full;
		$content['mt_basename'] = $intro;

		if(isset($dateCreated) && $dateCreated != null )
			$content['created'] = $dateCreated;

		if(!isset($content['mt_keywords'])){
			$content['mt_keywords'] = '';
		}

		$content['metakey'] = $content['mt_keywords'];

		if(!isset($content['mt_excerpt'])){
			$content['mt_excerpt'] = '';
		}

		$content['metadesc'] = $content['mt_excerpt'];

		if(isset($state))
		$content['state'] = $state;

		if(isset($access))
		$content['access'] = $access;
		if(isset($language))
		$content['language'] = $language;


		if(isset($created_by))
		$content['created_by'] = $created_by;
		if(isset($created_by_alias))
		$content['created_by_alias'] = $created_by_alias;

		if(isset($metakey))
		$content['metakey'] = $metakey;
		if(isset($metadesc))
		$content['metadesc'] = $metadesc;
		if(isset($metadata))
		$content['metadata'] = $metadata;

		if(isset($content['dateCreated_gmt'])){
			$date = JFactory::getDate(iso8601_decode($content['dateCreated'], 0));
			$content['created']  = $content['publish_up'] = joooid_toSQL($date);
		} else if(isset($content['created'])){
			$date = JFactory::getDate(iso8601_decode($content['created'], 0));
		}

		if(empty($content['id']) && empty($content['created'])){
			$content['created'] = joooid_toSQL(JFactory::getDate());
		}

		if (isset($published_up) && $published_up!='0') {
				
			$tmp = JFactory::getDate($published_up);
			$content['publish_up'] = joooid_toSQL($tmp);
		}

		if (isset($published_down) && $published_down!='0') {
			$tmp = JFactory::getDate($published_down);
			$content['publish_down'] = joooid_toSQL($tmp);
		}

		return $content;
	}
Esempio n. 11
0
function getRecentChanges($params)
{
    global $request;
    // Get the first parameter as an ISO 8601 date. Assume UTC
    $encoded_date = $params->getParam(0);
    $datetime = iso8601_decode($encoded_date->scalarval(), 1);
    $dbh = $request->getDbh();
    $pages = array();
    $iterator = $dbh->mostRecent(array('since' => $datetime));
    while ($page = $iterator->next()) {
        // $page contains a WikiDB_PageRevision object
        // no need to url encode $name, because it is already stored in that format ???
        $name = short_string($page->getPageName());
        $lastmodified = new xmlrpcval(iso8601_encode($page->get('mtime')), "dateTime.iso8601");
        $author = short_string($page->get('author'));
        $version = new xmlrpcval($page->getVersion(), 'int');
        // Build an array of xmlrpc structs
        $pages[] = new xmlrpcval(array('name' => $name, 'lastModified' => $lastmodified, 'author' => $author, 'version' => $version), 'struct');
    }
    return new xmlrpcresp(new xmlrpcval($pages, "array"));
}
Esempio n. 12
0
	protected function buildData($content, $publish, $blogger = false)
	{
		if ($blogger)
		{
			$this->GoogleDocsToContent($content);
		}

		if (!isset($content['description']))
		{
			$content['description'] = '';
		}

		$content['articletext'] = $content['description'];
		unset($content['description']);

		//alias
		if (isset($content['mt_basename']) && !empty($content['mt_basename']))
		{
			$content['alias'] = $content['mt_basename'];
			unset($content['mt_basename']);
		}
		else if (isset($content['wp_slug']) && !empty($content['wp_slug']))
		{
			$content['alias'] = $content['wp_slug'];
			unset($content['wp_slug']);
		}

		if (!isset($content['mt_text_more']))
		{
			$content['mt_text_more'] = '';
		}

		$content['mt_text_more'] = trim($content['mt_text_more']);

		if (JString::strlen($content['mt_text_more']) < 1)
		{
			$temp = explode('<!--more-->', $content['articletext']); //for MetaWeblog
			if (count($temp) > 1)
			{
				$content['articletext'] = $temp[0] . '<hr id="system-readmore" />';
				$content['articletext'] .= $temp[1];
			}
		}
		else
		{
			$content['articletext'] .= '<hr id="system-readmore" />';
			$content['articletext'] .= $content['mt_text_more'];
		}

		unset($content['mt_text_more']);

		if (!isset($content['mt_keywords']))
		{
			$content['mt_keywords'] = '';
		}

		$content['metakey'] = $content['mt_keywords'];

		if (!isset($content['mt_excerpt']))
		{
			$content['mt_excerpt'] = '';
		}

		$content['metadesc'] = $content['mt_excerpt'];

		$content['state'] = 0;

		if ($publish)
		{
			$content['state'] = 1;
		}

		$content['language'] = $this->params->get('language', '*');

		//date
		$basedate = null;
		switch(true)
		{
			case (isset($content['date_created_gmt'])):
				$basedate = $content['date_created_gmt'];
				break;
			case (isset($content['dateCreated_gmt'])):
				$basedate = $content['dateCreated_gmt'];
				break;

			case (isset($content['dateCreated'])):
				$basedate = $content['dateCreated'];
				break;
		}

		if($basedate){
			$timezone = new DateTimeZone(JFactory::getConfig()->get('offset'));
			$now = new DateTime('now', $timezone);
			$offsetsecond = $timezone->getOffset($now);

			$offset = 0;
			if($offsetsecond){
				$offset = $offsetsecond / 3600;
			}

			$date = JFactory::getDate(iso8601_decode($basedate, $offset));
//			$date->setTimeZone(new DateTimeZone(JFactory::getConfig()->get('offset')));
			$content['created'] = $content['publish_up'] = $date->toSql();
		}

		if (empty($content['id']) && empty($content['created']))
		{
			$content['created'] = $content['publish_up'] = JFactory::getDate()->toSql();
		}

		$content['created_by_alias'] = '';
		if(isset($content['wp_author_id']) && $content['wp_author_id'] > 0)
		{
			$author = JFactory::getUser($content['wp_author_id']);
			if($author)
			{
				$content['created_by_alias'] = $author->get('name');
			}
		}

		return $content;
	}
Esempio n. 13
0
 public function convertDate($unixDate)
 {
     jimport('joomla.utilities.date');
     $date = new JDate(iso8601_decode($unixDate));
     if (date('Y', $date->toUnix()) == 1970 && date('m', $date->toUnix()) == 1 && date('d', $date->toUnix()) == 1) {
         return '0000-00-00 00:00:00';
     } else {
         return $date->toMySQL();
     }
 }