How to publish image folder from content manager using C# TBB? [closed] - tridion

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I want to move all my images from one of the folder in content manager to one of the folder on the server, how to do it using C# TBB?

On SDL Tridion World you can find a set of useful Template Building Blocks which contains a solution for that: http://sdltridionworld.com/community/extension_overview/useful_tbbs.aspx
See #5: Get CSS Images - Publish all the images in a particular CMS folder.
Here is a snipped of the code from that solution just to get the idea of how its done.
Filter filter = new Filter();
filter.Conditions["ItemType"] = ItemType.Component;
filter.Conditions["Recursive"] = false;
foreach (Component img in folder.GetItems(filter))
{
if (img.ComponentType == ComponentType.Multimedia)
{
string filename = Utilities.GetFilename(img.BinaryContent.Filename);
Item item = package.GetByName(filename);
bool push = true;
if (item != null)
{
Logger.Debug("An item with the same name exists in the package");
KeyValuePair<string, string> pair = new KeyValuePair<string,string>("TCMURI", img.Id.ToString());
if (item.Properties.Contains(pair))
{
Logger.Debug("An item with the same uri exists in the package, we will not push it twice to the package.");
push = false;
}
}
if(push)
{
Logger.Debug(String.Format("Pushing item {0} to the package", filename));
package.PushItem(filename, package.CreateMultimediaItem(img.Id));
}
}
}
Instead of pushing the item into the package and allowing it to be published by the Default Finish Actions, you can also call AddBinary and specify the Structure group you want it published too.
Engine.PublishingContext.RenderedItem.AddBinary(img, structureGroup);
See the TOM.NET API documentation for more details.

Couple of ways you can do this:
1) static publishing, that is create a structure group (i.e. the folder that will be created on the server) and create a page inside. Your page will need a metadata schema that takes a multivalve multimedia component link such that you can add images to the page's metadata. You will need to build a page template for this page that will have a TBB which gets the multimedia components from the page metadata and uses the Engine.AddBinary method to add the images into the package and be published with the page (the page output can be some dummy stuff). Note, if you have a lot of images there will be a performance impact.
2) dynamic publishing: if you have the broker, you can configure file system publishing. Then create a dynamic component template linked to your image schema. Inside use a TBB with the engine.AddBinary method for the given MM component to publish an image to a given structure group as a dynamic component presentation.

Related

How to Read the Tridion Page URL from the publication using Core Services?

I have a list of Tridion page URL's in an excel sheet, which should be unpublished on Click of a button for which I am developing a custom page. How do I read the URL from the publication.? For example, the URL looks like "https://www.example.com/us/en/abc/cde/index.html" (us/en - country/language; abc- folder in structure group, cde- subfolder in abc, index.html is the page) Now index.html should be unpublished.
If I understand you correctly, you have the URL of a page and you want to find the corresponding page in Tridion. First the bad news: The core service (the CM API) does not support a 'find by url'. The quick and dirty approach would be to use the CD API to retrieve the page. This will give you Page back which has an ID property. You can then use the core service to unpublish the page.
You can also do it with a pure core service approach but it's a bit more work and it's slow. It goes like this:
Start from the top level directory (in your example 'us')
List all structure groups inside the root using a filter like this:
var filter = new OrganizationalItemItemsFilterData()
{
ItemTypes = new ItemType[] { ItemType.Page },
IncludePathColumn = true
};
Use Linq to find the one with the top-level directory you're after
Move to the next directory and repeat with the child structure group you found

Get TinyMCE 4.3 Image Tools to save images as regular image files

The new TinyMCE 4.3 Image Tools (eg when cropping) saves images as blob data instead of image files in a directory. the edited mage url is like
blob:http://www.example.com/f2953aa1-e64f-49e1-a6e3-a283986663bf
I want to upload the image file to a specific folder and then use it as regular image referance / path.
Note
The question I am going to put is similar to Image edit issue. but the answer to this question is not working. I also tried http://archive.tinymce.com/forum/viewtopic.php?id=35740 solution but not working because it produces always same name image name.
The basic process is that TinyMCE will create a separate HTTP POST for each image that you modify with the image editor. It will send that image to a URL of your choosing (via HTTP POST) based on the setting of the images_upload_url option in your init.
The image handler at the URL referenced in the images_upload_url (which you have to create) has to do whatever needs to be done to "store" the image in your application. That could mean something like:
Store the item in a folder on your web server
Store the item in a database
Store the item in an asset management system
...regardless of where you choose to store the image your image handler needs to return a single line of JSON telling TinyMCE the new location of the image. As referenced in the TinyMCE documentation this might look like:
{ location : '/uploaded/image/path/image.png' }
TinyMCE will then update the image's src attribute to the value you return. If you use the images_upload_base_path setting in the init that will be prepended to the returned location. The TinyMCE page has more details on all of this:
https://www.tinymce.com/docs/advanced/handle-async-image-uploads/
The net here is that TinyMCE knows when an embedded image exists in your content but it can't possibly know what to do with that image in the context of your application so that job (the "image handler") is something you must create.

Search customization for html documents in Alfresco

I have a set of html documents. According to the normal search, whenever a document is searched for, a set of relevant documents shows up, by clicking on which we are taken to the document details page. From this document details, we can do view in Browser. My clients want this search results link to take them directly to the View in Browser page, skipping the document details page for html documents. How can I achieve this?
I have a custom JavaScript which creates the html page. Can I modify the JS code, to produce this functionality?
Thanks in advance!
Assuming you are running a recent version of Alfresco, there is a hack and an proper way.
The code you want to tweak is in share/components/search/search.js.
renderCellDescription = function Search_renderCellDescription(elCell, oRecord, oColumn, oData)
{
// ...
// displayname and link to details page
var displayName = oRecord.getData("displayName");
var desc = '<h3 class="itemname">' + $html(displayName) + '';
// ...
}
For the proper way, try following http://blogs.alfresco.com/wp/developer/2012/05/22/customizing-share-javascript-widget-instantiation-part-1/
If this looks all Chinese to you, hack the file in place an keep a copy of the original. Drop the tweaked version in tomcat/shared/classes/components/search.
If you are not running a recent version of Alfresco, go staight for the hack.

Tridion 2009 SP1: Image Thumbnails - How to publish the original image as well?

I have a Dynamic Component Template which publishes XML to the Broker database which is then dynamically loaded using the Component Presentation factory.
This Xml contains URLs to Images. I need a thumbnail and a full image to be available. I have managed to use the Image Resizer TBB to produce the thumbnails however, I was hoping that this would add separate package items and binaries that could be referenced, but it seems to overwrite the full size images.
Is there a way I can get both into my Xml and the Package without writing my own custom TBB?
Tridion Content Delivery can store multiple variants of the same Multimedia Component. Each such variant has an ID that identifies it and the variant with no ID (of in newer versions #def# as its ID) is known as the default variant.
When you reference an image from a DWT, it is automatically added as an item to package when the render engine executes your DWT. This item is then later processed by the default "Publish Binaries in Package" TBB that is part of the Default Finish Actions. The Publish Binaries in Package TBB publishes binaries by calling AddBinary on them - you can verify this by looking at the original code for most default TBBs that was published on the Tridion forum here (login required).
appliedTemplateUri = new TcmUri(item.Properties[Item.ItemPropertyTemplateUri]);
...
engine.AddBinary(itemUri, appliedTemplateUri, targetStructureGroup,
data, fileName);
The AddBinary method that is called is defined in the TOM.NET CHM as:
public abstract string AddBinary(
TcmUri componentUri,
TcmUri templateUri,
TcmUri targetLocation,
byte[] data,
string fileName
)
componentUri
The multimedia component this item refers to
templateUri
The template in whose context this AddBinary call is executed (used as variant id)
targetLocation
The location to publish the binary to (if null, publish to standard path)
data
The binary data to publish
fileName
The filename to publish the file under
So as you can see in that last call to AddBinary, the Publish Binaries in Package TBB uses a property (look here if you've never heard of Item.Properties) to determine which variant to publish (and publishes the binary as the default variant if the property is not present).
With all this knowledge in hand, the task becomes quite simple: you have to ensure that there are two binary Items in the package for your MMC, each with a different value of the Item.ItemPropertyTemplateUri property.
The default Image Resizer TBB replaces the binary content of the Item it resizes and does not set this property. So the least code you'll have to write is either a pre-processor TBB that duplicates the item or a post-processor TBB that re-adds the item. In both cases the TBB will have to set the "magic" property too.
Useful links:
the original C# source code of the default template building blocks
a page describing Item.Properties and how to see what they do in your compound template
a recent post on the SDL Tridion forum about the same topic (login required)
Basically all the Image Resizer TBB does is resize the image already in package, so the Default Finish Actions TBBcan publish it (using an AddBinary() call).
So what you require is a slight change in the logic of the Resizer TBB (you need to do something yourself here), so that it does not resize the original item in the package, but publishes a variant of it. Then you have two images available on the delivery side (you can distinguish them by sending the resized image to a different structure group for instance).

User defined CSS / Styles

We are looking into providing users of our application the ability override the default site CSS.
Currently they can choose a site theme but it would be nice to allow them to change properties such as background color, font color, font face etc.
I'm torn between giving each site a "user defined" stylesheet that can be edited from the administration area or providing some kind of CSS builder.
The first option provides the most flexibility but could also be the most problematic and requires the user to have some basic understanding of CSS.
So aside from the obvious, (which is the best solution?) I have a few additional questions:
User Defined Css:
Is there a web based CSS editor available?
Is there a server side (.net) CSS validator available (for verifying the css the user enters)
Css Builder:
Is there a web based CSS builder already available?
What is the best way of generating the CSS based on the rules provided by the user (I thought about using some kind of templating engine to do this (NVelocity, Razor etc.)?
Thanks
Solution
I've added an answer below with the solution we went for.
however never used, recently I looked at Brosho Design in the Browser jQuery Plugin
With this Plugin you can style your
markup right in your browser with a
build-in element selector and CSS
editor. Generate the CSS code of
altered elements with one click and
use it in your own stylesheet.
demo here
I'd recommend to build a custom css editor since it's the easiest way to limit which elements and attributes the user will be able to edit / customize, and how. Just keep it simple and you will do just fine.
To validate CSS you could use the API of the W3 CSS Validator, http://jigsaw.w3.org/css-validator/api.html
I've built an application that does exactly this. It's a little more involved as there are multiple master pages and themes, and the user can attach custom urls to load themes - example: /someclienturl would load a specific theme.
Anyway, here's the schema I used. One thing I wish I added is the ability for power users to add custom styles to the stylesheet that's eventually written. Basically, a theme section would apply to a selector #header, for example. And ThemeSectionCssStyle holds user added customizations for that selector. If you have any more questions let me know. It ended up being a fairly involved sub-project. I'm curious to see what anyone else came up with.
I think the key factor here is whether you want your users to 'play with the codez'
If you do then something like this (posted by #Caspar) can be helpful in generating the css. If you do allow direct access to the css then the W3 CSS Validator (posted by #Trikks) is definitely necessary.
In my case I didn't want to provide direct access to the Css. Looking around at various sites that allow you to change simple style properties (background-color, font-face, color etc.) it seems that they have just created their own interfaces for this. There are plenty of javascript plugins around for making this process quite slick (color pickers etc.).
Once you have the styles stored somewhere you need some way of rendering them out.
I couldn't find any .net Css writers. I think it may be possible in Less but the solution was quite simple just using what's built into asp.net mvc.
I created a Css action result (courtesy of #Darin Dimitrov):
public class CssResult : PartialViewResult {
public override void ExecuteResult(ControllerContext context) {
context.HttpContext.Response.ContentType = "text/css";
base.ExecuteResult(context);
}
}
Then in my controller (a simple example):
[HttpGet]
public ActionResult Index()
{
var styles = new Dictionary<string, string>()
{
{ "color", "red" },
{ "font-family", "Consolas, Courier, Serif" },
{ "font-size" , "12px" }
};
return this.Css(styles);
}
Then my view (views/css/index.cshtml):
body {#foreach (var item in Model) {
#string.Format("{0}: {1};", item.Key, item.Value)
}
}
This will essentially render out the styles in the passed in dictionary. Of course you may want to create a specific class for holding these styles so that you could also specify the dom element name/class/id.
Finally to render out the stylesheet on our page we can call Url.Action("index", "css").

Resources