├── .htaccess ├── LICENSE ├── README.ja.md ├── README.md ├── assets ├── .htaccess ├── css │ └── gutenberg.css ├── img │ ├── icon-128x128.png │ └── icon-24x24.png └── js │ ├── .htaccess │ └── __tests__ │ └── utils.js ├── autoload.php ├── configs ├── config.php ├── db.php ├── design_preset.php ├── filter.php ├── io.php ├── preset.php └── setting.php ├── index.php ├── languages ├── add-richtext-toolbar-button-ja.mo └── add-richtext-toolbar-button-ja.po ├── readme.txt ├── src ├── classes │ ├── controllers │ │ └── admin │ │ │ └── dashboard.php │ └── models │ │ ├── assets.php │ │ ├── custom_post │ │ └── setting.php │ │ ├── editor.php │ │ ├── style.php │ │ └── validation.php ├── interfaces │ └── models │ │ └── custom_post.php ├── traits │ └── models │ │ └── custom_post.php └── views │ ├── admin │ ├── custom_post │ │ └── setting │ │ │ ├── detail.php │ │ │ ├── preview.php │ │ │ └── preview │ │ │ └── icon.php │ ├── include │ │ └── custom_post │ │ │ ├── icon.php │ │ │ ├── style.php │ │ │ └── test.php │ ├── script │ │ ├── custom_post │ │ │ ├── preview.php │ │ │ └── setting.php │ │ ├── dashboard.php │ │ └── icon.php │ └── style │ │ ├── custom_post │ │ ├── preview.php │ │ └── setting.php │ │ └── dashboard.php │ └── front │ └── style.php └── tests ├── controllers └── admin │ └── test-dashboard.php └── models ├── custom_post └── test-setting.php ├── test-assets.php ├── test-editor.php ├── test-style.php └── test-validation.php /.htaccess: -------------------------------------------------------------------------------- 1 | Order Deny,Allow 2 | Deny from all -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | Add RichText Toolbar Button 635 | Copyright (C) 2019 technote 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Add RichText Toolbar Button Copyright (C) 2019 technote 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.ja.md: -------------------------------------------------------------------------------- 1 | # Add RichText Toolbar Button 2 | 3 | [![CI Status](https://github.com/technote-space/add-richtext-toolbar-button/workflows/CI/badge.svg)](https://github.com/technote-space/add-richtext-toolbar-button/actions) 4 | [![codecov](https://codecov.io/gh/technote-space/add-richtext-toolbar-button/branch/master/graph/badge.svg)](https://codecov.io/gh/technote-space/add-richtext-toolbar-button) 5 | [![CodeFactor](https://www.codefactor.io/repository/github/technote-space/add-richtext-toolbar-button/badge)](https://www.codefactor.io/repository/github/technote-space/add-richtext-toolbar-button) 6 | [![License: GPL v2+](https://img.shields.io/badge/License-GPL%20v2%2B-blue.svg)](http://www.gnu.org/licenses/gpl-2.0.html) 7 | [![PHP: >=5.6](https://img.shields.io/badge/PHP-%3E%3D5.6-orange.svg)](http://php.net/) 8 | [![WordPress: >=5.4](https://img.shields.io/badge/WordPress-%3E%3D5.4-brightgreen.svg)](https://wordpress.org/) 9 | 10 | ![バナー](https://raw.githubusercontent.com/technote-space/add-richtext-toolbar-button/images/assets/banner-772x250.png) 11 | 12 | *Read this in other languages: [English](README.md), [日本語](README.ja.md).* 13 | 14 | Gutenberg エディタのツールバーに文章修飾用のボタンを追加するプラグインです。 15 | 16 | [最新バージョン](https://github.com/technote-space/add-richtext-toolbar-button/releases/latest/download/release.zip) 17 | 18 | ## Table of Contents 19 | 20 | 21 | 22 |
23 | Details 24 | 25 | - [スクリーンショット](#%E3%82%B9%E3%82%AF%E3%83%AA%E3%83%BC%E3%83%B3%E3%82%B7%E3%83%A7%E3%83%83%E3%83%88) 26 | - [動作](#%E5%8B%95%E4%BD%9C) 27 | - [ツールバー](#%E3%83%84%E3%83%BC%E3%83%AB%E3%83%90%E3%83%BC) 28 | - [サイドバー](#%E3%82%B5%E3%82%A4%E3%83%89%E3%83%90%E3%83%BC) 29 | - [設定追加](#%E8%A8%AD%E5%AE%9A%E8%BF%BD%E5%8A%A0) 30 | - [設定一覧](#%E8%A8%AD%E5%AE%9A%E4%B8%80%E8%A6%A7) 31 | - [ダッシュボード](#%E3%83%80%E3%83%83%E3%82%B7%E3%83%A5%E3%83%9C%E3%83%BC%E3%83%89) 32 | - [要件](#%E8%A6%81%E4%BB%B6) 33 | - [導入手順](#%E5%B0%8E%E5%85%A5%E6%89%8B%E9%A0%86) 34 | - [使用方法](#%E4%BD%BF%E7%94%A8%E6%96%B9%E6%B3%95) 35 | - [設定の追加](#%E8%A8%AD%E5%AE%9A%E3%81%AE%E8%BF%BD%E5%8A%A0) 36 | - [ボタンの利用](#%E3%83%9C%E3%82%BF%E3%83%B3%E3%81%AE%E5%88%A9%E7%94%A8) 37 | - [インラインテキスト設定の利用](#%E3%82%A4%E3%83%B3%E3%83%A9%E3%82%A4%E3%83%B3%E3%83%86%E3%82%AD%E3%82%B9%E3%83%88%E8%A8%AD%E5%AE%9A%E3%81%AE%E5%88%A9%E7%94%A8) 38 | - [設定](#%E8%A8%AD%E5%AE%9A) 39 | - [タグ名](#%E3%82%BF%E3%82%B0%E5%90%8D) 40 | - [クラス名](#%E3%82%AF%E3%83%A9%E3%82%B9%E5%90%8D) 41 | - [グループ名](#%E3%82%B0%E3%83%AB%E3%83%BC%E3%83%97%E5%90%8D) 42 | - [アイコン](#%E3%82%A2%E3%82%A4%E3%82%B3%E3%83%B3) 43 | - [スタイル](#%E3%82%B9%E3%82%BF%E3%82%A4%E3%83%AB) 44 | - [ツールバーボタンが有効かどうか](#%E3%83%84%E3%83%BC%E3%83%AB%E3%83%90%E3%83%BC%E3%83%9C%E3%82%BF%E3%83%B3%E3%81%8C%E6%9C%89%E5%8A%B9%E3%81%8B%E3%81%A9%E3%81%86%E3%81%8B) 45 | - [優先度](#%E5%84%AA%E5%85%88%E5%BA%A6) 46 | - [ダッシュボード](#%E3%83%80%E3%83%83%E3%82%B7%E3%83%A5%E3%83%9C%E3%83%BC%E3%83%89-1) 47 | - [有効かどうか](#%E6%9C%89%E5%8A%B9%E3%81%8B%E3%81%A9%E3%81%86%E3%81%8B) 48 | - [文字色ボタンが有効かどうか](#%E6%96%87%E5%AD%97%E8%89%B2%E3%83%9C%E3%82%BF%E3%83%B3%E3%81%8C%E6%9C%89%E5%8A%B9%E3%81%8B%E3%81%A9%E3%81%86%E3%81%8B) 49 | - [文字色ボタンのアイコン](#%E6%96%87%E5%AD%97%E8%89%B2%E3%83%9C%E3%82%BF%E3%83%B3%E3%81%AE%E3%82%A2%E3%82%A4%E3%82%B3%E3%83%B3) 50 | - [背景色ボタンが有効かどうか](#%E8%83%8C%E6%99%AF%E8%89%B2%E3%83%9C%E3%82%BF%E3%83%B3%E3%81%8C%E6%9C%89%E5%8A%B9%E3%81%8B%E3%81%A9%E3%81%86%E3%81%8B) 51 | - [背景色ボタンのアイコン](#%E8%83%8C%E6%99%AF%E8%89%B2%E3%83%9C%E3%82%BF%E3%83%B3%E3%81%AE%E3%82%A2%E3%82%A4%E3%82%B3%E3%83%B3) 52 | - [文字サイズボタンが有効かどうか](#%E6%96%87%E5%AD%97%E3%82%B5%E3%82%A4%E3%82%BA%E3%83%9C%E3%82%BF%E3%83%B3%E3%81%8C%E6%9C%89%E5%8A%B9%E3%81%8B%E3%81%A9%E3%81%86%E3%81%8B) 53 | - [文字サイズボタンのアイコン](#%E6%96%87%E5%AD%97%E3%82%B5%E3%82%A4%E3%82%BA%E3%83%9C%E3%82%BF%E3%83%B3%E3%81%AE%E3%82%A2%E3%82%A4%E3%82%B3%E3%83%B3) 54 | - [全てのフォーマットを外すボタンが有効かどうか](#%E5%85%A8%E3%81%A6%E3%81%AE%E3%83%95%E3%82%A9%E3%83%BC%E3%83%9E%E3%83%83%E3%83%88%E3%82%92%E5%A4%96%E3%81%99%E3%83%9C%E3%82%BF%E3%83%B3%E3%81%8C%E6%9C%89%E5%8A%B9%E3%81%8B%E3%81%A9%E3%81%86%E3%81%8B) 55 | - [Fontawesomeが有効かどうか](#fontawesome%E3%81%8C%E6%9C%89%E5%8A%B9%E3%81%8B%E3%81%A9%E3%81%86%E3%81%8B) 56 | - [デフォルトアイコン](#%E3%83%87%E3%83%95%E3%82%A9%E3%83%AB%E3%83%88%E3%82%A2%E3%82%A4%E3%82%B3%E3%83%B3) 57 | - [デフォルトグループ](#%E3%83%87%E3%83%95%E3%82%A9%E3%83%AB%E3%83%88%E3%82%B0%E3%83%AB%E3%83%BC%E3%83%97) 58 | - [テスト用文章](#%E3%83%86%E3%82%B9%E3%83%88%E7%94%A8%E6%96%87%E7%AB%A0) 59 | - [カラーパレットやフォントサイズ一覧の変更](#%E3%82%AB%E3%83%A9%E3%83%BC%E3%83%91%E3%83%AC%E3%83%83%E3%83%88%E3%82%84%E3%83%95%E3%82%A9%E3%83%B3%E3%83%88%E3%82%B5%E3%82%A4%E3%82%BA%E4%B8%80%E8%A6%A7%E3%81%AE%E5%A4%89%E6%9B%B4) 60 | - [プラグイン独自のフィルタ](#%E3%83%97%E3%83%A9%E3%82%B0%E3%82%A4%E3%83%B3%E7%8B%AC%E8%87%AA%E3%81%AE%E3%83%95%E3%82%A3%E3%83%AB%E3%82%BF) 61 | - [Dependency](#dependency) 62 | - [Author](#author) 63 | - [プラグイン作成用フレームワーク](#%E3%83%97%E3%83%A9%E3%82%B0%E3%82%A4%E3%83%B3%E4%BD%9C%E6%88%90%E7%94%A8%E3%83%95%E3%83%AC%E3%83%BC%E3%83%A0%E3%83%AF%E3%83%BC%E3%82%AF) 64 | 65 |
66 | 67 | 68 | ## スクリーンショット 69 | ### 動作 70 | 71 | ![動作](https://raw.githubusercontent.com/technote-space/add-richtext-toolbar-button/images/assets/201903070308.gif) 72 | 73 | ### ツールバー 74 | 75 | ![ツールバー](https://raw.githubusercontent.com/technote-space/add-richtext-toolbar-button/images/assets/201902150444.png) 76 | 77 | ### サイドバー 78 | 79 | ![サイドバー](https://raw.githubusercontent.com/technote-space/add-richtext-toolbar-button/images/assets/201902181831.png) 80 | 81 | ### 設定追加 82 | 83 | ![設定追加](https://raw.githubusercontent.com/technote-space/add-richtext-toolbar-button/images/assets/201902170345.png) 84 | 85 | ### 設定一覧 86 | 87 | ![設定一覧](https://raw.githubusercontent.com/technote-space/add-richtext-toolbar-button/images/assets/201902150436.png) 88 | 89 | ### ダッシュボード 90 | 91 | ![ダッシュボード](https://raw.githubusercontent.com/technote-space/add-richtext-toolbar-button/images/assets/201902181859.png) 92 | 93 | ## 要件 94 | - PHP 5.6 以上 95 | - WordPress 5.4 以上 96 | 97 | ## 導入手順 98 | 1. 最新版をGitHubからダウンロード 99 | [release.zip](https://github.com/technote-space/add-richtext-toolbar-button/releases/latest/download/release.zip) 100 | 2. 「プラグインのアップロード」からインストール 101 | ![install](https://raw.githubusercontent.com/technote-space/screenshots/master/misc/install-wp-plugin.png) 102 | 3. プラグインを有効化 103 | 104 | ## 使用方法 105 | ### 設定の追加 106 | 1. 管理画面左メニューから「Add RichText Toolbar Button」⇒「設定管理」に移動 107 | 2. 「新規追加」 108 | 3. 設定名やスタイル等の情報を入力 109 | 4. 「公開」ボタンを押下 110 | 111 | ### ボタンの利用 112 | 1. 記事の投稿画面に移動(Gutenbergエディタ) 113 | 2. 修飾したい文字列を選択 114 | 3. 適用するボタンを押下 115 | ![ボタン](https://raw.githubusercontent.com/technote-space/add-richtext-toolbar-button/images/assets/201902181846.png) 116 | 117 | ### インラインテキスト設定の利用 118 | 1. 記事の投稿画面に移動(Gutenbergエディタ) 119 | 2. 修飾したい文字列を選択 120 | 3. 右側のサイドバーから適用する色やサイズを選択 121 | ![インラインテキスト設定](https://raw.githubusercontent.com/technote-space/add-richtext-toolbar-button/images/assets/201902181842.png) 122 | * サイドバーが見つからない場合 123 | 右上の歯車マークを押してサイドバーを表示 124 | ![設定](https://raw.githubusercontent.com/technote-space/add-richtext-toolbar-button/images/assets/201902181841.png) 125 | 126 | ## 設定 127 | ### タグ名 128 | **span** や **cite** などのタグを指定します。 129 | 何も指定しない場合は **span** が使用されます。 130 | 131 | ### クラス名 132 | クラス名を指定します。 133 | 他のボタンで使用されているものを指定するとエラーになります。 134 | 何も指定しない場合は **投稿IDを使用した被らないもの** が使用されます。 135 | 136 | ### グループ名 137 | 同じグループ名のボタンが複数あった場合にドロップダウンでまとまります。 138 | 多くのボタンを追加する場合に横に広がりすぎるのを防ぐことができます。 139 | 何も指定しない場合はドロップダウンになりません。 140 | 141 | ### アイコン 142 | ボタンに表示するアイコンを指定します。 143 | **dashicon** や URL等の画像を指定することができます。 144 | 145 | ### スタイル 146 | 適用するデザインを指定します。 147 | セレクタを除いた部分を記述します。 148 | ``` 149 | プロパティ: 値 150 | ``` 151 | **before** や **after** のような疑似クラスは次のルールで記述します。 152 | ``` 153 | [疑似クラス] プロパティ: 値 154 | ``` 155 | 例: 156 | ``` 157 | display: block; 158 | padding: 10px; 159 | background: #f0f9ff; 160 | border: 1px solid #acf; 161 | [before] font-family: "Font Awesome 5 Free"; 162 | [before] content: "\f06a"; 163 | [before] font-size: 1.2em; 164 | [before] font-weight: 900; 165 | [before] padding-right: .2em; 166 | [before] margin-right: .2em; 167 | [before] color: #9cf; 168 | [before] border-right: 1px solid #acf; 169 | ``` 170 | #### プリセット 171 | いくつかのデザインパターンを用意しています。 172 | ボタンを押すことでスタイルのテキストエリアに挿入されます。 173 | 174 | ### ツールバーボタンが有効かどうか 175 | Gutenbergエディタのツールバーに表示するかどうかを指定します。 176 | ゴミ箱に移動したり削除したりするとデザイン自体が無効になってしまいますが、 177 | この設定によって『デザインは適用される』けれども『ツールバーには表示されない』が実現可能です。 178 | 新しくボタンを追加して過去に追加したものが不要になった場合に、デザインの適用を残しておきたい場合に有効です。 179 | 180 | ### 優先度 181 | 値が小さいほど優先順位が高くなります。 182 | * 一覧で上に表示される (**ツールバーボタンが有効かどうか** が無効の場合を除く) 183 | * CSSで後ろに出力される 184 | * ツールバーで前のほうに配置される 185 | 186 | ## ダッシュボード 187 | ### 有効かどうか 188 | これを外すと全ての機能が無効になります。 189 | 190 | ### 文字色ボタンが有効かどうか 191 | 文字色を変更できるボタンを追加するかどうかを指定します。 192 | 193 | ![文字色ボタン](https://raw.githubusercontent.com/technote-space/add-richtext-toolbar-button/images/assets/201902170357.png) 194 | 195 | [インラインテキスト設定の利用](#インラインテキスト設定の利用) からは常に使用できるため、ツールバーにもボタンが必要な場合に有効にします。 196 | 197 | ### 文字色ボタンのアイコン 198 | 文字色を変更できるボタンのアイコンを指定します。 199 | 200 | ### 背景色ボタンが有効かどうか 201 | 背景色を変更できるボタンを追加するかどうかを指定します。 202 | 203 | ![背景色ボタン](https://raw.githubusercontent.com/technote-space/add-richtext-toolbar-button/images/assets/201902170358.png) 204 | 205 | [インラインテキスト設定の利用](#インラインテキスト設定の利用) からは常に使用できるため、ツールバーにもボタンが必要な場合に有効にします。 206 | 207 | ### 背景色ボタンのアイコン 208 | 背景色を変更できるボタンのアイコンを指定します。 209 | 210 | ### 文字サイズボタンが有効かどうか 211 | 文字サイズを変更できるボタンを追加するかどうかを指定します。 212 | 213 | ![文字サイズボタン](https://raw.githubusercontent.com/technote-space/add-richtext-toolbar-button/images/assets/201902181852.png) 214 | 215 | [インラインテキスト設定の利用](#インラインテキスト設定の利用) からは常に使用できるため、ツールバーにもボタンが必要な場合に有効にします。 216 | 217 | ### 文字サイズボタンのアイコン 218 | 文字サイズを変更できるボタンのアイコンを指定します。 219 | 220 | ### 全てのフォーマットを外すボタンが有効かどうか 221 | サイドバーに全てのフォーマットを外すボタンを追加するかどうかを指定します。 222 | 223 | ### Fontawesomeが有効かどうか 224 | Fontawesomeを読み込むかどうかを指定します。 225 | v1.2 以降はこの設定をONにしない限り読みこみません。 226 | またOFFの場合はFontawesomeが必要な[プリセット](#プリセット)は表示されません。 227 | 228 | ### デフォルトアイコン 229 | 設定でアイコンを指定しなかった場合に使用されるアイコンです。 230 | 231 | ### デフォルトグループ 232 | 設定でグループ名を指定しなかった場合に使用されるグループ名です。 233 | 234 | ### テスト用文章 235 | 設定画面や一覧でテスト表示用に使用される文章を指定します。 236 | 237 | ## カラーパレットやフォントサイズ一覧の変更 238 | add_theme_support の設定で変更することが可能です。 239 | 参考ページ: 240 | [WordPress:Gutenbergで文字サイズと色設定(文字色・背景色)をカスタマイズする方法](https://www.nxworld.net/wordpress/wp-gutenberg-custom-font-sizes-and-color-palette.html) 241 | 242 | ## プラグイン独自のフィルタ 243 | いくつかの値は上書きすることが可能です。 244 | 245 | |フィルタ名|説明| 246 | |---|---| 247 | |artb/get_setting_presets|設定のプリセット| 248 | |artb/default_class_name|デフォルトのクラス名| 249 | |artb/get_groups|グループ一覧| 250 | |artb/get_preset|スタイルのプリセット| 251 | |artb/editor_wrap_selector|エディタ用にラップするセレクタ| 252 | |artb/cache_front_file_base_name|フロント用 出力ファイル名| 253 | |artb/cache_editor_file_base_name|エディタ(ツールボタン)用 出力ファイル名| 254 | |artb/pre_style_for_front|フロント用 自動適用スタイル| 255 | |artb/pre_style_for_editor|エディタ(ツールボタン)用 自動適用スタイル| 256 | 257 | 例: クラス名が設定されていない場合にデフォルトで設定されるクラス名の上書き 258 | ``` 259 | add_filter( 'artb/default_class_name', function ( $value, $post_id ) { 260 | return 'test-' . $post_id; 261 | }, 10, 2 ); 262 | ``` 263 | 264 | ## Dependency 265 | [Register Grouped Format Type](https://github.com/technote-space/register-grouped-format-type) 266 | 267 | ## Author 268 | [GitHub (Technote)](https://github.com/technote-space) 269 | [Blog](https://technote.space) 270 | 271 | ## プラグイン作成用フレームワーク 272 | [WP Content Framework](https://github.com/wp-content-framework/core) 273 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Add RichText Toolbar Button 2 | 3 | [![CI Status](https://github.com/technote-space/add-richtext-toolbar-button/workflows/CI/badge.svg)](https://github.com/technote-space/add-richtext-toolbar-button/actions) 4 | [![codecov](https://codecov.io/gh/technote-space/add-richtext-toolbar-button/branch/master/graph/badge.svg)](https://codecov.io/gh/technote-space/add-richtext-toolbar-button) 5 | [![CodeFactor](https://www.codefactor.io/repository/github/technote-space/add-richtext-toolbar-button/badge)](https://www.codefactor.io/repository/github/technote-space/add-richtext-toolbar-button) 6 | [![License: GPL v2+](https://img.shields.io/badge/License-GPL%20v2%2B-blue.svg)](http://www.gnu.org/licenses/gpl-2.0.html) 7 | [![PHP: >=5.6](https://img.shields.io/badge/PHP-%3E%3D5.6-orange.svg)](http://php.net/) 8 | [![WordPress: >=5.4](https://img.shields.io/badge/WordPress-%3E%3D5.4-brightgreen.svg)](https://wordpress.org/) 9 | 10 | ![Banner](https://raw.githubusercontent.com/technote-space/add-richtext-toolbar-button/images/assets/banner-772x250.png) 11 | 12 | *Read this in other languages: [English](README.md), [日本語](README.ja.md).* 13 | 14 | This plugin makes it easy to add RichText toolbar button. 15 | 16 | [Latest version](https://github.com/technote-space/add-richtext-toolbar-button/releases/latest/download/release.zip) 17 | 18 | ## Table of Contents 19 | 20 | 21 | 22 |
23 | Details 24 | 25 | - [Screenshots](#screenshots) 26 | - [Behavior](#behavior) 27 | - [Toolbar](#toolbar) 28 | - [Sidebar](#sidebar) 29 | - [Add setting](#add-setting) 30 | - [Setting list](#setting-list) 31 | - [Dashboard](#dashboard) 32 | - [Requirements](#requirements) 33 | - [Installation](#installation) 34 | - [Usage](#usage) 35 | - [Add setting](#add-setting-1) 36 | - [Use button](#use-button) 37 | - [Use `Inline Text Settings`](#use-inline-text-settings) 38 | - [Setting](#setting) 39 | - [Tag name](#tag-name) 40 | - [Class name](#class-name) 41 | - [Group name](#group-name) 42 | - [Icon](#icon) 43 | - [Style](#style) 44 | - [Validity of toolbar button](#validity-of-toolbar-button) 45 | - [Priority](#priority) 46 | - [Dashboard](#dashboard-1) 47 | - [Validity](#validity) 48 | - [Validity of font color button](#validity-of-font-color-button) 49 | - [Font color button icon](#font-color-button-icon) 50 | - [Validity of background color button](#validity-of-background-color-button) 51 | - [Background color button icon](#background-color-button-icon) 52 | - [Validity of font size button](#validity-of-font-size-button) 53 | - [Font size button icon](#font-size-button-icon) 54 | - [Validity of remove formatting button](#validity-of-remove-formatting-button) 55 | - [Validity of fontawesome](#validity-of-fontawesome) 56 | - [Default icon](#default-icon) 57 | - [Default group](#default-group) 58 | - [Test phrase](#test-phrase) 59 | - [Dependency](#dependency) 60 | - [Author](#author) 61 | - [Plugin framework](#plugin-framework) 62 | 63 |
64 | 65 | 66 | ## Screenshots 67 | ### Behavior 68 | 69 | ![Behavior](https://raw.githubusercontent.com/technote-space/add-richtext-toolbar-button/images/assets/201903070308.gif) 70 | 71 | ### Toolbar 72 | 73 | ![Toolbar](https://raw.githubusercontent.com/technote-space/add-richtext-toolbar-button/images/assets/201902150444.png) 74 | 75 | ### Sidebar 76 | 77 | ![Sidebar](https://raw.githubusercontent.com/technote-space/add-richtext-toolbar-button/images/assets/201902181831.png) 78 | 79 | ### Add setting 80 | 81 | ![Add setting](https://raw.githubusercontent.com/technote-space/add-richtext-toolbar-button/images/assets/201902170345.png) 82 | 83 | ### Setting list 84 | 85 | ![Setting list](https://raw.githubusercontent.com/technote-space/add-richtext-toolbar-button/images/assets/201902150436.png) 86 | 87 | ### Dashboard 88 | 89 | ![Dashboard](https://raw.githubusercontent.com/technote-space/add-richtext-toolbar-button/images/assets/201902181859.png) 90 | 91 | ## Requirements 92 | - \>= PHP 5.6 93 | - \>= WordPress 5.4 94 | 95 | ## Installation 96 | 1. Download latest version 97 | [release.zip](https://github.com/technote-space/add-richtext-toolbar-button/releases/latest/download/release.zip) 98 | 1. Install plugin 99 | ![install](https://raw.githubusercontent.com/technote-space/screenshots/master/misc/install-wp-plugin.png) 100 | 1. Activate plugin 101 | 102 | ## Usage 103 | ### Add setting 104 | 1. Go to "All Settings" from left side menu "Add RichText Toolbar Button" of admin page. 105 | 1. "Add New" 106 | 1. Input settings like name or styles. 107 | 1. Press "Publish" button. 108 | 109 | ### Use button 110 | 1. Go to editor page. 111 | 1. Select sentence which you want to add style. 112 | 1. Apply button. 113 | ![Button](https://raw.githubusercontent.com/technote-space/add-richtext-toolbar-button/images/assets/201902181846.png) 114 | 115 | ### Use `Inline Text Settings` 116 | 1. Go to editor page. 117 | 1. Select sentence which you want to add style. 118 | 1. Apply color and font size from sidebar on the right. 119 | ![Inline Text Settings](https://raw.githubusercontent.com/technote-space/add-richtext-toolbar-button/images/assets/201902181842.png) 120 | 121 | ## Setting 122 | ### Tag name 123 | Specify the tag name. 124 | You can use HTML tags like **span** or **cite**. 125 | If you do not input anything, **span** is used. 126 | 127 | ### Class name 128 | Specify the class name. 129 | An error will occur if you specify something that is used by another. 130 | If you do not input anything, **Unique name using post ID** is used. 131 | 132 | ### Group name 133 | Specify the group name. 134 | If there are multiple buttons with the same group name, they will be gathered by DropDown. 135 | 136 | ### Icon 137 | Specify the icon. 138 | You can use **dashicon** or URL. 139 | 140 | ### Style 141 | Specify the design to be applied in the following format. 142 | ``` 143 | property: value 144 | ``` 145 | Pseudo classes like **before** and **after** are described by the following rules. 146 | ``` 147 | [Pseudo-classes] property: value 148 | ``` 149 | ex. 150 | ``` 151 | display: block; 152 | padding: 10px; 153 | background: #f0f9ff; 154 | border: 1px solid #acf; 155 | [before] font-family: "Font Awesome 5 Free"; 156 | [before] content: "\f06a"; 157 | [before] font-size: 1.2em; 158 | [before] font-weight: 900; 159 | [before] padding-right: .2em; 160 | [before] margin-right: .2em; 161 | [before] color: #9cf; 162 | [before] border-right: 1px solid #acf; 163 | ``` 164 | #### Preset 165 | Several design patterns are available. 166 | 167 | ### Validity of toolbar button 168 | Specify whether to display on the toolbar of the Gutenberg editor. 169 | If you move setting to the trash or delete setting, the design itself will be invalid. 170 | This setting is useful when you want to keep the design applied. 171 | 172 | ### Priority 173 | The lower the value, the higher the priority. 174 | 175 | ## Dashboard 176 | ### Validity 177 | When this setting is off, all functions are disabled. 178 | 179 | ### Validity of font color button 180 | Specify whether to add a button that can change the text color. 181 | 182 | ![font color button](https://raw.githubusercontent.com/technote-space/add-richtext-toolbar-button/images/assets/201902170357.png) 183 | 184 | ### Font color button icon 185 | Specify the icon of `font color button` 186 | 187 | ### Validity of background color button 188 | Specify whether to add a button that can change the background color. 189 | 190 | ![background color button](https://raw.githubusercontent.com/technote-space/add-richtext-toolbar-button/images/assets/201902170358.png) 191 | 192 | ### Background color button icon 193 | Specify the icon of `background color button` 194 | 195 | ### Validity of font size button 196 | Specify whether to add a button that can change the font size. 197 | 198 | ![font size button](https://raw.githubusercontent.com/technote-space/add-richtext-toolbar-button/images/assets/201902181852.png) 199 | 200 | ### Font size button icon 201 | Specify the icon of `font size button` 202 | 203 | ### Validity of remove formatting button 204 | Specify whether to add a button to remove all formatting in the sidebar. 205 | 206 | ### Validity of fontawesome 207 | Specify whether to load Fontawesome. 208 | 209 | ### Default icon 210 | Specify the default icon. 211 | 212 | ### Default group 213 | Specify the default group. 214 | 215 | ### Test phrase 216 | Specify the test phrase. 217 | 218 | ## Dependency 219 | [Register Grouped Format Type](https://github.com/technote-space/register-grouped-format-type) 220 | 221 | ## Author 222 | [GitHub (Technote)](https://github.com/technote-space) 223 | [Blog](https://technote.space) 224 | 225 | ## Plugin framework 226 | [WP Content Framework](https://github.com/wp-content-framework/core) 227 | -------------------------------------------------------------------------------- /assets/.htaccess: -------------------------------------------------------------------------------- 1 | Order Deny,Allow 2 | Deny from all 3 | 4 | #allow access to assets 5 | 6 | Allow from all 7 | 8 | 9 | #allow access to images 10 | 11 | Allow from all 12 | 13 | -------------------------------------------------------------------------------- /assets/css/gutenberg.css: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Technote 3 | * @copyright Technote All Rights Reserved 4 | * @license http://www.opensource.org/licenses/gpl-2.0.php GNU General Public License, version 2 5 | * @link https://technote.space/ 6 | */ 7 | 8 | .arbt-menu .components-dropdown-menu__menu-item { 9 | height: auto; 10 | } 11 | 12 | .arbt-menu .components-dropdown-menu__menu-item.is-active { 13 | color: #1e1e1e; 14 | background: #ddd; 15 | } 16 | -------------------------------------------------------------------------------- /assets/img/icon-128x128.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/technote-space/add-richtext-toolbar-button/072e4dcb2b20d4f86b5c7edb5153e9e2c8251df4/assets/img/icon-128x128.png -------------------------------------------------------------------------------- /assets/img/icon-24x24.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/technote-space/add-richtext-toolbar-button/072e4dcb2b20d4f86b5c7edb5153e9e2c8251df4/assets/img/icon-24x24.png -------------------------------------------------------------------------------- /assets/js/.htaccess: -------------------------------------------------------------------------------- 1 | Order Deny,Allow 2 | Deny from all 3 | 4 | #allow access to assets 5 | 6 | Allow from all 7 | 8 | -------------------------------------------------------------------------------- /assets/js/__tests__/utils.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable no-magic-numbers */ 2 | import { getDefaultButtonGroupSetting, getColorButtonSetting, getFontSizeButtonSetting, getSettings } from '../src/utils'; 3 | 4 | describe('getDefaultButtonGroupSetting', () => { 5 | it('should return default button group setting', () => { 6 | artbParams.isValidRemoveFormatting = true; 7 | artbParams.isValidContrastChecker = true; 8 | const setting = getDefaultButtonGroupSetting(artbParams); 9 | expect(typeof setting).toBe('object'); 10 | expect(setting).toHaveLength(2); 11 | expect(setting[ 0 ]).toBe('arbt--inspector'); 12 | expect(typeof setting[ 1 ]).toBe('object'); 13 | expect(setting[ 1 ]).toHaveProperty('toolbarGroup'); 14 | expect(setting[ 1 ]).toHaveProperty('inspectorSettings'); 15 | expect(setting[ 1 ]).toHaveProperty('useContrastChecker'); 16 | expect(setting[ 1 ]).toHaveProperty('additionalInspectors'); 17 | expect(setting[ 1 ].useContrastChecker).toBe(artbParams.isValidContrastChecker); 18 | expect(setting[ 1 ].additionalInspectors).toHaveLength(1); 19 | }); 20 | 21 | it('should return default button group setting', () => { 22 | artbParams.isValidRemoveFormatting = false; 23 | artbParams.isValidContrastChecker = false; 24 | const setting = getDefaultButtonGroupSetting(artbParams); 25 | expect(typeof setting).toBe('object'); 26 | expect(setting).toHaveLength(2); 27 | expect(setting[ 0 ]).toBe('arbt--inspector'); 28 | expect(typeof setting[ 1 ]).toBe('object'); 29 | expect(setting[ 1 ]).toHaveProperty('toolbarGroup'); 30 | expect(setting[ 1 ]).toHaveProperty('inspectorSettings'); 31 | expect(setting[ 1 ]).toHaveProperty('useContrastChecker'); 32 | expect(setting[ 1 ]).toHaveProperty('additionalInspectors'); 33 | expect(setting[ 1 ].useContrastChecker).toBe(artbParams.isValidContrastChecker); 34 | expect(setting[ 1 ].additionalInspectors).toHaveLength(0); 35 | }); 36 | }); 37 | 38 | describe('getColorButtonSetting', () => { 39 | it('should return color button setting', () => { 40 | const setting = getColorButtonSetting(artbParams, 'font-color'); 41 | expect(typeof setting).toBe('object'); 42 | expect(setting).toHaveLength(5); 43 | expect(setting [ 0 ]).toEndWith(artbParams.defaultButtons[ 'font-color' ].name); 44 | expect(setting [ 1 ]).toBe(artbParams.defaultButtons[ 'font-color' ].title); 45 | expect(typeof setting [ 2 ]).toBe('object'); 46 | expect(setting [ 3 ]).toBe(artbParams.defaultButtons[ 'font-color' ].style); 47 | expect(typeof setting [ 4 ]).toBe('object'); 48 | expect(setting[ 4 ]).toHaveProperty('group'); 49 | expect(setting[ 4 ]).toHaveProperty('className'); 50 | expect(setting[ 4 ]).toHaveProperty('createDisabled'); 51 | expect(setting[ 4 ].className).toBe(artbParams.defaultButtons[ 'font-color' ].className); 52 | expect(setting[ 4 ].createDisabled).toBe(!artbParams.defaultButtons[ 'font-color' ].isValid); 53 | }); 54 | }); 55 | 56 | describe('getFontSizeButtonSetting', () => { 57 | it('should return font size button setting', () => { 58 | const setting = getFontSizeButtonSetting(artbParams, 'font-size'); 59 | expect(typeof setting).toBe('object'); 60 | expect(setting).toHaveLength(4); 61 | expect(setting[ 0 ]).toEndWith(artbParams.defaultButtons[ 'font-size' ].name); 62 | expect(setting[ 1 ]).toBe(artbParams.defaultButtons[ 'font-size' ].title); 63 | expect(typeof setting[ 2 ]).toBe('object'); 64 | expect(typeof setting[ 3 ]).toBe('object'); 65 | expect(setting[ 3 ]).toHaveProperty('group'); 66 | expect(setting[ 3 ]).toHaveProperty('className'); 67 | expect(setting[ 3 ]).toHaveProperty('createDisabled'); 68 | expect(setting[ 3 ].className).toBe(artbParams.defaultButtons[ 'font-size' ].className); 69 | expect(setting[ 3 ].createDisabled).toBe(!artbParams.defaultButtons[ 'font-size' ].isValid); 70 | }); 71 | }); 72 | 73 | describe('getSettings', () => { 74 | it('should return settings', () => { 75 | const setting = getSettings(artbParams); 76 | expect(typeof setting).toBe('object'); 77 | expect(setting).toHaveProperty('groups'); 78 | expect(setting).toHaveProperty('settings'); 79 | expect(setting.groups).toHaveProperty('arbt--item--group1'); 80 | expect(setting.groups).toHaveProperty('arbt--item--group2'); 81 | expect(setting.groups).toHaveProperty('arbt--item--group3'); 82 | expect(setting.groups[ 'arbt--item--group1' ]).toHaveProperty('toolbarGroup'); 83 | expect(setting.groups[ 'arbt--item--group1' ]).toHaveProperty('icon'); 84 | expect(setting.groups[ 'arbt--item--group1' ]).toHaveProperty('label'); 85 | expect(setting.groups[ 'arbt--item--group1' ].label).toBe('group1'); 86 | expect(setting.groups[ 'arbt--item--group2' ].label).toBe('group2'); 87 | expect(setting.groups[ 'arbt--item--group3' ].label).toBe('group3'); 88 | expect(setting.settings).toHaveLength(4); 89 | expect(setting.settings[ 0 ]).toHaveLength(4); 90 | expect(setting.settings[ 0 ][ 0 ]).toEndWith(artbParams.settings[ 0 ].groupName); 91 | expect(setting.settings[ 0 ][ 1 ]).toBe(artbParams.settings[ 0 ].name); 92 | expect(typeof setting.settings[ 0 ][ 2 ]).toBe('object'); 93 | expect(typeof setting.settings[ 0 ][ 3 ]).toBe('object'); 94 | expect(setting.settings[ 0 ][ 3 ]).toHaveProperty('title'); 95 | expect(setting.settings[ 0 ][ 3 ]).toHaveProperty('className'); 96 | expect(setting.settings[ 0 ][ 3 ]).toHaveProperty('tagName'); 97 | expect(setting.settings[ 0 ][ 3 ]).toHaveProperty('createDisabled'); 98 | expect(setting.settings[ 0 ][ 3 ].title).toBe(artbParams.settings[ 0 ].title); 99 | expect(setting.settings[ 0 ][ 3 ].className).toBe(artbParams.settings[ 0 ].className); 100 | expect(setting.settings[ 0 ][ 3 ].tagName).toBe(artbParams.settings[ 0 ].tagName); 101 | expect(setting.settings[ 0 ][ 3 ].createDisabled).toBe(!artbParams.settings[ 0 ].isValid); 102 | }); 103 | }); 104 | -------------------------------------------------------------------------------- /autoload.php: -------------------------------------------------------------------------------- 1 | '5.4', 17 | 18 | // main menu title 19 | 'main_menu_title' => 'Add RichText Toolbar Button', 20 | 21 | // update 22 | 'update_info_file_url' => 'https://raw.githubusercontent.com/technote-space/add-richtext-toolbar-button/master/update.json', 23 | 24 | // menu image url 25 | 'menu_image' => 'icon-24x24.png', 26 | 27 | // suppress setting help contents 28 | 'suppress_setting_help_contents' => true, 29 | 30 | // setting page title 31 | 'setting_page_title' => 'Detail Settings', 32 | 33 | // setting page priority 34 | 'setting_page_priority' => 100, 35 | 36 | // setting page slug 37 | 'setting_page_slug' => 'dashboard', 38 | 39 | // detail url 40 | 'detail_url' => 'https://technote.space/add-richtext-toolbar-button', 41 | 42 | // twitter 43 | 'twitter' => 'technote15', 44 | 45 | // github repo 46 | 'github_repo' => 'technote-space/add-richtext-toolbar-button', 47 | ]; 48 | -------------------------------------------------------------------------------- /configs/db.php: -------------------------------------------------------------------------------- 1 | [ 16 | 'columns' => [ 17 | 'post_id' => [ 18 | 'type' => 'BIGINT(20)', 19 | 'unsigned' => true, 20 | 'null' => false, 21 | 'comment' => 'post id', 22 | ], 23 | 'tag_name' => [ 24 | 'type' => 'VARCHAR(32)', 25 | 'default' => 'span', 26 | 'comment' => 'tag name', 27 | ], 28 | 'class_name' => [ 29 | 'type' => 'VARCHAR(64)', 30 | 'comment' => 'class name', 31 | ], 32 | 'group_name' => [ 33 | 'type' => 'VARCHAR(64)', 34 | 'comment' => 'group name', 35 | ], 36 | 'icon' => [ 37 | 'type' => 'TEXT', 38 | 'comment' => 'icon', 39 | ], 40 | 'style' => [ 41 | 'type' => 'TEXT', 42 | 'comment' => 'style', 43 | ], 44 | 'priority' => [ 45 | 'type' => 'INT(11)', 46 | 'unsigned' => true, 47 | 'null' => false, 48 | 'default' => 10, 49 | 'comment' => 'priority', 50 | ], 51 | 'is_valid_toolbar_button' => [ 52 | 'type' => 'BIT(1)', 53 | 'unsigned' => true, 54 | 'null' => false, 55 | 'default' => 1, 56 | 'comment' => 'Validity of toolbar button', 57 | ], 58 | ], 59 | 'index' => [ 60 | 'key' => [ 61 | 'priority' => [ 'priority' ], 62 | ], 63 | 'unique' => [ 64 | 'uk_post_id' => [ 'post_id' ], 65 | ], 66 | ], 67 | 'comment' => 'settings', 68 | ], 69 | 70 | ]; 71 | -------------------------------------------------------------------------------- /configs/design_preset.php: -------------------------------------------------------------------------------- 1 | 'font-weight: bold;', 16 | 'font color' => 'color: #f00;', 17 | 'font size' => 'font-size: 1.5em;', 18 | 'line height' => 'line-height: 1.5;', 19 | 'background color' => 'background-color: #9ff;', 20 | 'border' => 'border: solid 2px #f9f;', 21 | 'border radius' => 'border-radius: 5px;', 22 | 'padding' => 'padding: .5em;', 23 | 'shadow' => 'box-shadow: 3px 3px 3px #ccc;', 24 | 'highlighter' => 'background-image: linear-gradient(to bottom, rgba(255, 255, 255, 0) 60%, #6f6 75%);', 25 | 'stripe' => [ 26 | 'background-image: repeating-linear-gradient(-45deg, rgb(64, 255, 0), rgb(64, 255, 0) 2px, transparent 2px, transparent 4px);', 27 | 'background-size: 100% 0.6em', 28 | 'padding-bottom: 0.6em', 29 | 'background-position: 0 center', 30 | 'background-repeat: no-repeat', 31 | ], 32 | 'block' => 'display: block;', 33 | 'inline block' => 'display: inline-block;', 34 | 'icon' => function ( $font_family ) { 35 | return [ 36 | 'display: block;', 37 | 'padding: 1em 1em 1em 4.6em;', 38 | 'position: relative;', 39 | 'line-height: 1.4;', 40 | 'background: #f0f9ff;', 41 | 'border: 1px solid #acf;', 42 | '[after] content: " ";', 43 | '[after] display: block;', 44 | '[after] width: 0;', 45 | '[after] height: 50%;', 46 | '[after] position: absolute;', 47 | '[after] top: 25%;', 48 | '[after] left: 3.4em;', 49 | '[after] opacity: 0.6;', 50 | '[after] border-right: 2px dashed;', 51 | '[after] border-right-color: #76b3f7;', 52 | "[before] font-family: {$font_family};", 53 | '[before] content: "\f06a";', 54 | '[before] font-weight: 900;', 55 | '[before] color: #9cf;', 56 | '[before] display: inline-block;', 57 | '[before] position: absolute;', 58 | '[before] top: 50%;', 59 | '[before] left: 1.2em;', 60 | '[before] transform: translateY(-50%) scale(1.5);', 61 | ]; 62 | }, 63 | 'tab' => function ( $font_family ) { 64 | return [ 65 | 'display: block;', 66 | 'position: relative;', 67 | 'border: 2px solid #f94;', 68 | 'padding: 1.2em 1em;', 69 | 'margin-top: 1.4em;', 70 | '[before] position: absolute;', 71 | "[before] font-family: {$font_family};", 72 | '[before] content: "\f0f3 tab";', 73 | '[before] left: -2px;', 74 | '[before] top: -1.8em', 75 | '[before] font-size: .8em;', 76 | '[before] font-weight: 900;', 77 | '[before] padding: 0 1em 0 .8em;', 78 | '[before] background-color: #f94;', 79 | '[before] color: white;', 80 | '[before] border-radius: 6px 6px 0 0;', 81 | '[before] line-height: 1.8em;', 82 | ]; 83 | }, 84 | 'tag' => [ 85 | 'display: block;', 86 | 'border-left: 6px solid #06c;', 87 | 'padding: 1.2em 1em;', 88 | 'background-color: #def;', 89 | ], 90 | 'label' => function ( $font_family ) { 91 | return [ 92 | 'display: block;', 93 | 'position: relative;', 94 | 'padding: 1em .5em .7em;', 95 | 'background-color: #d9d9d9;', 96 | '[before] position: absolute;', 97 | "[before] font-family: {$font_family};", 98 | '[before] content: "\f005 label";', 99 | '[before] right: 0;', 100 | '[before] top: 0;', 101 | '[before] font-size: .6em;', 102 | '[before] font-weight: 900;', 103 | '[before] padding: 0 .8em;', 104 | '[before] background-color: #666;', 105 | '[before] color: white;', 106 | '[before] line-height: 1.6em;', 107 | '[before] white-space: pre;', 108 | ]; 109 | }, 110 | 'warning' => function ( $font_family ) { 111 | return [ 112 | 'display: block;', 113 | 'padding: 1em 1em 1em 3em;', 114 | 'position: relative;', 115 | 'line-height: 1.4;', 116 | 'background-color: #fbeaea;', 117 | 'border-width: 0 0 0 5px;', 118 | 'border-style: solid;', 119 | 'border-color: #dc3232;', 120 | "[before] font-family: {$font_family};", 121 | '[before] content: "\f057";', 122 | '[before] font-weight: 900;', 123 | '[before] color: #dc3232;', 124 | '[before] display: inline-block;', 125 | '[before] position: absolute;', 126 | '[before] top: 50%;', 127 | '[before] left: 1.2em;', 128 | '[before] transform: translateY(-50%) scale(1.5);', 129 | ]; 130 | }, 131 | 132 | ]; 133 | -------------------------------------------------------------------------------- /configs/filter.php: -------------------------------------------------------------------------------- 1 | [ 16 | '${prefix}post_load_admin_page' => [ 17 | 'remove_setting', 18 | ], 19 | 'wp_head' => [ 20 | 'setup_assets', 21 | ], 22 | '${prefix}changed_option' => [ 23 | 'changed_option', 24 | ], 25 | '${prefix}app_activated' => [ 26 | 'clear_cache_file', 27 | ], 28 | 'upgrader_process_complete' => [ 29 | 'clear_cache_file', 30 | ], 31 | ], 32 | 33 | '\Richtext_Toolbar_Button\Classes\Models\Editor' => [ 34 | 'enqueue_block_editor_assets' => [ 35 | 'enqueue_block_editor_assets', 36 | ], 37 | ], 38 | 39 | '\Richtext_Toolbar_Button\Classes\Models\Custom_Post\Setting' => [ 40 | '${prefix}app_activated' => [ 41 | 'insert_presets', 42 | ], 43 | 'load-edit.php' => [ 44 | 'setup_assets', 45 | ], 46 | ], 47 | ]; 48 | -------------------------------------------------------------------------------- /configs/io.php: -------------------------------------------------------------------------------- 1 | [ 16 | 'tag_name', 17 | 'class_name', 18 | 'group_name', 19 | 'icon' => [ 20 | 'export' => function ( $v ) { 21 | if ( preg_match( '#^data:image#', $v ) || preg_match( '#^dashicons-#', $v ) ) { 22 | return $v; 23 | } 24 | 25 | return null; 26 | }, 27 | ], 28 | 'style', 29 | 'priority', 30 | 'is_valid_toolbar_button', 31 | ], 32 | 33 | ]; 34 | -------------------------------------------------------------------------------- /configs/preset.php: -------------------------------------------------------------------------------- 1 | 'Source code', 17 | 'tag_name' => 'code', 18 | 'icon' => 'dashicons-editor-code', 19 | 'is_valid_toolbar_button' => 0, 20 | 'priority' => 100, 21 | ], 22 | 23 | [ 24 | 'name' => 'Superscript', 25 | 'tag_name' => 'sup', 26 | 'icon' => 'data:image/svg+xml;base64,PHN2ZyB2ZXJzaW9uPSIxLjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgdmlld0JveD0iLTg1IC05NzUgMTAyNCAxMDI0Ij4KPHBhdGggYXJpYS1oaWRkZW49InRydWUiIHJvbGQ9ImltZyIgZm9jdXNhYmxlPSJmYWxzZSIgdHJhbnNmb3JtPSJzY2FsZSgxLCAtMSkiIHRyYW5zbGF0ZT0iKDAsIC05NjApIiBkPSJNNzY4IDc1NHYtNTBoMTI4di02NGgtMTkydjE0NmwxMjggNjB2NTBoLTEyOHY2NGgxOTJ2LTE0NnpNNjc2IDcwNGgtMTM2bC0xODgtMTg4LTE4OCAxODhoLTEzNmwyNTYtMjU2LTI1Ni0yNTZoMTM2bDE4OCAxODggMTg4LTE4OGgxMzZsLTI1NiAyNTZ6Ii8+Cjwvc3ZnPg==', 27 | 'is_valid_toolbar_button' => 0, 28 | 'priority' => 100, 29 | ], 30 | 31 | [ 32 | 'name' => 'Subscript', 33 | 'tag_name' => 'sub', 34 | 'icon' => 'data:image/svg+xml;base64,PHN2ZyB2ZXJzaW9uPSIxLjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgdmlld0JveD0iLTg1IC05NzUgMTAyNCAxMDI0Ij4KPHBhdGggYXJpYS1oaWRkZW49InRydWUiIHJvbGQ9ImltZyIgZm9jdXNhYmxlPSJmYWxzZSIgdHJhbnNmb3JtPSJzY2FsZSgxLCAtMSkiIHRyYW5zbGF0ZT0iKDAsIC05NjApIiBkPSJNNzY4IDUwdi01MGgxMjh2LTY0aC0xOTJ2MTQ2bDEyOCA2MHY1MGgtMTI4djY0aDE5MnYtMTQ2ek02NzYgNzA0aC0xMzZsLTE4OC0xODgtMTg4IDE4OGgtMTM2bDI1Ni0yNTYtMjU2LTI1NmgxMzZsMTg4IDE4OCAxODgtMTg4aDEzNmwtMjU2IDI1NnoiLz4KPC9zdmc+', 35 | 'is_valid_toolbar_button' => 0, 36 | 'priority' => 100, 37 | ], 38 | 39 | [ 40 | 'name' => 'Highlighter(Red)', 41 | 'group_name' => 'Pen', 42 | 'style' => 'background-image: linear-gradient(to bottom, rgba(255, 255, 255, 0) 60%, #f69 75%); font-weight: bold;', 43 | 'is_valid_toolbar_button' => 1, 44 | 'priority' => 50, 45 | ], 46 | 47 | [ 48 | 'name' => 'Highlighter(Green)', 49 | 'group_name' => 'Pen', 50 | 'style' => 'background-image: linear-gradient(to bottom, rgba(255, 255, 255, 0) 60%, #6f6 75%); font-weight: bold;', 51 | 'is_valid_toolbar_button' => 1, 52 | 'priority' => 50, 53 | ], 54 | 55 | [ 56 | 'name' => 'Highlighter(Blue)', 57 | 'group_name' => 'Pen', 58 | 'style' => 'background-image: linear-gradient(to bottom, rgba(255, 255, 255, 0) 60%, #6cf 75%); font-weight: bold;', 59 | 'is_valid_toolbar_button' => 1, 60 | 'priority' => 50, 61 | ], 62 | 63 | [ 64 | 'name' => 'Highlighter(Yellow)', 65 | 'group_name' => 'Pen', 66 | 'style' => 'background-image: linear-gradient(to bottom, rgba(255, 255, 255, 0) 60%, #ff6 75%); font-weight: bold;', 67 | 'is_valid_toolbar_button' => 1, 68 | 'priority' => 50, 69 | ], 70 | 71 | ]; 72 | -------------------------------------------------------------------------------- /configs/setting.php: -------------------------------------------------------------------------------- 1 | [ 16 | 'Main Setting' => [ 17 | 10 => [ 18 | 'is_valid' => [ 19 | 'label' => 'Validity', 20 | 'type' => 'bool', 21 | 'default' => true, 22 | ], 23 | 'is_valid_font_color' => [ 24 | 'label' => 'Validity of font color button', 25 | 'type' => 'bool', 26 | 'default' => true, 27 | ], 28 | 'font_color_icon' => [ 29 | 'label' => 'Font color button icon', 30 | 'default' => 'dashicons-editor-textcolor', 31 | ], 32 | 'is_valid_background_color' => [ 33 | 'label' => 'Validity of background color button', 34 | 'type' => 'bool', 35 | 'default' => true, 36 | ], 37 | 'background_color_icon' => [ 38 | 'label' => 'Background color button icon', 39 | 'default' => 'dashicons-editor-textcolor', 40 | ], 41 | 'is_valid_font_size' => [ 42 | 'label' => 'Validity of font size button', 43 | 'type' => 'bool', 44 | 'default' => true, 45 | ], 46 | 'font_size_icon' => [ 47 | 'label' => 'Font size button icon', 48 | 'default' => 'dashicons-editor-textcolor', 49 | ], 50 | 'test_phrase' => [ 51 | 'label' => 'Test phrase', 52 | 'default' => 'Hello world!', 53 | 'translate' => true, 54 | ], 55 | 'default_icon' => [ 56 | 'label' => 'Default icon', 57 | 'default' => 'dashicons-edit', 58 | ], 59 | 'default_group' => [ 60 | 'label' => 'Default group', 61 | ], 62 | 'is_valid_contrast_checker' => [ 63 | 'label' => 'Validity of ContrastChecker', 64 | 'type' => 'bool', 65 | 'default' => false, 66 | ], 67 | 'is_valid_remove_formatting' => [ 68 | 'label' => 'Validity of remove formatting button', 69 | 'type' => 'bool', 70 | 'default' => true, 71 | ], 72 | 'is_valid_fontawesome' => [ 73 | 'label' => 'Validity of fontawesome', 74 | 'type' => 'bool', 75 | 'default' => false, 76 | ], 77 | ], 78 | ], 79 | ], 80 | 81 | ]; 82 | -------------------------------------------------------------------------------- /index.php: -------------------------------------------------------------------------------- 1 | 優先度の数値を下げたりクラスの順番を変えると使用できる場合があります。" 291 | 292 | msgid "Remove All formatting" 293 | msgstr "全てのフォーマットを外す" 294 | -------------------------------------------------------------------------------- /readme.txt: -------------------------------------------------------------------------------- 1 | === Add RichText Toolbar Button === 2 | Contributors: technote0space 3 | Tags: Gutenberg, rich text, Formatting, ツールバー, リッチテキスト 4 | Requires at least: 5.4 5 | Requires PHP: 5.6 6 | Tested up to: 5.4 7 | Stable tag: 2.1.2 8 | Donate link: https://paypal.me/technote0space 9 | License: GPLv2 or later 10 | License URI: http://www.gnu.org/licenses/gpl-2.0.html 11 | 12 | This plugin makes it easy to add RichText toolbar button. 13 | 14 | == Description == 15 | 16 | This plugin makes it easy to add RichText toolbar button. 17 | [日本語の説明](https://technote.space/add-richtext-toolbar-button "Documentation in Japanese") 18 | [GitHub (More details)](https://github.com/technote-space/add-richtext-toolbar-button) 19 | [Issues (Reporting a new bug or feature request)](https://github.com/technote-space/add-richtext-toolbar-button/issues) 20 | [Demonstration](https://technote-space.github.io/add-richtext-toolbar-button) 21 | 22 | This plugin needs PHP5.6 or higher. 23 | 24 | * You can add formatting buttons which have any tag name and class name to the rich text toolbar as many as you like. 25 | * You can make some groups to add dropdown list instead of button. 26 | * You can use not only inline text and background color panels but also inline font size panel. 27 | 28 | == Installation == 29 | 30 | 1. Upload the `add-richtext-toolbar-button` folder to the `/wp-content/plugins/` directory. 31 | 2. Activate the plugin through the 'Plugins' menu in WordPress. 32 | 33 | == Frequently asked questions == 34 | 35 | == Screenshots == 36 | 37 | == Upgrade Notice == 38 | 39 | = 2.0.0 = 40 | * [[最新のバージョン(WP5.4)のみサポート]](color:red;font-weight:bold) 41 | * [すべての差分](https://github.com/technote-space/add-richtext-toolbar-button/pull/306) 42 | 43 | == Changelog == 44 | -------------------------------------------------------------------------------- /src/classes/controllers/admin/dashboard.php: -------------------------------------------------------------------------------- 1 | setup_dashicon_picker(); 32 | $this->setup_media_uploader(); 33 | } 34 | 35 | /** 36 | * @return array 37 | */ 38 | protected function get_setting_list() { 39 | return [ 40 | 'is_valid', 41 | 'is_valid_font_color', 42 | 'font_color_icon', 43 | 'is_valid_background_color', 44 | 'background_color_icon', 45 | 'is_valid_font_size', 46 | 'font_size_icon', 47 | 'is_valid_remove_formatting', 48 | 'is_valid_fontawesome', 49 | 'default_icon', 50 | 'default_group', 51 | 'test_phrase', 52 | ]; 53 | } 54 | 55 | /** 56 | * @param array $detail 57 | * @param string $name 58 | * @param array $option 59 | * 60 | * @return array 61 | * @SuppressWarnings(PHPMD.UnusedFormalParameter) 62 | */ 63 | protected function filter_view_setting( 64 | /** @noinspection PhpUnusedParameterInspection */ 65 | array $detail, $name, array $option 66 | ) { 67 | if ( $this->app->string->ends_with( $name, '_icon' ) ) { 68 | $detail['form_type'] = 'icon'; 69 | } 70 | 71 | return $detail; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/classes/models/assets.php: -------------------------------------------------------------------------------- 1 | app->setting->remove_setting( 'assets_version' ); 42 | } 43 | 44 | /** 45 | * setup assets 46 | * @noinspection PhpUnusedPrivateMethodInspection 47 | * @SuppressWarnings(PHPMD.UnusedPrivateMethod) 48 | */ 49 | private function setup_assets() { 50 | if ( ! $this->apply_filters( 'is_valid' ) ) { 51 | return; 52 | } 53 | $this->enqueue_plugin_assets(); 54 | } 55 | 56 | /** 57 | * @noinspection PhpUnusedPrivateMethodInspection 58 | * @SuppressWarnings(PHPMD.UnusedPrivateMethod) 59 | * 60 | * @param string $key 61 | */ 62 | private function changed_option( $key ) { 63 | if ( $this->app->string->starts_with( $key, $this->get_filter_prefix() ) ) { 64 | $this->clear_cache_file(); 65 | } 66 | } 67 | 68 | /** 69 | * @param bool $is_editor 70 | */ 71 | public function enqueue_plugin_assets( $is_editor = false ) { 72 | $this->enqueue_upload_style( $this->get_css_handle(), $this->get_cache_file_name( $is_editor ), function () use ( $is_editor ) { 73 | /** @var Custom_Post\Setting $setting */ 74 | $setting = Custom_Post\Setting::get_instance( $this->app ); 75 | $params = [ 76 | 'settings' => $setting->get_settings( 'front' ), 77 | 'pre_style' => $this->get_pre_style_for_front(), 78 | ]; 79 | $style = $this->get_view( 'front/style', $params ); 80 | 81 | if ( $is_editor ) { 82 | $params['wrap'] = $this->apply_filters( 'editor_wrap_selector', '.components-tooltip .components-popover__content' ); 83 | $params['pre_style'] = $this->get_pre_style_for_editor(); 84 | $params['is_editor'] = true; 85 | $style = $style . $this->get_view( 'front/style', $params ); 86 | } 87 | 88 | return $style; 89 | } ); 90 | if ( $this->apply_filters( 'is_valid_fontawesome' ) ) { 91 | $this->setup_fontawesome(); 92 | } 93 | } 94 | 95 | /** 96 | * @return string 97 | */ 98 | public function get_css_handle() { 99 | return $this->get_slug( 'css-handle', '-css' ); 100 | } 101 | 102 | /** 103 | * @param bool $is_editor 104 | * 105 | * @return string 106 | */ 107 | private function get_cache_file_name( $is_editor ) { 108 | return $is_editor ? $this->get_editor_cache_file_name() : $this->get_front_cache_file_name(); 109 | } 110 | 111 | /** 112 | * @return string 113 | */ 114 | private function get_front_cache_file_name() { 115 | return $this->apply_filters( 'cache_front_file_name', 'artb.css' ); 116 | } 117 | 118 | /** 119 | * @return string 120 | */ 121 | private function get_editor_cache_file_name() { 122 | return $this->apply_filters( 'cache_editor_file_name', 'artb.editor.css' ); 123 | } 124 | 125 | /** 126 | * @return array 127 | */ 128 | private function get_pre_style_for_front() { 129 | return $this->apply_filters( 'pre_style_for_front', [ 130 | 'line-height: 1;', 131 | 'font-size: 1em;', 132 | ] ); 133 | } 134 | 135 | /** 136 | * @return array 137 | */ 138 | private function get_pre_style_for_editor() { 139 | return $this->apply_filters( 'pre_style_for_editor', [] ); 140 | } 141 | 142 | /** 143 | * @return bool 144 | */ 145 | public function clear_cache_file() { 146 | if ( isset( $this->cleared_cache_file ) ) { 147 | return $this->cleared_cache_file; 148 | } 149 | $this->cleared_cache_file = false; 150 | 151 | $deleted = false; 152 | foreach ( [ true, false ] as $is_editor ) { 153 | $deleted |= $this->app->file->delete_upload_file( $this->app, 'css' . DS . $this->get_cache_file_name( $is_editor ) ); 154 | } 155 | $this->cleared_cache_file = $deleted; 156 | $this->app->option->set( $this->get_filter_prefix() . 'assets_version', $this->app->utility->uuid() ); 157 | 158 | return $deleted; 159 | } 160 | } 161 | -------------------------------------------------------------------------------- /src/classes/models/custom_post/setting.php: -------------------------------------------------------------------------------- 1 | app->get_option( 'has_inserted_presets' ) ) { 49 | return; 50 | } 51 | $this->app->option->set( 'has_inserted_presets', true ); 52 | 53 | if ( ! $this->is_empty() ) { 54 | return; 55 | } 56 | 57 | foreach ( $this->apply_filters( 'get_setting_presets', $this->app->get_config( 'preset' ) ) as $item ) { 58 | $item['post_title'] = $this->translate( $this->app->array->search( $item, 'name', 'class_name', 'tag_name', '' ) ); 59 | unset( $item['name'] ); 60 | if ( ! empty( $item['group_name'] ) ) { 61 | $item['group_name'] = $this->translate( $item['group_name'] ); 62 | } 63 | $this->insert( $item ); 64 | } 65 | } 66 | 67 | /** 68 | * setup assets 69 | * @noinspection PhpUnusedPrivateMethodInspection 70 | * @SuppressWarnings(PHPMD.UnusedPrivateMethod) 71 | */ 72 | private function setup_assets() { 73 | global $typenow; 74 | if ( empty( $typenow ) || $typenow !== $this->get_post_type() ) { 75 | return; 76 | } 77 | 78 | /** @var Assets $assets */ 79 | $assets = Assets::get_instance( $this->app ); 80 | $assets->enqueue_plugin_assets(); 81 | $this->add_script_view( 'admin/script/custom_post/preview', [ 82 | 'css_handle' => $assets->get_css_handle(), 83 | 'fontawesome_handle' => $this->apply_filters( 'is_valid_fontawesome' ) ? $this->app->get_config( 'config', 'fontawesome_handle' ) : null, 84 | ] ); 85 | $this->add_style_view( 'admin/style/custom_post/preview', [ 86 | 'post_type' => $this->get_post_type(), 87 | ] ); 88 | } 89 | 90 | /** 91 | * setup page 92 | */ 93 | public function setup_page() { 94 | if ( $this->apply_filters( 'is_valid_fontawesome' ) ) { 95 | $this->setup_fontawesome(); 96 | } 97 | } 98 | 99 | /** 100 | * @param array $params 101 | * @param WP_Post $post 102 | * 103 | * @return array 104 | */ 105 | protected function filter_edit_form_params( array $params, $post ) { 106 | $setting_details = $this->get_setting_details( 'setting' ); 107 | $columns = []; 108 | foreach ( $setting_details as $key => $args ) { 109 | $column = $this->app->array->get( $params['columns'], $key, function () use ( $args ) { 110 | return $this->app->array->get( $args, 'detail', [] ); 111 | } ); 112 | $column['args'] = $args; 113 | unset( $column['args']['name'], $column['args']['value'], $column['args']['selected'], $column['args']['attributes']['checked'] ); 114 | $column['args']['attributes']['data-default'] = $column['args']['attributes']['data-value']; 115 | $column['default'] = $column['args']['attributes']['data-default']; 116 | if ( empty( $column['args']['attributes']['data-option_name'] ) ) { 117 | $column['args']['attributes']['data-option_name'] = $key; 118 | } 119 | $column['is_user_defined'] = true; 120 | if ( empty( $column['type'] ) ) { 121 | $column['type'] = 'VARCHAR'; 122 | } 123 | $column['form_type'] = $this->get_form_type( $column ); 124 | $columns[ $key ] = $column; 125 | } 126 | $params['columns'] = $columns; 127 | $params = $this->app->array->set( $params, 'columns.class_name.args.attributes.data-default', $this->get_default_class_name( $post->ID ) ); 128 | $params = $this->app->array->set( $params, 'columns.class_name.default', $this->app->array->get( $params, 'columns.class_name.args.attributes.data-default' ) ); 129 | $params['name_prefix'] = $this->get_post_field_name_prefix(); 130 | $params['groups'] = $this->get_groups(); 131 | $params['fontawesome_handle'] = $this->apply_filters( 'is_valid_fontawesome' ) ? $this->app->get_config( 'config', 'fontawesome_handle' ) : null; 132 | 133 | return $params; 134 | } 135 | 136 | /** 137 | * @param array $column 138 | * 139 | * @return string 140 | */ 141 | private function get_form_type( array $column ) { 142 | return ! empty( $column['args']['form_type'] ) ? $column['args']['form_type'] : ( empty( $column['form_type'] ) ? $this->get_form_by_type( $column['type'] ) : $column['form_type'] ); 143 | } 144 | 145 | 146 | /** 147 | * @param WP_Post $post 148 | * @param array $params 149 | * @SuppressWarnings(PHPMD.UnusedFormalParameter) 150 | */ 151 | protected function before_output_edit_form( 152 | /** @noinspection PhpUnusedParameterInspection */ 153 | WP_Post $post, array $params 154 | ) { 155 | $this->setup_dashicon_picker(); 156 | $this->setup_media_uploader(); 157 | } 158 | 159 | /** 160 | * @return array 161 | */ 162 | private function get_setting_list() { 163 | return [ 164 | 'tag_name' => [], 165 | 'class_name' => [], 166 | 'group_name' => [ 167 | 'default' => $this->apply_filters( 'default_group' ), 168 | ], 169 | 'icon' => [ 170 | 'args' => [ 171 | 'form_type' => 'icon', 172 | ], 173 | ], 174 | 'style' => [ 175 | 'args' => [ 176 | 'target' => [ 177 | 'setting', 178 | 'front', 179 | ], 180 | 'form_type' => 'style', 181 | 'preset' => $this->get_preset(), 182 | 'is_valid_fontawesome' => $this->apply_filters( 'is_valid_fontawesome' ), 183 | ], 184 | ], 185 | 'styles' => [ 186 | 'args' => [ 187 | 'target' => [ 188 | 'front', 189 | ], 190 | ], 191 | ], 192 | 'test' => [ 193 | 'args' => [ 194 | 'target' => [ 195 | 'setting', 196 | ], 197 | 'form_type' => 'test', 198 | ], 199 | ], 200 | 'is_valid_toolbar_button' => [ 201 | 'args' => [ 202 | 'target' => [ 203 | 'setting', 204 | 'front', 205 | 'editor', 206 | ], 207 | ], 208 | ], 209 | 'priority' => [ 210 | 'args' => [ 211 | 'target' => [ 212 | 'setting', 213 | 'front', 214 | ], 215 | ], 216 | ], 217 | ]; 218 | } 219 | 220 | /** 221 | * @param string $target 222 | * 223 | * @return array 224 | */ 225 | private function get_setting_details( $target ) { 226 | $args = []; 227 | foreach ( $this->get_setting_list() as $key => $setting ) { 228 | if ( is_array( $setting ) && ! empty( $setting['args']['target'] ) && ! in_array( $target, $setting['args']['target'], true ) ) { 229 | continue; 230 | } 231 | $args[ $key ] = $this->get_setting( $key, $setting ); 232 | } 233 | 234 | return $args; 235 | } 236 | 237 | /** 238 | * @param string $name 239 | * @param string|array $setting 240 | * 241 | * @return array 242 | */ 243 | private function get_setting( $name, $setting ) { 244 | if ( ! isset( $this->cache_setting[ $name ] ) ) { 245 | $columns = $this->app->db->get_columns( $this->get_related_table_name() ); 246 | $detail = $this->app->array->get( is_array( $setting ) ? $setting : [], 'detail', function () use ( $columns, $name ) { 247 | return $this->app->array->get( $columns, $name, [] ); 248 | } ); 249 | $value = $this->app->array->get( is_array( $setting ) ? $setting : [], 'default', function () use ( $detail ) { 250 | return $this->app->array->get( $detail, 'default' ); 251 | } ); 252 | $ret = [ 253 | 'class' => 'add-richtext-toolbar-option', 254 | 'name' => $this->get_post_field_name_prefix() . $name, 255 | 'value' => $value, 256 | 'label' => $this->translate( $this->app->array->get( $detail, 'comment', $name ) ), 257 | 'attributes' => [ 258 | 'data-value' => $value, 259 | 'data-default' => $value, 260 | ], 261 | 'detail' => $detail, 262 | 'type' => $this->app->utility->parse_db_type( $this->app->array->get( $detail, 'type' ) ), 263 | ]; 264 | if ( is_array( $setting ) ) { 265 | $ret = array_replace_recursive( $ret, isset( $setting['args'] ) && is_array( $setting['args'] ) ? $setting['args'] : [] ); 266 | } 267 | if ( 'bool' === $ret['type'] ) { 268 | $ret['value'] = 1; 269 | if ( ! empty( $value ) ) { 270 | $ret['attributes']['checked'] = 'checked'; 271 | } 272 | $ret['label'] = $this->translate( 'Valid' ); 273 | } 274 | $this->cache_setting[ $name ] = $ret; 275 | } 276 | 277 | return $this->cache_setting[ $name ]; 278 | } 279 | 280 | /** 281 | * @return null|string 282 | */ 283 | protected function get_post_column_title() { 284 | return $this->translate( 'Setting name' ); 285 | } 286 | 287 | /** 288 | * @return array 289 | */ 290 | protected function get_manage_posts_columns() { 291 | return [ 292 | 'preview' => $this->get_manage_column_preview(), 293 | 'display' => $this->get_manage_column_display(), 294 | 'is_valid_toolbar_button' => [ 295 | 'name' => $this->translate( 'Validity of toolbar button' ), 296 | 'callback' => function ( $value ) { 297 | return ! empty( $value ) ? $this->translate( 'Valid' ) : $this->translate( 'Invalid' ); 298 | }, 299 | 'sortable' => true, 300 | 'default_sort' => true, 301 | 'default_sort_priority' => 1, 302 | 'desc' => true, 303 | ], 304 | 'priority' => [ 305 | 'name' => $this->translate( 'priority' ), 306 | 'value' => '', 307 | 'sortable' => true, 308 | 'default_sort' => true, 309 | 'default_sort_priority' => 5, 310 | ], 311 | ]; 312 | } 313 | 314 | /** 315 | * @return array 316 | * @SuppressWarnings(PHPMD.UnusedFormalParameter) 317 | */ 318 | private function get_manage_column_preview() { 319 | return [ 320 | 'name' => $this->translate( 'preview' ), 321 | 'callback' => function ( 322 | /** @noinspection PhpUnusedParameterInspection */ 323 | $value, $data, $post 324 | ) { 325 | $setting_details = $this->get_setting_details( 'list' ); 326 | $data['class_name'] = $this->get_setting_class_name( $data, $post ); 327 | foreach ( [ 'class_name', 'tag_name' ] as $key ) { 328 | $is_default = $this->is_default( $data[ $key ] ); 329 | if ( $is_default ) { 330 | $setting = $this->app->array->get( $setting_details, $key ); 331 | $data[ $key ] = $setting['value']; 332 | } 333 | } 334 | 335 | return $this->get_view( 'admin/custom_post/setting/preview', [ 336 | 'class_name' => $data['class_name'], 337 | 'tag_name' => $data['tag_name'], 338 | ] ); 339 | }, 340 | 'unescape' => true, 341 | ]; 342 | } 343 | 344 | /** 345 | * @return array 346 | * @SuppressWarnings(PHPMD.UnusedFormalParameter) 347 | */ 348 | private function get_manage_column_display() { 349 | return [ 350 | 'name' => $this->translate( 'display' ), 351 | 'callback' => function ( 352 | /** @noinspection PhpUnusedParameterInspection */ 353 | $value, $data, $post 354 | ) { 355 | $setting_details = $this->get_setting_details( 'list' ); 356 | $details = []; 357 | $data['class_name'] = $this->get_setting_class_name( $data, $post ); 358 | foreach ( array_keys( $this->get_setting_list() ) as $key ) { 359 | $setting = $this->app->array->get( $setting_details, $key ); 360 | if ( empty( $setting ) ) { 361 | continue; 362 | } 363 | $is_default = $this->is_default( $data[ $key ] ); 364 | if ( $is_default ) { 365 | $data[ $key ] = $setting['value']; 366 | } 367 | $details[ $setting['label'] ] = 'icon' === $key ? [ 368 | 'value' => $data[ $key ], 369 | 'form_type' => 'icon', 370 | ] : $data[ $key ]; 371 | } 372 | 373 | return $this->get_view( 'admin/custom_post/setting/detail', [ 374 | 'details' => $details, 375 | ] ); 376 | }, 377 | 'unescape' => true, 378 | ]; 379 | } 380 | 381 | /** 382 | * @param string $key 383 | * 384 | * @return null|string 385 | */ 386 | protected function get_table_column_name( $key ) { 387 | if ( 'post_title' === $key ) { 388 | return $this->get_post_column_title(); 389 | } 390 | 391 | return null; 392 | } 393 | 394 | /** 395 | * @param int $post_id 396 | * @param WP_Post $post 397 | * @param array $old 398 | * @param array $new 399 | * @SuppressWarnings(PHPMD.UnusedFormalParameter) 400 | */ 401 | public function data_updated( $post_id, WP_Post $post, array $old, array $new ) { 402 | $this->clear_cache_file(); 403 | } 404 | 405 | /** 406 | * @param int $post_id 407 | * @param WP_Post $post 408 | * @param array $data 409 | * @SuppressWarnings(PHPMD.UnusedFormalParameter) 410 | */ 411 | public function data_inserted( $post_id, WP_Post $post, array $data ) { 412 | $this->clear_cache_file(); 413 | } 414 | 415 | /** 416 | * @param int $post_id 417 | * @param WP_Post $post 418 | * @SuppressWarnings(PHPMD.UnusedFormalParameter) 419 | */ 420 | public function untrash_post( $post_id, WP_Post $post ) { 421 | $this->clear_cache_file(); 422 | } 423 | 424 | /** 425 | * @param int $post_id 426 | * @SuppressWarnings(PHPMD.UnusedFormalParameter) 427 | */ 428 | public function trash_post( $post_id ) { 429 | $this->clear_cache_file(); 430 | } 431 | 432 | /** 433 | * @param int $post_id 434 | * @SuppressWarnings(PHPMD.UnusedFormalParameter) 435 | */ 436 | protected function delete_misc( 437 | /** @noinspection PhpUnusedParameterInspection */ 438 | $post_id 439 | ) { 440 | $this->clear_cache_file(); 441 | } 442 | 443 | /** 444 | * clear options cache 445 | */ 446 | private function clear_cache_file() { 447 | /** @var Assets $assets */ 448 | $assets = Assets::get_instance( $this->app ); 449 | $assets->clear_cache_file(); 450 | } 451 | 452 | /** 453 | * @param string $target 454 | * 455 | * @return array 456 | */ 457 | public function get_settings( $target ) { 458 | if ( ! isset( $this->cache_settings[ $target ] ) ) { 459 | $setting_details = $this->get_setting_details( $target ); 460 | $priority_direction = 'front' === $target ? 'DESC' : 'ASC'; 461 | $group_name_direction = 'front' === $target ? 'DESC' : 'ASC'; 462 | $updated_at_direction = 'front' === $target ? 'ASC' : 'DESC'; 463 | $list_data = $this->get_list_data( function ( $query ) use ( $priority_direction, $updated_at_direction, $group_name_direction ) { 464 | /** @var Builder $query */ 465 | $query->order_by( 'priority', $priority_direction ) 466 | ->order_by( 'updated_at', $updated_at_direction ) 467 | ->order_by( 'group_name', $group_name_direction ); 468 | } ); 469 | $this->cache_settings[ $target ] = $this->app->array->map( $this->app->array->get( $list_data, 'data' ), function ( $data ) use ( $setting_details, $target ) { 470 | return $this->data_to_setting( $data, $setting_details, $target ); 471 | } ); 472 | } 473 | 474 | return $this->cache_settings[ $target ]; 475 | } 476 | 477 | /** 478 | * @param array $data 479 | * @param array $setting_details 480 | * @param string $target 481 | * 482 | * @return array 483 | */ 484 | private function data_to_setting( $data, $setting_details, $target ) { 485 | $setting = []; 486 | foreach ( array_keys( $this->get_setting_list() ) as $key ) { 487 | $detail = $this->app->array->get( $setting_details, $key ); 488 | if ( empty( $detail ) ) { 489 | continue; 490 | } 491 | 492 | $is_default = $this->is_default( $data[ $key ] ); 493 | $detail['attributes']['data-value'] = $is_default ? $detail['value'] : $data[ $key ]; 494 | list( $name, $value ) = $this->parse_setting( $detail, $key ); // phpcs:ignore Generic.Formatting.MultipleStatementAlignment.NotSameWarning 495 | $setting[ $name ] = $value; // phpcs:ignore Generic.Formatting.MultipleStatementAlignment.NotSameWarning 496 | } 497 | /** @var WP_Post $post */ 498 | $post = $data['post']; 499 | $setting['class_name'] = $this->get_setting_class_name( $setting, $post ); 500 | $setting['group_name'] = $this->get_setting_group_name( $setting, $post ); 501 | $setting['title'] = $post->post_title; 502 | $setting['name'] = "setting-{$post->ID}"; 503 | $setting['selector'] = $this->get_selector( $setting ); 504 | $setting['is_valid'] = $setting['is_valid_toolbar_button']; 505 | if ( 'editor' === $target ) { 506 | foreach ( $setting as $key => $item ) { 507 | $new_key = $this->app->string->camel( $key ); 508 | if ( $key !== $new_key ) { 509 | $setting[ $new_key ] = $item; 510 | unset( $setting[ $key ] ); 511 | } 512 | } 513 | } 514 | 515 | return $setting; 516 | } 517 | 518 | /** 519 | * @param array $setting 520 | * @param WP_Post $post 521 | * 522 | * @return string 523 | */ 524 | private function get_setting_class_name( array $setting, $post ) { 525 | return $this->apply_filters( 'class_name', empty( $setting['class_name'] ) ? $this->get_default_class_name( $post->ID ) : $setting['class_name'], $setting, $post ); 526 | } 527 | 528 | /** 529 | * @param int|string $post_id 530 | * 531 | * @return string 532 | */ 533 | public function get_default_class_name( $post_id ) { 534 | return $this->apply_filters( 'default_class_name', $this->get_default_class_name_prefix() . $post_id, $post_id ); 535 | } 536 | 537 | /** 538 | * @return string 539 | */ 540 | public function get_default_class_name_prefix() { 541 | return 'artb-'; 542 | } 543 | 544 | /** 545 | * @param array $setting 546 | * @param WP_Post $post 547 | * 548 | * @return string 549 | */ 550 | private function get_setting_group_name( array $setting, $post ) { 551 | if ( ! empty( $setting['group_name'] ) ) { 552 | return $this->apply_filters( 'group_name', $setting['group_name'], $setting, $post ); 553 | } 554 | 555 | $group_name = $this->apply_filters( 'default_group' ); 556 | if ( '' === (string) $group_name ) { 557 | $group_name = $this->get_default_group_name( $post ); 558 | } 559 | 560 | return $this->apply_filters( 'group_name', $group_name, $setting, $post ); 561 | } 562 | 563 | /** 564 | * @param WP_Post $post 565 | * 566 | * @return string 567 | */ 568 | private function get_default_group_name( $post ) { 569 | return $this->apply_filters( 'default_group_name', $post->post_title . '-' . $post->ID, $post ); 570 | } 571 | 572 | /** 573 | * @param array $setting 574 | * 575 | * @return string 576 | */ 577 | private function get_selector( array $setting ) { 578 | $class_names = $this->app->string->explode( $setting['class_name'], ' ' ); 579 | $class_names = '.' . implode( '.', $class_names ); 580 | 581 | return $this->apply_filters( 'get_selector', $setting['tag_name'] . $class_names, $setting['tag_name'], $setting['class_name'], $setting ); 582 | } 583 | 584 | /** 585 | * @param array $setting 586 | * @param string $key 587 | * 588 | * @return array 589 | */ 590 | private function parse_setting( array $setting, $key ) { 591 | $value = $setting['attributes']['data-value']; 592 | $name = empty( $setting['attributes']['data-option_name'] ) ? $key : $setting['attributes']['data-option_name']; 593 | 594 | return [ $name, $value ]; 595 | } 596 | 597 | /** 598 | * @param array $errors 599 | * @param array $post_array 600 | * 601 | * @return array 602 | * 603 | */ 604 | protected function filter_validate_input( array $errors, array $post_array ) { 605 | /** @var Validation $validation */ 606 | $validation = Validation::get_instance( $this->app ); 607 | 608 | $class_name = trim( $this->get_post_field( 'class_name' ) ); 609 | $class_name = preg_replace( '/\s{2,}/', ' ', $class_name ); 610 | if ( '' !== $class_name ) { 611 | $priority = (int) $this->get_post_field( 'priority', 10 ); 612 | $errors = $validation->validate_class_name( $class_name, $priority, $post_array, $errors ); 613 | } 614 | 615 | $tag_name = trim( $this->get_post_field( 'tag_name' ) ); 616 | if ( '' !== $tag_name ) { 617 | $errors = $validation->validate_tag_name( $tag_name, $errors ); 618 | } 619 | 620 | return $errors; 621 | } 622 | 623 | /** 624 | * @param string $key 625 | * @param mixed $value 626 | * @param mixed $default 627 | * @param array|null $post_array 628 | * 629 | * @return mixed 630 | * @SuppressWarnings(PHPMD.UnusedFormalParameter) 631 | */ 632 | protected function filter_post_field( 633 | /** @noinspection PhpUnusedParameterInspection */ 634 | $key, $value, $default, $post_array 635 | ) { 636 | if ( is_string( $value ) ) { 637 | $value = trim( $value ); 638 | } 639 | if ( 'style' === $key ) { 640 | /** @var Style $style */ 641 | $style = Style::get_instance( $this->app ); 642 | 643 | return $style->encode_style( $value ); 644 | } elseif ( 'group_name' === $key ) { 645 | return preg_replace( '/[\x00-\x1F\x7F]/', '', $value ); 646 | } elseif ( 'class_name' === $key ) { 647 | return preg_replace( '/\s{2,}/', ' ', $value ); 648 | } 649 | 650 | return $value; 651 | } 652 | 653 | /** 654 | * @param array $data 655 | * 656 | * @return array 657 | */ 658 | protected function filter_item( array $data ) { 659 | /** @var Style $style */ 660 | $style = Style::get_instance( $this->app ); 661 | $data['styles'] = $style->decode_style( $data['style'] ); 662 | $data['style'] = $style->decode_style( $data['style'], true ); 663 | 664 | return $data; 665 | } 666 | 667 | /** 668 | * @return array 669 | */ 670 | private function get_groups() { 671 | $groups = array_filter( $this->app->array->pluck_unique( $this->app->array->get( $this->get_list_data( null, false ), 'data', [] ), 'group_name' ), function ( $data ) { 672 | return isset( $data ) && '' !== $data; 673 | } ); 674 | $default = $this->apply_filters( 'default_group' ); 675 | if ( $default && ! in_array( $default, $groups, true ) ) { 676 | $groups[] = $default; 677 | } 678 | 679 | return $this->apply_filters( 'get_groups', $this->app->array->combine( $groups, null ) ); 680 | } 681 | 682 | /** 683 | * @return array 684 | */ 685 | private function get_preset() { 686 | $font_family = $this->apply_filters( 'is_valid_fontawesome' ) ? $this->app->get_config( 'config', 'fontawesome_font_family' ) : null; 687 | 688 | return $this->apply_filters( 'get_preset', array_filter( $this->app->array->map( $this->app->get_config( 'design_preset' ), function ( $preset ) use ( $font_family ) { 689 | if ( $this->is_closure( $preset ) ) { 690 | if ( ! $font_family ) { 691 | return null; 692 | } 693 | 694 | return $preset( $font_family ); 695 | } 696 | 697 | return $preset; 698 | } ) ) ); 699 | } 700 | 701 | /** 702 | * @return array 703 | */ 704 | public function get_valid_post_types() { 705 | return $this->app->array->combine( array_intersect( get_post_types_by_support( 'editor' ), get_post_types( [ 706 | 'show_in_rest' => true, 707 | ] ) ), null ); 708 | } 709 | } 710 | -------------------------------------------------------------------------------- /src/classes/models/editor.php: -------------------------------------------------------------------------------- 1 | apply_filters( 'is_valid' ) ) { 37 | return; 38 | } 39 | 40 | $handle = 'add-richtext-toolbar-button-editor'; 41 | $this->enqueue_style( $handle, 'gutenberg.css' ); 42 | $this->enqueue_script( $handle, 'index.min.js', $this->app->editor->filter_packages( [ 43 | 'wp-block-editor', 44 | 'wp-blocks', 45 | 'wp-components', 46 | 'wp-compose', 47 | 'wp-core-data', 48 | 'wp-data', 49 | 'wp-dom', 50 | 'wp-editor', 51 | 'wp-element', 52 | 'wp-format-library', 53 | 'wp-hooks', 54 | 'wp-i18n', 55 | 'wp-is-shallow-equal', 56 | 'wp-keycodes', 57 | 'wp-rich-text', 58 | 'wp-server-side-render', 59 | 'wp-url', 60 | ], [ 'lodash' ] ), $this->app->get_plugin_version() ); 61 | $this->localize_script( $handle, 'artbParams', $this->get_editor_params() ); 62 | 63 | /** @var Assets $assets */ 64 | $assets = Assets::get_instance( $this->app ); 65 | $assets->enqueue_plugin_assets( true ); 66 | } 67 | 68 | /** 69 | * @return array 70 | */ 71 | private function get_editor_params() { 72 | /** @var Custom_Post\Setting $setting */ 73 | $setting = Custom_Post\Setting::get_instance( $this->app ); 74 | 75 | return [ 76 | 'settings' => $setting->get_settings( 'editor' ), 77 | 'defaultIcon' => $this->apply_filters( 'default_icon' ), 78 | 'isValidContrastChecker' => $this->apply_filters( 'is_valid_contrast_checker' ), 79 | 'isValidRemoveFormatting' => $this->apply_filters( 'is_valid_remove_formatting' ), 80 | 'translate' => $this->get_translate_data( [ 81 | 'Please select text', 82 | 'Remove All formatting', 83 | 'Inline Text Settings', 84 | ] ), 85 | 'defaultButtons' => [ 86 | 'font-color' => [ 87 | 'name' => 'font-color', 88 | 'title' => $this->translate( 'font color' ), 89 | 'icon' => $this->apply_filters( 'font_color_icon' ), 90 | 'className' => $setting->get_default_class_name( 'font-color' ), 91 | 'style' => 'color', 92 | 'isValid' => $this->apply_filters( 'is_valid_font_color' ), 93 | ], 94 | 'background-color' => [ 95 | 'name' => 'background-color', 96 | 'title' => $this->translate( 'background color' ), 97 | 'icon' => $this->apply_filters( 'background_color_icon' ), 98 | 'className' => $setting->get_default_class_name( 'background-color' ), 99 | 'style' => 'background-color', 100 | 'isValid' => $this->apply_filters( 'is_valid_background_color' ), 101 | ], 102 | 'font-size' => [ 103 | 'name' => 'font-size', 104 | 'title' => $this->translate( 'font size' ), 105 | 'icon' => $this->apply_filters( 'font_size_icon' ), 106 | 'className' => $setting->get_default_class_name( 'font-size' ), 107 | 'isValid' => $this->apply_filters( 'is_valid_font_size' ), 108 | ], 109 | ], 110 | ]; 111 | } 112 | } 113 | -------------------------------------------------------------------------------- /src/classes/models/style.php: -------------------------------------------------------------------------------- 1 | $v ) { 43 | $matches = null; 44 | if ( ! preg_match( '/^(\[([-().#>+~|*a-z]+)]\s*)?(.+?)\s*:\s*(.+?)\s*$/', $v, $matches ) ) { 45 | continue; 46 | } 47 | 48 | $pseudo = trim( $matches[2] ); 49 | $key = trim( $matches[3] ); 50 | $val = trim( $matches[4] ); 51 | if ( ! preg_match( '/\A[a-z-]+\z/i', $key ) ) { 52 | continue; 53 | } 54 | 55 | $value = "{$key}: {$val};"; 56 | $index[ $pseudo ][ $value ] = $k; 57 | $styles[ $pseudo ][ $k ] = $value; 58 | } 59 | 60 | ksort( $styles ); 61 | foreach ( $styles as $pseudo => $values ) { 62 | foreach ( $values as $k => $value ) { 63 | if ( $index[ $pseudo ][ $value ] !== $k ) { 64 | unset( $styles[ $pseudo ][ $k ] ); 65 | } 66 | } 67 | $styles[ $pseudo ] = array_values( $styles[ $pseudo ] ); 68 | } 69 | 70 | return wp_json_encode( $styles ); 71 | } 72 | 73 | /** 74 | * @param string $style 75 | * @param bool $is_editor 76 | * 77 | * @return array|string 78 | * @SuppressWarnings(PHPMD.ErrorControlOperator) 79 | */ 80 | public function decode_style( $style, $is_editor = false ) { 81 | $styles = @json_decode( $style, true ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged 82 | if ( ! is_array( $styles ) ) { 83 | $styles = []; 84 | } 85 | 86 | if ( ! $is_editor ) { 87 | return $styles; 88 | } 89 | 90 | $items = []; 91 | foreach ( $styles as $pseudo => $values ) { 92 | foreach ( $values as $value ) { 93 | $items[] = '' === $pseudo ? $value : "[{$pseudo}] {$value}"; 94 | } 95 | $items[] = ''; 96 | } 97 | 98 | return implode( "\r\n", $items ); 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /src/classes/models/validation.php: -------------------------------------------------------------------------------- 1 | app ); 40 | if ( preg_match( '/\A' . preg_quote( $setting->get_default_class_name_prefix(), '/' ) . '/', $class_name ) ) { 41 | $errors['class_name'][] = $this->translate( 'The value is unusable.' ); 42 | 43 | return $errors; 44 | } 45 | if ( ! preg_match( '/\A([_a-zA-Z]+[a-zA-Z0-9-]*)(\s+[_a-zA-Z]+[_a-zA-Z0-9-]*)*\z/', $class_name ) ) { 46 | $errors['class_name'][] = $this->translate( 'Invalid format.' ); 47 | $errors['class_name'][] = $this->translate( 'A class name must begin with a letter, followed by any number of hyphens, letters, or numbers.' ); 48 | 49 | return $errors; 50 | } 51 | 52 | if ( ! isset( $post_array['ID'] ) ) { 53 | $post_array['ID'] = -1; 54 | } 55 | if ( $this->app->db->builder() 56 | ->from( $setting->get_related_table_name() ) 57 | ->where( 'post_id', '<>', $post_array['ID'] ) 58 | ->where( 'class_name', $class_name ) 59 | ->exists() ) { 60 | $errors['class_name'][] = $this->translate( 'The value has already been used.' ); 61 | } else { 62 | // この時点で $class_name は 英数及びアンダーバー、ハイフン、スーペースのみ 63 | $replace = " {$class_name} "; 64 | if ( $this->app->db->builder() 65 | ->from( $setting->get_related_table_name() ) 66 | ->where( 'post_id', '<>', $post_array['ID'] ) 67 | ->where( 'priority', '<=', $priority ) 68 | ->where_raw( "LENGTH(%s) <> LENGTH(REPLACE(%s, CONCAT(' ', class_name, ' '), ''))", [ $replace, $replace ] ) 69 | ->exists() ) { 70 | $errors['class_name'][] = $this->translate( 'The value is included in the class name of other settings.' ); 71 | } 72 | } 73 | 74 | return $errors; 75 | } 76 | 77 | /** 78 | * @param string $tag_name 79 | * @param array $errors 80 | * 81 | * @return array 82 | */ 83 | public function validate_tag_name( $tag_name, array $errors ) { 84 | if ( 'div' === strtolower( $tag_name ) ) { 85 | $errors['tag_name'][] = $this->translate( 'This tag name is unusable.' ); 86 | } elseif ( ! preg_match( '/\A[a-zA-Z]+\z/', $tag_name ) ) { 87 | $errors['tag_name'][] = $this->translate( 'Invalid format.' ); 88 | } 89 | 90 | return $errors; 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /src/interfaces/models/custom_post.php: -------------------------------------------------------------------------------- 1 | cap; 33 | } 34 | 35 | /** 36 | * @return string|false 37 | */ 38 | protected function get_post_type_parent() { 39 | return $this->app->admin->get_menu_slug(); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/views/admin/custom_post/setting/detail.php: -------------------------------------------------------------------------------- 1 | 17 | 18 | $value ) : ?> 19 | 20 | 21 | 32 | 33 | 34 |
h( $name ); ?> 22 | 23 | 24 | get_view( 'admin/custom_post/setting/preview/' . $value['form_type'], $value, true, false ); ?> 25 | 26 | h( $instance->app->array->get( $value, 'value' ) ); ?> 27 | 28 | 29 | h( $value ); ?> 30 | 31 |
35 | -------------------------------------------------------------------------------- /src/views/admin/custom_post/setting/preview.php: -------------------------------------------------------------------------------- 1 | 18 | 19 | -------------------------------------------------------------------------------- /src/views/admin/custom_post/setting/preview/icon.php: -------------------------------------------------------------------------------- 1 | 17 |
18 | form( 'input/hidden', [ 19 | 'name' => '', 20 | 'value' => $value, 21 | 'class' => 'display-icon', 22 | ] ); ?> 23 |
24 |
25 | -------------------------------------------------------------------------------- /src/views/admin/include/custom_post/icon.php: -------------------------------------------------------------------------------- 1 | old( $prefix . $name, $data, $name ); 20 | $target = '#' . preg_replace( '#/#', '\\/', $prefix . $name ); 21 | ?> 22 |
23 |
24 |
25 | form( 'input/text', [ 26 | 'name' => $prefix . $name, 27 | 'id' => $prefix . $name, 28 | 'value' => $val, 29 | ], $instance->app->array->get( $column, 'args', [] ) ); ?> 30 | 31 | form( 'dashicon', [ 32 | 'target' => $target, 33 | 'value' => 'Select icon', 34 | 'class' => 'button-primary', 35 | ] ); ?> 36 | form( 'uploader', [ 37 | 'target' => $target, 38 | 'value' => 'Media uploader', 39 | 'class' => 'button-primary', 40 | ] ); ?> 41 | form( 'input/button', [ 42 | 'value' => 'reset', 43 | 'name' => 'reset', 44 | 'class' => 'button-primary reset-icon', 45 | 'attributes' => [ 46 | 'data-target' => $target, 47 | 'data-value' => $instance->app->array->get( $data, $name ), 48 | ], 49 | ] ); ?> 50 |
51 |
52 | -------------------------------------------------------------------------------- /src/views/admin/include/custom_post/style.php: -------------------------------------------------------------------------------- 1 | app->array->get( $column, 'attributes', [] ); 20 | $attr['rows'] = $instance->app->array->get( $column, 'rows', 5 ); 21 | $attr['data-reset'] = $instance->json( $instance->app->array->get( $data, $name, '' ), false ); 22 | $preset = $instance->app->array->get( $column['args'], 'preset' ); 23 | $is_valid_fontawesome = $instance->app->array->get( $column['args'], 'is_valid_fontawesome' ); 24 | ?> 25 | form( 'textarea', [ 26 | 'name' => $prefix . $name, 27 | 'id' => $prefix . $name, 28 | 'value' => $instance->old( $prefix . $name, $data, $name, $instance->app->array->get( $column, 'default', '' ) ), 29 | 'attributes' => $attr, 30 | ], $instance->app->array->get( $column, 'args', [] ) ); ?> 31 |
32 | form( 'input/button', [ 33 | 'value' => 'clear', 34 | 'name' => 'clear', 35 | 'class' => 'button-primary clear-style', 36 | ] ); ?> 37 | form( 'input/button', [ 38 | 'value' => 'reset', 39 | 'name' => 'reset', 40 | 'class' => 'button-primary reset-style', 41 | ] ); ?> 42 |
43 | 44 |
45 | h( 'preset', true ); ?> 46 | $value ) : ?> 47 | form( 'input/button', [ 48 | 'value' => $key, 49 | 'name' => $key, 50 | 'class' => 'button-primary preset-style' . ( is_array( $value ) && count( $value ) > 1 ? ' multiple' : '' ), 51 | 'attributes' => [ 52 | 'data-value' => $instance->json( $value, false ), 53 | ], 54 | ] ); ?> 55 | 56 |
57 | 58 | url( $instance->app->get_config( 'config', 'fontawesome_icon_url' ), 'Font Awesome Icons', true, true ); 60 | endif; ?> 61 | -------------------------------------------------------------------------------- /src/views/admin/include/custom_post/test.php: -------------------------------------------------------------------------------- 1 | 16 |
17 | h( 'preview', true ); ?> 18 |
19 | 20 |
21 |
22 |
23 | form( 'input/checkbox', [ 24 | 'value' => 1, 25 | 'name' => '', 26 | 'label' => 'Display auxiliary line', 27 | 'checked' => false, 28 | 'class' => 'display-auxiliary-line', 29 | ] ); ?> 30 | form( 'input/checkbox', [ 31 | 'value' => 1, 32 | 'name' => '', 33 | 'label' => 'Multiple lines', 34 | 'checked' => false, 35 | 'class' => 'multiple-lines', 36 | ] ); ?> 37 |
38 | -------------------------------------------------------------------------------- /src/views/admin/script/custom_post/preview.php: -------------------------------------------------------------------------------- 1 | add_script_view( 'admin/script/icon' ); 18 | ?> 19 | 53 | -------------------------------------------------------------------------------- /src/views/admin/script/custom_post/setting.php: -------------------------------------------------------------------------------- 1 | add_script_view( 'admin/script/icon' ); 19 | $phrase = $instance->app->filter->apply_filters( 'test_phrase' ); 20 | ?> 21 | 22 | 262 | -------------------------------------------------------------------------------- /src/views/admin/script/dashboard.php: -------------------------------------------------------------------------------- 1 | add_script_view( 'admin/script/icon' ); 16 | $target = []; 17 | foreach ( $settings as $k => $v ) { 18 | if ( $instance->app->string->ends_with( $k, '_icon' ) ) { 19 | $target[] = '#' . preg_replace( '#/#', '\\\\/', $v['name'] ); 20 | } 21 | } 22 | ?> 23 | 51 | -------------------------------------------------------------------------------- /src/views/admin/script/icon.php: -------------------------------------------------------------------------------- 1 | 16 | 36 | -------------------------------------------------------------------------------- /src/views/admin/style/custom_post/preview.php: -------------------------------------------------------------------------------- 1 | 17 | 18 | 27 | -------------------------------------------------------------------------------- /src/views/admin/style/custom_post/setting.php: -------------------------------------------------------------------------------- 1 | 17 | 18 | 91 | -------------------------------------------------------------------------------- /src/views/admin/style/dashboard.php: -------------------------------------------------------------------------------- 1 | 13 | 23 | -------------------------------------------------------------------------------- /src/views/front/style.php: -------------------------------------------------------------------------------- 1 | $styles ) { 37 | $selector = $tmp; 38 | if ( '' !== $pseudo ) { 39 | $selector .= ':' . $pseudo; 40 | } 41 | $style_content .= $selector . "{\n"; 42 | foreach ( $pre_style as $style ) { 43 | $style_content .= "\t{$style}\n"; 44 | } 45 | foreach ( $styles as $style ) { 46 | $style_content .= "\t{$style}\n"; 47 | } 48 | $style_content .= "}\n"; 49 | } 50 | } 51 | } 52 | } 53 | ?> 54 | 57 | -------------------------------------------------------------------------------- /tests/controllers/admin/test-dashboard.php: -------------------------------------------------------------------------------- 1 | assertFalse( wp_script_is( 'media-upload' ) ); 69 | $this->assertFalse( wp_script_is( 'thickbox' ) ); 70 | $this->assertFalse( wp_style_is( 'thickbox' ) ); 71 | 72 | static::$dashboard->action(); 73 | $this->assertTrue( wp_script_is( 'media-upload' ) ); 74 | $this->assertTrue( wp_script_is( 'thickbox' ) ); 75 | $this->assertTrue( wp_style_is( 'thickbox' ) ); 76 | $this->assertNotEmpty( static::get_output_js() ); 77 | $this->assertNotEmpty( static::get_output_css() ); 78 | } 79 | 80 | public function test_presenter() { 81 | ob_start(); 82 | static::$dashboard->presenter(); 83 | $contents = ob_get_contents(); 84 | ob_end_clean(); 85 | 86 | $this->assertContains( 'name="artb_nonce_admin_dashboard"', $contents ); 87 | $this->assertContains( 'id="artb-is_valid"', $contents ); 88 | $this->assertContains( 'id="artb-is_valid_font_color"', $contents ); 89 | $this->assertContains( 'id="artb/font_color_icon"', $contents ); 90 | $this->assertContains( 'id="artb-is_valid_background_color"', $contents ); 91 | $this->assertContains( 'id="artb/background_color_icon"', $contents ); 92 | $this->assertContains( 'id="artb-is_valid_font_size"', $contents ); 93 | $this->assertContains( 'id="artb/font_size_icon"', $contents ); 94 | $this->assertContains( 'id="artb-is_valid_remove_formatting"', $contents ); 95 | $this->assertContains( 'id="artb/default_icon"', $contents ); 96 | $this->assertContains( 'id="artb-default_group"', $contents ); 97 | $this->assertContains( 'id="artb-test_phrase"', $contents ); 98 | $this->assertContains( 'name="update"', $contents ); 99 | $this->assertContains( 'name="reset"', $contents ); 100 | $this->assertContains( 'id="artb-info-wrap"', $contents ); 101 | } 102 | 103 | /** 104 | * @return false|string 105 | * @throws ReflectionException 106 | */ 107 | private static function get_output_js() { 108 | ob_start(); 109 | static::$app->minify->output_js( true ); 110 | $contents = ob_get_contents(); 111 | ob_end_clean(); 112 | 113 | static::set_property( static::$app->minify, 'has_output_script', false ); 114 | 115 | return $contents; 116 | } 117 | 118 | /** 119 | * @return false|string 120 | * @throws ReflectionException 121 | */ 122 | private static function get_output_css() { 123 | ob_start(); 124 | static::$app->minify->output_css( true ); 125 | $contents = ob_get_contents(); 126 | ob_end_clean(); 127 | 128 | static::set_property( static::$app->minify, 'end_footer', false ); 129 | 130 | return $contents; 131 | } 132 | 133 | /** 134 | * @param $target 135 | * @param $name 136 | * @param $value 137 | * 138 | * @throws ReflectionException 139 | */ 140 | private static function set_property( $target, $name, $value ) { 141 | $reflection = new ReflectionClass( $target ); 142 | $property = $reflection->getProperty( $name ); 143 | $property->setAccessible( true ); 144 | $property->setValue( $target, $value ); 145 | $property->setAccessible( false ); 146 | } 147 | } 148 | -------------------------------------------------------------------------------- /tests/models/custom_post/test-setting.php: -------------------------------------------------------------------------------- 1 | db->table( 'setting' )->truncate(); 66 | static::$app->db->wp_table( 'posts' )->truncate(); 67 | static::$app->option->delete( 'has_inserted_presets' ); 68 | wp_dequeue_style( static::$assets->get_css_handle() ); 69 | 70 | $handle = static::$app->get_config( 'config', 'fontawesome_handle' ); 71 | wp_dequeue_style( $handle ); 72 | static::set_property( static::$setting, 'setup_fontawesome', [] ); 73 | static::set_property( static::$setting, 'cache_settings', [] ); 74 | static::set_property( static::$setting, 'cache_setting', [] ); 75 | } 76 | 77 | /** 78 | * @throws ReflectionException 79 | */ 80 | public function test_insert_presets() { 81 | static::reset(); 82 | $this->assertEmpty( static::$app->get_option( 'has_inserted_presets' ) ); 83 | $this->assertEmpty( static::$setting->get_list_data( null, false )['data'] ); 84 | static::$app->filter->do_action( 'app_activated' ); 85 | $this->assertNotEmpty( static::$app->get_option( 'has_inserted_presets' ) ); 86 | $list = static::$setting->get_list_data( null, false ); 87 | $this->assertCount( 7, $list['data'] ); 88 | 89 | static::$app->option->delete( 'has_inserted_presets' ); 90 | static::$app->filter->do_action( 'app_activated' ); 91 | $list2 = static::$setting->get_list_data( null, false ); 92 | $this->assertEquals( $list['data'], $list2['data'] ); 93 | 94 | static::reset(); 95 | static::$app->option->set( 'has_inserted_presets', true ); 96 | $this->assertNotEmpty( static::$app->get_option( 'has_inserted_presets' ) ); 97 | $this->assertEmpty( static::$setting->get_list_data( null, false )['data'] ); 98 | static::$app->filter->do_action( 'app_activated' ); 99 | $this->assertNotEmpty( static::$app->get_option( 'has_inserted_presets' ) ); 100 | $this->assertEmpty( static::$setting->get_list_data( null, false )['data'] ); 101 | } 102 | 103 | /** 104 | * @throws ReflectionException 105 | */ 106 | public function test_setup_assets() { 107 | $this->get_output_js(); 108 | $this->get_output_css(); 109 | 110 | global $typenow; 111 | wp_dequeue_style( static::$assets->get_css_handle() ); 112 | $typenow = 'post'; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited 113 | do_action( 'load-edit.php' ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores 114 | $this->assertFalse( wp_style_is( static::$assets->get_css_handle() ) ); 115 | $this->assertEmpty( $this->get_output_js() ); 116 | $this->assertEmpty( $this->get_output_css() ); 117 | 118 | wp_dequeue_style( static::$assets->get_css_handle() ); 119 | $typenow = 'artb-setting'; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited 120 | do_action( 'load-edit.php' ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores 121 | $this->assertTrue( wp_style_is( static::$assets->get_css_handle() ) ); 122 | $this->assertNotEmpty( $this->get_output_js() ); 123 | $this->assertNotEmpty( $this->get_output_css() ); 124 | } 125 | 126 | /** 127 | * @throws ReflectionException 128 | */ 129 | public function test_setup_page() { 130 | $handle = static::$app->get_config( 'config', 'fontawesome_handle' ); 131 | 132 | static::reset(); 133 | static::$app->setting->edit_setting( 'is_valid_fontawesome', 'default', true ); 134 | static::$app->delete_shared_object( '_hook_cache' ); 135 | $this->assertTrue( static::$app->filter->apply_filters( 'is_valid_fontawesome' ) ); 136 | $this->assertFalse( wp_style_is( $handle ) ); 137 | static::$setting->setup_page(); 138 | $this->assertTrue( wp_style_is( $handle ) ); 139 | 140 | static::reset(); 141 | static::$app->setting->edit_setting( 'is_valid_fontawesome', 'default', false ); 142 | static::$app->delete_shared_object( '_hook_cache' ); 143 | $this->assertFalse( static::$app->filter->apply_filters( 'is_valid_fontawesome' ) ); 144 | $this->assertFalse( wp_style_is( $handle ) ); 145 | static::$setting->setup_page(); 146 | $this->assertFalse( wp_style_is( $handle ) ); 147 | } 148 | 149 | /** 150 | * @throws ReflectionException 151 | */ 152 | public function test_output_edit_form() { 153 | static::insert_settings(); 154 | static::$app->setting->edit_setting( 'is_valid_fontawesome', 'default', true ); 155 | static::$app->setting->edit_setting( 'default_group', 'default', null ); 156 | static::$app->delete_shared_object( '_hook_cache' ); 157 | $this->assertTrue( static::$app->filter->apply_filters( 'is_valid_fontawesome' ) ); 158 | $this->assertNull( static::$app->filter->apply_filters( 'default_group' ) ); 159 | ob_start(); 160 | static::$setting->output_edit_form( get_post( 1 ) ); 161 | $contents = ob_get_contents(); 162 | ob_end_clean(); 163 | $this->assertContains( '
', $contents ); 164 | $this->assertContains( 'id="artb-tag_name"', $contents ); 165 | $this->assertContains( 'id="artb-class_name"', $contents ); 166 | $this->assertContains( 'id="artb-group_name"', $contents ); 167 | $this->assertContains( 'id="artb-icon"', $contents ); 168 | $this->assertContains( 'id="artb-style"', $contents ); 169 | $this->assertContains( 'id="artb-is_valid_toolbar_button"', $contents ); 170 | $this->assertContains( 'id="artb-priority"', $contents ); 171 | $this->assertContains( 'preset', $contents ); 172 | $this->assertContains( 'Font Awesome Icons', $contents ); 173 | 174 | static::insert_settings(); 175 | static::$app->setting->edit_setting( 'is_valid_fontawesome', 'default', false ); 176 | static::$app->setting->edit_setting( 'default_group', 'default', 'default_test' ); 177 | static::$app->delete_shared_object( '_hook_cache' ); 178 | $this->assertFalse( static::$app->filter->apply_filters( 'is_valid_fontawesome' ) ); 179 | $this->assertEquals( 'default_test', static::$app->filter->apply_filters( 'default_group' ) ); 180 | ob_start(); 181 | static::$setting->output_edit_form( get_post( 2 ) ); 182 | $contents = ob_get_contents(); 183 | ob_end_clean(); 184 | $this->assertContains( '
', $contents ); 185 | $this->assertNotContains( 'Font Awesome Icons', $contents ); 186 | } 187 | 188 | /** 189 | * @throws ReflectionException 190 | */ 191 | public function test_manage_posts_columns() { 192 | static::insert_settings(); 193 | 194 | $columns = static::$setting->manage_posts_columns( [ 'title' => 'タイトル' ] ); 195 | $this->assertArrayHasKey( 'title', $columns ); 196 | $this->assertArrayHasKey( 'artb-setting-preview', $columns ); 197 | $this->assertArrayHasKey( 'artb-setting-display', $columns ); 198 | $this->assertArrayHasKey( 'artb-setting-is_valid_toolbar_button', $columns ); 199 | $this->assertArrayHasKey( 'artb-setting-priority', $columns ); 200 | $this->assertEquals( 'Setting name', $columns['title'] ); 201 | 202 | ob_start(); 203 | static::$setting->manage_posts_custom_column( 'artb-setting-preview', get_post( 1 ) ); 204 | $contents = ob_get_contents(); 205 | ob_end_clean(); 206 | $this->assertEquals( '', str_replace( [ "\r", "\n" ], '', $contents ) ); 207 | 208 | ob_start(); 209 | static::$setting->manage_posts_custom_column( 'artb-setting-display', get_post( 1 ) ); 210 | $contents = ob_get_contents(); 211 | ob_end_clean(); 212 | $this->assertContains( '', $contents ); 213 | $this->assertContains( '', $contents ); 214 | $this->assertContains( '', $contents ); 215 | $this->assertContains( '', $contents ); 216 | $this->assertContains( '', $contents ); 217 | 218 | ob_start(); 219 | static::$setting->manage_posts_custom_column( 'artb-setting-is_valid_toolbar_button', get_post( 1 ) ); 220 | $contents = ob_get_contents(); 221 | ob_end_clean(); 222 | $this->assertEquals( 'Valid', $contents ); 223 | 224 | ob_start(); 225 | static::$setting->manage_posts_custom_column( 'artb-setting-is_valid_toolbar_button', get_post( 2 ) ); 226 | $contents = ob_get_contents(); 227 | ob_end_clean(); 228 | $this->assertEquals( 'Invalid', $contents ); 229 | 230 | ob_start(); 231 | static::$setting->manage_posts_custom_column( 'artb-setting-priority', get_post( 1 ) ); 232 | $contents = ob_get_contents(); 233 | ob_end_clean(); 234 | $this->assertEquals( '25', $contents ); 235 | } 236 | 237 | public function test_get_error_messages() { 238 | $errors = static::$setting->get_error_messages( 'post_title', [ 'test1', 'test2' ] ); 239 | $this->assertCount( 2, $errors ); 240 | $this->assertEquals( 'test1: [Setting name]', $errors[0] ); 241 | $this->assertEquals( 'test2: [Setting name]', $errors[1] ); 242 | } 243 | 244 | /** 245 | * @dataProvider cache_clear_test_targets 246 | * 247 | * @param Closure $func 248 | * 249 | * @throws ReflectionException 250 | */ 251 | public function test_call_clear_cache_file( $func ) { 252 | $post = get_post( 1 ); 253 | 254 | static::set_property( static::$assets, 'cleared_cache_file', null ); 255 | static::$app->file->put_contents( static::$app->define->upload_dir . DS . 'css' . DS . 'artb.css', '' ); 256 | $this->assertTrue( static::$app->file->upload_file_exists( static::$app, 'css' . DS . 'artb.css' ) ); 257 | $func( $post ); 258 | $this->assertFalse( static::$app->file->upload_file_exists( static::$app, 'css' . DS . 'artb.css' ) ); 259 | } 260 | 261 | /** 262 | * @return array 263 | */ 264 | public function cache_clear_test_targets() { 265 | return [ 266 | [ 267 | function ( $post ) { 268 | static::$setting->data_updated( 1, $post, [], [] ); 269 | }, 270 | ], 271 | [ 272 | function ( $post ) { 273 | static::$setting->data_inserted( 1, $post, [] ); 274 | }, 275 | ], 276 | [ 277 | function ( $post ) { 278 | static::$setting->untrash_post( 1, $post ); 279 | }, 280 | ], 281 | [ 282 | function () { 283 | static::$setting->trash_post( 1 ); 284 | }, 285 | ], 286 | ]; 287 | } 288 | 289 | /** 290 | * @throws ReflectionException 291 | */ 292 | public function test_delete() { 293 | static::insert_settings(); 294 | $this->assertEquals( 1, static::$setting->delete_data( 2 ) ); 295 | } 296 | 297 | /** 298 | * @throws ReflectionException 299 | */ 300 | public function test_get_settings() { 301 | static::insert_settings(); 302 | 303 | static::$app->setting->edit_setting( 'default_group', 'default', null ); 304 | static::$app->delete_shared_object( '_hook_cache' ); 305 | $this->assertNull( static::$app->filter->apply_filters( 'default_group' ) ); 306 | $settings = static::$setting->get_settings( 'editor' ); 307 | $this->assertCount( 4, $settings ); 308 | $this->assertArrayHasKey( 'icon', $settings[0] ); 309 | $this->assertArrayHasKey( 'title', $settings[0] ); 310 | $this->assertArrayHasKey( 'name', $settings[0] ); 311 | $this->assertArrayHasKey( 'selector', $settings[0] ); 312 | $this->assertArrayHasKey( 'tagName', $settings[0] ); 313 | $this->assertArrayHasKey( 'groupName', $settings[0] ); 314 | $this->assertArrayHasKey( 'isValidToolbarButton', $settings[0] ); 315 | $this->assertArrayHasKey( 'isValid', $settings[0] ); 316 | 317 | static::$app->setting->edit_setting( 'default_group', 'default', 'default_test' ); 318 | static::$app->delete_shared_object( '_hook_cache' ); 319 | $this->assertEquals( 'default_test', static::$app->filter->apply_filters( 'default_group' ) ); 320 | $settings = static::$setting->get_settings( 'front' ); 321 | $this->assertCount( 4, $settings ); 322 | $this->assertArrayHasKey( 'icon', $settings[0] ); 323 | $this->assertArrayHasKey( 'title', $settings[0] ); 324 | $this->assertArrayHasKey( 'name', $settings[0] ); 325 | $this->assertArrayHasKey( 'selector', $settings[0] ); 326 | $this->assertArrayHasKey( 'tag_name', $settings[0] ); 327 | $this->assertArrayHasKey( 'group_name', $settings[0] ); 328 | $this->assertArrayHasKey( 'is_valid_toolbar_button', $settings[0] ); 329 | $this->assertArrayHasKey( 'is_valid', $settings[0] ); 330 | } 331 | 332 | public function test_get_valid_post_types() { 333 | $post_types = static::$setting->get_valid_post_types(); 334 | $this->assertContains( 'post', $post_types ); 335 | $this->assertContains( 'page', $post_types ); 336 | $this->assertContains( 'wp_block', $post_types ); 337 | } 338 | 339 | public function test_get_post_type_args() { 340 | $args = static::$setting->get_post_type_args(); 341 | $this->assertEquals( 'Settings', $args['labels']['name'] ); 342 | $this->assertEquals( 'artb-dashboard', $args['show_in_menu'] ); 343 | } 344 | 345 | /** 346 | * @return false|string 347 | * @throws ReflectionException 348 | */ 349 | private function get_output_js() { 350 | ob_start(); 351 | static::$app->minify->output_js( true ); 352 | $contents = ob_get_contents(); 353 | ob_end_clean(); 354 | 355 | static::set_property( static::$app->minify, 'has_output_script', false ); 356 | 357 | return $contents; 358 | } 359 | 360 | /** 361 | * @return false|string 362 | * @throws ReflectionException 363 | */ 364 | private function get_output_css() { 365 | ob_start(); 366 | static::$app->minify->output_css( true ); 367 | $contents = ob_get_contents(); 368 | ob_end_clean(); 369 | 370 | static::set_property( static::$app->minify, 'end_footer', false ); 371 | 372 | return $contents; 373 | } 374 | 375 | /** 376 | * @param $target 377 | * @param $name 378 | * @param $value 379 | * 380 | * @throws ReflectionException 381 | */ 382 | private static function set_property( $target, $name, $value ) { 383 | $reflection = new ReflectionClass( $target ); 384 | $property = $reflection->getProperty( $name ); 385 | $property->setAccessible( true ); 386 | $property->setValue( $target, $value ); 387 | $property->setAccessible( false ); 388 | } 389 | 390 | /** 391 | * @throws ReflectionException 392 | */ 393 | private static function insert_settings() { 394 | static::reset(); 395 | foreach ( 396 | [ 397 | [ 398 | 'post_title' => 'test title1', 399 | 'group_name' => 'test group1', 400 | 'class_name' => 'test1', 401 | 'style' => '', 402 | 'is_valid_toolbar_button' => 1, 403 | 'priority' => 25, 404 | ], 405 | [ 406 | 'post_title' => 'test title2', 407 | 'group_name' => 'test group2', 408 | 'class_name' => 'test2', 409 | 'style' => '', 410 | 'is_valid_toolbar_button' => 0, 411 | 'priority' => 50, 412 | ], 413 | [ 414 | 'post_title' => 'test title3', 415 | 'group_name' => 'test group2', 416 | 'class_name' => 'test3-1 test3-2', 417 | 'style' => '', 418 | 'is_valid_toolbar_button' => 1, 419 | ], 420 | [ 421 | 'post_title' => 'test title4', 422 | 'class_name' => 'test4', 423 | 'style' => '', 424 | 'is_valid_toolbar_button' => 1, 425 | ], 426 | ] as $item 427 | ) { 428 | static::$setting->insert( $item ); 429 | } 430 | } 431 | } 432 | -------------------------------------------------------------------------------- /tests/models/test-assets.php: -------------------------------------------------------------------------------- 1 | get_css_handle() ); 65 | wp_dequeue_style( 'artb-css' ); 66 | 67 | $handle = static::$app->get_config( 'config', 'fontawesome_handle' ); 68 | wp_dequeue_style( $handle ); 69 | static::set_property( static::$setting, 'setup_fontawesome', [] ); 70 | } 71 | 72 | public function test_remove_setting() { 73 | $this->assertEquals( false, static::$app->setting->is_setting_removed( 'assets_version' ) ); 74 | static::$app->filter->do_action( 'post_load_admin_page' ); 75 | $this->assertEquals( true, static::$app->setting->is_setting_removed( 'assets_version' ) ); 76 | } 77 | 78 | public function test_setup_assets() { 79 | wp_dequeue_style( static::$assets->get_css_handle() ); 80 | $this->assertFalse( wp_style_is( static::$assets->get_css_handle() ) ); 81 | 82 | static::$app->setting->edit_setting( 'is_valid', 'default', false ); 83 | static::$app->delete_shared_object( '_hook_cache' ); 84 | $this->assertFalse( static::$app->filter->apply_filters( 'is_valid' ) ); 85 | ob_start(); 86 | do_action( 'wp_head' ); 87 | ob_end_clean(); 88 | $this->assertFalse( wp_style_is( static::$assets->get_css_handle() ) ); 89 | 90 | static::$app->setting->edit_setting( 'is_valid', 'default', true ); 91 | static::$app->delete_shared_object( '_hook_cache' ); 92 | $this->assertTrue( static::$app->filter->apply_filters( 'is_valid' ) ); 93 | ob_start(); 94 | do_action( 'wp_head' ); 95 | ob_end_clean(); 96 | $this->assertTrue( wp_style_is( static::$assets->get_css_handle() ) ); 97 | } 98 | 99 | /** 100 | * @throws Exception 101 | */ 102 | public function test_changed_option() { 103 | $path = 'css' . DS . 'artb.css'; 104 | static::$app->file->create_upload_file( static::$app, $path, '' ); 105 | $this->assertTrue( static::$app->file->upload_file_exists( static::$app, $path ) ); 106 | 107 | static::set_property( static::$assets, 'cleared_cache_file', null ); 108 | static::$app->filter->do_action( 'changed_option', 'test' ); 109 | $this->assertTrue( static::$app->file->upload_file_exists( static::$app, $path ) ); 110 | 111 | static::set_property( static::$assets, 'cleared_cache_file', null ); 112 | static::$app->filter->do_action( 'changed_option', 'artb/test' ); 113 | $this->assertFalse( static::$app->file->upload_file_exists( static::$app, $path ) ); 114 | } 115 | 116 | /** 117 | * @throws ReflectionException 118 | */ 119 | public function test_enqueue_plugin_assets() { 120 | $handle = static::$app->get_config( 'config', 'fontawesome_handle' ); 121 | 122 | static::reset(); 123 | static::$app->setting->edit_setting( 'is_valid_fontawesome', 'default', true ); 124 | static::$app->delete_shared_object( '_hook_cache' ); 125 | $this->assertTrue( static::$app->filter->apply_filters( 'is_valid_fontawesome' ) ); 126 | $this->assertFalse( wp_style_is( 'artb-css' ) ); 127 | $this->assertFalse( wp_style_is( $handle ) ); 128 | static::$assets->enqueue_plugin_assets( true ); 129 | $this->assertTrue( wp_style_is( 'artb-css' ) ); 130 | $this->assertTrue( wp_style_is( $handle ) ); 131 | 132 | static::reset(); 133 | static::$app->setting->edit_setting( 'is_valid_fontawesome', 'default', false ); 134 | static::$app->delete_shared_object( '_hook_cache' ); 135 | $this->assertFalse( static::$app->filter->apply_filters( 'is_valid_fontawesome' ) ); 136 | $this->assertFalse( wp_style_is( 'artb-css' ) ); 137 | $this->assertFalse( wp_style_is( $handle ) ); 138 | static::$assets->enqueue_plugin_assets( true ); 139 | $this->assertTrue( wp_style_is( 'artb-css' ) ); 140 | $this->assertFalse( wp_style_is( $handle ) ); 141 | } 142 | 143 | /** 144 | * @param $target 145 | * @param $name 146 | * @param $value 147 | * 148 | * @throws ReflectionException 149 | */ 150 | private static function set_property( $target, $name, $value ) { 151 | $reflection = new ReflectionClass( $target ); 152 | $property = $reflection->getProperty( $name ); 153 | $property->setAccessible( true ); 154 | $property->setValue( $target, $value ); 155 | $property->setAccessible( false ); 156 | } 157 | } 158 | -------------------------------------------------------------------------------- /tests/models/test-editor.php: -------------------------------------------------------------------------------- 1 | get_css_handle() ); 62 | if ( static::$is_ci ) { 63 | static::$app->file->delete( static::$app->define->plugin_assets_dir . DS . 'js' . DS . 'index.min.js' ); 64 | } 65 | } 66 | 67 | public function test_enqueue_block_editor_assets() { 68 | wp_dequeue_script( 'add-richtext-toolbar-button-editor' ); 69 | wp_dequeue_style( static::$assets->get_css_handle() ); 70 | if ( static::$is_ci ) { 71 | static::$app->file->put_contents( static::$app->define->plugin_assets_dir . DS . 'js' . DS . 'index.min.js', '' ); 72 | } 73 | 74 | static::$app->setting->edit_setting( 'is_valid', 'default', false ); 75 | static::$app->delete_shared_object( '_hook_cache' ); 76 | $this->assertFalse( static::$app->filter->apply_filters( 'is_valid' ) ); 77 | do_action( 'enqueue_block_editor_assets' ); 78 | $this->assertFalse( wp_script_is( 'add-richtext-toolbar-button-editor' ) ); 79 | $this->assertFalse( wp_style_is( static::$assets->get_css_handle() ) ); 80 | 81 | static::$app->setting->edit_setting( 'is_valid', 'default', true ); 82 | static::$app->delete_shared_object( '_hook_cache' ); 83 | $this->assertTrue( static::$app->filter->apply_filters( 'is_valid' ) ); 84 | do_action( 'enqueue_block_editor_assets' ); 85 | $this->assertTrue( wp_script_is( 'add-richtext-toolbar-button-editor' ) ); 86 | $this->assertTrue( wp_style_is( static::$assets->get_css_handle() ) ); 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /tests/models/test-style.php: -------------------------------------------------------------------------------- 1 | assertEquals( $expected, static::$style->encode_style( $style ) ); 49 | } 50 | 51 | public function encode_style_data_provider() { 52 | return [ 53 | [ 54 | '[]', 55 | '', 56 | ], 57 | [ 58 | '[]', 59 | null, 60 | ], 61 | [ 62 | '{"":["background-image: linear-gradient(to bottom, rgba(255, 255, 255, 0) 60%, #f69 75%);","font-weight: bold;"]}', 63 | 'background-image: linear-gradient(to bottom, rgba(255, 255, 255, 0) 60%, #f69 75%); 64 | font-weight: bold;', 65 | ], 66 | [ 67 | '{"":["font-weight: bold;","color: red;"]}', 68 | '!#$%&"abc: linear-gradient(to bottom, rgba(255, 255, 255, 0) 60%, #f69 75%); 69 | font-weight: bold;;;color: red', 70 | ], 71 | [ 72 | '{"":["padding: 6px;"],"after":["color: red;"],"before":["font-weight: bold;","display: block;"]}', 73 | '!#$%&"abc: linear-gradient(to bottom, rgba(255, 255, 255, 0) 60%, #f69 75%); 74 | [before]font-weight: bold;;;[after]color: red 75 | [before]display:block 76 | padding: 6px 77 | [after]color: red', 78 | ], 79 | ]; 80 | } 81 | 82 | /** 83 | * @dataProvider decode_style_data_provider 84 | * 85 | * @param $expected 86 | * @param $style 87 | * @param $is_editor 88 | */ 89 | public function test_decode_style( $expected, $style, $is_editor ) { 90 | $this->assertEquals( $expected, static::$style->decode_style( $style, $is_editor ) ); 91 | } 92 | 93 | public function decode_style_data_provider() { 94 | return [ 95 | [ 96 | [], 97 | '', 98 | false, 99 | ], 100 | [ 101 | [ '' => [ 'padding: 6px;' ] ], 102 | '{"":["padding: 6px;"]}', 103 | false, 104 | ], 105 | [ 106 | "padding: 6px;\r\n", 107 | '{"":["padding: 6px;"]}', 108 | true, 109 | ], 110 | [ 111 | "padding: 6px\r\n\r\n[after] color: red;\r\n\r\n[before] font-weight: bold\r\n[before] display: block;\r\n", 112 | '{"":["padding: 6px"],"after":["color: red;"],"before":["font-weight: bold","display: block;"]}', 113 | true, 114 | ], 115 | ]; 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /tests/models/test-validation.php: -------------------------------------------------------------------------------- 1 | insert( $item ); 56 | } 57 | 58 | public static function tearDownAfterClass() { 59 | static::reset(); 60 | } 61 | 62 | private static function reset() { 63 | static::$app->db->table( 'setting' )->truncate(); 64 | static::$app->db->wp_table( 'posts' )->truncate(); 65 | } 66 | 67 | /** 68 | * @dataProvider validate_class_name_data_provider 69 | * 70 | * @param $class_name 71 | * @param $priority 72 | * @param $post_array 73 | * @param $errors 74 | * @param $callback 75 | */ 76 | public function test_validate_class_name( $class_name, $priority, $post_array, $errors, $callback ) { 77 | $errors = static::$validation->validate_class_name( $class_name, $priority, $post_array, $errors ); 78 | $callback( $errors ); 79 | } 80 | 81 | public function validate_class_name_data_provider() { 82 | return [ 83 | [ 84 | 'artb-test', 85 | 10, 86 | [], 87 | [], 88 | function ( $errors ) { 89 | $this->assertArrayHasKey( 'class_name', $errors ); 90 | $this->assertCount( 1, $errors['class_name'] ); 91 | $this->assertContains( static::$validation->translate( 'The value is unusable.' ), $errors['class_name'] ); 92 | }, 93 | ], 94 | [ 95 | '0abc', 96 | 10, 97 | [], 98 | [ 'class_name' => [ 'a' ] ], 99 | function ( $errors ) { 100 | $this->assertArrayHasKey( 'class_name', $errors ); 101 | $this->assertCount( 3, $errors['class_name'] ); 102 | $this->assertContains( 'a', $errors['class_name'] ); 103 | $this->assertContains( static::$validation->translate( 'Invalid format.' ), $errors['class_name'] ); 104 | $this->assertContains( static::$validation->translate( 'A class name must begin with a letter, followed by any number of hyphens, letters, or numbers.' ), $errors['class_name'] ); 105 | }, 106 | ], 107 | [ 108 | 'test', 109 | 10, 110 | [], 111 | [], 112 | function ( $errors ) { 113 | $this->assertArrayHasKey( 'class_name', $errors ); 114 | $this->assertCount( 1, $errors['class_name'] ); 115 | $this->assertContains( static::$validation->translate( 'The value has already been used.' ), $errors['class_name'] ); 116 | }, 117 | ], 118 | [ 119 | 'test test2', 120 | 100, 121 | [ 'ID' => 0 ], 122 | [], 123 | function ( $errors ) { 124 | $this->assertArrayHasKey( 'class_name', $errors ); 125 | $this->assertCount( 1, $errors['class_name'] ); 126 | $this->assertContains( static::$validation->translate( 'The value is included in the class name of other settings.' ), $errors['class_name'] ); 127 | }, 128 | ], 129 | [ 130 | 'test test2', 131 | 10, 132 | [ 'ID' => 0 ], 133 | [], 134 | function ( $errors ) { 135 | $this->assertEmpty( $errors ); 136 | }, 137 | ], 138 | [ 139 | 'test test2', 140 | 100, 141 | [ 'ID' => 1 ], 142 | [], 143 | function ( $errors ) { 144 | $this->assertEmpty( $errors ); 145 | }, 146 | ], 147 | ]; 148 | } 149 | 150 | /** 151 | * @dataProvider validate_tag_name_data_provider 152 | * 153 | * @param $tag_name 154 | * @param $errors 155 | * @param $callback 156 | */ 157 | public function test_validate_tag_name( $tag_name, $errors, $callback ) { 158 | $errors = static::$validation->validate_tag_name( $tag_name, $errors ); 159 | $callback( $errors ); 160 | } 161 | 162 | public function validate_tag_name_data_provider() { 163 | return [ 164 | [ 165 | 'div', 166 | [], 167 | function ( $errors ) { 168 | $this->assertArrayHasKey( 'tag_name', $errors ); 169 | $this->assertCount( 1, $errors['tag_name'] ); 170 | $this->assertContains( static::$validation->translate( 'This tag name is unusable.' ), $errors['tag_name'] ); 171 | }, 172 | ], 173 | [ 174 | '0abc', 175 | [ 'tag_name' => [ 'a' ] ], 176 | function ( $errors ) { 177 | $this->assertArrayHasKey( 'tag_name', $errors ); 178 | $this->assertCount( 2, $errors['tag_name'] ); 179 | $this->assertContains( 'a', $errors['tag_name'] ); 180 | $this->assertContains( static::$validation->translate( 'Invalid format.' ), $errors['tag_name'] ); 181 | }, 182 | ], 183 | ]; 184 | } 185 | } 186 | --------------------------------------------------------------------------------
tag nameclass namegroup nameicon