ThemeAvenue /
BetterOptin
This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | /** |
||
| 3 | * Define vars |
||
| 4 | */ |
||
| 5 | $datas = array(); |
||
| 6 | $seen = array(); |
||
| 7 | $query = array( 'data_type' => 'any', 'limit' => -1 ); |
||
| 8 | |||
| 9 | /* Select a specific popup */ |
||
| 10 | if( 'all' != $show ) { |
||
| 11 | $query['popup_id'] = intval( $show ); |
||
| 12 | } |
||
| 13 | |||
| 14 | switch( $period ) { |
||
| 15 | |||
| 16 | case 'today': |
||
| 17 | $timeframe = strtotime( 'today' ); |
||
| 18 | break; |
||
| 19 | |||
| 20 | case 'this_week': |
||
| 21 | |||
| 22 | $timeframe = array( |
||
| 23 | 'from' => strtotime( 'last monday', time() ), |
||
| 24 | 'to' => strtotime( 'next sunday', time() ) |
||
| 25 | ); |
||
| 26 | |||
| 27 | break; |
||
| 28 | |||
| 29 | case 'last_week': |
||
| 30 | |||
| 31 | $timeframe = array( |
||
| 32 | 'from' => strtotime( 'last monday -1 week' ), |
||
| 33 | 'to' => strtotime( 'next sunday -1 week' ) |
||
| 34 | ); |
||
| 35 | |||
| 36 | break; |
||
| 37 | |||
| 38 | case 'this_month': |
||
| 39 | |||
| 40 | $timeframe = array( |
||
| 41 | 'from' => strtotime( 'first day of this month', time() ), |
||
| 42 | 'to' => strtotime( 'last day of this month', time() ) |
||
| 43 | ); |
||
| 44 | |||
| 45 | break; |
||
| 46 | |||
| 47 | case 'last_month': |
||
| 48 | |||
| 49 | $timeframe = array( |
||
| 50 | 'from' => strtotime( 'first day of last month', time() ), |
||
| 51 | 'to' => strtotime( 'last day of last month', time() ) |
||
| 52 | ); |
||
| 53 | |||
| 54 | break; |
||
| 55 | |||
| 56 | case 'this_quarter': |
||
| 57 | |||
| 58 | $quarters = array( 1, 4, 7, 10 ); |
||
| 59 | $month = intval( date( 'm' ) ); |
||
| 60 | |||
| 61 | View Code Duplication | if( in_array( $month, $quarters ) ) { |
|
|
0 ignored issues
–
show
|
|||
| 62 | $current = date( 'Y-m-d', time() ); |
||
| 63 | } else { |
||
| 64 | |||
| 65 | /* Get first month of this quarter */ |
||
| 66 | while( !in_array( $month, $quarters) ) { |
||
| 67 | $month = $month-1; |
||
| 68 | } |
||
| 69 | |||
| 70 | $current = date( 'Y' ) . '-' . $month . '-' . '01'; |
||
| 71 | |||
| 72 | } |
||
| 73 | |||
| 74 | $current = strtotime( $current ); |
||
| 75 | |||
| 76 | $timeframe = array( |
||
| 77 | 'from' => strtotime( 'first day of this month', $current ), |
||
| 78 | 'to' => strtotime( 'last day of this month', strtotime( '+2 months', $current ) ) |
||
| 79 | ); |
||
| 80 | |||
| 81 | break; |
||
| 82 | |||
| 83 | case 'last_quarter': |
||
| 84 | |||
| 85 | $quarters = array( 1, 4, 7, 10 ); |
||
| 86 | $month = intval( date( 'm' ) ) - 3; |
||
| 87 | $rewind = false; |
||
| 88 | |||
| 89 | View Code Duplication | if( in_array( $month, $quarters ) ) { |
|
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. Loading history...
|
|||
| 90 | $current = date( 'Y-m-d', time() ); |
||
| 91 | } else { |
||
| 92 | |||
| 93 | /* Get first month of this quarter */ |
||
| 94 | while( !in_array( $month, $quarters) ) { |
||
| 95 | |||
| 96 | $month = $month-1; |
||
| 97 | |||
| 98 | /* Rewind to last year after we passed January */ |
||
| 99 | if( 0 === $month ) |
||
| 100 | $month = 12; |
||
| 101 | } |
||
| 102 | |||
| 103 | $current = date( 'Y' ) . '-' . $month . '-' . '01'; |
||
| 104 | |||
| 105 | } |
||
| 106 | |||
| 107 | /* Set the theorical current date */ |
||
| 108 | $current = false === $rewind ? strtotime( $current ) : strtotime( '-1 year', $current ); |
||
| 109 | |||
| 110 | $timeframe = array( |
||
| 111 | 'from' => strtotime( 'first day of this month', $current ), |
||
| 112 | 'to' => strtotime( 'last day of this month', strtotime( '+2 months', $current ) ) |
||
| 113 | ); |
||
| 114 | |||
| 115 | break; |
||
| 116 | |||
| 117 | case 'this_year': |
||
| 118 | |||
| 119 | $timeframe = array( |
||
| 120 | 'from' => strtotime( 'first day of January', time() ), |
||
| 121 | 'to' => strtotime( 'last day of December', time() ) |
||
| 122 | ); |
||
| 123 | |||
| 124 | break; |
||
| 125 | |||
| 126 | case 'last_year': |
||
| 127 | |||
| 128 | $timeframe = array( |
||
| 129 | 'from' => strtotime( 'first day of January last year', time() ), |
||
| 130 | 'to' => strtotime( 'last day of December last year', time() ) |
||
| 131 | ); |
||
| 132 | |||
| 133 | break; |
||
| 134 | |||
| 135 | } |
||
| 136 | |||
| 137 | /* Set the period */ |
||
| 138 | $query['period'] = $timeframe; |
||
| 139 | |||
| 140 | /* Get the datas */ |
||
| 141 | $datas = wpbo_db_get_datas( $query, 'OBJECT' ); |
||
| 142 | ?> |
||
| 143 | <div class="postbox"> |
||
| 144 | |||
| 145 | <!-- <h3><span>Conversion Statistics per Popup</span></h3> --> |
||
| 146 | <div class="inside-no-padding"> |
||
| 147 | |||
| 148 | <table class="form-table" id="wpbo-stats-general" data-timeframe="<?php echo htmlspecialchars( serialize( $timeframe ) ); ?>" data-popup="<?php echo $show; ?>" data-period="<?php echo $period; ?>"> |
||
| 149 | <thead> |
||
| 150 | <tr> |
||
| 151 | <th class="row-title"><?php _e( 'Popup Name', 'betteroptin' ); ?></th> |
||
| 152 | <th><?php _e( 'Impressions', 'betteroptin' ); ?></th> |
||
| 153 | <th><?php _e( 'Conversions', 'betteroptin' ); ?></th> |
||
| 154 | <th><?php _e( '% Conversion', 'betteroptin' ); ?></th> |
||
| 155 | <th><?php _e( 'Status', 'betteroptin' ); ?></th> |
||
| 156 | <th data-bSortable="false"><?php _e( 'Settings', 'betteroptin' ); ?></th> |
||
| 157 | </tr> |
||
| 158 | </thead> |
||
| 159 | <tbody> |
||
| 160 | <?php |
||
| 161 | if( is_array( $datas ) ) { |
||
| 162 | |||
| 163 | foreach( $datas as $key => $data ) { |
||
| 164 | |||
| 165 | if( in_array( $data->popup_id, $seen ) ) |
||
| 166 | continue; |
||
| 167 | |||
| 168 | /* Mark this popup as parsed */ |
||
| 169 | array_push( $seen, $data->popup_id ); |
||
| 170 | |||
| 171 | $popup = get_post( $data->popup_id ); |
||
| 172 | $impressions = wpbo_db_get_datas( array( 'popup_id' => $data->popup_id, 'data_type' => 'impression', 'limit' => -1, 'period' => $timeframe ), 'ARRAY_A' ); |
||
| 173 | $conversions = wpbo_db_get_datas( array( 'popup_id' => $data->popup_id, 'data_type' => 'conversion', 'limit' => -1, 'period' => $timeframe ), 'ARRAY_A' ); |
||
| 174 | $rate = ( 0 === count( $conversions ) || 0 === count( $impressions ) ) ? 0 : ( 100 * count( $conversions ) ) / count( $impressions ); |
||
| 175 | $status = 'publish' == $popup->post_status ? __( 'Active', 'betteroptin' ) : __( 'Inactive', 'betteroptin' ); |
||
| 176 | $status_class = 'publish' == $popup->post_status ? 'wpbo-stats-active' : 'wpbo-stats-inactive'; |
||
| 177 | |||
| 178 | /* Increment the global vars */ |
||
| 179 | $total_impressions = $total_impressions + count( $impressions ); |
||
| 180 | $total_conversions = $total_conversions + count( $conversions ); |
||
| 181 | ?> |
||
| 182 | |||
| 183 | <tr valign="top"> |
||
| 184 | <td scope="row"><a href="<?php echo add_query_arg( array( 'post' => $data->popup_id, 'action' => 'edit' ), admin_url( 'post.php' ) ); ?>"><?php echo $popup->post_title; ?></a> <em>(#<?php echo $data->popup_id; ?>)</em></td> |
||
| 185 | <td><?php echo number_format( count( $impressions ), 0 ); ?></td> |
||
| 186 | <td><?php echo number_format( count( $conversions ), 0 ); ?></td> |
||
| 187 | <td><?php echo number_format( $rate, 2 ); ?>% <!-- <span class="wpbo-stats-variation">▼</span> --></td> |
||
| 188 | <td><span class="<?php echo $status_class; ?>"><?php echo $status; ?></span></td> |
||
| 189 | <td><a href="<?php echo add_query_arg( array( 'post' => $data->popup_id, 'action' => 'edit' ), admin_url( 'post.php' ) ); ?>" class="button-secondary"><?php _e( 'Settings', 'betteroptin' ); ?></a></td> |
||
| 190 | </tr> |
||
| 191 | |||
| 192 | <?php } |
||
| 193 | |||
| 194 | } |
||
| 195 | ?> |
||
| 196 | </tbody> |
||
| 197 | </table> |
||
| 198 | </div> <!-- .inside --> |
||
| 199 | </div> <!-- .postbox --> |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.