Вход Регистрация
Файл: InstantSocial/uploud/components/photoblog/model.php
Строк: 175
<?php

if(!defined('VALID_CMS')) { die('ACCESS DENIED'); }

class 
cms_model_photoblog{

    private 
$inDB;

    function 
__construct(){
        
$this->inDB cmsDatabase::getInstance();
    }

    public function 
getPhlogDate($pubdate){
 
$arr_date=explode(' ',$pubdate);
   
$arr_date['y_m_d']=explode('-',$arr_date[0]);
   
$arr_date['h_m_s']=explode(':',$arr_date[1]);        
        
      switch (
$arr_date['y_m_d'][1]) {
     case 
"1":$month="ЯНВ"; break;case "2":$month="ФЕВ";break;case "3":$month="МАР"; break;case "4":$month="АПР"; break;
     case 
"5":$month="МАЙ"; break;case "6":$month="ИЮН"; break;case "7":$month="ИЮЛ"; break;case "8":$month="АВГ"; break;
     case 
"9":$month="СЕН"; break;case "10":$month="ОКТ"; break;case "11":$month="НОЯ"; break;case "12":$month="ДЕК"; break;}   
   
        
$pdate['day'] = $arr_date['y_m_d'][2];
        
$pdate['month'] = $month;
        
$pdate['year'] = $arr_date['y_m_d'][0];    

  return 
$pdate;
}
/* ==================================================================================================== */
/* ==================================================================================================== */
    
public function getVotingBlock($f_id){
    
$inUser cmsUser::getInstance();
    
$user_id $inUser->id;
  
$is_vote $this->inDB->get_field('cms_phlog_rating',"ph_id={$f_id} AND user_id={$user_id}"'vote'); 
    
$votes $this->inDB->rows_count('cms_phlog_rating',"ph_id={$f_id}");
    
$total =    $this->inDB->query("SELECT SUM(vote) as votes FROM cms_phlog_rating WHERE ph_id={$f_id}");
    
$rat $this->inDB->fetch_assoc($total);
    
$rating round( ($rat[votes] /  $votes), );  
 
  if (
$user_id && !$is_vote) {   
 
      
$ratform '<ul class="voting"> 
        <li class="one"><a href="#" title="плохо" onclick="doRate(1, '
.$f_id.'); return false;" ';  if ($rating ==1) {$ratform .= 'class="cur"';}
    
$ratform .='>1</a></li>
        <li class="two"><a href="#" title="приемлимо" onclick="doRate(2, '
.$f_id.');return false;" '; if ($rating ==2) {$ratform .= 'class="cur"';}
    
$ratform .= '>2</a></li>
        <li class="three"><a href="#" title="нормально" onclick="doRate(3, '
.$f_id.');return false;" ';  if ($rating ==3) {$ratform .= 'class="cur"';}
    
$ratform .= '>3</a></li>
        <li class="four"><a href="#" title="хорошо" onclick="doRate(4, '
.$f_id.');return false;" ';  if ($rating ==4) {$ratform .= 'class="cur"';}
    
$ratform .= '>4</a></li>
        <li class="five"><a href="#" title="отлично" onclick="doRate(5, '
.$f_id.');return false;" '; if ($rating ==5) {$ratform .= 'class="cur"';}
    
$ratform .= '>5</a></li>
    </ul> <span>('
.$votes.' голосов)</span>';
     } 
  else {
     
$ratform '<ul class="voting"> 
        <li class="one"><a href="#" title="плохо" onclick="return false;" '
;  if ($rating ==1) {$ratform .= 'class="cur"';}
    
$ratform .='>1</a></li>
        <li class="two"><a href="#" title="приемлимо" onclick="return false;" '
; if ($rating ==2) {$ratform .= 'class="cur"';}
    
$ratform .= '>2</a></li>
        <li class="three"><a href="#" title="нормально" onclick="return false;" '
;  if ($rating ==3) {$ratform .= 'class="cur"';}
    
$ratform .= '>3</a></li>
        <li class="four"><a href="#" title="хорошо" onclick="return false;" '
;  if ($rating ==4) {$ratform .= 'class="cur"';}
    
$ratform .= '>4</a></li>
        <li class="five"><a href="#" title="отлично" onclick="return false;" '
; if ($rating ==5) {$ratform .= 'class="cur"';}
    
$ratform .= '>5</a></li>
    </ul> <span>('
.$votes.' голосов)</span>';  
  }   
     
      return 
$ratform;
  }

/* ==================================================================================================== */
/* ==================================================================================================== */

    
public function uploadPhoto($ph_id$photo_file false) {
        
        if (!
$ph_id) { return false; }

        
$inCore cmsCore::getInstance();
    
$cfg        $inCore->loadComponentConfig('photoblog');
   
$height $cfg['height']; 
     
$width $cfg['width'];
   
$watermark $cfg['watermark'];  
        if (
$_FILES['Filedata']['name']){
            
            
$cfg $inCore->loadComponentConfig('photoblog');
            if (!isset(
$cfg['watermark'])) { $cfg['watermark'] = 0; }

            
$inCore->includeGraphics();
            
            
$file = array();

            
$uploaddir                 PATH.'/images/photoblog/';
            
$realfile                 $this->inDB->escape_string($_FILES['Filedata']['name']);
        
            
$path_parts             pathinfo($realfile);
            
$ext                    strtolower($path_parts['extension']);
            
            
// убираем расширение файла вместе с точкой
            
$realfile substr($realfile0strrpos($realfile'.'));
        
            if (
$ext != 'jpg' && $ext != 'jpeg' && $ext != 'gif' && $ext != 'png' && $ext != 'bmp') { return false; }
        
            
$lid                     $this->inDB->get_fields('cms_phlog_photos''id>0''id''id DESC');
            
$lastid                 $lid['id']+1;    
            
$filename                 md5($lastid.$realfile).'.jpg';                    
        
            
$uploadfile                $uploaddir $realfile;
            
$uploadphoto             $uploaddir $filename;
            
$uploadthumb['small']     = $uploaddir 'small/' $filename;
            
$uploadthumb['medium']    = $uploaddir 'medium/' $filename;
        
            
$source                    $_FILES['Filedata']['tmp_name'];
            
$errorCode                $_FILES['Filedata']['error'];
        
            if (
$inCore->moveUploadedFile($source$uploadphoto$errorCode)) {
                


                @
img_resize($uploadphoto$uploadthumb['small'], 100100true);
             @
img_resize($uploadphoto$uploadthumb['medium'], $width$heightfalsefalse);

                if (
$cfg['watermark']) { @img_add_watermark($uploadthumb['medium']); }
            @
unlink($uploadphoto);

                   
$sql "INSERT INTO cms_phlog_photos (phlog_id, image)
                VALUES ('
{$ph_id}', '{$filename}')";
         
$this->inDB->query($sql);
        
            } else {
        
                return 
false;
                
            }


        } else {
        
            return 
false;
            
        }

        return 
$file;

    }

/* ==================================================================================================== */
/* ==================================================================================================== */

    
public function checkAccess($ph_id$user_id){
        
        
$inCore cmsCore::getInstance();
        
$inUser cmsUser::getInstance();
        
        
$user_id    $user_id $user_id $inUser->id;
        
        if (!
$user_id) { return false; }
        
   
$access =$this->inDB->get_field('cms_phlog_item'"id={$ph_id} AND user_id={$user_id}"'title');
    if (
$inUser->is_admin) { $access '1'; }
   
   return 
$access;
}   
/* ==================================================================================================== */
/* ==================================================================================================== */

     
public function getPhlogSeoLink($phlog){
    
    
$seolink cmsCore::strToURL($phlog['title']);

     if (
$phlog['id']){
            
$where ' AND id<>'.$phlog['id'];
        } else {
            
$where '';
       }

    
$is_exists $this->inDB->rows_count('cms_phlog_items'"seolink='{$seolink}'".$where1);

    if (
$is_exists) { $seolink .= '-' $phlog['id']; }

    return 
$seolink;
   }


/* ==================================================================================================== */
/* ==================================================================================================== */

   
public function deletePhlog($f_id) {

  
$access $this->checkAccess($f_id$inUser->id);
  if (
$access) {
    
$sql "SELECT * FROM cms_phlog_photos WHERE phlog_id = $f_id";
            
$result $this->inDB->query($sql);    
     if (
$this->inDB->num_rows($result)){ 
                while(
$phlog $this->inDB->fetch_assoc($result)){
          
unlink(PATH.'/images/photoblog/small/'.$phlog['image']);
           
unlink(PATH.'/images/photoblog/medium/'.$phlog['image']);
       
$this->inDB->query("DELETE FROM cms_phlog_photos WHERE id = $phlog[id]");    
       } }

     
$this->inDB->query("DELETE FROM cms_phlog_rating WHERE ph_id = $f_id");    
     
$this->inDB->query("DELETE FROM cms_comments WHERE target = 'photoblog' AND target_id = $f_id");    
     
$this->inDB->query("DELETE FROM cms_phlog_item WHERE id = $f_id");       
    } else {
cmsCore::error404();}
}

/* ==================================================================================================== */
/* ==================================================================================================== */


   
public function getCommentTarget($target$target_id) {

        
$result = array();

        switch(
$target){

            case 
'photoblog'$sql "SELECT title, seolink                                        
                                   FROM cms_phlog_item     
                                 WHERE id=
{$target_id}
                                 LIMIT 1"
;
                         
$res $this->inDB->query($sql);
                         if (!
$this->inDB->num_rows($res)){ return false; }
                         
$phlog $this->inDB->fetch_assoc($res);
                         
$result['link']  = "/photoblog/".$phlog['seolink'].".html";
                         
$result['title'] = $phlog['title'];
                         break;

        }

        return (
$result $result false);

    }


}
Онлайн: 0
Реклама