示例#1
0
 private function getChannelId($name)
 {
     $name = trim($name);
     static $cache = array();
     if (!isset($cache[$name])) {
         $channel = Channel::model()->findByAttributes(array('name' => $name));
         if ($channel == null) {
             $channel = new Channel();
             $channel->name = $name;
             $channel->save();
         }
         $cache[$name] = $channel->id;
     }
     return $cache[$name];
 }
示例#2
0
 private function action($form)
 {
     $session = session_currentSession();
     $p = new Channel();
     $p->user = $session->id;
     $p->label = $form->name;
     $p->short_label = $form->shortname;
     $p->key = $this->generateKey();
     $p->secret = $this->generateSecret();
     $p->domain = $form->domain;
     // ISO-8601 2005-08-14T16:13:03+0000;
     $time = time() + $value;
     $p->created = date('c', $time);
     $p->save();
     //header('location:/account/settings');
 }
示例#3
0
function update_channel()
{
	global $user;
	global $CONF;

	$_SESSION['channel_last_flood_time']=time();

	$user = $_SESSION['user'];	

	$channel = new Channel();
	if (isset($_GET['channelid_update_channel'])){
		$channel->setId($_GET['channelid_update_channel']);
		$channel->load();
		if ( ($user->getId()!=$channel->getUser()->getId()) || ($user->isAnon()) )
			return array('ok'=>false, 'error'=>'you are not the owner');
	} else {
		return array('ok'=>false, 'error'=>'no id');
	}

	$description = unescape_ampersand($_POST['description']);
	$description = strip_tags($description, $CONF['permitted_tags_msg']);
	$description = text_linkify($description);
	$description = str_replace(' ',' ',$description);
	$channel->setDescription($description);

	//system("echo \"$description\" > log.txt");

	if (isset($_POST['lang']) && !empty($_POST['lang']))
		$channel->setLang($_POST['lang']);

	if (isset($_POST['asktofollow'])) $channel->setAsktofollow($_POST['asktofollow']);
	if (isset($_POST['perm_member'])) $channel->setPermMember($_POST['perm_member']);
	if (isset($_POST['perm_reguser'])) $channel->setPermReguser($_POST['perm_reguser']);
	if (isset($_POST['perm_anon'])) $channel->setPermAnon($_POST['perm_anon']);

	if ($channel->save()=='ok'){
		return array('ok'=>true, 'error'=>'');
	}
	else
		return array('ok'=>false, 'error'=>'problems with this channel');
}
示例#4
0
function add_channel()
{
	global $CONF;
	global $LANGALL;
	$user = $_SESSION['user'];

	if ($user->getBanned()>0){
		return array('ok'=>false, 'error'=>'banned '.$user->getBanned());
	}

	if (isset($_SESSION['channel_last_flood_time'])){

		if ((time() - $_SESSION['channel_last_flood_time']) < $CONF['channel_time_to_wait_flood']){
			$time_to_wait = $CONF['channel_time_to_wait_flood'] - (time() - $_SESSION['channel_last_flood_time']);
			//return array('ok'=>false, 'error'=>'flood '.$time_to_wait);
		}

	}

	$_SESSION['channel_last_flood_time']=time();

	$user = $_SESSION['user'];	
	if ($user->isAnon())
		return array('ok'=>false, 'error'=>'anonymous cannot create channel');

	$channel = new Channel();
	$channel->setUser($user);

	$name = strip_tags($_POST['name']);
	if (strlen(str_replace(' ', '', $name)) < $CONF['channel_min_name'])
		return array('ok'=>false, 'error'=>'too short name');
	$channel->setName($name);

	$description = $_POST['description'];
	$description = strip_tags($description, $CONF['permitted_tags_msg']);
	$description = text_linkify($description);
	$description = str_replace('&nbsp;',' ',$description);
	$channel->setDescription($description);

	if (isset($_POST['lang']) && !empty($_POST['lang']))
		$channel->setLang($_POST['lang']);

	if (!isset($_POST['urlname']))
		$channel->setUrlname( Channel::prettyUrlAvailable($_POST['name']) );
	else {
		if ($_POST['urlname']!=Channel::prettyUrlAvailable($_POST['urlname']))
			return array('ok'=>false, 'error'=>'invalid urlname');
		else
			$channel->setUrlname($_POST['urlname']);
	}

	if (isset($_POST['asktofollow'])) $channel->setAsktofollow($_POST['asktofollow']);
	if (isset($_POST['perm_member'])) $channel->setPermMember($_POST['perm_member']);
	if (isset($_POST['perm_reguser'])) $channel->setPermReguser($_POST['perm_reguser']);
	if (isset($_POST['perm_anon'])) $channel->setPermAnon($_POST['perm_anon']);

	$result=$channel->save();
	if ($result=='ok'){
		$channel->follow();

		/*if ($channel->getLang()=='pt_br'){
			$title=$LANGALL['pt_br']['addchannel_welcome_title'];
			$message=$LANGALL['pt_br']['addchannel_welcome_message'];
		} else {
			$title=$LANGALL['en_us']['addchannel_welcome_title'];
			$message=$LANGALL['en_us']['addchannel_welcome_message'];
		}
		require_once('class/Topic.php');
		require_once('class/User.php');
		$user=new RegUser();
		$user->setId(1);
		$topic=new Topic();
		$topic->setSubject($title);
		$topic->setMsg($message);
		$topic->setChannel($channel);
		$topic->setUser($user);
		$topic->save();*/
		
		return array('ok'=>true, 'error'=>'', 'id'=>$channel->getId());
	}
	elseif ($result=='error channel already exists'){
		return array('ok'=>false, 'error'=>'error channel already exists','id'=>null);
	} elseif ($result=='error you created many channels'){
		return array('ok'=>false, 'error'=>'error you created many channels','id'=>null);
	} elseif ($result=='error user anon'){
		return array('ok'=>false, 'error'=>'error user anon','id'=>null);
	} else
		return array('ok'=>false, 'error'=>'problems with this channel - '.$result,'id'=>null);
}
示例#5
0
 public function createWebsite()
 {
     $user_id = Auth::user()->id;
     $rules = array('title' => 'required', 'type' => 'required', 'account_id' => 'required');
     $validator = Validator::make(Input::all(), $rules);
     if ($validator->fails()) {
         return Redirect::to('/websites/new')->withErrors($validator)->withInput();
     } else {
         $client = new GuzzleHttp\Client();
         $title = Input::get('title');
         $tagline = Input::get('tagline');
         $about = Input::get('about');
         $type = Input::get('type');
         $account_id = Input::get('account_id');
         $domain_name = Input::get('domain_name');
         $is_public = 0;
         if (Input::has('public')) {
             $is_public = 1;
         }
         $website = new Website();
         $website->user_id = $user_id;
         $website->long_id = Str::slug(substr($title, 0, 160) . '-' . str_random(6));
         $website->type = $type;
         $website->domain_name = $domain_name;
         $website->title = $title;
         $website->tagline = $tagline;
         $website->about = $about;
         $website->public = $is_public;
         $website->save();
         $website_id = $website->id;
         if ($type == 'youtube') {
             $youtube = new Youtube(array('key' => Config::get('keys.youtube')));
             $youtube_channel = $youtube->getChannelByName($account_id);
             $site_channel_id = $youtube_channel->id;
             $site_channel_title = $youtube_channel->snippet->title;
             $site_channel_description = $youtube_channel->snippet->description;
             $site_channel_thumbnail = $youtube_channel->snippet->thumbnails->high->url;
         } else {
             if ($type == 'vimeo') {
                 $vimeo = $client->get("http://vimeo.com/api/v2/{$account_id}/info.json");
                 $vimeo_channel = json_decode($vimeo->getBody(), true);
                 $site_channel_id = $vimeo_channel['id'];
                 $site_channel_title = $vimeo_channel['display_name'];
                 $site_channel_description = strip_tags($vimeo_channel['bio']);
                 $site_channel_thumbnail = $vimeo_channel['portrait_huge'];
             }
         }
         $channel = new Channel();
         $channel->user_id = $user_id;
         $channel->website_id = $website_id;
         $channel->channel_id = $site_channel_id;
         $channel->title = $site_channel_title;
         $channel->description = $site_channel_description;
         $channel->thumbnail = $site_channel_thumbnail;
         $channel->save();
         $channel_id = $channel->id;
         $next_playlisttoken = '';
         if ($type == 'youtube') {
             do {
                 $playlists = $youtube->getPlaylistsByChannelId($youtube_channel->id, array('maxResults' => 50, 'pageToken' => $next_playlisttoken));
                 $next_playlisttoken = $youtube->page_info;
                 if (!empty($playlists)) {
                     foreach ($playlists as $pl) {
                         //only cached playlists that are public
                         if ($pl->status->privacyStatus == 'public') {
                             $playlist_id = $pl->id;
                             $playlist_params['body'] = array('id' => $playlist_id, 'user_id' => $user_id, 'website_id' => $website_id, 'channel_id' => $channel_id, 'title' => $pl->snippet->title, 'playlist_type' => 'youtube', 'description' => $pl->snippet->description, 'thumbnail' => $pl->snippet->thumbnails->high->url, 'published_at' => $pl->snippet->publishedAt);
                             $playlist_params['index'] = 'video-websites';
                             $playlist_params['type'] = 'playlist';
                             $playlist_params['id'] = $playlist_id;
                             $ret = Es::index($playlist_params);
                             $next_videostoken = '';
                             do {
                                 $playlist_items = $youtube->getPlaylistItemsByPlaylistId($playlist_id, array('maxResults' => 50, 'pageToken' => $next_videostoken));
                                 $next_videostoken = $youtube->page_info;
                                 if (!empty($playlist_items)) {
                                     foreach ($playlist_items as $video) {
                                         if ($video->status->privacyStatus == 'public') {
                                             $video_id = $video->id;
                                             $video_params['body'] = array('id' => $video_id, 'video_id' => $video->contentDetails->videoId, 'user_id' => $user_id, 'website_id' => $website_id, 'channel_id' => $channel_id, 'playlist_id' => $playlist_id, 'video_type' => 'youtube', 'position' => $video->snippet->position, 'title' => $video->snippet->title, 'description' => $video->snippet->description, 'thumbnails' => array('small' => $video->snippet->thumbnails->default->url, 'medium' => $video->snippet->thumbnails->medium->url, 'large' => $video->snippet->thumbnails->high->url), 'published_at' => $video->snippet->publishedAt);
                                             $video_params['index'] = 'video-websites';
                                             $video_params['type'] = 'video';
                                             $video_params['id'] = $video_id;
                                             $ret = Es::index($video_params);
                                         }
                                     }
                                 }
                             } while (is_string($next_videostoken));
                         }
                     }
                 }
             } while (is_string($next_playlisttoken));
         } else {
             if ($type == 'vimeo') {
                 $playlists_response = $client->get("http://vimeo.com/api/v2/{$account_id}/channels.json");
                 $playlists = json_decode($playlists_response->getBody(), true);
                 if (!empty($playlists)) {
                     foreach ($playlists as $pl) {
                         $playlist_id = $pl['id'];
                         $playlist_params['body'] = array('id' => $playlist_id, 'user_id' => $user_id, 'website_id' => $website_id, 'channel_id' => $channel_id, 'title' => $pl['name'], 'playlist_type' => 'vimeo', 'description' => $pl['description'], 'thumbnail' => $pl['logo'], 'published_at' => $pl['created_on']);
                         $playlist_params['index'] = 'video-websites';
                         $playlist_params['type'] = 'playlist';
                         $playlist_params['id'] = $playlist_id;
                         $ret = Es::index($playlist_params);
                         $video_page = 1;
                         $video_index = 0;
                         do {
                             $videos_response = $client->get("http://vimeo.com/api/v2/{$playlist_id}/videos.json?page={$video_page}");
                             $videos = json_decode($videos_response->getBody(), true);
                             if (!empty($videos)) {
                                 foreach ($videos as $video) {
                                     if ($video['embed_privacy'] == 'anywhere') {
                                         $video_id = $video['id'];
                                         $video_params['body'] = array('id' => $video_id, 'video_id' => $video_id, 'user_id' => $user_id, 'website_id' => $website_id, 'channel_id' => $channel_id, 'playlist_id' => $playlist_id, 'video_type' => 'vimeo', 'position' => $video_index, 'title' => $video['title'], 'description' => strip_tags($video['description']), 'thumbnails' => array('small' => $video['thumbnail_small'], 'medium' => $video['thumbnail_medium'], 'large' => $video['thumbnail_large']), 'published_at' => date('Y-m-d', strtotime($video['upload_date'])));
                                         $video_params['index'] = 'video-websites';
                                         $video_params['type'] = 'video';
                                         $video_params['id'] = $video_id;
                                         $ret = Es::index($video_params);
                                     }
                                     $video_index += 1;
                                 }
                             }
                             $video_page += 1;
                         } while (!empty($videos) && $video_page <= 3);
                     }
                 } else {
                     $video_page = 1;
                     $video_index = 0;
                     do {
                         $allvideos_response = $client->get("http://vimeo.com/api/v2/{$account_id}/all_videos.json?page={$video_page}");
                         $videos = json_decode($allvideos_response->getBody(), true);
                         if (!empty($videos)) {
                             foreach ($videos as $video) {
                                 if ($video['embed_privacy'] == 'anywhere') {
                                     $video_id = $video['id'];
                                     $video_params['body'] = array('id' => $video_id, 'video_id' => $video_id, 'user_id' => $user_id, 'website_id' => $website_id, 'channel_id' => $channel_id, 'video_type' => 'vimeo', 'position' => $video_index, 'title' => $video['title'], 'description' => strip_tags($video['description']), 'thumbnails' => array('small' => $video['thumbnail_small'], 'medium' => $video['thumbnail_medium'], 'large' => $video['thumbnail_large']), 'published_at' => date('Y-m-d', strtotime($video['upload_date'])));
                                     $video_params['index'] = 'video-websites';
                                     $video_params['type'] = 'video';
                                     $video_params['id'] = $video_id;
                                     $ret = Es::index($video_params);
                                 }
                                 $video_index += 1;
                             }
                         }
                         $video_page += 1;
                     } while (!empty($videos) && $video_page <= 3);
                 }
             }
         }
         return Redirect::to('/websites/new')->with('message', array('type' => 'success', 'text' => 'You have successfully created a website!'));
     }
 }
示例#6
0
 public function AddChannelToPoint($pointId)
 {
     $_pointId = $pointId;
     $model = new Channel();
     $res = Channel::model()->findAll('id_point=:id_point ORDER BY internalId ASC', array(':id_point' => $_pointId));
     $internalId = 1;
     if (count($res) > 0) {
         $internalId = $res[count($res) - 1]['internalId'] + 1;
     }
     $model->attributes = array('id_point' => $_pointId, 'internalId' => $internalId);
     if ($model->validate() && $model->save()) {
         $id = $model->getPrimaryKey();
         return array("status" => true, "id" => $id, "internalId" => $internalId);
     } else {
         return array("status" => false, "error" => json_encode($model->getErrors()));
     }
 }
示例#7
0
 public function CreateChannelsForWindows($screenId, $pointId)
 {
     $Screen = Screen::model()->findByPk($screenId);
     $windows = $Screen->windows;
     Channel::model()->deleteAll("id_point = :id_point AND window_id IS NOT NULL", array('id_point' => $pointId));
     $ii = 0;
     foreach ($windows as $window) {
         $ii++;
         $channel = new Channel();
         $channel->attributes = array('id_point' => $pointId, 'window_id' => $window->id, 'internalId' => $ii);
         $channel->save();
     }
 }
示例#8
0
 public function actionData()
 {
     $todo = array();
     $filename = './public/friend.txt';
     $data = file($filename);
     $data = array_map('check', $data);
     $i = 1;
     $pid = 0;
     foreach ($data as $item) {
         $channel = new Channel();
         $channel->charge = 1;
         $channel->uid = Yii::app()->user->id;
         $channel->type = Channel::CHANNEL_FREIND;
         $channel->weight = rand(1, 10);
         if (strpos($item, '.')) {
             $todo[$i]['pid'] = 0;
             $todo[$i]['name'] = str_replace('.', '', $item);
             $channel->pid = 0;
             $channel->name = str_replace('.', '', $item);
             $channel->description = '此频道提供' . $channel->name . '相关信息';
             if ($channel->save()) {
                 $pid = $channel->id;
             } else {
                 echo CHtml::errorSummary($channel);
             }
         } elseif (strpos($item, ':')) {
             $todo[$i]['name'] = str_replace(':', '', $item);
             $todo[$i]['pid'] = $pid;
             $model = Channel::model()->find(array('condition' => 'pid = :pid', 'order' => 'id DESC', 'params' => array(':pid' => 0)));
             //				UtilHelper::dump($model->attributes);
             $channel->pid = $model->id;
             $channel->name = str_replace(':', '', $item);
             $channel->description = '此频道提供' . $channel->name . '相关信息';
             if ($channel->save()) {
                 $pid = $channel->id;
             } else {
                 echo CHtml::errorSummary($channel);
             }
         } else {
             $todo[$i]['pid'] = $pid;
             $todo[$i]['name'] = $item;
             $channel->pid = $pid;
             $channel->name = $item;
             $channel->description = '此频道提供' . $channel->name . '相关信息';
             if ($channel->save()) {
                 echo CHtml::errorSummary($channel);
             }
         }
         $i++;
     }
     UtilHelper::dump($todo);
 }