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

Hoffmann, Patrick HOP at bito.de
Tue Mar 4 13:31:44 MET 2014

Hi Vincent,

Hi Vincent,

just wanted to let you know that my app is now working :-)

But now the cleanup progress starts and some things are really messy coded.

So I could need some tipps, because I recognized that you are really fit with jQuery and OC.

Here you can see the current state: http://imgbox.com/ZFjqBuyh . It locks all other fileactions and
marks the line in a color. But i will add more options later.

If you have some ideas to shorten the code please feel free to answer.

Here is my filetree:
  - l10n.php (grab translation with ajax)
  - workin2gether.php (the core)
-+lock (where the locks are stored)

Source: workin2gether.js

var text = "";
var lockedtext = "";
var lockstate = "";


        text = translate("filelock");
        lockedtext = translate("File is locked");
        lockstate = translate("Status: locked");

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

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

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

                                $('#fileList tr td.filename a.name span.nametext').each(function() {
                                        var $tr = $(this);


function disable_control(filename)

        $('#fileList tr').each(function() {

                var $tr = $(this);

                var $_tr = $tr.html().replace(/^\s+|\s+$/g, '').replace('<span class="extension">','').replace('</span>','');



function enable_control(filename)
        $('#fileList tr').each(function() {

                var $tr = $(this);

                var $_tr = $tr.html().replace(/^\s+|\s+$/g, '').replace('<span class="extension">','').replace('</span>','');

                    if($_tr.indexOf(lockedtext)==-1 && $_tr.indexOf(lockstate)==-1)

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

function getState(filename,_safe)
        filename = filename.replace(/^\s+|\s+$/g, '').replace('<span class="extension">','').replace('</span>','');

    oc_dir = $('#dir').val();
        filename = filename.replace(/ /g, "%20");
        oc_path = oc_dir +'/'+filename;

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


function postmode(filename,data)
                filename = filename.replace(/%20/g,' ');

                var html = '<img class="svg" src="'+OC.imagePath('files_w2g','w2g.svg')+'"></img> '+data;



Source: workin2gether.php

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

//Requirements check

//Default path for lock files


$apath = $root.OCP\Util::linkTo('files_w2g', 'lock')."/";

        @mkdir($root.OCP\Util::linkTo('files_w2g')."/lock", 0777, true);

$storage = "D:/";

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

if(cleanPath($path)=="/Shared"){ echo "Forbidden"; return 1; }

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

        $backcount = 0;
        $dbg = $relpath[count($relpath)-1-0];
                $query = OCP\DB::prepare("SELECT X.parent, X.id, 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();
        }while(count($result)<1 && $backcount<count($relpath));

        if ($backcount>0) $backcount-=1;

        $user = $result[0]['uid_owner'];
        $postpath = $result[0]['path'];
        //get the original share user name

        $old = ""; $new = "-";
        while ($new!="")
                $old = $new;
                $query = OCP\DB::prepare("SELECT parent, uid_owner, id FROM *PREFIX*share where id = ? LIMIT 1");
                $result = $query->execute(array($result[0]['parent']))->fetchAll();
                $new = $result[0]['uid_owner'];
        if($old!="-") $user = $old;

        $realpath = $storage.$user.'$'.$postpath;

                $realpath .= '/'.$relpath[count($relpath)-$i];

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

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

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

                $h = fopen($lock, "w");
                fwrite($h,OCP\User::getDisplayName()." ".date(DATE_RFC822)." ".$path);
                echo $l->t("File is 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, "/");
        $path = urldecode($path);
                return preg_replace('{(/)\1+}', "/", $path);

Source: l10n.php
$l = \OCP\Util::getL10N('files_w2g');
if($l->t($_POST['rawtext'])!="") echo $l->t($_POST['rawtext']); else echo $_POST['rawtext'];

Source: styles.css
#workin2gether p {
        float: left;
        padding-top: 0.8em;
        padding-left: 1.2em;

#workin2gether img  {
        float: left;
        width: 48px;
        height: 48px;
        background: transparent url('apps/files_w2g/img/pattern.png');
        border: 1px solid #D8D8D8;
        padding: 5px;
display:none !important;

a.name.statelock a.action{
opacity:1 !important;
a.name.statelock a.action:hover, a.name.statelock span.extension{

.statelock, .statelock span.modified{
color:#fff !important;

Source: sample language file (de.php)
"File not locked" => "Datei nicht gesperrt",
"File is locked" => "Datei ist gesperrt",
"Status: locked" => "Status: gesperrt",
"Status: not locked" => "Status: nicht gesperrt",
"filelock" => "Dateisperre"

Example for Lockname:



BITO-Lagertechnik Bittmann GmbH

Obertor 29
55590 Meisenheim

Tel: +49 (0) 6753 122 0
Fax: +49 (0) 6753 122 399

E-Mail: info at bito.de

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

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.
Versand am 04.03.2014 13:31 von Patrick Hoffmann

Devel mailing list
Devel at owncloud.org

More information about the Devel mailing list