original_string: public function sync_reference(stored_file $file) {
          global $CFG;
          if ($file->get_referencelastsync() + DAYSECS > time()) {
              // Synchronise not more often than once a day.
              return false;
          }
          $c = new curl();
          $reference = unserialize(self::convert_to_valid_reference($file->get_reference()));
          $url = $reference->downloadurl;
          if (file_extension_in_typegroup($file->get_filename(), 'web_image')) {
              $path = $this->prepare_file('');
              $result = $c->download_one($url, null, array('filepath' => $path, 'timeout' => $CFG->repositorysyncimagetimeout));
              $info = $c->get_info();
              if ($result === true && isset($info['http_code']) && $info['http_code'] == 200) {
                  $file->set_synchronised_content_from_file($path);
                  return true;
              }
          }
          $c->get($url, null, array('timeout' => $CFG->repositorysyncimagetimeout, 'followlocation' => true, 'nobody' => true));
          $info = $c->get_info();
          if (isset($info['http_code']) && $info['http_code'] == 200 &&
                  array_key_exists('download_content_length', $info) &&
                  $info['download_content_length'] >= 0) {
              $filesize = (int)$info['download_content_length'];
              $file->set_synchronized(null, $filesize);
              return true;
          }
          $file->set_missingsource();
          return true;
      }
code: public function sync_reference(stored_file $file) {
          global $CFG;
          if ($file->get_referencelastsync() + DAYSECS > time()) {
              // Synchronise not more often than once a day.
              return false;
          }
          $c = new curl();
          $reference = unserialize(self::convert_to_valid_reference($file->get_reference()));
          $url = $reference->downloadurl;
          if (file_extension_in_typegroup($file->get_filename(), 'web_image')) {
              $path = $this->prepare_file('');
              $result = $c->download_one($url, null, array('filepath' => $path, 'timeout' => $CFG->repositorysyncimagetimeout));
              $info = $c->get_info();
              if ($result === true && isset($info['http_code']) && $info['http_code'] == 200) {
                  $file->set_synchronised_content_from_file($path);
                  return true;
              }
          }
          $c->get($url, null, array('timeout' => $CFG->repositorysyncimagetimeout, 'followlocation' => true, 'nobody' => true));
          $info = $c->get_info();
          if (isset($info['http_code']) && $info['http_code'] == 200 &&
                  array_key_exists('download_content_length', $info) &&
                  $info['download_content_length'] >= 0) {
              $filesize = (int)$info['download_content_length'];
              $file->set_synchronized(null, $filesize);
              return true;
          }
          $file->set_missingsource();
          return true;
      }
code_tokens: public function sync_reference ( stored_file $ file ) { global $ CFG ; if ( $ file -> get_referencelastsync ( ) + DAYSECS > time ( ) ) { // Synchronise not more often than once a day. return false ; } $ c = new curl ( ) ; $ reference = unserialize ( self :: convert_to_valid_reference ( $ file -> get_reference ( ) ) ) ; $ url = $ reference -> downloadurl ; if ( file_extension_in_typegroup ( $ file -> get_filename ( ) , 'web_image' ) ) { $ path = $ this -> prepare_file ( '' ) ; $ result = $ c -> download_one ( $ url , null , array ( 'filepath' => $ path , 'timeout' => $ CFG -> repositorysyncimagetimeout ) ) ; $ info = $ c -> get_info ( ) ; if ( $ result === true && isset ( $ info [ 'http_code' ] ) && $ info [ 'http_code' ] == 200 ) { $ file -> set_synchronised_content_from_file ( $ path ) ; return true ; } } $ c -> get ( $ url , null , array ( 'timeout' => $ CFG -> repositorysyncimagetimeout , 'followlocation' => true , 'nobody' => true ) ) ; $ info = $ c -> get_info ( ) ; if ( isset ( $ info [ 'http_code' ] ) && $ info [ 'http_code' ] == 200 && array_key_exists ( 'download_content_length' , $ info ) && $ info [ 'download_content_length' ] >= 0 ) { $ filesize = ( int ) $ info [ 'download_content_length' ] ; $ file -> set_synchronized ( null , $ filesize ) ; return true ; } $ file -> set_missingsource ( ) ; return true ; }
docstring: Synchronize the references.
  
  @param stored_file $file Stored file.
  @return boolean
docstring_tokens: Synchronize the references .