We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 53697
    • 10 Posts
    Thanks Eko, I added your styles instead and took out all valid_elements - all works on p tags etc... none work on img tags, even when specified as a selector.

    Thinking I might have to re-install?
      • 40088
      • 708 Posts
      So the "img" tag is the only one that fails?

      Hmmm... I just tried adding the "float" code I posted previously to my custom styles and it works beautifully so I'm not sure what the problem is.
        Todd
        • 53697
        • 10 Posts
        I just re-installed, and everything seems to work. I then applied 'customSettings' to the plugin (to use _custom etc and preserve on update) and it doesn't work again sad

        Thinking i'm just going to have to make a copy of what I do should I need to do an update...
          • 40088
          • 708 Posts
          With regard to TW I duplicate all the Chunks I need to use (e.g. CommonCode etc.) and give them a suffix of "-custom". Then I create a custom property set for the TinymceWrapper plugin and set the "chunkSuffix" property to "-custom".

          From this point forward I only edit the "-custom" Chunks so all of my TinyMCE settings et.al. remain intact if I need to reinstall or update.
            Todd
            • 53697
            • 10 Posts
            That's what I did, but used "_Custom" as a suffix as per the setup instructions...
              • 40088
              • 708 Posts
              Oh ok, good.

              Here's my entire init call for the (front-end) Content field, though the style/format settings are exactly the same for my Manager Content field (selector: #ta).

              Granted most of it will not apply to your needs but perhaps you can spot something since it works fine with the img "float" style (included below):
              tinymce.init({
                  selector: "#np-content",
                  skin_url: '[[++assets_url]]components/tinymcewrapper/tinymceskins/modxPericles',
                  menubar: false,
                  contextmenu_never_use_native: true,
              	body_class: 'frontClass',
              	body_id: 'frontId',
                  content_css: [
                  	'//fonts.googleapis.com/css?family=Crimson+Text:400',
                  	'//fonts.googleapis.com/css?family=Cormorant:300,300i,400,400i,500,500i,600,600i,700,700i',
                  	'//fonts.googleapis.com/css?family=Oswald:300,400,700',
                  	'//fonts.googleapis.com/css?family=Expletus+Sans:400,400italic,500,500italic,600,600italic,700,700italic',
                  	'//fonts.googleapis.com/css?family=Roboto+Condensed:300,400',
              		'[[~1]]css/global.css?' + new Date().getTime()
              	],
                  external_plugins: {
                      bubbleBar: "[[++assets_url]]components/tinymcewrapper/tinymceplugins/tinymceBubbleBar.js",
                      charwordcount: "[[++assets_url]]components/tinymcewrapper/tinymceplugins/charwordcount.min.js",
                      definitionlist: "[[++assets_url]]components/tinymcewrapper/tinymceplugins/definitionlist/plugin.min.js",
                      twPreCodeManager: "[[++assets_url]]components/tinymcewrapper/tinymceplugins/twPreCodeManager.js",
              		twAceEditor: "[[++assets_url]]components/tinymcewrapper/tinymceplugins/twAceEditor.js"
                  },
                  twAceEditorPoppedOrInline: 1, //1 for popped (default), 0 for inline
              	twAceEditorSettings: { // pass in any Ace official setting you like to overwrite default behaviour
              	    twAceEditorCDNbase: "",
              	    twPoppedTitle: "Source Code",
              	    twPopped: 0, // popped (1 default) or inline (0)
              	    twPoppedWidth: "",
              	    twPoppedHeight: "",
              	    twEmmetUrl: "[[~1]]assets/components/tinymcewrapper/tinymceplugins/ace/emmet.min.js", // emmet.js version must be for Ace
              	    twViewInlineButtonText: "View Inline",
              	    twCloseButtonText: "Close",
              	    twInlineWidth: "auto",
              	    twInlineHeight: 360,
              	    fontSize: "12px",
              	    theme: "ace/theme/solarized_dark",
              	    showPrintMargin: false,
              	    wrapBehavioursEnabled: true,
              	    twLoadCSS: 0 //default 1
              	},
                  twPreCodeManagerSettings: {
                      twLoadCSS: 0, //default 1
                      protectMODXsquareBrackets: true, // default is false
                      protectMODXsquareBracketsXter: "*", // default xter to place in between open square brackets [[ = [*[
                      contentEditable: true, //default is false
                      managerPREcss: false, //default is true
                  },
                  file_browser_callback: autoFileBrowser,
                  plugins: "anchor,autoresize,preview,contextmenu,image,imagetools,media,link,fullscreen,code,charmap,searchreplace,textpattern",
                  resize: true,
                  autoresize_bottom_margin: 0,
                  autoresize_min_height: 200,
                  autoresize_max_height: 400,
                  image_advtab: true,
                  image_caption: true,
                  style_formats_merge: true,
                  style_formats: [
                  	{ title: 'Containers', items: [
                          { title: 'Article', block: 'article', wrapper: true, merge_siblings: false },
                          { title: 'Aside', block: 'aside', wrapper: true },
                          { title: 'Figure', block: 'figure', wrapper: true },
                          { title: 'Header', block: 'header', wrapper: true },
                          { title: 'Section', block: 'section', wrapper: true, merge_siblings: false }
                      ]},
                  	{ title: 'Custom Styles', items: [
              	    	{ title: 'Cite', inline: 'cite' },
              	    	{ title: 'Horizontal Rule', block: 'hr' },
              	    	{ title: 'Lowercase', inline: 'span', classes: 'lowercase' },
              	    	{ title: 'Quote', inline: 'q' },
              	    	{ title: 'Small', inline: 'small' },
              	    	{ title: 'Sub-heading', block: 'p', classes: 'subHead' },
                  		{ title: 'Tooltip', inline: 'span', classes: 'tooltip' },
                  		{ title: 'Update', block: 'div', classes: 'update' },
                          { title: 'Wide', block: 'div', classes: 'wide' },
                          { title: 'Image Right', selector: 'img', styles: { 'float': 'right' }}
                  	]}
                  ],
                  link_class_list: [
                      { title: 'None', value: '' },
                      { title: 'Image Zoom', value: 'fancybox' }
                  ],
                  rel_list: [
                      { title: 'Default', value: '' },
                      { title: 'External', value: 'external' },
                      { title: 'Do Not Follow', value: 'nofollow' }
                  ],
                  toolbar: "code twPreCodeManager bullist numlist ToggleDefinitionList ToggleDefinitionItem | link unlink anchor | image media | charmap | styleselect | bubbleBarOptionsButton | fullscreen",
                  contextmenu: "code | bold italic underline | link | image media | charmap | removeformat | fullscreen"
              });
              [ed. note: todd.b last edited this post 6 years ago.]
                Todd
                • 53697
                • 10 Posts
                Oh, wow haha. Thanks.

                It can't be my code, as i've just reset to Default properties and put my code in the original chunk. All works fine. My head hurts and client needs this finished so will test on a fresh install when i get time smiley
                  • 53697
                  • 10 Posts
                  Ok new problem - when using 'Default' property set, setting 'no' to TinyMCE on description and introtext fields does not work. It appears even when set to no. (I have also checked System Events to make sure all was set back to Default).

                  So, i'm back to using my custom chunks again, and when using 'img' as selector in styles, it doesn't do anything. As tinyMCE wraps my image in a p tag, i've set the selector to 'p' and have worked around it that way. Still not ideal though and original problem still exists of not being able to apply any formats/styles to an img tag.
                    • 40088
                    • 708 Posts
                    I'm using RFM (part of TW) to auto-create a unique media folder for each user. If I remember correctly the (plain-text) username is used as the folder name by default. Obviously this is not ideal so I'm using a different value (fullname) and converting it into a md5 hash. Also, the below code grabs the hash which I then display with the mediaFolder placeholder in the users’ profile.

                    Everything works, but I don't like relying on a user profile field for the hash because if the user udates that field then a new (empty) media folder will be created, but I also don't want to prevent the user from editing their profile either. So I would like to take it a step further.

                    I would like to automatically generate a unique one-time random hash for each user. So basically it would work as it does now: The very first time RFM is launched by the user their media folder is created with a unique hash instead of using a value from their profile.

                    I found this example on StackOverflow https://stackoverflow.com/questions/1846202/php-how-to-generate-a-random-unique-alphanumeric-string/13733588#13733588 (see post "379") which seems to do what I need, though I'm open to other or better solutions.

                    My problem is I don’t know how to integrate such code into my custom autoCreateFoldersTWrfm file:
                    <?php
                    //extendedRFMcode placed here will catch even existing user folders, and listen for changes
                    //if you wish to encrypt this name and/or use another userfield do it here
                    $myPersonal = $modx->user->get('username');
                    $myPersonal = substr(md5($myPersonal), 0, 24);
                    $rfmUser = $modx->user;
                    $rfmUserProfile = $rfmUser->getOne('Profile');
                    if ($rfmUserProfile) {
                      $extended = $rfmUserProfile->get('extended');
                      $extended['mediaFolder'] = $myPersonal; //change ['responsivefilemanager'] if you like
                      $rfmUserProfile->set('extended', $extended);
                      $rfmUserProfile->save();
                    }
                    
                    // $path is supplied by the calling connector, elFinder or responsivefilemanager
                    if (!file_exists($path.$myPersonal.'/')) {
                      mkdir($path.$myPersonal.'/', 0755, true);
                    }
                    
                    // Create as many subfolders as you want under $myPersonal
                    // if (!file_exists($path.$myPersonal.'/media/')) {
                    //    mkdir($path.$myPersonal.'/media/', 0755, true);
                    //}
                    
                    $copyPath = $path.$myPersonal.'/';
                    $targetFile = $copyPath.'config.php';
                    $userSpecificConfigTemplate = $modx->getChunk('responsivePersonalConfig-custom');
                    
                    // Copy user-specific config.php to each folder
                    if ($copyConfig == 1 && $userSpecificConfigTemplate) {
                        if (!file_exists($targetFile)) { //kill this line if you want to create the config file each time RFM fires.
                            $myfile = fopen($targetFile, "w") or die("Unable to open file!");
                            fwrite($myfile, $userSpecificConfigTemplate);
                            fclose($myfile);
                         } // Kill this line if you want to create the config file each time RFM fires.
                    }
                    
                    $indexFile = $copyPath.'index.html';
                    if (!file_exists($indexFile)) {
                        $myfile = fopen($indexFile, "w") or die("Unable to create/open file.");
                        fclose($myfile);
                    }
                    
                    $readmeFile = $copyPath.'README.txt';
                    if
                     (!file_exists($readmeFile)) {
                        if (file_put_contents($readmeFile, $modx->getChunk('rfmReadMe')) == false) {
                          return 'Failed to write to file ' . $readmeFile;
                        }
                    }
                    
                    return $myPersonal;
                      Todd
                      • 42562
                      • 1,145 Posts
                      $myPersonal = $modx->user->get('id');
                      $myPersonal = substr(md5($myPersonal), 0, 24);


                      I would use ID instead ... that attribute stays through the life of that user.
                        TinymceWrapper: Complete back/frontend content solution.
                        Harden your MODX site by passwording your three main folders: core, manager, connectors and renaming your assets (thank me later!)
                        5 ways to sniff / hack your own sites; even with renamed/hidden folders, burst them all up, to see how secure you are not.