Skip to content

Commit

Permalink
Massive formatting fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Aram Zucker-Scharff committed Jan 7, 2017
1 parent b12ed91 commit f310511
Show file tree
Hide file tree
Showing 159 changed files with 19,931 additions and 20,392 deletions.
42 changes: 19 additions & 23 deletions Application.php
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
<?php
namespace PressForward;
//var_dump('2<pre>');

//var_dump(__NAMESPACE__); //die();

// var_dump('2<pre>');
// var_dump(__NAMESPACE__); //die();
$obj = new Loader;
//$obj->test();

// $obj->test();
use Intraxia\Jaxion\Core\Application as JaxionCore;
//use Intraxia\Jaxion\Contract\Core\Application as ApplicationContract;

// use Intraxia\Jaxion\Contract\Core\Application as ApplicationContract;
class Application extends JaxionCore {
var $ver = PF_VERSION;
/**
* ServiceProviders to register with the Application
*
* @var string[]
*/
* ServiceProviders to register with the Application
*
* @var string[]
*/
protected $providers = array(
'PressForward\Core\Providers\LibrariesProvider',
'PressForward\Core\Providers\SchemaProvider',
Expand All @@ -28,10 +24,10 @@ class Application extends JaxionCore {
'PressForward\Core\Providers\PreferencesServiceProvider',
'PressForward\Core\Providers\ModulesProvider',
'PressForward\Core\Providers\AJAXServiceProvider',
'PressForward\Core\Providers\APIProvider'
// 'PressForward\Core\Providers\CoreServiceProvider',
// 'PressForward\Core\Providers\EmbedServiceProvider',
// 'PressForward\Core\Providers\RouterServiceProvider',
'PressForward\Core\Providers\APIProvider',
// 'PressForward\Core\Providers\CoreServiceProvider',
// 'PressForward\Core\Providers\EmbedServiceProvider',
// 'PressForward\Core\Providers\RouterServiceProvider',
);
/**
* {@inheritdoc}
Expand All @@ -45,24 +41,24 @@ public function activate() {
// This is a new installation
if ( ! $saved_version ) {
// Do whatever you need to do during first installation
$check = pressforward('schema.feeds')->create(
$check = pressforward( 'schema.feeds' )->create(
'http://pressforward.org/feed/',
array(
'title' => 'PressForward',
'htmlUrl' => 'http://pressforward.org/',
'description' => 'The news feed for the PressForward project.',
'type' => 'rss',
'module_added' => 'rss-import'
'module_added' => 'rss-import',
)
);

$wp_rewrite->flush_rules(false);
$wp_rewrite->flush_rules( false );

// This is an upgrade
} else if ( version_compare( $saved_version, $current_version, '<' ) ) {
// This is an upgrade
} elseif ( version_compare( $saved_version, $current_version, '<' ) ) {
// Do whatever you need to do on an upgrade
delete_option( 'pf_delete_queue_nonce' );
// Version is up to date - do nothing
// Version is up to date - do nothing
} else {
return;
}
Expand All @@ -72,4 +68,4 @@ public function activate() {
}

}
//call_user_func(array(new Application(__FILE__), 'boot'));
// call_user_func(array(new Application(__FILE__), 'boot'));
207 changes: 102 additions & 105 deletions Controllers/HTTPTools.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
namespace PressForward\Controllers;

//use Intraxia\Jaxion\Contract\Core\HasActions;
// use Intraxia\Jaxion\Contract\Core\HasActions;
use PressForward\Interfaces\System;
use URLResolver;
/**
Expand All @@ -11,43 +11,42 @@
class HTTPTools {

function __construct( URLResolver $resolver, System $system, Metas $meta ) {
$this->url_resolver = $resolver;
$this->url_resolver = $resolver;
$this->system = $system;
$this->meta = $meta;
}

public function resolve_source_url($url){
$url = $this->resolve_a_url($url);
$url_array = parse_url($url);
if (empty($url_array['host'])){
public function resolve_source_url( $url ) {
$url = $this->resolve_a_url( $url );
$url_array = parse_url( $url );
if ( empty( $url_array['host'] ) ) {
return;
}
$source_url = 'http://' . $url_array['host'];
return $source_url;
}

public function resolve_full_url($url){
$url = $this->resolve_a_url($url);
public function resolve_full_url( $url ) {
$url = $this->resolve_a_url( $url );
return $url;
}

/**
* Examine a URL and resolve it as needed.
*
* @since 3.4.5
*
* @param string $url A web address URI.
* @return bool True value for a submitted URL that matches an aggregation service.
*
*/
public function resolve_a_url($url){
$url_array = parse_url($url);
if (empty($url_array['host'])){
* Examine a URL and resolve it as needed.
*
* @since 3.4.5
*
* @param string $url A web address URI.
* @return bool True value for a submitted URL that matches an aggregation service.
*/
public function resolve_a_url( $url ) {
$url_array = parse_url( $url );
if ( empty( $url_array['host'] ) ) {
return $url;
} else {
$check = $this->url_is_aggregation_service($url);
if ($check && in_array('curl', get_loaded_extensions())){
$url = $this->url_resolver->resolveURL($url)->getURL();
$check = $this->url_is_aggregation_service( $url );
if ( $check && in_array( 'curl', get_loaded_extensions() ) ) {
$url = $this->url_resolver->resolveURL( $url )->getURL();
}
}

Expand All @@ -57,133 +56,131 @@ public function resolve_a_url($url){


/**
* Return an array of known aggregation services.
*
* @since 3.4.5
*
* @return array An array of URLs with aggregation URL host parts.
*
*/
public function aggregation_services(){
* Return an array of known aggregation services.
*
* @since 3.4.5
*
* @return array An array of URLs with aggregation URL host parts.
*/
public function aggregation_services() {
return array(
'Google' => 'google.com',
'Tweeted Times' => 'tweetedtimes.com'
'Google' => 'google.com',
'Tweeted Times' => 'tweetedtimes.com',
);
}

/**
* Check a URL for an aggregation service's forward and return true or false.
*
* @since 3.4.5
*
* @param string $url A web address URI.
* @return bool True value for a submitted URL that matches an aggregation service.
*
*/
public function url_is_aggregation_service($url){
* Check a URL for an aggregation service's forward and return true or false.
*
* @since 3.4.5
*
* @param string $url A web address URI.
* @return bool True value for a submitted URL that matches an aggregation service.
*/
public function url_is_aggregation_service( $url ) {
$check = false;
$services = $this->aggregation_services();
foreach ($services as $service){
$pos = strpos($url, $service);
if(!empty($pos)){
foreach ( $services as $service ) {
$pos = strpos( $url, $service );
if ( ! empty( $pos ) ) {
$check = true;
}
}
return $check;
}

function attempt_to_get_cookiepath(){
function attempt_to_get_cookiepath() {
$reset = true;
$upload_dir = wp_upload_dir();
$cookie_path = $upload_dir['basedir'] . 'cookie.txt';
if ( ! is_file( $cookie_path ) ) {
touch( $cookie_path );
}
if ( ! is_writable( $cookie_path ) ) {
pf_log( "Can't write to the cookie at $cookie_path." );
return false;
pf_log( "Can't write to the cookie at $cookie_path." );
return false;
} else {
$debug = 1;
$debug = 1;
}
if ($reset) {
$fo = fopen($cookie_path, 'w') or pf_log('Can\'t open cookie file.');
fwrite($fo, "");
fclose($fo);
if ( $reset ) {
$fo = fopen( $cookie_path, 'w' ) or pf_log( 'Can\'t open cookie file.' );
fwrite( $fo, '' );
fclose( $fo );

}
return $cookie_path;
}

function get_url_content( $url, $function = false ){
function get_url_content( $url, $function = false ) {
$args = func_get_args();
$url = str_replace('&amp;','&', $url);
$url = str_replace( '&amp;','&', $url );
$url_first = $url;
if (!$function){
$r = set_url_scheme($url, 'http');
if ( ! $function ) {
$r = set_url_scheme( $url, 'http' );
} else {
$args[0] = $url;
unset($args[1]);
#var_dump($args);
unset( $args[1] );
// var_dump($args);
$r = call_user_func_array( $function, $args );
//var_dump($r); die();
# "A variable is considered empty if it does not exist or if its value equals FALSE"
if ( is_wp_error( $r ) || empty($r) ) {
$non_ssl_url = set_url_scheme($url, 'http');
// var_dump($r); die();
// "A variable is considered empty if it does not exist or if its value equals FALSE"
if ( is_wp_error( $r ) || empty( $r ) ) {
$non_ssl_url = set_url_scheme( $url, 'http' );
if ( $non_ssl_url != $url ) {
$args[0] = $non_ssl_url;
$r = call_user_func_array( $function, $args );
//var_dump($url); die();
// var_dump($url); die();
}
//$r = false;
if ( !$r || is_wp_error( $r ) ) {
# Last Chance!
if ('file_get_contents' != $function){
$response = file_get_contents($url_first);
#var_dump($r); die();
} else {
// bail
$response = false;
}
// $r = false;
if ( ! $r || is_wp_error( $r ) ) {
// Last Chance!
if ( 'file_get_contents' != $function ) {
$response = file_get_contents( $url_first );
// var_dump($r); die();
} else {
// bail
$response = false;
}
}
}
}
$response = $r;
$loaded_extensions = get_loaded_extensions();
if ( empty($response) || is_wp_error($response) || ( !empty($response) && !empty($response['headers']) && isset($response['headers']['content-length']) && ( 50 > strlen($response['headers']['content-length']) ) ) && in_array('curl', $loaded_extensions) ){
$cookie_path = 'cookie.txt';
if ( defined('COOKIE_PATH_FOR_CURL') ){
$cookie_path = constant('COOKIE_PATH_FOR_CURL');
if ( !isset($cookie_path) || false == $cookie_path ){
if ( empty( $response ) || is_wp_error( $response ) || ( ! empty( $response ) && ! empty( $response['headers'] ) && isset( $response['headers']['content-length'] ) && ( 50 > strlen( $response['headers']['content-length'] ) ) ) && in_array( 'curl', $loaded_extensions ) ) {
$cookie_path = 'cookie.txt';
if ( defined( 'COOKIE_PATH_FOR_CURL' ) ) {
$cookie_path = constant( 'COOKIE_PATH_FOR_CURL' );
if ( ! isset( $cookie_path ) || false == $cookie_path ) {
$cookie_path = $this->attempt_to_get_cookiepath();
if ( false === $cookie_path ) {
return false;
}
}
} else {
$cookie_path = $this->attempt_to_get_cookiepath();
if (false === $cookie_path){
if ( ! $cookie_path ) {
return false;
}
}
} else {
$cookie_path = $this->attempt_to_get_cookiepath();
if (!$cookie_path){
return false;
}
}
$curl = curl_init($args[0]);

curl_setopt($curl, constant('CURLOPT_FAILONERROR'), true);
curl_setopt($curl, constant('CURLOPT_FOLLOWLOCATION'), true);
curl_setopt($curl, constant('CURLOPT_RETURNTRANSFER'), true);
curl_setopt($curl, constant('CURLOPT_TIMEOUT'), 15);
curl_setopt($curl, constant('CURLOPT_SSL_VERIFYHOST'), false);
curl_setopt($curl, constant('CURLOPT_SSL_VERIFYPEER'), false);
curl_setopt($curl, constant('CURLOPT_USERAGENT'), "facebookexternalhit/1.1 (+http://www.facebook.com/externalhit_uatext.php)");
//The following 2 set up lines work with sites like www.nytimes.com
curl_setopt($curl, constant('CURLOPT_COOKIEFILE'), $cookie_path); //you can change this path to whetever you want.
curl_setopt($curl, constant('CURLOPT_COOKIEJAR'), $cookie_path); //you can change this path to whetever you want.

$response = mb_convert_encoding(curl_exec($curl), 'HTML-ENTITIES', 'UTF-8');
// Will return false or the content.
curl_close($curl);
return array( 'body' => $response );
} else {
return $response;
}
$curl = curl_init( $args[0] );

curl_setopt( $curl, constant( 'CURLOPT_FAILONERROR' ), true );
curl_setopt( $curl, constant( 'CURLOPT_FOLLOWLOCATION' ), true );
curl_setopt( $curl, constant( 'CURLOPT_RETURNTRANSFER' ), true );
curl_setopt( $curl, constant( 'CURLOPT_TIMEOUT' ), 15 );
curl_setopt( $curl, constant( 'CURLOPT_SSL_VERIFYHOST' ), false );
curl_setopt( $curl, constant( 'CURLOPT_SSL_VERIFYPEER' ), false );
curl_setopt( $curl, constant( 'CURLOPT_USERAGENT' ), 'facebookexternalhit/1.1 (+http://www.facebook.com/externalhit_uatext.php)' );
// The following 2 set up lines work with sites like www.nytimes.com
curl_setopt( $curl, constant( 'CURLOPT_COOKIEFILE' ), $cookie_path ); // you can change this path to whetever you want.
curl_setopt( $curl, constant( 'CURLOPT_COOKIEJAR' ), $cookie_path ); // you can change this path to whetever you want.

$response = mb_convert_encoding( curl_exec( $curl ), 'HTML-ENTITIES', 'UTF-8' );
// Will return false or the content.
curl_close( $curl );
return array( 'body' => $response );
} else {
return $response;
}
}
}
Loading

0 comments on commit f310511

Please sign in to comment.