PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0
Showing posts with label dotnetnuke. Show all posts
Showing posts with label dotnetnuke. Show all posts

Friday, October 14, 2022

[FIXED] How to remove a Tag using javascript?

 October 14, 2022     dom, dotnetnuke, javascript     No comments   

Issue

I'm in a bit of a pickle. What I'm trying to achieve is to remove a div IF it is empty and then do what I have to afterwards which is the easy bit. The hard part is trying to remove the empty tags. I'm using DNN and it likes to put in empty tags like p and br. I want to be able to remove them before performing my check. Here is my code so far

$(document).ready(function(){
var element = document.getElementsByTagName("p"); //Need to remove all tags. not just P
element.parentNode.removeChild(element); //Doesn't target which child

if( !$.trim( $('#container2Test').html() ).length ) {
    alert("empty");
    $('#container2Test').remove();
    $('#container3Test').css({'width' : '50%', 'background-color' : '#3F0'});
    $('#container3Test').append("This is some content");
}
else{
    alert("not empty");
}
});

The html:

<div id="container1Test" style="width:30%; height:10em; background-color:#000;">
</div>
<div id="container2Test" style="width:50%; height:10em; background-color:#666;">
    <p></p><br /><p></p>
</div>
<div id="container3Test" style="width:20%; height:10em; background-color:#F66;">
</div>

I've tried many options to try and remove the tags but I've had no such luck :( Please help!


Solution

As far as your container2test block goes, try using .text() instead of .html(). This will ignore the empty tags that get inserted and focus only on the text content.

Regarding the piece above it, I'm not quite sure what you're trying to achieve. I don't think it's needed if you implement the change I mentioned earlier.



Answered By - Niet the Dark Absol
Answer Checked By - Willingham (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Wednesday, August 24, 2022

[FIXED] How do I determine pages that contain layouts with content-item of certain entity object in DNN module 2sxc programmatically?

 August 24, 2022     2sxc, dotnetnuke, module     No comments   

Issue

I have entity ListSettings which is used as Content-Item type for 2 layouts. Each layout is used 3 times on different pages. The code I'm writing is not executed on the page - it's outside of 2sxc module. So I wan't to find out on which page each object of entity ListSettings is. TabId is the best. Filtering by layout could be helpful as well since I need 3 tabIds that use 1 of the 2 layouts. How do I do that programmatically? There's a lot of data inside of each entity including some relationships, children, parents and so on. Also I'm sure that all this data could be taken from the database manually, but it seems to be a hard way for me.

Bottom line: I have 6 entities. I want to get their tabIds and layouts programmatically. Layouts are optional but would be good. Any suggestions?


Solution

This is quite challenging, because there are so many steps involved. But you can find something that does something similar here https://2sxc.org/dnn-tutorials/en/razor/2sa110/page

Here is an excerpt of the code:


  // CONSTANTS
  // this key is used in module settings
  const string SettingsCG = "ToSIC_SexyContent_ContentGroupGuid";

  // create array with all 2sxc modules in this portal
  List<ModuleInfo> GetAllModulesOfPortal(int portalId) {
    var mc = ModuleController.Instance;
    var dnnMod2sxcContent = mc.GetModulesByDefinition(portalId, "2Sexy Content");
    var dnnMod2sxcApp = mc.GetModulesByDefinition(portalId, "2Sexy Content App");
    var mergedMods = new ModuleInfo[dnnMod2sxcContent.Count + dnnMod2sxcApp.Count];
    dnnMod2sxcContent.CopyTo(mergedMods);
    dnnMod2sxcApp.CopyTo(mergedMods, dnnMod2sxcContent.Count);
    var allMods = mergedMods
      .Where(m => m.DefaultLanguageModule == null)
      .Where(m => !m.IsDeleted)
      .Where(m => m.ModuleSettings.ContainsKey(SettingsCG));
    return allMods.ToList();
  }



Answered By - iJungleBoy
Answer Checked By - Mildred Charles (PHPFixing Admin)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] How do I make .dnn manifest file to create parent node in web.config for my child not if parent node doesn't exist?

 August 24, 2022     dotnetnuke, manifest, module     No comments   

Issue

I'm working on a DNN module. I need to edit web.config via .dnn manifest file. I need to add rule for url rewrite. I need it to look like this:

<rewrite>
  <rules>
    <rule name="rule1">
      {some content here}
    </rule>
    <rule name="rule2">
      {some content here}
    </rule>
  </rules>
</rewrite>

So main goal is actually to add 1 rule on install and delete it on module deletion. Here is the code from .dnn file that I tried first:

<component type="Config">
  <config>
    <configFile>web.config</configFile>
    <install>
      <configuration>
        <nodes>
          <!--<node path="/configuration/system.webServer" action="add" collision="overwrite">
            <rewrite>
              <rules>
              </rules>
            </rewrite>
          </node>-->

          <node path="/configuration/system.webServer/rewrite/rules" action="add" collision="overwrite">
            <rule name="rule1">
              {some content here}
            </rule>
          </node>
        </nodes>
      </configuration>
    </install>
    <uninstall>
      <configuration>
        <nodes>
          <node path="/configuration/system.webServer/rewrite/rules/rule[@name='rule1']" action="remove">
          </node>
        </nodes>
      </configuration>
    </uninstall>
  </config>
</component>

Problem is that if nodes "rewrite" and "rules" don't exist they are not created and nothing is happening at all on install.

So I tried to add the code that is commented above to create node "rewrite" and "rules" inside of it with collision="ignore" to avoid duplicates. But it doesn't work properly. If "rewrite/rules" exists and it contains already some rules - then DNN thinks that those nodes are different because the existing one contains children and the one that needs to be created has no children. And duplicated "rewrite" is created. Like this:

<rewrite>
  <rules>
    <rule name="rule_existing_before_module_install">
      {some content here}
    </rule>
    <rule name="rule_added_on_module_install">
      {some content here}
    </rule>
  </rules>
</rewrite>
<rewrite> <!--duplicated nod created by uncommented code-->
  <rules>
  </rules>
</rewrite>

If I try to add all the nodes at once by wrapping my rule inside "rewrite" and "rules" then it's not merged with existing "rewrite" but instead creates second one and I end up with web.config like this:

<rewrite>
  <rules>
    <rule name="rule1">
      {some content here}
    </rule>
  </rules>
</rewrite>
<rewrite>
  <rules>
    <rule name="rule2">
      {some content here}
    </rule>
  </rules>
</rewrite>

So eventually if there was a way to create "rewrite/rules" nodes on condition only if they don't exist and make it work both for node with and without children or make my "rewrite/rules" to merge with existing one - it would solve the problem. Tried to google - didn't find anything helpful for this case. Overwriting existing rules with mine and deleting existing rules is not an option. Currently I'm thinking of manual "rewrite/rules" creation and the rest to leave for module's .dnn manifest file but it's not the best option.

Any suggestions?

P.S. I tried to add existing tag "dnn-module" but editor doesn't find it in tag search for some reason. Maybe a bug because it exists but has no questions so far?


Solution

I don't believe that this scenario, is really the targeted goal, as not all installations will actually support this section. (Rewrites is an optional IIS feature, adding this section without it enabled will take a site down)

As such, the current configuration merge functionality doesn't support this exact pathway as you are actually potentially introducing new features/breaking changes so the behavior that it only works with those sections existing is expected.

If you feel that you MUST do this, you could use IUpgradable to have your own custom code modify this, but again, be aware if building for public consumption you run the risk of doing real harm to a site.



Answered By - Mitchel Sellers
Answer Checked By - Terry (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Saturday, April 16, 2022

[FIXED] How can I wait for the create/edit entity modal window to finish rendering and execute my custom js code in 2sxc module?

 April 16, 2022     2sxc, dotnetnuke, iframe, javascript, jquery     No comments   

Issue

When user presses either create entity button or edit entity button, there's the same modal window in an iframe that is build by js dynamically. So what I'm trying to do is to wait until it's fully rendered and then execute my custom js code. So is there a proper way to do that? Some sort of event like RenderFinished shooting or something? Don't want to use timeout since I understand that it's not a good way to do that. What I tried so far is that I've added jquery to the page programmatically, since it's not used currently at that particular page for some reason (probably because iframe is built dynamically without jquery and I needed to add it myself). After that I tried to access iframe via jquery selector and then on iframe.ready access element inside in the same manner (selector and even ready for that element). But iframe is accessed and element inside it is not. Console log inside ready function just outputs no elements found. When I placed breakpoint inside I saw that there's no modal window built yet and my code is executed synchronously before it. So there's nothing to find yet at that moment. Oh and I tried to put it all inside $(document).ready, of course. But it didn't change the situation neither... Any ideas about how to do that properly?

The final goal why am I doing all this complicated dancing: I'm trying to add validation that UrlKey for entity is unique. So I want to bind my js function to UrlKey input's onchange event and call backend api to do the validation and return new UrlKey if it wasn't unique and edit the UrlKey input accordingly. The problem that I stumbled upon is to execute my code after modal iframe window is rendered. Any tips are highly appreciated.


Solution

You are in luck :)

2sxc added a Formula feature which will help you with this. There are videos and tutorials and more. See http://r.2sxc.org/formulas



Answered By - iJungleBoy
Answer Checked By - Senaida (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Older Posts Home
View mobile version

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
All Comments
Atom
All Comments

Copyright © PHPFixing