Jump to content
AndZyk

Allow protocol file:// in FieldType URL and CKEditor links

Recommended Posts

Hello,

I am currently building a intranet which will be hosted on the local network of a company. This intranet has many links to files on their fileserver with the protocol file://.

So for example the links look like this file://domain.tld/filename.ext

  • When I try to insert such a link into a URL field, I get the error, that only the protocol http:// is allowed.
  • When I try to insert such a link into a CKEeditor link, it gets stripped out.

Is it possible to insert such links into the FieldType URL and CKEditor.

I know that I could use a FieldType Text or insert a RewriteRule in the .htaccess file, but I am looking for a more elegant solution. 😉

Regards, Andreas

Share this post


Link to post
Share on other sites

I have not truly vetted the plugin, but there is this official plugin via CKEditor. It let me select from various protocols and has an "other" selection. I was able to successfully use the file:// protocol inside the href without it getting stripped.

  • Like 1

Share this post


Link to post
Share on other sites

Thank you @louisstephens for the hint. I tried it out, but the link still gets stripped out, even with disabled ACF. Do you have configured extra allowed content?

Maybe a RewriteRule in the .htaccess file would be the easiest solution. 🤔

Share this post


Link to post
Share on other sites
4 hours ago, AndZyk said:

Thank you @louisstephens for the hint. I tried it out, but the link still gets stripped out, even with disabled ACF. Do you have configured extra allowed content?

Maybe a RewriteRule in the .htaccess file would be the easiest solution. 🤔

Ah, I did not have extra allowed content enabled, but it was a bit confusing for me as I had to add it to the toolbar and the icon appeared to be exactly like the current "url" icon. 

Share this post


Link to post
Share on other sites

My solution for textareas with CKEditor is now a simple Textformatter module. 😉

<?php
class TextformatterReplaceLinks extends Textformatter implements Module {

    public static function getModuleInfo() {
        return array(
            "title" => "Replace Links",
            "version" => "1.0.0",
            "summary" => "Find and replace links of domain.",
            "author" => "AndZyk",
            "singular" => true,
            "requires" => "ProcessWire>=2.6",
            "icon" => "link"
        );
    }

    /**
     * Find and replace the input string
     *
     * @param string $str The block of text to parse
     *
     * The incoming string is replaced with the formatted version of itself.
     *
     */

    public function format(&$str) {

        $str = preg_replace("/(http|https):\/\/example.com/", "file://example.com", $str);

    }
}

Regards, Andreas

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By picarica
      so hello there i have fiel field type i have lots of stuff there, and also an image i can easily get image from that field using
                                                        
      $options = array('quality' => 85, 'upscaling' => true, 'cropping' => 'north', 'sharpening' => 'medium'); $word = ".png"; // Test if string contains the word foreach($childgames->subor_hry as $file) { if(strpos($file, $word) !== false){ /* $imger = $file->size(473, 266, $options); */ echo $file; /* echo $file->url; */ } } so i get the fiel i tried invoking size on it like the commented out part and it doesnt work i get error Oh snizzle… Error:     Exception: Method Pagefile::size does not exist or is not callable in this context (in
      what am i doing wrong? can you guys help me by all logic this should work
    • By Marvin
      Hello,
      I'm new at process wire and i want to make an web using upload file and showing it at the table as a link to open it at the new tab. I wa succed while upload a file, but how i showing it as a link at the table to open it at the new tab of my browser? Any suggestion may helpfull
      Here i attach my code below :
      This code is for upload it to back-end (process wire)
      <?php $note = $note2 = $hidden =""; if($input->post->submit){ $upload_path = $config->paths->assets.'files/upload/'; if(!is_dir($upload_path)){ if(!wireMkdir($upload_path)) throw new WireException("No upload path"); } $original = $sanitizer->text($input->post->original); $indonesia = $sanitizer->text($input->post->indonesia); $other = $sanitizer->text($input->post->other); $composer = $sanitizer->text($input->post->composer); if(!$original || !$indonesia || !$other || !$composer){ $note = "Data tidak lengkap"; } else { $newFile = new WireUpload("song_files"); $newFile->setMaxFiles(1); $newFile->setOverwrite(false); $newFile->setDestinationPath($upload_path); $newFile->setValidExtensions(array('pdf','docx','doc')); $files = $newFile->execute(); if(!count($files)) { $newFile->error("No files received, so not creating page."); return false; } $newImg = new WireUpload("img_files"); $newImg->setMaxFiles(1); $newImg->setOverwrite(false); $newImg->setDestinationPath($upload_path); $newImg->setValidExtensions(array('jpeg','jpg','png','gif')); $files = $newImg->execute(); if(!count($files)) { $newImg->error("No files received, so not creating page."); return false; } $newPage = new Page(); $newPage->template = "files"; $newPage->parent = $pages->get("/files/"); $newPage->title = $original; $newPage->text_1 = $indonesia; $newPage->text_2 = $other; $newPage->text_3 = $composer; $newPage->of(false); $newPage->save(); foreach($files as $filename) { $filepath = $upload_path . $filename; $newPage->files->add($filepath); $newPage->message("Add file : $filename"); unlink($filepath); } $newPage->save(); } } ?> and this code to showing it as a link at the table
      <table class="border"> <tr> <th>No.</th> <th>Original Song Title</th> <th>Indonesia Song Title</th> <th>Other Song Title</th> <th>Composer</th> <th>File (pdf)</th> </tr> <?php $num = 1; $song; foreach($pages->get("/files/")->children as $child) { //showing every child at files parent directory $page == $child; $song = $pages->get("/files/".$child->id."/")->files; //showing uploaded files at child directory echo $child->id; echo "<tr><td>".$num++.".</td><td>".$child->title."</td><td>".$child->text_1."</td><td>".$child->text_2."</td><td>".$child->text_3."</td><td><a href='".$song->httpUrl."'</a>".$song->name."</td></tr>"; } ?> </table> Thank you for any suggestion
    • By theoretic
      Hi there! And thanks for Processwire!
      It appears there's a possible bug in Processwire 3.0.170 concerning file and/or image inputfield. Creating such a field results in the following error:

      Fatal Error: Uncaught Error: Call to a member function get() on null
      The inputfield is created however. The closer look reveals a problem at line 60 in wire\modules\Fieldtype\FieldtypeFile\config.php:
      if(!$value) $value = $fieldtype->get('defaultFileExtensions'); Commenting this line removes the problem, but the newly created inputfield requires 'Allowed file extensions' config option to be set (which is rather expectable since i commented the above-cited line of code). Never faced this problem before, hope it can be resolved.
    • By humanafterall
      Hi,
      I have a URL field that will sometimes have relative/local URLs on a multilingual site, for example /contact/ 

      However the URL field does not seem to pick up when I'm on another language, for example /fr/ so I'm taken to the default language page for /contact/ rather than /fr/contact/
      Is there a way to make the URL fields play well with a multi-language site?
      Thanks!
       
×
×
  • Create New...