Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Stephen 47 posts 69 karma points
    Oct 04, 2011 @ 21:38
    Stephen
    0

    How to identify the media folder...

    Hello,

    Here's the scenario...

    I've got two users, each with their own unique media folder.

    They each have an image in their folder called test.jpg. The two images are not the same.

    The pages they create each share the same template.

    Here's what I want to do.........

    I want the published webpages to display the relevent test.jpg image dependant on the author's media folder.

    I hope that someone might be able to help.

    Thanks

    Steve

     

     

     

  • Rodion Novoselov 694 posts 859 karma points
    Oct 04, 2011 @ 22:08
    Rodion Novoselov
    0

    I think you could use the 'member type' feature. Create a new member type and add a property to it e.g. 'UserImage' of type 'Media picker'. Then assign this member type to the members and set the value of this property for each member to the corresponding image. Then you can access its value for instance in Xslt:

    <xsl:variable name="userImage" select="umbraco.library:GetCurrentMember()/UserImage" />

    and so on.

  • Stephen 47 posts 69 karma points
    Oct 04, 2011 @ 23:23
    Stephen
    0

    Well thank you for your very quick response. I have added a new member type but can't see how to add a property. Iseem to have fallen at the first hurdle.

    I'm somewhat of a novice at Umbraco. Given that each page seems to have the author details, I I windered if there was a simple way to call the relevant media folder,

    If you could point me in the direction of the 'add a property' function then I'll give your method another try.

     

    Thanks

     

    Steve

     

  • Rodion Novoselov 694 posts 859 karma points
    Oct 04, 2011 @ 23:44
    Rodion Novoselov
    0

    When you select your member type in the tree on the left there'll be three tabs in the main area of administrator's window - two of them named 'Generic Properties' and 'Tabs' are absolutely the same as the corresponding tabs of the document type editor. They allow to add properties to the member type and organise them to tabs absolutely the same way as in the case of a document type.

  • Stephen 47 posts 69 karma points
    Oct 04, 2011 @ 23:55
    Stephen
    0

    I hadn't read your first post properly. I was looking at 'Users' instead of 'Members'.

    But I'm not sue that the 'Members' method would work as I want the image to be dependant on the media folder of the author.

    I'm not sure as I'm very new to this.

    Steve

  • Rodion Novoselov 694 posts 859 karma points
    Oct 05, 2011 @ 00:27
    Rodion Novoselov
    0

    So, you want just to show different images depending on the current page's author, do you?

  • Stephen 47 posts 69 karma points
    Oct 05, 2011 @ 01:24
    Stephen
    0

    Yes. That's it.

    Maybe I didn't really explain my needs properly.

    I want the top banner to change depending on the media folder that belongs to the editor who create the page.

    Each editor has thier own separate media folder, they don't share the same folder. So each editor can upload a different banner (test.jpg) to their media folder. Then when their pages are displayed, it will be their chosen banner that is displayed.

    Do you think this is possible to acheive?

     

    Steve

  • Stephen 47 posts 69 karma points
    Oct 05, 2011 @ 01:30
    Stephen
    0

    I forgot to say that the image file would always be called test.jpg.

    So the only thing I'm trying to work out is how to identify the folder itself.

    Then I could follow the solution with /test.jpg

    This would present the image.

  • Rodion Novoselov 694 posts 859 karma points
    Oct 05, 2011 @ 08:35
    Rodion Novoselov
    0

    Well. I would do the next:

    1) Create some common parent folder, say 'Banners', for all user's subfolder (in the media library);

    2) For each user create a subfolder named, for instance with the the same name as a user is;

    3) Under each user's folder create an image item named 'test.jpg' and upload an image file to it;

    After these steps you will have a structure like this in your media library:

    Media
        Banners
              admin
                    test.jpg
              some_user
                    test.jpg
              another_user
                    test.jpg 

    ... and so on 

    4) Now create an Xslt file e.g. banner.xslt:

      <xsl:param name="currentPage"/>
      <xsl:variable name="bannersFolder" select="/macro/bannersFolder"/>
      <xsl:template match="/">
        <xsl:variable name="imgSrc">
          <xsl:if test="$bannersFolder/Folder/@id">
            <xsl:value-of
              select="umbraco.library:GetMedia($bannersFolder/Folder/@id, true())/Folder[@nodeName = $currentPage/@creatorName]/Image[@nodeName = 'test.jpg']/umbracoFile"/>
          </xsl:if>
        </xsl:variable>
        <xsl:if test="$imgSrc">
          <img src="{$imgSrc}" alt=""/>
        </xsl:if>
      </xsl:template>

     

    5) Create a macro for this xslt, name it 'Banner'. Add a parameter to the macro with the alias 'bannersFolder' and the type 'mediaCurrent'

    6) Place the macro to the page you need and set the value of the 'bannersFolder' parameter to the folder created in the step #1

     

    I hope it will help.

     

  • Stephen 47 posts 69 karma points
    Oct 05, 2011 @ 09:50
    Stephen
    0

    Hello Rodion,

     

    Thank you for your continued help on this.

    Will your method let 'User's upload their own banner image such as test.jpg?

    How will I give additional access to other folders for the users?

    I don't want users to be able to have access to the folders of other users. This was my reason for letting each user have their own media folder.

    Then if a User want to change the banner (test.jpg) image they would simply overwrite the existing one in their folder.

    Any ideas?

     

    Steve

     

  • Rodion Novoselov 694 posts 859 karma points
    Oct 05, 2011 @ 10:30
    Rodion Novoselov
    0
    I don't want users to be able to have access to the folders of other users.
    This was my reason for letting each user have their own media folder.

    Hi. There's some problem with this. There's no support of access control for Media like the one for Documents in Umbraco. So, any user that has access to the Media section of the backoffice has full control to the whole media library. However, you can workaround this in two ways.

    One option is to dissalow access to the Media section of the backoffice for the users in question. (backoffice -> Users -> user -> Sections). Then you will need to create some custom upload page that lets these users upload their banners without logging in the backoffice and will save the uploaded image to a media folder depending on the current user.

    Simpler way can be to create special document type to hold a banner image in a property of type 'Upload'. Then you can create a separate document of this document type for each user and set access right to it so that each user has access to his separate document with his own banner.

  • Rodion Novoselov 694 posts 859 karma points
    Oct 05, 2011 @ 13:38
    Rodion Novoselov
    0
  • Rodion Novoselov 694 posts 859 karma points
    Oct 05, 2011 @ 13:40
    Rodion Novoselov
    0

    Oh. Sorry, I have just recalled a feature that I missed completely. You can also assign 'Start Node in Media Library' to any user. So that a user can access only a subtree of the whole media library. Probably it's exactly what you need in your case.

  • Stephen 47 posts 69 karma points
    Oct 05, 2011 @ 19:49
    Stephen
    0

    Hello Rodion,

    Thanks again with your persistance on this....

    Yes. That was what I was thinking. I am assigning each user with a start folder in the media library.

    My problem is that I don't know how to call this property using xslt or some other method.

    I have discovered that the property I want to get is startMediaID. I just don't know the code that would let me use it in a template.

    I want to do something like   ...

    < img " src="startMediaID/test.jpg" />

    wherestartMediaID is a variable and test.jpg is the contstant, always test.jpg

     

    Does that make any more sense?

     

    Steve

     

  • Stephen 47 posts 69 karma points
    Oct 06, 2011 @ 01:15
    Stephen
    0

    Hi Rodion,

    Did you have any more ideas on this? Or do you think it's not possible?

     

    Steve

  • Rodion Novoselov 694 posts 859 karma points
    Oct 06, 2011 @ 06:26
    Rodion Novoselov
    0

    Hi. You can get the ID of a user's start media node with a custom script inside your xslt.

    Insert such a snippet into your xslt:

    <xsl:stylesheet ...
    ...
    xmlns:user="urn:user-scripts">

    <msxml:script language="C#" implements-prefix="user"> <msxml:assembly name="businesslogic"/> <msxml:using namespace="umbraco.BusinessLogic"/> <![CDATA[ public static int GetStartMediaId() { return User.GetCurrent().StartMediaId; } ]]> </msxml:script>

    And then you can use user:GetStartMediaId() later in this xslt exactly like any extension function.

    You can read more on this on MSDN: http://msdn.microsoft.com/en-us/library/ms256042.aspx

     

  • Stephen 47 posts 69 karma points
    Oct 06, 2011 @ 19:37
    Stephen
    0

    Hello Rodion,

     

    I am sure that this must be the answer. But I am too much of a beginner to know how to implement it.

    Is it possible for me to email you directly with a question?

     

    Steve

  • Stephen 47 posts 69 karma points
    Oct 07, 2011 @ 00:20
    Stephen
    0

    Hello Rodion,

    Do you do freelance? 

    Steve

  • Rodion Novoselov 694 posts 859 karma points
    Oct 07, 2011 @ 08:23
    Rodion Novoselov
    0

    Hi. Below is a complete xslt script to perform the rendering that you need:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp "&#x00A0;"> ]>
    <xsl:stylesheet version="1.0"
                    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                    xmlns:msxml="urn:schemas-microsoft-com:xslt"
                    xmlns:lib="urn:umbraco.library"
                    xmlns:scripts="urn:scripts"
                    exclude-result-prefixes="msxml lib scripts">
      <msxml:script language="C#" implements-prefix="scripts">
        <msxml:assembly name="businesslogic"/>
        <msxml:using namespace="umbraco.BusinessLogic"/>
          <![CDATA[
            public static int GetUserStartMediaId(int userId)
            {
              var u = User.GetUser(userId);
              return (u != null)? u.StartMediaId : -1;
            }
          ]]>
      </msxml:script>
      <xsl:output method="xml" omit-xml-declaration="yes"/>
      <xsl:param name="currentPage"/>
      <xsl:template match="/">
        <xsl:variable name="pageCreatorId" select="$currentPage/@creatorID"/>
        <xsl:variable name="pageCreatorStartMediaId" select="scripts:GetUserStartMediaId($pageCreatorId)"/>
        <xsl:if test="$pageCreatorStartMediaId != -1">
          <xsl:variable name="pageCreatorMedia" select="lib:GetMedia($pageCreatorStartMediaId, true())"/>
          <xsl:variable name="imgSrc" select="$pageCreatorMedia/Image[@nodeName = 'test.jpg']/umbracoFile"/>
          <xsl:if test="$imgSrc">
            <img src="{$imgSrc}" alt=""/>
          </xsl:if>
        </xsl:if>
      </xsl:template>
    </xsl:stylesheet>

    As for a fee - thank you for your offering, but I'm not going to ask for this for any kind of forum advisory :-) However, currently from time to time I work as a freelance consultant/developer on web development with ASP.NET, Umbraco, DotNetNuke, and SharePoint. If you know someone who can be ineterested in my teleworking then you can let me know :-)

  • Rodion Novoselov 694 posts 859 karma points
    Oct 07, 2011 @ 08:26
    Rodion Novoselov
    0

    And, yeah, feel free to contact me by e-mail (r.novoselov at gmail.com) if you need.

  • Stephen 47 posts 69 karma points
    Mar 28, 2012 @ 09:38
    Stephen
    0

    Hello Rodion,

    Your answer was very helpful to me. I have been looking at using Umbraco 5 which does not use xslt.

    Is it possible to perform the same function using Razor?

    Steve

     

Please Sign in or register to post replies

Write your reply to:

Draft