Your IP : 10.10.0.253


Current Path : /var/www/components/com_yendifvideoshare/models/
Upload File :
Current File : /var/www/components/com_yendifvideoshare/models/user.php

<?php
/**
 * @version    1.2.9
 * @package    Com_YendifVideoShare
 * @author     PluginsWare Interactive Pvt. Ltd <admin@yendifplayer.com>
 * @copyright  Copyright (c) 2012 - 2021 PluginsWare Interactive Pvt. Ltd. All Rights Reserved.
 * @license    GNU General Public License version 2 or later; see LICENSE.txt
 */

// Prevent direct access
defined( '_JEXEC' ) or die( 'Restricted access' );

class YendifVideoShareModelUser extends YendifVideoShareModel {
	
	var $searchKey;
	
	public function getItems( $limit, $userid, $orderby ) {		
		$app = JFactory::getApplication();
		$db = JFactory::getDbo();
				 
		$limit = $app->getUserStateFromRequest( 'global.list.limit', 'limit', $limit, 'int' );
		$limitstart = $app->input->get( 'limitstart', '0', 'INT' );	 
		$limitstart = $limit != 0 ? ( floor( $limitstart / $limit ) * $limit ) : 0; 
		
		$this->setState( 'limit', $limit );
		$this->setState( 'limitstart', $limitstart );	

		$query  = 'SELECT v.*, c.name as category FROM #__yendifvideoshare_videos AS v';
		$query .= ' LEFT JOIN #__yendifvideoshare_categories AS c ON v.catid=c.id';

		$where = array();
		
		$where[] = 'v.userid=' . $userid;
		$where[] = 'v.title != ' . $db->quote( '' );
		
		$this->searchKey = $app->getUserStateFromRequest( 'yendif.search.user', 'search', '', 'string' );	
		$this->searchKey = JString::strtolower( $this->searchKey );
		if ( $this->searchKey ) {
			$searchKey = $db->quote( '%' . $db->escape( $this->searchKey, true ) . '%', false );
			$where[] = '(CONCAT(v.title,v.description,v.meta_keywords,v.meta_description) LIKE '. $searchKey . ' OR c.name LIKE ' . $searchKey . ')';
		}

		$where = count( $where ) ? ' WHERE ' . implode( ' AND ', $where ) : '';
		$query .= $where;
		
		switch ( $orderby ) {
			case 'latest':
				$query .= ' ORDER BY v.created_date DESC';
				break;	
			case 'most_viewed':
				$query .= ' ORDER BY v.views DESC';
				break;
			case 'most_rated':
				$query .= ' ORDER BY v.rating DESC';
				break;
			case 'date_added':
				$query .= ' ORDER BY v.created_date ASC';
				break;
			case 'a_z':
				$query .= ' ORDER BY v.title ASC';
				break;
			case 'z_a':
				$query .= ' ORDER BY v.title DESC';
				break;
			case 'random':
				$query .= ' ORDER BY RAND()';
				break;
			case 'ordering':
				$query .= ' ORDER BY v.catid, v.ordering';
				break;
			default:
				$query .= ' ORDER BY v.id DESC';
		}
		 
    	$db->setQuery ( $query, $limitstart, $limit );
    	$items = $db->loadObjectList();
		 
        return $items;		
	}
	
	public function getTotal( $userid ) {	
		$app = JFactory::getApplication();
        $db = JFactory::getDbo();
		
		$query  = 'SELECT COUNT(v.id) FROM #__yendifvideoshare_videos AS v';
		$query .= ' LEFT JOIN #__yendifvideoshare_categories AS c ON v.catid=c.id';

		$where = array();
		
		$where[] = 'v.userid=' . $userid;
		$where[] = 'v.title != ' . $db->quote( '' );
		
		$this->searchKey = $app->getUserStateFromRequest( 'yendif.search.user', 'search', '', 'string' );	
		$this->searchKey = JString::strtolower( $this->searchKey );
		if ( $this->searchKey ) {
			$searchKey = $db->quote( '%' . $db->escape( $this->searchKey, true ) . '%', false );
			$where[] = '(CONCAT(v.title,v.description,v.meta_keywords,v.meta_description) LIKE '. $searchKey . ' OR c.name LIKE ' . $searchKey . ')';
		}

		$where = count( $where ) ? ' WHERE ' . implode( ' AND ', $where ) : '';
		$query .= $where;
		
        $db->setQuery( $query );
        $count = $db->loadResult();
		 
        return $count;		
	}
	
	public function getPagination( $userid ) {	
    	jimport( 'joomla.html.pagination' );
		 
		$count = $this->getTotal( $userid );
		$pagination = new JPagination( $count, $this->getState( 'limitstart' ), $this->getState( 'limit' ) );
        
		return $pagination;		 
	}	
	
	public function getCategories() {	
        $db = JFactory::getDbo();
		 
		$query = 'SELECT * FROM #__yendifvideoshare_categories WHERE published=1';
		$db->setQuery( $query );
		$mitems = $db->loadObjectList();
		
		$children = array();
		if ( $mitems ) {
			foreach ( $mitems as $v ) {
				$v->title = $v->name;
				$v->parent_id = $v->parent;
				$pt = $v->parent;				
				$list = @$children[ $pt ] ? $children[ $pt ] : array();
				array_push( $list, $v );
				$children[ $pt ] = $list;
			}
		}
		
		$list = JHTML::_( 'menu.treerecurse', 0, '', array(), $children, 9999, 0, 0 );		
		
		return $list;		 
	}
	
	public function getItem() {	
		$app = JFactory::getApplication();
		
        $row = JTable::getInstance( 'Videos', 'YendifVideoShareTable' );
        $row->load( $app->input->getInt( 'id' ) );

        return $row;		
	}
	
	public function save() {	
		$app = JFactory::getApplication();
		
		$cid = $app->input->get( 'cid', array(0), 'ARRAY' );
		$id = $cid[0];
		
	  	$row = JTable::getInstance( 'Videos', 'YendifVideoShareTable' );
      	$row->load( $id );
	
      	$post = $app->input->post->getArray();
      	if ( ! $row->bind( $post ) ) {
			$app->enqueueMessage( $row->getError(), 'error' );
	  	}	  	   	 
		 
		$row->title = YendifVideoShareUtils::safeString( $row->title );
	  	if ( ! $row->alias ) $row->alias = $row->title;		
		$row->alias = YendifVideoShareUtils::stringURLSafe( $row->alias );
		
		if ( $row->alias ) {
			$row->alias = str_replace( '-amp-', '-and-', $row->alias );
		}
		
		$row->description = $app->input->post->get( 'description', '', 'RAW' );
		
		if ( ! $row->published_up ) {
			$date = JFactory::getDate();
			$nowDate = $date->toSql();

			$row->published_up = $nowDate;
		}
		
		$msg = JText::_( 'YENDIF_VIDEO_SHARE_SAVED' );
		
		if ( isset( $post['status'] ) && 'new' == $post['status'] ) {
			$row->access   = YendifVideoShareUtils::getColumn( 'categories', 'access', $row->catid );
			$row->featured = 0;
			$row->preroll  = -1;
			$row->postroll = -1;

			$config = YendifVideoShareUtils::getConfig();

			$row->published = $config->autopublish;	
			if ( ! $row->published ) {
				$msg = JText::_( 'YENDIF_VIDEO_SHARE_WAITING_APPROVAL' );
			}	
		}
		
		if ( $row->type == 'youtube' ) {
			$v = YendifVideoShareUtils::getYouTubeVideoId( $row->youtube );

			$row->youtube = 'https://www.youtube.com/watch?v=' . $v;

			if ( ! $row->image ) {
          		$row->image = 'https://img.youtube.com/vi/' . $v . '/0.jpg';
			}
	    }
		
		if ( $row->type == 'rtmp' ) {
			$row->mp4 = $app->input->post->get( 'mobile', '', 'STRING' );
		}
		
		$row->userid = YENDIF_VIDEO_SHARE_USERID;
		
		$row->reorder( 'catid=' . $row->catid );
		 
	  	if ( ! $row->store() ){
			$app->enqueueMessage( $row->getError(), 'error' );
	  	}

		$itemId = $app->input->getInt( 'Itemid', 0 );
		$itemId = $itemId > 0 ? '&Itemid=' . $itemId : '';
		$redirectUrl = JRoute::_( 'index.php?option=com_yendifvideoshare&view=user' . $itemId, false );
		 
		$app->redirect( $redirectUrl, $msg, 'message' );		
	}	
	
	public function delete() {	
		$app = JFactory::getApplication();
        $db = JFactory::getDbo();
		 
        $id = $app->input->getInt( 'id', 0 );

        if ( $id > 0 ) {
            $query = 'DELETE FROM #__yendifvideoshare_videos WHERE id=' . $id;

            $db->setQuery( $query );
            if ( ! $db->execute() ) {
				echo "<script> alert('" . $db->getErrorMsg() . "');window.history.go(-1); </script>\n";
			} else {
				jimport( 'joomla.filesystem.folder' );

				$folder = YENDIF_VIDEO_SHARE_UPLOAD_BASE . 'videos' . DIRECTORY_SEPARATOR . $id;
				if ( JFolder::exists( $folder ) ) {
					JFolder::delete( $folder );
				}
				
				$query = 'DELETE FROM #__yendifvideoshare_ratings WHERE videoid=' . $id;

				$db->setQuery( $query );
				if ( ! $db->execute() ) {
                	echo "<script> alert('" . $db->getErrorMsg() . "');window.history.go(-1); </script>\n";
            	}
			}
        }
		
        $itemId = $app->input->getInt( 'Itemid', 0 );
		$itemId = $itemId > 0 ? '&Itemid=' . $itemId : '';
		$redirectUrl = JRoute::_( 'index.php?option=com_yendifvideoshare&view=user' . $itemId, false );
		 
		$app->redirect( $redirectUrl ); 
	}
		
}