<commit_before><?php

/*
// Alkaline
// Copyright (c) 2010-2011 by Budin Ltd. All rights reserved.
// Do not redistribute this code without written permission from Budin Ltd.
// http://www.alkalineapp.com/
*/

/**
 * @author Budin Ltd. <<EMAIL>>
 * @copyright Copyright (c) 2010-2011, Budin Ltd.
 * @version 1.0
 */

class XMLRPC extends Alkaline{
	public $user;
	
	public function __construct(){
		parent::__construct();
	}
	
	public function __destruct(){
		parent::__destruct();
	}
	
	protected function auth($username, $password){
		$user = new User;
		if(!$user->auth($username, $password)){
			$this->addError('Must be authenticated.', 'Check your username and password.', null, null, 401);
			exit();
		}
		
		$this->user = $user;
	}
	
	public function newPost($method, $args){
		list($blogid, $username, $password, $content, $publish) = $args;
		
		$this->auth($username, $password);
		
		$post_title = trim($content['title']);
		
		$post_title_url = $this->makeURL($post_title);
		
		$post_text_raw = $content['description'];
		$post_text = $post_text_raw;
		
		// Configuration: post_markup
		if($this->returnConf('post_markup')){
			$orbit = new Orbit;
			$post_markup_ext = $this->returnConf('post_markup_ext');
			$post_text = $orbit->hook('markup_' . $post_markup_ext, $post_text_raw, $post_text);
		}
		else{
			$post_markup_ext = '';
			$post_text = $this->nl2br($post_text_raw);
		}
		
		// Publish?
		$post_publish = '';
		if(($publish == true) or ($publish == 'true')){
			$post_publish = date('Y-m-d H:i:s');
		}
		
		$post_images = implode(', ', $this->findIDRef($post_text));
		
		$post_words = $this->countWords($post_text_raw);
		
		$fields = array('post_title' => $this->makeUnicode($post_title),
			'post_title_url' => $post_title_url,
			'post_text_raw' => $this->makeUnicode($post_text_raw),
			'post_markup' => $post_markup_ext,
			'post_images' => $post_images,
			'post_text' => $this->makeUnicode($post_text),
			'post_published' => $post_publish,
			'post_words' => $post_words);
		
		$post_id = $this->addRow($fields, 'posts');
		
		return $post_id;
	}
	
	public function newMediaObject($method, $args){
		list($blogid, $username, $password, $content) = $args;
		
		$this->auth($username, $password);<commit_msg>XML-RPC adds user_id when newPost()<commit_after><?php

/*
// Alkaline
// Copyright (c) 2010-2011 by Budin Ltd. All rights reserved.
// Do not redistribute this code without written permission from Budin Ltd.
// http://www.alkalineapp.com/
*/

/**
 * @author Budin Ltd. <<EMAIL>>
 * @copyright Copyright (c) 2010-2011, Budin Ltd.
 * @version 1.0
 */

class XMLRPC extends Alkaline{
	public $user;
	
	public function __construct(){
		parent::__construct();
	}
	
	public function __destruct(){
		parent::__destruct();
	}
	
	protected function auth($username, $password){
		$user = new User;
		if(!$user->auth($username, $password)){
			$this->addError('Must be authenticated.', 'Check your username and password.', null, null, 401);
			exit();
		}
		
		$this->user = $user;
	}
	
	public function newPost($method, $args){
		list($blogid, $username, $password, $content, $publish) = $args;
		
		$this->auth($username, $password);
		
		$post_title = trim($content['title']);
		
		$post_title_url = $this->makeURL($post_title);
		
		$post_text_raw = $content['description'];
		$post_text = $post_text_raw;
		
		// Configuration: post_markup
		if($this->returnConf('post_markup')){
			$orbit = new Orbit;
			$post_markup_ext = $this->returnConf('post_markup_ext');
			$post_text = $orbit->hook('markup_' . $post_markup_ext, $post_text_raw, $post_text);
		}
		else{
			$post_markup_ext = '';
			$post_text = $this->nl2br($post_text_raw);
		}
		
		// Publish?
		$post_publish = '';
		if(($publish == true) or ($publish == 'true')){
			$post_publish = date('Y-m-d H:i:s');
		}
		
		$post_images = implode(', ', $this->findIDRef($post_text));
		
		$post_words = $this->countWords($post_text_raw);
		
		$fields = array('post_title' => $this->makeUnicode($post_title),
			'user_id' => $this->user->user['user_id'];
			'post_title_url' => $post_title_url,
			'post_text_raw' => $this->makeUnicode($post_text_raw),
			'post_markup' => $post_markup_ext,
			'post_images' => $post_images,
			'post_text' => $this->makeUnicode($post_text),
			'post_published' => $post_publish,
			'post_words' => $post_words);
		
		$post_id = $this->addRow($fields, 'posts');
		
		return $post_id;
	}
	
	public function newMediaObject($method, $args){
		list($blogid, $username, $password, $content) = $args;
		
		$this->auth($username, $password);
{'fraction_non_alphanumeric': 0.18223684210526317, 'fraction_numerical': 0.009649122807017544, 'mean_word_length': 4.2546082949308754, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 58, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4966290', 'n_tokens_mistral': 1852, 'n_tokens_neox': 1595, 'n_words': 319}