2014-03-30 92 views
1

我有Orchard CMS设置并正常工作。当使用Windows Live作家创建页面将其映射图像,像/媒体/默认/ WindowsLiveWriter文件夹如何更改Orchard CMS默认图像文件夹路径

如一个文件夹。 /Media/Default/WindowsLiveWriter/testpost-title_12A72/sample_image_2.jpg

我不希望我的网址有技术的具体章节,如“WindowsLiveWriter”

1)我怎样才能在果园1.7代码自定义此。我想有一个图像的URL结构像

/Media/Default/2014/March/02/sample_image_2.jpg或 /Media/Default/MyBlog/testpost-title_12A72/sample_image_2.jpg

2)在现场作家有一个选项来指定图像应该放在哪个文件夹?例如。使用日期作为子文件夹?

3)我可以更改元数据活写作者接收告诉它我的图像文件夹在哪里?

我搜索字符串WindowsLiveWriter(这是URL的一部分),但无法找到它的整个果园1.7的代码库。

回答

0

更改文件 的\ src \ Orchard.Web \模块\ Orchard.MediaLibrary \ SERVICES \ XmlRpcHandler.cs

如下。 有一个叫

private XRpcStruct MetaWeblogNewMediaObject(
       string userName, 
       string password, 
       XRpcStruct file, 
       UrlHelper url){ 

     } 

内,在开始响应发送到MS字博客模板活作家之前更改文件名的方法。

var name = file.Optional<string>("name"); 
    name = Path.GetFileName(name); 
    name = "images/"+DateTime.Now.Year+"/"+DateTime.Now.Month+"/" + name; 

完整的方法现在看起来像

public void Process(XmlRpcContext context) { 
     var urlHelper = new UrlHelper(context.ControllerContext.RequestContext, _routeCollection); 

    if (context.Request.MethodName == "metaWeblog.newMediaObject") { 
     var result = MetaWeblogNewMediaObject(
      Convert.ToString(context.Request.Params[1].Value), 
      Convert.ToString(context.Request.Params[2].Value), 
      (XRpcStruct)context.Request.Params[3].Value, 
      urlHelper); 
     context.Response = new XRpcMethodResponse().Add(result); 
    } 
} 

private XRpcStruct MetaWeblogNewMediaObject(
    string userName, 
    string password, 
    XRpcStruct file, 
    UrlHelper url) { 

    var user = _membershipService.ValidateUser(userName, password); 
    if (!_authorizationService.TryCheckAccess(Permissions.ManageMediaContent, user, null)) { 
     throw new OrchardCoreException(T("Access denied")); 
    } 

    var name = file.Optional<string>("name"); 

    name = Path.GetFileName(name); 
    name = "images/"+DateTime.Now.Year+"/"+DateTime.Now.Month+"/" + name; 

    var bits = file.Optional<byte[]>("bits"); 

    string directoryName = Path.GetDirectoryName(name); 
    if (string.IsNullOrWhiteSpace(directoryName)) { // Some clients only pass in a name path that does not contain a directory component. 
     directoryName = "media"; 
    } 

    try { 
     // delete the file if it already exists, e.g. an updated image in a blog post 
     // it's safe to delete the file as each content item gets a specific folder 
     _mediaLibraryService.DeleteFile(directoryName, Path.GetFileName(name)); 
    } 
    catch { 
     // current way to delete a file if it exists 
    } 

    string publicUrl = _mediaLibraryService.UploadMediaFile(directoryName, Path.GetFileName(name), bits); 
    _mediaLibraryService.ImportMedia(directoryName, Path.GetFileName(name)); 
    return new XRpcStruct() // Some clients require all optional attributes to be declared Wordpress responds in this way as well. 
     .Set("file", publicUrl) 
     .Set("url", url.MakeAbsolute(publicUrl)) 
     .Set("type", file.Optional<string>("type")); 
}