コード例 #1
0
    protected void btnPostAtTwitter_Click(object sender, EventArgs e)
    {
        if (txtTemplateTwitter.Text.Trim() == "")
        {
            ShowError(ResHelper.GetString("socialnetworking.twitter.emptyerror"));
            return;
        }

        string template = txtTemplateTwitter.Text;

        // Process template.
        MacroResolver mr         = MacroResolver.GetInstance();
        string        textToSend = mr.ResolveMacros(template);

        // Shorten URLs.
        textToSend = URLShortenerHelper.ShortenURLsInText(textToSend, SocialNetworkType.Twitter);

        ShowInformation(String.Format(ResHelper.GetString("socialnetworking.lengthafterprocessing"), textToSend.Length));

        // Send tweet
        string tweetUrl = TwitterProvider.PublishTweet(textToSend, CMSContext.CurrentSiteName);

        // Check if tweet was succesfully published.
        bool success = !string.IsNullOrEmpty(tweetUrl);

        if (success)
        {
            ShowConfirmation(ResHelper.GetString("socialnetworking.twitter.sendsuccess"));

            dataElement.IsPublished             = true;
            dataElement.PostURL                 = tweetUrl;
            dataElement.AutoPostAfterPublishing = false;
            dataElement.Template                = txtTemplateTwitter.Text;

            try
            {
                // Save dataElement into database
                node.SetValue(FieldInfo.Name, SerializeData().OuterXml);
                if (IsWorkflow)
                {
                    DocumentHelper.UpdateDocument(node, node.TreeProvider);
                }
                else
                {
                    node.Update();
                }

                RenderControls();
            }
            catch (Exception ex)
            {
                EventLogProvider ev = new EventLogProvider();
                ev.LogEvent("TwitterAutoPost", "AfterPost", ex, CMSContext.CurrentSiteID);
            }
        }
        else
        {
            ShowError(ResHelper.GetString("socialnetworking.twitter.senderror"));
        }
    }
コード例 #2
0
    /// <summary>
    /// Initializes inner controls. Post data are loaded when editing post.
    /// </summary>
    private void InitializeControls()
    {
        chkPostAfterDocumentPublish.Checked = false;

        string content = String.Empty;

        if (mBackCompatibilityValue.HasValue)
        {
            // Pre fill form with old data
            chkPostAfterDocumentPublish.Checked = mBackCompatibilityValue.Value.AutoPostAfterPublishing;
            content = mBackCompatibilityValue.Value.Template;
        }
        else if (!String.IsNullOrWhiteSpace(mDefaultValue))
        {
            // Default content given as control's string Value
            content = mDefaultValue;
        }
        else if ((FieldInfo != null) && !String.IsNullOrWhiteSpace(FieldInfo.DefaultValue))
        {
            // Default content from field info
            content = FieldInfo.DefaultValue;
        }
        tweetContent.Text = content;

        if (!chkPostAfterDocumentPublish.Checked)
        {
            publishDateTime.Value = DateTime.Now;
        }

        channelSelector.ObjectSiteName = SiteIdentifier;
        TwitterAccountInfo defaultAccountInfo = TwitterAccountInfoProvider.GetDefaultTwitterAccount(SiteIdentifier);

        if (defaultAccountInfo != null)
        {
            channelSelector.Value = defaultAccountInfo.TwitterAccountID;
        }

        ClearPostState();
        urlShortenerSelector.SiteID         = SiteIdentifier;
        urlShortenerSelector.Value          = URLShortenerHelper.GetDefaultURLShortenerForSocialNetwork(SocialNetworkTypeEnum.Twitter, SiteIdentifier);
        chkPostAfterDocumentPublish.Visible = (Document != null);
        campaingSelector.Value          = null;
        campaingSelector.ObjectSiteName = SiteIdentifier;

        if ((FieldInfo != null) && !FieldInfo.AllowEmpty)
        {
            // Post must be created because field doesn't allow an empty value
            chkPostToTwitter.Enabled = false;
            DisplayForm = true;
        }
        else
        {
            // Form is displayed if it is pre filled with old data
            DisplayForm = mBackCompatibilityValue.HasValue;
        }
    }
コード例 #3
0
 private void InitializeDropDownList()
 {
     UrlShortenerDropDownList.Items.Add(CreateDropDownListItem(URLShortenerTypeEnum.None));
     foreach (URLShortenerTypeEnum shortener in URLShortenerHelper.GetAvailableURLShorteners(SiteID))
     {
         UrlShortenerDropDownList.Items.Add(CreateDropDownListItem(shortener));
     }
     if (SocialNetworkName != SocialNetworkTypeEnum.None)
     {
         URLShortenerTypeEnum defaultShortener = URLShortenerHelper.GetDefaultURLShortenerForSocialNetwork(SocialNetworkName, SiteID);
         UrlShortenerDropDownList.SelectedValue = Enum.GetName(typeof(URLShortenerTypeEnum), defaultShortener);
     }
 }
コード例 #4
0
    /// <summary>
    /// Initializes inner controls to its default state.
    /// </summary>
    private void InitializeControls()
    {
        chkPostAfterDocumentPublish.Checked = false;

        string content = String.Empty;

        if (!String.IsNullOrWhiteSpace(mDefaultValue))
        {
            // Default content given as control's string Value
            content = mDefaultValue;
        }
        else if ((FieldInfo != null) && !String.IsNullOrWhiteSpace(FieldInfo.DefaultValue))
        {
            // Default content from field info
            content = FieldInfo.DefaultValue;
        }
        txtPost.Text      = content;
        txtPost.MaxLength = (int)LinkedInHelper.COMPANY_SHARE_COMMENT_MAX_LENGTH;

        if (!chkPostAfterDocumentPublish.Checked)
        {
            publishDateTime.Value = DateTime.Now;
        }

        companySelector.ObjectSiteName = SiteIdentifier;
        LinkedInAccountInfo defaultAccountInfo = LinkedInAccountInfoProvider.GetDefaultLinkedInAccount(SiteIdentifier);

        if (defaultAccountInfo != null)
        {
            companySelector.Value = defaultAccountInfo.LinkedInAccountID;
        }

        ClearPostState();
        urlShortenerSelector.SiteID         = SiteIdentifier;
        urlShortenerSelector.Value          = URLShortenerHelper.GetDefaultURLShortenerForSocialNetwork(SocialNetworkTypeEnum.LinkedIn, SiteIdentifier);
        chkPostAfterDocumentPublish.Visible = (Document != null);
        campaingSelector.Value          = null;
        campaingSelector.ObjectSiteName = SiteIdentifier;

        if ((FieldInfo != null) && !FieldInfo.AllowEmpty)
        {
            // Post must be created because field doesn't allow an empty value
            chkPostToLinkedIn.Enabled = false;
            DisplayForm = true;
        }
    }