1

我有 Orchard CMS 设置并正常工作。当使用 windows live writer 创建页面时,它将图像映射到 /Media/Default/WindowsLiveWriter 文件夹等文件夹

例如。/Media/Default/WindowsLiveWriter/testpost-title_12A72/sample_image_2.jpg

我不希望我的网址包含诸如“WindowsLiveWriter”之类的技术特定部分

1)如何在 Orchard 1.7 代码中自定义它。我想要一个图像 url 结构,如

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

2) live writer 中是否有一个选项来指定应该将图像拖放到的文件夹?例如使用日期作为子文件夹?

3) 我可以更改实时作家收到的元数据以告诉它我的图像文件夹在哪里吗?

我在整个 Orchard 1.7 代码库中搜索了一个字符串 WindowsLiveWriter(它是 url 的一部分),但找不到它。

4

1 回答 1

0

更改文件 \src\Orchard.Web\Modules\Orchard.MediaLibrary\Services\XmlRpcHandler.cs

如下。有一种方法叫

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

        }

在将响应发送到现场作家的 MS Word 博客模板之前,在开头更改文件的名称。

    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"));
}
于 2014-03-30T23:43:18.097 回答