Current File : /home/users/barii/public_html/finansenl.com.pl/wodki/application/classes/aurora.php
<?php defined('SYSPATH') or die('No direct script access.');

class Aurora {

    /**
     * Returns unique user hash with login prefix
     *
     * @param string $login
     * @param string $email
     * @return string
     */
    public static function uniqueUserLink($login,$email) {

		$login= str_replace('@','-malpa-',$login); 
	 
		$login= str_replace('.','-kropka-',$login); 
		
        return $login.'/'.Auth::instance()->hash($email);
    }
	
	 public static function uniqueUserLink2($login,$email) {

		$login= str_replace('@','-malpa-',$login); 
	 
		$login= str_replace('.','-kropka-',$login); 
		
        return $login.'&e='.Auth::instance()->hash($email);
    }
	
    public static function uniqueCompanyLink($id,$email) {
	
		//$login= str_replace('@','-malpa-',$login); 
	 
		//$login= str_replace('.','-kropka-',$login); 
		
        return $id.'/'.Auth::instance()->hash($email);
    }	
	
	public static function isMember( $id ) {
	
		$test = ORM::Factory('user_member')->where('user_id','=', $id)->find_all();
		if( $test->count() > 0 ) return array( $test[0]->has_friend, Users::getFirstname($test[0]->has_friend)); else return 0;
	
	}
	
	static public function getSelectionCount($type_id, $type ) {
	
		$selection = ORM::Factory('selection')->where('type_id','=', $type_id)->where('type','=',$type)->find_all();
		return $selection->count();
		
	
	}
	
	static public function putShortDescription($text) {
		/*
		$text = substr($text, 0, 255);
		$first = strstr($text, 'http');
		$url = substr($first, 0, strpos($first, " "));
		$link = "<a href='".$url."' target='_blank'>".$url."</a>";
		return str_replace($url, $link, $text);
		*/
		$text = stripslashes( $text );
		
		$text = preg_replace('"\b(http://\S+)"', '<a href="$1" target="_blank">$1</a>', $text);
		$text = preg_replace('"\b^(www\S+)"', '<a href="http://$1" target="_blank">$1</a>', $text);
		return $text;
		
	}	

	static public function putDescription($text) {

		//$first = strstr($text, 'http');
		//$url = substr($first, 0, strpos($first, " "));
		$text = stripslashes( $text );
		$text = preg_replace('"\b(http://\S+)"', '<a href="$1" target="_blank">$1</a>', $text);
		$text = preg_replace('"\b^(www\S+)"', '<a href="http://$1" target="_blank">$1</a>', $text);
		return $text;
		
		//$link = "<a href='".$url."' target='_blank'>".$url."</a>";
		//return str_replace($url, $link, $text);
	}
	
	public static  function addSelection( $user_id, $type_id, $type ) {
	
		$selection = ORM::Factory('selection');
		$selection->type = $type;
		$selection->user_id = $user_id;
		$selection->type_id = $type_id;
		
		$selection->save();
		
		return self::getSelectionCount($type_id, $type);
		
	
	}
	
	public static  function prevProfile( $user_id ) {
	
		$user = ORM::Factory('user')->where('id','<', $user_id)->order_by('id','desc')->limit(1)->find_all();
		if( $user->count() == 0 ) return $user_id;
		else return $user[0]->id;
	
	}
	
	public static  function nextProfile( $user_id ) {
	
		$user = ORM::Factory('user')->where('id','>', $user_id)->limit(1)->find_all();
		if( $user->count() == 0 ) return $user_id;
		else return $user[0]->id;
	
	}
	
	public static function getProfileName($what) {
	 
		return ORM::Factory('packet', $what)->title;
		
	 
	 }	

	 public static function addPoints($id_user, $what) {
	 
		$user = ORM::Factory('user', $id_user);
		$user->points += 1;
		$user->save();
	 
	 }
    /**
     * Sends standard email message. (with standard layout)
     *
     * @param string $to
     * @param string $subject
     * @param View $message
     * @param bool $html
     * @param array $from
     * @return bool
     */
    //public static function standardEmail($to, $subject, $message,$html=TRUE, $from = null) {
	
	static public function standardEmail($email, $subject, $text, $html = true, $mime=null, $attachments=null) {
		$cant_send = 0;
		$emails = array();
		if( is_array( $email ) ) {
			foreach( $email as $e ) {
				if( !empty( $e ) AND strstr( $e, "@" ) ) {
					$emails[$e] = $e;
				}
			}
		} else {
			if( !empty( $email ) AND strstr( $email, "@" ) ) {
				$emails = $email;
			} else {
			$cant_send = 1;
			}
		}
		
		$mime = array( !is_null( $mime ) ? @$mime['from_email'] : Kohana::$config->load('site.emailnoreply') =>  !is_null( $mime ) ? @$mime['from_name'] : Kohana::$config->load('site.appName'));
		
		
		if( $cant_send == 0 ) {
			try {
				mailer::factory('user')->send_welcome($emails, $subject, $text, $html = true, $mime = null, $attachments);
			} catch (Exception $e) { }
		}
		
		
	}
	/*
        $email = View::factory('email/standard')
                ->bind('content', $message);

        if(null === $from) {

            $from[0]    =   Kohana::$config->load('site.emailnoreply');
            $from[1]    =   Kohana::$config->load('site.sitename');

        }
	

        if (email::send($to, $from, $subject, $email->render(), $html))
            return true;
        else
            return false;
			
			*/
		
   // }

    /**
     * Wyslanie emaila o nowym komentarzu
     * @param string $to adresat
     * @return boolean
     */
    public static function new_art_comment_email($art_id, $content)
    {
        $subject    =   __t('Sprungle - nowy komentarz dla Twojej pracy');
        $art        =   new Model_Art($art_id);
        $user = new Model_User(Auth::instance()->get_user()->id);
        $message    =   View::factory('email/art_comment')
                            ->bind('content',$content)
                            ->bind('art', $art)
                            ->bind('user', $user);
        $to         =   $art->users->find()->email;
        //echo("self::standardEmail($to, $subject, $message);");exit;
        self::standardEmail($to, $subject, $message);
    }

    public static function partial($path, $data=array()) {

        return View::factory((strpos($path,'/'))? $path : '/_partials/'.$path)
                ->bind('data', $data);
    }

    /**
     * Zwraca widok listy stron z określonej sekcji
     * @param integer $sectionId
     * @return View
     */
    public static function getPages($sectionId) {
        $section=ORM::factory('section',$sectionId);
        $pages= $section->pages->order_by('order')->find_all();
        $langID= $_SESSION['lang_id'];


        return View::factory('_partials/pages')
                ->bind('section',$section)
                ->bind('langID',$langID)
                ->bind('pages',$pages);
    }

    /**
     * Zwraca stringa klasy aktywnego elementy górnej nawigacji
     * @param string $controller
     * @param string $action
     * @return string
     */
    public static function __top_menu($c, $a) {
        $controller = Request::current()->controller;
        $action =  Request::current()->action;

        $css = 'active';

        if ($c == $controller) {
			if ($a == 'index' || $a == $action)
            	return $css;
        }
    }

    public static function __check_menu($c, $a) {
        $controller = Request::current()->controller;
        $action =  Request::current()->action;
        $return= false;
 
        if ($a == $action) {
            $return= true;
        }

        return $return;
    }

    /**
     * Zwraca liste obiektow COLOR
     * @return <type>
     */
    public static function getColors(){
        return ORM::factory('color')->find_all();
    }
    /**
     * Zwraca liste obiektow STYLE
     * @return <type>
     */
    public static function getStyles(){
        return ORM::factory('style')->find_all();
    }
    /**
     * Zwraca obiekt 'Style_Name' na podstawie obiektu Style
     * @param <type> $style
     */
    public static function getStyleName($style){

        return $style->style_names->where('language_id','=',Kohana::config('site.language_id'))->find();
    }

    public static function countStyleArts($styleId, $isShop)
    {
        $art_status_id = 3;
        if ($isShop == 1){
            $art_status_id = 3;
        } else {
            $art_status_id = 2;
        }
        return ORM::factory('art')->where('art_status_id','=', $art_status_id)->where('style_id','=',$styleId)->count_all();
    }
    
    public static function newsletterLink($userID,$userEmail){
        $link;
        $hash       = Auth::instance()->hash($userEmail);
        $webpage    = Kohana::config('site.domain');

        $link = 'http://'.$webpage.'/newsletter/unsubscribe/'.$userID.'/'.$hash;

        return $link;
    }
	
    public static function seoLink($link){
       
	   $link = str_replace(" ","_", $link);
	   //$link = strtolower($link);

        return $link;
    }	


}