Improve CSV importer close #50
This commit is contained in:
@@ -106,6 +106,15 @@
|
|||||||
margin: 0;
|
margin: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.sportspress table.form-table .forminp-radio ul li {
|
||||||
|
display: inline;
|
||||||
|
margin-right: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sportspress table.form-table .forminp-radio ul li label.post-format-icon {
|
||||||
|
margin-top: 0 !important;
|
||||||
|
}
|
||||||
|
|
||||||
.sportspress table.form-table fieldset {
|
.sportspress table.form-table fieldset {
|
||||||
margin-top: 4px;
|
margin-top: 4px;
|
||||||
}
|
}
|
||||||
@@ -483,6 +492,44 @@ table.sp_status_table td mark.yes {
|
|||||||
color: #7ad03a;
|
color: #7ad03a;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Importers */
|
||||||
|
#import-upload-form table.form-table th,
|
||||||
|
#import-upload-form table.form-table td {
|
||||||
|
padding-bottom: 0;
|
||||||
|
}
|
||||||
|
#import-upload-form table.form-table tbody tr:last-child td {
|
||||||
|
padding-bottom: 20px;
|
||||||
|
}
|
||||||
|
.sp-import-table th,
|
||||||
|
.sp-import-table td {
|
||||||
|
padding-right: 0;
|
||||||
|
}
|
||||||
|
.sp-import-table th:last-child,
|
||||||
|
.sp-import-table td:last-child {
|
||||||
|
padding-right: 10px;
|
||||||
|
}
|
||||||
|
.sp-import-table tbody tr:nth-child(2n-1) {
|
||||||
|
background: #f9f9f9;
|
||||||
|
}
|
||||||
|
.sp-import-table select {
|
||||||
|
max-width: 100%;
|
||||||
|
}
|
||||||
|
.sp-import-table .sp-actions-column {
|
||||||
|
width: 40px;
|
||||||
|
text-align: right;
|
||||||
|
}
|
||||||
|
.sp-import-table .sp-add-row {
|
||||||
|
line-height: 1.5;
|
||||||
|
}
|
||||||
|
.sp-import-table .sp-delete-row {
|
||||||
|
font-size: 16px;
|
||||||
|
line-height: 1.5;
|
||||||
|
color: #a00;
|
||||||
|
}
|
||||||
|
.sp-import-table .sp-delete-row:hover {
|
||||||
|
color: #f00;
|
||||||
|
}
|
||||||
|
|
||||||
/* Media Queries */
|
/* Media Queries */
|
||||||
@media only screen and (max-width: 782px) {
|
@media only screen and (max-width: 782px) {
|
||||||
|
|
||||||
|
|||||||
@@ -60,6 +60,9 @@
|
|||||||
.sp-icon-smile:before {
|
.sp-icon-smile:before {
|
||||||
content: "\f328";
|
content: "\f328";
|
||||||
}
|
}
|
||||||
|
.sp-icon-trash:before {
|
||||||
|
content: "\f153";
|
||||||
|
}
|
||||||
|
|
||||||
#adminmenu #toplevel_page_sportspress .toplevel_page_sportspress div.wp-menu-image:before,
|
#adminmenu #toplevel_page_sportspress .toplevel_page_sportspress div.wp-menu-image:before,
|
||||||
#adminmenu #menu-posts-sp_event .menu-icon-sp_event div.wp-menu-image:before,
|
#adminmenu #menu-posts-sp_event .menu-icon-sp_event div.wp-menu-image:before,
|
||||||
@@ -84,12 +87,15 @@
|
|||||||
box-shadow: none;
|
box-shadow: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.sp-prefs .button input[type=checkbox]:before {
|
||||||
|
font: 400 14px/22px sportspress, dashicons;
|
||||||
|
width: 22px;
|
||||||
|
}
|
||||||
|
|
||||||
.sp-prefs .button input[type=checkbox]:not(:checked):before {
|
.sp-prefs .button input[type=checkbox]:not(:checked):before {
|
||||||
float: left;
|
float: left;
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
vertical-align: middle;
|
vertical-align: middle;
|
||||||
width: 16px;
|
|
||||||
font: 400 21px/1 dashicons;
|
|
||||||
speak: none;
|
speak: none;
|
||||||
-webkit-font-smoothing: antialiased;
|
-webkit-font-smoothing: antialiased;
|
||||||
-moz-osx-font-smoothing: grayscale;
|
-moz-osx-font-smoothing: grayscale;
|
||||||
@@ -99,11 +105,9 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* TinyMCE */
|
/* TinyMCE */
|
||||||
|
|
||||||
.mce-toolbar i.mce-i-sp_shortcodes_button, .mce-toolbar span.mce_sp_shortcodes_button {
|
.mce-toolbar i.mce-i-sp_shortcodes_button, .mce-toolbar span.mce_sp_shortcodes_button {
|
||||||
margin-right: -5px;
|
margin-right: -5px;
|
||||||
}
|
}
|
||||||
|
|
||||||
i.mce-i-sp_shortcodes_button:before, span.mce_sp_shortcodes_button:before {
|
i.mce-i-sp_shortcodes_button:before, span.mce_sp_shortcodes_button:before {
|
||||||
font-family: 'sportspress';
|
font-family: 'sportspress';
|
||||||
speak: none;
|
speak: none;
|
||||||
|
|||||||
Binary file not shown.
@@ -9,6 +9,8 @@
|
|||||||
<glyph unicode=" " d="" horiz-adv-x="256" />
|
<glyph unicode=" " d="" horiz-adv-x="256" />
|
||||||
<glyph unicode="" d="M383.6 235.2v149.2h25.6c14.16 0 25.6-11.44 25.6-25.6v-51.2c0-33.44-21.36-61.84-51.2-72.4zM358 384.4v-153.6c0-56.56-45.84-102.4-102.4-102.4s-102.4 45.84-102.4 102.4v153.6c0 0 0 0 0 0v51.2h204.8v-51.2c0 0 0 0 0 0v0zM76.4 307.6v0 51.2c0 14.16 11.44 25.6 25.6 25.6h25.6v-149.2c-29.84 10.56-51.2 38.96-51.2 72.4zM191.76 51.92h38.24v25.28c0 14.16 11.44 25.6 25.6 25.6s25.6-11.44 25.6-25.6v-25.28h38.24c7.12 0 12.96-5.76 12.96-12.96s-5.76-12.96-12.96-12.96h-127.68c-7.12 0-12.96 5.76-12.96 12.96s5.76 12.96 12.96 12.96z" />
|
<glyph unicode="" d="M383.6 235.2v149.2h25.6c14.16 0 25.6-11.44 25.6-25.6v-51.2c0-33.44-21.36-61.84-51.2-72.4zM358 384.4v-153.6c0-56.56-45.84-102.4-102.4-102.4s-102.4 45.84-102.4 102.4v153.6c0 0 0 0 0 0v51.2h204.8v-51.2c0 0 0 0 0 0v0zM76.4 307.6v0 51.2c0 14.16 11.44 25.6 25.6 25.6h25.6v-149.2c-29.84 10.56-51.2 38.96-51.2 72.4zM191.76 51.92h38.24v25.28c0 14.16 11.44 25.6 25.6 25.6s25.6-11.44 25.6-25.6v-25.28h38.24c7.12 0 12.96-5.76 12.96-12.96s-5.76-12.96-12.96-12.96h-127.68c-7.12 0-12.96 5.76-12.96 12.96s5.76 12.96 12.96 12.96z" />
|
||||||
<glyph unicode="" d="M384 435.2h-51.2v-51.2h51.2v51.2zM435.2 435.2h-25.6v-76.8h-102.4v76.8h-102.4v-76.8h-102.4v76.8h-25.6c-14.16 0-25.6-11.44-25.6-25.6v-358.4c0-14.16 11.44-25.6 25.6-25.6h358.4c14.16 0 25.6 11.44 25.6 25.6v358.4c0 14.16-11.44 25.6-25.6 25.6zM409.6 76.8h-307.2v230.4h307.2v-230.4zM179.2 435.2h-51.2v-51.2h51.2v51.2zM281.6 256h-51.2v-51.2h51.2v51.2zM358.4 256h-51.2v-51.2h51.2v51.2zM204.8 179.2h-51.2v-51.2h51.2v51.2zM204.8 256h-51.2v-51.2h51.2v51.2zM281.6 179.2h-51.2v-51.2h51.2v51.2zM358.4 179.2h-51.2v-51.2h51.2v51.2z" />
|
<glyph unicode="" d="M384 435.2h-51.2v-51.2h51.2v51.2zM435.2 435.2h-25.6v-76.8h-102.4v76.8h-102.4v-76.8h-102.4v76.8h-25.6c-14.16 0-25.6-11.44-25.6-25.6v-358.4c0-14.16 11.44-25.6 25.6-25.6h358.4c14.16 0 25.6 11.44 25.6 25.6v358.4c0 14.16-11.44 25.6-25.6 25.6zM409.6 76.8h-307.2v230.4h307.2v-230.4zM179.2 435.2h-51.2v-51.2h51.2v51.2zM281.6 256h-51.2v-51.2h51.2v51.2zM358.4 256h-51.2v-51.2h51.2v51.2zM204.8 179.2h-51.2v-51.2h51.2v51.2zM204.8 256h-51.2v-51.2h51.2v51.2zM281.6 179.2h-51.2v-51.2h51.2v51.2zM358.4 179.2h-51.2v-51.2h51.2v51.2z" />
|
||||||
|
<glyph unicode="" d="M256 426.667c-92.805 0-185.597-66.375-256-199.111 70.403-132.736 163.195-199.111 256-199.111s185.597 66.375 256 199.111c-70.403 132.736-163.195 199.111-256 199.111zM256 85.334c-67.486 0-135.945 51.43-190.667 142.222 54.722 90.792 123.18 142.222 190.667 142.222s135.945-51.43 190.667-142.222c-54.722-90.792-123.18-142.222-190.667-142.222zM312.889 227.556c0-31.417-25.472-56.889-56.889-56.889s-56.889 25.472-56.889 56.889 25.472 56.889 56.889 56.889 56.889-25.472 56.889-56.889z" />
|
||||||
|
<glyph unicode="" d="M288 256h64v-160h-64zM480 384h-128v64c0 17.688-14.312 32-32 32h-128c-17.688 0-32-14.312-32-32v-64h-128c-17.688 0-32-14.312-32-32v-32h32v-320c0-17.688 14.312-32 32-32h384c17.688 0 32 14.312 32 32v320h32v32c0 17.688-14.312 32-32 32zM224 416h64v-32h-64v32zM416 32h-320v288h320v-288zM160 256h64v-160h-64z" />
|
||||||
<glyph unicode="" d="M153.6 332.8h51.2v-51.2h-51.2v51.2zM153.6 256h51.2v-51.2h-51.2v51.2zM153.6 179.2h51.2v-51.2h-51.2v51.2zM256 179.2h102.4v-51.2h-102.4v51.2zM435.2 435.2h-358.4c-14.16 0-25.6-11.44-25.6-25.6v-358.4c0-14.16 11.44-25.6 25.6-25.6h358.4c14.16 0 25.6 11.44 25.6 25.6v358.4c0 14.16-11.44 25.6-25.6 25.6zM409.6 76.8h-307.2v307.2h307.2v-307.2zM256 256h102.4v-51.2h-102.4v51.2zM256 332.8h102.4v-51.2h-102.4v51.2z" />
|
<glyph unicode="" d="M153.6 332.8h51.2v-51.2h-51.2v51.2zM153.6 256h51.2v-51.2h-51.2v51.2zM153.6 179.2h51.2v-51.2h-51.2v51.2zM256 179.2h102.4v-51.2h-102.4v51.2zM435.2 435.2h-358.4c-14.16 0-25.6-11.44-25.6-25.6v-358.4c0-14.16 11.44-25.6 25.6-25.6h358.4c14.16 0 25.6 11.44 25.6 25.6v358.4c0 14.16-11.44 25.6-25.6 25.6zM409.6 76.8h-307.2v307.2h307.2v-307.2zM256 256h102.4v-51.2h-102.4v51.2zM256 332.8h102.4v-51.2h-102.4v51.2z" />
|
||||||
<glyph unicode="" d="M153.6 179.2h204.8v-51.2h-204.8v51.2zM153.6 256h204.8v-51.2h-204.8v51.2zM435.2 435.2h-358.4c-14.16 0-25.6-11.44-25.6-25.6v-358.4c0-14.16 11.44-25.6 25.6-25.6h358.4c14.16 0 25.6 11.44 25.6 25.6v358.4c0 14.16-11.44 25.6-25.6 25.6zM409.6 76.8h-307.2v307.2h307.2v-307.2zM153.6 332.8h204.8v-51.2h-204.8v51.2z" />
|
<glyph unicode="" d="M153.6 179.2h204.8v-51.2h-204.8v51.2zM153.6 256h204.8v-51.2h-204.8v51.2zM435.2 435.2h-358.4c-14.16 0-25.6-11.44-25.6-25.6v-358.4c0-14.16 11.44-25.6 25.6-25.6h358.4c14.16 0 25.6 11.44 25.6 25.6v358.4c0 14.16-11.44 25.6-25.6 25.6zM409.6 76.8h-307.2v307.2h307.2v-307.2zM153.6 332.8h204.8v-51.2h-204.8v51.2z" />
|
||||||
<glyph unicode="" d="M296 256c6.88-15.68 10.8-32.96 10.8-51.2 0-70.72-57.28-128-128-128s-128 57.28-128 128c0 31.12 11.6 59.28 30.080 81.52-17.68 8.080-30.080 25.84-30.080 46.48 0 28.24 22.96 51.2 51.2 51.2s51.2-22.96 51.2-51.2c0-0.88-0.24-1.76-0.24-2.64 8.32 1.68 17.040 2.64 25.84 2.64h281.6v-76.8h-164.4zM102 358.4c-14.16 0-25.6-11.44-25.6-25.6s11.44-25.6 25.6-25.6 25.6 11.44 25.6 25.6-11.44 25.6-25.6 25.6z" />
|
<glyph unicode="" d="M296 256c6.88-15.68 10.8-32.96 10.8-51.2 0-70.72-57.28-128-128-128s-128 57.28-128 128c0 31.12 11.6 59.28 30.080 81.52-17.68 8.080-30.080 25.84-30.080 46.48 0 28.24 22.96 51.2 51.2 51.2s51.2-22.96 51.2-51.2c0-0.88-0.24-1.76-0.24-2.64 8.32 1.68 17.040 2.64 25.84 2.64h281.6v-76.8h-164.4zM102 358.4c-14.16 0-25.6-11.44-25.6-25.6s11.44-25.6 25.6-25.6 25.6 11.44 25.6 25.6-11.44 25.6-25.6 25.6z" />
|
||||||
@@ -16,6 +18,7 @@
|
|||||||
<glyph unicode="" d="M435.2 332.8h-0.8l0.8-177.6v-1.6c0-6.96-2.56-12.96-7.6-18s-11.040-7.6-18-7.6h-307.2c-7.2 0-13.28 2.56-18.24 7.6s-7.36 11.040-7.36 18v1.6l0.8 177.6h-0.8c-7.2 0-13.28 2.48-18.24 7.36s-7.36 11.040-7.36 18.24 2.48 13.28 7.36 18.24 10.96 7.36 18.080 7.36 13.12-2.48 18.24-7.36 7.52-11.040 7.52-18.24c0-8.8-3.6-15.76-10.8-20.8l87.6-124 66.4 147.2c-4.56 1.84-8.16 4.96-11.040 9.2s-4.16 8.96-4.16 14c0 7.2 2.48 13.28 7.36 18.24s10.96 7.36 18 7.36 13.12-2.48 18.24-7.36 7.6-11.040 7.6-18.24c0-5.040-1.44-9.76-4.16-14s-6.48-7.36-11.040-9.2l66.4-147.2 87.6 124c-7.2 5.040-10.8 12-10.8 20.8 0 7.2 2.48 13.28 7.36 18.24s10.96 7.36 18 7.36 13.12-2.48 18.24-7.36 7.6-11.040 7.6-18.24-2.56-13.28-7.6-18.24-11.040-7.36-18-7.36zM76.8 102.4h358.4c6.96 0 12.96-2.48 18-7.36s7.6-10.96 7.6-18-2.56-13.12-7.6-18.24-11.040-7.6-18-7.6h-358.4c-6.96 0-12.96 2.56-18 7.6s-7.6 11.12-7.6 18.16 2.48 13.040 7.36 18 11.040 7.44 18.24 7.44z" />
|
<glyph unicode="" d="M435.2 332.8h-0.8l0.8-177.6v-1.6c0-6.96-2.56-12.96-7.6-18s-11.040-7.6-18-7.6h-307.2c-7.2 0-13.28 2.56-18.24 7.6s-7.36 11.040-7.36 18v1.6l0.8 177.6h-0.8c-7.2 0-13.28 2.48-18.24 7.36s-7.36 11.040-7.36 18.24 2.48 13.28 7.36 18.24 10.96 7.36 18.080 7.36 13.12-2.48 18.24-7.36 7.52-11.040 7.52-18.24c0-8.8-3.6-15.76-10.8-20.8l87.6-124 66.4 147.2c-4.56 1.84-8.16 4.96-11.040 9.2s-4.16 8.96-4.16 14c0 7.2 2.48 13.28 7.36 18.24s10.96 7.36 18 7.36 13.12-2.48 18.24-7.36 7.6-11.040 7.6-18.24c0-5.040-1.44-9.76-4.16-14s-6.48-7.36-11.040-9.2l66.4-147.2 87.6 124c-7.2 5.040-10.8 12-10.8 20.8 0 7.2 2.48 13.28 7.36 18.24s10.96 7.36 18 7.36 13.12-2.48 18.24-7.36 7.6-11.040 7.6-18.24-2.56-13.28-7.6-18.24-11.040-7.36-18-7.36zM76.8 102.4h358.4c6.96 0 12.96-2.48 18-7.36s7.6-10.96 7.6-18-2.56-13.12-7.6-18.24-11.040-7.6-18-7.6h-358.4c-6.96 0-12.96 2.56-18 7.6s-7.6 11.12-7.6 18.16 2.48 13.040 7.36 18 11.040 7.44 18.24 7.44z" />
|
||||||
<glyph unicode="" d="M324 179.28c-7.040-23.040-20.16-41.6-39.44-55.68-19.2-14.080-40.96-21.12-65.12-21.12s-45.92 7.040-65.12 21.12c-19.2 14.080-32.4 32.64-39.44 55.68-1.52 4.8-1.12 9.36 1.12 13.84 2.32 4.48 5.92 7.44 10.88 8.96 4.8 1.52 9.36 1.12 13.84-1.12 4.48-2.32 7.44-5.92 8.96-10.88 4.8-15.2 13.6-27.6 26.4-36.96 12.88-9.44 27.28-14.16 43.28-14.16s30.4 4.72 43.28 14.16c12.88 9.44 21.68 21.76 26.4 36.96 1.52 4.96 4.56 8.56 9.12 10.88s9.2 2.64 14 1.12c4.8-1.52 8.32-4.56 10.56-8.96 2.4-4.48 2.8-9.12 1.28-13.84v0zM182.88 303.52c0-10.080-3.6-18.72-10.72-25.84s-15.76-10.72-25.84-10.72c-10.080 0-18.72 3.6-25.84 10.72s-10.72 15.76-10.72 25.84 3.6 18.72 10.72 25.84c7.12 7.12 15.76 10.72 25.84 10.72s18.72-3.6 25.84-10.72c7.12-7.12 10.72-15.76 10.72-25.84v0zM329.12 303.52c0-10.080-3.6-18.72-10.72-25.84s-15.76-10.72-25.84-10.72c-10.080 0-18.72 3.6-25.84 10.72s-10.72 15.76-10.72 25.84 3.6 18.72 10.72 25.84c7.12 7.12 15.76 10.72 25.84 10.72s18.72-3.6 25.84-10.72c7.2-7.12 10.72-15.76 10.72-25.84v0zM402.32 230.4c0 24.8-4.88 48.4-14.56 70.96s-22.72 42-39.040 58.32-35.68 29.28-58.32 39.040-46.24 14.56-71.040 14.56c-24.8 0-48.4-4.88-71.040-14.56-22.56-9.68-42-22.72-58.32-39.040s-29.12-35.68-38.88-58.32-14.56-46.16-14.56-70.96c0-24.8 4.88-48.4 14.56-71.040s22.72-42 39.040-58.32c16.32-16.32 35.68-29.28 58.32-39.040s46.24-14.56 71.040-14.56 48.4 4.88 71.040 14.56c22.56 9.68 42 22.72 58.32 39.040s29.28 35.68 39.040 58.32c9.52 22.64 14.4 46.32 14.4 71.040v0zM438.88 230.4c0-39.84-9.84-76.56-29.44-110.16s-46.24-60.24-79.84-79.84-70.32-29.44-110.16-29.44-76.56 9.84-110.16 29.44-60.24 46.24-79.84 79.84-29.44 70.32-29.44 110.16 9.84 76.56 29.44 110.16 46.24 60.24 79.84 79.84 70.32 29.44 110.16 29.44 76.48-9.84 110.16-29.44 60.24-46.24 79.84-79.84c19.6-33.6 29.44-70.32 29.44-110.16v0z" horiz-adv-x="439" />
|
<glyph unicode="" d="M324 179.28c-7.040-23.040-20.16-41.6-39.44-55.68-19.2-14.080-40.96-21.12-65.12-21.12s-45.92 7.040-65.12 21.12c-19.2 14.080-32.4 32.64-39.44 55.68-1.52 4.8-1.12 9.36 1.12 13.84 2.32 4.48 5.92 7.44 10.88 8.96 4.8 1.52 9.36 1.12 13.84-1.12 4.48-2.32 7.44-5.92 8.96-10.88 4.8-15.2 13.6-27.6 26.4-36.96 12.88-9.44 27.28-14.16 43.28-14.16s30.4 4.72 43.28 14.16c12.88 9.44 21.68 21.76 26.4 36.96 1.52 4.96 4.56 8.56 9.12 10.88s9.2 2.64 14 1.12c4.8-1.52 8.32-4.56 10.56-8.96 2.4-4.48 2.8-9.12 1.28-13.84v0zM182.88 303.52c0-10.080-3.6-18.72-10.72-25.84s-15.76-10.72-25.84-10.72c-10.080 0-18.72 3.6-25.84 10.72s-10.72 15.76-10.72 25.84 3.6 18.72 10.72 25.84c7.12 7.12 15.76 10.72 25.84 10.72s18.72-3.6 25.84-10.72c7.12-7.12 10.72-15.76 10.72-25.84v0zM329.12 303.52c0-10.080-3.6-18.72-10.72-25.84s-15.76-10.72-25.84-10.72c-10.080 0-18.72 3.6-25.84 10.72s-10.72 15.76-10.72 25.84 3.6 18.72 10.72 25.84c7.12 7.12 15.76 10.72 25.84 10.72s18.72-3.6 25.84-10.72c7.2-7.12 10.72-15.76 10.72-25.84v0zM402.32 230.4c0 24.8-4.88 48.4-14.56 70.96s-22.72 42-39.040 58.32-35.68 29.28-58.32 39.040-46.24 14.56-71.040 14.56c-24.8 0-48.4-4.88-71.040-14.56-22.56-9.68-42-22.72-58.32-39.040s-29.12-35.68-38.88-58.32-14.56-46.16-14.56-70.96c0-24.8 4.88-48.4 14.56-71.040s22.72-42 39.040-58.32c16.32-16.32 35.68-29.28 58.32-39.040s46.24-14.56 71.040-14.56 48.4 4.88 71.040 14.56c22.56 9.68 42 22.72 58.32 39.040s29.28 35.68 39.040 58.32c9.52 22.64 14.4 46.32 14.4 71.040v0zM438.88 230.4c0-39.84-9.84-76.56-29.44-110.16s-46.24-60.24-79.84-79.84-70.32-29.44-110.16-29.44-76.56 9.84-110.16 29.44-60.24 46.24-79.84 79.84-29.44 70.32-29.44 110.16 9.84 76.56 29.44 110.16 46.24 60.24 79.84 79.84 70.32 29.44 110.16 29.44 76.48-9.84 110.16-29.44 60.24-46.24 79.84-79.84c19.6-33.6 29.44-70.32 29.44-110.16v0z" horiz-adv-x="439" />
|
||||||
<glyph unicode="" d="M425.76 154.48c-6.16-15.76-14-29.84-23.2-42s-20.24-24.080-33.040-35.68c-12.8-11.52-24.56-21.2-35.36-28.88-10.88-7.6-22.080-14.88-33.84-21.68-11.84-6.8-20.16-11.44-25.12-13.92-4.96-2.4-8.96-4.24-11.92-5.52-2.24-1.2-4.64-1.68-7.28-1.68s-5.040 0.64-7.28 1.68c-3.040 1.28-6.88 3.12-11.92 5.52s-13.36 7.040-25.12 13.92c-11.76 6.8-23.040 14-33.84 21.68-10.88 7.68-22.56 17.28-35.36 28.88-12.8 11.52-23.84 23.36-33.040 35.68s-16.96 26.24-23.2 42c-6.32 15.76-9.44 31.76-9.44 47.76v215.040c0 4.8 1.68 9.12 5.28 12.64s7.76 5.28 12.64 5.28h322.56c4.8 0 9.12-1.68 12.64-5.28s5.28-7.76 5.28-12.64v-215.040c0-16-3.2-32-9.44-47.76v0zM384 384h-256v-181.92c0-33.36 22.4-67.52 67.12-102.32 17.92-14 38.24-27.040 60.88-38.96v0 0 0 0c22.64 11.92 42.96 24.96 60.88 38.96 44.72 34.88 67.12 68.96 67.12 102.32v181.92zM304.72 122.8c-14.32-11.6-30.56-22.4-48.72-32.24v0 0 267.68h102.4v-150.72c0-27.6-17.92-55.84-53.68-84.72v0z" />
|
<glyph unicode="" d="M425.76 154.48c-6.16-15.76-14-29.84-23.2-42s-20.24-24.080-33.040-35.68c-12.8-11.52-24.56-21.2-35.36-28.88-10.88-7.6-22.080-14.88-33.84-21.68-11.84-6.8-20.16-11.44-25.12-13.92-4.96-2.4-8.96-4.24-11.92-5.52-2.24-1.2-4.64-1.68-7.28-1.68s-5.040 0.64-7.28 1.68c-3.040 1.28-6.88 3.12-11.92 5.52s-13.36 7.040-25.12 13.92c-11.76 6.8-23.040 14-33.84 21.68-10.88 7.68-22.56 17.28-35.36 28.88-12.8 11.52-23.84 23.36-33.040 35.68s-16.96 26.24-23.2 42c-6.32 15.76-9.44 31.76-9.44 47.76v215.040c0 4.8 1.68 9.12 5.28 12.64s7.76 5.28 12.64 5.28h322.56c4.8 0 9.12-1.68 12.64-5.28s5.28-7.76 5.28-12.64v-215.040c0-16-3.2-32-9.44-47.76v0zM384 384h-256v-181.92c0-33.36 22.4-67.52 67.12-102.32 17.92-14 38.24-27.040 60.88-38.96v0 0 0 0c22.64 11.92 42.96 24.96 60.88 38.96 44.72 34.88 67.12 68.96 67.12 102.32v181.92zM304.72 122.8c-14.32-11.6-30.56-22.4-48.72-32.24v0 0 267.68h102.4v-150.72c0-27.6-17.92-55.84-53.68-84.72v0z" />
|
||||||
|
<glyph unicode="" d="M256 455.111c-125.681 0-227.555-101.874-227.555-227.555s101.875-227.555 227.555-227.555 227.555 101.875 227.555 227.555-101.875 227.555-227.555 227.555zM85.334 227.556c0 36.82 11.833 70.847 31.736 98.764l237.694-237.694c-27.916-19.903-61.944-31.736-98.764-31.736-94.111 0-170.667 76.555-170.667 170.667zM394.93 128.792l-237.694 237.694c27.917 19.903 61.944 31.736 98.763 31.736 94.111 0 170.667-76.555 170.667-170.667 0-36.82-11.833-70.847-31.736-98.763z" />
|
||||||
<glyph unicode="" d="M256 465.92c-130.080 0-235.52-105.44-235.52-235.52s105.44-235.52 235.52-235.52 235.52 105.44 235.52 235.52c0 130.080-105.44 235.52-235.52 235.52v0zM256 46.080c-101.84 0-184.32 82.56-184.32 184.32s82.48 184.32 184.32 184.32 184.32-82.56 184.32-184.32-82.48-184.32-184.32-184.32v0zM273.92 363.52h-35.84v-140.56l87.2-87.2 25.36 25.36-76.64 76.64v125.76z" />
|
<glyph unicode="" d="M256 465.92c-130.080 0-235.52-105.44-235.52-235.52s105.44-235.52 235.52-235.52 235.52 105.44 235.52 235.52c0 130.080-105.44 235.52-235.52 235.52v0zM256 46.080c-101.84 0-184.32 82.56-184.32 184.32s82.48 184.32 184.32 184.32 184.32-82.56 184.32-184.32-82.48-184.32-184.32-184.32v0zM273.92 363.52h-35.84v-140.56l87.2-87.2 25.36 25.36-76.64 76.64v125.76z" />
|
||||||
<glyph unicode="" d="M376.16 25.6h-238.080c-20.48 0-35.84 15.36-35.84 35.84v312.32c0 10.24 5.12 20.48 12.8 28.16l28.16-66.56h225.28l28.16 69.12c7.68-5.12 12.8-15.36 12.8-28.16v-312.32c2.56-23.040-15.36-38.4-33.28-38.4zM358.24 307.2h-204.8v-230.4h204.8v230.4zM332.64 230.4h-153.6v25.6h153.6v-25.6zM332.64 179.2h-153.6v25.6h153.6v-25.6zM332.64 128h-153.6v25.6h153.6v-25.6zM163.68 358.4l-23.040 51.2h56.32l7.68 20.48 10.24 30.72h81.92l10.24-30.72 10.24-20.48h56.32l-23.040-51.2h-186.88z" />
|
<glyph unicode="" d="M376.16 25.6h-238.080c-20.48 0-35.84 15.36-35.84 35.84v312.32c0 10.24 5.12 20.48 12.8 28.16l28.16-66.56h225.28l28.16 69.12c7.68-5.12 12.8-15.36 12.8-28.16v-312.32c2.56-23.040-15.36-38.4-33.28-38.4zM358.24 307.2h-204.8v-230.4h204.8v230.4zM332.64 230.4h-153.6v25.6h153.6v-25.6zM332.64 179.2h-153.6v25.6h153.6v-25.6zM332.64 128h-153.6v25.6h153.6v-25.6zM163.68 358.4l-23.040 51.2h56.32l7.68 20.48 10.24 30.72h81.92l10.24-30.72 10.24-20.48h56.32l-23.040-51.2h-186.88z" />
|
||||||
<glyph unicode="" d="M430.8 56.56l-116.8 97.2h-160.4v-76.8c0-7.2-2.56-13.28-7.6-18.24s-11.040-7.36-18-7.36h-25.6c-7.2 0-13.28 2.48-18.24 7.36s-7.36 11.040-7.36 18.24v76.8c-7.2 0-13.28 2.48-18.24 7.36s-7.36 11.040-7.36 18.24v128c0 7.2 2.48 13.28 7.36 18.24s11.040 7.36 18.24 7.36h237.2l116.8 97.2c2.96 3.2 6.88 4.88 11.84 4.96s9.2-0.88 12.8-3.040c3.6-2.16 5.44-4.8 5.44-8v-362c0-3.2-1.76-5.84-5.44-8s-7.84-3.040-12.8-2.8c-5.040 0.4-8.88 2.080-11.84 5.28zM243.2 332.96h-51.2c3.44 0 6.48-1.28 8.96-3.84s3.84-5.52 3.84-8.96v-153.6c0-3.44-1.28-6.48-3.84-8.96s-5.52-3.84-8.96-3.84h51.2c-3.76 0-6.8 1.28-9.2 3.84s-3.6 5.52-3.6 8.96v153.6c0 3.44 1.2 6.48 3.6 8.96s5.36 3.84 9.2 3.84v0z" />
|
<glyph unicode="" d="M430.8 56.56l-116.8 97.2h-160.4v-76.8c0-7.2-2.56-13.28-7.6-18.24s-11.040-7.36-18-7.36h-25.6c-7.2 0-13.28 2.48-18.24 7.36s-7.36 11.040-7.36 18.24v76.8c-7.2 0-13.28 2.48-18.24 7.36s-7.36 11.040-7.36 18.24v128c0 7.2 2.48 13.28 7.36 18.24s11.040 7.36 18.24 7.36h237.2l116.8 97.2c2.96 3.2 6.88 4.88 11.84 4.96s9.2-0.88 12.8-3.040c3.6-2.16 5.44-4.8 5.44-8v-362c0-3.2-1.76-5.84-5.44-8s-7.84-3.040-12.8-2.8c-5.040 0.4-8.88 2.080-11.84 5.28zM243.2 332.96h-51.2c3.44 0 6.48-1.28 8.96-3.84s3.84-5.52 3.84-8.96v-153.6c0-3.44-1.28-6.48-3.84-8.96s-5.52-3.84-8.96-3.84h51.2c-3.76 0-6.8 1.28-9.2 3.84s-3.6 5.52-3.6 8.96v153.6c0 3.44 1.2 6.48 3.6 8.96s5.36 3.84 9.2 3.84v0z" />
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 8.0 KiB After Width: | Height: | Size: 9.3 KiB |
Binary file not shown.
Binary file not shown.
@@ -466,4 +466,53 @@ jQuery(document).ready(function($){
|
|||||||
nonce: $("#sp-config-nonce").val()
|
nonce: $("#sp-config-nonce").val()
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Update importer post count
|
||||||
|
$(".sp-import-table").on("updatePostCount", function() {
|
||||||
|
$(".sp-post-count").text(localized_strings.displaying_posts.replace("%s", 1).replace(/%s/g, count = $(this).find("tbody tr").length));
|
||||||
|
});
|
||||||
|
|
||||||
|
// Delete importer row
|
||||||
|
$(".sp-import-table").on("click", ".sp-delete-row", function() {
|
||||||
|
$self = $(this);
|
||||||
|
$self.closest("tr").css("background-color", "#fcc").fadeOut(400, function() {
|
||||||
|
$table = $self.closest(".sp-import-table");
|
||||||
|
$(this).remove();
|
||||||
|
$table.trigger("updatePostCount");
|
||||||
|
});
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
// Add importer row
|
||||||
|
$(".sp-import-table").on("click", ".sp-add-row", function() {
|
||||||
|
$self = $(this);
|
||||||
|
$table = $self.closest(".sp-import-table");
|
||||||
|
if ( $self.hasClass("sp-add-first") ) {
|
||||||
|
$tr = $table.find("tbody tr:first-child");
|
||||||
|
$row = $tr.clone();
|
||||||
|
$row.insertBefore($tr).find("input").val("");
|
||||||
|
} else {
|
||||||
|
$tr = $self.closest("tr");
|
||||||
|
$row = $tr.clone();
|
||||||
|
$tr.find("input").val("");
|
||||||
|
$row.insertBefore($tr);
|
||||||
|
}
|
||||||
|
$table.trigger("updatePostCount");
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
// Enable or disable importer inputs based on column label
|
||||||
|
$(".sp-import-table").on("change", "select", function() {
|
||||||
|
$self = $(this);
|
||||||
|
$table = $self.closest(".sp-import-table");
|
||||||
|
index = parseInt($self.data("index"));
|
||||||
|
if ( $self.val() == 0 ) {
|
||||||
|
$table.find("tbody tr td:nth-child("+parseInt(index+1)+") input").prop("disabled", true);
|
||||||
|
} else {
|
||||||
|
$table.find("tbody tr td:nth-child("+parseInt(index+1)+") input").prop("disabled", false);
|
||||||
|
$self.closest("th").siblings().find("select").each(function() {
|
||||||
|
if ( $(this).val() == $self.val() ) $(this).val("0").trigger("change");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
@@ -108,7 +108,8 @@ class SP_Admin_Assets {
|
|||||||
'days' => __( 'days', 'sportspress' ),
|
'days' => __( 'days', 'sportspress' ),
|
||||||
'hrs' => __( 'hrs', 'sportspress' ),
|
'hrs' => __( 'hrs', 'sportspress' ),
|
||||||
'mins' => __( 'mins', 'sportspress' ),
|
'mins' => __( 'mins', 'sportspress' ),
|
||||||
'secs' => __( 'secs', 'sportspress' )
|
'secs' => __( 'secs', 'sportspress' ),
|
||||||
|
'displaying_posts' => html_entity_decode( __( 'Displaying %s–%s of %s', 'sportspress' ) ),
|
||||||
);
|
);
|
||||||
|
|
||||||
// Localize scripts
|
// Localize scripts
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
* @author ThemeBoy
|
* @author ThemeBoy
|
||||||
* @category Admin
|
* @category Admin
|
||||||
* @package SportsPress/Admin/Importers
|
* @package SportsPress/Admin/Importers
|
||||||
* @version 0.9
|
* @version 1.3
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
||||||
@@ -21,351 +21,385 @@ if ( class_exists( 'WP_Importer' ) ) {
|
|||||||
*/
|
*/
|
||||||
public function __construct() {
|
public function __construct() {
|
||||||
$this->import_page = 'sportspress_event_csv';
|
$this->import_page = 'sportspress_event_csv';
|
||||||
|
$this->import_label = __( 'Import Events', 'sportspress' );
|
||||||
|
$this->columns = array(
|
||||||
|
'post_date' => __( 'Date', 'sportspress' ),
|
||||||
|
'post_time' => __( 'Time', 'sportspress' ),
|
||||||
|
'sp_venue' => __( 'Venue', 'sportspress' ),
|
||||||
|
'sp_team' => __( 'Teams', 'sportspress' ),
|
||||||
|
'sp_results' => __( 'Results', 'sportspress' ),
|
||||||
|
'sp_outcome' => __( 'Outcome', 'sportspress' ),
|
||||||
|
'sp_player' => __( 'Players', 'sportspress' ),
|
||||||
|
);
|
||||||
|
$performance_labels = sp_get_var_labels( 'sp_performance' );
|
||||||
|
if ( $performance_labels && is_array( $performance_labels ) && sizeof( $performance_labels ) )
|
||||||
|
$this->columns = array_merge( $this->columns, $performance_labels );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* import function.
|
* import function.
|
||||||
*
|
*
|
||||||
* @access public
|
* @access public
|
||||||
* @param mixed $file
|
* @param array $array
|
||||||
|
* @param array $columns
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function import( $file ) {
|
function import( $array = array(), $columns = array( 'post_title' ) ) {
|
||||||
global $wpdb;
|
|
||||||
|
|
||||||
$this->imported = $this->skipped = 0;
|
$this->imported = $this->skipped = 0;
|
||||||
|
|
||||||
if ( ! is_file($file) ):
|
if ( ! is_array( $array ) || ! sizeof( $array ) ):
|
||||||
$this->footer();
|
$this->footer();
|
||||||
die();
|
die();
|
||||||
endif;
|
endif;
|
||||||
|
|
||||||
ini_set( 'auto_detect_line_endings', '1' );
|
$rows = array_chunk( $array, sizeof( $columns ) );
|
||||||
|
|
||||||
if ( ( $handle = fopen( $file, "r" ) ) !== FALSE ):
|
// Get event format, league, and season from post vars
|
||||||
|
$event_format = ( empty( $_POST['sp_format'] ) ? false : $_POST['sp_format'] );
|
||||||
$header = fgetcsv( $handle, 0, $this->delimiter );
|
$league = ( sp_array_value( $_POST, 'sp_league', '-1' ) == '-1' ? false : $_POST['sp_league'] );
|
||||||
|
$season = ( sp_array_value( $_POST, 'sp_season', '-1' ) == '-1' ? false : $_POST['sp_season'] );
|
||||||
if ( sizeof( $header ) >= 3 ):
|
|
||||||
|
// Get labels from result and performance post types
|
||||||
$loop = 0;
|
$result_labels = sp_get_var_labels( 'sp_result' );
|
||||||
|
$performance_labels = sp_get_var_labels( 'sp_performance' );
|
||||||
// Get event format, league, and season from post vars
|
|
||||||
$event_format = ( empty( $_POST['sp_format'] ) ? false : $_POST['sp_format'] );
|
foreach ( $rows as $row ):
|
||||||
$league = ( empty( $_POST['sp_league'] ) ? false : $_POST['sp_league'] );
|
|
||||||
$season = ( empty( $_POST['sp_season'] ) ? false : $_POST['sp_season'] );
|
if ( empty( array_filter( $row ) ) ) continue;
|
||||||
|
|
||||||
// Get labels from result and performance post types
|
$meta = array();
|
||||||
$result_labels = sp_get_var_labels( 'sp_result' );
|
|
||||||
$performance_labels = sp_get_var_labels( 'sp_performance' );
|
foreach ( $columns as $index => $key ):
|
||||||
|
$meta[ $key ] = sp_array_value( $row, $index );
|
||||||
while ( ( $row = fgetcsv( $handle, 0, $this->delimiter ) ) !== FALSE ):
|
endforeach;
|
||||||
|
|
||||||
// Slice array into event, team, and player
|
// Slice array into event, team, and player
|
||||||
$event = array_slice( $row, 0, 3 );
|
$event = array_slice( $row, 0, 3 );
|
||||||
$team = array_slice( $row, 3, 3 );
|
$team = array_slice( $row, 3, 3 );
|
||||||
$player = array_slice( $row, 6 );
|
$player = array_slice( $row, 6 );
|
||||||
|
|
||||||
// Add new event if date is given
|
// Get event details
|
||||||
if ( sizeof( $event ) > 0 && ! empty( $event[0] ) ):
|
$event = array(
|
||||||
|
sp_array_value( $meta, 'post_date' ),
|
||||||
// Add player performance to last event if available
|
sp_array_value( $meta, 'post_time' ),
|
||||||
if ( isset( $id ) && isset( $players ) && sizeof( $players ) > 0 ):
|
sp_array_value( $meta, 'sp_venue' ),
|
||||||
update_post_meta( $id, 'sp_players', $players );
|
);
|
||||||
endif;
|
unset( $meta['post_date'] );
|
||||||
|
unset( $meta['post_time'] );
|
||||||
// List event columns
|
unset( $meta['sp_venue'] );
|
||||||
list( $date, $time, $venue ) = $event;
|
|
||||||
|
// Get team results
|
||||||
// Format date by replacing slashes with dashes
|
$team = array(
|
||||||
$date = str_replace( '/', '-', trim( $date ) );
|
sp_array_value( $meta, 'sp_team' ),
|
||||||
|
sp_array_value( $meta, 'sp_results' ),
|
||||||
// Add time to date if given
|
sp_array_value( $meta, 'sp_outcome' ),
|
||||||
if ( ! empty( $time ) ):
|
);
|
||||||
$date .= ' ' . trim( $time );
|
unset( $meta['sp_team'] );
|
||||||
endif;
|
unset( $meta['sp_results'] );
|
||||||
|
unset( $meta['sp_outcome'] );
|
||||||
// Define post type args
|
|
||||||
$args = array( 'post_type' => 'sp_event', 'post_status' => 'publish', 'post_date' => $date );
|
// Get player performance
|
||||||
|
$player = array(
|
||||||
// Insert event
|
sp_array_value( $meta, 'sp_player' ),
|
||||||
$id = wp_insert_post( $args );
|
);
|
||||||
|
unset( $meta['sp_player' ] );
|
||||||
// Initialize performance array
|
foreach ( $performance_labels as $key => $label ):
|
||||||
$players = array();
|
$player[] = sp_array_value( $meta, $key, '' );
|
||||||
|
endforeach;
|
||||||
// Flag as import
|
|
||||||
update_post_meta( $id, '_sp_import', 1 );
|
// Add new event if date is given
|
||||||
|
if ( sizeof( $event ) > 0 && ! empty( $event[0] ) ):
|
||||||
// Update event format
|
|
||||||
if ( $event_format ):
|
|
||||||
update_post_meta( $id, 'sp_format', $event_format );
|
|
||||||
endif;
|
|
||||||
|
|
||||||
// Update league
|
|
||||||
if ( $league ):
|
|
||||||
wp_set_object_terms( $id, $league, 'sp_league', false );
|
|
||||||
endif;
|
|
||||||
|
|
||||||
// Update season
|
|
||||||
if ( $season ):
|
|
||||||
wp_set_object_terms( $id, $season, 'sp_season', false );
|
|
||||||
endif;
|
|
||||||
|
|
||||||
// Update venue
|
|
||||||
wp_set_object_terms( $id, $venue, 'sp_venue', false );
|
|
||||||
|
|
||||||
// Increment
|
|
||||||
$loop ++;
|
|
||||||
$this->imported ++;
|
|
||||||
|
|
||||||
endif;
|
|
||||||
|
|
||||||
// Add new team if team name is given
|
|
||||||
if ( sizeof( $team ) > 0 && ! empty( $team[0] ) ):
|
|
||||||
|
|
||||||
// List team columns
|
|
||||||
list( $team_name, $result, $outcome ) = $team;
|
|
||||||
|
|
||||||
// Find out if team exists
|
|
||||||
$team_object = get_page_by_title( $team_name, OBJECT, 'sp_team' );
|
|
||||||
|
|
||||||
// Get or insert team
|
|
||||||
if ( $team_object ):
|
|
||||||
|
|
||||||
// Make sure team is published
|
|
||||||
if ( $team_object->post_status != 'publish' ):
|
|
||||||
wp_update_post( array( 'ID' => $team_object->ID, 'post_status' => 'publish' ) );
|
|
||||||
endif;
|
|
||||||
|
|
||||||
// Get team ID
|
|
||||||
$team_id = $team_object->ID;
|
|
||||||
|
|
||||||
else:
|
|
||||||
|
|
||||||
// Insert team
|
|
||||||
$team_id = wp_insert_post( array( 'post_type' => 'sp_team', 'post_status' => 'publish', 'post_title' => $team_name ) );
|
|
||||||
|
|
||||||
// Flag as import
|
|
||||||
update_post_meta( $team_id, '_sp_import', 1 );
|
|
||||||
|
|
||||||
endif;
|
|
||||||
|
|
||||||
// Update league
|
|
||||||
if ( $league ):
|
|
||||||
wp_set_object_terms( $team_id, $league, 'sp_league', true );
|
|
||||||
endif;
|
|
||||||
|
|
||||||
// Update season
|
|
||||||
if ( $season ):
|
|
||||||
wp_set_object_terms( $team_id, $season, 'sp_season', true );
|
|
||||||
endif;
|
|
||||||
|
|
||||||
// Add to event if exists
|
|
||||||
if ( isset( $id ) ):
|
|
||||||
|
|
||||||
// Add team to event
|
|
||||||
add_post_meta( $id, 'sp_team', $team_id );
|
|
||||||
|
|
||||||
// Add empty player to event
|
|
||||||
add_post_meta( $id, 'sp_player', 0 );
|
|
||||||
|
|
||||||
// Explode results into array
|
|
||||||
$results = explode( '|', $result );
|
|
||||||
|
|
||||||
// Create team results array from result keys
|
|
||||||
$team_results = array();
|
|
||||||
if ( sizeof( $result_labels ) > 0 ):
|
|
||||||
foreach( $result_labels as $key => $label ):
|
|
||||||
$team_results[ $key ] = trim( array_shift( $results ) );
|
|
||||||
endforeach;
|
|
||||||
$team_results[ 'outcome' ] = array();
|
|
||||||
endif;
|
|
||||||
|
|
||||||
// Explode outcomes into array
|
|
||||||
$outcomes = explode( '|', $outcome );
|
|
||||||
|
|
||||||
// Add outcome slugs to team outcomes array
|
|
||||||
foreach ( $outcomes as $outcome ):
|
|
||||||
|
|
||||||
// Continue if outcome doesn't exist
|
|
||||||
if ( $outcome == null ):
|
|
||||||
continue;
|
|
||||||
endif;
|
|
||||||
|
|
||||||
// Remove whitespace
|
|
||||||
$outcome = trim( $outcome );
|
|
||||||
|
|
||||||
// Get or insert outcome
|
|
||||||
$outcome_object = get_page_by_title( $outcome, OBJECT, 'sp_outcome' );
|
|
||||||
|
|
||||||
if ( $outcome_object ):
|
|
||||||
|
|
||||||
// Make sure outcome is published
|
|
||||||
if ( $outcome_object->post_status != 'publish' ):
|
|
||||||
wp_update_post( array( 'ID' => $outcome_object->ID, 'post_status' => 'publish' ) );
|
|
||||||
endif;
|
|
||||||
|
|
||||||
// Get outcome slug
|
|
||||||
$outcome_slug = $outcome_object->post_name;
|
|
||||||
|
|
||||||
else:
|
|
||||||
|
|
||||||
// Insert outcome
|
|
||||||
$outcome_id = wp_insert_post( array( 'post_type' => 'sp_outcome', 'post_status' => 'publish', 'post_title' => $outcome ) );
|
|
||||||
|
|
||||||
// Get outcome slug
|
|
||||||
$post_data = get_post( $outcome_id, ARRAY_A );
|
|
||||||
$outcome_slug = $post_data['post_name'];
|
|
||||||
|
|
||||||
// Flag as import
|
|
||||||
update_post_meta( $outcome_id, '_sp_import', 1 );
|
|
||||||
|
|
||||||
endif;
|
|
||||||
|
|
||||||
// Add to team results array
|
|
||||||
$team_results[ 'outcome' ][] = $outcome_slug;
|
|
||||||
|
|
||||||
endforeach;
|
|
||||||
|
|
||||||
// Get existing results
|
|
||||||
$event_results = get_post_meta( $id, 'sp_results', true );
|
|
||||||
|
|
||||||
// Create new array if results not exists
|
|
||||||
if ( ! $event_results ):
|
|
||||||
$event_results = array();
|
|
||||||
endif;
|
|
||||||
|
|
||||||
// Add team results to existing results
|
|
||||||
$event_results[ $team_id ] = $team_results;
|
|
||||||
|
|
||||||
// Update event results
|
|
||||||
update_post_meta( $id, 'sp_results', $event_results );
|
|
||||||
|
|
||||||
// Get event name
|
|
||||||
$title = get_the_title( $id );
|
|
||||||
|
|
||||||
// Add delimiter if event name is set
|
|
||||||
if ( $title ):
|
|
||||||
$title .= ' ' . get_option( 'sportspress_event_teams_delimiter', 'vs' ) . ' ';
|
|
||||||
endif;
|
|
||||||
|
|
||||||
// Append team name to event name
|
|
||||||
$title .= $team_name;
|
|
||||||
|
|
||||||
// Update event with new name
|
|
||||||
$post = array(
|
|
||||||
'ID' => $id,
|
|
||||||
'post_title' => $title,
|
|
||||||
);
|
|
||||||
wp_update_post( $post );
|
|
||||||
|
|
||||||
endif;
|
|
||||||
|
|
||||||
endif;
|
|
||||||
|
|
||||||
// Add new player if player name is given
|
|
||||||
if ( sizeof( $player ) > 0 && ! empty( $player[0] ) ):
|
|
||||||
|
|
||||||
// Get and unset player name leaving us with the performance
|
|
||||||
$player_name = $player[0];
|
|
||||||
unset( $player[0] );
|
|
||||||
|
|
||||||
// Find out if player exists
|
|
||||||
$player_object = get_page_by_title( $player_name, OBJECT, 'sp_player' );
|
|
||||||
|
|
||||||
// Get or insert player
|
|
||||||
if ( $player_object ):
|
|
||||||
|
|
||||||
// Make sure player is published
|
|
||||||
if ( $player_object->post_status != 'publish' ):
|
|
||||||
wp_update_post( array( 'ID' => $player_object->ID, 'post_status' => 'publish' ) );
|
|
||||||
endif;
|
|
||||||
|
|
||||||
// Get player ID
|
|
||||||
$player_id = $player_object->ID;
|
|
||||||
|
|
||||||
else:
|
|
||||||
|
|
||||||
// Insert player
|
|
||||||
$player_id = wp_insert_post( array( 'post_type' => 'sp_player', 'post_status' => 'publish', 'post_title' => $player_name ) );
|
|
||||||
|
|
||||||
// Flag as import
|
|
||||||
update_post_meta( $player_id, '_sp_import', 1 );
|
|
||||||
|
|
||||||
// Update number
|
|
||||||
update_post_meta( $player_id, 'sp_number', null );
|
|
||||||
|
|
||||||
endif;
|
|
||||||
|
|
||||||
// Update league
|
|
||||||
if ( $league ):
|
|
||||||
wp_set_object_terms( $player_id, $league, 'sp_league', true );
|
|
||||||
endif;
|
|
||||||
|
|
||||||
// Update season
|
|
||||||
if ( $season ):
|
|
||||||
wp_set_object_terms( $player_id, $season, 'sp_season', true );
|
|
||||||
endif;
|
|
||||||
|
|
||||||
// Add to event if exists
|
|
||||||
if ( isset( $id ) ):
|
|
||||||
|
|
||||||
// Add player to event
|
|
||||||
add_post_meta( $id, 'sp_player', $player_id );
|
|
||||||
|
|
||||||
// Add player performance to array if team is available
|
|
||||||
if ( isset( $team_id ) ):
|
|
||||||
|
|
||||||
// Initialize performance array
|
|
||||||
$performance = array();
|
|
||||||
|
|
||||||
// Map keys to player performance
|
|
||||||
foreach ( $performance_labels as $key => $label ):
|
|
||||||
$performance[ $key ] = array_shift( $player );
|
|
||||||
endforeach;
|
|
||||||
$players[ $team_id ][ $player_id ] = $performance;
|
|
||||||
|
|
||||||
// Get player teams
|
|
||||||
$player_teams = get_post_meta( $player_id, 'sp_team', false );
|
|
||||||
$current_team = get_post_meta( $player_id, 'sp_current_team', true );
|
|
||||||
$past_teams = get_post_meta( $player_id, 'sp_past_team', false );
|
|
||||||
|
|
||||||
// Add team if not exists in player
|
|
||||||
if ( ! in_array( $team_id, $player_teams ) ):
|
|
||||||
add_post_meta( $player_id, 'sp_team', $team_id );
|
|
||||||
endif;
|
|
||||||
|
|
||||||
// Add as past team or set current team if not set
|
|
||||||
if ( ! $current_team ):
|
|
||||||
update_post_meta( $player_id, 'sp_current_team', $team_id );
|
|
||||||
elseif ( $current_team != $team_id && ! in_array( $team_id, $past_teams ) ):
|
|
||||||
add_post_meta( $player_id, 'sp_past_team', $team_id );
|
|
||||||
endif;
|
|
||||||
|
|
||||||
endif;
|
|
||||||
|
|
||||||
endif;
|
|
||||||
|
|
||||||
endif;
|
|
||||||
|
|
||||||
endwhile;
|
|
||||||
|
|
||||||
// Add player performance to last event if available
|
// Add player performance to last event if available
|
||||||
if ( isset( $id ) && isset( $players ) && sizeof( $players ) > 0 ):
|
if ( isset( $id ) && isset( $players ) && sizeof( $players ) > 0 ):
|
||||||
update_post_meta( $id, 'sp_players', $players );
|
update_post_meta( $id, 'sp_players', $players );
|
||||||
endif;
|
endif;
|
||||||
|
|
||||||
else:
|
// List event columns
|
||||||
|
list( $date, $time, $venue ) = $event;
|
||||||
|
|
||||||
echo '<p><strong>' . __( 'Sorry, there has been an error.', 'sportspress' ) . '</strong><br />';
|
// Format date by replacing slashes with dashes
|
||||||
_e( 'The CSV is invalid.', 'sportspress' ) . '</p>';
|
$date = str_replace( '/', '-', trim( $date ) );
|
||||||
$this->footer();
|
|
||||||
die();
|
// Add time to date if given
|
||||||
|
if ( ! empty( $time ) ):
|
||||||
|
$date .= ' ' . trim( $time );
|
||||||
|
endif;
|
||||||
|
|
||||||
|
// Define post type args
|
||||||
|
$args = array( 'post_type' => 'sp_event', 'post_status' => 'publish', 'post_date' => $date );
|
||||||
|
|
||||||
|
// Insert event
|
||||||
|
$id = wp_insert_post( $args );
|
||||||
|
|
||||||
|
// Initialize performance array
|
||||||
|
$players = array();
|
||||||
|
|
||||||
|
// Flag as import
|
||||||
|
update_post_meta( $id, '_sp_import', 1 );
|
||||||
|
|
||||||
|
// Update event format
|
||||||
|
if ( $event_format ):
|
||||||
|
update_post_meta( $id, 'sp_format', $event_format );
|
||||||
|
endif;
|
||||||
|
|
||||||
|
// Update league
|
||||||
|
if ( $league ):
|
||||||
|
wp_set_object_terms( $id, $league, 'sp_league', false );
|
||||||
|
endif;
|
||||||
|
|
||||||
|
// Update season
|
||||||
|
if ( $season ):
|
||||||
|
wp_set_object_terms( $id, $season, 'sp_season', false );
|
||||||
|
endif;
|
||||||
|
|
||||||
|
// Update venue
|
||||||
|
wp_set_object_terms( $id, $venue, 'sp_venue', false );
|
||||||
|
|
||||||
|
// Increment
|
||||||
|
$this->imported ++;
|
||||||
|
|
||||||
endif;
|
endif;
|
||||||
|
|
||||||
fclose( $handle );
|
// Add new team if team name is given
|
||||||
|
if ( sizeof( $team ) > 0 && ! empty( $team[0] ) ):
|
||||||
|
|
||||||
|
// List team columns
|
||||||
|
list( $team_name, $result, $outcome ) = $team;
|
||||||
|
|
||||||
|
// Find out if team exists
|
||||||
|
$team_object = get_page_by_title( $team_name, OBJECT, 'sp_team' );
|
||||||
|
|
||||||
|
// Get or insert team
|
||||||
|
if ( $team_object ):
|
||||||
|
|
||||||
|
// Make sure team is published
|
||||||
|
if ( $team_object->post_status != 'publish' ):
|
||||||
|
wp_update_post( array( 'ID' => $team_object->ID, 'post_status' => 'publish' ) );
|
||||||
|
endif;
|
||||||
|
|
||||||
|
// Get team ID
|
||||||
|
$team_id = $team_object->ID;
|
||||||
|
|
||||||
|
else:
|
||||||
|
|
||||||
|
// Insert team
|
||||||
|
$team_id = wp_insert_post( array( 'post_type' => 'sp_team', 'post_status' => 'publish', 'post_title' => $team_name ) );
|
||||||
|
|
||||||
|
// Flag as import
|
||||||
|
update_post_meta( $team_id, '_sp_import', 1 );
|
||||||
|
|
||||||
|
endif;
|
||||||
|
|
||||||
|
// Update league
|
||||||
|
if ( $league ):
|
||||||
|
wp_set_object_terms( $team_id, $league, 'sp_league', true );
|
||||||
|
endif;
|
||||||
|
|
||||||
|
// Update season
|
||||||
|
if ( $season ):
|
||||||
|
wp_set_object_terms( $team_id, $season, 'sp_season', true );
|
||||||
|
endif;
|
||||||
|
|
||||||
|
// Add to event if exists
|
||||||
|
if ( isset( $id ) ):
|
||||||
|
|
||||||
|
// Add team to event
|
||||||
|
add_post_meta( $id, 'sp_team', $team_id );
|
||||||
|
|
||||||
|
// Add empty player to event
|
||||||
|
add_post_meta( $id, 'sp_player', 0 );
|
||||||
|
|
||||||
|
// Explode results into array
|
||||||
|
$results = explode( '|', $result );
|
||||||
|
|
||||||
|
// Create team results array from result keys
|
||||||
|
$team_results = array();
|
||||||
|
if ( sizeof( $result_labels ) > 0 ):
|
||||||
|
foreach( $result_labels as $key => $label ):
|
||||||
|
$team_results[ $key ] = trim( array_shift( $results ) );
|
||||||
|
endforeach;
|
||||||
|
$team_results[ 'outcome' ] = array();
|
||||||
|
endif;
|
||||||
|
|
||||||
|
// Explode outcomes into array
|
||||||
|
$outcomes = explode( '|', $outcome );
|
||||||
|
|
||||||
|
// Add outcome slugs to team outcomes array
|
||||||
|
foreach ( $outcomes as $outcome ):
|
||||||
|
|
||||||
|
// Continue if outcome doesn't exist
|
||||||
|
if ( $outcome == null ):
|
||||||
|
continue;
|
||||||
|
endif;
|
||||||
|
|
||||||
|
// Remove whitespace
|
||||||
|
$outcome = trim( $outcome );
|
||||||
|
|
||||||
|
// Get or insert outcome
|
||||||
|
$outcome_object = get_page_by_title( $outcome, OBJECT, 'sp_outcome' );
|
||||||
|
|
||||||
|
if ( $outcome_object ):
|
||||||
|
|
||||||
|
// Make sure outcome is published
|
||||||
|
if ( $outcome_object->post_status != 'publish' ):
|
||||||
|
wp_update_post( array( 'ID' => $outcome_object->ID, 'post_status' => 'publish' ) );
|
||||||
|
endif;
|
||||||
|
|
||||||
|
// Get outcome slug
|
||||||
|
$outcome_slug = $outcome_object->post_name;
|
||||||
|
|
||||||
|
else:
|
||||||
|
|
||||||
|
// Insert outcome
|
||||||
|
$outcome_id = wp_insert_post( array( 'post_type' => 'sp_outcome', 'post_status' => 'publish', 'post_title' => $outcome ) );
|
||||||
|
|
||||||
|
// Get outcome slug
|
||||||
|
$post_data = get_post( $outcome_id, ARRAY_A );
|
||||||
|
$outcome_slug = $post_data['post_name'];
|
||||||
|
|
||||||
|
// Flag as import
|
||||||
|
update_post_meta( $outcome_id, '_sp_import', 1 );
|
||||||
|
|
||||||
|
endif;
|
||||||
|
|
||||||
|
// Add to team results array
|
||||||
|
$team_results[ 'outcome' ][] = $outcome_slug;
|
||||||
|
|
||||||
|
endforeach;
|
||||||
|
|
||||||
|
// Get existing results
|
||||||
|
$event_results = get_post_meta( $id, 'sp_results', true );
|
||||||
|
|
||||||
|
// Create new array if results not exists
|
||||||
|
if ( ! $event_results ):
|
||||||
|
$event_results = array();
|
||||||
|
endif;
|
||||||
|
|
||||||
|
// Add team results to existing results
|
||||||
|
$event_results[ $team_id ] = $team_results;
|
||||||
|
|
||||||
|
// Update event results
|
||||||
|
update_post_meta( $id, 'sp_results', $event_results );
|
||||||
|
|
||||||
|
// Get event name
|
||||||
|
$title = get_the_title( $id );
|
||||||
|
|
||||||
|
// Add delimiter if event name is set
|
||||||
|
if ( $title ):
|
||||||
|
$title .= ' ' . get_option( 'sportspress_event_teams_delimiter', 'vs' ) . ' ';
|
||||||
|
endif;
|
||||||
|
|
||||||
|
// Append team name to event name
|
||||||
|
$title .= $team_name;
|
||||||
|
|
||||||
|
// Update event with new name
|
||||||
|
$post = array(
|
||||||
|
'ID' => $id,
|
||||||
|
'post_title' => $title,
|
||||||
|
);
|
||||||
|
wp_update_post( $post );
|
||||||
|
|
||||||
|
endif;
|
||||||
|
|
||||||
|
endif;
|
||||||
|
|
||||||
|
// Add new player if player name is given
|
||||||
|
if ( sizeof( $player ) > 0 && ! empty( $player[0] ) ):
|
||||||
|
|
||||||
|
// Get and unset player name leaving us with the performance
|
||||||
|
$player_name = $player[0];
|
||||||
|
unset( $player[0] );
|
||||||
|
|
||||||
|
// Find out if player exists
|
||||||
|
$player_object = get_page_by_title( $player_name, OBJECT, 'sp_player' );
|
||||||
|
|
||||||
|
// Get or insert player
|
||||||
|
if ( $player_object ):
|
||||||
|
|
||||||
|
// Make sure player is published
|
||||||
|
if ( $player_object->post_status != 'publish' ):
|
||||||
|
wp_update_post( array( 'ID' => $player_object->ID, 'post_status' => 'publish' ) );
|
||||||
|
endif;
|
||||||
|
|
||||||
|
// Get player ID
|
||||||
|
$player_id = $player_object->ID;
|
||||||
|
|
||||||
|
// Get player number
|
||||||
|
$player_number = get_post_meta( $player_id, 'sp_number', true );
|
||||||
|
|
||||||
|
else:
|
||||||
|
|
||||||
|
// Insert player
|
||||||
|
$player_id = wp_insert_post( array( 'post_type' => 'sp_player', 'post_status' => 'publish', 'post_title' => $player_name ) );
|
||||||
|
|
||||||
|
// Flag as import
|
||||||
|
update_post_meta( $player_id, '_sp_import', 1 );
|
||||||
|
|
||||||
|
// Update number
|
||||||
|
update_post_meta( $player_id, 'sp_number', null );
|
||||||
|
|
||||||
|
// Get player number
|
||||||
|
$player_number = null;
|
||||||
|
|
||||||
|
endif;
|
||||||
|
|
||||||
|
// Update league
|
||||||
|
if ( $league ):
|
||||||
|
wp_set_object_terms( $player_id, $league, 'sp_league', true );
|
||||||
|
endif;
|
||||||
|
|
||||||
|
// Update season
|
||||||
|
if ( $season ):
|
||||||
|
wp_set_object_terms( $player_id, $season, 'sp_season', true );
|
||||||
|
endif;
|
||||||
|
|
||||||
|
// Add to event if exists
|
||||||
|
if ( isset( $id ) ):
|
||||||
|
|
||||||
|
// Add player to event
|
||||||
|
add_post_meta( $id, 'sp_player', $player_id );
|
||||||
|
|
||||||
|
// Add player performance to array if team is available
|
||||||
|
if ( isset( $team_id ) ):
|
||||||
|
|
||||||
|
// Initialize performance array
|
||||||
|
$performance = array( 'number' => $player_number );
|
||||||
|
|
||||||
|
// Map keys to player performance
|
||||||
|
foreach ( $performance_labels as $key => $label ):
|
||||||
|
$performance[ $key ] = array_shift( $player );
|
||||||
|
endforeach;
|
||||||
|
$players[ $team_id ][ $player_id ] = $performance;
|
||||||
|
|
||||||
|
// Get player teams
|
||||||
|
$player_teams = get_post_meta( $player_id, 'sp_team', false );
|
||||||
|
$current_team = get_post_meta( $player_id, 'sp_current_team', true );
|
||||||
|
$past_teams = get_post_meta( $player_id, 'sp_past_team', false );
|
||||||
|
|
||||||
|
// Add team if not exists in player
|
||||||
|
if ( ! in_array( $team_id, $player_teams ) ):
|
||||||
|
add_post_meta( $player_id, 'sp_team', $team_id );
|
||||||
|
endif;
|
||||||
|
|
||||||
|
// Add as past team or set current team if not set
|
||||||
|
if ( ! $current_team ):
|
||||||
|
update_post_meta( $player_id, 'sp_current_team', $team_id );
|
||||||
|
elseif ( $current_team != $team_id && ! in_array( $team_id, $past_teams ) ):
|
||||||
|
add_post_meta( $player_id, 'sp_past_team', $team_id );
|
||||||
|
endif;
|
||||||
|
|
||||||
|
endif;
|
||||||
|
|
||||||
|
endif;
|
||||||
|
|
||||||
|
endif;
|
||||||
|
|
||||||
|
endforeach;
|
||||||
|
|
||||||
|
// Add player performance to last event if available
|
||||||
|
if ( isset( $id ) && isset( $players ) && sizeof( $players ) > 0 ):
|
||||||
|
update_post_meta( $id, 'sp_players', $players );
|
||||||
endif;
|
endif;
|
||||||
|
|
||||||
// Show Result
|
// Show Result
|
||||||
@@ -385,16 +419,6 @@ if ( class_exists( 'WP_Importer' ) ) {
|
|||||||
do_action( 'import_end' );
|
do_action( 'import_end' );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* header function.
|
|
||||||
*
|
|
||||||
* @access public
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
function header() {
|
|
||||||
echo '<div class="wrap"><h2>' . __( 'Import Events', 'sportspress' ) . '</h2>';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* greet function.
|
* greet function.
|
||||||
*
|
*
|
||||||
@@ -402,98 +426,87 @@ if ( class_exists( 'WP_Importer' ) ) {
|
|||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function greet() {
|
function greet() {
|
||||||
|
|
||||||
echo '<div class="narrow">';
|
echo '<div class="narrow">';
|
||||||
echo '<p>' . __( 'Hi there! Choose a .csv file to upload, then click "Upload file and import".', 'sportspress' ).'</p>';
|
echo '<p>' . __( 'Hi there! Choose a .csv file to upload, then click "Upload file and import".', 'sportspress' ).'</p>';
|
||||||
|
|
||||||
echo '<p>' . sprintf( __( 'Events need to be defined with columns in a specific order (3+ columns). <a href="%s">Click here to download a sample</a>.', 'sportspress' ), plugin_dir_url( SP_PLUGIN_FILE ) . 'dummy-data/events-sample.csv' ) . '</p>';
|
echo '<p>' . sprintf( __( 'Events need to be defined with columns in a specific order (3+ columns). <a href="%s">Click here to download a sample</a>.', 'sportspress' ), plugin_dir_url( SP_PLUGIN_FILE ) . 'dummy-data/events-sample.csv' ) . '</p>';
|
||||||
|
wp_import_upload_form( 'admin.php?import=sportspress_event_csv&step=1' );
|
||||||
$action = 'admin.php?import=sportspress_event_csv&step=1';
|
|
||||||
|
|
||||||
$bytes = apply_filters( 'import_upload_size_limit', wp_max_upload_size() );
|
|
||||||
$size = size_format( $bytes );
|
|
||||||
$upload_dir = wp_upload_dir();
|
|
||||||
if ( ! empty( $upload_dir['error'] ) ) :
|
|
||||||
?><div class="error"><p><?php _e('Before you can upload your import file, you will need to fix the following error:', 'sportspress'); ?></p>
|
|
||||||
<p><strong><?php echo $upload_dir['error']; ?></strong></p></div><?php
|
|
||||||
else :
|
|
||||||
?>
|
|
||||||
<form enctype="multipart/form-data" id="import-upload-form" method="post" action="<?php echo esc_attr(wp_nonce_url($action, 'import-upload')); ?>">
|
|
||||||
<table class="form-table">
|
|
||||||
<tbody>
|
|
||||||
<tr>
|
|
||||||
<th>
|
|
||||||
<label for="upload"><?php _e( 'Choose a file from your computer:', 'sportspress' ); ?></label>
|
|
||||||
</th>
|
|
||||||
<td>
|
|
||||||
<input type="file" id="upload" name="import" size="25" />
|
|
||||||
<input type="hidden" name="action" value="save" />
|
|
||||||
<input type="hidden" name="max_file_size" value="<?php echo $bytes; ?>" />
|
|
||||||
<small><?php printf( __( 'Maximum size: %s', 'sportspress' ), $size ); ?></small>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<th>
|
|
||||||
<label for="file_url"><?php _e( 'OR enter path to file:', 'sportspress' ); ?></label>
|
|
||||||
</th>
|
|
||||||
<td>
|
|
||||||
<?php echo ' ' . ABSPATH . ' '; ?><input type="text" id="file_url" name="file_url" size="25" />
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<th><label><?php _e( 'Delimiter', 'sportspress' ); ?></label><br/></th>
|
|
||||||
<td><input type="text" name="delimiter" placeholder="," size="2" /></td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<th><label><?php _e( 'Format', 'sportspress' ); ?></label><br/></th>
|
|
||||||
<td id="sp_formatdiv">
|
|
||||||
<div id="post-formats-select">
|
|
||||||
<input type="radio" name="sp_format" class="post-format" id="post-format-league" value="league" checked="checked"> <label for="post-format-league" class="post-format-icon post-format-league">League</label>
|
|
||||||
<br><input type="radio" name="sp_format" class="post-format" id="post-format-friendly" value="friendly"> <label for="post-format-friendly" class="post-format-icon post-format-friendly">Friendly</label>
|
|
||||||
<br>
|
|
||||||
</div>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<th><label><?php _e( 'League', 'sportspress' ); ?></label><br/></th>
|
|
||||||
<td><?php
|
|
||||||
$args = array(
|
|
||||||
'taxonomy' => 'sp_league',
|
|
||||||
'name' => 'sp_league',
|
|
||||||
'values' => 'slug',
|
|
||||||
'show_option_none' => __( '-- Not set --', 'sportspress' ),
|
|
||||||
);
|
|
||||||
if ( ! sp_dropdown_taxonomies( $args ) ):
|
|
||||||
echo '<p>' . __( 'None', 'sportspress' ) . '</p>';
|
|
||||||
sp_taxonomy_adder( 'sp_league', 'sp_team', __( 'Add New', 'sportspress' ) );
|
|
||||||
endif;
|
|
||||||
?></td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<th><label><?php _e( 'Season', 'sportspress' ); ?></label><br/></th>
|
|
||||||
<td><?php
|
|
||||||
$args = array(
|
|
||||||
'taxonomy' => 'sp_season',
|
|
||||||
'name' => 'sp_season',
|
|
||||||
'values' => 'slug',
|
|
||||||
'show_option_none' => __( '-- Not set --', 'sportspress' ),
|
|
||||||
);
|
|
||||||
if ( ! sp_dropdown_taxonomies( $args ) ):
|
|
||||||
echo '<p>' . __( 'None', 'sportspress' ) . '</p>';
|
|
||||||
sp_taxonomy_adder( 'sp_season', 'sp_team', __( 'Add New', 'sportspress' ) );
|
|
||||||
endif;
|
|
||||||
?></td>
|
|
||||||
</tr>
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
<p class="submit">
|
|
||||||
<input type="submit" class="button" value="<?php esc_attr_e( 'Upload file and import', 'sportspress' ); ?>" />
|
|
||||||
</p>
|
|
||||||
</form>
|
|
||||||
<?php
|
|
||||||
endif;
|
|
||||||
|
|
||||||
echo '</div>';
|
echo '</div>';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* options function.
|
||||||
|
*
|
||||||
|
* @access public
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function options() {
|
||||||
|
?>
|
||||||
|
<table class="form-table">
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<th scope="row" class="titledesc">
|
||||||
|
<?php _e( 'Date Format', 'sportspress' ); ?>
|
||||||
|
</th>
|
||||||
|
<td class="forminp forminp-radio">
|
||||||
|
<fieldset>
|
||||||
|
<ul>
|
||||||
|
<li>
|
||||||
|
<label><input name="sp_date_format" value="yyyy/mm/dd" type="radio" checked> yyyy/mm/dd</label>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<label><input name="sp_date_format" value="dd/mm/yyyy" type="radio"> dd/mm/yyyy</label>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<label><input name="sp_date_format" value="mm/dd/yyyy" type="radio"> mm/dd/yyyy</label>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</fieldset>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th scope="row"><label><?php _e( 'Format', 'sportspress' ); ?></label><br/></th>
|
||||||
|
<td class="forminp forminp-radio" id="sp_formatdiv">
|
||||||
|
<fieldset id="post-formats-select">
|
||||||
|
<ul>
|
||||||
|
<li><input type="radio" name="sp_format" class="post-format" id="post-format-league" value="league" checked="checked"> <label for="post-format-league" class="post-format-icon post-format-league">League</label></li>
|
||||||
|
<li><input type="radio" name="sp_format" class="post-format" id="post-format-friendly" value="friendly"> <label for="post-format-friendly" class="post-format-icon post-format-friendly">Friendly</label></li>
|
||||||
|
<br>
|
||||||
|
</fieldset>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th scope="row"><label><?php _e( 'League', 'sportspress' ); ?></label><br/></th>
|
||||||
|
<td><?php
|
||||||
|
$args = array(
|
||||||
|
'taxonomy' => 'sp_league',
|
||||||
|
'name' => 'sp_league',
|
||||||
|
'values' => 'slug',
|
||||||
|
'show_option_none' => __( '-- Not set --', 'sportspress' ),
|
||||||
|
);
|
||||||
|
if ( ! sp_dropdown_taxonomies( $args ) ):
|
||||||
|
echo '<p>' . __( 'None', 'sportspress' ) . '</p>';
|
||||||
|
sp_taxonomy_adder( 'sp_league', 'sp_team', __( 'Add New', 'sportspress' ) );
|
||||||
|
endif;
|
||||||
|
?></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th scope="row"><label><?php _e( 'Season', 'sportspress' ); ?></label><br/></th>
|
||||||
|
<td><?php
|
||||||
|
$args = array(
|
||||||
|
'taxonomy' => 'sp_season',
|
||||||
|
'name' => 'sp_season',
|
||||||
|
'values' => 'slug',
|
||||||
|
'show_option_none' => __( '-- Not set --', 'sportspress' ),
|
||||||
|
);
|
||||||
|
if ( ! sp_dropdown_taxonomies( $args ) ):
|
||||||
|
echo '<p>' . __( 'None', 'sportspress' ) . '</p>';
|
||||||
|
sp_taxonomy_adder( 'sp_season', 'sp_team', __( 'Add New', 'sportspress' ) );
|
||||||
|
endif;
|
||||||
|
?></td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<?php
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
* @author ThemeBoy
|
* @author ThemeBoy
|
||||||
* @category Admin
|
* @category Admin
|
||||||
* @package SportsPress/Admin/Importers
|
* @package SportsPress/Admin/Importers
|
||||||
* @version 0.9
|
* @version 1.3
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
||||||
@@ -20,6 +20,22 @@ if ( class_exists( 'WP_Importer' ) ) {
|
|||||||
var $posts = array();
|
var $posts = array();
|
||||||
var $imported;
|
var $imported;
|
||||||
var $skipped;
|
var $skipped;
|
||||||
|
var $import_label;
|
||||||
|
var $columns = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor.
|
||||||
|
*/
|
||||||
|
public function __construct() {
|
||||||
|
add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts' ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enqueue scripts
|
||||||
|
*/
|
||||||
|
public function admin_scripts() {
|
||||||
|
wp_enqueue_script( 'sportspress-admin', SP()->plugin_url() . '/assets/js/admin/sportspress-admin.js', array( 'jquery', 'chosen', 'jquery-ui-core', 'jquery-ui-draggable', 'jquery-ui-droppable', 'jquery-ui-sortable', 'jquery-tiptip', 'jquery-caret', 'jquery-countdown' ), SP_VERSION, true );
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registered callback function for the WordPress Importer
|
* Registered callback function for the WordPress Importer
|
||||||
@@ -58,13 +74,125 @@ if ( class_exists( 'WP_Importer' ) ) {
|
|||||||
@ob_flush();
|
@ob_flush();
|
||||||
@flush();
|
@flush();
|
||||||
|
|
||||||
$this->import( $file );
|
$this->table( $file );
|
||||||
|
endif;
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
check_admin_referer( 'import-upload' );
|
||||||
|
if ( isset( $_POST['sp_import'] ) ):
|
||||||
|
$this->import( $_POST['sp_import'], array_values( array_filter( sp_array_value( $_POST, 'sp_columns', array( 'post_title' ) ) ) ) );
|
||||||
endif;
|
endif;
|
||||||
break;
|
break;
|
||||||
endswitch;
|
endswitch;
|
||||||
$this->footer();
|
$this->footer();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* dropdown function.
|
||||||
|
*
|
||||||
|
* @access public
|
||||||
|
* @param mixed $file
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function dropdown( $selected ) {
|
||||||
|
?>
|
||||||
|
<select name="sp_columns[]" data-index="<?php echo array_search( $selected, array_keys( $this->columns ) ); ?>">
|
||||||
|
<option value="0">— <?php _e( 'Disable', 'sportspress' ); ?> —</option>
|
||||||
|
<?php foreach ( $this->columns as $key => $label ): ?>
|
||||||
|
<option value="<?php echo $key; ?>" <?php selected( $selected, $key ); ?>><?php echo $label; ?></option>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</select>
|
||||||
|
<?php
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* table function.
|
||||||
|
*
|
||||||
|
* @access public
|
||||||
|
* @param mixed $file
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function table( $file ) {
|
||||||
|
global $wpdb;
|
||||||
|
|
||||||
|
$this->imported = $this->skipped = 0;
|
||||||
|
|
||||||
|
if ( ! is_file($file) ):
|
||||||
|
$this->footer();
|
||||||
|
die();
|
||||||
|
endif;
|
||||||
|
|
||||||
|
ini_set( 'auto_detect_line_endings', '1' );
|
||||||
|
|
||||||
|
if ( ( $handle = fopen( $file, "r" ) ) !== FALSE ):
|
||||||
|
|
||||||
|
$header = fgetcsv( $handle, 0, $this->delimiter );
|
||||||
|
|
||||||
|
if ( sizeof( $header ) >= 1 ):
|
||||||
|
$action = 'admin.php?import=' . $this->import_page . '&step=2';
|
||||||
|
?>
|
||||||
|
<form enctype="multipart/form-data" id="import-upload-form" class="sportspress" method="post" action="<?php echo esc_attr(wp_nonce_url($action, 'import-upload')); ?>">
|
||||||
|
<?php $this->options(); ?>
|
||||||
|
<table class="wp-list-table sp-data-table sp-import-table widefat fixed pages">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<?php foreach ( $this->columns as $key => $label ): ?>
|
||||||
|
<th scope="col" class="manage-column">
|
||||||
|
<?php $this->dropdown( $key ); ?>
|
||||||
|
</th>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
<th scope="col" class="sp-actions-column">
|
||||||
|
<a href="#" title="<?php _e( 'Insert row after', 'sportspress' ); ?>" class="dashicons dashicons-plus-alt sp-add-row sp-add-first"></a>
|
||||||
|
</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<?php while ( ( $row = fgetcsv( $handle, 0, $this->delimiter ) ) !== FALSE ): ?>
|
||||||
|
<tr>
|
||||||
|
<?php $index = 0; foreach ( $this->columns as $key => $label ): $value = sp_array_value( $row, $index ); ?>
|
||||||
|
<td>
|
||||||
|
<input type="text" class="widefat" value="<?php echo $value; ?>" name="sp_import[]">
|
||||||
|
</td>
|
||||||
|
<?php $index ++; endforeach; ?>
|
||||||
|
<td class="sp-actions-column">
|
||||||
|
<a href="#" title="<?php _e( 'Delete row', 'sportspress' ); ?>" class="sp-icon-trash sp-delete-row"></a>
|
||||||
|
<a href="#" title="<?php _e( 'Insert row after', 'sportspress' ); ?>" class="dashicons dashicons-plus-alt sp-add-row"></a>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<?php $this->imported++; endwhile; ?>
|
||||||
|
<tr>
|
||||||
|
<?php foreach ( $this->columns as $key => $label ): ?>
|
||||||
|
<td>
|
||||||
|
<input type="text" class="widefat" name="sp_import[]">
|
||||||
|
</td>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
<td class="sp-actions-column">
|
||||||
|
<a href="#" title="<?php _e( 'Insert row after', 'sportspress' ); ?>" class="dashicons dashicons-plus-alt sp-add-row"></a>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<p class="sp-post-count alignright">
|
||||||
|
<?php printf( __( 'Displaying %s–%s of %s', 'sportspress' ), 1, $this->imported+1, $this->imported+1 ); ?>
|
||||||
|
</p>
|
||||||
|
<p class="submit">
|
||||||
|
<input type="submit" class="button button-primary button-hero" value="<?php echo esc_attr( $this->import_label ); ?>" />
|
||||||
|
</p>
|
||||||
|
</form>
|
||||||
|
<?php
|
||||||
|
else:
|
||||||
|
|
||||||
|
echo '<p><strong>' . __( 'Sorry, there has been an error.', 'sportspress' ) . '</strong><br />';
|
||||||
|
_e( 'The CSV is invalid.', 'sportspress' ) . '</p>';
|
||||||
|
$this->footer();
|
||||||
|
die();
|
||||||
|
|
||||||
|
endif;
|
||||||
|
|
||||||
|
fclose( $handle );
|
||||||
|
endif;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* format_data_from_csv function.
|
* format_data_from_csv function.
|
||||||
*
|
*
|
||||||
@@ -122,7 +250,7 @@ if ( class_exists( 'WP_Importer' ) ) {
|
|||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function header() {
|
function header() {
|
||||||
echo '<div class="wrap"><h2>' . __( 'Import', 'sportspress' ) . '</h2>';
|
echo '<div class="wrap"><h2>' . $this->import_label . '</h2>';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -135,6 +263,15 @@ if ( class_exists( 'WP_Importer' ) ) {
|
|||||||
echo '</div>';
|
echo '</div>';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* options function.
|
||||||
|
*
|
||||||
|
* @access public
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function options() {
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Added to http_request_timeout filter to force timeout at 60 seconds during import
|
* Added to http_request_timeout filter to force timeout at 60 seconds during import
|
||||||
* @param int $val
|
* @param int $val
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
* @author ThemeBoy
|
* @author ThemeBoy
|
||||||
* @category Admin
|
* @category Admin
|
||||||
* @package SportsPress/Admin/Importers
|
* @package SportsPress/Admin/Importers
|
||||||
* @version 0.9
|
* @version 1.3
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
||||||
@@ -21,119 +21,114 @@ if ( class_exists( 'WP_Importer' ) ) {
|
|||||||
*/
|
*/
|
||||||
public function __construct() {
|
public function __construct() {
|
||||||
$this->import_page = 'sportspress_player_csv';
|
$this->import_page = 'sportspress_player_csv';
|
||||||
|
$this->import_label = __( 'Import Players', 'sportspress' );
|
||||||
|
$this->columns = array(
|
||||||
|
'sp_number' => __( 'Number', 'sportspress' ),
|
||||||
|
'post_title' => __( 'Name', 'sportspress' ),
|
||||||
|
'sp_position' => __( 'Positions', 'sportspress' ),
|
||||||
|
'sp_team' => __( 'Teams', 'sportspress' ),
|
||||||
|
'sp_league' => __( 'Leagues', 'sportspress' ),
|
||||||
|
'sp_season' => __( 'Seasons', 'sportspress' ),
|
||||||
|
'sp_nationality' => __( 'Nationality', 'sportspress' ),
|
||||||
|
);
|
||||||
|
parent::__construct();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* import function.
|
* import function.
|
||||||
*
|
*
|
||||||
* @access public
|
* @access public
|
||||||
* @param mixed $file
|
* @param array $array
|
||||||
|
* @param array $columns
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function import( $file ) {
|
function import( $array = array(), $columns = array( 'post_title' ) ) {
|
||||||
global $wpdb;
|
|
||||||
|
|
||||||
$this->imported = $this->skipped = 0;
|
$this->imported = $this->skipped = 0;
|
||||||
|
|
||||||
if ( ! is_file($file) ):
|
if ( ! is_array( $array ) || ! sizeof( $array ) ):
|
||||||
$this->footer();
|
$this->footer();
|
||||||
die();
|
die();
|
||||||
endif;
|
endif;
|
||||||
|
|
||||||
ini_set( 'auto_detect_line_endings', '1' );
|
$rows = array_chunk( $array, sizeof( $columns ) );
|
||||||
|
|
||||||
if ( ( $handle = fopen( $file, "r" ) ) !== FALSE ):
|
foreach ( $rows as $row ):
|
||||||
|
|
||||||
$header = fgetcsv( $handle, 0, $this->delimiter );
|
if ( empty( array_filter( $row ) ) ) continue;
|
||||||
|
|
||||||
if ( sizeof( $header ) == 7 ):
|
$meta = array();
|
||||||
|
|
||||||
$loop = 0;
|
foreach ( $columns as $index => $key ):
|
||||||
|
$meta[ $key ] = sp_array_value( $row, $index );
|
||||||
|
endforeach;
|
||||||
|
|
||||||
while ( ( $row = fgetcsv( $handle, 0, $this->delimiter ) ) !== FALSE ):
|
$name = sp_array_value( $meta, 'post_title' );
|
||||||
|
|
||||||
list( $number, $name, $positions, $teams, $leagues, $seasons, $nationality ) = $row;
|
|
||||||
|
|
||||||
$nationality = trim( strtoupper( $nationality ) );
|
|
||||||
|
|
||||||
if ( $nationality == '*' )
|
|
||||||
$nationality = '';
|
|
||||||
|
|
||||||
if ( ! $name ):
|
|
||||||
$this->skipped++;
|
|
||||||
continue;
|
|
||||||
endif;
|
|
||||||
|
|
||||||
$args = array( 'post_type' => 'sp_player', 'post_status' => 'publish', 'post_title' => $name );
|
|
||||||
|
|
||||||
$id = wp_insert_post( $args );
|
|
||||||
|
|
||||||
// Flag as import
|
|
||||||
update_post_meta( $id, '_sp_import', 1 );
|
|
||||||
|
|
||||||
// Update number
|
|
||||||
update_post_meta( $id, 'sp_number', $number );
|
|
||||||
|
|
||||||
// Update positions
|
|
||||||
$positions = explode( '|', $positions );
|
|
||||||
wp_set_object_terms( $id, $positions, 'sp_position', false );
|
|
||||||
|
|
||||||
// Update leagues
|
|
||||||
$leagues = explode( '|', $leagues );
|
|
||||||
wp_set_object_terms( $id, $leagues, 'sp_league', false );
|
|
||||||
|
|
||||||
// Update seasons
|
|
||||||
$seasons = explode( '|', $seasons );
|
|
||||||
wp_set_object_terms( $id, $seasons, 'sp_season', false );
|
|
||||||
|
|
||||||
// Update teams
|
|
||||||
$teams = (array)explode( '|', $teams );
|
|
||||||
$i = 0;
|
|
||||||
foreach ( $teams as $team ):
|
|
||||||
// Get or insert team
|
|
||||||
$team_object = get_page_by_title( $team, OBJECT, 'sp_team' );
|
|
||||||
if ( $team_object ):
|
|
||||||
if ( $team_object->post_status != 'publish' ):
|
|
||||||
wp_update_post( array( 'ID' => $team_object->ID, 'post_status' => 'publish' ) );
|
|
||||||
endif;
|
|
||||||
$team_id = $team_object->ID;
|
|
||||||
else:
|
|
||||||
$team_id = wp_insert_post( array( 'post_type' => 'sp_team', 'post_status' => 'publish', 'post_title' => $team ) );
|
|
||||||
// Flag as import
|
|
||||||
update_post_meta( $team_id, '_sp_import', 1 );
|
|
||||||
wp_set_object_terms( $team_id, $leagues, 'sp_league', false );
|
|
||||||
wp_set_object_terms( $team_id, $seasons, 'sp_season', false );
|
|
||||||
endif;
|
|
||||||
|
|
||||||
// Add team to player
|
|
||||||
add_post_meta( $id, 'sp_team', $team_id );
|
|
||||||
|
|
||||||
// Update current team if first in array
|
|
||||||
if ( $i == 0 ):
|
|
||||||
update_post_meta( $id, 'sp_current_team', $team_id );
|
|
||||||
endif;
|
|
||||||
|
|
||||||
$i++;
|
|
||||||
endforeach;
|
|
||||||
|
|
||||||
// Update nationality
|
|
||||||
update_post_meta( $id, 'sp_nationality', $nationality );
|
|
||||||
|
|
||||||
$loop ++;
|
|
||||||
$this->imported++;
|
|
||||||
endwhile;
|
|
||||||
|
|
||||||
else:
|
|
||||||
|
|
||||||
echo '<p><strong>' . __( 'Sorry, there has been an error.', 'sportspress' ) . '</strong><br />';
|
|
||||||
_e( 'The CSV is invalid.', 'sportspress' ) . '</p>';
|
|
||||||
$this->footer();
|
|
||||||
die();
|
|
||||||
|
|
||||||
|
if ( ! $name ):
|
||||||
|
$this->skipped++;
|
||||||
|
continue;
|
||||||
endif;
|
endif;
|
||||||
|
|
||||||
fclose( $handle );
|
$args = array( 'post_type' => 'sp_player', 'post_status' => 'publish', 'post_title' => $name );
|
||||||
endif;
|
|
||||||
|
$id = wp_insert_post( $args );
|
||||||
|
|
||||||
|
// Flag as import
|
||||||
|
update_post_meta( $id, '_sp_import', 1 );
|
||||||
|
|
||||||
|
// Update number
|
||||||
|
update_post_meta( $id, 'sp_number', sp_array_value( $meta, 'sp_number' ) );
|
||||||
|
|
||||||
|
// Update positions
|
||||||
|
$positions = explode( '|', sp_array_value( $meta, 'sp_position' ) );
|
||||||
|
wp_set_object_terms( $id, $positions, 'sp_position', false );
|
||||||
|
|
||||||
|
// Update leagues
|
||||||
|
$leagues = explode( '|', sp_array_value( $meta, 'sp_league' ) );
|
||||||
|
wp_set_object_terms( $id, $leagues, 'sp_league', false );
|
||||||
|
|
||||||
|
// Update seasons
|
||||||
|
$seasons = explode( '|', sp_array_value( $meta, 'sp_season' ) );
|
||||||
|
wp_set_object_terms( $id, $seasons, 'sp_season', false );
|
||||||
|
|
||||||
|
// Update teams
|
||||||
|
$teams = (array)explode( '|', sp_array_value( $meta, 'sp_team' ) );
|
||||||
|
$i = 0;
|
||||||
|
foreach ( $teams as $team ):
|
||||||
|
// Get or insert team
|
||||||
|
$team_object = get_page_by_title( $team, OBJECT, 'sp_team' );
|
||||||
|
if ( $team_object ):
|
||||||
|
if ( $team_object->post_status != 'publish' ):
|
||||||
|
wp_update_post( array( 'ID' => $team_object->ID, 'post_status' => 'publish' ) );
|
||||||
|
endif;
|
||||||
|
$team_id = $team_object->ID;
|
||||||
|
else:
|
||||||
|
$team_id = wp_insert_post( array( 'post_type' => 'sp_team', 'post_status' => 'publish', 'post_title' => $team ) );
|
||||||
|
// Flag as import
|
||||||
|
update_post_meta( $team_id, '_sp_import', 1 );
|
||||||
|
wp_set_object_terms( $team_id, $leagues, 'sp_league', false );
|
||||||
|
wp_set_object_terms( $team_id, $seasons, 'sp_season', false );
|
||||||
|
endif;
|
||||||
|
|
||||||
|
// Add team to player
|
||||||
|
add_post_meta( $id, 'sp_team', $team_id );
|
||||||
|
|
||||||
|
// Update current team if first in array
|
||||||
|
if ( $i == 0 ):
|
||||||
|
update_post_meta( $id, 'sp_current_team', $team_id );
|
||||||
|
endif;
|
||||||
|
|
||||||
|
$i++;
|
||||||
|
endforeach;
|
||||||
|
|
||||||
|
// Update nationality
|
||||||
|
$nationality = trim( strtoupper( sp_array_value( $meta, 'sp_nationality' ) ) );
|
||||||
|
if ( $nationality == '*' ) $nationality = '';
|
||||||
|
update_post_meta( $id, 'sp_nationality', $nationality );
|
||||||
|
|
||||||
|
$this->imported++;
|
||||||
|
|
||||||
|
endforeach;
|
||||||
|
|
||||||
// Show Result
|
// Show Result
|
||||||
echo '<div class="updated settings-error below-h2"><p>
|
echo '<div class="updated settings-error below-h2"><p>
|
||||||
@@ -169,57 +164,10 @@ if ( class_exists( 'WP_Importer' ) ) {
|
|||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function greet() {
|
function greet() {
|
||||||
|
|
||||||
echo '<div class="narrow">';
|
echo '<div class="narrow">';
|
||||||
echo '<p>' . __( 'Hi there! Choose a .csv file to upload, then click "Upload file and import".', 'sportspress' ).'</p>';
|
echo '<p>' . __( 'Hi there! Choose a .csv file to upload, then click "Upload file and import".', 'sportspress' ).'</p>';
|
||||||
|
|
||||||
echo '<p>' . sprintf( __( 'Players need to be defined with columns in a specific order (7 columns). <a href="%s">Click here to download a sample</a>.', 'sportspress' ), plugin_dir_url( SP_PLUGIN_FILE ) . 'dummy-data/players-sample.csv' ) . '</p>';
|
echo '<p>' . sprintf( __( 'Players need to be defined with columns in a specific order (7 columns). <a href="%s">Click here to download a sample</a>.', 'sportspress' ), plugin_dir_url( SP_PLUGIN_FILE ) . 'dummy-data/players-sample.csv' ) . '</p>';
|
||||||
|
wp_import_upload_form( 'admin.php?import=sportspress_player_csv&step=1' );
|
||||||
$action = 'admin.php?import=sportspress_player_csv&step=1';
|
|
||||||
|
|
||||||
$bytes = apply_filters( 'import_upload_size_limit', wp_max_upload_size() );
|
|
||||||
$size = size_format( $bytes );
|
|
||||||
$upload_dir = wp_upload_dir();
|
|
||||||
if ( ! empty( $upload_dir['error'] ) ) :
|
|
||||||
?><div class="error"><p><?php _e('Before you can upload your import file, you will need to fix the following error:', 'sportspress'); ?></p>
|
|
||||||
<p><strong><?php echo $upload_dir['error']; ?></strong></p></div><?php
|
|
||||||
else :
|
|
||||||
?>
|
|
||||||
<form enctype="multipart/form-data" id="import-upload-form" method="post" action="<?php echo esc_attr(wp_nonce_url($action, 'import-upload')); ?>">
|
|
||||||
<table class="form-table">
|
|
||||||
<tbody>
|
|
||||||
<tr>
|
|
||||||
<th>
|
|
||||||
<label for="upload"><?php _e( 'Choose a file from your computer:', 'sportspress' ); ?></label>
|
|
||||||
</th>
|
|
||||||
<td>
|
|
||||||
<input type="file" id="upload" name="import" size="25" />
|
|
||||||
<input type="hidden" name="action" value="save" />
|
|
||||||
<input type="hidden" name="max_file_size" value="<?php echo $bytes; ?>" />
|
|
||||||
<small><?php printf( __( 'Maximum size: %s', 'sportspress' ), $size ); ?></small>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<th>
|
|
||||||
<label for="file_url"><?php _e( 'OR enter path to file:', 'sportspress' ); ?></label>
|
|
||||||
</th>
|
|
||||||
<td>
|
|
||||||
<?php echo ' ' . ABSPATH . ' '; ?><input type="text" id="file_url" name="file_url" size="25" />
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<th><label><?php _e( 'Delimiter', 'sportspress' ); ?></label><br/></th>
|
|
||||||
<td><input type="text" name="delimiter" placeholder="," size="2" /></td>
|
|
||||||
</tr>
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
<p class="submit">
|
|
||||||
<input type="submit" class="button" value="<?php esc_attr_e( 'Upload file and import', 'sportspress' ); ?>" />
|
|
||||||
</p>
|
|
||||||
</form>
|
|
||||||
<?php
|
|
||||||
endif;
|
|
||||||
|
|
||||||
echo '</div>';
|
echo '</div>';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
* @author ThemeBoy
|
* @author ThemeBoy
|
||||||
* @category Admin
|
* @category Admin
|
||||||
* @package SportsPress/Admin/Importers
|
* @package SportsPress/Admin/Importers
|
||||||
* @version 0.9
|
* @version 1.3
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
||||||
@@ -21,112 +21,110 @@ if ( class_exists( 'WP_Importer' ) ) {
|
|||||||
*/
|
*/
|
||||||
public function __construct() {
|
public function __construct() {
|
||||||
$this->import_page = 'sportspress_staff_csv';
|
$this->import_page = 'sportspress_staff_csv';
|
||||||
|
$this->import_label = __( 'Import Staff', 'sportspress' );
|
||||||
|
$this->columns = array(
|
||||||
|
'post_title' => __( 'Name', 'sportspress' ),
|
||||||
|
'sp_role' => __( 'Roles', 'sportspress' ),
|
||||||
|
'sp_team' => __( 'Teams', 'sportspress' ),
|
||||||
|
'sp_league' => __( 'Leagues', 'sportspress' ),
|
||||||
|
'sp_season' => __( 'Seasons', 'sportspress' ),
|
||||||
|
'sp_nationality' => __( 'Nationality', 'sportspress' ),
|
||||||
|
);
|
||||||
|
parent::__construct();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* import function.
|
* import function.
|
||||||
*
|
*
|
||||||
* @access public
|
* @access public
|
||||||
* @param mixed $file
|
* @param array $array
|
||||||
|
* @param array $columns
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function import( $file ) {
|
function import( $array = array(), $columns = array( 'post_title' ) ) {
|
||||||
global $wpdb;
|
|
||||||
|
|
||||||
$this->imported = $this->skipped = 0;
|
$this->imported = $this->skipped = 0;
|
||||||
|
|
||||||
if ( ! is_file($file) ):
|
if ( ! is_array( $array ) || ! sizeof( $array ) ):
|
||||||
$this->footer();
|
$this->footer();
|
||||||
die();
|
die();
|
||||||
endif;
|
endif;
|
||||||
|
|
||||||
ini_set( 'auto_detect_line_endings', '1' );
|
$rows = array_chunk( $array, sizeof( $columns ) );
|
||||||
|
|
||||||
if ( ( $handle = fopen( $file, "r" ) ) !== FALSE ):
|
foreach ( $rows as $row ):
|
||||||
|
|
||||||
$header = fgetcsv( $handle, 0, $this->delimiter );
|
if ( empty( array_filter( $row ) ) ) continue;
|
||||||
|
|
||||||
if ( sizeof( $header ) == 5 ):
|
$meta = array();
|
||||||
|
|
||||||
$loop = 0;
|
foreach ( $columns as $index => $key ):
|
||||||
|
$meta[ $key ] = sp_array_value( $row, $index );
|
||||||
|
endforeach;
|
||||||
|
|
||||||
while ( ( $row = fgetcsv( $handle, 0, $this->delimiter ) ) !== FALSE ):
|
$name = sp_array_value( $meta, 'post_title' );
|
||||||
|
|
||||||
list( $name, $teams, $leagues, $seasons, $nationality ) = $row;
|
|
||||||
|
|
||||||
$nationality = trim( strtoupper( $nationality ) );
|
|
||||||
|
|
||||||
if ( $nationality == '*' )
|
|
||||||
$nationality = '';
|
|
||||||
|
|
||||||
if ( ! $name ):
|
|
||||||
$this->skipped++;
|
|
||||||
continue;
|
|
||||||
endif;
|
|
||||||
|
|
||||||
$args = array( 'post_type' => 'sp_staff', 'post_status' => 'publish', 'post_title' => $name );
|
|
||||||
|
|
||||||
$id = wp_insert_post( $args );
|
|
||||||
|
|
||||||
// Flag as import
|
|
||||||
update_post_meta( $id, '_sp_import', 1 );
|
|
||||||
|
|
||||||
// Update leagues
|
|
||||||
$leagues = explode( '|', $leagues );
|
|
||||||
wp_set_object_terms( $id, $leagues, 'sp_league', false );
|
|
||||||
|
|
||||||
// Update seasons
|
|
||||||
$seasons = explode( '|', $seasons );
|
|
||||||
wp_set_object_terms( $id, $seasons, 'sp_season', false );
|
|
||||||
|
|
||||||
// Update teams
|
|
||||||
$teams = (array)explode( '|', $teams );
|
|
||||||
$i = 0;
|
|
||||||
foreach ( $teams as $team ):
|
|
||||||
// Get or insert team
|
|
||||||
$team_object = get_page_by_title( $team, OBJECT, 'sp_team' );
|
|
||||||
if ( $team_object ):
|
|
||||||
if ( $team_object->post_status != 'publish' ):
|
|
||||||
wp_update_post( array( 'ID' => $team_object->ID, 'post_status' => 'publish' ) );
|
|
||||||
endif;
|
|
||||||
$team_id = $team_object->ID;
|
|
||||||
else:
|
|
||||||
$team_id = wp_insert_post( array( 'post_type' => 'sp_team', 'post_status' => 'publish', 'post_title' => $team ) );
|
|
||||||
// Flag as import
|
|
||||||
update_post_meta( $team_id, '_sp_import', 1 );
|
|
||||||
wp_set_object_terms( $team_id, $leagues, 'sp_league', false );
|
|
||||||
wp_set_object_terms( $team_id, $seasons, 'sp_season', false );
|
|
||||||
endif;
|
|
||||||
|
|
||||||
// Add team to staff
|
|
||||||
add_post_meta( $id, 'sp_team', $team_id );
|
|
||||||
|
|
||||||
// Update current team if first in array
|
|
||||||
if ( $i == 0 ):
|
|
||||||
update_post_meta( $id, 'sp_current_team', $team_id );
|
|
||||||
endif;
|
|
||||||
|
|
||||||
$i++;
|
|
||||||
endforeach;
|
|
||||||
|
|
||||||
// Update nationality
|
|
||||||
update_post_meta( $id, 'sp_nationality', $nationality );
|
|
||||||
|
|
||||||
$loop ++;
|
|
||||||
$this->imported++;
|
|
||||||
endwhile;
|
|
||||||
|
|
||||||
else:
|
|
||||||
|
|
||||||
echo '<p><strong>' . __( 'Sorry, there has been an error.', 'sportspress' ) . '</strong><br />';
|
|
||||||
_e( 'The CSV is invalid.', 'sportspress' ) . '</p>';
|
|
||||||
$this->footer();
|
|
||||||
die();
|
|
||||||
|
|
||||||
|
if ( ! $name ):
|
||||||
|
$this->skipped++;
|
||||||
|
continue;
|
||||||
endif;
|
endif;
|
||||||
|
|
||||||
fclose( $handle );
|
$args = array( 'post_type' => 'sp_staff', 'post_status' => 'publish', 'post_title' => $name );
|
||||||
endif;
|
|
||||||
|
$id = wp_insert_post( $args );
|
||||||
|
|
||||||
|
// Flag as import
|
||||||
|
update_post_meta( $id, '_sp_import', 1 );
|
||||||
|
|
||||||
|
// Update roles
|
||||||
|
$roles = explode( '|', sp_array_value( $meta, 'sp_role' ) );
|
||||||
|
wp_set_object_terms( $id, $roles, 'sp_role', false );
|
||||||
|
|
||||||
|
// Update leagues
|
||||||
|
$leagues = explode( '|', sp_array_value( $meta, 'sp_league' ) );
|
||||||
|
wp_set_object_terms( $id, $leagues, 'sp_league', false );
|
||||||
|
|
||||||
|
// Update seasons
|
||||||
|
$seasons = explode( '|', sp_array_value( $meta, 'sp_season' ) );
|
||||||
|
wp_set_object_terms( $id, $seasons, 'sp_season', false );
|
||||||
|
|
||||||
|
// Update teams
|
||||||
|
$teams = (array)explode( '|', sp_array_value( $meta, 'sp_team' ) );
|
||||||
|
$i = 0;
|
||||||
|
foreach ( $teams as $team ):
|
||||||
|
// Get or insert team
|
||||||
|
$team_object = get_page_by_title( $team, OBJECT, 'sp_team' );
|
||||||
|
if ( $team_object ):
|
||||||
|
if ( $team_object->post_status != 'publish' ):
|
||||||
|
wp_update_post( array( 'ID' => $team_object->ID, 'post_status' => 'publish' ) );
|
||||||
|
endif;
|
||||||
|
$team_id = $team_object->ID;
|
||||||
|
else:
|
||||||
|
$team_id = wp_insert_post( array( 'post_type' => 'sp_team', 'post_status' => 'publish', 'post_title' => $team ) );
|
||||||
|
// Flag as import
|
||||||
|
update_post_meta( $team_id, '_sp_import', 1 );
|
||||||
|
wp_set_object_terms( $team_id, $leagues, 'sp_league', false );
|
||||||
|
wp_set_object_terms( $team_id, $seasons, 'sp_season', false );
|
||||||
|
endif;
|
||||||
|
|
||||||
|
// Add team to staff
|
||||||
|
add_post_meta( $id, 'sp_team', $team_id );
|
||||||
|
|
||||||
|
// Update current team if first in array
|
||||||
|
if ( $i == 0 ):
|
||||||
|
update_post_meta( $id, 'sp_current_team', $team_id );
|
||||||
|
endif;
|
||||||
|
|
||||||
|
$i++;
|
||||||
|
endforeach;
|
||||||
|
|
||||||
|
// Update nationality
|
||||||
|
$nationality = trim( strtoupper( sp_array_value( $meta, 'sp_nationality' ) ) );
|
||||||
|
if ( $nationality == '*' ) $nationality = '';
|
||||||
|
update_post_meta( $id, 'sp_nationality', $nationality );
|
||||||
|
|
||||||
|
$this->imported++;
|
||||||
|
|
||||||
|
endforeach;
|
||||||
|
|
||||||
// Show Result
|
// Show Result
|
||||||
echo '<div class="updated settings-error below-h2"><p>
|
echo '<div class="updated settings-error below-h2"><p>
|
||||||
@@ -162,57 +160,10 @@ if ( class_exists( 'WP_Importer' ) ) {
|
|||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function greet() {
|
function greet() {
|
||||||
|
|
||||||
echo '<div class="narrow">';
|
echo '<div class="narrow">';
|
||||||
echo '<p>' . __( 'Hi there! Choose a .csv file to upload, then click "Upload file and import".', 'sportspress' ).'</p>';
|
echo '<p>' . __( 'Hi there! Choose a .csv file to upload, then click "Upload file and import".', 'sportspress' ).'</p>';
|
||||||
|
echo '<p>' . sprintf( __( 'Staff need to be defined with columns in a specific order (6 columns). <a href="%s">Click here to download a sample</a>.', 'sportspress' ), plugin_dir_url( SP_PLUGIN_FILE ) . 'dummy-data/staff-sample.csv' ) . '</p>';
|
||||||
echo '<p>' . sprintf( __( 'Staff need to be defined with columns in a specific order (5 columns). <a href="%s">Click here to download a sample</a>.', 'sportspress' ), plugin_dir_url( SP_PLUGIN_FILE ) . 'dummy-data/staff-sample.csv' ) . '</p>';
|
wp_import_upload_form( 'admin.php?import=sportspress_staff_csv&step=1' );
|
||||||
|
|
||||||
$action = 'admin.php?import=sportspress_staff_csv&step=1';
|
|
||||||
|
|
||||||
$bytes = apply_filters( 'import_upload_size_limit', wp_max_upload_size() );
|
|
||||||
$size = size_format( $bytes );
|
|
||||||
$upload_dir = wp_upload_dir();
|
|
||||||
if ( ! empty( $upload_dir['error'] ) ) :
|
|
||||||
?><div class="error"><p><?php _e('Before you can upload your import file, you will need to fix the following error:', 'sportspress'); ?></p>
|
|
||||||
<p><strong><?php echo $upload_dir['error']; ?></strong></p></div><?php
|
|
||||||
else :
|
|
||||||
?>
|
|
||||||
<form enctype="multipart/form-data" id="import-upload-form" method="post" action="<?php echo esc_attr(wp_nonce_url($action, 'import-upload')); ?>">
|
|
||||||
<table class="form-table">
|
|
||||||
<tbody>
|
|
||||||
<tr>
|
|
||||||
<th>
|
|
||||||
<label for="upload"><?php _e( 'Choose a file from your computer:', 'sportspress' ); ?></label>
|
|
||||||
</th>
|
|
||||||
<td>
|
|
||||||
<input type="file" id="upload" name="import" size="25" />
|
|
||||||
<input type="hidden" name="action" value="save" />
|
|
||||||
<input type="hidden" name="max_file_size" value="<?php echo $bytes; ?>" />
|
|
||||||
<small><?php printf( __( 'Maximum size: %s', 'sportspress' ), $size ); ?></small>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<th>
|
|
||||||
<label for="file_url"><?php _e( 'OR enter path to file:', 'sportspress' ); ?></label>
|
|
||||||
</th>
|
|
||||||
<td>
|
|
||||||
<?php echo ' ' . ABSPATH . ' '; ?><input type="text" id="file_url" name="file_url" size="25" />
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<th><label><?php _e( 'Delimiter', 'sportspress' ); ?></label><br/></th>
|
|
||||||
<td><input type="text" name="delimiter" placeholder="," size="2" /></td>
|
|
||||||
</tr>
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
<p class="submit">
|
|
||||||
<input type="submit" class="button" value="<?php esc_attr_e( 'Upload file and import', 'sportspress' ); ?>" />
|
|
||||||
</p>
|
|
||||||
</form>
|
|
||||||
<?php
|
|
||||||
endif;
|
|
||||||
|
|
||||||
echo '</div>';
|
echo '</div>';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
* @author ThemeBoy
|
* @author ThemeBoy
|
||||||
* @category Admin
|
* @category Admin
|
||||||
* @package SportsPress/Admin/Importers
|
* @package SportsPress/Admin/Importers
|
||||||
* @version 0.9
|
* @version 1.3
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
||||||
@@ -21,76 +21,71 @@ if ( class_exists( 'WP_Importer' ) ) {
|
|||||||
*/
|
*/
|
||||||
public function __construct() {
|
public function __construct() {
|
||||||
$this->import_page = 'sportspress_team_csv';
|
$this->import_page = 'sportspress_team_csv';
|
||||||
|
$this->import_label = __( 'Import Teams', 'sportspress' );
|
||||||
|
$this->columns = array(
|
||||||
|
'post_title' => __( 'Name', 'sportspress' ),
|
||||||
|
'sp_league' => __( 'Leagues', 'sportspress' ),
|
||||||
|
'sp_season' => __( 'Seasons', 'sportspress' ),
|
||||||
|
'sp_url' => __( 'Site URL', 'sportspress' ),
|
||||||
|
'sp_abbreviation' => __( 'Abbreviation', 'sportspress' ),
|
||||||
|
'sp_venue' => __( 'Home', 'sportspress' ),
|
||||||
|
);
|
||||||
|
parent::__construct();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* import function.
|
* import function.
|
||||||
*
|
*
|
||||||
* @access public
|
* @access public
|
||||||
* @param mixed $file
|
* @param array $array
|
||||||
|
* @param array $columns
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function import( $file ) {
|
function import( $array = array(), $columns = array( 'post_title' ) ) {
|
||||||
global $wpdb;
|
|
||||||
|
|
||||||
$this->imported = $this->skipped = 0;
|
$this->imported = $this->skipped = 0;
|
||||||
|
|
||||||
if ( ! is_file($file) ):
|
if ( ! is_array( $array ) || ! sizeof( $array ) ):
|
||||||
$this->footer();
|
$this->footer();
|
||||||
die();
|
die();
|
||||||
endif;
|
endif;
|
||||||
|
|
||||||
ini_set( 'auto_detect_line_endings', '1' );
|
$rows = array_chunk( $array, sizeof( $columns ) );
|
||||||
|
|
||||||
if ( ( $handle = fopen( $file, "r" ) ) !== FALSE ):
|
foreach ( $rows as $row ):
|
||||||
|
|
||||||
$header = fgetcsv( $handle, 0, $this->delimiter );
|
if ( empty( array_filter( $row ) ) ) continue;
|
||||||
|
|
||||||
if ( sizeof( $header ) == 3 ):
|
$meta = array();
|
||||||
|
|
||||||
$loop = 0;
|
foreach ( $columns as $index => $key ):
|
||||||
|
$meta[ $key ] = sp_array_value( $row, $index );
|
||||||
|
endforeach;
|
||||||
|
|
||||||
while ( ( $row = fgetcsv( $handle, 0, $this->delimiter ) ) !== FALSE ):
|
$name = sp_array_value( $meta, 'post_title' );
|
||||||
|
|
||||||
list( $name, $leagues, $seasons ) = $row;
|
|
||||||
|
|
||||||
$team_object = get_page_by_title( $name, OBJECT, 'sp_team' );
|
|
||||||
|
|
||||||
if ( ! $name || $team_object ):
|
|
||||||
$this->skipped++;
|
|
||||||
continue;
|
|
||||||
endif;
|
|
||||||
|
|
||||||
$args = array( 'post_type' => 'sp_team', 'post_status' => 'publish', 'post_title' => $name );
|
|
||||||
|
|
||||||
$id = wp_insert_post( $args );
|
|
||||||
|
|
||||||
// Flag as import
|
|
||||||
update_post_meta( $id, '_sp_import', 1 );
|
|
||||||
|
|
||||||
// Update leagues
|
|
||||||
$leagues = explode( '|', $leagues );
|
|
||||||
wp_set_object_terms( $id, $leagues, 'sp_league', false );
|
|
||||||
|
|
||||||
// Update seasons
|
|
||||||
$seasons = explode( '|', $seasons );
|
|
||||||
wp_set_object_terms( $id, $seasons, 'sp_season', false );
|
|
||||||
|
|
||||||
$loop ++;
|
|
||||||
$this->imported++;
|
|
||||||
endwhile;
|
|
||||||
|
|
||||||
else:
|
|
||||||
|
|
||||||
echo '<p><strong>' . __( 'Sorry, there has been an error.', 'sportspress' ) . '</strong><br />';
|
|
||||||
_e( 'The CSV is invalid.', 'sportspress' ) . '</p>';
|
|
||||||
$this->footer();
|
|
||||||
die();
|
|
||||||
|
|
||||||
|
if ( ! $name ):
|
||||||
|
$this->skipped++;
|
||||||
|
continue;
|
||||||
endif;
|
endif;
|
||||||
|
|
||||||
fclose( $handle );
|
$args = array( 'post_type' => 'sp_team', 'post_status' => 'publish', 'post_title' => $name );
|
||||||
endif;
|
|
||||||
|
$id = wp_insert_post( $args );
|
||||||
|
|
||||||
|
// Flag as import
|
||||||
|
update_post_meta( $id, '_sp_import', 1 );
|
||||||
|
|
||||||
|
// Update leagues
|
||||||
|
$leagues = explode( '|', sp_array_value( $meta, 'sp_league' ) );
|
||||||
|
wp_set_object_terms( $id, $leagues, 'sp_league', false );
|
||||||
|
|
||||||
|
// Update seasons
|
||||||
|
$seasons = explode( '|', sp_array_value( $meta, 'sp_season' ) );
|
||||||
|
wp_set_object_terms( $id, $seasons, 'sp_season', false );
|
||||||
|
|
||||||
|
$this->imported++;
|
||||||
|
|
||||||
|
endforeach;
|
||||||
|
|
||||||
// Show Result
|
// Show Result
|
||||||
echo '<div class="updated settings-error below-h2"><p>
|
echo '<div class="updated settings-error below-h2"><p>
|
||||||
@@ -109,16 +104,6 @@ if ( class_exists( 'WP_Importer' ) ) {
|
|||||||
do_action( 'import_end' );
|
do_action( 'import_end' );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* header function.
|
|
||||||
*
|
|
||||||
* @access public
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
function header() {
|
|
||||||
echo '<div class="wrap"><h2>' . __( 'Import Teams', 'sportspress' ) . '</h2>';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* greet function.
|
* greet function.
|
||||||
*
|
*
|
||||||
@@ -126,57 +111,10 @@ if ( class_exists( 'WP_Importer' ) ) {
|
|||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function greet() {
|
function greet() {
|
||||||
|
|
||||||
echo '<div class="narrow">';
|
echo '<div class="narrow">';
|
||||||
echo '<p>' . __( 'Hi there! Choose a .csv file to upload, then click "Upload file and import".', 'sportspress' ).'</p>';
|
echo '<p>' . __( 'Hi there! Choose a .csv file to upload, then click "Upload file and import".', 'sportspress' ).'</p>';
|
||||||
|
|
||||||
echo '<p>' . sprintf( __( 'Teams need to be defined with columns in a specific order (3 columns). <a href="%s">Click here to download a sample</a>.', 'sportspress' ), plugin_dir_url( SP_PLUGIN_FILE ) . 'dummy-data/teams-sample.csv' ) . '</p>';
|
echo '<p>' . sprintf( __( 'Teams need to be defined with columns in a specific order (3 columns). <a href="%s">Click here to download a sample</a>.', 'sportspress' ), plugin_dir_url( SP_PLUGIN_FILE ) . 'dummy-data/teams-sample.csv' ) . '</p>';
|
||||||
|
wp_import_upload_form( 'admin.php?import=sportspress_team_csv&step=1' );
|
||||||
$action = 'admin.php?import=sportspress_team_csv&step=1';
|
|
||||||
|
|
||||||
$bytes = apply_filters( 'import_upload_size_limit', wp_max_upload_size() );
|
|
||||||
$size = size_format( $bytes );
|
|
||||||
$upload_dir = wp_upload_dir();
|
|
||||||
if ( ! empty( $upload_dir['error'] ) ) :
|
|
||||||
?><div class="error"><p><?php _e('Before you can upload your import file, you will need to fix the following error:', 'sportspress'); ?></p>
|
|
||||||
<p><strong><?php echo $upload_dir['error']; ?></strong></p></div><?php
|
|
||||||
else :
|
|
||||||
?>
|
|
||||||
<form enctype="multipart/form-data" id="import-upload-form" method="post" action="<?php echo esc_attr(wp_nonce_url($action, 'import-upload')); ?>">
|
|
||||||
<table class="form-table">
|
|
||||||
<tbody>
|
|
||||||
<tr>
|
|
||||||
<th>
|
|
||||||
<label for="upload"><?php _e( 'Choose a file from your computer:', 'sportspress' ); ?></label>
|
|
||||||
</th>
|
|
||||||
<td>
|
|
||||||
<input type="file" id="upload" name="import" size="25" />
|
|
||||||
<input type="hidden" name="action" value="save" />
|
|
||||||
<input type="hidden" name="max_file_size" value="<?php echo $bytes; ?>" />
|
|
||||||
<small><?php printf( __( 'Maximum size: %s', 'sportspress' ), $size ); ?></small>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<th>
|
|
||||||
<label for="file_url"><?php _e( 'OR enter path to file:', 'sportspress' ); ?></label>
|
|
||||||
</th>
|
|
||||||
<td>
|
|
||||||
<?php echo ' ' . ABSPATH . ' '; ?><input type="text" id="file_url" name="file_url" size="25" />
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<th><label><?php _e( 'Delimiter', 'sportspress' ); ?></label><br/></th>
|
|
||||||
<td><input type="text" name="delimiter" placeholder="," size="2" /></td>
|
|
||||||
</tr>
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
<p class="submit">
|
|
||||||
<input type="submit" class="button" value="<?php esc_attr_e( 'Upload file and import', 'sportspress' ); ?>" />
|
|
||||||
</p>
|
|
||||||
</form>
|
|
||||||
<?php
|
|
||||||
endif;
|
|
||||||
|
|
||||||
echo '</div>';
|
echo '</div>';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
|||||||
*/
|
*/
|
||||||
function sp_get_screen_ids() {
|
function sp_get_screen_ids() {
|
||||||
return apply_filters( 'sportspress_screen_ids', array(
|
return apply_filters( 'sportspress_screen_ids', array(
|
||||||
|
'admin',
|
||||||
'widgets',
|
'widgets',
|
||||||
'dashboard',
|
'dashboard',
|
||||||
'dashboard_page_sp-about',
|
'dashboard_page_sp-about',
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ class SP_WPML {
|
|||||||
// Get translated post ID
|
// Get translated post ID
|
||||||
$translated_id = icl_object_id( $id, 'any', false, ICL_LANGUAGE_CODE );
|
$translated_id = icl_object_id( $id, 'any', false, ICL_LANGUAGE_CODE );
|
||||||
|
|
||||||
if ( $translated_id && $translated_id != $id ):
|
if ( $translated_id && $translated_id != $id && get_the_ID() != $translated_id ):
|
||||||
return get_permalink( $translated_id, $leavename );
|
return get_permalink( $translated_id, $leavename );
|
||||||
endif;
|
endif;
|
||||||
endif;
|
endif;
|
||||||
@@ -59,7 +59,7 @@ class SP_WPML {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static function can_localize( $post, $id = null ) {
|
public static function can_localize( $post, $id = null ) {
|
||||||
return function_exists( 'icl_object_id' ) && is_sp_post_type( get_post_type( $post ) ) && $id != get_the_ID();
|
return function_exists( 'icl_object_id' ) && is_sp_post_type( get_post_type( $post ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user