OwlCyberSecurity - MANAGER
Edit File: Index.jwDMsUOD.js
import{s as k,b as X,k as x,u as B,r as ee,D as q}from"./links.Ce9S4kjc.js";import{R as P,a as $}from"./constants.CPpKID74.js";import{b as z,c as H,e as F,d as I,C as M,_ as W}from"./Caret.BthVBOwE.js";import{J as te}from"./JsonValues.D25FTfEu.js";import{B as N,S as J,b as j}from"./index.B6JTtDta.js";import{C as se}from"./ProBadge.CVd2ImKm.js";import{S as re}from"./External.BnlDuPIp.js";import{v as u,o as l,c as p,a,F as E,J as w,k as g,l as m,C as y,t as R,b as h,E as Y,B as _,G as D,m as ie,Y as le}from"./runtime-dom.esm-bundler.tPRhSV4q.js";import{_ as V}from"./_plugin-vue_export-helper.BN1snXvA.js";import{e as ae}from"./escapeRegExp.D4cfHJVO.js";import{S as Q}from"./Exclamation.DGJubTNT.js";import{B as oe}from"./Checkbox.CmdF-nFt.js";import{S as ue}from"./Gear.DwDaVskn.js";import{T as G}from"./Slide.fjAuzpC8.js";import{D as ne}from"./Date.POMBhYKD.js";import{B as ce}from"./DatePicker.XUt7yief.js";import{C as de}from"./Tooltip.DhkkBQWW.js";import{S as he}from"./Plus.CG1QxokA.js";const ge={emits:["set-url"],components:{CoreProBadge:se,SvgExternal:re},props:{results:{type:Array,required:!0},url:String},data(){return{strings:{DRAFT:this.$t.__("DRAFT",this.$td),PENDING:this.$t.__("PENDING",this.$td),FUTURE:this.$t.__("FUTURE",this.$td)}}},methods:{getOptionTitle(e){e=k(e);const t=k(this.url),r=new RegExp(`(${ae(t)})`,"gi");return e.replace(r,'<span class="search-term">$1</span>')},getStatusLabel(e){switch(e.toLowerCase()){case"draft":return this.strings.DRAFT;case"future":return this.strings.FUTURE;case"pending":return this.strings.PENDING}}}},_e={class:"aioseo-add-redirection-url-results"},me=["onClick"],pe={class:"option"},fe={class:"option-title"},Re=["innerHTML"],Se={class:"option-details"},ye=["href"];function Ue(e,t,r,d,s,i){const n=u("core-pro-badge"),U=u("svg-external");return l(),p("div",_e,[a("ul",null,[(l(!0),p(E,null,w(r.results,(S,C)=>(l(),p("li",{key:C,onClick:L=>e.$emit("set-url",S.link)},[a("span",null,[a("div",pe,[a("div",fe,[a("div",{innerHTML:i.getOptionTitle(S.label)},null,8,Re),S.status!=="publish"?(l(),g(n,{key:0},{default:m(()=>[y(R(i.getStatusLabel(S.status)),1)]),_:2},1024)):h("",!0)]),a("div",Se,[a("span",null,R(S.link),1)])]),a("a",{class:"option-permalink",href:S.link,target:"_blank",onClick:Y(()=>{},["stop"])},[_(U)],8,ye)])],8,me))),128))])])}const K=V(ge,[["render",Ue]]),ve={setup(){return{postEditorStore:X(),redirectsStore:x(),rootStore:B()}},components:{BaseInput:N,CoreAddRedirectionUrlResults:K,CoreLoader:z,SvgCircleCheck:H,SvgCircleClose:F,SvgCircleExclamation:Q},props:{url:String,errors:Array,warnings:Array},data(){return{showResults:!1,isLoading:!1,value:null,results:[]}},watch:{value(){this.value&&(this.value=this.value.replace(/(https?:\/)(\/)+|(\/)+/g,"$1$2$3"),this.value.startsWith("/")&&(this.value=this.value.replace(/\s+/g,"")))},url:{immediate:!0,handler(){this.value=this.url}}},methods:{onBlur(){setTimeout(()=>{this.$emit("update:modelValue",this.value)},150)},searchChange(){if(!this.value){this.isLoading=!1,this.showResults=!1,this.results=[];return}if(this.value.startsWith("/")||this.value.startsWith("http:")||this.value.startsWith("https:")){this.isLoading=!1,this.showResults=!1,this.results=[];return}this.isLoading=!0,I(()=>{if(!this.value){this.isLoading=!1,this.showResults=!1,this.results=[];return}this.showResults=!0,this.ajaxSearch(this.value).then(()=>this.isLoading=!1)},500)},ajaxSearch(e){return this.redirectsStore.getPosts({query:e,postId:this.postEditorStore.currentPost.id}).then(t=>{this.results=t.body.objects})},setUrl(e){this.showResults=!1,this.value=e.replace(this.rootStore.aioseo.urls.home,"",e),this.$emit("update:modelValue",this.value)},documentClick(e){if(!this.showResults)return;const t=e&&e.target?e.target:null,r=this.$refs["redirect-target-url"];r&&r!==t&&!r.contains(t)&&(this.showResults=!1)}},mounted(){document.addEventListener("click",this.documentClick);const e=document.querySelector("#aioseo-modal-portal .modal-wrapper");e&&e.addEventListener("click",this.documentClick);const t=document.querySelector("#main-settings-cont");t&&t.addEventListener("click",this.documentClick)},beforeUnmount(){document.removeEventListener("click",this.documentClick);const e=document.querySelector("#aioseo-modal-portal .modal-wrapper");e&&e.removeEventListener("click",this.documentClick);const t=document.querySelector("#main-settings-cont");t&&t.removeEventListener("click",this.documentClick)}},be={class:"aioseo-add-redirection-target-url",ref:"redirect-target-url"},Te={class:"append-icon"};function Ee(e,t,r,d,s,i){const n=u("svg-circle-close"),U=u("svg-circle-check"),S=u("svg-circle-exclamation"),C=u("core-loader"),L=u("base-input"),T=u("core-add-redirection-url-results");return l(),p("div",be,[_(L,{modelValue:s.value,"onUpdate:modelValue":[t[0]||(t[0]=b=>s.value=b),t[2]||(t[2]=b=>e.$emit("update:modelValue",s.value))],onKeyup:i.searchChange,onFocus:t[1]||(t[1]=b=>s.showResults=!0),onBlur:t[3]||(t[3]=b=>e.$emit("blur",s.value)),size:"medium",placeholder:"/target-page/",class:D({"aioseo-error":r.errors.length,"aioseo-active":!r.errors.length&&!r.warnings.length&&r.url,"aioseo-warning":r.warnings.length})},{"append-icon":m(()=>[a("div",Te,[s.isLoading?h("",!0):(l(),p(E,{key:0},[r.errors.length?(l(),g(n,{key:0})):h("",!0),!r.errors.length&&!r.warnings.length&&r.url?(l(),g(U,{key:1})):h("",!0),r.warnings.length?(l(),g(S,{key:2})):h("",!0)],64)),s.isLoading?(l(),g(C,{key:1,dark:""})):h("",!0)])]),_:1},8,["modelValue","onKeyup","class"]),s.showResults&&s.results.length?(l(),g(T,{key:0,results:s.results,url:s.value,onSetUrl:i.setUrl},null,8,["results","url","onSetUrl"])):h("",!0)],512)}const Ce=V(ve,[["render",Ee]]),Le=function(e,t){if(typeof e!="string")return e;const r=new RegExp("^"+t.replace(/\/$/,""),"i");return e.replace(r,"")},Z={setup(){return{links:ee}},methods:{redirectHasUnPublishedPost(e){return e.post_id&&e.postStatus!=="publish"},validateRedirect(e){var r;if(!e.url.url)return!1;const t=[];if(e.url.regex)try{new RegExp(e.url.url)}catch{return t.push(this.$t.__("The regex syntax is invalid.",this.$td)),t}if(!e.url.regex&&!k(e.url.url))return t.push(this.$t.__("Your URL is invalid.",this.$td)),t;if(e.url.url.substr(0,4)==="http"&&t.push(this.$t.__("Please enter a valid relative source URL.",this.$td)),e.url.url.match(/%[a-zA-Z]+%/)&&t.push(this.$t.__("Permalinks are not currently supported.",this.$td)),(e.url.url==="/(.*)"||e.url.url==="^/(.*)")&&t.push(this.$t.__("This redirect is supported using the Relocate Site feature under Full Site Redirect tab.",this.$td)),e.url.url&&e.url.url.length&&e.targetUrl&&e.targetUrl.length){let d=e.url.ignoreSlash?this.$links.unTrailingSlashIt(e.url.url):e.url.url,s=e.url.ignoreSlash?this.$links.unTrailingSlashIt(e.targetUrl):e.targetUrl;d=e.url.ignoreCase?d.toLowerCase():d,s=e.url.ignoreCase?s.toLowerCase():s,(d===s||e.url.regex&&s.match(d))&&t.push(this.$t.__("Your source is the same as a target and this will create a loop.",this.$td))}if(0<((r=this.redirectsStore)==null?void 0:r.protectedPaths.length)){const d=this.redirectsStore.protectedPaths.map(s=>s.replace(/\/$/,""));e.url.url.match(new RegExp("^("+d.join("|")+")"))&&t.push(this.$t.__("Your source is a protected path and cannot be redirected.",this.$td))}return t}}},ke={setup(){return{redirectsStore:x(),rootStore:B()}},mixins:[Z],emits:["updated-url","remove-url","updated-option"],components:{BaseCheckbox:oe,BaseInput:N,CoreAddRedirectionUrlResults:K,CoreAlert:M,CoreLoader:z,SvgCircleCheck:H,SvgCircleClose:F,SvgCircleExclamation:Q,SvgGear:ue,SvgTrash:J,TransitionSlide:G},props:{url:{type:Object,default(){return{id:null,url:null,regex:!1,ignoreSlash:!0,ignoreCase:!0,errors:[],warnings:[]}}},allowDelete:Boolean,targetUrl:String,log404:Boolean,disableSource:Boolean},data(){return{showResults:!1,isLoading:!1,showOptions:!1,strings:{ignoreSlash:this.$t.__("Ignore Slash",this.$td),ignoreCase:this.$t.__("Ignore Case",this.$td),regex:this.$t.__("Regex",this.$td)},results:[]}},watch:{targetUrl(){this.updateSourceUrl(this.url.url)}},computed:{maybeRegex(){return this.url.url.match(/[*\\()[\]^$]/)!==null||this.url.url.indexOf(".?")!==-1},iffyUrl(){if(!this.url.url||this.disableSource)return[];const e=[];return this.url.url.substr(0,4)!=="http"&&this.url.url.substr(0,1)!=="/"&&0<this.url.url.length&&!this.url.regex&&e.push(this.$t.sprintf(this.$t.__("The source URL should probably start with a %1$s",this.$td),"<code>/</code>")),this.url.url.indexOf("#")!==-1&&e.push(this.$t.__("Anchor values are not sent to the server and cannot be redirected.",this.$td)),!this.log404&&this.maybeRegex&&!this.url.regex&&e.push(this.$t.sprintf(this.$t.__("Remember to enable the %1$s option if this is a regular expression.",this.$td),"<code>Regex</code>")),this.url.regex&&(this.url.url.indexOf("^")===-1&&this.url.url.indexOf("$")===-1&&e.push(this.$t.sprintf(this.$t.__("To prevent a greedy regular expression you can use %1$s to anchor it to the start of the URL. For example: %2$s",this.$td),"<code>^/</code>","<code>^/"+k(this.url.url.replace(/^\//,""))+"</code>")),0<this.url.url.indexOf("^")&&e.push(this.$t.sprintf(this.$t.__("The caret %1$s should be at the start. For example: %2$s",this.$td),"<code>^/</code>","<code>^/"+k(this.url.url.replace("^","").replace(/^\//,""))+"</code>")),this.url.url.indexOf("^")===0&&this.url.url.indexOf("^/")===-1&&e.push(this.$t.sprintf(this.$t.__("The source URL should probably start with a %1$s",this.$td),"<code>^/</code>")),this.url.url.length-1!==this.url.url.indexOf("$")&&this.url.url.indexOf("$")!==-1&&e.push(this.$t.sprintf(this.$t.__("The dollar symbol %1$s should be at the end. For example: %2$s",this.$td),"<code>$</code>","<code>"+k(this.url.url.replace(/\$/g,""))+"$</code>"))),this.url.url.match(/(\.html|\.htm|\.php|\.pdf|\.jpg)$/)!==null&&e.push(this.$t.__("Some servers may be configured to serve file resources directly, preventing a redirect occurring.",this.$td)),e},urlOptionsActive(){return this.url.regex||this.showOptions}},methods:{updateSourceUrl(e){!this.disableSource&&e&&(e&&(e=e.replace(/(https?:\/)(\/)+|(\/)+/g,"$1$2$3")),!this.url.regex&&e.startsWith("/")&&(e=e.replace(/\s+/g,"")),e=Le(e,this.rootStore.aioseo.urls.home)),this.url.url=e,this.url.errors=this.validateRedirect(this),this.url.warnings=this.iffyUrl,this.$emit("updated-url",this.url)},updateOption(e,t){this.url[e]=t,this.updateSourceUrl(this.url.url),this.$emit("updated-option",this.url)},searchChange(){if(!this.url.url||this.url.regex){this.isLoading=!1,this.showResults=!1,this.results=[];return}if(this.url.url.startsWith("/")||this.url.url.startsWith("^")||this.url.url.startsWith("http:")||this.url.url.startsWith("https:")){this.isLoading=!1,this.showResults=!1,this.results=[];return}this.isLoading=!0,I(()=>{if(!this.url.url){this.isLoading=!1,this.showResults=!1,this.results=[];return}this.showResults=!0,this.ajaxSearch(this.url.url).then(()=>this.isLoading=!1)},500)},ajaxSearch(e){return this.redirectsStore.getPosts({query:e}).then(t=>{this.results=t.body.objects})},setUrl(e){this.showResults=!1,this.updateOption("url",e.replace(this.rootStore.aioseo.urls.home,"",e))},documentClick(e){if(!this.showResults)return;const t=e&&e.target?e.target:null,r=this.$refs["redirect-source-url"];r&&r!==t&&!r.contains(t)&&(this.showResults=!1)}},mounted(){this.url.showOptions&&(this.showOptions=!0,this.updateSourceUrl(this.url.url)),document.addEventListener("click",this.documentClick)},beforeUnmount(){document.removeEventListener("click",this.documentClick)}},we={class:"aioseo-redirect-source-url",ref:"redirect-source-url"},De={class:"append-icon"};function $e(e,t,r,d,s,i){const n=u("svg-circle-close"),U=u("svg-circle-check"),S=u("svg-circle-exclamation"),C=u("svg-gear"),L=u("svg-trash"),T=u("core-loader"),b=u("base-input"),A=u("core-add-redirection-url-results"),f=u("base-checkbox"),v=u("transition-slide"),o=u("core-alert");return l(),p("div",we,[_(b,{modelValue:r.url.url,"onUpdate:modelValue":t[2]||(t[2]=c=>i.updateSourceUrl(c)),onKeyup:i.searchChange,onFocus:t[3]||(t[3]=c=>s.showResults=!0),disabled:r.log404||r.disableSource,size:"medium",placeholder:"/source-page/",class:D({"aioseo-error":r.url.errors.length,"aioseo-active":!r.url.errors.length&&!r.url.warnings.length&&r.url.url,"aioseo-warning":r.url.warnings.length})},{"append-icon":m(()=>[a("div",De,[s.isLoading?h("",!0):(l(),p(E,{key:0},[r.url.errors.length?(l(),g(n,{key:0})):h("",!0),!r.url.errors.length&&!r.url.warnings.length&&r.url.url?(l(),g(U,{key:1})):h("",!0),r.url.warnings.length?(l(),g(S,{key:2})):h("",!0),_(C,{class:D({active:i.urlOptionsActive}),onClick:t[0]||(t[0]=c=>s.showOptions=!s.showOptions)},null,8,["class"]),r.allowDelete?(l(),g(L,{key:3,onClick:t[1]||(t[1]=c=>e.$emit("remove-url"))})):h("",!0)],64)),s.isLoading?(l(),g(T,{key:1,dark:""})):h("",!0)])]),_:1},8,["modelValue","onKeyup","disabled","class"]),!r.url.regex&&s.showResults&&s.results.length?(l(),g(A,{key:0,results:s.results,url:r.url.url,onSetUrl:i.setUrl},null,8,["results","url","onSetUrl"])):h("",!0),r.log404?h("",!0):ie(e.$slots,"source-url-description",{key:1}),_(v,{active:s.showOptions,class:"source-url-options"},{default:m(()=>[_(f,{size:"medium",modelValue:r.url.ignoreSlash,"onUpdate:modelValue":t[4]||(t[4]=c=>i.updateOption("ignoreSlash",c))},{default:m(()=>[y(R(s.strings.ignoreSlash),1)]),_:1},8,["modelValue"]),_(f,{size:"medium",modelValue:r.url.ignoreCase,"onUpdate:modelValue":t[5]||(t[5]=c=>i.updateOption("ignoreCase",c))},{default:m(()=>[y(R(s.strings.ignoreCase),1)]),_:1},8,["modelValue"]),!r.log404&&!r.disableSource?(l(),g(f,{key:0,size:"medium",modelValue:r.url.regex,"onUpdate:modelValue":t[6]||(t[6]=c=>i.updateOption("regex",c))},{default:m(()=>[y(R(s.strings.regex),1)]),_:1},8,["modelValue"])):h("",!0)]),_:1},8,["active"]),_(v,{active:!!r.url.errors.length},{default:m(()=>[(l(!0),p(E,null,w(r.url.errors,(c,O)=>(l(),g(o,{key:O,class:"source-url-error",type:"red",size:"small",innerHTML:c},null,8,["innerHTML"]))),128))]),_:1},8,["active"]),_(v,{active:!!r.url.warnings.length},{default:m(()=>[(l(!0),p(E,null,w(r.url.warnings,(c,O)=>(l(),g(o,{key:O,class:"source-url-warning",type:"yellow",size:"small",innerHTML:c},null,8,["innerHTML"]))),128))]),_:1},8,["active"])],512)}const Ve=V(ke,[["render",$e]]),Ae={type:null,key:null,value:null,regex:null},Pe={emits:["redirects-custom-rule-error"],setup(){return{rootStore:B()}},components:{BaseButton:W,BaseDatePicker:ce,BaseInput:N,BaseSelect:j,CoreAlert:M,CoreTooltip:de,SvgCirclePlus:he,SvgTrash:J},props:{editCustomRules:Array},mixins:[ne],data(){return{DateTime:q,strings:{customRules:this.$t.__("Custom Rules",this.$td),selectMatchRule:this.$t.__("Select Rule",this.$td),delete:this.$t.__("Delete",this.$td),add:this.$t.__("Add Custom Rule",this.$td),regex:this.$t.__("Regex",this.$td),selectAValue:this.$t.__("Select a Value or Add a New One",this.$td),key:this.$t.__("Key",this.$td),value:this.$t.__("Value",this.$td),startDate:this.$t.__("Start Date",this.$td),endDate:this.$t.__("End Date",this.$td)},customRules:[],rulesErrors:[],types:[{label:this.$constants.REDIRECTS_CUSTOM_RULES_LABELS.schedule,value:"schedule",taggable:!1,regex:!1,dateRange:!0},{label:this.$constants.REDIRECTS_CUSTOM_RULES_LABELS.login,value:"login",placeholder:this.$t.__("Select Status",this.$td),singleRule:!0,options:[{label:this.$constants.REDIRECTS_CUSTOM_RULES_LABELS.loggedin,value:"loggedin"},{label:this.$constants.REDIRECTS_CUSTOM_RULES_LABELS.loggedout,value:"loggedout"}]},{label:this.$constants.REDIRECTS_CUSTOM_RULES_LABELS.role,value:"role",multiple:!0,placeholder:this.$t.__("Select Roles",this.$td),options:Object.entries(this.rootStore.aioseo.user.roles).map(e=>({label:e[1],value:e[0]}))},{label:this.$constants.REDIRECTS_CUSTOM_RULES_LABELS.referrer,value:"referrer",regex:!0,singleRule:!0},{label:this.$constants.REDIRECTS_CUSTOM_RULES_LABELS.agent,value:"agent",regex:!0,taggable:!0,multiple:!0,options:[{label:this.$constants.REDIRECTS_CUSTOM_RULES_LABELS.mobile,value:"mobile",docLink:this.$links.getDocLink(this.$t.__("Learn more",this.$td),"redirectCustomRulesUserAgent",!0)},{label:this.$constants.REDIRECTS_CUSTOM_RULES_LABELS.feeds,value:"feeds",docLink:this.$links.getDocLink(this.$t.__("Learn more",this.$td),"redirectCustomRulesUserAgent",!0)},{label:this.$constants.REDIRECTS_CUSTOM_RULES_LABELS.libraries,value:"libraries",docLink:this.$links.getDocLink(this.$t.__("Learn more",this.$td),"redirectCustomRulesUserAgent",!0)}]},{label:this.$constants.REDIRECTS_CUSTOM_RULES_LABELS.cookie,value:"cookie",keyValuePair:!0,regex:!0},{label:this.$constants.REDIRECTS_CUSTOM_RULES_LABELS.ip,value:"ip",placeholder:this.$t.__("Enter an IP Address",this.$td),taggable:!0,regex:!0,singleRule:!0},{label:this.$constants.REDIRECTS_CUSTOM_RULES_LABELS.server,value:"server",placeholder:this.$t.__("Enter the Server Name",this.$td),regex:!0,singleRule:!0},{label:this.$constants.REDIRECTS_CUSTOM_RULES_LABELS.header,value:"header",keyValuePair:!0,regex:!0},{label:this.$constants.REDIRECTS_CUSTOM_RULES_LABELS.wp_filter,value:"wp_filter",placeholder:this.$t.__("Enter a WordPress Filter Name",this.$td),taggable:!0},{label:this.$constants.REDIRECTS_CUSTOM_RULES_LABELS.locale,value:"locale",taggable:!0,regex:!0,placeholder:this.$t.__("Enter a Locale Code, e.g.: en_GB, es_ES",this.$td),singleRule:!0}]}},computed:{hasCustomRules(){return 0<this.customRules.length},filteredTypes(){return this.types.map(e=>(e.$isDisabled=!1,e.singleRule&&this.customRules.find(t=>e.value===t.type)&&(e.$isDisabled=!0),e))}},methods:{isDisabledStartDate(e){const t=new Date;return t.setHours(0,0,0,0),e<t},isDisabledEndDate(e,t){const r=this.getRuleValue("scheduleStart",t);return r?(e.setHours(23,59,59,0),this.dateStringToLocalJs(r)>e):this.isDisabledStartDate(e)},removeRule(e){this.customRules.splice(e,1),this.hasCustomRules||this.addRule(null)},addRule(e,t=!1){e||(e=JSON.parse(JSON.stringify(Ae))),(!t||t&&this.customRules.filter(r=>r===e).length===0)&&this.customRules.push(e)},updateRule(e,t,r){const d=this.customRules[r];t=typeof t.value<"u"?t.value:t,t=typeof t=="object"&&t.length?t.map(s=>s.value):t,d[e]=t,e==="type"&&(d.value=""),this.customRules[r]=d},getRuleValue(e,t,r=!1){if(!this.customRules[t])return;let s=this.customRules[t][e],i=null;if(r)return s;switch(e){case"type":s=this.types.find(n=>s===n.value);break;case"value":i=this.getType(t,"options"),i&&(typeof s=="object"?s=s.map(n=>i.find(U=>n===U.value)||n).filter(n=>!!n):s=i.find(n=>s===n.value)||s),this.getType(t,"taggable")&&(s=typeof s=="object"?s.map(n=>typeof n.label>"u"?{label:n,value:n}:n):[]);break}return s},getType(e,t){const r=this.getRuleValue("type",e);return t?r&&typeof r[t]<"u"?r[t]:!1:r},validationError(){let e=!1,t=null,r=null;this.customRules.forEach((d,s)=>{switch(this.rulesErrors[s]=null,d.type){case"schedule":t=this.getRuleValue("scheduleStart",s),r=this.getRuleValue("scheduleEnd",s),t&&r&&(t>r&&(this.rulesErrors[s]=this.$t.__("The Start Date must be lower than the End Date.",this.$td),e=!0),t===r&&(this.rulesErrors[s]=this.$t.__("Start Date and End Date must be different.",this.$td),e=!0));break}}),this.$emit("redirects-custom-rule-error",e)},updateDate(e,t,r){const d=e!==null?q.fromJSDate(e).toUTC().toString():"";this.updateRule(t,d,r)}},mounted(){this.editCustomRules&&(this.customRules=this.editCustomRules),this.hasCustomRules||this.addRule(null)},watch:{customRules:{deep:!0,handler(){this.validationError()}}}},Oe={class:"custom-rules"},xe={class:"redirects-options-table",cellspacing:"0",cellpadding:"0","aria-label":"Custom Rules"},Be={colspan:"2"},Ie={class:"rule-settings"},Me={class:"rule-row"},Ne={class:"rule-option"},qe={key:3,class:"date-range"},ze={key:0,class:"rule-error"},He={class:"actions"},Fe={colspan:"2"};function We(e,t,r,d,s,i){const n=u("base-select"),U=u("base-input"),S=u("base-date-picker"),C=u("base-toggle"),L=u("core-alert"),T=u("svg-trash"),b=u("core-tooltip"),A=u("svg-circle-plus"),f=u("base-button");return l(),p("div",Oe,[a("table",xe,[a("thead",null,[a("tr",null,[a("td",Be,R(s.strings.customRules),1)])]),a("tbody",null,[(l(!0),p(E,null,w(s.customRules,(v,o)=>(l(),p("tr",{class:D(["rule",{even:o%2===0}]),key:o},[a("td",Ie,[a("div",Me,[a("div",Ne,[_(n,{options:i.filteredTypes,size:"medium",placeholder:s.strings.selectMatchRule,modelValue:i.getRuleValue("type",o),"onUpdate:modelValue":c=>i.updateRule("type",c,o)},null,8,["options","placeholder","modelValue","onUpdate:modelValue"]),i.getType(o,"options")||i.getType(o,"taggable")?(l(),g(n,{key:0,options:i.getType(o,"options")||[],size:"medium",modelValue:i.getRuleValue("value",o),"onUpdate:modelValue":c=>i.updateRule("value",c,o),multiple:i.getType(o,"multiple")||i.getType(o,"taggable"),taggable:i.getType(o,"taggable"),placeholder:i.getType(o,"placeholder")||s.strings.selectAValue},null,8,["options","modelValue","onUpdate:modelValue","multiple","taggable","placeholder"])):h("",!0),i.getType(o,"keyValuePair")?(l(),g(U,{key:1,modelValue:i.getRuleValue("key",o),"onUpdate:modelValue":c=>i.updateRule("key",c,o),size:"medium",placeholder:i.getType(o,"placeholderKey")||s.strings.key},null,8,["modelValue","onUpdate:modelValue","placeholder"])):h("",!0),!i.getType(o,"options")&&!i.getType(o,"taggable")&&!i.getType(o,"dateRange")?(l(),g(U,{key:2,modelValue:i.getRuleValue("value",o),"onUpdate:modelValue":c=>i.updateRule("value",c,o),size:"medium",placeholder:i.getType(o,"placeholder")||s.strings.value,disabled:!i.getType(o)},null,8,["modelValue","onUpdate:modelValue","placeholder","disabled"])):h("",!0),i.getType(o,"dateRange")?(l(),p("div",qe,[_(S,{type:"datetime",size:"large",placeholder:s.strings.startDate,dateFormat:d.rootStore.aioseo.data.dateFormat+" - "+d.rootStore.aioseo.data.timeFormat,defaultValue:e.dateStringToLocalJs(i.getRuleValue("scheduleStart",o)),onChange:c=>i.updateDate(c,"scheduleStart",o),isDisabledDate:i.isDisabledStartDate},null,8,["placeholder","dateFormat","defaultValue","onChange","isDisabledDate"]),_(S,{type:"datetime",size:"large",placeholder:s.strings.endDate,dateFormat:d.rootStore.aioseo.data.dateFormat+" - "+d.rootStore.aioseo.data.timeFormat,defaultValue:e.dateStringToLocalJs(i.getRuleValue("scheduleEnd",o)),onChange:c=>i.updateDate(c,"scheduleEnd",o),isDisabledDate:c=>i.isDisabledEndDate(c,o)},null,8,["placeholder","dateFormat","defaultValue","onChange","isDisabledDate"])])):h("",!0),i.getType(o,"regex")?(l(),g(C,{key:4,modelValue:i.getRuleValue("regex",o),"onUpdate:modelValue":c=>i.updateRule("regex",c,o)},{default:m(()=>[y(R(s.strings.regex),1)]),_:2},1032,["modelValue","onUpdate:modelValue"])):h("",!0)]),s.rulesErrors[o]?(l(),p("div",ze,[_(L,{type:"red",size:"small"},{default:m(()=>[y(R(s.rulesErrors[o]),1)]),_:2},1024)])):h("",!0)])]),a("td",He,[_(b,{class:"action",type:"action"},{tooltip:m(()=>[y(R(s.strings.delete),1)]),default:m(()=>[_(T,{onClick:c=>i.removeRule(o)},null,8,["onClick"])]),_:2},1024)])],2))),128))]),a("tfoot",null,[a("tr",null,[a("td",Fe,[_(f,{size:"small-table",type:"black",onClick:t[0]||(t[0]=v=>i.addRule(null))},{default:m(()=>[_(A),y(" "+R(s.strings.add),1)]),_:1})])])])])])}const Je=V(Pe,[["render",We],["__scopeId","data-v-06c2c8d2"]]),je={},Ye={width:"36",height:"16",viewBox:"0 0 36 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",class:"aioseo-right-arrow"},Qe=a("path",{d:"M36 8L28.4211 0.5V6.125H0V9.875H28.4211V15.5L36 8Z",fill:"currentColor"},null,-1),Ge=[Qe];function Ke(e,t){return l(),p("svg",Ye,Ge)}const Ze=V(je,[["render",Ke]]),Xe={setup(){return{redirectsStore:x()}},emits:["cancel","added-redirect"],components:{BaseButton:W,BaseSelect:j,CoreAddRedirectionTargetUrl:Ce,CoreAddRedirectionUrl:Ve,CoreAlert:M,CustomRules:Je,SvgRightArrow:Ze,TransitionSlide:G},mixins:[te,Z],props:{edit:Boolean,log404:Boolean,disableSource:Boolean,url:Object,urls:Array,target:String,type:Number,query:String,slash:Boolean,case:Boolean,rules:{type:Array,default(){return[]}},postId:Number,postStatus:String},data(){return{REDIRECT_TYPES:P,genericError:!1,addingRedirect:!1,targetUrlErrors:[],targetUrlWarnings:[],customRulesError:!1,strings:{redirectType:this.$t.__("Redirect Type:",this.$td),targetUrl:this.$t.__("Target URL",this.$td),targetUrlDescription:this.$t.__("Enter a URL or start by typing a page or post title, slug or ID.",this.$td),addUrl:this.$t.__("Add URL",this.$td),sourceUrlDescription:this.$t.sprintf(this.$t.__("Enter a relative URL to redirect from or start by typing in page or post title, slug or ID. You can also use regex (%1$s)",this.$td),this.$links.getDocLink(this.$t.__("what's this?",this.$td),"redirectManagerRegex")),advancedSettings:this.$t.__("Advanced Settings",this.$td),queryParams:this.$t.__("Query Parameters:",this.$td),saveChanges:this.$t.__("Save Changes",this.$td),cancel:this.$t.__("Cancel",this.$td),genericErrorMessage:this.$t.__("An error occurred while adding your redirects. Please try again later.",this.$td),sourceUrlSetOncePublished:this.$t.__("source url set once post is published",this.$td)},sourceDisabled:!1,editing:!1,editingRedirect:{sourceUrls:[],targetUrl:null,redirectType:null,queryParam:null,customRules:[],showAdvancedSettings:!1}}},watch:{sourceUrls:{deep:!0,handler(){I(()=>this.checkForDuplicates(),500)}}},computed:{sourceUrls:{get(){return this.editing?this.editingRedirect.sourceUrls:this.redirectsStore.addNewRedirect.sourceUrls},set(e){this.editing?this.editingRedirect.sourceUrls=e:this.redirectsStore.addNewRedirect.sourceUrls=e}},targetUrl:{get(){return this.editing?this.editingRedirect.targetUrl:this.redirectsStore.addNewRedirect.targetUrl},set(e){this.editing?this.editingRedirect.targetUrl=e:this.redirectsStore.addNewRedirect.targetUrl=e}},redirectType:{get(){return this.editing?this.editingRedirect.redirectType:this.redirectsStore.addNewRedirect.redirectType},set(e){this.editing?this.editingRedirect.redirectType=e:this.redirectsStore.addNewRedirect.redirectType=e}},queryParam:{get(){return this.editing?this.editingRedirect.queryParam:this.redirectsStore.addNewRedirect.queryParam},set(e){this.editing?this.editingRedirect.queryParam=e:this.redirectsStore.addNewRedirect.queryParam=e}},customRules:{get(){return this.editing?this.editingRedirect.customRules:this.redirectsStore.addNewRedirect.customRules},set(e){this.editing?this.editingRedirect.customRules=e:this.redirectsStore.addNewRedirect.customRules=e}},showAdvancedSettings:{get(){return this.editing?this.editingRedirect.showAdvancedSettings:this.redirectsStore.addNewRedirect.showAdvancedSettings},set(e){this.editing?this.editingRedirect.showAdvancedSettings=e:this.redirectsStore.addNewRedirect.showAdvancedSettings=e}},saveIsDisabled(){return!!this.sourceUrls.filter(e=>!e.url).length||!!this.sourceUrls.filter(e=>0<e.errors.length).length||this.redirectTypeHasTarget()&&!this.targetUrl||this.customRulesError},getRelativeAbsolute(){const e=this.targetUrl.match(/^\/([a-zA-Z0-9_\-%]*\..*)\//);return e?e[0]:null},sourceUrl(){return 1<this.sourceUrls.length?this.$t.__("Source URLs",this.$td):this.$t.__("Source URL",this.$td)},addRedirect(){return 1<this.sourceUrls.length?this.$t.__("Add Redirects",this.$td):this.$t.__("Add Redirect",this.$td)},hasTargetUrlErrors(){if(!this.targetUrl)return[];const e=[],t=k(this.targetUrl);if(!t)return e.push(this.$t.__("Your target URL is not valid.",this.$td)),e;this.targetUrl&&!this.beginsWith(this.targetUrl,"https://")&&!this.beginsWith(this.targetUrl,"http://")&&this.targetUrl.substr(0,1)!=="/"&&e.push(this.$t.sprintf(this.$t.__("Your target URL should be an absolute URL like %1$s or start with a slash %2$s.",this.$td),"<code>https://domain.com/"+t+"</code>","<code>/"+t+"</code>"));const r=this.targetUrl.match(/[|\\$]/g);return r!==null&&(this.sourceUrls.map(s=>s.regex).every(s=>s)||e.push(this.$t.sprintf(this.$t.__("Your target URL contains the invalid character(s) %1$s",this.$td),"<code>"+r+"</code>"))),e},hasTargetUrlWarnings(){if(!k(this.targetUrl))return[];const e=[];return this.getRelativeAbsolute&&e.push(this.$t.sprintf(this.$t.__("Your URL appears to contain a domain inside the path: %1$s. Did you mean to use %2$s instead?",this.$td),"<code>"+this.getRelativeAbsolute+"</code>","<code>https:/"+this.getRelativeAbsolute+"</code>")),e},getDefaultRedirectType(){let e=this.getJsonValue(this.redirectsStore.options.redirectDefaults.redirectType);return e||(e=P[0]),e},getDefaultQueryParam(){let e=this.getJsonValue(this.redirectsStore.options.redirectDefaults.queryParam);return e||(e=$[0]),e},getDefaultSlash(){return this.redirectsStore.options.redirectDefaults.ignoreSlash},getDefaultCase(){return this.redirectsStore.options.redirectDefaults.ignoreCase},getDefaultSourceUrls(){return[JSON.parse(JSON.stringify(this.getDefaultSourceUrl))]},getDefaultSourceUrl(){return{id:null,url:null,regex:!1,ignoreSlash:this.slash||this.getDefaultSlash||!1,ignoreCase:this.case||this.getDefaultCase||!1,errors:[],warnings:[]}},redirectQueryParams(){return 0<this.sourceUrls.filter(e=>e.regex).length?$.map(e=>(e.$isDisabled=!1,e.value==="exact"&&(e.$isDisabled=!0,this.queryParam.value==="exact"&&(this.queryParam=$.find(t=>!t.$isDisabled))),e)):$.map(e=>(e.$isDisabled=!1,e))},unPublishedPost(){return this.redirectHasUnPublishedPost({post_id:this.postId,postStatus:this.postStatus})}},methods:{beginsWith(e,t){return t.indexOf(e)===0||e.substr(0,t.length)===t},addUrl(){this.sourceUrls.push(JSON.parse(JSON.stringify(this.getDefaultSourceUrl)))},removeUrl(e){this.sourceUrls.splice(e,1)},addRedirects(){this.genericError=!1,this.addingRedirect=!0,this.sourceUrls.map(e=>(e.url.substr(0,4)!=="http"&&e.url.substr(0,1)!=="/"&&0<e.url.length&&!e.regex&&(e.url="/"+e.url),e)),this.redirectsStore.create({sourceUrls:this.sourceUrls,targetUrl:this.targetUrl,queryParam:this.queryParam.value,customRules:this.customRules,redirectType:this.redirectType.value,redirectTypeHasTarget:this.redirectTypeHasTarget(),group:this.log404?"404":"manual",postId:this.postId}).then(()=>{this.$emit("added-redirect"),window.aioseoBus.$emit("added-redirect"),this.reset()}).catch(e=>{this.handleError(e)})},saveChanges(){this.genericError=!1,this.addingRedirect=!0,this.sourceUrls[0].url.substr(0,4)!=="http"&&this.sourceUrls[0].url.substr(0,1)!=="/"&&0<this.sourceUrls[0].url.length&&!this.sourceUrls[0].regex&&(this.sourceUrls[0].url="/"+this.sourceUrls[0].url),this.redirectsStore.update({id:this.sourceUrls[0].id,payload:{sourceUrls:this.sourceUrls,targetUrl:this.targetUrl,queryParam:this.queryParam.value,customRules:this.customRules,redirectType:this.redirectType.value,redirectTypeHasTarget:this.redirectTypeHasTarget(),postId:this.postId}}).then(()=>{this.$emit("added-redirect"),this.reset()}).catch(e=>{console.error(e),this.handleError(e)})},handleError(e){if(e.response.status!==409||!e.response.body.failed||!e.response.body.failed.length){this.genericError=!0,this.addingRedirect=!1;return}const t=[],r=e.response.body.failed,d=this.$t.__("A redirect already exists for this source URL. To make changes, edit the original instead.",this.$td);r.forEach(s=>{const i=this.sourceUrls.findIndex(n=>n.url===s.url||s);i!==-1&&(this.sourceUrls[i].errors.find(n=>n===s.error||n===d)||this.sourceUrls[i].errors.push(s.error||d),t.push(i))});for(let s=this.sourceUrls.length-1;0<=s;s--)t.includes(s)||this.sourceUrls.splice(s,1);this.addingRedirect=!1},updateTargetUrl(e){this.targetUrl=e,this.targetUrlErrors=this.hasTargetUrlErrors,this.targetUrlWarnings=this.hasTargetUrlWarnings},reset(){if(this.showAdvancedSettings=!1,this.addingRedirect=!1,this.edit)return;const e=P.find(r=>r.value===this.type)||this.getDefaultRedirectType,t=$.find(r=>r.value===this.query)||this.getDefaultQueryParam;this.sourceUrls=[JSON.parse(JSON.stringify(this.getDefaultSourceUrl))],this.targetUrl=null,this.targetUrlErrors=[],this.targetUrlWarnings=[],this.redirectType=e||{label:"301 "+this.$t.__("Moved Permanently",this.$td),value:301},this.queryParam=t||{label:this.$t.__("Ignore all parameters",this.$td),value:"ignore"},this.customRules=[]},checkForDuplicates(){const e=[];this.sourceUrls.forEach((t,r)=>{if(!(!t.url||t.errors.length)){if(e.includes(t.url.replace(/\/$/,""))){this.sourceUrls[r].errors.push(this.$t.__("This is a duplicate of a URL you are already adding. You can only add unique source URLs.",this.$td));return}e.push(t.url.replace(/\/$/,""))}}),this.updateTargetUrl(this.targetUrl)},redirectTypeHasTarget(){return this.redirectType&&(typeof this.redirectType.noTarget>"u"||!this.redirectType.noTarget)}},mounted(){this.sourceUrls.length||(this.sourceUrls=this.getDefaultSourceUrls),this.url&&(this.editing=!0,this.sourceUrls=[{...this.getDefaultSourceUrl,...this.url}]),this.urls&&this.urls.length&&(this.editing=!0,this.sourceUrls=this.urls.map(e=>({...this.getDefaultSourceUrl,...e}))),this.sourceDisabled=this.disableSource,this.unPublishedPost&&(this.sourceUrls=this.sourceUrls.map(e=>(e.url="("+this.strings.sourceUrlSetOncePublished+")",e)),this.sourceDisabled=!0),this.target&&(this.targetUrl=this.target),this.rules&&this.rules.length!==0&&(this.customRules=this.rules),this.redirectType=P.find(e=>e.value===this.type)||this.redirectType||this.getDefaultRedirectType,this.queryParam=$.find(e=>e.value===this.query)||this.queryParam||this.getDefaultQueryParam}},et={class:"urls"},tt={class:"source"},st={class:"aioseo-settings-row no-border no-margin small-padding"},rt={class:"settings-name"},it={class:"name small-margin"},lt=["innerHTML"],at={key:0,class:"url-arrow"},ot={key:1,class:"target"},ut={class:"aioseo-settings-row no-border no-margin small-padding"},nt={class:"settings-name"},ct={class:"name small-margin"},dt={class:"url"},ht={class:"aioseo-description"},gt=a("div",{class:"break"},null,-1),_t={class:"source"},mt=["innerHTML"],pt=a("div",{class:"url-arrow"},null,-1),ft=a("div",{class:"target"},null,-1),Rt={class:"all-settings"},St={class:"all-settings-content"},yt={class:"redirect-type"},Ut={class:"query-params"};function vt(e,t,r,d,s,i){const n=u("core-alert"),U=u("core-add-redirection-url"),S=u("base-button"),C=u("svg-right-arrow"),L=u("core-add-redirection-target-url"),T=u("transition-slide"),b=u("base-select"),A=u("custom-rules");return l(),p("div",{class:D(["aioseo-add-redirection",{"edit-url":r.edit,"log-404":r.log404}])},[s.genericError?(l(),g(n,{key:0,class:"generic-error",type:"red"},{default:m(()=>[y(R(s.strings.genericErrorMessage),1)]),_:1})):h("",!0),a("div",et,[a("div",tt,[a("div",st,[a("div",rt,[a("div",it,R(i.sourceUrl)+": ",1)]),(l(!0),p(E,null,w(i.sourceUrls,(f,v)=>(l(),g(U,{key:v,url:f,"allow-delete":1<i.sourceUrls.length,onRemoveUrl:o=>i.removeUrl(v),"target-url":i.targetUrl,log404:r.log404,disableSource:s.sourceDisabled},le({_:2},[r.edit&&!s.sourceDisabled?{name:"source-url-description",fn:m(()=>[a("div",{class:"aioseo-description source-description",innerHTML:s.strings.sourceUrlDescription},null,8,lt)]),key:"0"}:void 0]),1032,["url","allow-delete","onRemoveUrl","target-url","log404","disableSource"]))),128)),!r.edit&&!r.log404&&!s.sourceDisabled?(l(),g(S,{key:0,size:"small",type:"gray",onClick:i.addUrl},{default:m(()=>[y(R(s.strings.addUrl),1)]),_:1},8,["onClick"])):h("",!0)])]),i.redirectTypeHasTarget()?(l(),p("div",at,[_(C)])):h("",!0),i.redirectTypeHasTarget()?(l(),p("div",ot,[a("div",ut,[a("div",nt,[a("div",ct,R(s.strings.targetUrl)+": ",1)]),a("div",dt,[_(L,{url:i.targetUrl,errors:s.targetUrlErrors,warnings:s.targetUrlWarnings,"onUpdate:modelValue":i.updateTargetUrl},null,8,["url","errors","warnings","onUpdate:modelValue"]),a("div",ht,R(s.strings.targetUrlDescription),1),_(T,{active:!!s.targetUrlErrors.length},{default:m(()=>[a("div",null,[(l(!0),p(E,null,w(s.targetUrlErrors,(f,v)=>(l(),g(n,{key:v,class:"target-url-error",type:"red",size:"small",innerHTML:f},null,8,["innerHTML"]))),128))])]),_:1},8,["active"]),_(T,{active:!!s.targetUrlWarnings.length},{default:m(()=>[a("div",null,[(l(!0),p(E,null,w(s.targetUrlWarnings,(f,v)=>(l(),g(n,{key:v,class:"target-url-warning",type:"yellow",size:"small",innerHTML:f},null,8,["innerHTML"]))),128))])]),_:1},8,["active"])])])])):h("",!0),!r.edit&&!r.log404&&!s.sourceDisabled?(l(),p(E,{key:2},[gt,a("div",_t,[a("div",{class:"aioseo-description source-description",innerHTML:s.strings.sourceUrlDescription},null,8,mt)]),pt,ft],64)):h("",!0)]),a("div",{class:D(["settings",{advanced:i.showAdvancedSettings}])},[a("div",Rt,[a("div",St,[a("div",yt,[y(R(s.strings.redirectType)+" ",1),_(b,{options:s.REDIRECT_TYPES,modelValue:i.redirectType,"onUpdate:modelValue":t[0]||(t[0]=f=>i.redirectType=f),size:"medium"},null,8,["options","modelValue"])]),_(T,{class:"advanced-settings",active:i.showAdvancedSettings},{default:m(()=>[a("div",Ut,[y(R(s.strings.queryParams)+" ",1),_(b,{options:i.redirectQueryParams,modelValue:i.queryParam,"onUpdate:modelValue":t[1]||(t[1]=f=>i.queryParam=f),size:"medium"},null,8,["options","modelValue"])])]),_:1},8,["active"]),i.showAdvancedSettings?h("",!0):(l(),p("a",{key:0,class:"advanced-settings-link",href:"#",onClick:t[2]||(t[2]=Y(f=>i.showAdvancedSettings=!i.showAdvancedSettings,["prevent"]))},R(s.strings.advancedSettings),1))])]),_(T,{class:"advanced-settings",active:i.showAdvancedSettings},{default:m(()=>[(l(),g(A,{key:i.customRules,"edit-custom-rules":i.customRules,onRedirectsCustomRuleError:t[3]||(t[3]=f=>this.customRulesError=f)},null,8,["edit-custom-rules"]))]),_:1},8,["active"]),a("div",{class:D(["actions",{advanced:i.showAdvancedSettings}])},[_(S,{size:"medium",type:"blue",onClick:t[4]||(t[4]=f=>r.edit?i.saveChanges():i.addRedirects()),loading:s.addingRedirect,disabled:i.saveIsDisabled},{default:m(()=>[y(R(r.edit?s.strings.saveChanges:i.addRedirect),1)]),_:1},8,["loading","disabled"]),r.edit?(l(),g(S,{key:0,size:"medium",type:"gray",onClick:t[5]||(t[5]=f=>e.$emit("cancel",!0)),class:"cancel-edit-row"},{default:m(()=>[y(R(s.strings.cancel),1)]),_:1})):h("",!0)],2)],2)],2)}const qt=V(Xe,[["render",vt]]);export{qt as C};