[owncloud-devel] [app] Workin2gether - support request

Hoffmann, Patrick HOP at bito.de
Fri Feb 21 12:42:12 MET 2014


Hello,

currently I'm making an app for my cloud to prevent changes on files by multiple people at the same time.

The idea was:


-          Adding a fileaction for "lock" the file.

-          See the lock status on mouseover

-          Forbid any actions with the locked file (deleting, renaming,replacing)

Currently I made some progress, but I think there is a lack of knowledge about the Owncloud constants.
At the moment I have the problem to really lock the line of the file in the OC filelist, showing the lockstatus automatically on page load, and lock files which have been shared from someones other share.

Is it possible to add the fileaction here called "Dateisperre" with php and not js and can I somehow let the staus load automatically?
atm it's showing the status after the first click and then after the second click it toggles the lockstate.



I've attached the full app project. Here are the important 2 files in my project:

[workin2gether.js]

$(document).ready(function(){

                        var text = "file lock";

                        $.ajax({
        url: OC.filePath('files_w2g','ajax','l10n.php'),
        type: "post",
        data: { rawtext: text},
                                               async: false,
        success: function(data){text = data;},
    });

    if (typeof FileActions !== 'undefined' && $('#dir').length>0) {


            FileActions.register('file',text,OC.PERMISSION_READ,function(){return OC.imagePath('files_w2g','w2g.svg')},function(filename){
                workin(filename,text);
            });

            FileActions.register('dir',text,OC.PERMISSION_READ,function(){return OC.imagePath('files_w2g','w2g.svg')},function(filename){
                workin(filename,text);
            });
    }

});


function workin(filename,text)
{
    oc_dir = $('#dir').val();
    oc_path = oc_dir +'/'+filename;

                        var _safe = "";

                        if($('tr').filterAttr('data-file',filename).find('td.filename').find('a.name').find('span.fileactions').find("a.action").filterAttr('data-action',text).html().indexOf(text)!=-1)
                        {_safe = "true";}
                        else{_safe = "false";}

                        $.ajax({
        url: OC.filePath('files_w2g','ajax','workin2gether.php'),
        type: "post",
        data: { path: oc_path, safe: _safe},
        success: function(data){postmode(filename,data,text)},
    });

}

function postmode(filename,data,text)
{
                                               var html = '<img class="svg" src="'+OC.imagePath('files_w2g','w2g.svg')+'"></img> '+data;
                                               $('tr').filterAttr('data-file',filename).find('td.filename').find('a.name').find('span.fileactions').find("a.action").filterAttr('data-action',text).html(html);
}


[workin2gether.php]
<?php

/*
19.02.2014 Patrick Hoffmann
AGPL free to use :-)
*/


//Init translations
$l = \OCP\Util::getL10N('files_w2g');

//Requirements check
OCP\JSON::checkLoggedIn();
OCP\JSON::checkAppEnabled('files_w2g');


//Default path for lock files
$apath = "C:/xampp/htdocs/apps/files_w2g/lock/";
$storage = "D:/";

//Vars
$path = stripslashes($_POST['path']) ;
@$safe = @$_POST['safe'];
$ppath = lockname($path);


if(cleanPath($path)=="/Shared")
{                      //Exit if you want to lock the Share folder
                        echo "Forbidden";
                        return 1;
}


if(substr(cleanPath($path),0,7)=="/Shared")
{
                        // /Shared/...
                        $relpath = substr(cleanPath($path),7,strlen($path)-7);
                        $relpath = explode('/',$relpath);
                        $relative_path = '/'.$relpath[count($relpath)-1];

                        $backcount = 0;

                        do
                        {
                                               $query = OCP\DB::prepare("SELECT X.uid_owner, Y.path FROM *PREFIX*share X INNER JOIN *PREFIX*filecache Y ON X.file_source = Y.fileid where X.share_with = ? and X.file_target = ? LIMIT 1");
                                               $result = $query->execute(array(OCP\USER::getUser(),'/'.$relpath[count($relpath)-1-$backcount]))->fetchAll();
                                               $backcount+=1;
                        }while(count($result)<1);

                        $realpath = $storage.$result[0]['uid_owner'].'/'.$result[0]['path'];

                        $backcount-=1;
                        for($i=$backcount;$i>0;$i-=1)
                        {
                                               $realpath .= '/'.$relpath[count($relpath)-$i];
                        }

}
else
{
                        // /root
                        $realpath = $storage.OCP\USER::getUser()."/files".cleanPath($path);

}

//lockfile name
$lock = $apath.lockname($realpath);

if(@$safe=="false")
{

                        if (file_exists($lock))
                        {
                                               @unlink($lock);

                                               echo $l->t("File not locked");
                        }
                        else
                        {
                                               @date_default_timezone_set('Europe/Berlin');

                                               $h = fopen($lock, "w");
                                               fwrite($h,OCP\User::getDisplayName()." ".date(DATE_RFC822));
                                               fclose($h);

                                               echo $l->t("File is locked");
                        }
}
else
{
                        if (file_exists($lock))
                        {
                                               echo $l->t("Status: locked");
                        }
                        else
                        {
                                               echo $l->t("Status: not locked");
                        }
}


function lockname($path)
{
                        //Replace all '/' with $ for a filename for the lock file
                        $ppath = str_replace("/","$",cleanPath($path))."$";

                        $ppath = str_replace("Shared","",$ppath);
                        $ppath = str_replace(":","#",$ppath);

                        //Remove double dollar char when exist
                        if ($ppath[0] == "$" and $ppath[1] == "$") $ppath = substr($ppath,1);

                        return $ppath;

}

function cleanPath($path) {

        $path = rtrim($path, "/");
        return preg_replace('{(/)\1+}', "/", $path);
}



I'm looking forward for your feedback.

Kind regards,

Patrick Hoffmann




Gesch?ftsf?hrer: Werner Magin, Winfried Schmuck | HRB 2704 Bad Kreuznach | Gesellschafter: Fritz Bittmann Holding GmbH | USt-ID: DE 811 202 181


BITO-Lagertechnik
Bittmann GmbH
Obertor 29
D-55590 Meisenheim      Telefon:
Telefax:
E-Mail:
Internet:       +49 (0) 6753 122 0
+49 (0) 6753 122 399
info at bito.de
www.bito.de



Dieses E-Mail ist nur f?r den Empf?nger bestimmt, an den es gerichtet ist und kann vertrauliches bzw. unter das Berufsgeheimnis fallendes Material enthalten. Jegliche darin enthaltene Ansicht oder Meinungs?u?erung ist die des Autors und stellt nicht notwendigerweise die Ansicht oder Meinung von BITO-Lagertechnik Bittmann GmbH dar.
Sind Sie nicht der Empf?nger und haben diese E-Mail irrt?mlich erhalten, sind jegliche Verwendung, Ver?ffentlichung, Weiterleitung, Abschrift oder jeglicher Druck dieser E-Mail strengstens untersagt.
Jede ausgehende E-Mail wird von uns mit h?chster Sorgfalt auf Viren gepr?ft. Jedoch ?bernehmen weder BITO-Lagertechnik Bittmann GmbH noch der Absender (Patrick Hoffmann) die Haftung f?r Viren; es obliegt Ihrer Verantwortung, die E-Mail und deren Anh?nge auf Viren zu pr?fen.

This email is exclusively meant for the addressee and may contain confidential information or information which can be classified as professional secret. Any view or opinion stated in this email is that of the author and does not necessarily represent the view or the opinion of BITO-Lagertechnik Bittmann GmbH. If you are not the addressee and if this email has been transmitted to you by mistake, you may not make use of, publish, transmit, reproduce or print the information contained therein for whatever purpose. We take every reasonable care to check all out-bound emails for viruses. However, neither BITO-Lagertechnik Bittmann GmbH nor the sender (Patrick Hoffmann) can be held liable for the occurrence of viruses and any consequential damages. It is therefore the addressee's sole responsibility to check incoming emails and attachments for viruses.

Anh?nge - 2: files_w2g.tar
files_w2g.zip
Versand am 21.02.2014 12:42 von Patrick Hoffmann



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.owncloud.org/pipermail/devel/attachments/20140221/78d1f059/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: files_w2g.tar
Type: application/x-tar
Size: 22528 bytes
Desc: files_w2g.tar
URL: <http://mailman.owncloud.org/pipermail/devel/attachments/20140221/78d1f059/attachment-0001.tar>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: files_w2g.zip
Type: application/x-zip-compressed
Size: 6692 bytes
Desc: files_w2g.zip
URL: <http://mailman.owncloud.org/pipermail/devel/attachments/20140221/78d1f059/attachment-0001.bin>


More information about the Devel mailing list