PluginProbe ʕ •ᴥ•ʔ
پارسی دیت – Parsi Date / trunk
پارسی دیت – Parsi Date vtrunk
6.2.1 6.2 6.1 5.1.6 5.1.7 5.1.8 5.1.8.2 6.0 trunk 1.0 1.1 1.2 1.3 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 2.0.0-alpha 2.1 2.1.1 2.1.2 2.1.3 2.1.5 2.1.6 2.1.7 2.2.0 2.2.1 2.2.2 2.2.3 2.3.0.1 2.3.0.2 2.3.1 2.3.2 2.3.3 2.3.4 3.0.1 3.0.2 3.0.3 4.0.0 4.0.1 4.0.2 5.1.0 5.1.1 5.1.2 5.1.3 5.1.4 5.1.5
wp-parsidate / inc / Helper / Helper.php
wp-parsidate / inc / Helper Last commit date
Assets.php 1 month ago Cache.php 2 months ago Date.php 1 month ago Debug.php 1 month ago FeedReader.php 1 month ago HTML.php 1 month ago Helper.php 2 months ago JSON.php 2 months ago Nonce.php 2 months ago Notice.php 1 month ago Number.php 2 months ago NumberConverter.php 1 month ago Param.php 2 months ago Sanitizing.php 1 month ago Strip.php 2 months ago Templates.php 2 months ago User.php 2 months ago Validating.php 2 months ago WooCommerce.php 2 months ago WordPress.php 1 month ago
Helper.php
106 lines
1 <?php
2
3 namespace WPParsidate\Helper;
4
5 class Helper {
6 /**
7 * Reorder array list
8 *
9 * @param array $array Input array
10 * @param array $orders Order number lists
11 *
12 * @return array|false Reordered array
13 */
14 public static function reorderArray( $array, $orders ) {
15 $reorderArray = [];
16 $orders = array_map( 'intval', $orders );
17
18 if ( count( array_unique( array_keys( $orders ) ) ) !== count( array_unique( array_values( $orders ) ) ) ) {
19 return false;
20 }
21
22 foreach ( $orders as $index => $order ) {
23 $reorderArray[ $order ] = $array[ $index ];
24 }
25
26 ksort( $reorderArray );
27
28 return $reorderArray;
29 }
30
31 /**
32 * Random string
33 *
34 * @param int $length String length
35 * @param bool $smallAlphabet Use small alphabet
36 * @param bool $largeAlphabet Use large alphabet
37 * @param bool $numbers Use numbers
38 *
39 * @return false|string Random string, Otherwise return false if empty
40 */
41 public static function randomString( $length, $smallAlphabet = true, $largeAlphabet = true, $numbers = true ) {
42 $strings = [];
43 if ( $smallAlphabet ) {
44 $strings = array_merge( $strings, range( 'a', 'z' ) );
45 }
46 if ( $largeAlphabet ) {
47 $strings = array_merge( $strings, range( 'A', 'Z' ) );
48 }
49 if ( $numbers ) {
50 $strings = array_merge( $strings, range( 1, 9 ) );
51 }
52
53 if ( empty( $strings ) ) {
54 return false;
55 }
56
57 shuffle( $strings );
58
59 $strings = implode( "", $strings );
60
61 return substr( str_shuffle( $strings ), 0, $length );
62 }
63
64 /**
65 * Inserts any number of scalars or arrays at the point
66 * in the haystack immediately after the search key ($needle) was found,
67 * or at the end if the needle is not found or not supplied.
68 * Modifies $haystack in place.
69 * https://stackoverflow.com/a/7257599/3224296
70 *
71 * @param array &$haystack the associative array to search. This will be modified by the function
72 * @param int $needle the key to search for
73 * @param array $stuff one or more arrays or scalars to be inserted into $haystack
74 *
75 * @return array the index at which $needle was found
76 */
77 public static function arrayInsertAfter( array $haystack, int $needle = 0, array $stuff = [] ): array {
78 return array_merge( array_slice( $haystack, 0, $needle, true ), $stuff,
79 array_slice( $haystack, $needle, count( $haystack ) - 1, true ) );
80 }
81
82 /**
83 * URL to key
84 * Use for cache base on url string
85 *
86 * @param string $url
87 * @param bool $hostOnly
88 *
89 * @return false|string Key string, if url isn't valid return false
90 */
91 public static function urlToKey( string $url, $hostOnly = false ) {
92 if ( Validating::isUrl( $url ) ) {
93 if ( $hostOnly ) {
94 $url = wp_parse_url( $url, PHP_URL_HOST );
95 } else {
96 $url = wp_parse_url( $url, PHP_URL_HOST ) . wp_parse_url( $url, PHP_URL_PATH );
97 $url = trim( $url, '/' );
98 }
99
100 return Sanitizing::title( $url );
101 }
102
103 return false;
104 }
105 }
106