Our blog contains the activity stream of Orchard Dojo: general news, new resources or tutorials are announced here.

Featured tags

IIS
API
All tags >

Media search indexing, code analysis - This week in Orchard (14/06/2021)

Improving the code quality of Orchard Core by code analysis, supporting multiple translation providers, and adding a media search indexing feature to Orchard Core! Check out our post now for more! Orchard Core updates Code analysis Software is critical in all aspects of our lives. From entertainment, shopping, and dating to business-critical systems and software where human lives are at stake. And yet, security bugs are all too frequent, mainly because the process of finding vulnerabilities is manual, tedious, and repetitive, and because the expertise is not shared with other security researchers or with developers. LGTM seeks to address this situation. If you open up that site and enter Orchard Core to the search box on the top, you will see the active alerts for this repository. So, this site will go on GitHub and analyze the source of the projects. It's like a static analyzer for the code that finds potential issues, like this variable is never used, or here you are throwing an exception where you should not, and so on. We can also filter by language to see the alerts related to the C# code of the repository. Based on these issues, some fixes have been made to the source code. For example, we could remove some unused variables to make the code cleaner. Do you know that our Lombiq .NET Analyzers repository contains .NET code analyzers and code convention settings for Lombiq projects? We use these to enforce common standards across all our .NET projects, including e.g. in all of our open-source Orchard Core extensions. If you contribute to our open-source projects while using that solution, you'll be guided by these rules too. If you are interested in how to add these analyzers to your solution too, check out This week in Orchard post, but if you prefer videos, you can find a short presentation about how to use those on YouTube! Support multiple translation providers The localization manager should be able to handle multiple instances of ITranslationProvider. This feature is about supporting multiple translation providers. This way, we can create more methods for storing translations, like filesystem plus database. Right now, we have only one ITranslationProvider implementation in Orchard Core, the PoFilesTranslationProvider. This provider is part of the Localization module, which module provides the infrastructure necessary to support the PO (Portable Object) localization file format. As you can see, the LocalizationManager now injects a list of available ITranslationProvider implementations and calls the LoadTranslations method of every provider to load the translations to the CultureDictionary. Recipes Dropdown focus during setup Let's say you want to set up your Orchard Core site, or you just want to add a new tenant to it. When you move the focus from site name to recipe combo box and press Arrow Down the recipe list pops up. But when you commit your choice via Enter, focus resets to the first item on the page. Not it's fixed. It's a nice to have feature because there are people who prefer using the keyboard to navigate on the site instead of using the mouse. Serve module compile view for package reference If a module is referenced as a NuGet package e.g., OrchardCore.Application.Cms.Targets and if the NuGet package includes precompiled Views.dll, in development views are not served from the Views.dll, instead, it re-compiles all embedded cshtml resulted in a slow start in development. This code is to just ensure that it doesn't try to recompile if it finds the correct DLLs. Demos Media search indexing The idea here was to allow to search for content in files. This demo shows a feature that provides a simple implementation to index media for search. More precisely, it indexes media files related to content items, so said content items will turn up in search when one of their media files matches the search query. The following data can be indexed for each file referenced from a Media Field: Media Text The textual content of PDF files To index the textual content of the PDF files, the pull request uses the PdfPig library, which allows users to read and extract text and other content from PDF files. In addition, the library can be used to create simple PDF documents containing text and geometrical shapes. First of all, let's set up your site using the Blog recipe. This recipe constructs the Blog Post content type that has a Media Field called Banner Image. Let's say we would like to search by using the media text of the Banner Image field. To allow that, open the settings of the Banner Image (Content -> Content Definition -> Content Types -> Blog Post -> Banner Image) and put a tick in the Include this element in the index checkbox. After that, you have to do some configuration for the search fields. If you navigate to Search -> Settings -> Search, you can find the comma-separated list of fields to use for search pages. You can see the Content.ContentItem.FullText value there by default. Here we need to add the BlogPost.Image one. BlogPost is the technical name of the content type (and in this case of the content part too) and Image is the technical name of the Banner Image Media Field. Let's try out this feature quickly! Let's say we just want to edit the predefined blog post with the title Man must explore, and this is exploration at its greatest. Select the browsed image of the Banner Image field and add a media text to it. Now let's navigate to the predefined search form (https://yoursite.com/search) and try to search for the Astronaut word. This is the one that we have just added as the media text to our blog post. Astronaut is not a word that would actually show up anywhere in the body. As you can see, our blog post has just appeared as a result of the search. If you attach a PDF file to the Banner Image media field and try to search for a word or a phrase that is inside the PDF file, the query will return that content item too. This feature is still under development by Zoltán Lehóczky from Lombiq and as we mentioned you can find the PR containing the code here. If you would like to know more about it, don't forget to check out the following recording on YouTube! News from the community Orchard Dojo Newsletter Lombiq's Orchard Dojo Newsletter has 203 subscribers! We have started this newsletter to inform the community around Orchard with the latest news about the platform. By subscribing to this newsletter, you will get an e-mail whenever a new post is published to Orchard Dojo, including This week in Orchard of course. Do you know of other Orchard enthusiasts who you think would like to read our weekly articles? Tell them to subscribe here! If you are interested in more news around Orchard and the details of the topics above, don't forget to check out the recording of this week's Orchard meeting!

This week in Orchard - 04/26/2019

There was no Orchard Podcast this week, but we have lots of news around Orchard Core and new PRs that will be added to Orchard Core soon! On Orchard Core The Arabic translation for Orchard Core is ready A few weeks ago Hisham Bin Ateya and Abdullah Salem have started to work on the Arabic translation for Orchard Core. Thanks to their hard work, the Arabic translation is now ready! This is the second language that has been completed after the French language, which is the main language for many of the core team. Now it's time to test those translations! Order TimeZone list by name When you would like to set the default time zone for your site under Configuration -> Settings -> General you had to select the preferred timezone from a list that wasn't ordered. Now thanks to this PR you can set the value of the time zone using a list that contains ordered values. New user created event and assign user to role task to workflows Soon you can use two brand new activities when constructing your workflows in Orchard Core. The first one called User created, which is surprisingly fired when a user created. The second one is about assigning a role to a user. Let's say we attached this task after the user created event. In this case, when you edit this task, you can say that assign the Authenticated role for the user that has been created just now. In the following workflow, we do the following and show success or failed notification just for demonstration purposes. GitHub authentication Thanks to Michael Petrinolis when this PR will be merge, you can authenticate yourself in Orchard Core using GitHub, by adding this provider to the list of supported external providers soon. Let's see how this feature will work! First, you need to create a new GitHub App. To do that, head to the GitHub Apps page in the Developer settings and hit New GitHub App. Here you need to provide the name of your GitHub app, the full URL to your GitHub App's website and a user authorization callback URL. Don't forget to generate a private key. After you will get a Client ID and a Client secret. You will need them in the next step. Now you can navigate to Orchard Core admin site and enable the Github Authentication feature. After that, you can notice the Github Authentication option under Github in the menubar. Copy your values here and hit save. Now let's open a new incognito window and navigate to the admin page. Here you can see the GitHub, as another service to log in. Provide the username and the password of a GitHub account to sign in. Now Orchard Core asks you to create a new account based on the user information you have just provided in the previous step. If you click on Register your user account will be created in Orchard Core and you will be able to log in using your newly created account. For note, let's see what happens if a user tries to login with an external provider, and registration is enabled: If the external provider provides an email claim, we search for an existing account with that email. If not found, a new OC Account is created based on the username, email, and password provided by the user. If found, we request the password of the OC Account in order to link the external login. There is a PR that takes into consideration the email must confirmed parameter, if we request a password in order to create a local Account from external login, and also uses the ReCaptcha. There is a front page (OrchardCore.Users/Account/ExternalLogins) where you can link/unlink OC account with external providers. Of course, is not complete, we must decide how this is integrated with profile/account info in admin/front end. Regarding the GitHub, you must select to use your email in public and select which one of the verified emails will be included in the claims. External Login registration without password As you noticed in the previous section when you create a new account using an external login provider you have to provide a password to create the user account in Orchard Core. There is a PR to add a setting to register external users without requesting a local password. In this PR, Michael Petrinolis also implements the way to generate a username instead of parsing claims from external login info and to integrate ReCaptcha in External Login Registration. Facebook module OrchardCore.Facebook provides the following features: Core Components Facebook Login First, you need to enable the Users Registrations module and put a tick in the Users can create new accounts on the site checkbox under Configuration -> Settings -> Registration, because we will create a new user account based on the details provided in the Facebook log in page. To register the Facebook App with the site you need to provide the following settings: AppId: Facebook application id. AppSecret: The application secret. Both settings are available in the Facebook for developers application's page, under Basic Settings. Now enable the Facebook Login module and add these values to Orchard Core. The configuration can be set through the Configuration -> Facebook -> Application menu in the admin dashboard. Now you can log in in your site using a Facebook account, where you can get a familiar screen. After that, you can create your new account in Orchard Core that you can use to log in to Orchard. But the PR is not just about authenticating users from Facebook. If you head to the modules, you will find a feature called Facebook Social Plugins Widgets. Let's enable it! Let's say you installed your site using the Blog recipe. In this case, you have a Page content type with a FlowPart attached to it. Create a new Page and hit on the Add Widget button. Here you will see several new widgets that you can attach to your content type that has a FlowPart attached, like Facebook Comments, Facebook Share, Facebook Like and many more. If you publish or preview your page you will see that the widgets are displayed in your page. On Lombiq Orchard Dojo Newsletter Now we have 57 subscribers of the Lombiq's Orchard Dojo Newsletter! We have started this newsletter to inform the community around Orchard with the latest news about the platform. By subscribing to this newsletter, you will get an e-mail every time when a new post published to Orchard Dojo, including This week in Orchard of course. Do you know of other Orchard enthusiasts who you think would like to read our weekly articles? Tell them to subscribe here!

This week in Orchard - 04/05/2019

Orchard Core Beta 3 is here! Read our post about the latest improvements of the new release and a way about how we could store static media files in the future using Orchard Core! On Orchard Core Orchard Core Beta 3 release We are proudly announcing that the community shipped Orchard Core Beta 3 release! Head to the GitHub page of Orchard Core to download the assets of the new release, where you can also find the list of changes for this release! Fixing DataAnnotations localization Using the PO file string localizer, users can't localize data annotations. When you have a model with some Required or DisplayName attributes, the value of the Error Message will be translated automatically using the StringLocalizer. In Orchard 1.x it never worked, but in Orchard Core, it supposed to work because it's using the correct service for translating which Orchard implements. The IStringLocalizer is created by a StringLocalizerFactory. The question is should a StringLocalizer know about the culture supposed to render or is it when we call _localizer.GetString that we should check what is the current culture? Our assumption was that the localizer should be localize for a specific culture because it had a method called WithCulture to return a new one for another culture. But actually, it's not working in this way. In our case is that we were creating a localizer for the current culture (like English, because it's our default), then we go on a page for Spanish, and it will still reuse the same localizer. Now we do the culture resolution when the GetString is called on the instance. It worked in the case of views, because the views get a new StringLocalizer instance every time they rendered, but not when the attributes are evaluated. It's important because this package is not just for the Orchard Core Framework or the CMS, it's a NuGet package, that anyone can use to localize their ASP.NET applications based on PO files. We support pluralization and dynamic PO files too. How to create Media content items in Orchard Core? In Orchard Core media are not content items, they are just files with a path. The Media Field is just a list of path to a file that is handled by the media storage. Most of the time we don't need a content item for the media. It's faster to store just the path and then to load the content item to store the data and render an image. But we can have Media content items by just create a content type (call it Image, Video or whatever) and attach a Media Field to that. Then you can have content pickers on your other content items to select this kind of media. Localization files guide Last week we wrote about that the new localization guide has been added to Orchard Core documentation. And we have good progress on some translations! As you can see, the Arabic is over 40%, the Chinese more than 80% ready! And we have just added the Orchard Core project to Crowdin! The documentation just has the dev version Now when you visit the ReadTheDocs page of Orchard Core, you will not see the option to read the latest or the dev version of the documentation, only the dev version is available. There can't be any misunderstanding about which branch you are targeting, we always show the latest branch (dev branch), and if we have documentation that only relates to the dev branch, we should make some notes in the documentation to say this won't work with the master. Improve the create button on List Part When you have only one content type attached to a List Part, then instead of having a drop down to select it, there is a button to create the given content type. Storing static Media By using the IFileStore, you can get files, store documents into a file store, etc. The IMediaFileStore implements IFileStore and provides two additional methods: MapPathToPublicUrlKnowing a path for media (like /images/thumbnail.png), this method will return the public URL that we need to render when we render a media. This file store can serve the correct media when it's requested. It's a bridge between an HTTP request to the file that is contained by the store. The default one is using the file system implementation (the folder), so it's just saying whenever you want to access /images/thumbnail.png, it will return /media/images/thumbnail.png. MapPublicUrlToPathThis is the opposite. When we have a public URL, can you guess which image it will present? This is done for a very specific reason. If we have an Azure Blob Storage, we want to render not the local path to the image, but the path to Azure Blob Storage. When we have an image to the media manager, it will store the image for example on Azure Blob Storage and then when we get the path for this media from a content item we need to find what is the public URL of this media in Azure. So the custom implementation for Azure Blob Storage will return http://mystorageaccount.blob.core.windows.net/mycontainer/myblob. The next step would be to remove the whole IMediaFileStore interface. Therefore we don't have to care about where publicly the media is accessible.What about serving the Blob Storage from our web server? When we go in /media/myimage.png, the path will be: "myimage.png". In case of an Azure Blob Storage, the public URL will be http://mystorageaccount.blob.core.windows.net/mycontainer/myimage.png. This is the URL, where the browser finds the image. When /media/myimage.png is requested, Orchard will download the blob (corresponding to that from Azure, and either render it directly on the request or save it as a cache locally) and serve it for the next request without having to ask for Azure. In terms of perf, it won't be slow and it opens other possibilities: 1. Resizing images If we do a resize, we could use the following URL: http://mystorageaccount.blob.core.windows.net/mycontainer/myimage.png?width=123 But this won't work, because if we do something like this, the server of Azure doesn't know about ImageSharp or whatever. This thing can only be done if we server the image by ourself. To be able to resize images, we need to process them, that means we need to load them and serve them not from a public URL. 2. CDNs Content Delivery Networks are local caches of the files we request. Some people use Azure Blob Storage because they want CDNs. But we can use CDNs even for our local images. The idea is to use CDNs even for Blob Storage. We could say that yes, we have Blob Storage, but just for storage, it's not for serving the images. We could also make it completely private, so nobody can access our Azure Blob Storage. It's the Orchard web server that will download the media, serve it in a way (/media/images/thumbnail.png) and if we have a CDN, then the CDN itself is responsible for asking us for the media (which will download from Blog Storage, so it will be slower for the first time), but then every time the users will hit the CDN, then they will get the image from the CDN, not from us. We won't even serve the image. Instead of having an interface, that gives us a public URL, every time we render a media is to have a configuration setting with the public CDN prefix for media files. In this configuration, we would define //myownsite.azurecdn.com. What you would do is configure Azure CDN to be a CDN on your website which is mywebsite.com. And whenever we render a media file, we would prefix the URL with that. The browser will ask the CDN for the resource, which will itself ask our site for the resource and then get the blob storage thing. We serve it, that means it will be resizeable, even with a CDN. If we make a request like //myownsite.azurecdn.com/foo.png?width=123, it will request that on our server, so we can resize everything. That would work with any CDN, like Azure CDN, Akamai, Horizon, CloudFlare, etc. Another option is to add a configuration setting with public CDN for resources. When we define a resource, we can set the debug version and the minified version, and also the CDN version. And we also have a setting to say I want to use a CDN version of my resources instead of the local ones (if they are available). We could also be able to set the CDN prefix for these files too, and then they would be also cached by a full CDN and the site would be much faster. However, we need to purge ImageSharp cache automatically with some thresholds. If we cache media items, need to have a way to purge. That's doable because every time we store a media we can store how much data we already stored like in a file that is also on the file system. There are many ways to do that. There is a website using the Blog recipe under sebastienrosdotcom.azurewebsites.net. It's hosted on the east coast, if we look at the Network tab using Google Chrome Developer Tools, it takes about 150 ms to render the page in Hungary, plus the static files, which are either in CDN or loaded by Orchard Core. Seb enabled the CDN and mapped this website to cdn.sebastienros.com. In the first time, it will be slower, but after if you hit F5, it takes less ms. On Lombiq Orchard Dojo Newsletter Now we have 56 subscribers of the Lombiq's Orchard Dojo Newsletter! We have started this newsletter to inform the community around Orchard with the latest news about the platform. By subscribing to this newsletter, you will get an e-mail every time when a new post published to Orchard Dojo, including This week in Orchard of course. Do you know of other Orchard enthusiasts who you think would like to read our weekly articles? Tell them to subscribe here! If you are interested in more news around Orchard and the details of the topics above, don't forget to check out the recording of this week's Orchard meeting!