public DialogResult CreateContentFromFile(IWin32Window dialogOwner, ISmartContent content, string[] files, object context)
        {
            bool youtubeEnabled = MarketizationOptions.IsFeatureEnabled(MarketizationOptions.Feature.YouTubeVideo);

            if (!youtubeEnabled)
            {
                return(DialogResult.Cancel);
            }

            Trace.Assert(files.Length == 1, "Cannot insert more then 1 video at once through drag and drop.");

            IBlogContext blogContext = dialogOwner as IBlogContext;

            List <MediaTab> videoSources = new List <MediaTab>();

            videoSources.Add(new WebVideoSource());

            VideoPublishSource videoPublishSource = new VideoPublishSource(Options.GetString("Video.lastPermission", String.Empty));

            videoPublishSource.SelectedPath = files[0];
            videoSources.Add(videoPublishSource);

            VideoServiceVideoSource source = new VideoServiceVideoSource();

            source.RegisterServices(new IVideoService[] { new YouTubeVideoService() });

            videoSources.Add(source);

            return(CreateContentForm(dialogOwner, content, videoSources, 1));
        }
Example #2
0
        public override string GenerateEditorHtml(ISmartContent content, IPublishingContext publishingContext)
        {
            var settings = new Settings(content.Properties);

            // Always want to embed stylesheet for editor markup.
            return(settings.Format.FormatCode(settings.SourceCode, embedStylesheet: true, alternate: settings.HighlightAlternateLines, lineNumbers: settings.ShowLineNumbers));
        }
		public override DialogResult CreateContent(IWin32Window dialogOwner, ISmartContent newContent)
		{
			using (var contentForm = new ContentForm(newContent.Properties, Options))
			{
				return contentForm.ShowDialog(dialogOwner);
			}
		}
 public override void CreateContentFromUrl(string url, ref string title, ISmartContent content)
 {
     try
     {
         // download the video
         Video video = VideoProviderManager.FindVideo(url);
         if (video == null)
         {
             throw new ContentCreationException(
                       Res.Get(StringId.Plugin_Video_Cannot_Parse_Url),
                       Res.Get(StringId.Plugin_Video_Cannot_Parse_Url_Message));
         }
         VideoSmartContent vsc = new VideoSmartContent(content);
         vsc.Initialize(video, null);
     }
     catch (ContentCreationException)
     {
         throw;
     }
     catch (VideoPluginException ex)
     {
         throw new ContentCreationException(ex.Title, ex.Description);
     }
     catch (Exception ex)
     {
         VideoPluginUnexpectedException exception = new VideoPluginUnexpectedException(ex);
         throw new ContentCreationException(exception.Title, exception.Description);
     }
 }
        public override DialogResult CreateContent(IWin32Window dialogOwner, ISmartContent content)
        {
            using (new WaitCursor())
            {
                if (!MapForm.ValidateLiveLocalConnection(true))
                {
                    return(DialogResult.Cancel);
                }

                using (MapForm mapForm = new MapForm(true, _pluginOptions, ((ICommandManagerHost)dialogOwner).CommandManager))
                {
                    mapForm.LoadMap(-0.3515603f, 0.3515625f, null, "r", 1, null);
                    if (mapForm.ShowDialog(dialogOwner) == DialogResult.OK)
                    {
                        MapSettings settings = new MapSettings(content.Properties);
                        settings.MapId = "map-" + Guid.NewGuid().ToString();
                        settings.UpdateSettings(mapForm.Latitude, mapForm.Longitude, mapForm.Reserved, mapForm.ZoomLevel, mapForm.MapStyle, mapForm.Pushpins, mapForm.BirdseyeScene);
                        _pluginOptions.DefaultDialogSize = mapForm.Size;

                        return(DialogResult.OK);
                    }
                    else
                    {
                        return(DialogResult.Cancel);
                    }
                }
            }
        }
 public override void CreateContentFromUrl(string url, ref string title, ISmartContent content)
 {
     try
     {
         // download the video
         Video video = VideoProviderManager.FindVideo(url);
         if (video == null)
         {
             throw new ContentCreationException(
                 Res.Get(StringId.Plugin_Video_Cannot_Parse_Url),
                 Res.Get(StringId.Plugin_Video_Cannot_Parse_Url_Message));
         }
         VideoSmartContent vsc = new VideoSmartContent(content);
         vsc.Initialize(video, null);
     }
     catch (ContentCreationException)
     {
         throw;
     }
     catch (VideoPluginException ex)
     {
         throw new ContentCreationException(ex.Title, ex.Description);
     }
     catch (Exception ex)
     {
         VideoPluginUnexpectedException exception = new VideoPluginUnexpectedException(ex);
         throw new ContentCreationException(exception.Title, exception.Description);
     }
 }
        public override void OnResizeStart(ISmartContent content, ResizeOptions options)
        {
            //force the resize operation to scale based on the size of the map image.
            MapSettings settings = new MapSettings(content.Properties);

            options.ResizeableElementId = settings.MapId;
        }
        private string GenerateLink(ISmartContent smartContent, IPublishingContext publishingContext, out Position position)
        {
            position = Position.Footer;

            string culture = Thread.CurrentThread.CurrentCulture.Name;
            if (culture.Contains("-"))
                culture = culture.Replace("-", "_");

            var stringWriter = new StringWriter();
            stringWriter.WriteLine("<script type=\"text/javascript\">");

            stringWriter.WriteLine("var flattr_uid = '{0}';", _settings.FlattrId);
            stringWriter.WriteLine("var flattr_tle = '{0}';", publishingContext.PostInfo.Title);
            stringWriter.WriteLine("var flattr_dsc = '{0}';", publishingContext.PostInfo.Contents);
            stringWriter.WriteLine("var flattr_cat = 'text';");
            stringWriter.WriteLine("var flattr_lng = '{0}';", culture);
            stringWriter.WriteLine("var flattr_tag = '';");
            stringWriter.WriteLine("var flattr_url = '{0}';", publishingContext.PostInfo.Permalink);
            stringWriter.WriteLine("var flattr_hide = 'false';");

            if (_settings.CompactMode)
                stringWriter.WriteLine("var flattr_btn = 'compact';");

            stringWriter.WriteLine("</script>");
            stringWriter.WriteLine("<script type=\"text/javascript\" src=\"http://api.flattr.com/button/load.js\"></script>");

            return stringWriter.ToString();
        }
        public override DialogResult CreateContent(IWin32Window dialogOwner, ISmartContent content)
        {
            using (new WaitCursor())
            {
                if (!MapForm.ValidateLiveLocalConnection(true))
                    return DialogResult.Cancel;

                using (MapForm mapForm = new MapForm(true, _pluginOptions, ((ICommandManagerHost)dialogOwner).CommandManager))
                {
                    mapForm.LoadMap(-0.3515603f, 0.3515625f, null, "r", 1, null);
                    if (mapForm.ShowDialog(dialogOwner) == DialogResult.OK)
                    {
                        MapSettings settings = new MapSettings(content.Properties);
                        settings.MapId = "map-" + Guid.NewGuid().ToString();
                        settings.UpdateSettings(mapForm.Latitude, mapForm.Longitude, mapForm.Reserved, mapForm.ZoomLevel, mapForm.MapStyle, mapForm.Pushpins, mapForm.BirdseyeScene);
                        _pluginOptions.DefaultDialogSize = mapForm.Size;

                        return DialogResult.OK;
                    }
                    else
                    {
                        return DialogResult.Cancel;
                    }
                }
            }
        }
 public void CreateContentFromEmbed(string embed, ISmartContent content)
 {
     try
     {
         // download the video
         Video             video = VideoProviderManager.FindVideo(embed);
         VideoSmartContent vsc   = new VideoSmartContent(content);
         vsc.Initialize(video, null);
         if (video == null)
         {
             throw new ContentCreationException(
                       "Unable to Parse Video Embed", "Unknown provider or incomplete embed.");
         }
     }
     catch (ContentCreationException)
     {
         throw;
     }
     catch (VideoPluginException ex)
     {
         throw new ContentCreationException(ex.Title, ex.Description);
     }
     catch (Exception ex)
     {
         VideoPluginUnexpectedException exception = new VideoPluginUnexpectedException(ex);
         throw new ContentCreationException(exception.Title, exception.Description);
     }
 }
        public DialogResult CreateContentFromTabbedDialog(IWin32Window dialogOwner, ISmartContent content, int selectedTab)
        {
            bool youtubeEnabled = MarketizationOptions.IsFeatureEnabled(MarketizationOptions.Feature.YouTubeVideo);

            if (!youtubeEnabled)
            {
                return(DialogResult.Cancel);
            }

            IBlogContext blogContext = dialogOwner as IBlogContext;

            List <MediaTab> videoSources = new List <MediaTab>();

            videoSources.Add(new WebVideoSource());

            VideoPublishSource videoPublishSource = new VideoPublishSource(Options.GetString("Video.lastPermission", String.Empty));

            //videoPublishSource.SelectedPath = files[0];
            videoSources.Add(videoPublishSource);

            VideoServiceVideoSource source = new VideoServiceVideoSource();

            source.RegisterServices(new IVideoService[] { new YouTubeVideoService() });

            videoSources.Add(source);

            return(CreateContentForm(dialogOwner, content, videoSources, selectedTab));
        }
        public override void OnResizeComplete(ISmartContent content, Size newSize)
        {
            // access content object
            VideoSmartContent VideoContent = new VideoSmartContent(content);

            // update html size
            VideoContent.HtmlSize = newSize;
        }
        public override void OnResizeStart(ISmartContent content, ResizeOptions options)
        {
            // access content object
            VideoSmartContent VideoContent = new VideoSmartContent(content);

            // make sure we keep to the current aspect ratio
            options.AspectRatio = VideoContent.HtmlSize.Width / (double)VideoContent.HtmlSize.Height;
        }
        public override string GenerateEditorHtml(ISmartContent content, IPublishingContext publishingContext)
        {
            VideoSmartContent VideoContent = new VideoSmartContent(content);
            string            html         = VideoContent.GenerateEditorHtml(publishingContext);

            ((IInternalContent)content).RefreshCallback = VideoContent.GetRefreshCallback();
            return(html);
        }
 public InlineEditField(IHTMLElement element, ISmartContent smartContent, IHtmlEditorComponentContext editorContext, IHTMLElement smartContentElement, IUndoRedoExecutingChecker undoRedoCheck)
 {
     Debug.Assert(element != null, "Making an edit field with a null element.");
     _element = element;
     _smartContent = smartContent;
     _smartContentElement = smartContentElement;
     _editorContext = editorContext;
     _undoRedoCheck = undoRedoCheck;
 }
Example #16
0
 public InlineEditField(IHTMLElement element, ISmartContent smartContent, IHtmlEditorComponentContext editorContext, IHTMLElement smartContentElement, IUndoRedoExecutingChecker undoRedoCheck)
 {
     Debug.Assert(element != null, "Making an edit field with a null element.");
     _element             = element;
     _smartContent        = smartContent;
     _smartContentElement = smartContentElement;
     _editorContext       = editorContext;
     _undoRedoCheck       = undoRedoCheck;
 }
        public static void InsertEditorHtmlIntoElement(IContentSourceSidebarContext contentSourceContext, SmartContentSource source, ISmartContent sContent, IHTMLElement element)
        {
            string content = source.GenerateEditorHtml(sContent, contentSourceContext);

            // If the plugin returned null has the HTML it would like to insert, remove the element from the editor
            if (content == null)
                HTMLElementHelper.RemoveElement(element);
            else
                InsertContentIntoElement(content, sContent, contentSourceContext, element);
        }
Example #18
0
        public override string GeneratePublishHtml(IWin32Window dialogOwner, ISmartContent smartContent, IPublishingContext publishingContext, bool publish, out Position position)
        {
            if (string.IsNullOrEmpty(publishingContext.PostInfo.Permalink))
            {
                Debug.Fail("No permalink!");
                position = Position.Footer;
                return(string.Empty);
            }

            return(GenerateLink(publishingContext.PostInfo.Permalink, publishingContext.PostInfo.Title, out position));
        }
Example #19
0
        public override string GeneratePreviewHtml(ISmartContent smartContent, IPublishingContext publishingContext, out Position position)
        {
            string url = publishingContext.PostInfo.Permalink;

            if (string.IsNullOrEmpty(url))
            {
                url = DotNetShoutoutCounterGenerator.BaseUrl;
            }

            return(GenerateLink(url, publishingContext.PostInfo.Title, out position));
        }
Example #20
0
        private void MakeSmartContentEditable()
        {
            String newContentId = Guid.NewGuid().ToString();

            _smartContent   = _contentSourceContext.CloneSmartContent(_smartContentId, newContentId);
            _smartContentId = newContentId;
            Debug.Assert(_smartContent != null);
            _properties.SmartContentRaw      = _smartContent;
            _supportingFiles.SmartContentRaw = _smartContent;
            _layout.SmartContentRaw          = _smartContent;
        }
Example #21
0
 public override string GeneratePublishHtml(ISmartContent content, IPublishingContext publishingContext)
 {
     if (!content.Properties.Contains("html"))
     {
         content.Properties["html"] = GenerateHtml(
             content.Properties["code"],
             content.Properties["language"],
             content.Properties["style"]);
     }
     return(content.Properties["html"]);
 }
        private string GenerateHtml(ISmartContent content, bool editor, string blogId)
        {
            MapSettings settings = new MapSettings(content.Properties);

            settings.PublishTargetId = blogId;

            Uri imageUri = content.Files.GetUri(settings.ImageFileId);

            if (imageUri == null)
            {
                //try to regenerate the image using the default size for blog
                Size mapSize = _pluginOptions.GetDefaultMapSize(blogId);
                UpdateMapImage(content, settings, mapSize);
                settings.Size = mapSize;

                imageUri = content.Files.GetUri(settings.ImageFileId);
            }

            string imgAltText = Res.Get(StringId.MapImageAltText);

            if (settings.Caption != String.Empty)
            {
                imgAltText = settings.Caption;
            }

            string imageHtml = settings.Caption;

            if (imageUri != null)
            {
                Size   mapSize   = settings.Size;
                string sizeAttrs = mapSize != Size.Empty
                                                        ? String.Format(CultureInfo.InvariantCulture, " width=\"{0}\" height=\"{1}\"", mapSize.Width, mapSize.Height) : "";
                imageHtml = String.Format(CultureInfo.InvariantCulture, "<img src=\"{0}\"{1} alt=\"{2}\">", HtmlServices.HtmlEncode(imageUri.ToString()), sizeAttrs, HtmlServices.HtmlEncode(imgAltText));
            }
            else
            {
                if (imageHtml.Equals(String.Empty))
                {
                    imageHtml = Res.Get(StringId.ViewMap);
                }
            }

            string clickToViewAttr = editor ? "" : String.Format(CultureInfo.InvariantCulture, " alt=\"{0}\" title=\"{0}\"", clickToViewText);
            string mapHtml         = String.Format(CultureInfo.InvariantCulture, "<a href=\"{0}\" id=\"{2}\"{3}>{1}</a>",
                                                   HtmlServices.HtmlEncode(settings.LiveMapUrl), imageHtml, settings.MapId, clickToViewAttr);

            if (imageUri != null && settings.Caption != String.Empty)
            {
                //append the caption HTML
                mapHtml += String.Format(CultureInfo.InvariantCulture, _pluginOptions.CaptionHtmlFormat, HtmlServices.HtmlEncode(settings.Caption), settings.MapId);
            }
            return(mapHtml);
        }
		/// <summary>
		/// Resize started
		/// </summary>
		/// <param name="content"></param>
		/// <param name="options"></param>
		public override void OnResizeStart(ISmartContent content, ResizeOptions options)
		{
			// Check if we have editor mode element ID
			if (content.Properties.Contains(_elementIdProperty))
			{
				string elementId = content.Properties.GetString(_elementIdProperty, null);
				if (elementId != null)
				{
					options.ResizeableElementId = elementId;
				}
			}
		}
        public override void OnResizeComplete(ISmartContent content, Size newSize)
        {
            //don't allow the size to be smaller than the min size (fixes bug 398580)
            newSize.Width = Math.Max(newSize.Width, MIN_MAP_SIZE.Width);
            newSize.Height = Math.Max(newSize.Height, MIN_MAP_SIZE.Height);

            MapSettings settings = new MapSettings(content.Properties);
            UpdateMapImage(content, settings, newSize);
            settings.Size = newSize;

            if (settings.PublishTargetId != null)
                _pluginOptions.SetDefaultMapSize(settings.PublishTargetId, newSize);
        }
Example #25
0
        /// <summary>
        /// Clones active smart content contained in the provided HTML, and disables unknown smart content.
        /// </summary>
        public static string PrepareSmartContentHtmlForEditorInsertion(string html, IContentSourceSidebarContext sourceContext)
        {
            StringBuilder output = new StringBuilder();

            ContentSourceManager.SmartContentPredicate predicate = new ContentSourceManager.SmartContentPredicate();
            SimpleHtmlParser p = new SimpleHtmlParser(html);

            for (Element el; null != (el = p.Next());)
            {
                if (predicate.IsMatch(el))
                {
                    BeginTag bt     = el as BeginTag;
                    Attr     idAttr = bt.GetAttribute("id");

                    String contentSourceId, contentItemId;
                    ContentSourceManager.ParseContainingElementId(idAttr.Value, out contentSourceId, out contentItemId);
                    ISmartContent smartContent = sourceContext.FindSmartContent(contentItemId);
                    if (smartContent != null)
                    {
                        String newId = Guid.NewGuid().ToString();
                        sourceContext.CloneSmartContent(contentItemId, newId);

                        if (RefreshableContentManager.ContentSourcesWithRefreshableContent.Contains(contentSourceId))
                        {
                            IExtensionData extensionData = sourceContext.FindExtentsionData(newId);
                            Debug.Assert(extensionData != null);

                            // Since we just made a new id for the smart content just about to be inserted
                            // we want to give it a chance to get a callback because its callback might have happened while
                            // it was on the clipboard(in the event of cut).  This means the refreshable content manager doesnt know
                            // to watch out for this smart content on paste, it only knows to look out for who created it.   Thus
                            // we just force the callback, and if it didnt need it, nothing will happen.
                            if (extensionData.RefreshCallBack == null)
                            {
                                extensionData.RefreshCallBack = DateTime.UtcNow;
                            }
                        }


                        idAttr.Value = ContentSourceManager.MakeContainingElementId(contentSourceId, newId);
                    }
                    else
                    {
                        ContentSourceManager.RemoveSmartContentAttributes(bt);
                    }
                }
                output.Append(el.ToString());
            }
            return(output.ToString());
        }
        /*public override DialogResult CreateContent(IWin32Window dialogOwner, ref string newContent)
        {
            var insertForm = new InsertCodeInsertForm();

            using (insertForm)
            {
                var result = insertForm.ShowDialog();

                if (result == DialogResult.OK)
                {
                    newContent = insertForm.Code;
                }

                return result;
            }
        }*/
        public override DialogResult CreateContent(IWin32Window dialogOwner, ISmartContent newContent)
        {
            var settings = new Settings(newContent.Properties);

            using (var insertForm = new InsertCodeInsertForm()) {
                var result = insertForm.ShowDialog();

                if (result == DialogResult.OK) {
                    settings.UpdateFromForm(insertForm);
                }

                return result;
            }
        }
Example #27
0
        /*public override DialogResult CreateContent(IWin32Window dialogOwner, ref string newContent)
         * {
         *      var insertForm = new InsertCodeInsertForm();
         *
         *      using (insertForm)
         *      {
         *              var result = insertForm.ShowDialog();
         *
         *              if (result == DialogResult.OK)
         *              {
         *                      newContent = insertForm.Code;
         *              }
         *
         *              return result;
         *      }
         * }*/

        public override DialogResult CreateContent(IWin32Window dialogOwner, ISmartContent newContent)
        {
            var settings = new Settings(newContent.Properties);

            using (var insertForm = new InsertCodeInsertForm()) {
                var result = insertForm.ShowDialog();

                if (result == DialogResult.OK)
                {
                    settings.UpdateFromForm(insertForm);
                }

                return(result);
            }
        }
        private string GenerateHtml(ISmartContent content, bool editor, string blogId)
        {
            MapSettings settings = new MapSettings(content.Properties);
            settings.PublishTargetId = blogId;

            Uri imageUri = content.Files.GetUri(settings.ImageFileId);

            if (imageUri == null)
            {
                //try to regenerate the image using the default size for blog
                Size mapSize = _pluginOptions.GetDefaultMapSize(blogId);
                UpdateMapImage(content, settings, mapSize);
                settings.Size = mapSize;

                imageUri = content.Files.GetUri(settings.ImageFileId);
            }

            string imgAltText = Res.Get(StringId.MapImageAltText);
            if (settings.Caption != String.Empty)
                imgAltText = settings.Caption;

            string imageHtml = settings.Caption;
            if (imageUri != null)
            {
                Size mapSize = settings.Size;
                string sizeAttrs = mapSize != Size.Empty
                                       ? String.Format(CultureInfo.InvariantCulture, " width=\"{0}\" height=\"{1}\"", mapSize.Width, mapSize.Height) : "";
                imageHtml = String.Format(CultureInfo.InvariantCulture, "<img src=\"{0}\"{1} alt=\"{2}\">", HtmlServices.HtmlEncode(imageUri.ToString()), sizeAttrs, HtmlServices.HtmlEncode(imgAltText));
            }
            else
            {
                if (imageHtml.Equals(String.Empty))
                {
                    imageHtml = Res.Get(StringId.ViewMap);
                }
            }

            string clickToViewAttr = editor ? "" : String.Format(CultureInfo.InvariantCulture, " alt=\"{0}\" title=\"{0}\"", clickToViewText);
            string mapHtml = String.Format(CultureInfo.InvariantCulture, "<a href=\"{0}\" id=\"{2}\"{3}>{1}</a>",
                HtmlServices.HtmlEncode(settings.LiveMapUrl), imageHtml, settings.MapId, clickToViewAttr);
            if (imageUri != null && settings.Caption != String.Empty)
            {
                //append the caption HTML
                mapHtml += String.Format(CultureInfo.InvariantCulture, _pluginOptions.CaptionHtmlFormat, HtmlServices.HtmlEncode(settings.Caption), settings.MapId);
            }
            return mapHtml;
        }
Example #29
0
        public EditableSmartContent(IContentSourceSidebarContext context, SmartContentSource contentSource, IHTMLElement smartContentElement)
        {
            GC.SuppressFinalize(this);
            _contentSourceContext = context;
            _contentSource        = contentSource;
            _smartContentElement  = smartContentElement;

            ContentSourceManager.ParseContainingElementId(_smartContentElement.id, out _contentSourceId, out _smartContentId);

            _smartContent  = _contentSourceContext.FindSmartContent(_smartContentId);
            _extensionData = _contentSourceContext.FindExtentsionData(_smartContentId);

            _properties      = new EditableRootProperties();
            _layout          = new EditableLayoutStyle();
            _supportingFiles = new EditableSupportingFiles();
            MakeSmartContentEditable();
        }
        public EditableSmartContent(IContentSourceSidebarContext context, SmartContentSource contentSource, IHTMLElement smartContentElement)
        {
            GC.SuppressFinalize(this);
            _contentSourceContext = context;
            _contentSource = contentSource;
            _smartContentElement = smartContentElement;

            ContentSourceManager.ParseContainingElementId(_smartContentElement.id, out _contentSourceId, out _smartContentId);

            _smartContent = _contentSourceContext.FindSmartContent(_smartContentId);
            _extensionData = _contentSourceContext.FindExtentsionData(_smartContentId);

            _properties = new EditableRootProperties();
            _layout = new EditableLayoutStyle();
            _supportingFiles = new EditableSupportingFiles();
            MakeSmartContentEditable();
        }
Example #31
0
        public override DialogResult CreateContent(IWin32Window dialogOwner, ISmartContent newContent)
        {
            var form   = new CodeInsertForm();
            var result = form.ShowDialog(dialogOwner);

            if (result == DialogResult.OK)
            {
                if (form.Code.Trim().Length == 0)
                {
                    return(DialogResult.Cancel);
                }

                newContent.Properties["code"] = form.Code;
            }

            return(result);
        }
        internal static void UpdateMapImage(ISmartContent content, MapSettings settings, Size newSize)
        {
            if (settings.MapImageInvalidated)
            {
                settings.MapImageInvalidated = false;
                float           latitude   = settings.Latitude;
                float           longitude  = settings.Longitude;
                string          reserved   = settings.Reserved;
                int             zoomLevel  = settings.ZoomLevel;
                string          style      = settings.MapStyle;
                string          sceneId    = settings.BirdseyeSceneId;
                VEBirdseyeScene scene      = sceneId != null ? new VEBirdseyeScene(sceneId, settings.BirdseyeOrientation) : null;
                string          previewUrl = MapUrlHelper.CreateMapUrl(LocalMapPreviewUrl, latitude, longitude, reserved, style, zoomLevel, settings.Pushpins, scene);

#pragma warning disable 612,618
                HtmlScreenCapture screenCapture = new HtmlScreenCapture(new Uri(previewUrl, true), newSize.Width);
#pragma warning restore 612,618

                screenCapture.HtmlDocumentAvailable += new OpenLiveWriter.Api.HtmlDocumentAvailableHandler(screenCapture_HtmlDocumentAvailable);
                screenCapture.MaximumHeight          = newSize.Height;
                Bitmap bitmap = screenCapture.CaptureHtml(45000);
                if (bitmap != null)
                {
                    try
                    {
                        if (content.Files.Contains(settings.ImageFileId))
                        {
                            content.Files.Remove(settings.ImageFileId);
                        }
                    }
                    catch (Exception e) { Debug.Fail(e.ToString()); }

                    //add the new map image (note that we use a new name to a bug in IE7 that prevents the editor
                    //from refreshing the image displayed in the browser (bug 287563)
                    string newGuid        = Guid.NewGuid().ToString();
                    string newImageFileId = "map-" + newGuid.Substring(newGuid.LastIndexOf("-", StringComparison.OrdinalIgnoreCase) + 1) + ".jpg";
                    settings.ImageFileId = newImageFileId;
                    content.Files.AddImage(settings.ImageFileId, bitmap, ImageFormat.Jpeg);
                }
                else
                {
                    Debug.WriteLine("Map image could not be regenerated.");
                }
            }
        }
        public static bool ExecuteSmartContentRetreival(
            IWin32Window dialogOwner, ContentSourceInfo contentSourceInfo, string url, ref string title, ISmartContent newContent)
        {
            try
            {
                if (contentSourceInfo.UrlContentSourceRequiresProgress)
                {
                    // create the progress dialog and the async operation
                    UrlContentRetreivalWithProgressDialog progressDialog = new UrlContentRetreivalWithProgressDialog(contentSourceInfo);
                    progressDialog.CreateControl();

                    SmartUrlContentRetreivalAsyncOperation asyncOperation = new SmartUrlContentRetreivalAsyncOperation(progressDialog, contentSourceInfo.Instance as SmartContentSource, url, title, newContent);

                    // execute and retreive results
                    if (ExecuteWithProgress(dialogOwner, progressDialog, asyncOperation, contentSourceInfo))
                    {
                        title = asyncOperation.Title;
                        return true;
                    }
                    else
                    {
                        return false;
                    }
                }
                else
                {
                    try
                    {
                        (contentSourceInfo.Instance as SmartContentSource).CreateContentFromUrl(url, ref title, newContent);
                        return true;
                    }
                    catch (Exception ex)
                    {
                        ContentSourceManager.DisplayContentRetreivalError(dialogOwner, ex, contentSourceInfo);
                        return false;
                    }
                }

            }
            catch (Exception ex)
            {
                Trace.Fail("Unexpected exception executing network operation for content source: " + ex.ToString());
                return false;
            }
        }
Example #34
0
        public override System.Windows.Forms.DialogResult CreateContent(System.Windows.Forms.IWin32Window dialogOwner, ISmartContent newContent)
        {
            using (var form = new frmEdit())
            {
                if (Clipboard.ContainsText())
                {
                    form.Editor.ContentText = Clipboard.GetText();
                }
                DialogResult res = form.ShowDialog();
                if (res == DialogResult.OK)
                {
                    newContent.Properties.SetString("code", form.Editor.ContentText);
                    newContent.Properties.SetString("class", form.Editor.CssClass);
                }

                return res;
            }
        }
        public override DialogResult CreateContent(IWin32Window dialogOwner, ISmartContent newContent)
        {
            IBlogContext blogContext = dialogOwner as IBlogContext;
            if (blogContext != null)
                _currentBlogId = blogContext.CurrentAccountId;

            TagContext context = new TagContext(newContent, Options, _currentBlogId);
            using (TagForm form = new TagForm(context))
            {
                DialogResult result = form.ShowDialog(dialogOwner);
                if (result == DialogResult.OK)
                {
                    context.Tags = form.Tags;
                    context.CurrentProvider = form.TagProvider;
                    context.AddTagsToHistory(form.Tags);
                }
                return result;
            }
        }
        public override DialogResult CreateContent(IWin32Window dialogOwner, ISmartContent content)
        {
            IBlogContext blogContext = dialogOwner as IBlogContext;

            List <MediaTab> videoSources = new List <MediaTab>();

            videoSources.Add(new WebVideoSource());

            bool youtubeEnabled = MarketizationOptions.IsFeatureEnabled(MarketizationOptions.Feature.YouTubeVideo);

            if (youtubeEnabled)
            {
                videoSources.Add(new VideoPublishSource(Options.GetString("Video.lastPermission", String.Empty)));

                VideoServiceVideoSource source = new VideoServiceVideoSource();
                source.RegisterServices(new IVideoService[] { new YouTubeVideoService() });

                videoSources.Add(source);
            }

            return(CreateContentForm(dialogOwner, content, videoSources, 0));
        }
        public override DialogResult CreateContent(IWin32Window dialogOwner, ISmartContent content)
        {
            IBlogContext blogContext = dialogOwner as IBlogContext;

            List<MediaTab> videoSources = new List<MediaTab>();

            videoSources.Add(new WebVideoSource());

            bool youtubeEnabled = MarketizationOptions.IsFeatureEnabled(MarketizationOptions.Feature.YouTubeVideo);

            if (youtubeEnabled)
            {
                videoSources.Add(new VideoPublishSource(Options.GetString("Video.lastPermission", String.Empty)));

                VideoServiceVideoSource source = new VideoServiceVideoSource();
                source.RegisterServices(new IVideoService[] { new YouTubeVideoService() });

                videoSources.Add(source);
            }

            return CreateContentForm(dialogOwner, content, videoSources, 0);
        }
        public override DialogResult CreateContent(IWin32Window dialogOwner, ISmartContent newContent)
        {
            IBlogContext blogContext = dialogOwner as IBlogContext;

            if (blogContext != null)
            {
                _currentBlogId = blogContext.CurrentAccountId;
            }

            TagContext context = new TagContext(newContent, Options, _currentBlogId);

            using (TagForm form = new TagForm(context))
            {
                DialogResult result = form.ShowDialog(dialogOwner);
                if (result == DialogResult.OK)
                {
                    context.Tags            = form.Tags;
                    context.CurrentProvider = form.TagProvider;
                    context.AddTagsToHistory(form.Tags);
                }
                return(result);
            }
        }
        private DialogResult CreateContentForm(IWin32Window dialogOwner, ISmartContent content, List <MediaTab> videoSources, int selectedTab)
        {
            using (new WaitCursor())
            {
                IBlogContext      blogContext       = dialogOwner as IBlogContext;
                VideoSmartContent videoSmartContent = new VideoSmartContent(content);
                using (MediaInsertForm videoBrowserForm = new MediaInsertForm(videoSources, blogContext.CurrentAccountId, selectedTab, videoSmartContent, Res.Get(StringId.Plugin_Videos_Select_Video_Form), true))
                {
                    if (videoBrowserForm.ShowDialog(dialogOwner) == DialogResult.OK)
                    {
                        string VIDEO_LAST_PERMISSION = "Video.lastPermission";
                        Options.SetString(VIDEO_LAST_PERMISSION, videoSmartContent.Permission);

                        videoBrowserForm.SaveContent(videoSmartContent);

                        return(DialogResult.OK);
                    }
                    else
                    {
                        return(DialogResult.Cancel);
                    }
                }
            }
        }
        public static void InsertContentIntoElement(string content, ISmartContent sContent, IContentSourceSidebarContext contentSourceContext, IHTMLElement element)
        {
            MshtmlMarkupServices MarkupServices = new MshtmlMarkupServices((IMarkupServicesRaw)element.document);

            //Note: undo/redo disabled for smart content since undo causes the HTML to get out of sync
            //with the inserter's settings state, so undo changes will be blown away the next time the
            //the inserter's HTML is regenerated.  Also note that making this insertion without wrapping it
            //in an undo clears the undo/redo stack, which is what we want for beta.
            //string undoId = Guid.NewGuid().ToString();

            MarkupRange htmlRange = MarkupServices.CreateMarkupRange(element, false);

            htmlRange.Start.PushCling(true);
            htmlRange.End.PushCling(true);
            MarkupServices.Remove(htmlRange.Start, htmlRange.End);
            htmlRange.Start.PopCling();
            htmlRange.End.PopCling();

            element.style.padding = ToPaddingString(sContent.Layout);

            if (sContent.Layout.Alignment == Alignment.None ||
                sContent.Layout.Alignment == Alignment.Right ||
                sContent.Layout.Alignment == Alignment.Left)
            {
                element.style.display     = "inline";
                element.style.marginLeft  = "0px";
                element.style.marginRight = "0px";
                element.style.styleFloat  = sContent.Layout.Alignment.ToString().ToLower(CultureInfo.InvariantCulture);
            }
            else if (sContent.Layout.Alignment == Alignment.Center)
            {
                element.style.styleFloat  = Alignment.None.ToString().ToLower(CultureInfo.InvariantCulture);
                element.style.display     = "block";
                element.style.marginLeft  = "auto";
                element.style.marginRight = "auto";
            }

            // Clear out any width on the overall smart content block, if the element is centered, we will add the width back in later
            // after we calcuate it from the childern, the current width value is stale.
            element.style.width = "";

            //Note: we use MarkupServices to insert the content so that IE doesn't try to fix up URLs.
            //Element.insertAdjacentHTML() is a no-no because it rewrites relaive URLs to include
            //the fullpath from the local filesytem.

            //MarkupServices.ParseString() doesn't attempt to fix up URLs, so its safe to use.
            //We will now stage the new content into a MarkupContainer, and then move it into
            //the working document.
            MarkupPointer sc1 = MarkupServices.CreateMarkupPointer();
            MarkupPointer sc2 = MarkupServices.CreateMarkupPointer();

            //Create a temporary document from the html and set the start/end pointers to the
            //start and end of the document.
            MarkupServices.ParseString(content, sc1, sc2);
            IHTMLDocument2 doc          = sc1.GetDocument();
            MarkupRange    stagingRange = MarkupServices.CreateMarkupRange(sc1, sc2);

            stagingRange.MoveToElement(doc.body, false);

            //IE7 hack: fixes bug 305512.  Note that this will destroy the inner content of the element,
            //so make sure it is called before the refreshed content is inserted.
            BeforeInsertInvalidateHackForIE7(element);

            //move the content from the staging area into the actual insertion point.
            MarkupServices.Move(stagingRange.Start, stagingRange.End, htmlRange.End);

            if (sContent.Layout.Alignment == Alignment.Center)
            {
                MarkupContext mc    = htmlRange.End.Right(false);
                MarkupRange   range = MarkupServices.CreateMarkupRange(mc.Element, false);

                IHTMLElement[] childern = range.GetTopLevelElements(MarkupRange.FilterNone);

                int maxWidth = 0;
                foreach (IHTMLElement child in childern)
                {
                    maxWidth = Math.Max(maxWidth, child.offsetWidth);
                }

                if (maxWidth != 0)
                {
                    mc.Element.style.width = maxWidth;
                }
            }

            // Let the context provider know the smart content was edited.
            string contentSourceId, contentId;

            ContentSourceManager.ParseContainingElementId(element.id, out contentSourceId, out contentId);
            contentSourceContext.OnSmartContentEdited(contentId);
        }
        public static void InsertEditorHtmlIntoElement(IContentSourceSidebarContext contentSourceContext, SmartContentSource source, ISmartContent sContent, IHTMLElement element)
        {
            string content = source.GenerateEditorHtml(sContent, contentSourceContext);

            // If the plugin returned null has the HTML it would like to insert, remove the element from the editor
            if (content == null)
            {
                HTMLElementHelper.RemoveElement(element);
            }
            else
            {
                InsertContentIntoElement(content, sContent, contentSourceContext, element);
            }
        }
        public static string GenerateBlock(string className, string elementId, ISmartContent sContent, bool displayInline, string content, bool noFloat, IHTMLElement element)
        {
            if (string.IsNullOrEmpty(content))
            {
                return("");
            }

            // generate the html to insert
            StringBuilder htmlBuilder = new StringBuilder();

            htmlBuilder.AppendFormat("<div class=\"{0}\"", className);
            if (!string.IsNullOrEmpty(elementId))
            {
                htmlBuilder.AppendFormat(" id=\"{0}\"", elementId);
            }

            if (element != null)
            {
                // Persist the language direction of the smart content if it's explicitly set.
                string currentDirection = element.getAttribute("dir", 2) as string;
                if (!String.IsNullOrEmpty(currentDirection))
                {
                    htmlBuilder.AppendFormat(" dir=\"{0}\"", currentDirection);
                }
            }

            StringBuilder styleBuilder = new StringBuilder();

            if (sContent.Layout.Alignment == Alignment.None ||
                sContent.Layout.Alignment == Alignment.Right ||
                sContent.Layout.Alignment == Alignment.Left)
            {
                // If the smart content is none/right/left we just use float
                if (!noFloat || sContent.Layout.Alignment != Alignment.None)
                {
                    AppendStyle(noFloat ? "text-align" : "float",
                                sContent.Layout.Alignment.ToString().ToLower(CultureInfo.InvariantCulture),
                                styleBuilder);
                }
            }
            else if (element != null && sContent.Layout.Alignment == Alignment.Center)
            {
                // If the alignment is centered then it needs to make sure float is set to none
                AppendStyle("float", "none", styleBuilder);
                AppendStyle("display", "block", styleBuilder);
                AppendStyle("margin-left", "auto", styleBuilder);
                AppendStyle("margin-right", "auto", styleBuilder);
                AppendStyle("width", element.offsetWidth.ToString(CultureInfo.InvariantCulture), styleBuilder);
            }

            if (displayInline && sContent.Layout.Alignment != Alignment.Center)
            {
                AppendStyle("display", "inline", styleBuilder);
            }

            if (sContent.Layout.Alignment != Alignment.Center)
            {
                AppendStyle("margin", "0px", styleBuilder);
            }

            AppendStyle("padding", ToPaddingString(sContent.Layout), styleBuilder);

            if (styleBuilder.Length > 0)
            {
                htmlBuilder.AppendFormat(" style=\"{0}\"", styleBuilder.ToString());
            }

            htmlBuilder.AppendFormat(">{0}</div>", content);

            return(htmlBuilder.ToString());
        }
        public static string GenerateContentBlock(string contentSourceId, string blockId, string content, ISmartContent sContent, IHTMLElement element)
        {
            string className = ContentSourceManager.EDITABLE_SMART_CONTENT;
            string elementId = ContentSourceManager.MakeContainingElementId(contentSourceId, blockId);
            bool   inline    = true;

            return(GenerateBlock(className, elementId, sContent, inline, content, false, element));
        }
 /// <summary>
 /// Notification that the sizing of an object is complete. The  implementation of
 /// this method should update the ISmartContent object as approriate based on the
 /// new size. The editor will first call this method and then call the GenerateEditorHtml
 /// method to update the display based on the new size.
 /// </summary>
 /// <param name="content">SmartContent which is being resized.</param>
 /// <param name="newSize">New size of object (or of resizable element if the ResizeOptions.ResizableElementId option was specified).</param>
 public virtual void OnResizeComplete(ISmartContent content, Size newSize)
 {
 }
 /// <summary>
 /// Create content based on a URL. The source of this URL can either be the page the user was
 /// navigated to when they pressed the "Blog This" button or a URL that is pasted or dragged
 /// into the editor. Plugin classes which override this method must also be declared with the
 /// UrlContentSourceAttribute.
 /// </summary>
 /// <param name="url">Url to create content from.</param>
 /// <param name="title">Default title of post (used for "Blog This" case).</param>
 /// <param name="newContent">SmartContent object which is populated with initial values by this method.</param>
 /// <exception cref="ContentCreationException">Thrown if an error occurs during the creation of content.</exception>
 public virtual void CreateContentFromUrl(string url, ref string title, ISmartContent newContent)
 {
     throw new NotImplementedException("SmartContentSource.CreateContentFromUrl");
 }
 /// <summary>
 /// Generate the HTML content which is published to the destination weblog.
 /// </summary>
 /// <param name="content">SmartContent object to generate HTML for.</param>
 /// <param name="publishingContext">Publishing context for HTML generation.</param>
 /// <returns>HTML to be published to the destination weblog.</returns>
 public abstract string GeneratePublishHtml(ISmartContent content, IPublishingContext publishingContext);
 public SmartContentPersistedFileList(ISmartContent smartContent, string listId)
 {
     this.smartContent = smartContent;
     this.listId = listId;
 }
 /// <summary>
 /// Notification of realtime resizing of the object (this will only be called if the
 /// ResizeCapabilities include RealtimeResizing). The implementation of this method
 /// should update the ISmartContent object as appropriate based on the new size.
 /// The editor will first call this method and then call the GenerateEditorHtml
 /// method to update the display as the user resizes.
 /// </summary>
 /// <param name="content">SmartContent which is being resized.</param>
 /// <param name="newSize">New size of object (or of resizable element if the ResizeOptions.ResizableElementId option was specified).</param>
 public virtual void OnResizing(ISmartContent content, Size newSize)
 {
 }
            internal void DoPublishWork(IPublishingContext site, SmartContentSource source, ISmartContent sContent, ref string content)
            {
                if (source is IPublishTimeWorker)
                {
                    try
                    {
                        // For each piece of IPublishTimeWorker smart content we find we need to ask if it has
                        // work to do while publishing.  We pass null as the external context because that object
                        // is only for use when providing external code a chance to interact with the publish.
                        content = ((IPublishTimeWorker)source).DoPublishWork(_form, sContent, _blog.Id, site, null);

                    }
                    catch (WebException ex)
                    {
                        HttpRequestHelper.LogException(ex);
                        _exception = ex;
                        throw;
                    }
                    catch (Exception ex)
                    {
                        Trace.WriteLine("Content Source failed to do publish work: " + ex);
                        _exception = ex;
                        throw;
                    }

                }
            }
Example #50
0
        public override string GeneratePublishHtml(ISmartContent content, IPublishingContext publishingContext)
        {
            var settings = new Settings(content.Properties);

            return(settings.Format.FormatCode(settings.SourceCode, embedStylesheet: settings.EmbedStylesheet, alternate: settings.HighlightAlternateLines, lineNumbers: settings.ShowLineNumbers));
        }
 public override string GeneratePublishHtml(ISmartContent content, IPublishingContext publishingContext)
 {
     _currentBlogId = publishingContext.AccountId;
     return FormTagLinks(content);
 }
 public SmartUrlContentRetreivalAsyncOperation(
     ISynchronizeInvoke invokeTarget, SmartContentSource contentSource, string url, string title, ISmartContent newContent)
     : base(invokeTarget, contentSource, url, title)
 {
     _newContent = newContent;
 }
 public override string GeneratePreviewHtml(ISmartContent smartContent, IPublishingContext publishingContext, out Position position)
 {
     return GenerateLink(smartContent, publishingContext, out position);
 }
 /// <summary>
 /// Create content using an Insert dialog. Plugin classes which override this method must
 /// also be declared with the InsertableContentSourceAttribute.
 /// </summary>
 /// <param name="dialogOwner">Owner for any dialogs shown.</param>
 /// <param name="newContent">SmartContent object which is populated with initial values by this method.</param>
 /// <returns>DialogResult.OK if content was successfully created, DialogResult.Cancel
 /// if the user cancels the Insert dialog.</returns>
 /// <exception cref="ContentCreationException">Thrown if an error occurs during the creation of content.</exception>
 public virtual DialogResult CreateContent(IWin32Window dialogOwner, ISmartContent newContent)
 {
     throw new NotImplementedException("SmartContentSource.CreateContent");
 }
 public override string GeneratePublishHtml(IWin32Window dialogOwner, ISmartContent smartContent, IPublishingContext publishingContext, bool publish, out Position position)
 {
     return GenerateLink(smartContent, publishingContext, out position);
 }
 private void MakeSmartContentEditable()
 {
     String newContentId = Guid.NewGuid().ToString();
     _smartContent = _contentSourceContext.CloneSmartContent(_smartContentId, newContentId);
     _smartContentId = newContentId;
     Debug.Assert(_smartContent != null);
     _properties.SmartContentRaw = _smartContent;
     _supportingFiles.SmartContentRaw = _smartContent;
     _layout.SmartContentRaw = _smartContent;
 }
 /// <summary>
 /// Generate the HTML content which is used to represent the SmartContent item within
 /// the post editor. The default behavior for this method if it is not overridden is to
 /// call GeneratePublishHtml.
 /// </summary>
 /// <param name="content">SmartContent object to generate HTML for.</param>
 /// <param name="publishingContext">Publishing context for HTML generation.</param>
 /// <returns>HTML content to be inserted into the post editor.</returns>
 public virtual string GenerateEditorHtml(ISmartContent content, IPublishingContext publishingContext)
 {
     return GeneratePublishHtml(content, publishingContext);
 }
        internal static void PlainTextTransform(IPublishingContext site, SmartContentSource source, ISmartContent sContent, ref string content)
        {
            if (source is IInternalSmartContentSource)
            {
                try
                {
                    content = ((IInternalSmartContentSource)source).GeneratePlainTextHtml(sContent, site);
                }
                catch (Exception ex)
                {
                    Trace.WriteLine("Content Source failed to generate plain text html: " + ex);
                    Trace.Flush();
                    throw;
                }

            }
        }
 /// <summary>
 /// Create content using the contents of a LiveClipboad Xml document. Plugin classes which override
 /// this method must also be declared with the LiveClipboardContentSourceAttribute.
 /// </summary>
 /// <param name="dialogOwner">Owner for any dialogs shown.</param>
 /// <param name="lcDocument">LiveClipboard Xml document</param>
 /// <param name="newContent">SmartContent object which is populated with initial values by this method.</param>
 /// <returns>DialogResult.OK if content was successfully created, DialogResult.Cancel
 /// if the user cancels the Insert dialog.</returns>
 /// <exception cref="ContentCreationException">Thrown if an error occurs during the creation of content.</exception>
 public virtual DialogResult CreateContentFromLiveClipboard(IWin32Window dialogOwner, XmlDocument lcDocument, ISmartContent newContent)
 {
     throw new NotImplementedException("SmartContentSource.CreateContentFromLiveClipboard");
 }
 private string FormTagLinks(ISmartContent smartContent)
 {
     TagContext context = new TagContext(smartContent, Options, _currentBlogId);
     return context.CurrentProvider.GenerateHtmlForTags(context.Tags);
 }