Merge branch 'master' into calendar_import
This commit is contained in:
commit
aa95cf2c98
|
@ -23,6 +23,7 @@
|
|||
// Check if we are a user
|
||||
OCP\JSON::checkLoggedIn();
|
||||
OCP\JSON::checkAppEnabled('contacts');
|
||||
OCP\JSON::callCheck();
|
||||
require_once('loghandler.php');
|
||||
|
||||
$view = OCP\Files::getStorage('contacts');
|
||||
|
|
|
@ -62,6 +62,14 @@
|
|||
<length>4</length>
|
||||
</field>
|
||||
|
||||
<field>
|
||||
<name>active</name>
|
||||
<type>integer</type>
|
||||
<default>1</default>
|
||||
<notnull>true</notnull>
|
||||
<length>4</length>
|
||||
</field>
|
||||
|
||||
</declaration>
|
||||
|
||||
</table>
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
<?php
|
||||
|
||||
$installedVersion=OCP\Config::getAppValue('contacts', 'installed_version');
|
||||
if (version_compare($installedVersion, '0.2.90', '<')) {
|
||||
// First set all address books in-active.
|
||||
$stmt = OCP\DB::prepare( 'UPDATE *PREFIX*contacts_addressbooks SET active=0' );
|
||||
$result = $stmt->execute(array());
|
||||
|
||||
// Then get all the active address books.
|
||||
$stmt = OCP\DB::prepare( 'SELECT userid,configvalue FROM *PREFIX*preferences WHERE appid=\'contacts\' AND configkey=\'openaddressbooks\'' );
|
||||
$result = $stmt->execute(array());
|
||||
|
||||
// Prepare statement for updating the new 'active' field.
|
||||
$stmt = OCP\DB::prepare( 'UPDATE *PREFIX*contacts_addressbooks SET active=? WHERE id=? AND userid=?' );
|
||||
while( $row = $result->fetchRow()) {
|
||||
$ids = explode(';', $row['configvalue']);
|
||||
foreach($ids as $id) {
|
||||
$r = $stmt->execute(array(1, $id, $row['userid']));
|
||||
}
|
||||
}
|
||||
|
||||
// Remove the old preferences.
|
||||
$stmt = OCP\DB::prepare( 'DELETE FROM *PREFIX*preferences WHERE appid=\'contacts\' AND configkey=\'openaddressbooks\'' );
|
||||
$result = $stmt->execute(array());
|
||||
}
|
|
@ -1 +1 @@
|
|||
0.2
|
||||
0.2.1
|
|
@ -1359,13 +1359,18 @@ Contacts={
|
|||
}
|
||||
return false;
|
||||
},
|
||||
activation:function(checkbox, bookid)
|
||||
{
|
||||
$.post(OC.filePath('contacts', 'ajax', 'activation.php'), { bookid: bookid, active: checkbox.checked?1:0 },
|
||||
function(data) {
|
||||
if (data.status == 'success'){
|
||||
checkbox.checked = data.active == 1;
|
||||
Contacts.UI.Contacts.update();
|
||||
activation:function(checkbox, bookid){
|
||||
var active = checkbox.checked;
|
||||
$.post(OC.filePath('contacts', 'ajax', 'activation.php'), {bookid: bookid, active: (active?1:0)}, function(jsondata) {
|
||||
if (jsondata.status == 'success'){
|
||||
if(!active) {
|
||||
$('#contacts h3[data-id="'+bookid+'"],#contacts ul[data-id="'+bookid+'"]').remove();
|
||||
} else {
|
||||
Contacts.UI.Contacts.update();
|
||||
}
|
||||
} else {
|
||||
OC.dialogs.alert(jsondata.data.message, t('contacts', 'Error'));
|
||||
checkbox.checked = !active;
|
||||
}
|
||||
});
|
||||
},
|
||||
|
@ -1460,7 +1465,7 @@ Contacts={
|
|||
}
|
||||
}
|
||||
};
|
||||
xhr.open('POST', OC.filePath('contacts', 'ajax', 'uploadimport.php') + '?file='+encodeURIComponent(file.name), true);
|
||||
xhr.open('POST', OC.filePath('contacts', 'ajax', 'uploadimport.php') + '?file='+encodeURIComponent(file.name)+'&requesttoken='+requesttoken, true);
|
||||
xhr.setRequestHeader('Cache-Control', 'no-cache');
|
||||
xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
|
||||
xhr.setRequestHeader('X_FILE_NAME', encodeURIComponent(file.name));
|
||||
|
|
|
@ -41,27 +41,62 @@ class OC_Contacts_Addressbook{
|
|||
/**
|
||||
* @brief Returns the list of addressbooks for a specific user.
|
||||
* @param string $uid
|
||||
* @param boolean $active Only return calendars with this $active state, default(=false) is don't care
|
||||
* @return array or false.
|
||||
*/
|
||||
public static function all($uid){
|
||||
public static function all($uid, $active=false){
|
||||
$values = array($uid);
|
||||
$active_where = '';
|
||||
if ($active){
|
||||
$active_where = ' AND active = ?';
|
||||
$values[] = 1;
|
||||
}
|
||||
try {
|
||||
$stmt = OCP\DB::prepare( 'SELECT * FROM *PREFIX*contacts_addressbooks WHERE userid = ? ORDER BY displayname' );
|
||||
$result = $stmt->execute(array($uid));
|
||||
$stmt = OCP\DB::prepare( 'SELECT * FROM *PREFIX*contacts_addressbooks WHERE userid = ? ' . $active_where . ' ORDER BY displayname' );
|
||||
$result = $stmt->execute($values);
|
||||
} catch(Exception $e) {
|
||||
OCP\Util::writeLog('contacts',__CLASS__.'::'.__METHOD__.' exception: '.$e->getMessage(),OCP\Util::ERROR);
|
||||
OCP\Util::writeLog('contacts',__CLASS__.'::'.__METHOD__.' uid: '.$uid,OCP\Util::DEBUG);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
$addressbooks = array();
|
||||
while( $row = $result->fetchRow()){
|
||||
$addressbooks[] = $row;
|
||||
}
|
||||
if(!$active && !count($addressbooks)) {
|
||||
self::addDefault($uid);
|
||||
}
|
||||
|
||||
return $addressbooks;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get active addressbook IDs for a user.
|
||||
* @param integer $uid User id. If null current user will be used.
|
||||
* @return array
|
||||
*/
|
||||
public static function activeIds($uid = null){
|
||||
if(is_null($uid)){
|
||||
$uid = OCP\USER::getUser();
|
||||
}
|
||||
$activeaddressbooks = self::all($uid, true);
|
||||
$ids = array();
|
||||
foreach($activeaddressbooks as $addressbook) {
|
||||
$ids[] = $addressbook['userid'];
|
||||
}
|
||||
return $ids;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns the list of active addressbooks for a specific user.
|
||||
* @param string $uid
|
||||
* @return array
|
||||
*/
|
||||
public static function active($uid){
|
||||
return self::all($uid, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns the list of addressbooks for a principal (DAV term of user)
|
||||
* @param string $principaluri
|
||||
|
@ -186,77 +221,6 @@ class OC_Contacts_Addressbook{
|
|||
return true;
|
||||
}
|
||||
|
||||
public static function cleanArray($array, $remove_null_number = true){
|
||||
$new_array = array();
|
||||
|
||||
$null_exceptions = array();
|
||||
|
||||
foreach ($array as $key => $value){
|
||||
$value = trim($value);
|
||||
|
||||
if($remove_null_number){
|
||||
$null_exceptions[] = '0';
|
||||
}
|
||||
|
||||
if(!in_array($value, $null_exceptions) && $value != "") {
|
||||
$new_array[] = $value;
|
||||
}
|
||||
}
|
||||
return $new_array;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get active addressbooks for a user.
|
||||
* @param integer $uid User id. If null current user will be used.
|
||||
* @return array
|
||||
*/
|
||||
public static function activeIds($uid = null){
|
||||
if(is_null($uid)){
|
||||
$uid = OCP\USER::getUser();
|
||||
}
|
||||
$prefbooks = OCP\Config::getUserValue($uid,'contacts','openaddressbooks',null);
|
||||
if(!$prefbooks){
|
||||
$addressbooks = OC_Contacts_Addressbook::all($uid);
|
||||
if(count($addressbooks) == 0){
|
||||
self::addDefault($uid);
|
||||
}
|
||||
}
|
||||
$prefbooks = OCP\Config::getUserValue($uid,'contacts','openaddressbooks',null);
|
||||
return explode(';',$prefbooks);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns the list of active addressbooks for a specific user.
|
||||
* @param string $uid
|
||||
* @return array
|
||||
*/
|
||||
public static function active($uid){
|
||||
if(is_null($uid)){
|
||||
$uid = OCP\USER::getUser();
|
||||
}
|
||||
$active = self::activeIds($uid);
|
||||
$addressbooks = array();
|
||||
$ids_sql = join(',', array_fill(0, count($active), '?'));
|
||||
$prep = 'SELECT * FROM *PREFIX*contacts_addressbooks WHERE id IN ('.$ids_sql.') ORDER BY displayname';
|
||||
try {
|
||||
$stmt = OCP\DB::prepare( $prep );
|
||||
$result = $stmt->execute($active);
|
||||
} catch(Exception $e) {
|
||||
OCP\Util::writeLog('contacts',__CLASS__.'::'.__METHOD__.', exception: '.$e->getMessage(),OCP\Util::ERROR);
|
||||
OCP\Util::writeLog('contacts',__CLASS__.'::'.__METHOD__.', uid: '.$uid,OCP\Util::DEBUG);
|
||||
OCP\Util::writeLog('contacts',__CLASS__.'::'.__METHOD__.', ids: '.join(',', $active),OCP\Util::DEBUG);
|
||||
OCP\Util::writeLog('contacts',__CLASS__.'::'.__METHOD__.', SQL:'.$prep,OCP\Util::DEBUG);
|
||||
}
|
||||
|
||||
while( $row = $result->fetchRow()){
|
||||
$addressbooks[] = $row;
|
||||
}
|
||||
if(!count($addressbooks)) {
|
||||
self::addDefault($uid);
|
||||
}
|
||||
return $addressbooks;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Activates an addressbook
|
||||
* @param integer $id
|
||||
|
@ -264,30 +228,16 @@ class OC_Contacts_Addressbook{
|
|||
* @return boolean
|
||||
*/
|
||||
public static function setActive($id,$active){
|
||||
// Need these ones for checking uri
|
||||
//$addressbook = self::find($id);
|
||||
|
||||
if(is_null($id)){
|
||||
$id = 0;
|
||||
$sql = 'UPDATE *PREFIX*contacts_addressbooks SET active = ? WHERE id = ?';
|
||||
OCP\Util::writeLog('contacts',__CLASS__.'::'.__METHOD__.', id: '.$id.', active: '.intval($active),OCP\Util::ERROR);
|
||||
try {
|
||||
$stmt = OCP\DB::prepare($sql);
|
||||
$stmt->execute(array(intval($active), $id));
|
||||
return true;
|
||||
} catch(Exception $e) {
|
||||
OCP\Util::writeLog('contacts',__CLASS__.'::'.__METHOD__.', exception for '.$id.': '.$e->getMessage(),OCP\Util::ERROR);
|
||||
return false;
|
||||
}
|
||||
|
||||
$openaddressbooks = self::activeIds();
|
||||
if($active) {
|
||||
if(!in_array($id, $openaddressbooks)) {
|
||||
$openaddressbooks[] = $id;
|
||||
}
|
||||
} else {
|
||||
if(in_array($id, $openaddressbooks)) {
|
||||
unset($openaddressbooks[array_search($id, $openaddressbooks)]);
|
||||
}
|
||||
}
|
||||
// NOTE: Ugly hack...
|
||||
$openaddressbooks = self::cleanArray($openaddressbooks, false);
|
||||
sort($openaddressbooks, SORT_NUMERIC);
|
||||
// FIXME: I alway end up with a ';' prepending when imploding the array..?
|
||||
OCP\Config::setUserValue(OCP\USER::getUser(),'contacts','openaddressbooks',implode(';', $openaddressbooks));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -296,8 +246,15 @@ class OC_Contacts_Addressbook{
|
|||
* @return boolean
|
||||
*/
|
||||
public static function isActive($id){
|
||||
//OCP\Util::writeLog('contacts','OC_Contacts_Addressbook::isActive('.$id.'):'.in_array($id, self::activeIds()), OCP\Util::DEBUG);
|
||||
return in_array($id, self::activeIds());
|
||||
$sql = 'SELECT active FROM *PREFIX*contacts_addressbooks WHERE id = ?';
|
||||
try {
|
||||
$stmt = OCP\DB::prepare( $sql );
|
||||
$result = $stmt->execute(array($id));
|
||||
$row = $result->fetchRow();
|
||||
return (bool)$row['active'];
|
||||
} catch(Exception $e) {
|
||||
OCP\Util::writeLog('contacts',__CLASS__.'::'.__METHOD__.', exception: '.$e->getMessage(),OCP\Util::ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
15
lib/base.php
15
lib/base.php
|
@ -330,21 +330,6 @@ class OC{
|
|||
|
||||
self::checkInstalled();
|
||||
self::checkSSL();
|
||||
|
||||
// CSRF protection
|
||||
if(isset($_SERVER['HTTP_REFERER'])) $referer=$_SERVER['HTTP_REFERER']; else $referer='';
|
||||
$refererhost=parse_url($referer);
|
||||
if(isset($refererhost['host'])) $refererhost=$refererhost['host']; else $refererhost='';
|
||||
$server=OC_Helper::serverHost();
|
||||
$serverhost=explode(':',$server);
|
||||
$serverhost=$serverhost['0'];
|
||||
if(!self::$CLI){
|
||||
if(($_SERVER['REQUEST_METHOD']=='POST') and ($refererhost<>$serverhost)) {
|
||||
$url = OC_Helper::serverProtocol().'://'.$server.OC::$WEBROOT.'/index.php';
|
||||
header("Location: $url");
|
||||
exit();
|
||||
}
|
||||
}
|
||||
self::initSession();
|
||||
self::initTemplateEngine();
|
||||
self::checkUpgrade();
|
||||
|
|
|
@ -324,16 +324,17 @@ class OC_Util {
|
|||
* Redirect to the user default page
|
||||
*/
|
||||
public static function redirectToDefaultPage(){
|
||||
OC_Log::write('core','redirectToDefaultPage',OC_Log::DEBUG);
|
||||
if(isset($_REQUEST['redirect_url']) && (substr($_REQUEST['redirect_url'], 0, strlen(OC::$WEBROOT)) == OC::$WEBROOT || $_REQUEST['redirect_url'][0] == '/')) {
|
||||
header( 'Location: '.$_REQUEST['redirect_url']);
|
||||
$location = $_REQUEST['redirect_url'];
|
||||
}
|
||||
else if (isset(OC::$REQUESTEDAPP) && !empty(OC::$REQUESTEDAPP)) {
|
||||
header( 'Location: '.OC::$WEBROOT.'/?app='.OC::$REQUESTEDAPP );
|
||||
$location = OC::$WEBROOT.'/?app='.OC::$REQUESTEDAPP;
|
||||
}
|
||||
else {
|
||||
header( 'Location: '.OC::$WEBROOT.'/'.OC_Appconfig::getValue('core', 'defaultpage', '?app=files'));
|
||||
$location = OC::$WEBROOT.'/'.OC_Appconfig::getValue('core', 'defaultpage', '?app=files');
|
||||
}
|
||||
OC_Log::write('core', 'redirectToDefaultPage: '.$location, OC_Log::DEBUG);
|
||||
header( 'Location: '.$location );
|
||||
exit();
|
||||
}
|
||||
|
||||
|
|
36
remote.php
36
remote.php
|
@ -25,27 +25,17 @@ if(is_null($file)){
|
|||
|
||||
$file = ltrim ($file, '/');
|
||||
|
||||
if(count(explode('/',$file)) == 2) {
|
||||
$parts=explode('/',$file);
|
||||
$app=$parts[0];
|
||||
switch ($app) {
|
||||
case 'files':
|
||||
OC_Util::checkAppEnabled($app);
|
||||
OC_App::loadApp($app);
|
||||
break;
|
||||
case 'core':
|
||||
break;
|
||||
default:
|
||||
OC_Response::setStatus(OC_Response::STATUS_NOT_FOUND);
|
||||
exit;
|
||||
}
|
||||
$baseuri = OC::$WEBROOT . '/remote.php/'.$service.'/';
|
||||
require_once( OC::$SERVERROOT.'/'.$file);
|
||||
} else {
|
||||
$parts=explode('/', $file, 2);
|
||||
$app=$parts[0];
|
||||
OC_Util::checkAppEnabled($app);
|
||||
OC_App::loadApp($app);
|
||||
$baseuri = OC::$WEBROOT . '/remote.php/'.$service.'/';
|
||||
require_once(OC_App::getAppPath($app) .'/'. $parts[1]);
|
||||
$parts=explode('/', $file, 2);
|
||||
$app=$parts[0];
|
||||
switch ($app) {
|
||||
default:
|
||||
OC_Util::checkAppEnabled($app);
|
||||
OC_App::loadApp($app);
|
||||
$file = OC_App::getAppPath($app) .'/'. $parts[1];
|
||||
break;
|
||||
case 'core':
|
||||
$file = OC::$SERVERROOT .'/'. $file;
|
||||
break;
|
||||
}
|
||||
$baseuri = OC::$WEBROOT . '/remote.php/'.$service.'/';
|
||||
require_once($file);
|
||||
|
|
Loading…
Reference in New Issue