Show thumbnail of News Author in Sitefinty - thumbnails

I have crated 1 news item in Sitefinty news content section .How can i get Image of News Author in Sitefinty . I have uploaded my pic in my sitefinty profile and crated 1 news Item but no idea i have for display my image on the news detail page .I am using Sitefinty 6.3.

This will have to be a user control referenced from the news widget details template that looks up the profile that created the news post.
I've got a custom control in my solution at ~/CustomControls/AuthorPicture.ascx, in the ascx file its just a .net image control:
<asp:Image runat="server" ID="imgAuthor" />
In the code behind for the control, use this:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Sitefinity.Modules.Libraries;
using Telerik.Sitefinity.Modules.News;
using Telerik.Sitefinity.Security;
using Telerik.Sitefinity.Security.Model;
namespace SitefinityWebApp.CustomControls
{
public partial class AuthorPicture : System.Web.UI.UserControl
{
public Guid NewsId { get; set; }
protected void Page_Load(object sender, EventArgs e)
{
if (NewsId == Guid.Empty) return;
var newsManager = NewsManager.GetManager();
var newsItem = newsManager.GetNewsItems().FirstOrDefault(n => n.Id == NewsId);
if (newsItem == null) return;
var userManager = UserManager.GetManager();
var upManager = UserProfileManager.GetManager();
var owner = userManager.GetUser(newsItem.Owner);
var profile = upManager.GetUserProfile<SitefinityProfile>(owner);
var lmanager = LibrariesManager.GetManager();
var image = lmanager.GetImage(profile.Avatar.ChildItemId);
imgAuthor.ImageUrl = image.ThumbnailUrl;
}
}
}
You can see that we'll be passing in the news item id through the NewsId Guid property on the control.
To just show how this works, create a page in Sitefinity and add a News widget on to the page. Click "Edit" select "One particular news item" and select your news item. Under the "Single Item Settings" tab select your details template, the default name is "Full News Item". Click "Edit Selected Template" and register your control in the template:
<%# Register TagPrefix="custom" TagName="AuthorImage" Src="~/CustomControls/AuthorPicture.ascx" %>
Then somewhere in the RadListView itemTemplate, use the control and pass in the news Id to the property:
<custom:AuthorImage runat="server" ID="cstmAuthorImage" NewsId='<%# Eval("Id") %>' />
Save the changes and publish your page, your new control should be run, and it should pull the profile image of whoever created the post.
I found something similar in Sitefinity forums here: http://www.sitefinity.com/developer-network/forums/developing-with-sitefinity-/retrieving-post-author-details-avatar-nickname-etc-in-blog-post-templates

I would probably create a new template for the News detail. Inside here you can attach to the ItemDataBound event where you can set an image for the news item.
The Author field has no relation to a Sitefinity User, so you need to get the ID of the user that created the Newsitem. (the owner)
This code shows you how to do this:
protected void Repeater_ItemDataBound(object sender, Telerik.Web.UI.RadListViewItemEventArgs e) {
var data = ((RadListViewDataItem)e.Item).DataItem as NewsItem;
// Get the owner
var owner = userManager.GetUser(data .Owner);
}
The logic for retrieving a user and an image you can find in the code from Ben.
Another way would be to create a custom field which shows you a UserPicker field, which would then allow you to be completely flexible on choosing which Sitefinity User you will relate to a news item.

Related

Umbraco create link to another page

I have two views: order letter
localhost:64351/order-letter
localhost:64351/basket
Both have document type and content in backoffice. I want do in order-letter view button, when I click it I will redirect to basket and I want have available backoffice content. I try do sourface controller and return View
public class MainBasketSourfaceController : SurfaceController
{
public ActionResult Basket()
{
return View("~/Views/Basket.cshtml", new Models.UmbracoModels.BasketRenderModel(CurrentPage));
}
}
But this return error when I using
#CurrentPage
How I can do redirect?

Dynamically Add Item to DropDownList in a form

I have a question and maybe someone could help me find the best solution. I want a user to be able to add items to a drop down list dynamically in a form. I have a form with text boxes and drop down lists and want the user to be able to add items to the drop down list if they don't find it. I would make the drop down lists text boxes but I want to try and keep the names consistent. An example of a form would be have the user enter a name and then have drop down lists for colors and shapes. If the user does not see the color in the drop down I want them to be able to click a link next to the drop down and enter the name or the color. Another link to add shapes to the drop down list.
I'm trying to do this in an MVC Razor environment. I tried using partial views by having the link open a modal box of a partial view to enter the name, but then I have a form within a form and cannot submit the inner form. If I open a small window to enter the name then how do I add it back to the original parent window form without loosing what they already entered in the text box? I know there has to be a good solution out there.
If you want the users new input to be saved for later use, you could use Ajax to submit the new data into the database, and then have the controller return a partial view with your new dropdown.
So your dropdown would be an action Like this:
public PartialViewResult Dropdown()
{
var model = new DropdownModel()
{
Data = yourdata;
}
return PartialView("Dropdown.cshtml", model)
}
And your action to insert new data would look something like this:
public PartialViewResult AddDataToDropdown(string data)
{
var newDropdown = repository.AddData(data);
var model = new DropdownModel()
{
Data = newDropdown;
}
return PartialView("Dropdown.cshtml", model)
}
So bascially, you can resplace the HTML in the div that contains the dropdown with Ajax like this:
$(".someButton").on("click", function () {
var newData = ("$someTextbox").val();
$.ajax({
url: "/YourController/AddDataToDropdown",
type: "GET",
data: { data: newData}
})
.success(function (partialView) {
$(".someDiv").html(partialView);
});
});
This way you save the data and the dropdown is refreshed without refreshing the entire page

Magento: How to add the widget button to the WYSIWYG Products Editor

I want to allow adding the Catalog Product Link widget in the description field of a product (so I can easily link to other products in the description). I've already extended Mage_Catalog_Model_Product by creating a file like:
class mymodule_Catalog_Model_Product extends Mage_Catalog_Model_Product
{
/**
* Add getDescription function that interprets widget or static blocks
* within product descriptions
*/
public function getDescription() {
$processor = Mage::getModel('widget/template_filter');
$html = $processor->filter($this->getData('description'));
return $html;
}
}
Now it works fine if I type something like
{{widget type="catalog/product_widget_link" anchor_text="my text" template="catalog/product/widget/link/link_inline.phtml" id_path="product/1234"}}
into the description field -- it creates a link to the product Id 1234.
But I want to add the actual Catalog Product Link widget button in the WYSIWYG editor for editing a product. The button is already in the CMS editor, but I am missing what I need to modify in order to add this widget to the Admin interface for editing a product. Can someone help me out?
For anybody stumbling across this later on like myself, you can use the cms_wysiwyg_config_prepare event to set this to true.
E.G:
in config.xml
<events>
<cms_wysiwyg_config_prepare>
<observers>
<webtise_widgets>
<class>webtise_widgets/observer</class>
<method>cmsWysiwygConfigPrepare</method>
</webtise_widgets>
</observers>
</cms_wysiwyg_config_prepare>
</events>
In your observer
<?php class Webtise_Widgets_Model_Observer{
public function cmsWysiwygConfigPrepare(Varien_Event_Observer $observer){
$observer->getEvent()->getConfig()->setAddWidgets(true);
}
}
I was able to do this by overriding the core file
app/code/local/Mage/Adminhtml/Block/Catalog/Helper/Form/Wysiwyg/Content.php
and setting
$config['add_widgets'] = true;
Now the widget button shows up in all WYSIWIG editors in the admin interface.

Image, link and title for Facebook like button at the product list.

How can I display the right image, title and link for a Facebook Like button in a list of products?
I do implement sucessfully the like button but it is when you navigate to the product details, you see only one product.
I ask how can i do it in the list of products, for now the image displayed on my facebook page is a generic image from the site and not the specific image of the product, the link is right.
Must the tag <meta property="og:image" content="some value"/> only be inside the head tag? I cannot use it inside the body tag?
The meta tags for the news story don't need to be on the page that is displaying the Like button. The news story will be generated from the meta tags on the page listed in the URL parameter of the Like button.
Here is an example. -
This Repeater will dynamically generate a list of products from a database with customized Like buttons:
<asp:Repeater ID="_RPT_Product" runat="server">
<HeaderTemplate><h3>Products</h3><ul class="bulleted-list"></HeaderTemplate>
<ItemTemplate><li><%# Utilities.ScrubText(((Product)Container.DataItem).ProductName) %>
</li>
<div style="padding-top:10px;">
<iframe
src="https://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.yourdomainname.com/Product.aspx%3FID%3D<%#((Product)Container.DataItem).ProductID %>%26x%3D1&send=false&layout=button_count&width=88&show_faces=false&action=like&colorscheme=light&font&height=23"
scrolling="no" frameborder="0"
style="border:none; overflow:hidden; width:88px; height:23px;"
allowTransparency="true">
</iframe></div><br />
</ItemTemplate>
<FooterTemplate></ul></FooterTemplate>
</asp:Repeater>
This would be the code-behind on a separate Product page that dynamically renders meta tags from a product database:
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
// Get the product meta content from the ID URL parameter.
string productName = "";
string productImageURL = "";
string productDescription = "";
int productID = 0;
if (Request.QueryString["ID"] != null)
{
productID = Convert.ToInt32(Request.QueryString["ID"]);
}
if (Request.QueryString["ID"] != null)
{
using (ProductDatabaseDataContext db = new ProductDatabaseDataContext(Config.ConnectionStrings.ProductDatabase))
{
Product select = new Product();
select = db.Products.FirstOrDefault(p =>
p.ProductID == Convert.ToInt32(Request.QueryString["ID"]));
productName = select.ProductName;
productImageURL = select.ProductImageURL;
productDescription = select.ProductDescription;
}
}
// Dynamically generate Open Graph Meta Tags for each Product:
HtmlMeta _metaTitle = new HtmlMeta();
_metaTitle.Name = "og:title";
_metaTitle.Content = "Product: " + productName;
this.Header.Controls.Add(_metaTitle);
HtmlMeta _metaURL = new HtmlMeta();
_metaURL.Name = "og:url";
_metaURL.Content = "http://www.yourdomainname.com/Product.aspx?ID=" + Convert.ToString(productID);
this.Header.Controls.Add(_metaURL);
HtmlMeta _metaImage = new HtmlMeta();
_metaImage.Name = "og:image";
_metaImage.Content = Convert.ToString(productImageURL);
this.Header.Controls.Add(_metaImage);
HtmlMeta _metaDescription = new HtmlMeta();
_metaDescription.Name = "og:description";
_metaDescription.Content = Convert.ToString(productDescription);
this.Header.Controls.Add(_metaDescription);
}
}
Note that every Like button must have a unique URL parameter, because only one set of meta content attributes can be tied to a single URL. This can be accomplished by having a unique ID parameter on your separate Product.aspx page. The "og:url" meta tag for each of your products can be the same if you just want all of the product news stories to link back to one master list page.
The Like button likes a specific URL and if it's a product the user is liking, that link really should bring users back to a description of that product and not to a completely different set of content.
What you display on that propduct page itself isn't really important (it could be the full product list if you really wanted) provided that that URL returns the same meta tags to the Facebook crawler each time
What you're trying to do could be achieved by setting up a script which serves the meta tags for each product based on URL parameters (making sure to keep the og:url tags pointing to the correct URL to generate the same tags again.
Serve those tags to the Facebook crawler and redirect other browsers wherever you want.

Can i access masterpage dropdown value in controller action in asp.net mvc

I have a masterpage on which i displays groups that user can access now i want to gets its selected value in many controllers for saving with the records. I want to know if it is possible in asp.net mvc 2 and if not then what is the way around for it
What you are trying is possible and there are different techniques to achieve it. The best approach would depend on how you are invoking your controller actions. Whether you are using normal hyperlinks, submitting standard <form> or using AJAX. So if you are using standard action links you could add some javascript which binds to the onclick event of each link and adds the selected value of the group. Example:
$(function() {
$('a').click(function() {
// everytime a link is clicked
// add the value of the selected group to the url
var selectedGroup = $('#IdOfYourDdl').val();
if (this.href.indexOf('?') > 0) {
window.location = this.href + '&selectedGroup=' + selectedGroup;
} else {
window.location = this.href + '?selectedGroup=' + selectedGroup;
}
// cancel the default action as it doesn't contain the selectedGroup
// parameter in the request
return false;
});
});
and in your controller action you could have this additional parameter:
public ActionResult Foo(string selectedGroup)
{
...
}
Another example is if you use AJAX you could setup a default data in the master page which will ensure that the value of the dropdown will be sent along each AJAX request you are performing:
$.ajaxSetup({
data: { selectedGroup: $('#IdOfYourDdl').val() }
});
Now whenever you send an AJAX request to your server:
$.get('/foo', { someParam: 'someValue' }, function(result) {
});
the following request will be sent: /foo?someParam=someValue&selectedGroup=123 so you will be able to fetch the value of the selected group back in the controller action.
I hope I understand your question since no code-example is supplied.
You can do this using a viewmodel on the page which contains your display groups. Another option is to get the value from the FormCollection when the page is posted.
For example:
public ActionResult MyAction(MyViewmodel viewModel)
{
//value from your viewmodel, strongtype
var value = viewModel.group;
}
OR
public ActionResult MyAction(FormCollection collection)
{
//value as a string
var value = collection.getValue("MyKey").AttemptedValue;
}
If this answer doesn't statisfy you then please be more clear in your question and i'll try to help you further.
As long as your drop down list is a descendant of the <form> that is submitted, it will be subjected to standard model binding, which means you can include it as a parameter on your action. Ensure the name attribute of the drop down list matches the name of the action parameter.
Final rendered HTML:
<form action="http://.../MyAction" method="post">
<select name="dropDownList">
<option value="a">Option A</option>
<option value="b">Option B</option>
...
</select>
...
</form>
Controller:
[HttpPost]
public ActionResult MyAction(string dropDownList, MyActionModel model)
{
// dropDownList = value attribute of selected <option>
...
}