Exemplo n.º 1
0
 public function __construct($post = null)
 {
     $this->initial = true;
     if ($post) {
         $this->initial = false;
         $this->id = $post->id;
         $this->url = $post->url;
         $this->referrer = $post->referrer;
         $this->alternative_keyword = $post->alternative_keyword;
         $latest = fortyfourwp_get_data(array('fields' => array('redirect_url'), 'where' => 'url', 'keyword' => $post->url, 'orderby' => 'access_date', 'order' => 'desc', 'items' => 1));
         $this->redirect_url = isset($latest[0]->redirect_url) ? $latest[0]->redirect_url : '';
         $this->ip = $post->ip;
         $this->access_date = $post->access_date;
         $this->total = $post->total;
         // $this->status = ('1' == $post->review_approved) ? 'approved' : 'unapproved';
     }
 }
Exemplo n.º 2
0
 function fortyfourwp_init()
 {
     if (is_404() && !current_user_can('manage_options')) {
         global $wpdb;
         global $fortyfourwp;
         $data = array();
         $data['referer'] = wp_get_referer();
         $data['path'] = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
         $data['ip'] = $_SERVER["REMOTE_ADDR"];
         //get redirect if available
         $a = fortyfourwp_get_data(array('fields' => array('redirect_url', 'redirect_type'), 'where' => 'url', 'keyword' => $data['path'], 'orderby' => 'access_date', 'order' => 'desc', 'items' => 1, 'select_type' => 'search'));
         //save data
         $data['id'] = fortyfourwp_insert_data(array('id' => '', 'url' => $data['path'], 'referrer' => $data['referer'], 'ip' => $data['ip'], 'user_agent' => isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : ''));
         $fortyfourwp = json_encode($data);
         //redirect
         if (isset($a[0]->redirect_url) && !empty($a[0]->redirect_url)) {
             fortyfourwp_update_data($data['id'], $data = array('redirect_url' => $a[0]->redirect_url, 'redirect_type' => $a[0]->redirect_type));
             wp_redirect($a[0]->redirect_url, $a[0]->redirect_type);
             exit;
             // header('Location:'. $a[0]->redirect_url);
         }
     }
 }
Exemplo n.º 3
0
 function fortyfourwp_delete_data($data_id, $type = '')
 {
     global $wpdb;
     $sql = '';
     switch ($type) {
         case 'url':
             //Delete Logs per Url
             $data_id = absint($data_id);
             if (empty($data_id)) {
                 return false;
             }
             $data = fortyfourwp_get_data(array('fields' => array('url'), 'where' => 'id', 'keyword' => $data_id, 'items' => 1));
             if (isset($data[0]->url) && !empty($data[0]->url)) {
                 $sql = $wpdb->prepare("DELETE from {$wpdb->fortyfour_logs} WHERE url = '%s'", $data[0]->url);
             }
             break;
         default:
             //Log ID must be positive integer
             $data_id = absint($data_id);
             if (empty($data_id)) {
                 return false;
             }
             do_action('fortyfourwp_delete_data', $data_id);
             $sql = $wpdb->prepare("DELETE from {$wpdb->fortyfour_logs} WHERE id = %d", $data_id);
             break;
     }
     if (!$wpdb->query($sql)) {
         return false;
     }
     // do_action('fortyfourwp_deleted_log',$data_id);
     return true;
 }
Exemplo n.º 4
0
    function fortyfourwp_ajax()
    {
        $id = intval(sanitize_text_field($_REQUEST['id']));
        $type = sanitize_text_field($_REQUEST['type']);
        $visits = array();
        $referrers = array();
        $keywords = array();
        $views = 0;
        $total_visits = 1;
        if (!empty($id)) {
            ob_start();
            ?>
	    <div class="fortyfourwp_tb">
	    <?php 
            switch ($type) {
                case 'edit':
                    //get data from table by ID selected
                    $data = fortyfourwp_get_data(array('fields' => array('url', 'referrer', 'alternative_keyword', 'redirect_url', 'access_date'), 'where' => 'id', 'keyword' => $id, 'items' => 1));
                    if (isset($data[0]->url) && !empty($data[0]->url)) {
                        //get total visits
                        $total_visits = fortyfourwp_get_data(array('fields' => 'count', 'where' => 'url', 'keyword' => $data[0]->url));
                        //get latest redirect url
                        $redirect_latest = fortyfourwp_get_data(array('fields' => array('redirect_url', 'redirect_type'), 'where' => 'url', 'keyword' => $data[0]->url, 'orderby' => 'access_date', 'order' => 'desc', 'items' => 1, 'select_type' => 'search'));
                    }
                    ?>
			<br />
			<span class="fortyfourwp-total-visits"><?php 
                    _e('Total Visits: ', 'forty-four');
                    echo '<span>' . $total_visits . '</span>';
                    ?>
</span>
	        <table class="form-table fortyfourwp-stats-head">
    			<tbody>
	    			<tr valign="top">
	    				<td colspan="2">
	              			<input type="text" class="widefat fortyfourwp-v-url" data-url="<?php 
                    echo $data[0]->url;
                    ?>
" readonly="readonly" value="<?php 
                    echo isset($data[0]->url) ? esc_url(home_url($data[0]->url)) : '';
                    ?>
" />
	    				</td>
						<td class="gotolink"><a href="<?php 
                    echo isset($data[0]->url) ? esc_url(home_url($data[0]->url)) : '';
                    ?>
" target="_blank"><?php 
                    _e('Go to Link', 'forty-four');
                    ?>
</a></td>
	    			</tr>
					<tr valign="top" class="fortyfourwp_add-redirect">
	    				<td>
	              			<input type="text" id="fortyfourwp-redirect-url" class="widefat" readonly="readonly" value="<?php 
                    echo isset($redirect_latest[0]->redirect_url) ? $redirect_latest[0]->redirect_url : '';
                    ?>
" />
	              			<input type="hidden" id="fortyfourwp-redirect-id" value="<?php 
                    echo isset($id) ? $id : '';
                    ?>
" />
	    				</td>
						<td class="fortyfourwp-redirect">
							<span>
								<?php 
                    if (isset($redirect_latest[0]->redirect_type) && !empty($redirect_latest[0]->redirect_type)) {
                        echo '<i>' . $redirect_latest[0]->redirect_type . '</i> ' . __('Redirect', 'forty-four');
                    } else {
                        _e('<i>no</i> Redirect', 'forty-four');
                    }
                    ?>
							</span>
	              			<select class="fortyfourwp-redirect-type" id="fortyfourwp-redirect-type">
								<option value="301" <?php 
                    if (isset($redirect_latest[0]) && isset($redirect_latest[0]->redirect_type) && $redirect_latest[0]->redirect_type == '301') {
                        echo 'selected="selected"';
                    }
                    ?>
 ><?php 
                    _e('301 Redirect(SEO)', 'forty-four');
                    ?>
</option>
								<option value="302" <?php 
                    if (isset($redirect_latest[0]) && isset($redirect_latest[0]->redirect_type) && $redirect_latest[0]->redirect_type == '302') {
                        echo 'selected="selected"';
                    }
                    ?>
><?php 
                    _e('302 Redirect', 'forty-four');
                    ?>
</option>
								<option value="307" <?php 
                    if (isset($redirect_latest[0]) && isset($redirect_latest[0]->redirect_type) && $redirect_latest[0]->redirect_type == '307') {
                        echo 'selected="selected"';
                    }
                    ?>
><?php 
                    _e('307 Redirect', 'forty-four');
                    ?>
</option>
							</select>
	    				</td>
						<td class="gotolink"><a href="#"><span class="fortyfourwp-add"><?php 
                    _e('Add/Edit Redirect', 'forty-four');
                    ?>
</span><span class="fortyfourwp-save"><?php 
                    _e('Save Redirect', 'forty-four');
                    ?>
</span></a></td>
	    			</tr>
    			</tbody>
    		</table>

	        <?php 
                    break;
                default:
                    # code...
                    break;
            }
            ?>
	    </div>
	    <?php 
            echo ob_get_clean();
        }
        die;
    }