Jump to content

error function __construct()


Danny620

Recommended Posts

When I first open the page of my blog i get a list of errors sometimes this happens and other times it doesn't

 

Notice: Trying to get property of non-object in /home/sites/coolcubeentertainment.co.uk/public_html/sno-blog/socialnewsoffice.php on line 68

Notice: Trying to get property of non-object in /home/sites/coolcubeentertainment.co.uk/public_html/sno-blog/socialnewsoffice.php on line 69

Notice: Trying to get property of non-object in /home/sites/coolcubeentertainment.co.uk/public_html/sno-blog/socialnewsoffice.php on line 72

Notice: Trying to get property of non-object in /home/sites/coolcubeentertainment.co.uk/public_html/sno-blog/socialnewsoffice.php on line 73

Notice: Trying to get property of non-object in /home/sites/coolcubeentertainment.co.uk/public_html/sno-blog/socialnewsoffice.php on line 74

Notice: Trying to get property of non-object in /home/sites/coolcubeentertainment.co.uk/public_html/sno-blog/socialnewsoffice.php on line 75

Notice: Trying to get property of non-object in /home/sites/coolcubeentertainment.co.uk/public_html/sno-blog/socialnewsoffice.php on line 76

Notice: Trying to get property of non-object in /home/sites/coolcubeentertainment.co.uk/public_html/sno-blog/socialnewsoffice.php on line 77

Notice: Trying to get property of non-object in /home/sites/coolcubeentertainment.co.uk/public_html/sno-blog/socialnewsoffice.php on line 78

 

<?php

////////////// PLEASE DO NOT EDIT THIS FILE AS ANY MODIFICATIONS MADE TO THIS FILE WILL BE OVERWRITTEN BY UPDATES ////////////////////

/**
* Copyright 2012 Social News Office, Northplanet Ltd.
* http://www.socialnewsoffice.com
*
* This file contains the foundations for querying information from Social News Office API URLS
* We have defined methods such as getFeaturedNews() which would return 15 articles that have been ticked as featured on
* your Social News Office blogging account.
*
* Break Down of how our class (new SocialNewsOffice("YOUR API KEY", 'AMOUNT OF TIME IN MINUTES FOR HOW LONG TO STORE CACHE BEFORE DELETING IT', 'FILE PATH TO CACHE FOLDER ON', 'BASE WEBSITE URL')
* works
* 1. Use curl to access Social News Office API URL to pull off JSON Data.
* 2. Cache JSON Data for specified amount of time before being deleted and new request for fresh data is made.
* 3. Parse JSON Data from cached file or from Curl URL
* 4. Loop though data and display it to end user (format it with HTML and CSS)
*
*/

if ( !function_exists( 'curl_init' ) ) {
    die( "Social News Office needs the CURL PHP extension." );
}
if ( !function_exists( 'json_decode' ) ) {
    die( "Social News Office needs the JSON PHP extension" );
}

class SocialNewsOffice
{
    private $meta_title;
    private $meta_description;
private $website_url;
private $permalink;
    
    private $api_url = 'http://www.socialnewsoffice.com/'; // Social News Office API URL
    private $api_key;
    
    private $request;
    private $data;
    
    private $cache_expire = 5; // Cache Refresh in Minutes (1 - 60)
    private $cache_folder_location; // Where to store Cache Folder
    
    private $header = false; // DISPLAY HEADERS (FALSE OR TRUE)
    private $follow = true; // FOLLOW REDIRCETS (FALSE OR TRUE)
    private $ssl = false; // If set false (it accpets any ssl) should false
    private $ctimeout = 5; // Timeout for connect in SECs when curl does next url
    private $timeout = 60; // Timeout of retriving page in SECs when curl does next url


private $google_analytics = NULL; // Should contain values like (UA-28433510-1)
    private $facebook_fanpage_link = NULL; // Should contain values like (https://www.facebook.com/northplanet)
private $youtube_username = NULL; // Should contain values like (northplanet)
private $twitter_username = NULL; // Should contain values like (northplanet)
private $google_plus = NULL; // Should contain values like (105665893715911819363)
private $youtube_video = NULL; // Should contain values like (ZWoFHBwxk8o)
private $disqus_shortname = NULL; // Should contain values like (northplanet)
    
    public function __construct( $api_key, $cache_expire_in_minutes, $cache_folder_location, $website_url )
    {
        $this->api_key               = $api_key;
        $this->cache_expire          = $cache_expire_in_minutes;
        $this->cache_folder_location = $cache_folder_location;

        $settings[0]                 = $this->getSettings();

        $this->meta_title            = $settings->meta_title;
        $this->meta_description      = $settings->meta_description;
	$this->website_url           = $website_url;

	$this->google_analytics      = $settings->google_analytics;
        $this->facebook_fanpage_link = $settings->facebook_fanpage_link;
    $this->youtube_username      = $settings->youtube_username;
    $this->twitter_username      = $settings->twitter_username;
    $this->google_plus           = $settings->google_plus;
    $this->youtube_video         = $settings->youtube_video;
    $this->disqus_shortname      = $settings->disqus_shortname;
    }
    
    public function setHeader( $header )
    {
        $this->header = $header;
    }
    public function setFollow( $follow )
    {
        $this->follow = $follow;
    }
    public function setSsl( $ssl )
    {
        $this->ssl = $ssl;
    }
    public function setCtimeout( $ctimeout )
    {
        $this->ctimeout = $ctimeout;
    }
    public function setTimeout( $timeout )
    {
        $this->timeout = $timeout;
    }
    
    private function connect( )
    {
        $ch = curl_init();
        
        $con = $this->api_url . $this->request . '&api_key=' . $this->api_key;
        
        curl_setopt( $ch, CURLOPT_URL, $con );
        curl_setopt( $ch, CURLOPT_HEADER, $this->header );
        curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, $this->follow );
        curl_setopt( $ch, CURLOPT_RETURNTRANSFER, TRUE );
        curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, $this->ssl );
        curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT, $this->ctimeout );
        curl_setopt( $ch, CURLOPT_TIMEOUT, $this->timeout );
        
        $response = curl_exec( $ch );
        
        /* Check for 404 (file not found). */
        $httpCode = curl_getinfo( $ch, CURLINFO_HTTP_CODE );

	curl_close( $ch );

        if ( $httpCode == 404 ) {
            return '404';
        } else {
            return $response;
        } 

    }
    
    public function cacheApiResult( )
    {
        $cache_file = $this->cache_folder_location . $this->request . '.json';
        
        $expires = time() - ( 60 * $this->cache_expire );
        
        if ( !file_exists( $cache_file ) ) {
            $handle = fopen( $cache_file, 'w' );
            fclose( $handle );
        }
        
        // Check that the file is older than the expire time and that it's not empty
        if ( filectime( $cache_file ) < $expires || file_get_contents( $cache_file ) == '' ) {
            // File is too old, refresh cache
            $api_result = $this->connect();
            
            try {
                if ( $api_result == '404' ) {

				// Remove cache file on error to avoid writing wrong json
				unlink( $cache_file );
                    
                    throw new Exception( "API: Page Not Found - 404" ); 

                } else {
                    file_put_contents( $cache_file, json_encode( $api_result ) );
                    $this->data = json_decode( file_get_contents( $cache_file ) );
                }
                
            }
            catch ( Exception $e ) {
                echo 'Error ' . $e->getMessage();
                
            }
            
        } else {
            // Fetch cache
            $this->data = json_decode( file_get_contents( $cache_file ) );
        }
        
    }

public function emptyCacheFolder()
    {

    $mydir = opendir($this->cache_folder_location);
    while (false !== ($file = readdir($mydir))) {
        if ($file != "." && $file != "..") {
            chmod($this->cache_folder_location . $file, 0777);
            if (is_dir($this->cache_folder_location . $file)) {
                chdir('.');
                destroy($this->cache_folder_location . $file . '/');
                rmdir($this->cache_folder_location . $file);
            } else
                unlink($this->cache_folder_location . $file);
        }
    }
    closedir($mydir);

return json_encode(array('cahceStatus' => 1));

    }

public function getWebsiteURL()
{
	return $this->website_url;
}
    
public function getPermalink($post_url)
{
	$this->permalink = $this->website_url . 'post/' . $post_url;
	return $this->permalink;
}

public function getThumbnail($img_url, $w=250,$h=190,$mode='fit')
{
    return $this->website_url . 'sno-blog/src.php?src=' . $img_url . "&w=$w&h=$h&mode=$mode";
}

    public function getMetaTitle()
    {
        return $this->meta_title;
    }
    
    public function getMetaDescription()
    {
        return $this->meta_description;
    }

public function getGoogleAnalytics()
    {
        return $this->google_analytics;
    }

public function getFacebookFanpageLink()
    {
        return $this->facebook_fanpage_link;
    }

public function getYoutubeUsername()
    {
        return $this->youtube_username;
    }

public function getTwitterUsername()
    {
        return $this->twitter_username;
    }

public function getGooglePlus()
    {
        return $this->google_plus;
    }

public function getYoutubeVideo()
    {
        return $this->youtube_video;
    }

public function getDisqusShortName()
    {
        return $this->disqus_shortname;
    }

    public function getBlogPosts( $start = 0, $display = 6, $categorie = NULL )
    {
        if ( $start == '' ) {
            $start = 0;
        }
        if ( $display == '' ) {
            $display = 6;
        }
        
        $this->request = "blog_posts?start=$start&display=$display&categorie=$categorie";
        $this->cacheApiResult();
        return json_decode( $this->data );
    }

public function getPost( $blog_url = '' )
{
	$this->request = "post?blog_url=$blog_url";
        $this->cacheApiResult();

	$post = json_decode( $this->data );

	if(isset($post[0]->post_title)){ $this->meta_title = substr(strip_tags($post[0]->post_title), 0, 65); }
	if(isset($post[0]->post_content)){ $this->meta_description = substr(strip_tags($post[0]->post_content), 0, 150); }

        return $post;
}
    
    public function getCategories()
    {
        $this->request = "categories?";
        $this->cacheApiResult();
        return json_decode( $this->data );
    }
    
    public function getFeaturedNews()
    {
        $this->request = "featured_news?";
        $this->cacheApiResult();
        return json_decode( $this->data );
    }
    
    public function getSettings()
    {
        $this->request = 'settings?';
        $this->cacheApiResult();
        return json_decode( $this->data );
    }
    
}


/////////////////////// Page Pagination Function ///////////////////////////////////

   function pagination($records, $per_page = 10,$page = 1, $url = '?'){        
    
    	$total = $records;
        $adjacents = "1"; 

    	$page = ($page == 0 ? 1 : $page);  
    	$start = ($page - 1) * $per_page;								

    	$prev = $page - 1;							
    	$next = $page + 1;
        $lastpage = ceil($total/$per_page);
    	$lpm1 = $lastpage - 1;
    	
    	$pagination = "";
    	if($lastpage > 1)
    	{	
    		$pagination .= "<ul class='pagination'>";
                    $pagination .= "<li class='details'>Page $page of $lastpage</li>";
    		if ($lastpage < 7 + ($adjacents * 2))
    		{	
    			for ($counter = 1; $counter <= $lastpage; $counter++)
    			{
    				if ($counter == $page)
    					$pagination.= "<li><a class='current'>$counter</a></li>";
    				else
    					$pagination.= "<li><a href='{$url}/$counter'>$counter</a></li>";					
    			}
    		}
    		elseif($lastpage > 5 + ($adjacents * 2))
    		{
    			if($page < 1 + ($adjacents * 2))		
    			{
    				for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++)
    				{
    					if ($counter == $page)
    						$pagination.= "<li><a class='current'>$counter</a></li>";
    					else
    						$pagination.= "<li><a href='{$url}page=$counter'>$counter</a></li>";					
    				}
    				$pagination.= "<li class='dot'>...</li>";
    				$pagination.= "<li><a href='{$url}page=$lpm1'>$lpm1</a></li>";
    				$pagination.= "<li><a href='{$url}page=$lastpage'>$lastpage</a></li>";		
    			}
    			elseif($lastpage - ($adjacents * 2) > $page && $page > ($adjacents * 2))
    			{
    				$pagination.= "<li><a href='{$url}/1'>1</a></li>";
    				$pagination.= "<li><a href='{$url}/2'>2</a></li>";
    				$pagination.= "<li class='dot'>...</li>";
    				for ($counter = $page - $adjacents; $counter <= $page + $adjacents; $counter++)
    				{
    					if ($counter == $page)
    						$pagination.= "<li><a class='current'>$counter</a></li>";
    					else
    						$pagination.= "<li><a href='{$url}/$counter'>$counter</a></li>";					
    				}
    				$pagination.= "<li class='dot'>..</li>";
    				$pagination.= "<li><a href='{$url}/$lpm1'>$lpm1</a></li>";
    				$pagination.= "<li><a href='{$url}/$lastpage'>$lastpage</a></li>";		
    			}
    			else
    			{
    				$pagination.= "<li><a href='{$url}/1'>1</a></li>";
    				$pagination.= "<li><a href='{$url}/2'>2</a></li>";
    				$pagination.= "<li class='dot'>..</li>";
    				for ($counter = $lastpage - (2 + ($adjacents * 2)); $counter <= $lastpage; $counter++)
    				{
    					if ($counter == $page)
    						$pagination.= "<li><a class='current'>$counter</a></li>";
    					else
    						$pagination.= "<li><a href='{$url}/$counter'>$counter</a></li>";					
    				}
    			}
    		}
    		
    		if ($page < $counter - 1){ 
    			$pagination.= "<li><a href='{$url}/$next'>Next</a></li>";
                $pagination.= "<li><a href='{$url}/$lastpage'>Last</a></li>";
    		}else{
    			$pagination.= "<li><a class='current'>Next</a></li>";
                $pagination.= "<li><a class='current'>Last</a></li>";
            }
    		$pagination.= "</ul>\n";		
    	}
    
    
        return $pagination;
    } 


?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.