GithubHelp home page GithubHelp logo

Comments (3)

jonathanlurie avatar jonathanlurie commented on September 25, 2024

I experienced the same issue, thinking using /sync/dropbox/download would synchronize. I actually only adds files.
To empty the post folder (ftp side) at the beginning of the sync would solve the problem for dropbox-exclusive users but would cause damage for someone who uses Dropbox AND ftp...
Since I plan to use Dropbox only to post on my blog, I will add this flush-the-post-folder-before-syncing command. Could you give me a clue on which php file/function it is more relevant to write it?

from justwriting.

hjue avatar hjue commented on September 25, 2024

unlink,delete a file

from justwriting.

jonathanlurie avatar jonathanlurie commented on September 25, 2024

Hi,

I added two stuff to the file application/controllers/dropbox.php :

  1. The feature to add files from from dropbox only if it matches certain extensions.

  2. Removing the blog post when the corresponding markdown file is removed from the dropbox folder

    It concerns only the function download() so the update is pretty quick

  public function download($value='')
  {
    $debug = false;
    if(isset($_GET['challenge'])){
      echo $_GET['challenge'];exit;
    }
    if(isset($_GET['debug'])){
      $debug = true;
    }
    set_time_limit(60*30);
      $this->load->library('dropbox_lib');
    $client = $this->dropbox_lib->getClient();
    if ($client === false) {
        header("Location:  /sync/dropbox");
        exit;
    }
    $cursor = null;
    $cursor_filename =  FCPATH."posts/cursor.txt";
    if(file_exists($cursor_filename)){
      $cursor = file_get_contents($cursor_filename);
    }
    if(empty($cursor)){
      $cursor = null;
    }
    $changes = $client->getDelta($cursor);

    if($debug){
      print_r($changes);
    }


    if(!empty($changes))
    {

      foreach($changes['entries'] as $row){
        $localFilename = "posts".$row[0];
        $filename = FCPATH.$localFilename;

        // extract the extension to filter the dropbox -> ftp transfert
        $ext = pathinfo($filename, PATHINFO_EXTENSION);
        $authorizedExt = array("md", "txt", "markdown");

        if(in_array($ext, $authorizedExt)){

            if($row[1]['is_dir'] ){
              if(!file_exists($filename)){
                mkdir($filename,0777,true);
              }

            }else{
              if(!file_exists(dirname($filename))){
                mkdir(dirname($filename),0777,true);
            }
              if(!empty($row[1])){ // means "a file was added to Dropbox"
                $fd = fopen($filename, "wb");
                $metadata = $client->getFile($row[0], $fd);
                fclose($fd);
                print_r($metadata);

              }else{ // mean "the file was removed from Dropbox"
                     unlink( $localFilename);
                  }
                }

        } // endif authorized ext
      }
      $cursor = $changes['cursor'];
      if($cursor){
        $fd = fopen($cursor_filename, "wb");
        fwrite($fd,$cursor);
        fclose($fd);
      }
    }
  }

(Sorry for the poor indentation)
It would be cooler to place the accepted extension list ($authorizedExt) to settings.php , but I does the job like that...
Cheers.

from justwriting.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.