Changeset 1329069
- Timestamp:
- 01/15/2016 03:22:32 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
quick-pagepost-redirect-plugin/trunk/page_post_redirect_plugin.php
r1283538 r1329069 1501 1501 1502 1502 function ppr_parse_request_new($wp) { 1503 global $wp, $wpdb; 1504 $this->ppr_all_redir_array = $this->get_main_array(); 1505 $this->pprptypes_ok = get_option( 'ppr_qpprptypeok', array() ); 1506 if ( isset( $_GET['action'] ) && $_GET['action'] == 'export-quick-redirects-file' ) { 1507 $newQPPR_Array = array(); 1508 check_admin_referer( 'export-redirects-qppr' ); 1509 $type = isset( $_GET['qppr-file-type'] ) && sanitize_text_field( $_GET['qppr-file-type'] ) == 'encoded' ? 'encoded' : 'pipe' ; // can be 'encoded' or 'pipe'; 1510 header( 'Expires: Sat, 26 Jul 1997 05:00:00 GMT' ); 1511 header( 'Last-Modified: ' . gmdate( 'D, d M Y H:i:s' ) . ' GMT' ); 1512 header( 'Cache-Control: no-store, no-cache, must-revalidate' ); 1513 header( 'Cache-Control: post-check=0, pre-check=0', false ); 1514 header( 'Pragma: no-cache' ); 1515 header( "Content-Type: application/force-download" ); 1516 header( "Content-Type: application/octet-stream" ); 1517 header( "Content-Type: application/download" ); 1518 header( "Content-Disposition: attachment; filename=qppr-quick-redirects-export-" . date('U') . ".txt;" ); 1519 $newQPPR_Array['quickppr_redirects'] = get_option( 'quickppr_redirects', array() ); 1520 $newQPPR_Array['quickppr_redirects_meta'] = get_option( 'quickppr_redirects_meta', array() ); 1521 if( $type == 'encoded' ){ 1522 die( 'QUICKPAGEPOSTREDIRECT' . base64_encode( serialize( $newQPPR_Array ) ) ); 1523 }else{ 1524 if( is_array( $newQPPR_Array ) ){ 1525 $qpprs = $newQPPR_Array['quickppr_redirects']; 1526 $qpprm = $newQPPR_Array['quickppr_redirects_meta']; 1527 foreach($qpprs as $key=>$val){ 1528 $nw = ( isset( $qpprm[$key]['newwindow'] ) && $qpprm[$key]['newwindow'] == '1' ) ? $qpprm[$key]['newwindow'] : '0' ; 1529 $nf = ( isset( $qpprm[$key]['nofollow'] ) && $qpprm[$key]['nofollow'] == '1' ) ? $qpprm[$key]['nofollow'] : '0' ; 1530 $temps = str_replace( '|', '%7C', $key ) . '|' . str_replace( '|', '%7C', $val ) . '|' . $nw . '|' . $nf; 1531 if($temps!='|||'){ 1532 $newline[] = $temps; 1503 if( current_user_can( 'manage_options' ) ){ 1504 global $wp, $wpdb; 1505 $this->ppr_all_redir_array = $this->get_main_array(); 1506 $this->pprptypes_ok = get_option( 'ppr_qpprptypeok', array() ); 1507 if ( isset( $_GET['action'] ) && $_GET['action'] == 'export-quick-redirects-file' ) { 1508 $newQPPR_Array = array(); 1509 check_admin_referer( 'export-redirects-qppr' ); 1510 $type = isset( $_GET['qppr-file-type'] ) && sanitize_text_field( $_GET['qppr-file-type'] ) == 'encoded' ? 'encoded' : 'pipe' ; // can be 'encoded' or 'pipe'; 1511 header( 'Expires: Sat, 26 Jul 1997 05:00:00 GMT' ); 1512 header( 'Last-Modified: ' . gmdate( 'D, d M Y H:i:s' ) . ' GMT' ); 1513 header( 'Cache-Control: no-store, no-cache, must-revalidate' ); 1514 header( 'Cache-Control: post-check=0, pre-check=0', false ); 1515 header( 'Pragma: no-cache' ); 1516 header( "Content-Type: application/force-download" ); 1517 header( "Content-Type: application/octet-stream" ); 1518 header( "Content-Type: application/download" ); 1519 header( "Content-Disposition: attachment; filename=qppr-quick-redirects-export-" . date('U') . ".txt;" ); 1520 $newQPPR_Array['quickppr_redirects'] = get_option( 'quickppr_redirects', array() ); 1521 $newQPPR_Array['quickppr_redirects_meta'] = get_option( 'quickppr_redirects_meta', array() ); 1522 if( $type == 'encoded' ){ 1523 die( 'QUICKPAGEPOSTREDIRECT' . base64_encode( serialize( $newQPPR_Array ) ) ); 1524 }else{ 1525 if( is_array( $newQPPR_Array ) ){ 1526 $qpprs = $newQPPR_Array['quickppr_redirects']; 1527 $qpprm = $newQPPR_Array['quickppr_redirects_meta']; 1528 foreach($qpprs as $key=>$val){ 1529 $nw = ( isset( $qpprm[$key]['newwindow'] ) && $qpprm[$key]['newwindow'] == '1' ) ? $qpprm[$key]['newwindow'] : '0' ; 1530 $nf = ( isset( $qpprm[$key]['nofollow'] ) && $qpprm[$key]['nofollow'] == '1' ) ? $qpprm[$key]['nofollow'] : '0' ; 1531 $temps = str_replace( '|', '%7C', $key ) . '|' . str_replace( '|', '%7C', $val ) . '|' . $nw . '|' . $nf; 1532 if($temps!='|||'){ 1533 $newline[] = $temps; 1534 } 1535 } 1536 $newfile = implode( "\r\n", $newline ); 1537 }else{ 1538 $newfile = $newtext; 1539 } 1540 die( $newfile ); 1541 } 1542 exit; 1543 } elseif( isset( $_POST['import-quick-redrects-file'] ) && isset( $_FILES['qppr_file'] ) ) { 1544 check_admin_referer( 'import-quick-redrects-file' ); 1545 if ( $_FILES['qppr_file']['error'] > 0 ) { 1546 wp_die( __( 'An error occured during the file upload. Please fix your server configuration and retry.', 'quick-pagepost-redirect-plugin' ) , __( 'SERVER ERROR - Could Not Load', 'quick-pagepost-redirect-plugin' ), array( 'response' => '200', 'back_link' => '1' ) ); 1547 exit; 1548 } else { 1549 $config_file = file_get_contents( $_FILES['qppr_file']['tmp_name'] ); 1550 if ( substr($config_file, 0, strlen('QUICKPAGEPOSTREDIRECT')) !== 'QUICKPAGEPOSTREDIRECT' ) { 1551 if(strpos($config_file,'|') !== false){ 1552 $delim = '|'; 1553 }elseif(strpos($config_file,',') !== false){ 1554 $delim = ','; 1555 }elseif(strpos($config_file,"\t") !== false){ 1556 $delim = "\t"; 1557 }else{ 1558 $delim = false; 1559 } 1560 if($delim != false){ 1561 $config_file = str_replace("\r\n", "\n", $config_file); 1562 $config_file = str_replace("\r", "\n", $config_file); 1563 $text = explode( "\n", $config_file ); 1564 $newfile1 = array(); 1565 if( is_array( $text ) && !empty( $text ) ){ 1566 foreach( $text as $nl ){ 1567 if( $nl != '' ){ 1568 $elem = explode( $delim, $nl ); 1569 if( isset( $elem[0] ) && isset( $elem[1] ) ){ 1570 $newfile1['quickppr_redirects'][esc_url($elem[0])] = esc_url($elem[1]); 1571 $nw = isset($elem[2]) && $elem[2] == '1' ? '1' : '0'; 1572 $nf = isset($elem[3]) && $elem[3] == '1' ? '1' : '0'; 1573 $newfile1['quickppr_redirects_meta'][$elem[0]]['newwindow'] = $nw; 1574 $newfile1['quickppr_redirects_meta'][$elem[0]]['nofollow'] = $nf; 1575 } 1576 } 1577 } 1578 if(is_array($newfile1) && !empty( $newfile1 )){ 1579 if( isset( $newfile1['quickppr_redirects'] ) ){ 1580 update_option( 'quickppr_redirects', $newfile1['quickppr_redirects'] ); 1581 } 1582 if( isset( $newfile1['quickppr_redirects_meta'] ) ){ 1583 update_option( 'quickppr_redirects_meta', $newfile1['quickppr_redirects_meta'] ); 1584 } 1585 } 1586 } 1587 $this->qppr_try_to_clear_cache_plugins(); 1588 wp_redirect( admin_url( 'admin.php?page=redirect-import-export&update=4' ), 302 ); 1589 exit; 1590 }else{ 1591 wp_die( __( 'This does not look like a Quick Page Post Redirect file - it is possibly damaged or corrupt.', 'quick-pagepost-redirect-plugin' ) , __( 'ERROR - Not a valid File', 'quick-pagepost-redirect-plugin' ), array( 'response' => '200', 'back_link' => '1' ) ); 1592 exit; 1593 } 1594 } else { 1595 $config_file = unserialize(base64_decode(substr($config_file, strlen('QUICKPAGEPOSTREDIRECT')))); 1596 if ( !is_array( $config_file ) ) { 1597 wp_die( __( 'This does not look like a Quick Page Post Redirect file - it is possibly damaged or corrupt.', 'quick-pagepost-redirect-plugin' ) , __( 'ERROR - Not a valid File', 'quick-pagepost-redirect-plugin' ), array( 'response' => '200', 'back_link' => '1' ) ); 1598 exit; 1599 } else { 1600 $newQPPRRedirects = $config_file['quickppr_redirects']; 1601 $newQPPRMeta = $config_file['quickppr_redirects_meta']; 1602 update_option('quickppr_redirects', $newQPPRRedirects); 1603 update_option('quickppr_redirects_meta', $newQPPRMeta); 1604 $this->qppr_try_to_clear_cache_plugins(); 1605 wp_redirect(admin_url('admin.php?page=redirect-import-export&update=4'),302); 1533 1606 } 1534 1607 } 1535 $newfile = implode( "\r\n", $newline );1536 }else{1537 $newfile = $newtext;1538 1608 } 1539 die( $newfile ); 1540 } 1541 exit; 1542 } elseif( isset( $_POST['import-quick-redrects-file'] ) && isset( $_FILES['qppr_file'] ) ) { 1543 check_admin_referer( 'import-quick-redrects-file' ); 1544 if ( $_FILES['qppr_file']['error'] > 0 ) { 1545 wp_die( __( 'An error occured during the file upload. Please fix your server configuration and retry.', 'quick-pagepost-redirect-plugin' ) , __( 'SERVER ERROR - Could Not Load', 'quick-pagepost-redirect-plugin' ), array( 'response' => '200', 'back_link' => '1' ) ); 1546 exit; 1547 } else { 1548 $config_file = file_get_contents( $_FILES['qppr_file']['tmp_name'] ); 1549 if ( substr($config_file, 0, strlen('QUICKPAGEPOSTREDIRECT')) !== 'QUICKPAGEPOSTREDIRECT' ) { 1609 } elseif( isset($_POST['import_redirects_add_qppr']) && isset($_FILES['qppr_file_add']) ) { 1610 check_admin_referer( 'import_redirects_add_qppr' ); 1611 if ( $_FILES['qppr_file_add']['error'] > 0 ) { 1612 wp_die(__( 'An error occured during the file upload. It might me that the file is too large or you do not have the premissions to write to the temporary upload directory. Please fix your server configuration and retry.', 'quick-pagepost-redirect-plugin' ) , __( 'SERVER ERROR - Could Not Load', 'quick-pagepost-redirect-plugin' ), array( 'response' => '200', 'back_link' => '1' ) ); 1613 exit; 1614 } else { 1615 $config_file = file_get_contents( $_FILES['qppr_file_add']['tmp_name'] ); 1550 1616 if(strpos($config_file,'|') !== false){ 1551 1617 $delim = '|'; … … 1557 1623 $delim = false; 1558 1624 } 1559 if($delim != false){ 1625 if ( strpos( $config_file, $delim ) === false ) { 1626 wp_die( __( 'This does not look like the file is in the correct format - it is possibly damaged or corrupt.<br/>Be sure the redirects are 1 per line and the redirect and destination are seperated by a PIPE (|), COMMA (,) or a TAB.', 'quick-pagepost-redirect-plugin' ) . '<br/>Example:<br/><br/><code>redirect|destination</code>', __( 'ERROR - Not a valid File', 'quick-pagepost-redirect-plugin' ), array( 'response' => '200', 'back_link' => '1' ) ); 1627 exit; 1628 } else { 1629 $tempArr = array(); 1630 $tempMArr = array(); 1560 1631 $config_file = str_replace("\r\n", "\n", $config_file); 1561 $config_file = str_replace("\r", "\n", $config_file);1562 $ text= explode( "\n", $config_file );1632 $config_file = str_replace("\r", "\n", $config_file); 1633 $QR_Array = explode( "\n", $config_file ); 1563 1634 $newfile1 = array(); 1564 if( is_array( $text ) && !empty( $text ) ){1565 foreach( $ text as $nl ){1566 if( $ nl != ''){1567 $elem = explode( $delim, $nl );1635 if( !empty( $QR_Array ) && is_array( $QR_Array )): 1636 foreach( $QR_Array as $qrtoadd ): 1637 if( $qrtoadd != '' && $delim != false && strpos( $qrtoadd, $delim ) !== false ){ 1638 $elem = explode( $delim, str_replace( array( "\r", "\n" ), array( '', '' ), $qrtoadd ) ); 1568 1639 if( isset( $elem[0] ) && isset( $elem[1] ) ){ 1569 1640 $newfile1['quickppr_redirects'][esc_url($elem[0])] = esc_url($elem[1]); … … 1574 1645 } 1575 1646 } 1576 }1647 endforeach; 1577 1648 if(is_array($newfile1) && !empty( $newfile1 )){ 1578 1649 if( isset( $newfile1['quickppr_redirects'] ) ){ 1579 update_option( 'quickppr_redirects', $newfile1['quickppr_redirects'] ); 1650 $currQRs = get_option( 'quickppr_redirects', array() ); 1651 $resultQRs = array_replace($currQRs, $newfile1['quickppr_redirects']); 1652 update_option( 'quickppr_redirects', $resultQRs ); 1580 1653 } 1581 1654 if( isset( $newfile1['quickppr_redirects_meta'] ) ){ 1582 update_option( 'quickppr_redirects_meta', $newfile1['quickppr_redirects_meta'] ); 1655 $currQRM = get_option( 'quickppr_redirects_meta', array() ); 1656 $resultQRMs = array_replace($currQRM, $newfile1['quickppr_redirects_meta']); 1657 update_option( 'quickppr_redirects_meta', $resultQRMs ); 1583 1658 } 1584 1659 } 1585 } 1586 $this->qppr_try_to_clear_cache_plugins(); 1587 wp_redirect( admin_url( 'admin.php?page=redirect-import-export&update=4' ), 302 ); 1588 exit; 1589 }else{ 1590 wp_die( __( 'This does not look like a Quick Page Post Redirect file - it is possibly damaged or corrupt.', 'quick-pagepost-redirect-plugin' ) , __( 'ERROR - Not a valid File', 'quick-pagepost-redirect-plugin' ), array( 'response' => '200', 'back_link' => '1' ) ); 1591 exit; 1592 } 1593 } else { 1594 $config_file = unserialize(base64_decode(substr($config_file, strlen('QUICKPAGEPOSTREDIRECT')))); 1595 if ( !is_array( $config_file ) ) { 1596 wp_die( __( 'This does not look like a Quick Page Post Redirect file - it is possibly damaged or corrupt.', 'quick-pagepost-redirect-plugin' ) , __( 'ERROR - Not a valid File', 'quick-pagepost-redirect-plugin' ), array( 'response' => '200', 'back_link' => '1' ) ); 1597 exit; 1598 } else { 1599 $newQPPRRedirects = $config_file['quickppr_redirects']; 1600 $newQPPRMeta = $config_file['quickppr_redirects_meta']; 1601 update_option('quickppr_redirects', $newQPPRRedirects); 1602 update_option('quickppr_redirects_meta', $newQPPRMeta); 1603 $this->qppr_try_to_clear_cache_plugins(); 1604 wp_redirect(admin_url('admin.php?page=redirect-import-export&update=4'),302); 1660 $this->qppr_try_to_clear_cache_plugins(); 1661 wp_redirect(admin_url('admin.php?page=redirect-import-export&update=5'),302); 1662 exit; 1663 else: 1664 wp_die( __( 'It does not look like there are any valid items to import - check the file and try again.', 'quick-pagepost-redirect-plugin' ) , __( 'ERROR - No Valid items to add.', 'quick-pagepost-redirect-plugin' ), array( 'response' => '200', 'back_link' => '1' ) ); 1665 exit; 1666 endif; 1605 1667 } 1606 1668 } 1607 } 1608 } elseif( isset($_POST['import_redirects_add_qppr']) && isset($_FILES['qppr_file_add']) ) { 1609 check_admin_referer( 'import_redirects_add_qppr' ); 1610 if ( $_FILES['qppr_file_add']['error'] > 0 ) { 1611 wp_die(__( 'An error occured during the file upload. It might me that the file is too large or you do not have the premissions to write to the temporary upload directory. Please fix your server configuration and retry.', 'quick-pagepost-redirect-plugin' ) , __( 'SERVER ERROR - Could Not Load', 'quick-pagepost-redirect-plugin' ), array( 'response' => '200', 'back_link' => '1' ) ); 1612 exit; 1613 } else { 1614 $config_file = file_get_contents( $_FILES['qppr_file_add']['tmp_name'] ); 1615 if(strpos($config_file,'|') !== false){ 1616 $delim = '|'; 1617 }elseif(strpos($config_file,',') !== false){ 1618 $delim = ','; 1619 }elseif(strpos($config_file,"\t") !== false){ 1620 $delim = "\t"; 1621 }else{ 1622 $delim = false; 1623 } 1624 if ( strpos( $config_file, $delim ) === false ) { 1625 wp_die( __( 'This does not look like the file is in the correct format - it is possibly damaged or corrupt.<br/>Be sure the redirects are 1 per line and the redirect and destination are seperated by a PIPE (|), COMMA (,) or a TAB.', 'quick-pagepost-redirect-plugin' ) . '<br/>Example:<br/><br/><code>redirect|destination</code>', __( 'ERROR - Not a valid File', 'quick-pagepost-redirect-plugin' ), array( 'response' => '200', 'back_link' => '1' ) ); 1626 exit; 1627 } else { 1628 $tempArr = array(); 1629 $tempMArr = array(); 1630 $config_file = str_replace("\r\n", "\n", $config_file); 1631 $config_file = str_replace("\r", "\n", $config_file); 1632 $QR_Array = explode( "\n", $config_file ); 1633 $newfile1 = array(); 1634 if( !empty( $QR_Array ) && is_array( $QR_Array )): 1635 foreach( $QR_Array as $qrtoadd ): 1636 if( $qrtoadd != '' && $delim != false && strpos( $qrtoadd, $delim ) !== false ){ 1637 $elem = explode( $delim, str_replace( array( "\r", "\n" ), array( '', '' ), $qrtoadd ) ); 1638 if( isset( $elem[0] ) && isset( $elem[1] ) ){ 1639 $newfile1['quickppr_redirects'][esc_url($elem[0])] = esc_url($elem[1]); 1640 $nw = isset($elem[2]) && $elem[2] == '1' ? '1' : '0'; 1641 $nf = isset($elem[3]) && $elem[3] == '1' ? '1' : '0'; 1642 $newfile1['quickppr_redirects_meta'][$elem[0]]['newwindow'] = $nw; 1643 $newfile1['quickppr_redirects_meta'][$elem[0]]['nofollow'] = $nf; 1644 } 1645 } 1646 endforeach; 1647 if(is_array($newfile1) && !empty( $newfile1 )){ 1648 if( isset( $newfile1['quickppr_redirects'] ) ){ 1649 $currQRs = get_option( 'quickppr_redirects', array() ); 1650 $resultQRs = array_replace($currQRs, $newfile1['quickppr_redirects']); 1651 update_option( 'quickppr_redirects', $resultQRs ); 1652 } 1653 if( isset( $newfile1['quickppr_redirects_meta'] ) ){ 1654 $currQRM = get_option( 'quickppr_redirects_meta', array() ); 1655 $resultQRMs = array_replace($currQRM, $newfile1['quickppr_redirects_meta']); 1656 update_option( 'quickppr_redirects_meta', $resultQRMs ); 1657 } 1658 } 1659 $this->qppr_try_to_clear_cache_plugins(); 1660 wp_redirect(admin_url('admin.php?page=redirect-import-export&update=5'),302); 1661 exit; 1662 else: 1663 wp_die( __( 'It does not look like there are any valid items to import - check the file and try again.', 'quick-pagepost-redirect-plugin' ) , __( 'ERROR - No Valid items to add.', 'quick-pagepost-redirect-plugin' ), array( 'response' => '200', 'back_link' => '1' ) ); 1664 exit; 1665 endif; 1666 } 1667 } 1668 } return; 1669 } return; 1670 } return; 1669 1671 } 1670 1672
Note: See TracChangeset
for help on using the changeset viewer.