/**
  * Collect URLs from the current page and stores it into the database for a later upload
  * This function does not upload anything because it speeds up the loadtime of the current page
  * It also does not check if the file is locally stored or not
  *
  * @param array $matches
  * @param bool  $is_css_file this will be converted to true if $is_css_import is true
  * @param bool  $is_css_import
  *
  * @return bool|null|string
  *
  * @since 1.0
  */
 public function collect_urls($matches, $is_css_file = false, $is_css_import = false)
 {
     if ($is_css_import) {
         $is_css_file = true;
     }
     $architecture = '[url]';
     if ($is_css_file) {
         $architecture = 'url("[url]") ';
     }
     if ($is_css_import) {
         $architecture = '@import url("[url]") ' . $matches[1] . ';';
     }
     $url = $matches[0];
     $url = trim($url);
     if ('' == $url) {
         return $url;
     }
     // leaves data: fields in URLs (used in some custom fonts)
     if (false !== stripos($url, 'data:')) {
         return $url;
     }
     // removes versioning from urls (ex. my-file.css?v=3.3.2)
     $versioning = stripos($url, '?');
     if (false !== $versioning) {
         $url = substr($url, 0, stripos($url, '?'));
     }
     // removes versioning with #
     $versioning = stripos($url, '#');
     if (false !== $versioning) {
         $url = substr($url, 0, stripos($url, '#'));
     }
     // checks if the ORIGINAL file URL is in the list of excluded files
     if ($this->is_file_excluded($url)) {
         return $url;
     }
     /**
      * CSS files are tricky
      * we first have to replace all relative paths with their absolute paths
      * then we can decide if it should be uploaded
      */
     if ($is_css_file) {
         $url = $this->real_css_image_url($url);
     }
     // check if the file is in the caching database table
     $drive_url = WPB_Google_Drive_Cdn_Service_Helper::get_cached_url($url);
     if (empty($drive_url)) {
         // if the file has not yet been uploaded to Google Drive, mark it (for doing this later)
         WPB_Google_Drive_Cdn_Service_Helper::record_url($url);
         return $is_css_file ? str_replace('[url]', $url, $architecture) : $url;
     }
     // yes, it's in the db table. Go for it!
     // checks if the DRIVE file URL is in the list of excluded files
     if ($this->is_file_excluded($url)) {
         return $url;
     }
     // now check whether this url should be replaced
     $every_x = (int) WPB_Google_Drive_Cdn_Settings::get_setting('every_x');
     if ($every_x) {
         if (!isset($this->_replacement_counter)) {
             $this->_replacement_counter = 0;
         }
         $this->_replacement_counter = $this->_replacement_counter + 1;
         // replace every single link when $every_x is 1
         if (1 == $every_x) {
             return $is_css_file ? str_replace('[url]', $drive_url, $architecture) : $drive_url;
         }
         // replace nothing
         if ($every_x <= 0) {
             return $is_css_file ? str_replace('[url]', $url, $architecture) : $url;
         }
         // replace each x
         if (0 == $this->_replacement_counter % $every_x) {
             return $is_css_file ? str_replace('[url]', $drive_url, $architecture) : $drive_url;
         }
     }
     // return the normal URL, because we cannot do anything here
     return $is_css_file ? str_replace('[url]', $url, $architecture) : $url;
 }