repo
stringlengths
7
63
file_url
stringlengths
81
284
file_path
stringlengths
5
200
content
stringlengths
0
32.8k
language
stringclasses
1 value
license
stringclasses
7 values
commit_sha
stringlengths
40
40
retrieved_at
stringdate
2026-01-04 15:02:33
2026-01-05 05:24:06
truncated
bool
2 classes
dwightwatson/neontsunami-laravel
https://github.com/dwightwatson/neontsunami-laravel/blob/fb39bdca9f6f7794d010e1229f26ea69419af1ec/resources/views/tags/show.blade.php
resources/views/tags/show.blade.php
@extends('app') @section('content') <div class="page-header"> <h3>{{ $tag->hashtag }}</h3> </div> <p class="lead">{{ $posts->total() }} {{ str_plural('post', $posts->total()) }} found with this tag.</h4> @each('posts._post', $posts, 'post') {{ $posts->render() }} @stop
php
MIT
fb39bdca9f6f7794d010e1229f26ea69419af1ec
2026-01-05T04:41:26.570282Z
false
dwightwatson/neontsunami-laravel
https://github.com/dwightwatson/neontsunami-laravel/blob/fb39bdca9f6f7794d010e1229f26ea69419af1ec/resources/views/posts/index.blade.php
resources/views/posts/index.blade.php
@extends('app') @section('content') <div class="page-header"> <h3>Posts</h3> </div> <p class="lead">I like to document the things I learn, problems I come across and solve and thoughts about most things web related. My blog posts range usually within the realms of PHP and Ruby, with a focus on Laravel 4 and Ruby On Rails. They go into awesome new or not-well-known features of these frameworks as well as discussing some real world approaches to web development. I'm interested in developing, testing, deploying and scaling.</p> <p>If there's something you'd like me to write about, shoot me a tweet.</p> @unless ($posts->count()) <div class="alert alert-info"> <strong>Oops!</strong> There are no posts yet, please come back soon for more content. </div> @else @each('posts._post', $posts, 'post') {{ $posts->render() }} @endunless @stop
php
MIT
fb39bdca9f6f7794d010e1229f26ea69419af1ec
2026-01-05T04:41:26.570282Z
false
dwightwatson/neontsunami-laravel
https://github.com/dwightwatson/neontsunami-laravel/blob/fb39bdca9f6f7794d010e1229f26ea69419af1ec/resources/views/posts/_post.blade.php
resources/views/posts/_post.blade.php
<article class="post"> <h4 class="post-title"> <a href="{{ route('posts.show', $post) }}">{{ $post->title }}</a> </h4> <p class="post-published">Published {{ $post->published_at->diffForHumans() }}</p> <div class="post-content"> <p> {{ str_limit(strip_tags(markdown($post->content)), 500) }} <a href="{{ route('posts.show', $post) }}">Read more...</a> </p> </div> @if ($post->tags->count()) <div class="post-tags"> @foreach ($post->tags as $tag) <a href="{{ route('tags.show', $tag) }}">{{ $tag->hashtag }}</a> @endforeach </div> @endif </article>
php
MIT
fb39bdca9f6f7794d010e1229f26ea69419af1ec
2026-01-05T04:41:26.570282Z
false
dwightwatson/neontsunami-laravel
https://github.com/dwightwatson/neontsunami-laravel/blob/fb39bdca9f6f7794d010e1229f26ea69419af1ec/resources/views/posts/show.blade.php
resources/views/posts/show.blade.php
@extends('app') @section('head') <meta property="og:type" content="article"> <meta property="og:title" content="{{ $post->title }}"> <meta property="og:description" content="{{ trim(str_limit(strip_tags(markdown($post->content)), 200)) }}"> <meta property="og:url" content="{{ route('posts.show', $post) }}"> <meta property="article:published_time" content="{{ $post->published_at->toIso8601String() }}"> <meta property="article:modified_time" content="{{ $post->updated_at->toIso8601String() }}"> @foreach($post->tags as $tag) <meta property="article:tag" property="{{ $tag->name }}"> @endforeach <meta name="twitter:card" content="summary"> <meta name="twitter:site" content="@dwightconrad"> <meta name="twitter:title" content="{{ $post->title }}"> <meta name="twitter:description" content="{{ trim(str_limit(strip_tags(markdown($post->content)), 200)) }}"> @stop @section('content') <div class="page-header"> <h3>{{ $post->title }} </h3> <p class="post-published"> Posted {{ $post->published_at->diffForHumans() }} @if ($post->series) in <a href="{{ route('series.show', $post->series) }}">{{ $post->series->name }}</a> @endif </p> </div> <div class="post"> {{ markdown($post->content) }} @if ($post->tags->count()) <div class="post-tags"> @foreach ($post->tags as $tag) <a href="{{ route('tags.show', $tag) }}">{{ $tag->hashtag }}</a> @endforeach </div> @endif </div> <div class="comments"> <div id="disqus_thread"></div> <script type="text/javascript"> /* * * CONFIGURATION VARIABLES * * */ var disqus_shortname = 'neontsunami'; /* * * DON'T EDIT BELOW THIS LINE * * */ (function() { var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true; dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js'; (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq); })(); </script> <noscript>Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript" rel="nofollow">comments powered by Disqus.</a></noscript> </div> <a href="{{ route('posts.index') }}">&larr; See more posts</a> @stop
php
MIT
fb39bdca9f6f7794d010e1229f26ea69419af1ec
2026-01-05T04:41:26.570282Z
false
dwightwatson/neontsunami-laravel
https://github.com/dwightwatson/neontsunami-laravel/blob/fb39bdca9f6f7794d010e1229f26ea69419af1ec/resources/views/projects/index.blade.php
resources/views/projects/index.blade.php
@extends('app') @section('content') <div class="page-header"> <h3>Projects</h3> </div> <p class="lead">I like to contribute to open source, both in the way of relentless issues and pull-requests on other repositories, but also in the way of maintaining my own. If you use <a href="http://laravel.com/">Laravel</a> or <a href="http://ellislab.com/codeigniter">CodeIgniter</a>, I've probably got something that might be of interest to you.</p> @unless ($projects->count()) <div class="alert alert-info"> <strong>Oops!</strong> There are no project yet, please come back soon for more content. </div> @else @each('projects._project', $projects, 'project') {{ $projects->render() }} @endunless @stop
php
MIT
fb39bdca9f6f7794d010e1229f26ea69419af1ec
2026-01-05T04:41:26.570282Z
false
dwightwatson/neontsunami-laravel
https://github.com/dwightwatson/neontsunami-laravel/blob/fb39bdca9f6f7794d010e1229f26ea69419af1ec/resources/views/projects/show.blade.php
resources/views/projects/show.blade.php
@extends('app') @section('content') <div class="page-header"> <h3>{{ $project->name }}</h3> </div> <p class="lead">{{ markdown($project->description) }}</p> <a href="{{ $project->url }}" title="{{ $project->name }}" target="_blank">See this project <span class="glyphicon glyphicon-chevron-right"></span></a> @stop
php
MIT
fb39bdca9f6f7794d010e1229f26ea69419af1ec
2026-01-05T04:41:26.570282Z
false
dwightwatson/neontsunami-laravel
https://github.com/dwightwatson/neontsunami-laravel/blob/fb39bdca9f6f7794d010e1229f26ea69419af1ec/resources/views/projects/_project.blade.php
resources/views/projects/_project.blade.php
<div class="project"> <h4 class="project-name"> <a href="{{ route('projects.show', $project) }}">{{ $project->name }}</a> </h4> {{ markdown(str_limit($project->description, 200)) }} </div>
php
MIT
fb39bdca9f6f7794d010e1229f26ea69419af1ec
2026-01-05T04:41:26.570282Z
false
dwightwatson/neontsunami-laravel
https://github.com/dwightwatson/neontsunami-laravel/blob/fb39bdca9f6f7794d010e1229f26ea69419af1ec/resources/views/series/_series.blade.php
resources/views/series/_series.blade.php
<div class="series"> <h4 class="series-name"> <a href="{{ route('series.show', $series) }}">{{ $series->name }}</a> </h4> <p class="series-posts">{{ $series->posts()->published()->count() }} {{ str_plural('post', $series->posts()->count()) }}</p> {{ markdown($series->description) }} </div>
php
MIT
fb39bdca9f6f7794d010e1229f26ea69419af1ec
2026-01-05T04:41:26.570282Z
false
dwightwatson/neontsunami-laravel
https://github.com/dwightwatson/neontsunami-laravel/blob/fb39bdca9f6f7794d010e1229f26ea69419af1ec/resources/views/series/index.blade.php
resources/views/series/index.blade.php
@extends('app') @section('content') <div class="page-header"> <h3>Series</h3> </div> <p class="lead">Some posts are part of an ongoing series around a certain topic. Please feel free to follow a series of blog posts if you want to learn more about it.</p> @unless ($series->count()) <div class="alert alert-info"> <strong>Oops!</strong> There are no series yet, please come back soon for more content. </div> @else @each('series._series', $series, 'series') {{ $series->render() }} @endunless @stop
php
MIT
fb39bdca9f6f7794d010e1229f26ea69419af1ec
2026-01-05T04:41:26.570282Z
false
dwightwatson/neontsunami-laravel
https://github.com/dwightwatson/neontsunami-laravel/blob/fb39bdca9f6f7794d010e1229f26ea69419af1ec/resources/views/series/show.blade.php
resources/views/series/show.blade.php
@extends('app') @section('content') <div class="page-header"> <h3>{{ $series->name }}</h3> </div> <p class="lead">{{ $series->description }}</p> <h4>{{ $posts->total() }} {{ str_plural('post', $posts->total()) }} in this series</h4> @each('posts._post', $posts, 'post') {{ $posts->render() }} <a href="{{ route('series.index') }}">Browse more series <span class="glyphicon glyphicon-chevron-right"></span></a> @stop
php
MIT
fb39bdca9f6f7794d010e1229f26ea69419af1ec
2026-01-05T04:41:26.570282Z
false
newsapps/wordpress-mtv
https://github.com/newsapps/wordpress-mtv/blob/29102ea8171e13b6e4d7fb1cc972985f343e54da/wp-plugin.php
wp-plugin.php
<?php /** * @package MTV * @version 1.0 */ /* Plugin Name: Wordpress MTV Plugin URI: http://blog.apps.chicagotribune.com Description: A simple framework for building custom apps and features on top of wordpress Author: Ryan Mark, Ryan Nagle Version: 1.0 */ include 'mtv.php'; use mtv\shortcuts; /** * Initialize the MTV framework **/ # MTV comes with an App for WordPressy stuff mtv\register_app( 'wp', dirname(__FILE__) . DIRECTORY_SEPARATOR . 'wp' ); /** * Register javascript libraries **/ $js_runtime_settings = array( 'ajaxurl' => admin_url( 'admin-ajax.php' ), 'current_blog_id' => get_current_blog_id(), 'DEBUG' => false ); if ( defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ) { wp_register_script('mtv-all', plugins_url('/mtv/devjs/mtv.js'), array('jquery'), MTV_VERSION); $js_runtime_settings['DEBUG'] = true; } else { wp_register_script('mtv-all', plugins_url('/mtv/mtv.min.js'), array('jquery'), MTV_VERSION); } wp_localize_script('mtv-all', 'WordPress', $js_runtime_settings); unset($js_runtime_settings); /** * Use the URL resolver for ajax calls **/ $handle_ajax = function() { // get the url patterns for the current theme if ( file_exists( get_stylesheet_directory() . DIRECTORY_SEPARATOR . 'urls.php' ) ) include get_stylesheet_directory() . DIRECTORY_SEPARATOR . 'urls.php'; else if ( file_exists( get_template_directory() . DIRECTORY_SEPARATOR . 'urls.php' ) ) include get_template_directory() . DIRECTORY_SEPARATOR . 'urls.php'; else if ( ! empty( $GLOBALS['ajax_url_patterns'] ) ) global $ajax_url_patterns; else throw new Exception("Can't find a urls.php file in your theme"); // Since we're doing ajax, we've already loaded $registered_apps in // our init callback and only need to resolve the url \mtv\http\urlresolver(array( 'url' => get_default( $_REQUEST, 'path', ''), 'url_patterns' => $ajax_url_patterns)); // That's all folks exit; }; add_action('wp_ajax_mtv', $handle_ajax); add_action('wp_ajax_nopriv_mtv', $handle_ajax); /** * Request handling **/ add_filter( 'query_vars', function( $vars ) { // Where we bless query vars so WP doesn't throw them out $vars[] = 'path'; return $vars; } ); add_action( 'init', function() { load_plugin_textdomain('mtv', false, basename(__DIR__) . '/locale/'); /** * If we're doing ajax, load MTV here in the init callback so * that it will be available throughout the request **/ if ( is_admin() && defined('DOING_AJAX') && DOING_AJAX == true ) { if ( !empty( $GLOBALS['apps'] ) ) mtv\load( $GLOBALS['apps'] ); } /** * Is our chosen theme an MTV theme? * Here we check to see if there is a urls.php file in the theme, then * we load the full MTV stack. If not, we don't want to hijack rewrite * rules and template selection. **/ if ( ! file_exists( get_stylesheet_directory() . DIRECTORY_SEPARATOR . 'urls.php' ) && ! file_exists( get_template_directory() . DIRECTORY_SEPARATOR . 'urls.php' ) ) { // if we're not loading the full stack, just load the basics, if we // have apps defined if ( !is_admin() && !empty( $GLOBALS['apps'] ) ) mtv\load($GLOBALS['apps']); return; } }, 999); /* * If we have urls.php files in our theme, then we have an mtv theme, so we * hijack urls and templates */ if ( file_exists( get_stylesheet_directory() . DIRECTORY_SEPARATOR . 'urls.php' ) && file_exists( get_template_directory() . DIRECTORY_SEPARATOR . 'urls.php' ) ) { /** * *_rewrite_rules * Extra "permastruct" rules are run through this filter. Extra "permastruct" rules are added * to $wp_rewrite->extra_rules_top and include rewrite rules for tags, categories, and post_formats. * This only happens while generate_rewrite_rules runs. $wp_rewrite->extra_rules_top looks like * it's typically used for 3rd party stuff, just not always. * * Anyway, it messes up our generate_rewrite_rules hook, so we have to prevent that stuff from * getting added to $wp_rewrite->extra_rules_top **/ add_filter( 'category_rewrite_rules', function() { return array(); } ); add_filter( 'post_tag_rewrite_rules', function() { return array(); } ); add_filter( 'post_format_rewrite_rules', function() { return array(); } ); /** * generate_rewrite_rules * Run immediately after WordPress generates it's rewrite rules. We'll replace all * the rules with one of ours. Our rule will route all requests into our url resolver. * We set this to run first so plugins can still add their own rules. * * P.S. $wp_rewrite is a object, so gets passed in by reference **/ add_action( 'generate_rewrite_rules', function( $wp_rewrite ) { # setup our hijack rules $mtv_rules = array(); $mtv_rules['$'] = 'index.php?path'; // Fix WP 3.3 home rewrite rule $mtv_rules['(.*)'] = 'index.php?path=$matches[1]'; # We're feeling adventurous, override wordpress' processing with ours # If we just relace $wp_rewrite->rules, we lose stuff added by other plugins # we just want to replace WordPress's default builtin stuff $wp_rewrite->rules = array_merge($wp_rewrite->extra_rules_top, $mtv_rules, $wp_rewrite->extra_rules); }, 1, 1); /** * redirect_canonical * Correct opinionated wordpress redirects **/ add_filter('redirect_canonical', function($redirect_url, $requested_url) { # Don't add trailing slashes to files. # if $redirect_url ends in '/' then if ( substr($redirect_url, -1) ) { $ext = pathinfo($requested_url,PATHINFO_EXTENSION); # if $requested_url ends in '.xml' or '.html' etc. then if ( in_array($ext, array('xml', 'html')) ) return false; } }, 10, 2); /** * Reroute the rest of the application through our url resolver **/ add_action( 'template_redirect', function() { // Where we figure out which view to use on the front end global $wp_query; // check for the path queryvar. That means we're on! if ( !($wp_query->query_vars['path'] === NULL) ) { // will work for the root path // reset wp_query's is_whatever flags and posts shortcuts\reset_wp_query(); // get the url patterns for the current theme if ( file_exists( get_stylesheet_directory() . DIRECTORY_SEPARATOR . 'urls.php' ) ) include get_stylesheet_directory() . DIRECTORY_SEPARATOR . 'urls.php'; else if ( file_exists( get_template_directory() . DIRECTORY_SEPARATOR . 'urls.php' ) ) include get_template_directory() . DIRECTORY_SEPARATOR . 'urls.php'; else throw new Exception("Can't find a urls.php file in your theme"); // whatever is in the $apps global is what we're going to load global $apps; // run MTV mtv\run( array( 'url' => $wp_query->query_vars['path'], 'url_patterns' => $url_patterns, 'apps' => $apps ) ); // That's all folks exit; } }); }
php
MIT
29102ea8171e13b6e4d7fb1cc972985f343e54da
2026-01-05T04:41:45.731026Z
false
newsapps/wordpress-mtv
https://github.com/newsapps/wordpress-mtv/blob/29102ea8171e13b6e4d7fb1cc972985f343e54da/http.php
http.php
<?php /** * @package MTV * @version 1.0 */ namespace mtv\http; use Exception, BadFunctionCallException, mtv\shortcuts; global $url_patterns; $url_patterns = array(); /** * Match a url to the associated function, then call it * Takes: * $url - url to run on, probably $_REQUEST['path'] or something * $url_patterns - url regexes and functions to pass them to **/ function urlresolver( $kwargs ) { extract( $kwargs ); if ( !isset($url) ) $url = get_default($_REQUEST, 'url', ''); if ( !isset($url_patterns) ) throw new BadFunctionCallException(__('url_patterns keyword argument required', 'mtv')); try { // Start buffering so we can toss output in case we get an exception ob_start(); if ( resolve( $url, $url_patterns ) ) { // everything worked! Flush the buffer and return ob_end_flush(); return true; } else // We didn't find any matching patterns :( So... 404! if (defined('DOING_AJAX') && DOING_AJAX) throw new AjaxHttp404; else throw new Http404; } catch (HttpException $e) { ob_end_clean(); // Our view threw an HttpException, so display it $e->display(); } catch (Exception $e) { ob_end_clean(); // Somebody threw some sort of exception, so display 500 if (defined('DOING_AJAX') && DOING_AJAX) $http_ex = new AjaxHttp500($e->getMessage(), $e->getCode(), $e); else $http_ex = new Http500($e->getMessage(), $e->getCode(), $e); $http_ex->display(); } return false; // We had some errors, so return false } function resolve($url, $url_patterns) { // collapse multidimensional $url_patterns $url_patterns = collapse_urls($url_patterns); // cycle through our patterns in order to find a view to execute foreach ($url_patterns as $pattern => $view) { if ( preg_match($pattern, $url, $matches) > 0 ) { // we found a match! // Check to see if the function exists if ( ! function_exists( $view ) ) throw new BadFunctionCallException( sprintf(__("Can't find view function: %s", 'mtv'), $view)); // pass the match array to the view function call_user_func( $view, array_slice($matches, 1) ); return true; // We're all done, so return } } return false; } function include_urls_for($app_name) { global $registered_apps; if ( isset($registered_apps[$app_name]['urls']) ) { include $registered_apps[$app_name]['urls']; return $url_patterns; } else throw new Exception(sprintf(__("MTV App %s has no urls.php", 'mtv'), $app_name)); } function collapse_urls($array) { $collapse = array(); array_walk_recursive($array, function($value, $key) use (&$collapse) { if ( !array_key_exists($key, $collapse) ) $collapse[$key] = $value; }); return $collapse; } class HttpException extends Exception { public $message = 'HTTP Error!'; public $code = null; public $error_data; public function __construct( $message=null, $error_data=null, $previous=null ) { parent::__construct($message, $this->code, $previous); $this->error_data = $error_data; } public function display_header() { switch ( $this->code ) { case '404': header( "HTTP/1.1 404 Not Found" ); break; default: header( "HTTP/1.1 500 Internal Server Error" ); } } public function display_message() { print( $this->message ); } public function display() { $this->display_header(); $this->display_message(); } } class Http404 extends HttpException { public $code = '404'; public function display_message() { global $wp_query; $wp_query->is_404 = true; if ( $this->getPrevious() ) $ex = $this->getPrevious(); else $ex = $this; shortcuts\set_query_flags(array('page', '404')); shortcuts\display_template( '404.html', array( 'exception_class' => get_class($ex), 'exception' => $ex, 'globals' => $GLOBALS, 'post' => $_POST, 'get' => $_GET, 'server' => $_SERVER ) ); exit; } } class Http500 extends HttpException { public $code = '500'; public function display_message() { shortcuts\set_query_flags('page'); if ( $this->getPrevious() ) $ex = $this->getPrevious(); else $ex = $this; shortcuts\display_template( '500.html', array( 'exception_class' => get_class($ex), 'exception' => $ex, 'globals' => $GLOBALS, 'post' => $_POST, 'get' => $_GET, 'server' => $_SERVER ) ); exit; } } class AjaxHttp500 extends HttpException { public $code = '500'; public function display_message() { $response = array( 'error' => $this->message, 'trace' => $this->getTrace(), 'data' => $this->error_data ); shortcuts\display_json($response); } } class AjaxHttp404 extends HttpException { public $code = '404'; public function display_message() { $response = array( 'exception' => $this, 'error' => __('Callback not found', 'mtv'), ); shortcuts\display_json($response); } }
php
MIT
29102ea8171e13b6e4d7fb1cc972985f343e54da
2026-01-05T04:41:45.731026Z
false
newsapps/wordpress-mtv
https://github.com/newsapps/wordpress-mtv/blob/29102ea8171e13b6e4d7fb1cc972985f343e54da/models.php
models.php
<?php /** * Models * A bunch of classes that standardize access to WordPress data. Model based, similar * to Django, Backbone or Rails. Heavily inspired by Backbone's models and collections. * TODO: Use more references in order to save memory **/ namespace mtv\models; use Iterator, ArrayAccess, Countable, Exception, LogicException, BadMethodCallException, JsonableException, NotImplementedException; use mtv\shortcuts; /** * Model class * * You can access the fields on a model object in the following ways: * $post->field_name; * $post->attributes['field_name']; * * If you need an array of the fields on a model object, do this: * $data = $post->attributes; **/ class Model { // Where the model's data is stored public $attributes = array(); // Default model data used when a new model is created public $defaults = array(); // Attributes that are OK to send over the wire public $json_fields = array(); // Attributes that can be updated over the wire public $editable_json_fields = array(); // WP Object Cache groups this model is associated with public $cache_groups = array(); public static $collection = 'mtv\models\Collection'; // Is this model's data sync'd with the DB? protected $_synchronized = false; // Attributes that have been changed since the last save or fetch protected $_previous_attributes = array(); public function __construct( $args=array() ) { $this->initialize( $args ); if ( empty($this->defaults) ) $this->set( $args ); else $this->set( array_merge($this->defaults, $args) ); } /** * Write the data in this model to permanent storage **/ public function save() { throw new NotImplementedException(); } /** * Validate the data in this model **/ public function validate() { throw new NotImplementedException(); } /** * Call initialize when the model is created **/ public function initialize( $args ) {} public function __toString() { return get_called_class(); } public function __get($name) { return $this->attributes[$name]; } public function __set( $name, $val ) { $this->set( array( $name => $val ) ); } public function __unset( $name ) { $this->clear( $name ); } public function __isset( $name ) { return isset($this->attributes[$name]); } /** * Delete all the attributes in this model **/ public function clear() { // TODO: update $this->_previous_attributes with removed items foreach ( func_get_args() as $arg ) { $this->_previous_attributes[$arg] = $this->attributes[$arg]; unset( $this->attributes[$arg] ); } } /** * Set a bunch of attributes at once **/ public function set( $args, $fetching=false ) { $this->attributes = array_merge( $this->attributes, (array) $args ); } /** * Populate this model from permanent storage **/ public function fetch() { // get my attributes from the db // $from_db = new Object; // pass the results to reload // $this->reload( $from_db ); throw new NotImplementedException(); } /** * Process the raw data from permanent storage **/ public function parse( &$data ) { // Make sure we have an array and not an object if ( is_object($data) ) return (array) $data; else return $data; } /** * Update this model with data from permanent storage **/ public function reload( &$data ) { // Parse raw data from the DB $tmp =& $this->parse($data); // Reset any change tracking $this->_previous_attributes = array(); $this->_synchronized = true; // Set the attributes $this->set( $tmp, true ); } /** * Returns an array of selected values * TODO: Return all values if no params are given **/ public function values(/* $key [,$key [,$key ...] ] */) { $keys = func_get_args(); $ret = array(); foreach ( $keys as $key ) $ret[] = $this->$key; return $ret; } /** * Returns an assoc array of this model's data to send over the wire **/ public function to_json() { // decide which fields to send over the wire if ( empty( $this->json_fields ) ) return $this->attributes; else { $ret = array(); foreach ( $this->json_fields as $k ) $ret[$k] = $this->attributes[$k]; return $ret; } } /** * Create a new model from json data sent over the wire **/ public static function from_json( &$data ) { $class = get_called_class(); $obj = new $class; $obj->set_from_json($data); return $obj; } /** * Update this model from json data sent over the wire **/ public function set_from_json( &$data ) { // decide which fields to use from the wire $new_data = (array) json_decode( stripslashes( $data ), true ); if ( empty( $this->editable_json_fields ) ) $this->set( $new_data ); else { foreach ( $new_data as $k=>$v ) if ( in_array($k, $this->editable_json_fields) ) $this->$k = $v; } } } class Collection implements Iterator, ArrayAccess, Countable { public $models = array(); public static $model = 'mtv\models\Model'; public static $default_filter = array(); public function __construct( $array=array() ) { foreach ( $array as $args ) { array_push( $this->models, new static::$model( $args ) ); } } /** * Makes a collection iterable like an array **/ public function current() { return current( $this->models ); } public function next() { return next( $this->models ); } public function key() { return key( $this->models); } public function valid() { $key = key( $this->models ); return ($key !== NULL && $key !== FALSE); } public function rewind() { reset( $this->models ); } /** * ArrayAccess interface * Makes a collection object addressable like an array **/ public function offsetExists( $offset ) { return isset( $this->models[$offset] ); } public function offsetGet( $offset ) { return isset( $this->models[$offset] ) ? $this->models[$offset] : null; } public function offsetSet( $offset, $value ) { if (is_null($offset)) $this->models[] = $value; else $this->models[$offset] = $value; } public function offsetUnset( $offset ) { unset($this->models[$offset]); } /** * Countable interface * Makes `count($collection)` work **/ public function count() { return count($this->models); } /** * Add a model instance to this collection **/ public function add( $model ) { $this->models[] =& $model; } /** * Remove all model instances from this collection **/ public function clear() { $this->models = array(); } /** * Return specific values from all the model instances in this collection * TODO: Return all values if no params are given **/ public function values(/* $key [,$key [,$key ...] ] */) { $keys = func_get_args(); $ret = array(); foreach ( $this->models as $model ) { $row = array(); foreach ( $keys as $key ) $row[] = $model->$key; $ret[] = $row; } return $ret; } /** * Return the results of calling `to_json` on all the model instances in this collection **/ public function to_json() { $tmp_array = array(); foreach ($this->models as $model) { array_push($tmp_array, $model->to_json()); } return $tmp_array; } /** * Create, fetch and return a single model instance with primary keys **/ public static function get( $args ) { $model = new static::$model( $args ); $model->fetch(); return $model; } /** * Create, fetch and return a single model instances based on some unique keys **/ public static function get_by( $args ) { throw new NotImplementedException(); } /** * Return a collection containing all model instances **/ public static function all() { return static::filter(array()); } /** * Return a collection containing model instances matching certian criteria **/ public static function filter( $args ) { throw new NotImplementedException(); } } /** * Model exceptions **/ class ModelParseException extends JsonableException {} class ModelNotFound extends JsonableException { public $class_name; public function __construct( $class_name, $message = "", $code = 0, $previous = NULL ) { parent::__construct( $message, $code, $previous ); $this->class_name = $class_name; } public function to_json() { return array( 'message' => $this->message, 'code' => $this->code, 'class' => $this->class ); } }
php
MIT
29102ea8171e13b6e4d7fb1cc972985f343e54da
2026-01-05T04:41:45.731026Z
false
newsapps/wordpress-mtv
https://github.com/newsapps/wordpress-mtv/blob/29102ea8171e13b6e4d7fb1cc972985f343e54da/shortcuts.php
shortcuts.php
<?php /** * @package MTV * @version 1.0 */ namespace mtv\shortcuts; use mtv\http\Http404; use mtv\http\Http500; use mtv\http\AjaxHttp500; use mtv\models\wp\PostCollection; use Exception; /** * Render and display a template **/ function display_template( $template_name, $context=array() ) { global $twig; if ( !is_object($twig) ) throw new Exception('Twig template engine not available'); $template = $twig->loadTemplate( $template_name ); $template->display( $context ); } /** * Render and return a template **/ function render( $template_name, $context=array() ) { global $twig; if ( !is_object($twig) ) throw new Exception('Twig template engine not available'); $template = $twig->loadTemplate( $template_name ); return $template->render( $context ); } /** * Encode and display JSON **/ function display_json($data) { header('Cache-Control: no-cache, must-revalidate'); header('Content-type: application/json'); print( json_encode( $data ) ); } /** * Check current user for a capability, throw an exception if not allowed **/ function require_capability($cap, $kwargs=null) { if ( ! empty( $kwargs['blogid'] ) ) $answer = current_user_can_for_blog( $kwargs['blogid'], $cap ); else $answer = current_user_can( $cap ); if ( ! $answer ) { if ( ! empty($kwargs['ajax']) ) throw new AjaxHttp500("You can't do that"); else throw new Exception("You can't do that"); } return true; } /** * Configure the flags in wp_query * * List of available WP query flags * $wp_query->is_single * $wp_query->is_page * $wp_query->is_archive * $wp_query->is_date * $wp_query->is_year * $wp_query->is_month * $wp_query->is_day * $wp_query->is_time * $wp_query->is_author * $wp_query->is_category * $wp_query->is_tag * $wp_query->is_tax * $wp_query->is_search * $wp_query->is_home * $wp_query->is_paged * $wp_query->is_admin * $wp_query->is_attachment * $wp_query->is_singular * $wp_query->is_404 * No case implemented for these yet: * $wp_query->is_feed * $wp_query->is_comment_feed * $wp_query->is_trackback * $wp_query->is_comments_popup * $wp_query->is_robots * $wp_query->is_posts_page * $wp_query->is_post_type_archive * $wp_query->is_preview * **/ function set_query_flags($views=null) { global $wp_query; if ($wp_query->max_num_pages > 1) $wp_query->is_paged = true; if (!is_array($views)) $views = array($views); if ($wp_query->query_vars['preview'] == true) $wp_query->is_preview = true; foreach ($views as $view) { switch ($view) { case '404': $wp_query->is_404 = true; break; case 'home': $wp_query->is_home = true; break; case 'search': $wp_query->is_search = true; break; case 'date': $wp_query->is_date = true; $wp_query->is_archive = true; break; case 'year': $wp_query->is_year = true; $wp_query->is_archive = true; break; case 'month': $wp_query->is_month = true; $wp_query->is_archive = true; break; case 'day': $wp_query->is_day = true; $wp_query->is_archive = true; break; case 'time': $wp_query->is_time = true; $wp_query->is_archive = true; break; case 'author': $wp_query->is_author = true; $wp_query->is_archive = true; break; case 'category': $wp_query->is_category = true; $wp_query->is_archive = true; break; case 'tag': $wp_query->is_tag = true; $wp_query->is_archive = true; break; case 'tax': $wp_query->is_tax = true; $wp_query->is_archive = true; break; case 'archive': $wp_query->is_archive = true; break; case 'single': $wp_query->is_single = true; $wp_query->is_singular = true; break; case 'attachment': $wp_query->is_attachment = true; break; case 'page': $wp_query->is_page = true; break; default: // stuff like our directory and pitch // page will end up here. $wp_query->is_page = true; } } } /** * Reset all of the $wp_query->is_blah flags and clear $wp_query->posts. Preps for * our url resolver **/ function reset_wp_query() { global $wp_query; // Reset query flags $wp_query->is_single = false; $wp_query->is_preview = false; $wp_query->is_page = false; $wp_query->is_archive = false; $wp_query->is_date = false; $wp_query->is_year = false; $wp_query->is_month = false; $wp_query->is_day = false; $wp_query->is_time = false; $wp_query->is_author = false; $wp_query->is_category = false; $wp_query->is_tag = false; $wp_query->is_tax = false; $wp_query->is_search = false; $wp_query->is_feed = false; $wp_query->is_comment_feed = false; $wp_query->is_trackback = false; $wp_query->is_home = false; $wp_query->is_404 = false; $wp_query->is_comments_popup = false; $wp_query->is_paged = false; $wp_query->is_admin = false; $wp_query->is_attachment = false; $wp_query->is_singular = false; $wp_query->is_robots = false; $wp_query->is_posts_page = false; $wp_query->is_post_type_archive = false; if (!empty($wp_query->posts)) unset($wp_query->posts); } /** * Return a Mysql date string or unix timestamp for the current local time **/ function current_time( $type, $gmt = 0 ) { $t = ( $gmt ) ? gmdate( 'Y-m-d H:i:s' ) : gmdate( 'Y-m-d H:i:s', ( time() + ( get_option( 'gmt_offset' ) * 3600 ) ) ); switch ( $type ) { case 'mysql': return $t; break; case 'timestamp': return strtotime($t); break; } }
php
MIT
29102ea8171e13b6e4d7fb1cc972985f343e54da
2026-01-05T04:41:45.731026Z
false
newsapps/wordpress-mtv
https://github.com/newsapps/wordpress-mtv/blob/29102ea8171e13b6e4d7fb1cc972985f343e54da/utils.php
utils.php
<?php /** * @package MTV * @version 1.0 */ // function exception_error_handler($errno, $errstr, $errfile, $errline ) { // throw new ErrorException($errstr, 0, $errno, $errfile, $errline); // } // set_error_handler("exception_error_handler"); /** * Check for an array item, return $default if it's empty **/ function get_default($array, $key, $default="") { return empty($array[$key]) ? $default : $array[$key]; } /** * Dump the contents of a variable to the error log. works * like var_dump. **/ function var_log( $stuff ) { error_log( stripslashes(var_export( $stuff, true )) ); } class NotImplementedException extends LogicException {} class WPException extends JsonableException { public $wp_error; public function __construct( $wp_error ) { parent::__construct( $wp_error->get_error_message() ); $this->wp_error = $wp_error; } public function __call( $method, $args ) { return call_user_func_array(array($this->wp_error, $name), $args); } public function to_json() { return array_merge(parent::to_json(), array( 'codes' => $this->wp_error->get_error_codes(), 'messages' => $this->wp_error->get_error_messages() )); } } class JsonableException extends Exception { public function to_json() { return array( 'message' => $this->message, 'code' => $this->code ); } }
php
MIT
29102ea8171e13b6e4d7fb1cc972985f343e54da
2026-01-05T04:41:45.731026Z
false
newsapps/wordpress-mtv
https://github.com/newsapps/wordpress-mtv/blob/29102ea8171e13b6e4d7fb1cc972985f343e54da/mtv.php
mtv.php
<?php namespace mtv; require __DIR__ . '/../../vendor/autoload.php'; use Twig_Autoloader, Twig_Environment, Twig_Loader_Filesystem, Exception, mtv\http; define("MTV_VERSION", "1.0.0"); # For a plugin or theme, i need to load: # urls # models # views # templates $GLOBALS['registered_apps'] = array(); function register_app( $name, $path ) { $views_file = $path . '/views.php'; $urls_file = $path . '/urls.php'; $models_file = $path . '/models.php'; $template_dir = $path . '/templates'; $tags_file = $path . '/templatetags/tags.php'; $funcs_file = $path . '/templatetags/functions.php'; $filter_file = $path . '/templatetags/filters.php'; $app_data = array(); if ( file_exists($views_file) ) $app_data['views'] = $views_file; if ( file_exists($urls_file) ) $app_data['urls'] = $urls_file; if ( file_exists($models_file) ) $app_data['models'] = $models_file; if ( file_exists($template_dir) ) $app_data['templates'] = $template_dir; if ( file_exists($tags_file) ) $app_data['tags'] = $tags_file; if ( file_exists($funcs_file) ) $app_data['functions'] = $funcs_file; if ( file_exists($filter_file) ) $app_data['filters'] = $filter_file; global $registered_apps; $registered_apps[$name] = $app_data; } /** * load MTV * Takes: * $apps - MTV apps to load. Apps must be registered. Loads in order. **/ function load( $apps ) { global $registered_apps; if ( empty($apps) ) throw new Exception( "No apps have been specified" ); # load our models, views and templates $template_dirs = array(); foreach ( $apps as $name ) { $app = $registered_apps[$name]; if ( $app['views'] ) include_once $app['views']; if ( $app['models'] ) include_once $app['models']; if ( $app['templates'] ) array_push($template_dirs, $app['templates']); } # Time to initialize our template engine Twig_Autoloader::register(); global $twig; if (empty($twig)) { $loader = new Twig_Loader_Filesystem($template_dirs); if ( DEPLOYMENT_TARGET == "development" ) { $twig = new Twig_Environment($loader, array('debug' => true)); } else { $cache_dir = '/tmp/mtv_tmpl_cache'; if ( ini_get('safe_mode') ) { $cache_dir = __DIR__.'/tmp/mtv_tmpl_cache'; } # TODO: get a temp directory from php to use for caching $twig = new Twig_Environment($loader, array( 'cache' => $cache_dir, 'auto_reload' => true )); } } else throw new Exception("MTV is already loaded!"); # now that we have a template engine, load some goodies foreach ( $apps as $name ) { $app = $registered_apps[$name]; if ( $app['tags'] ) include_once $app['tags']; if ( $app['functions'] ) include_once $app['functions']; if ( $app['filters'] ) include_once $app['filters']; } } /** * run MTV * Takes: * $url - url to run on, probably $_REQUEST['path'] or something * $url_patterns - url regexes and functions to pass them to * $apps - MTV apps to load. Apps must be registered. Loads in order. **/ function run( $kwargs ) { extract( $kwargs ); load( $apps ); # What's the url for this request? if ( ! $url ) $url = $_REQUEST['path']; # globalize our $url_patterns if ( $url_patterns ) $GLOBALS['url_patterns'] = $url_patterns; # oh, right, we gotta do something with our url http\urlresolver( array('url'=>$url, 'url_patterns'=>$url_patterns) ); # Smell ya later. exit; } # load the rest of MTV include('utils.php'); include('http.php'); include('shortcuts.php'); include('models.php');
php
MIT
29102ea8171e13b6e4d7fb1cc972985f343e54da
2026-01-05T04:41:45.731026Z
false
newsapps/wordpress-mtv
https://github.com/newsapps/wordpress-mtv/blob/29102ea8171e13b6e4d7fb1cc972985f343e54da/tests/test_collection.php
tests/test_collection.php
<?php require_once 'lib/mtv_test_classes.php'; class MTVCollectionTest extends MTVTest { public function setUp() { // Initialize a bare Collection $this->collection = new \mtv\models\Collection; } public function test_current() { // Bare Collection is initialized with no models $ret = $this->collection->current(); $this->assertEquals($ret, false); } public function test_next() { // Shouldn't be any models to iterate over $ret = $this->collection->next(); $this->assertEquals($ret, false); // Add two models and test $this->collection->add( new \mtv\models\Model(array('name' => 'one'))); $this->collection->add( new \mtv\models\Model(array('name' => 'two'))); $ret = $this->collection->next(); // Forward one $this->assertEquals($ret->attributes['name'], 'two'); } public function test_key() { $ret = $this->collection->key(); $this->assertEquals($ret, null); } public function test_valid() { $this->markTestIncomplete('This test has not been implemented yet.'); } public function test_rewind() { // Shouldn't be any models to iterate over $ret = $this->collection->rewind(); $this->assertEquals($ret, false); // Add two models and test $this->collection->add( new \mtv\models\Model(array('name' => 'one'))); $this->collection->add( new \mtv\models\Model(array('name' => 'two'))); $ret = $this->collection->next(); // Forward one $ret = $this->collection->rewind(); // Back one $this->assertEquals($ret->attributes['name'], 'one'); } public function test_offsetExists() { $this->markTestIncomplete('This test has not been implemented yet.'); } public function test_offsetGet() { $this->markTestIncomplete('This test has not been implemented yet.'); } public function test_offsetSet() { $this->markTestIncomplete('This test has not been implemented yet.'); } public function test_offsetUnset() { $this->markTestIncomplete('This test has not been implemented yet.'); } public function test_count() { $ret = $this->collection->count(); $this->assertEquals($ret, 0); } public function test_add() { $this->collection->add(new \mtv\models\Model); $this->assertEquals(count($this->collection->models), 1); $this->assertTrue( is_a($this->collection->models[0], 'mtv\models\Model')); } public function test_clear() { // Add a model $this->collection->add(new \mtv\models\Model); // Clear all $this->collection->clear(); // Expect an empty array $this->assertEquals($this->collection->models, array()); } public function test_to_json() { // Add empty Model $this->collection->add(new \mtv\models\Model); $ret = $this->collection->to_json(); // to_json should return an array with one empty array $this->assertEquals($ret, array(array())); } public function test_get() { /* * Collection::get() calls its static model's fetch() * method. In this case, the base Model's fetch * method is not implemented and throws an exception. * TODO: Figure a way to avoid the exception and test * the expected return value of Collection::get() */ $this->markTestIncomplete('This test has not been implemented yet.'); } public function test_get_by() { try { $this->collection->get_by(array()); } catch (NotImplementedException $expected) { return; } $this->fail('An expected NotImplementedException has not been raised.'); } public function test_filter() { try { $this->collection->filter(array()); } catch (NotImplementedException $expected) { return; } $this->fail('An expected NotImplementedException has not been raised.'); } }
php
MIT
29102ea8171e13b6e4d7fb1cc972985f343e54da
2026-01-05T04:41:45.731026Z
false
newsapps/wordpress-mtv
https://github.com/newsapps/wordpress-mtv/blob/29102ea8171e13b6e4d7fb1cc972985f343e54da/tests/test_core.php
tests/test_core.php
<?php require_once 'lib/mtv_test_classes.php'; class MTVCoreTest extends MTVTest { public function setUp() { check_before_wreck(); reset_app_globals(); } public function test_register_app() { global $registered_apps; \mtv\register_app('test_app', dirname(__DIR__) . '/test_app'); // Should have one app $this->assertEquals(count($registered_apps), 1); // App name should be 'test_app' $this->assertTrue(array_key_exists('test_app', $registered_apps)); } public function test_load() { global $twig, $apps; // Register and load test_app \mtv\register_app('test_app', dirname(__FILE__) . '/test_app'); $apps = array('test_app'); \mtv\load($apps); // Make sure test_app home view function is loaded $this->assertTrue(function_exists('test_app\views\home')); // Make sure test_app TestModel class is loaded $this->assertTrue(class_exists('test_app\models\TestModel')); // Make sure Twig was reinitialized $this->assertTrue(!empty($twig)); } public function test_run() { /* * NOTE: This test checks functionality of * the http.php lib. If these tests pass, * we can consider the http lib functionally sound. * TODO: Unit tests for http.php functions. */ // Request the home page $result = $this->http_get('/'); $this->assertEquals($result, 200); // Request non-existent page $result = $this->http_get('/404'); $this->assertEquals($result, 404); } }
php
MIT
29102ea8171e13b6e4d7fb1cc972985f343e54da
2026-01-05T04:41:45.731026Z
false
newsapps/wordpress-mtv
https://github.com/newsapps/wordpress-mtv/blob/29102ea8171e13b6e4d7fb1cc972985f343e54da/tests/test_model.php
tests/test_model.php
<?php require_once 'lib/mtv_test_classes.php'; class MTVModelTest extends MTVTest { public function setUp() { check_before_wreck(); $this->model = new \mtv\models\Model( array('name' => 'test_model') ); } public function test_save() { try { $this->model->save(); } catch (NotImplementedException $expected) { return; } $this->fail('An expected NotImplementedException has not been raised.'); } public function test_validate() { try { $this->model->save(); } catch (NotImplementedException $expected) { return; } $this->fail('An expected NotImplementedException has not been raised.'); } public function test_initialize() { $this->markTestIncomplete('This test has not been implemented yet.'); } public function test___toString() { $ret = $this->model->__toString(); $this->assertEquals($ret, 'mtv\models\Model'); } public function test___get() { $ret = $this->model->__get('name'); $this->assertEquals($ret, 'test_model'); } public function test___set() { $this->model->__set('name', 'name_changed_with_set'); $this->assertEquals($this->model->attributes['name'], 'name_changed_with_set'); } public function test___unset() { $this->model->__unset('name'); $this->assertTrue(empty($this->model->attributes['name'])); } public function test___isset() { $ret = $this->model->__isset('name'); $this->assertTrue($ret); } public function test_clear() { $this->markTestIncomplete('This test has not been implemented yet.'); } public function test_set() { // Set attribute values, verify $attrs = array( 'name' => 'changed_name', 'note' => 'Just a test' ); $this->model->set($attrs); $this->assertEquals($this->model->attributes['name'], 'changed_name'); $this->assertEquals($this->model->attributes['note'], 'Just a test'); } public function test_fetch() { $this->markTestIncomplete('This test has not been implemented yet.'); } public function test_parse() { $this->markTestIncomplete('This test has not been implemented yet.'); } public function test_reload() { $this->markTestIncomplete('This test has not been implemented yet.'); } public function test_to_json() { // Return assoc array of jsonable fields for passing to json_encode() $this->model->json_fields = array('name'); $ret = $this->model->to_json(); $this->assertEquals($ret, array('name' => 'test_model')); } public function test_set_from_json() { // Provide data for the model as a json string, // check that the attributes are set properly $json = '{"name": "changed_name_with_json"}'; $this->model->set_from_json($json); $this->assertEquals( $this->model->attributes['name'], 'changed_name_with_json'); } }
php
MIT
29102ea8171e13b6e4d7fb1cc972985f343e54da
2026-01-05T04:41:45.731026Z
false
newsapps/wordpress-mtv
https://github.com/newsapps/wordpress-mtv/blob/29102ea8171e13b6e4d7fb1cc972985f343e54da/tests/run_all_tests.php
tests/run_all_tests.php
<?php /* * PHPUnit is required in order to run these tests. * You can install PHPUnit by running requirements.sh * packaged with MTV. * * You'll also need to edit the accompanying settings.json file * in this directory and update the hostname of the WordPress * install you're using to run these tests. * * Note: if you encounter errors and/or failures when * running tests, you should try fixing errors first. They're * usually easier to tackle and might resolve failures. */ require_once 'lib/cli-load.php'; require_once 'PHPUnit/Autoload.php'; require_once 'PHPUnit/Util/ErrorHandler.php'; // All tests $tests = array(); // Printer object will eventually print results $printer = new PHPUnit_TextUI_ResultPrinter( NULL, true, !stristr(PHP_OS, 'WIN')); // Results object tracks results for all tests $result = new PHPUnit_Framework_TestResult; $result->addListener($printer); // Test core MTV functions require_once 'test_core.php'; $tests['MTVCoreTest'] = new PHPUnit_Framework_TestSuite('MTVCoreTest'); // Test MTV's http lib require_once 'test_http.php'; $tests['MTVHttpTest'] = new PHPUnit_Framework_TestSuite('MTVHttpTest'); // Test Model model require_once 'test_model.php'; $tests['MTVModelTest'] = new PHPUnit_Framework_TestSuite('MTVModelTest'); // Test Collection model require_once 'test_collection.php'; $tests['MTVCollectionTest'] = new PHPUnit_Framework_TestSuite('MTVCollectionTest'); // TODO: // Test Post model // Stub // Test PostCollection model // Stub // Test User model // Stub // Test UserCollection model // stub // Test Site model // stub // Test SiteCollection model // stub // Add above test suites to master suite and run, printing the result $suite = new PHPUnit_Framework_TestSuite(); foreach ($tests as $k => $v) $suite->addTestSuite($k); $suite->run($result); $printer->printResult($result);
php
MIT
29102ea8171e13b6e4d7fb1cc972985f343e54da
2026-01-05T04:41:45.731026Z
false
newsapps/wordpress-mtv
https://github.com/newsapps/wordpress-mtv/blob/29102ea8171e13b6e4d7fb1cc972985f343e54da/tests/test_http.php
tests/test_http.php
<?php require_once 'lib/mtv_test_classes.php'; /* * TODO: Fill in the stubbed tests below. */ class MTVHttpTest extends MTVOutputTest { public function test_resolve() { $this->markTestIncomplete('This test has not been implemented yet.'); } public function test_urlresolver() { $this->markTestIncomplete('This test has not been implemented yet.'); } public function test_include_urls_for() { $this->markTestIncomplete('This test has not been implemented yet.'); } }
php
MIT
29102ea8171e13b6e4d7fb1cc972985f343e54da
2026-01-05T04:41:45.731026Z
false
newsapps/wordpress-mtv
https://github.com/newsapps/wordpress-mtv/blob/29102ea8171e13b6e4d7fb1cc972985f343e54da/tests/test_app/models.php
tests/test_app/models.php
<?php namespace test_app\models; use mtv\models\Model; class TestModel extends Model {}
php
MIT
29102ea8171e13b6e4d7fb1cc972985f343e54da
2026-01-05T04:41:45.731026Z
false
newsapps/wordpress-mtv
https://github.com/newsapps/wordpress-mtv/blob/29102ea8171e13b6e4d7fb1cc972985f343e54da/tests/test_app/urls.php
tests/test_app/urls.php
<?php $url_patterns = array( '/^$/' => 'test_app\views\home', );
php
MIT
29102ea8171e13b6e4d7fb1cc972985f343e54da
2026-01-05T04:41:45.731026Z
false
newsapps/wordpress-mtv
https://github.com/newsapps/wordpress-mtv/blob/29102ea8171e13b6e4d7fb1cc972985f343e54da/tests/test_app/views.php
tests/test_app/views.php
<?php namespace test_app\views; function home() { print "OK: Home"; }
php
MIT
29102ea8171e13b6e4d7fb1cc972985f343e54da
2026-01-05T04:41:45.731026Z
false
newsapps/wordpress-mtv
https://github.com/newsapps/wordpress-mtv/blob/29102ea8171e13b6e4d7fb1cc972985f343e54da/tests/lib/cli-load.php
tests/lib/cli-load.php
<?php /* * This script loads WordPress for use in cli */ if ( !defined('STDIN') ) die("Please run this script from the command line."); $settings_file = 'settings.json'; global $settings; $settings_path = dirname( __DIR__ ) .'/'. $settings_file; $settings = json_decode( file_get_contents( $settings_path ), true ); define('DOING_AJAX', true); define('WP_USE_THEMES', false); global $_SERVER; $_SERVER["HTTP_HOST"] = $settings['hostname']; $_SERVER["SERVER_NAME"] = $settings['hostname']; $_SERVER["REQUEST_URI"] = "/cli"; $_SERVER["REQUEST_METHOD"] = "GET"; $abspath = dirname(dirname(dirname(dirname(dirname(dirname(__FILE__)))))); define( 'ABSPATH', $abspath . '/' ); require_once(ABSPATH.'wp-config.php'); if ( ! defined('WP_SITEURL') ) define( 'WP_SITEURL', "http://".$settings['hostname']);
php
MIT
29102ea8171e13b6e4d7fb1cc972985f343e54da
2026-01-05T04:41:45.731026Z
false
newsapps/wordpress-mtv
https://github.com/newsapps/wordpress-mtv/blob/29102ea8171e13b6e4d7fb1cc972985f343e54da/tests/lib/mtv_test_classes.php
tests/lib/mtv_test_classes.php
<?php require_once 'PHPUnit/Autoload.php'; require_once 'PHPUnit/Util/ErrorHandler.php'; class MTVTest extends PHPUnit_Framework_TestCase { protected $backupGlobals = false; protected $backupStaticAttributes = false; public function setUp() { // Make sure we have a WP install and MTV is active check_before_wreck(); } public function http_get($route = '') { global $settings; $ch = curl_init(); curl_setopt( $ch, CURLOPT_URL, 'http://' . $settings['hostname'] . '/' . $route); curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_exec($ch); $result = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); return $result; } } class MTVOutputTest extends PHPUnit_Extensions_OutputTestCase { protected $backupGlobals = false; protected $backupStaticAttributes = false; public function setUp() { // Make sure we have a WP install and MTV is active check_before_wreck(); } } function check_before_wreck() { require_once dirname(__FILE__) . '/cli-load.php'; $plugin_file = ABSPATH . 'wp-admin/includes/plugin.php'; // Check for WordPress if (file_exists($plugin_file)) require_once $plugin_file; else throw new Exception('Tests require a working installation of WordPress.'); // Make sure plugin is active if (!is_plugin_active('mtv/wp-plugin.php')) throw new Exception('Tests require MTV plugin is installed and activated.'); } function reset_app_globals() { global $registered_apps, $twig, $apps; // Reset registered and installed apps $apps = array(); $registered_apps = array(); $twig = null; }
php
MIT
29102ea8171e13b6e4d7fb1cc972985f343e54da
2026-01-05T04:41:45.731026Z
false
newsapps/wordpress-mtv
https://github.com/newsapps/wordpress-mtv/blob/29102ea8171e13b6e4d7fb1cc972985f343e54da/wp/models.php
wp/models.php
<?php /** * @package MTV * @version 1.0 */ namespace mtv\wp\models; use mtv\models\Model, mtv\models\Collection, mtv\models\ModelParseException, mtv\models\ModelNotFound, WPException, JsonableException, BadMethodCallException, WP_Query; /** * Wordpress models **/ /** * Post Model * * Core post fields directly from WordPress: * id // ID of the post * post_author // ID of the post author * post_date // timestamp in local time * post_date_gmt // timestamp in gmt time * post_content // Full body of the post * post_title // title of the post * post_excerpt // excerpt field of the post, caption if attachment * post_status // post status: publish, new, pending, draft, auto-draft, future, private, inherit, trash * comment_status // comment status: open, closed * ping_status // ping/trackback status * post_password // password of the post * post_name // post slug, string to use in the URL * to_ping // to ping ?? * pinged // pinged ?? * post_modified // timestamp in local time * post_modified_gmt // timestatmp in gmt tim * post_content_filtered // filtered content ?? * post_parent // id of the parent post, if attachment, id of the post that uses this image * guid // global unique id of the post * menu_order // menu order * post_type // type of post: post, page, attachment, or custom string * post_mime_type // mime type for attachment posts * comment_count // number of comments * filter // filter ?? * * Special MTV fields: * post_meta // an array containing all of the meta for this post * blogid // id number of the blog this post lives on * post_format // the post_format for this post * url // attachments only, url of the original uploaded image or whatever * thumb_url // attachments only, url of the thumbnail image, if thumbnails are enabled * * Post object functions * password_required() * Whether post requires password and correct password has been provided. * is_sticky() * Check if post is sticky. * post_class() * Retrieve the classes for the post div as an array. * permalink() * permalink for this post, from WP get_permalink() * categories() * returns an array of categories that are associated with this post * tags() * returns an array of tags that are associated with this post * featured_image() * Returns a Post object representing the featured image * attachments( $extra_query_args ) * Returns a PostCollection object representing attachments (gallery images) * the_time( $format ) * Returns a formatted date string. Works like WordPress's 'the_time'. * the_date( $format ) * Returns a formatted date string. Works like WordPress's 'the_date'. * make_excerpt( $more_text ) * Returns a generated excerpt. Simliar to how WordPress makes excerpts in The Loop. **/ class Post extends Model { public $cache_groups = array( 'posts', 'post_meta', 'post_ancestors', 'post_format_relationships'); public function __toString() { return $this->attributes['post_title']; } public function save() { $data = $this->attributes; if ( ! empty($data['blogid']) ) { $blogid =& $data['blogid']; unset( $data['blogid'] ); } else $blogid = get_current_blog_id(); if ( ! empty($data['post_meta']) ) { $meta =& $data['post_meta']; unset( $data['post_meta'] ); } if ( isset($data['post_format']) ) { $post_format =& $data['post_format']; unset( $data['post_format'] ); } if ( ! empty( $data['id'] ) ) { $data['ID'] =& $data['id']; unset($data['id']); } switch_to_blog( $blogid ); $postid = wp_insert_post( $data, true ); if ( is_wp_error( $postid ) ) throw new WPException( $postid ); else if ( $postid == 0 ) throw new JsonableException(__("Couldn't update the post", 'mtv')); if ( ! empty( $meta ) ) { foreach ( $meta as $key => $val ) update_post_meta( $postid, $key, $val ); } if ( isset($post_format) ) { $result = set_post_format( $postid, $post_format ); if ( is_wp_error( $result ) ) throw new WPException( $result ); } restore_current_blog(); $this->id = $postid; # Invalidate cached data for this Post foreach ( $this->cache_groups as $cache_group ) wp_cache_delete($this->id, $cache_group); $this->fetch(); // We refresh the post in case any filters changed the content } public function fetch() { if ( empty($this->attributes['blogid']) || empty($this->attributes['id']) ) throw new BadMethodCallException(__("Need a blogid and post id to fetch a post", 'mtv')); if ( is_multisite() && get_current_blog_id() !== $this->blogid ) switch_to_blog( $this->attributes['blogid'] ); $post = get_post( $this->attributes['id'] ); if ( $post === NULL ) { restore_current_blog(); throw new ModelNotFound("Post", __("Post not found", 'mtv')); } $this->reload( $post ); if ( is_multisite() && get_current_blog_id() !== $this->blogid ) restore_current_blog(); } public function parse( &$postdata ) { # Use the parent parse $ret =& parent::parse( $postdata ); # gonna pick a case if ( !empty($ret['ID']) ) { $ret['id'] =& $ret['ID']; unset($ret['ID']); } # Take only the fields we need, put them in a temp array # TODO: current_blog may not be correct $ret['blogid'] = get_current_blog_id(); # Fill up the meta attribute with post meta $ret['post_meta'] = array(); $meta_keys = get_post_custom_keys($ret['id']); if ( is_array( $meta_keys ) ) foreach( $meta_keys as $key ) $ret['post_meta'][$key] = get_post_meta($ret['id'], $key, true); if ( $ret['post_type'] == 'post' ) $ret['post_format'] = get_post_format( $ret['id'] ); return $ret; } public function password_required() { if ( empty($this->post_password) ) return false; if ( !isset($_COOKIE['wp-postpass_' . COOKIEHASH]) ) return true; if ( $_COOKIE['wp-postpass_' . COOKIEHASH] != $this->post_password ) return true; return false; } public function is_sticky() { return is_sticky($this->id); } public function post_class( $class='' ) { return get_post_class($class, $this->id); } public function permalink() { if ( get_current_blog_id() !== $this->blogid ) { switch_to_blog($this->blogid); $permalink = get_permalink($this->id); restore_current_blog(); return $permalink; } else return get_permalink($this->id); } public function categories() { return get_the_category($this->id); } public function tags() { return get_the_tags($this->id); } public function featured_image() { if ( !empty( $this->post_meta['_thumbnail_id'] ) ) return AttachmentCollection::get(array( 'id' => $this->post_meta['_thumbnail_id'], 'blogid' => $this->blogid )); else return null; } public function get_attachments() { return AttachmentCollection::for_post( $this->id ); } # TODO: optimize with SQL public function clear_attachments() { foreach ( $this->get_attachments() as $attachment ) { $attachment->post_parent = null; $attachment->menu_order = null; $attachment->save(); } } public function set_attachments( $attachments ) { $this->clear_attachments(); $menu_order = 0; foreach ( $attachments as $attachment ) { $attachment->post_parent = $this->id; $attachment->menu_order = $menu_order; $attachment->save(); $menu_order++; } } public function the_time($format = null) { if ($format) return mysql2date($format, $this->post_date); else return mysql2date(get_option('time_format'), $this->post_date); } public function the_date($format = null) { if ($format) return mysql2date($format, $this->post_date); else return mysql2date(get_option('date_format'), $this->post_date); } public function the_content() { return str_replace(']]>', ']]&gt;', apply_filters('the_content', $this->post_content) ); } public function make_excerpt($more_text = null) { // Author inserted a <!--more--> tag $parts = get_extended($this->post_content); if (!empty($parts['extended'])) { $ret = trim($parts['main']); // Conditionally add a read more link and // clean up punctuation and ellipsis at end of excerpt $wc_excerpt = str_word_count($ret); $wc_content = str_word_count($this->post_content); if ($wc_excerpt < $wc_content) { $ret = preg_replace('/([\.,;:!?\'"]{4,})$/', '...', $ret . '...'); if (!empty($more_text)) $ret = $ret . ' <a href="'. $this->permalink .'" class="more-link">'. $more_text .'</a>'; } } // Excerpt is empty, so generate one if (empty($parts['extended'])) { $text = strip_shortcodes( $this->post_content ); $text = apply_filters('the_content', $text); $text = str_replace(']]>', ']]&gt;', $text); $text = strip_tags($text); $excerpt_length = apply_filters('excerpt_length', 55); $read_more = apply_filters('read_more', ' ' . '[...]', $this); $words = preg_split("/[\n\r\t ]+/", $text, $excerpt_length + 1, PREG_SPLIT_NO_EMPTY); if ( count($words) > $excerpt_length ) { array_pop($words); $text = implode(' ', $words); $text = $text . $read_more; } else { $text = implode(' ', $words); } $ret = apply_filters('wp_trim_excerpt', $text, $raw_excerpt); } /* TODO: cache results of this function */ return $ret; } } class PostCollection extends Collection { public static $model = 'mtv\wp\models\Post'; public static $default_filter = array( 'post_type' => 'post', 'posts_per_page' => 10, 'order' => 'DESC', 'paged' => '1' ); public $wp_query; public static function filter( $args ) { $class = get_called_class(); $ret = new $class(); $ret->wp_query = new WP_Query( array_merge(static::$default_filter, $args) ); $ret->wp_query->get_posts(); foreach( $ret->wp_query->posts as $post ) { $p = new static::$model(); try { $p->reload($post); $ret->add($p); } catch(ModelParseException $e) { # post is bad for some reason, skip it continue; } } return $ret; } /** * Make this collection's wp_query the magical global * WordPress one. This should make a bunch of native WP * stuff work. **/ public function globalize_wp_query() { $GLOBALS['wp_the_query'] = $this->wp_query; wp_reset_query(); } } class PageCollection extends PostCollection { public static $default_filter = array( 'post_type' => 'page', 'posts_per_page' => -1, 'post_status' => 'inherit', 'orderby' => 'menu_order', 'order' => 'ASC' ); } class Attachment extends Post { public function parse( &$postdata ) { # Use the parent parse $ret =& parent::parse( $postdata ); # If this isn't an attachment, we haven't found what we're looking for if ( $ret['post_type'] != "attachment" ) throw new ModelParseException(__("Post is not an attachment", 'mtv')); # Add some special fields depending on the post type $ret['url'] = wp_get_attachment_url($ret['id']); $ret['thumb_url'] = wp_get_attachment_thumb_url($ret['id']); return $ret; } } class AttachmentCollection extends PostCollection { public static $model = 'mtv\wp\models\Attachment'; public static $default_filter = array( 'post_type' => 'attachment', 'posts_per_page' => -1, 'post_status' => 'inherit', 'orderby' => 'menu_order', 'order' => 'ASC' ); public static function for_post( $post_id ) { return static::filter( array('post_parent' => $post_id) ); } } # TODO: make user meta work like it does in Post class User extends Model { public $defaults = array( 'id' => '0', 'user_login' => 'guest', 'sites' => array(), ); public $json_fields = array( "id", "user_login", "user_url", "user_email", "display_name", "nickname", "first_name", "last_name", "user_description", "can_reblog", "zip", "capabilities", "jabber", "aim", "yim", "primary_blog", "user_level", "avatar"); public $editable_json_fields = array( "user_url", "user_email", "nickname", "first_name", "last_name", "user_description", "zip", "user_pass", "jabber", "aim", "yim", "userpic", "userthumb" ); public static $collection = 'mtv\wp\models\UserCollection'; public function initialize( $attrs ) { if ( empty($attrs['avatar']) ) $this->avatar = get_avatar($attrs['id']); } public function __toString() { return $this->display_name; } public function validate() { // Register if ( empty($this->id) ) { // Validate username and email $result = wpmu_validate_user_signup($this->user_login, $this->user_email); if ( $result['errors']->get_error_code() ) throw new WPException($result['errors']); // Update } else { // Don't accidently set our password to empty if ( isset($this->user_pass) && trim($this->user_pass) == '' ) unset( $this->user_pass ); } } public function register() { $this->validate(); // split incoming data and keep the stuff we can pass to // update_user_meta. Set the user's password as meta so that we don't // haveto ask the user for it again after activation. $this->user_meta = array_merge( array_diff_assoc($this->attributes, parse_user($this->attributes)), array('user_pass' => wp_hash_password($this->user_pass)) ); wpmu_signup_user($this->user_login, $this->user_email, $this->user_meta); } public function save() { $this->validate(); // split the incoming data into stuff we can pass to wp_update_user and // stuff we have to add with update_user_meta $userdata = parse_user( $this->attributes ); $usermeta = array_diff_assoc( $this->attributes, $userdata ); $removemeta = array_diff( array_keys($this->_previous_attributes), array_keys($this->attributes) ); unset($usermeta['id']); // make sure we don't accidently save the id as meta // Create if ( empty($this->id) ) { // create the new user with all the basic data // wp_update_user has bugs that doesn't let you create a user with it // http://core.trac.wordpress.org/ticket/17009 // TODO: just use wp_update_user once the bug is fixed $user_id = wp_create_user( $userdata['user_login'], $userdata['user_pass'], $userdata['user_email'] ); if ( is_wp_error($user_id) ) throw new WPException($user_id); // We should keep track of our user id $userdata['ID'] = $user_id; $this->id = $user_id; // Update } else { // Check which data has changed $data_to_diff = get_userdata( $this->id ); $data_to_update = array_diff_assoc( $userdata, (array) $data_to_diff->data ); // If we don't have any changes, we don't have to update! if ( empty( $data_to_update ) ) $userdata = false; else $userdata = array_merge( array('ID' => $this->id), $data_to_update); } // If we don't have any userdata, we don't have to update! if ( $userdata ) { $user_id = wp_update_user( $userdata ); if ( is_wp_error($user_id) ) throw new WPException($user_id); } // Update user meta with leftover data foreach ( $usermeta as $key => $val ) update_user_meta( $this->id, $key, $val); // Remove any deleted meta foreach ( $removemeta as $key ) delete_user_meta( $this->id, $key ); $this->fetch(); } public function fetch() { // Get userdata (this is a WP_User object in WP 3.3+) $user = get_userdata( $this->id ); if ($user->data) { $userdata = (array) $user->data; } else { $userdata = (array) $user; } // Fetch all user meta, flatten the returned array $usermeta = array_map( function($x) { return $x[0]; }, get_user_meta( $this->id )); // Set value for each user meta key not in userdata foreach ( $usermeta as $k => $v ) { if ( !in_array($k, array_keys($userdata)) ) $userdata[$k] = maybe_unserialize($v); } $this->reload( $userdata ); } public function parse( &$userdata ) { // Use the parent parse $ret =& parent::parse( $userdata ); // Pick a case for the id attribute if ( !empty($ret['ID']) ) { $ret['id'] = $ret['ID']; unset($ret['ID']); } // get the html to display the users avatar $ret['avatar'] = get_avatar( $ret['id'] ); // Get user capabilities for each blog in the network global $wpdb; $blogs = $wpdb->get_col("select blog_id from $wpdb->blogs"); $ret['capabilities'] = array(); foreach ( $blogs as $k => $v ) { if ( $k == 0 ) { $_caps = get_user_meta($ret['id'], 'wp_capabilities', true); if ( !empty($_caps) ) $ret['capabilities'][$v] = array_shift(array_keys((array) maybe_unserialize($_caps))); } else { $_caps = get_user_meta($ret['id'], 'wp_' . $v . '_capabilities', true ); if ( !empty($_caps) ) $ret['capabilities'][$v] = array_shift(array_keys((array) maybe_unserialize($_caps))); } } return $ret; } /** * signon * Takes an array of keyword arguments, attempts to find the user and sign him/her on. **/ public static function signon( $kwargs ) { $creds = array(); if ( ! empty( $kwargs['user_login'] ) ) { $creds['user_login'] = $kwargs['user_login']; } elseif ( ! empty( $kwargs['user_email'] ) ) { $collection = static::$collection; $user = $collection::get_by( array( 'user_email' => $kwargs['user_email'] ) ); $creds['user_login'] = $user->user_login; } else throw new JsonableException(__("Please enter your user name or email address.", 'mtv')); if ( empty( $kwargs['user_pass'] ) ) throw new JsonableException(__('Please enter your password.', 'mtv')); $creds['user_password'] = $kwargs['user_pass']; $result = wp_signon($creds, true); if ( is_wp_error($result) ) { throw new WPException($result); } else { // TODO: // Implement "remember me" functionality with wp_set_auth_cookie wp_set_auth_cookie($result->ID, true); // wp_set_current_user($result->ID); } $user = new static( array('id' => $result->ID) ); $user->fetch(); return $user; } public static function activate($key) { $result = activate_signup($key); if (is_wp_error($result)) throw new WPException($result); $collection = static::$collection; $user = $collection::get(array('id' => $result['user_id'])); return $user; } public function get_avatar() { return get_avatar( $this->id ); } /** * sites * Returns a SiteCollection containing all the sites this user is connected to. **/ public function sites() { if ( empty($this->_sites) ) $this->_sites = SiteCollection::for_user(array('user_id'=>$this->id)); return $this->_sites; } public function to_json() { return parent::to_json() + array('sites'=>$this->sites()->to_json()); } } class UserCollection extends Collection { public static $model = 'mtv\wp\models\User'; public static function get_by( $kwargs ) { if ( isset($kwargs['user_email']) ) { $userid = get_user_id_from_string($kwargs['user_email']); if ( $userid === 0 ) throw new JsonableException(__("I don't know that email address", 'mtv')); } else if ( isset($kwargs['user_login']) ) { $userid = get_user_id_from_string($kwargs['user_login']); if ( $userid === 0 ) throw new JsonableException(__("I don't know that user name", 'mtv')); } else throw new NotImplementedException(); $user = new static::$model( array( 'id'=>$userid ) ); $user->fetch(); return $user; } public static function get_current() { $userid = get_current_user_id(); if ( empty($userid) ) return new static::$model(); else { $user = new static::$model( array( 'id'=>$userid ) ); $user->fetch(); return $user; } } /** * Returns an array of users based on criteria * Proxies to the WordPress get_users function internally. Use this function as you would use * get_users. * * http://codex.wordpress.org/Function_Reference/get_users **/ public static function filter( $kwargs ) { # We set the blog_id query param to zero, so WordPress doesn't filter # the query based on the permissions for this blog. Hacky. if ( !isset($kwargs['blog_id']) ) $kwargs['blog_id'] = 0; $class = get_called_class(); $users = get_users( $kwargs ); $collection = new $class(); foreach ($users as $u) { $new_user = new static::$model(); $new_user->reload( $u ); $collection->add( $new_user ); } return $collection; } } class Site extends Model { public function fetch() { $this->reload( get_blog_details( $this->id ) ); } public function parse( &$data ) { // Use the parent parse $ret =& parent::parse( $data ); // figure out where the id is if ( !empty($ret['userblog_id']) ) { $ret['id'] =& $ret['userblog_id']; unset($ret['userblog_id']); } else if ( !empty($ret['blog_id']) ) { $ret['id'] =& $ret['blog_id']; unset($ret['blog_id']); } return $ret; } } class SiteCollection extends Collection { public static $model = 'mtv\wp\models\Site'; public static function for_user( $kwargs ) { if ( isset($kwargs['user_id']) ) { $userid = $kwargs['user_id']; } else if ( isset($kwargs['user_email']) ) { $userid = get_user_id_from_string($kwargs['user_email']); if ( $userid === 0 ) throw new JsonableException(__("I don't know that email address", 'mtv')); } else if ( isset($kwargs['user_login']) ) { $userid = get_user_id_from_string($kwargs['user_login']); if ( $userid === 0 ) throw new JsonableException(__("I don't know that username", 'mtv')); } else throw new NotImplementedException(); $class = get_called_class(); $blogdata = get_blogs_of_user($userid); $sites = new $class(); if ( !empty($blogdata) ) { foreach($blogdata as $b) { $site = new static::$model(); $site->reload($b); $sites->add($site); } } return $sites; } public static function published( ) { global $wpdb; $class = get_called_class(); $query = "select * from {$wpdb->base_prefix}blogs where public='1' and archived='0' and spam='0' and deleted='0' and mature='0'"; return new $class($wpdb->get_results($query, ARRAY_A)); } } # this returns an array of fields that wordpress's update_user can handle function parse_user( $userdata ) { $user_fields = array( "ID", "user_pass", "user_login", "user_nicename", "user_url", "user_email", "display_name", "nickname", "first_name", "last_name", "description", "rich_editing", "user_registered", "role", "jabber", "aim", "yim" ); foreach( $userdata as $key => $val ) if ( ! in_array( $key, $user_fields ) ) unset( $userdata[$key] ); return $userdata; } # activate user signup, avoid sending a second # email with username and password in plaintext. function activate_signup($key) { global $wpdb; $signup = $wpdb->get_row( $wpdb->prepare("select * from $wpdb->signups where activation_key = %s", $key) ); if (empty($signup)) return new \WP_Error('invalid_key', __('Invalid activation key.', 'mtv')); if ($signup->active) return new \WP_Error('already_active', __('This account is already activated.', 'mtv'), $signup ); $user_meta = unserialize($signup->meta); $user_login = $wpdb->escape($signup->user_login); $user_email = $wpdb->escape($signup->user_email); $user_pass = $user_meta['user_pass']; $user_id = username_exists($user_login); if (!$user_id) $user_id = wpmu_create_user($user_login, wp_generate_password( 12, false ), $user_email); if (!$user_id) return new \WP_Error('create_user', __('Could not create user', 'mtv'), $signup); // Be sure to unset the user pass because // we don't want to store it as meta once // the user is activated unset($user_meta['user_pass']); foreach ($user_meta as $k => $v) update_user_meta($user_id, $k, $v); $wpdb->update($wpdb->users, array( 'user_pass' => $user_pass, 'user_activation_key' => '' ), array('ID' => $user_id)); $wpdb->update($wpdb->signups, array( 'active' => 1, 'activated' => current_time('mysql', true), 'meta' => '' ), array('activation_key' => $key)); add_new_user_to_blog($user_id, $user_email, ''); return array( 'user_id' => $user_id, 'password' => $password, 'meta' => $meta ); }
php
MIT
29102ea8171e13b6e4d7fb1cc972985f343e54da
2026-01-05T04:41:45.731026Z
false
newsapps/wordpress-mtv
https://github.com/newsapps/wordpress-mtv/blob/29102ea8171e13b6e4d7fb1cc972985f343e54da/wp/templatetags/functions.php
wp/templatetags/functions.php
<?php namespace mtv\wp\templatetags\functions; use mtv\shortcuts; use Twig_Function_Function; // Debug $twig->addFunction('print_r', new Twig_Function_Function('print_r')); // General, helpful WordPress stuff $twig->addFunction('apply_filters', new Twig_Function_Function('apply_filters')); $twig->addFunction('esc_attr', new Twig_Function_Function('esc_attr')); $twig->addFunction('esc_url', new Twig_Function_Function('esc_url')); $twig->addFunction('get_option', new Twig_Function_Function('get_option')); $twig->addFunction('do_action', new Twig_Function_Function('do_action')); $twig->addFunction('__', new Twig_Function_Function('__')); // Request flags, conditionals $twig->addFunction('is_preview', new Twig_Function_Function('is_preview')); $twig->addFunction('is_single', new Twig_Function_Function('is_single')); $twig->addFunction('is_page', new Twig_Function_Function('is_page')); $twig->addFunction('is_archive', new Twig_Function_Function('is_archive')); $twig->addFunction('is_date', new Twig_Function_Function('is_date')); $twig->addFunction('is_year', new Twig_Function_Function('is_year')); $twig->addFunction('is_month', new Twig_Function_Function('is_month')); $twig->addFunction('is_day', new Twig_Function_Function('is_day')); $twig->addFunction('is_time', new Twig_Function_Function('is_time')); $twig->addFunction('is_author', new Twig_Function_Function('is_author')); $twig->addFunction('is_category', new Twig_Function_Function('is_category')); $twig->addFunction('is_tag', new Twig_Function_Function('is_tag')); $twig->addFunction('is_tax', new Twig_Function_Function('is_tax')); $twig->addFunction('is_search', new Twig_Function_Function('is_search')); $twig->addFunction('is_feed', new Twig_Function_Function('is_feed')); $twig->addFunction('is_comment_feed', new Twig_Function_Function('is_comment_feed')); $twig->addFunction('is_trackback', new Twig_Function_Function('is_trackback')); $twig->addFunction('is_home', new Twig_Function_Function('is_home')); $twig->addFunction('is_404', new Twig_Function_Function('is_404')); $twig->addFunction('is_comments_popup', new Twig_Function_Function('is_comments_popup')); $twig->addFunction('is_paged', new Twig_Function_Function('is_paged')); $twig->addFunction('is_admin', new Twig_Function_Function('is_admin')); $twig->addFunction('is_attachment', new Twig_Function_Function('is_attachment')); $twig->addFunction('is_singular', new Twig_Function_Function('is_singular')); $twig->addFunction('is_robots', new Twig_Function_Function('is_robots')); $twig->addFunction('is_posts_page', new Twig_Function_Function('is_posts_page')); $twig->addFunction('is_post_type_archive', new Twig_Function_Function('is_post_type_archive')); // Login/register $twig->addFunction('wp_login_url', new Twig_Function_Function('wp_login_url')); $twig->addFunction('is_user_logged_in', new Twig_Function_Function('is_user_logged_in')); // Author functions $twig->addFunction('get_avatar', new Twig_Function_Function('get_avatar', array('is_safe'=>array('html') )) ); $twig->addFunction('get_the_author_meta', new Twig_Function_Function('get_the_author_meta')); // Post functions $twig->addFunction('get_edit_post_link', new Twig_Function_Function('get_edit_post_link')); $twig->addFunction('wpautop', new Twig_Function_Function('wpautop')); $twig->addFunction('get_comments', new Twig_Function_Function('get_comments')); $twig->addFunction('mysql2date', new Twig_Function_Function('mysql2date')); // Comment form $twig->addFunction('get_comment_reply_link', new Twig_Function_Function('get_comment_reply_link')); $twig->addFunction('comment_author', new Twig_Function_Function('comment_author')); $twig->addFunction('get_comment_excerpt', new Twig_Function_Function('get_comment_excerpt')); // Thumbnails $twig->addFunction('has_post_thumbnail', new Twig_Function_Function('has_post_thumbnail')); $twig->addFunction('get_the_post_thumbnail', new Twig_Function_Function('get_the_post_thumbnail')); // Galleries $twig->addFunction('get_attachment_url', new Twig_Function_Function('wp_get_attachment_url')); $twig->addFunction('get_attachment_thumb_url', new Twig_Function_Function('wp_get_attachment_thumb_url')); // Post attachments // Theme functions // CSS $twig->addFunction('get_stylesheet', new Twig_Function_Function('get_stylesheet')); $twig->addFunction('get_stylesheet_directory', new Twig_Function_Function('get_stylesheet_directory')); $twig->addFunction('get_stylesheet_directory_uri', new Twig_Function_Function('get_stylesheet_directory_uri')); $twig->addFunction('get_stylesheet_uri', new Twig_Function_Function('get_stylesheet_uri')); $twig->addFunction('get_template_directory_uri', new Twig_Function_Function('get_template_directory_uri')); $twig->addFunction('get_theme_root', new Twig_Function_Function('get_theme_root')); // Blog functions $twig->addFunction('get_blog_details', new Twig_Function_Function('get_blog_details')); $twig->addFunction('get_current_blog_id', new Twig_Function_Function('get_current_blog_id')); $twig->addFunction('get_site_url', new Twig_Function_Function('get_site_url')); $twig->addFunction('get_home_url', new Twig_Function_Function('get_home_url')); $twig->addFunction('get_bloginfo', new Twig_Function_Function('get_bloginfo')); // Template functions $twig->addFunction('wp_title', new Twig_Function_Function('wp_title')); $twig->addFunction('wp_head', new Twig_Function_Function('mtv\wp\templatetags\functions\get_wp_head', array('is_safe'=>array('html'))) ); $twig->addFunction('wp_footer', new Twig_Function_Function('mtv\wp\templatetags\functions\get_wp_footer', array('is_safe'=>array('html'))) ); $twig->addFunction('body_class', new Twig_Function_Function('mtv\wp\templatetags\functions\get_body_class', array('is_safe'=>array('html'))) ); $twig->addFunction('language_attributes', new Twig_Function_Function('mtv\wp\templatetags\functions\get_language_attributes', array('is_safe'=>array('html'))) ); $twig->addFunction('get_header', new Twig_Function_Function('mtv\wp\templatetags\functions\get_header', array('is_safe'=>array('html'))) ); $twig->addFunction('get_footer', new Twig_Function_Function('mtv\wp\templatetags\functions\get_footer', array('is_safe'=>array('html'))) ); $twig->addFunction('dynamic_sidebar', new Twig_Function_Function('mtv\wp\templatetags\functions\dynamic_sidebar', array('is_safe'=>array('html'))) ); $twig->addFunction('sidebar_is_populated', new Twig_Function_Function('mtv\wp\templatetags\functions\sidebar_is_populated', array('is_safe'=>array('html'))) ); $twig->addFunction('this_year', new Twig_Function_Function('mtv\wp\templatetags\functions\this_year')); $twig->addFunction('wp_nav_menu', new Twig_Function_Function('wp_nav_menu', array('is_safe'=>array('html')))); $twig->addFunction('is_active_sidebar', new Twig_Function_Function('is_active_sidebar')); function get_wp_head() { ob_start(); wp_head(); $ret = ob_get_contents(); ob_end_clean(); return $ret; } function get_wp_footer() { ob_start(); wp_footer(); $ret = ob_get_contents(); ob_end_clean(); return $ret; } function get_body_class( $extra_classes=null ) { ob_start(); body_class( $extra_classes ); $ret = ob_get_contents(); ob_end_clean(); return $ret; } function get_language_attributes() { ob_start(); language_attributes(); $ret = ob_get_contents(); ob_end_clean(); return $ret; } function get_header() { ob_start(); do_action( 'get_header', null ); $ret = ob_get_contents(); ob_end_clean(); return $ret; } function get_footer() { ob_start(); do_action( 'get_footer', null ); $ret = ob_get_contents(); ob_end_clean(); return $ret; } function get_sidebar() { ob_start(); do_action( 'get_sidebar', null ); $ret = ob_get_contents(); ob_end_clean(); return $ret; } function dynamic_sidebar($id) { ob_start(); \dynamic_sidebar($id); ob_end_flush(); } function sidebar_is_populated($id) { ob_start(); $ret = \dynamic_sidebar($id); ob_end_clean(); return $ret; } function this_year() { return date('Y', shortcuts\current_time("timestamp")); }
php
MIT
29102ea8171e13b6e4d7fb1cc972985f343e54da
2026-01-05T04:41:45.731026Z
false
newsapps/wordpress-mtv
https://github.com/newsapps/wordpress-mtv/blob/29102ea8171e13b6e4d7fb1cc972985f343e54da/wp/templatetags/filters.php
wp/templatetags/filters.php
<?php namespace mtv\filters; // Twig filters go here // A not-so-useful example: // Author name filter functions function author_displayname($id) { return get_the_author_meta('display_name', $id); } $twig->addFilter('author_displayname', new \Twig_Filter_Function('mtv\filters\author_displayname')); function pluralize($array) { if (count($array) != 1) return "s"; else return ""; } $twig->addFilter('pluralize', new \Twig_Filter_Function('mtv\filters\pluralize')); function collection_contains($collection, $entity) { return (bool)$collection->contains( $entity ); } $twig->addFilter('collection_contains', new \Twig_Filter_Function('mtv\filters\collection_contains')); function bloginfo($blog_entity_or_id, $key) { if ( is_numeric($blog_entity_or_id) ) $id = $blog_entity_or_id; else $id = $blog_entity_or_id->id; \switch_to_blog($id); $ret = \get_bloginfo($key); \restore_current_blog(); return $ret; } $twig->addFilter('bloginfo', new \Twig_Filter_Function('mtv\filters\bloginfo')); function linebreaks($content) { return wpautop($content, false); } $twig->addFilter('linebreaks', new \Twig_Filter_Function('mtv\filters\linebreaks', array('is_safe'=>array('html') ))); function meta($post_or_id, $key) { if ( is_numeric($post_or_id) ) $id = $post_or_id; else $id = $post_or_id->ID; return get_post_meta($id, $key, true); } $twig->addFilter('meta', new \Twig_Filter_Function('mtv\filters\meta')); function url_decode($str) { $str = urldecode($str); return $str; } $twig->addFilter('url_decode', new \Twig_Filter_Function('mtv\filters\url_decode'));
php
MIT
29102ea8171e13b6e4d7fb1cc972985f343e54da
2026-01-05T04:41:45.731026Z
false
newsapps/wordpress-mtv
https://github.com/newsapps/wordpress-mtv/blob/29102ea8171e13b6e4d7fb1cc972985f343e54da/wp/templatetags/tags.php
wp/templatetags/tags.php
<?php namespace mtv\tags; # Allows use of: # {% while condition %} # do stuff # {% endwhile %} class Twig_TokenParser_While extends \Twig_TokenParser { public function parse(\Twig_Token $token) { $lineno = $token->getLine(); $expr = $this->parser->getExpressionParser()->parseExpression(); $this->parser->getStream()->expect(\Twig_Token::BLOCK_END_TYPE); $body = $this->parser->subparse(array($this, 'decideIfEnd')); $tests = array($expr, $body); $else = null; $end = false; $next_val = $this->parser->getStream()->next()->getValue(); while (!$end) { switch ($next_val) { case 'endwhile': $end = true; break; default: throw new \Twig_Error_Syntax(sprintf('Unexpected end of template. Twig was looking for "endwhile" to close the "while" block started at line %d)', $lineno), -1); } } $this->parser->getStream()->expect(\Twig_Token::BLOCK_END_TYPE); return new Twig_Node_While(new \Twig_Node($tests), $else, $lineno, $this->getTag()); } public function decideIfEnd(\Twig_Token $token) { return $token->test(array('endwhile')); } public function getTag() { return 'while'; } } $twig->addTokenParser(new Twig_TokenParser_While()); # Compiles the actual php # for the {% while %} loop class Twig_Node_While extends \Twig_Node { public function __construct(\Twig_NodeInterface $tests, $lineno, $tag = null) { parent::__construct(array('tests' => $tests), array(), $lineno, $tag); } public function compile(\Twig_Compiler $compiler) { $compiler->addDebugInfo($this); $compiler ->write('while (') ; for ($i = 0; $i < count($this->getNode('tests')); $i += 2) { $compiler ->subcompile($this->getNode('tests')->getNode($i)) ->raw(") {\n") ->indent() ->subcompile($this->getNode('tests')->getNode($i + 1)) ; } $compiler ->outdent() ->write("}\n"); } }
php
MIT
29102ea8171e13b6e4d7fb1cc972985f343e54da
2026-01-05T04:41:45.731026Z
false
thecodeholic/Yii2-Youtube-Clone
https://github.com/thecodeholic/Yii2-Youtube-Clone/blob/d8d6c35890b5d3ebb00b0cc6ace20deea99974b1/requirements.php
requirements.php
<?php /** * Application requirement checker script. * * In order to run this script use the following console command: * php requirements.php * * In order to run this script from the web, you should copy it to the web root. * If you are using Linux you can create a hard link instead, using the following command: * ln ../../requirements.php requirements.php */ // you may need to adjust this path to the correct Yii framework path // uncomment and adjust the following line if Yii is not located at the default path //$frameworkPath = dirname(__FILE__) . '/vendor/yiisoft/yii2'; if (!isset($frameworkPath)) { $searchPaths = array( dirname(__FILE__) . '/vendor/yiisoft/yii2', dirname(__FILE__) . '/../../vendor/yiisoft/yii2', ); foreach ($searchPaths as $path) { if (is_dir($path)) { $frameworkPath = $path; break; } } } if (!isset($frameworkPath) || !is_dir($frameworkPath)) { $message = "<h1>Error</h1>\n\n" . "<p><strong>The path to yii framework seems to be incorrect.</strong></p>\n" . '<p>You need to install Yii framework via composer or adjust the framework path in file <abbr title="' . __FILE__ . '">' . basename(__FILE__) . "</abbr>.</p>\n" . '<p>Please refer to the <abbr title="' . dirname(dirname(dirname(__FILE__))) . "/README.md\">README</abbr> on how to install Yii.</p>\n"; if (!empty($_SERVER['argv'])) { // do not print HTML when used in console mode echo strip_tags($message); } else { echo $message; } exit(1); } require_once $frameworkPath . '/requirements/YiiRequirementChecker.php'; $requirementsChecker = new YiiRequirementChecker(); $gdMemo = $imagickMemo = 'Either GD PHP extension with FreeType support or ImageMagick PHP extension with PNG support is required for image CAPTCHA.'; $gdOK = $imagickOK = false; if (extension_loaded('imagick')) { $imagick = new Imagick(); $imagickFormats = $imagick->queryFormats('PNG'); if (in_array('PNG', $imagickFormats)) { $imagickOK = true; } else { $imagickMemo = 'Imagick extension should be installed with PNG support in order to be used for image CAPTCHA.'; } } if (extension_loaded('gd')) { $gdInfo = gd_info(); if (!empty($gdInfo['FreeType Support'])) { $gdOK = true; } else { $gdMemo = 'GD extension should be installed with FreeType support in order to be used for image CAPTCHA.'; } } /** * Adjust requirements according to your application specifics. */ $requirements = array( // Database : array( 'name' => 'PDO extension', 'mandatory' => true, 'condition' => extension_loaded('pdo'), 'by' => 'All DB-related classes', ), array( 'name' => 'PDO SQLite extension', 'mandatory' => false, 'condition' => extension_loaded('pdo_sqlite'), 'by' => 'All DB-related classes', 'memo' => 'Required for SQLite database.', ), array( 'name' => 'PDO MySQL extension', 'mandatory' => false, 'condition' => extension_loaded('pdo_mysql'), 'by' => 'All DB-related classes', 'memo' => 'Required for MySQL database.', ), array( 'name' => 'PDO PostgreSQL extension', 'mandatory' => false, 'condition' => extension_loaded('pdo_pgsql'), 'by' => 'All DB-related classes', 'memo' => 'Required for PostgreSQL database.', ), // Cache : array( 'name' => 'Memcache extension', 'mandatory' => false, 'condition' => extension_loaded('memcache') || extension_loaded('memcached'), 'by' => '<a href="http://www.yiiframework.com/doc-2.0/yii-caching-memcache.html">MemCache</a>', 'memo' => extension_loaded('memcached') ? 'To use memcached set <a href="http://www.yiiframework.com/doc-2.0/yii-caching-memcache.html#$useMemcached-detail">MemCache::useMemcached</a> to <code>true</code>.' : '' ), array( 'name' => 'APC extension', 'mandatory' => false, 'condition' => extension_loaded('apc'), 'by' => '<a href="http://www.yiiframework.com/doc-2.0/yii-caching-apccache.html">ApcCache</a>', ), // CAPTCHA: array( 'name' => 'GD PHP extension with FreeType support', 'mandatory' => false, 'condition' => $gdOK, 'by' => '<a href="http://www.yiiframework.com/doc-2.0/yii-captcha-captcha.html">Captcha</a>', 'memo' => $gdMemo, ), array( 'name' => 'ImageMagick PHP extension with PNG support', 'mandatory' => false, 'condition' => $imagickOK, 'by' => '<a href="http://www.yiiframework.com/doc-2.0/yii-captcha-captcha.html">Captcha</a>', 'memo' => $imagickMemo, ), // PHP ini : 'phpExposePhp' => array( 'name' => 'Expose PHP', 'mandatory' => false, 'condition' => $requirementsChecker->checkPhpIniOff("expose_php"), 'by' => 'Security reasons', 'memo' => '"expose_php" should be disabled at php.ini', ), 'phpAllowUrlInclude' => array( 'name' => 'PHP allow url include', 'mandatory' => false, 'condition' => $requirementsChecker->checkPhpIniOff("allow_url_include"), 'by' => 'Security reasons', 'memo' => '"allow_url_include" should be disabled at php.ini', ), 'phpSmtp' => array( 'name' => 'PHP mail SMTP', 'mandatory' => false, 'condition' => strlen(ini_get('SMTP')) > 0, 'by' => 'Email sending', 'memo' => 'PHP mail SMTP server required', ), ); $result = $requirementsChecker->checkYii()->check($requirements)->getResult(); $requirementsChecker->render(); exit($result['summary']['errors'] === 0 ? 0 : 1);
php
BSD-3-Clause
d8d6c35890b5d3ebb00b0cc6ace20deea99974b1
2026-01-05T04:42:11.286050Z
false
thecodeholic/Yii2-Youtube-Clone
https://github.com/thecodeholic/Yii2-Youtube-Clone/blob/d8d6c35890b5d3ebb00b0cc6ace20deea99974b1/sample.php
sample.php
<?php $countries = ["Georgia", "USA", "India"]; foreach ($countries as $country) { }
php
BSD-3-Clause
d8d6c35890b5d3ebb00b0cc6ace20deea99974b1
2026-01-05T04:42:11.286050Z
false
thecodeholic/Yii2-Youtube-Clone
https://github.com/thecodeholic/Yii2-Youtube-Clone/blob/d8d6c35890b5d3ebb00b0cc6ace20deea99974b1/console/migrations/m130524_201442_init.php
console/migrations/m130524_201442_init.php
<?php use yii\db\Migration; class m130524_201442_init extends Migration { public function up() { $tableOptions = null; if ($this->db->driverName === 'mysql') { // http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB'; } $this->createTable('{{%user}}', [ 'id' => $this->primaryKey(), 'username' => $this->string()->notNull()->unique(), 'auth_key' => $this->string(32)->notNull(), 'password_hash' => $this->string()->notNull(), 'password_reset_token' => $this->string()->unique(), 'email' => $this->string()->notNull()->unique(), 'status' => $this->smallInteger()->notNull()->defaultValue(10), 'created_at' => $this->integer()->notNull(), 'updated_at' => $this->integer()->notNull(), ], $tableOptions); } public function down() { $this->dropTable('{{%user}}'); } }
php
BSD-3-Clause
d8d6c35890b5d3ebb00b0cc6ace20deea99974b1
2026-01-05T04:42:11.286050Z
false
thecodeholic/Yii2-Youtube-Clone
https://github.com/thecodeholic/Yii2-Youtube-Clone/blob/d8d6c35890b5d3ebb00b0cc6ace20deea99974b1/console/migrations/m200418_064142_create_fulltext_index_on_video.php
console/migrations/m200418_064142_create_fulltext_index_on_video.php
<?php use yii\db\Migration; /** * Class m200418_064142_create_fulltext_index_on_video */ class m200418_064142_create_fulltext_index_on_video extends Migration { /** * {@inheritdoc} */ public function safeUp() { $this->execute("ALTER TABLE {{%video}} ADD FULLTEXT(title, description, tags)"); } /** * {@inheritdoc} */ public function safeDown() { echo "m200418_064142_create_fulltext_index_on_video cannot be reverted.\n"; return false; } /* // Use up()/down() to run migration code without a transaction. public function up() { } public function down() { echo "m200418_064142_create_fulltext_index_on_video cannot be reverted.\n"; return false; } */ }
php
BSD-3-Clause
d8d6c35890b5d3ebb00b0cc6ace20deea99974b1
2026-01-05T04:42:11.286050Z
false
thecodeholic/Yii2-Youtube-Clone
https://github.com/thecodeholic/Yii2-Youtube-Clone/blob/d8d6c35890b5d3ebb00b0cc6ace20deea99974b1/console/migrations/m190124_110200_add_verification_token_column_to_user_table.php
console/migrations/m190124_110200_add_verification_token_column_to_user_table.php
<?php use \yii\db\Migration; class m190124_110200_add_verification_token_column_to_user_table extends Migration { public function up() { $this->addColumn('{{%user}}', 'verification_token', $this->string()->defaultValue(null)); } public function down() { $this->dropColumn('{{%user}}', 'verification_token'); } }
php
BSD-3-Clause
d8d6c35890b5d3ebb00b0cc6ace20deea99974b1
2026-01-05T04:42:11.286050Z
false
thecodeholic/Yii2-Youtube-Clone
https://github.com/thecodeholic/Yii2-Youtube-Clone/blob/d8d6c35890b5d3ebb00b0cc6ace20deea99974b1/console/migrations/m201112_042619_create_comment_table.php
console/migrations/m201112_042619_create_comment_table.php
<?php use yii\db\Migration; /** * Handles the creation of table `{{%comment}}`. * Has foreign keys to the tables: * * - `{{%video}}` * - `{{%comment}}` * - `{{%user}}` */ class m201112_042619_create_comment_table extends Migration { /** * {@inheritdoc} */ public function safeUp() { $this->createTable('{{%comment}}', [ 'id' => $this->primaryKey(), 'comment' => $this->text()->notNull(), 'video_id' => $this->string(16)->notNull(), 'parent_id' => $this->integer(11), 'pinned' => $this->tinyInteger()->defaultValue(0), 'created_at' => $this->integer(11), 'updated_at' => $this->integer(11), 'created_by' => $this->integer(11), ]); // creates index for column `video_id` $this->createIndex( '{{%idx-comment-video_id}}', '{{%comment}}', 'video_id' ); // add foreign key for table `{{%video}}` $this->addForeignKey( '{{%fk-comment-video_id}}', '{{%comment}}', 'video_id', '{{%video}}', 'video_id', 'CASCADE' ); // creates index for column `parent_id` $this->createIndex( '{{%idx-comment-parent_id}}', '{{%comment}}', 'parent_id' ); // add foreign key for table `{{%comment}}` $this->addForeignKey( '{{%fk-comment-parent_id}}', '{{%comment}}', 'parent_id', '{{%comment}}', 'id', 'CASCADE' ); // creates index for column `created_by` $this->createIndex( '{{%idx-comment-created_by}}', '{{%comment}}', 'created_by' ); // add foreign key for table `{{%user}}` $this->addForeignKey( '{{%fk-comment-created_by}}', '{{%comment}}', 'created_by', '{{%user}}', 'id', 'CASCADE' ); } /** * {@inheritdoc} */ public function safeDown() { // drops foreign key for table `{{%video}}` $this->dropForeignKey( '{{%fk-comment-video_id}}', '{{%comment}}' ); // drops index for column `video_id` $this->dropIndex( '{{%idx-comment-video_id}}', '{{%comment}}' ); // drops foreign key for table `{{%comment}}` $this->dropForeignKey( '{{%fk-comment-parent_id}}', '{{%comment}}' ); // drops index for column `parent_id` $this->dropIndex( '{{%idx-comment-parent_id}}', '{{%comment}}' ); // drops foreign key for table `{{%user}}` $this->dropForeignKey( '{{%fk-comment-created_by}}', '{{%comment}}' ); // drops index for column `created_by` $this->dropIndex( '{{%idx-comment-created_by}}', '{{%comment}}' ); $this->dropTable('{{%comment}}'); } }
php
BSD-3-Clause
d8d6c35890b5d3ebb00b0cc6ace20deea99974b1
2026-01-05T04:42:11.286050Z
false
thecodeholic/Yii2-Youtube-Clone
https://github.com/thecodeholic/Yii2-Youtube-Clone/blob/d8d6c35890b5d3ebb00b0cc6ace20deea99974b1/console/migrations/m200417_054237_create_videos_table.php
console/migrations/m200417_054237_create_videos_table.php
<?php use yii\db\Migration; /** * Handles the creation of table `{{%video}}`. * Has foreign keys to the tables: * * - `{{%user}}` */ class m200417_054237_create_videos_table extends Migration { /** * {@inheritdoc} */ public function safeUp() { $this->createTable('{{%video}}', [ 'video_id' => $this->string(16)->notNull(), 'title' => $this->string(512)->notNull(), 'description' => $this->text(), 'tags' => $this->string(512), 'status' => $this->integer(1), 'has_thumbnail' => $this->boolean(), 'video_name' => $this->string(512), 'created_at' => $this->integer(11), 'updated_at' => $this->integer(11), 'created_by' => $this->integer(11), ]); $this->addPrimaryKey('PK_videos_video_id', '{{%video}}', 'video_id'); // creates index for column `created_by` $this->createIndex( '{{%idx-videos-created_by}}', '{{%video}}', 'created_by' ); // add foreign key for table `{{%user}}` $this->addForeignKey( '{{%fk-videos-created_by}}', '{{%video}}', 'created_by', '{{%user}}', 'id', 'CASCADE' ); } /** * {@inheritdoc} */ public function safeDown() { // drops foreign key for table `{{%user}}` $this->dropForeignKey( '{{%fk-videos-created_by}}', '{{%video}}' ); // drops index for column `created_by` $this->dropIndex( '{{%idx-videos-created_by}}', '{{%video}}' ); $this->dropTable('{{%video}}'); } }
php
BSD-3-Clause
d8d6c35890b5d3ebb00b0cc6ace20deea99974b1
2026-01-05T04:42:11.286050Z
false
thecodeholic/Yii2-Youtube-Clone
https://github.com/thecodeholic/Yii2-Youtube-Clone/blob/d8d6c35890b5d3ebb00b0cc6ace20deea99974b1/console/migrations/m200418_051244_create_video_like_table.php
console/migrations/m200418_051244_create_video_like_table.php
<?php use yii\db\Migration; /** * Handles the creation of table `{{%video_like}}`. * Has foreign keys to the tables: * * - `{{%video}}` * - `{{%user}}` */ class m200418_051244_create_video_like_table extends Migration { /** * {@inheritdoc} */ public function safeUp() { $this->createTable('{{%video_like}}', [ 'id' => $this->primaryKey(), 'video_id' => $this->string(16)->notNull(), 'user_id' => $this->integer(11)->notNull(), 'type' => $this->integer(1), 'created_at' => $this->integer(11), ]); // creates index for column `video_id` $this->createIndex( '{{%idx-video_like-video_id}}', '{{%video_like}}', 'video_id' ); // add foreign key for table `{{%video}}` $this->addForeignKey( '{{%fk-video_like-video_id}}', '{{%video_like}}', 'video_id', '{{%video}}', 'video_id', 'CASCADE' ); // creates index for column `user_id` $this->createIndex( '{{%idx-video_like-user_id}}', '{{%video_like}}', 'user_id' ); // add foreign key for table `{{%user}}` $this->addForeignKey( '{{%fk-video_like-user_id}}', '{{%video_like}}', 'user_id', '{{%user}}', 'id', 'CASCADE' ); } /** * {@inheritdoc} */ public function safeDown() { // drops foreign key for table `{{%video}}` $this->dropForeignKey( '{{%fk-video_like-video_id}}', '{{%video_like}}' ); // drops index for column `video_id` $this->dropIndex( '{{%idx-video_like-video_id}}', '{{%video_like}}' ); // drops foreign key for table `{{%user}}` $this->dropForeignKey( '{{%fk-video_like-user_id}}', '{{%video_like}}' ); // drops index for column `user_id` $this->dropIndex( '{{%idx-video_like-user_id}}', '{{%video_like}}' ); $this->dropTable('{{%video_like}}'); } }
php
BSD-3-Clause
d8d6c35890b5d3ebb00b0cc6ace20deea99974b1
2026-01-05T04:42:11.286050Z
false
thecodeholic/Yii2-Youtube-Clone
https://github.com/thecodeholic/Yii2-Youtube-Clone/blob/d8d6c35890b5d3ebb00b0cc6ace20deea99974b1/console/migrations/m200418_050048_create_video_view_table.php
console/migrations/m200418_050048_create_video_view_table.php
<?php use yii\db\Migration; /** * Handles the creation of table `{{%video_view}}`. * Has foreign keys to the tables: * * - `{{%video}}` * - `{{%user}}` */ class m200418_050048_create_video_view_table extends Migration { /** * {@inheritdoc} */ public function safeUp() { $this->createTable('{{%video_view}}', [ 'id' => $this->primaryKey(), 'video_id' => $this->string(16)->notNull(), 'user_id' => $this->integer(11), 'created_at' => $this->integer(11), ]); // creates index for column `video_id` $this->createIndex( '{{%idx-video_view-video_id}}', '{{%video_view}}', 'video_id' ); // add foreign key for table `{{%video}}` $this->addForeignKey( '{{%fk-video_view-video_id}}', '{{%video_view}}', 'video_id', '{{%video}}', 'video_id', 'CASCADE' ); // creates index for column `user_id` $this->createIndex( '{{%idx-video_view-user_id}}', '{{%video_view}}', 'user_id' ); // add foreign key for table `{{%user}}` $this->addForeignKey( '{{%fk-video_view-user_id}}', '{{%video_view}}', 'user_id', '{{%user}}', 'id', 'CASCADE' ); } /** * {@inheritdoc} */ public function safeDown() { // drops foreign key for table `{{%video}}` $this->dropForeignKey( '{{%fk-video_view-video_id}}', '{{%video_view}}' ); // drops index for column `video_id` $this->dropIndex( '{{%idx-video_view-video_id}}', '{{%video_view}}' ); // drops foreign key for table `{{%user}}` $this->dropForeignKey( '{{%fk-video_view-user_id}}', '{{%video_view}}' ); // drops index for column `user_id` $this->dropIndex( '{{%idx-video_view-user_id}}', '{{%video_view}}' ); $this->dropTable('{{%video_view}}'); } }
php
BSD-3-Clause
d8d6c35890b5d3ebb00b0cc6ace20deea99974b1
2026-01-05T04:42:11.286050Z
false
thecodeholic/Yii2-Youtube-Clone
https://github.com/thecodeholic/Yii2-Youtube-Clone/blob/d8d6c35890b5d3ebb00b0cc6ace20deea99974b1/console/migrations/m200418_060320_create_subscriber_table.php
console/migrations/m200418_060320_create_subscriber_table.php
<?php use yii\db\Migration; /** * Handles the creation of table `{{%subscriber}}`. * Has foreign keys to the tables: * * - `{{%user}}` * - `{{%user}}` */ class m200418_060320_create_subscriber_table extends Migration { /** * {@inheritdoc} */ public function safeUp() { $this->createTable('{{%subscriber}}', [ 'id' => $this->primaryKey(), 'channel_id' => $this->integer(11), 'user_id' => $this->integer(11), 'created_at' => $this->integer(11), ]); // creates index for column `channel_id` $this->createIndex( '{{%idx-subscriber-channel_id}}', '{{%subscriber}}', 'channel_id' ); // add foreign key for table `{{%user}}` $this->addForeignKey( '{{%fk-subscriber-channel_id}}', '{{%subscriber}}', 'channel_id', '{{%user}}', 'id', 'CASCADE' ); // creates index for column `user_id` $this->createIndex( '{{%idx-subscriber-user_id}}', '{{%subscriber}}', 'user_id' ); // add foreign key for table `{{%user}}` $this->addForeignKey( '{{%fk-subscriber-user_id}}', '{{%subscriber}}', 'user_id', '{{%user}}', 'id', 'CASCADE' ); } /** * {@inheritdoc} */ public function safeDown() { // drops foreign key for table `{{%user}}` $this->dropForeignKey( '{{%fk-subscriber-channel_id}}', '{{%subscriber}}' ); // drops index for column `channel_id` $this->dropIndex( '{{%idx-subscriber-channel_id}}', '{{%subscriber}}' ); // drops foreign key for table `{{%user}}` $this->dropForeignKey( '{{%fk-subscriber-user_id}}', '{{%subscriber}}' ); // drops index for column `user_id` $this->dropIndex( '{{%idx-subscriber-user_id}}', '{{%subscriber}}' ); $this->dropTable('{{%subscriber}}'); } }
php
BSD-3-Clause
d8d6c35890b5d3ebb00b0cc6ace20deea99974b1
2026-01-05T04:42:11.286050Z
false
thecodeholic/Yii2-Youtube-Clone
https://github.com/thecodeholic/Yii2-Youtube-Clone/blob/d8d6c35890b5d3ebb00b0cc6ace20deea99974b1/console/migrations/m201115_124738_add_mention_column_to_comment_table.php
console/migrations/m201115_124738_add_mention_column_to_comment_table.php
<?php use yii\db\Migration; /** * Handles adding columns to table `{{%comment}}`. */ class m201115_124738_add_mention_column_to_comment_table extends Migration { /** * {@inheritdoc} */ public function safeUp() { $this->addColumn('{{%comment}}', 'mention', $this->string(255)->after('pinned')); } /** * {@inheritdoc} */ public function safeDown() { $this->dropColumn('{{%comment}}', 'mention'); } }
php
BSD-3-Clause
d8d6c35890b5d3ebb00b0cc6ace20deea99974b1
2026-01-05T04:42:11.286050Z
false
thecodeholic/Yii2-Youtube-Clone
https://github.com/thecodeholic/Yii2-Youtube-Clone/blob/d8d6c35890b5d3ebb00b0cc6ace20deea99974b1/console/config/main.php
console/config/main.php
<?php $params = array_merge( require __DIR__ . '/../../common/config/params.php', require __DIR__ . '/../../common/config/params-local.php', require __DIR__ . '/params.php', require __DIR__ . '/params-local.php' ); return [ 'id' => 'app-console', 'basePath' => dirname(__DIR__), 'bootstrap' => ['log'], 'controllerNamespace' => 'console\controllers', 'aliases' => [ '@bower' => '@vendor/bower-asset', '@npm' => '@vendor/npm-asset', ], 'controllerMap' => [ 'fixture' => [ 'class' => 'yii\console\controllers\FixtureController', 'namespace' => 'common\fixtures', ], ], 'components' => [ 'log' => [ 'targets' => [ [ 'class' => 'yii\log\FileTarget', 'levels' => ['error', 'warning'], ], ], ], ], 'params' => $params, ];
php
BSD-3-Clause
d8d6c35890b5d3ebb00b0cc6ace20deea99974b1
2026-01-05T04:42:11.286050Z
false
thecodeholic/Yii2-Youtube-Clone
https://github.com/thecodeholic/Yii2-Youtube-Clone/blob/d8d6c35890b5d3ebb00b0cc6ace20deea99974b1/console/config/params.php
console/config/params.php
<?php return [ 'adminEmail' => 'admin@example.com', ];
php
BSD-3-Clause
d8d6c35890b5d3ebb00b0cc6ace20deea99974b1
2026-01-05T04:42:11.286050Z
false
thecodeholic/Yii2-Youtube-Clone
https://github.com/thecodeholic/Yii2-Youtube-Clone/blob/d8d6c35890b5d3ebb00b0cc6ace20deea99974b1/console/config/test.php
console/config/test.php
<?php return [ ];
php
BSD-3-Clause
d8d6c35890b5d3ebb00b0cc6ace20deea99974b1
2026-01-05T04:42:11.286050Z
false
thecodeholic/Yii2-Youtube-Clone
https://github.com/thecodeholic/Yii2-Youtube-Clone/blob/d8d6c35890b5d3ebb00b0cc6ace20deea99974b1/console/config/bootstrap.php
console/config/bootstrap.php
<?php
php
BSD-3-Clause
d8d6c35890b5d3ebb00b0cc6ace20deea99974b1
2026-01-05T04:42:11.286050Z
false
thecodeholic/Yii2-Youtube-Clone
https://github.com/thecodeholic/Yii2-Youtube-Clone/blob/d8d6c35890b5d3ebb00b0cc6ace20deea99974b1/backend/tests/_bootstrap.php
backend/tests/_bootstrap.php
<?php defined('YII_DEBUG') or define('YII_DEBUG', true); defined('YII_ENV') or define('YII_ENV', 'test'); defined('YII_APP_BASE_PATH') or define('YII_APP_BASE_PATH', __DIR__.'/../../'); require_once YII_APP_BASE_PATH . '/vendor/autoload.php'; require_once YII_APP_BASE_PATH . '/vendor/yiisoft/yii2/Yii.php'; require_once YII_APP_BASE_PATH . '/common/config/bootstrap.php'; require_once __DIR__ . '/../config/bootstrap.php';
php
BSD-3-Clause
d8d6c35890b5d3ebb00b0cc6ace20deea99974b1
2026-01-05T04:42:11.286050Z
false
thecodeholic/Yii2-Youtube-Clone
https://github.com/thecodeholic/Yii2-Youtube-Clone/blob/d8d6c35890b5d3ebb00b0cc6ace20deea99974b1/backend/tests/_data/login_data.php
backend/tests/_data/login_data.php
<?php return [ [ 'username' => 'erau', 'auth_key' => 'tUu1qHcde0diwUol3xeI-18MuHkkprQI', // password_0 'password_hash' => '$2y$13$nJ1WDlBaGcbCdbNC5.5l4.sgy.OMEKCqtDQOdQ2OWpgiKRWYyzzne', 'password_reset_token' => 'RkD_Jw0_8HEedzLk7MM-ZKEFfYR7VbMr_1392559490', 'created_at' => '1392559490', 'updated_at' => '1392559490', 'email' => 'sfriesen@jenkins.info', ], ];
php
BSD-3-Clause
d8d6c35890b5d3ebb00b0cc6ace20deea99974b1
2026-01-05T04:42:11.286050Z
false
thecodeholic/Yii2-Youtube-Clone
https://github.com/thecodeholic/Yii2-Youtube-Clone/blob/d8d6c35890b5d3ebb00b0cc6ace20deea99974b1/backend/tests/unit/_bootstrap.php
backend/tests/unit/_bootstrap.php
<?php /** * Here you can initialize variables via \Codeception\Util\Fixtures class * to store data in global array and use it in Tests. * * ```php * // Here _bootstrap.php * \Codeception\Util\Fixtures::add('user1', ['name' => 'davert']); * ``` * * In Tests * * ```php * \Codeception\Util\Fixtures::get('user1'); * ``` */
php
BSD-3-Clause
d8d6c35890b5d3ebb00b0cc6ace20deea99974b1
2026-01-05T04:42:11.286050Z
false
thecodeholic/Yii2-Youtube-Clone
https://github.com/thecodeholic/Yii2-Youtube-Clone/blob/d8d6c35890b5d3ebb00b0cc6ace20deea99974b1/backend/tests/_support/UnitTester.php
backend/tests/_support/UnitTester.php
<?php namespace backend\tests; /** * Inherited Methods * @method void wantToTest($text) * @method void wantTo($text) * @method void execute($callable) * @method void expectTo($prediction) * @method void expect($prediction) * @method void amGoingTo($argumentation) * @method void am($role) * @method void lookForwardTo($achieveValue) * @method void comment($description) * @method \Codeception\Lib\Friend haveFriend($name, $actorClass = NULL) * * @SuppressWarnings(PHPMD) */ class UnitTester extends \Codeception\Actor { use _generated\UnitTesterActions; /** * Define custom actions here */ }
php
BSD-3-Clause
d8d6c35890b5d3ebb00b0cc6ace20deea99974b1
2026-01-05T04:42:11.286050Z
false
thecodeholic/Yii2-Youtube-Clone
https://github.com/thecodeholic/Yii2-Youtube-Clone/blob/d8d6c35890b5d3ebb00b0cc6ace20deea99974b1/backend/tests/_support/FunctionalTester.php
backend/tests/_support/FunctionalTester.php
<?php namespace backend\tests; /** * Inherited Methods * @method void wantToTest($text) * @method void wantTo($text) * @method void execute($callable) * @method void expectTo($prediction) * @method void expect($prediction) * @method void amGoingTo($argumentation) * @method void am($role) * @method void lookForwardTo($achieveValue) * @method void comment($description) * @method \Codeception\Lib\Friend haveFriend($name, $actorClass = NULL) * * @SuppressWarnings(PHPMD) */ class FunctionalTester extends \Codeception\Actor { use _generated\FunctionalTesterActions; /** * Define custom actions here */ }
php
BSD-3-Clause
d8d6c35890b5d3ebb00b0cc6ace20deea99974b1
2026-01-05T04:42:11.286050Z
false
thecodeholic/Yii2-Youtube-Clone
https://github.com/thecodeholic/Yii2-Youtube-Clone/blob/d8d6c35890b5d3ebb00b0cc6ace20deea99974b1/backend/tests/functional/LoginCest.php
backend/tests/functional/LoginCest.php
<?php namespace backend\tests\functional; use backend\tests\FunctionalTester; use common\fixtures\UserFixture; /** * Class LoginCest */ class LoginCest { /** * Load fixtures before db transaction begin * Called in _before() * @see \Codeception\Module\Yii2::_before() * @see \Codeception\Module\Yii2::loadFixtures() * @return array */ public function _fixtures() { return [ 'user' => [ 'class' => UserFixture::className(), 'dataFile' => codecept_data_dir() . 'login_data.php' ] ]; } /** * @param FunctionalTester $I */ public function loginUser(FunctionalTester $I) { $I->amOnPage('/site/login'); $I->fillField('Username', 'erau'); $I->fillField('Password', 'password_0'); $I->click('login-button'); $I->see('Logout (erau)', 'form button[type=submit]'); $I->dontSeeLink('Login'); $I->dontSeeLink('Signup'); } }
php
BSD-3-Clause
d8d6c35890b5d3ebb00b0cc6ace20deea99974b1
2026-01-05T04:42:11.286050Z
false
thecodeholic/Yii2-Youtube-Clone
https://github.com/thecodeholic/Yii2-Youtube-Clone/blob/d8d6c35890b5d3ebb00b0cc6ace20deea99974b1/backend/tests/functional/_bootstrap.php
backend/tests/functional/_bootstrap.php
<?php /** * Here you can initialize variables via \Codeception\Util\Fixtures class * to store data in global array and use it in Cests. * * ```php * // Here _bootstrap.php * \Codeception\Util\Fixtures::add('user1', ['name' => 'davert']); * ``` * * In Cests * * ```php * \Codeception\Util\Fixtures::get('user1'); * ``` */
php
BSD-3-Clause
d8d6c35890b5d3ebb00b0cc6ace20deea99974b1
2026-01-05T04:42:11.286050Z
false
thecodeholic/Yii2-Youtube-Clone
https://github.com/thecodeholic/Yii2-Youtube-Clone/blob/d8d6c35890b5d3ebb00b0cc6ace20deea99974b1/backend/controllers/CommentController.php
backend/controllers/CommentController.php
<?php namespace backend\controllers; use Yii; use common\models\Comment; use backend\models\CommentSearch; use yii\filters\AccessControl; use yii\web\Controller; use yii\web\NotFoundHttpException; use yii\filters\VerbFilter; /** * CommentController implements the CRUD actions for Comment model. */ class CommentController extends Controller { /** * {@inheritdoc} */ public function behaviors() { return [ 'access' => [ 'class' => AccessControl::class, 'rules' => [ [ 'allow' => true, 'roles' => ['@'] ] ] ], 'verbs' => [ 'class' => VerbFilter::className(), 'actions' => [ 'delete' => ['POST'], ], ], ]; } /** * Lists all Comment models. * @return mixed */ public function actionIndex() { $searchModel = new CommentSearch(); $dataProvider = $searchModel->search(Yii::$app->request->queryParams, Yii::$app->user->id); return $this->render('index', [ 'searchModel' => $searchModel, 'dataProvider' => $dataProvider, ]); } /** * Displays a single Comment model. * @param integer $id * @return mixed * @throws NotFoundHttpException if the model cannot be found */ public function actionView($id) { return $this->render('view', [ 'model' => $this->findModel($id), ]); } /** * Creates a new Comment model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Comment(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } return $this->render('create', [ 'model' => $model, ]); } /** * Updates an existing Comment model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id * @return mixed * @throws NotFoundHttpException if the model cannot be found */ public function actionUpdate($id) { $model = $this->findModel($id); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } return $this->render('update', [ 'model' => $model, ]); } /** * Deletes an existing Comment model. * If deletion is successful, the browser will be redirected to the 'index' page. * @param integer $id * @return mixed * @throws NotFoundHttpException if the model cannot be found */ public function actionDelete($id) { $this->findModel($id)->delete(); return $this->redirect(['index']); } /** * Finds the Comment model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Comment the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Comment::findOne($id)) !== null) { return $model; } throw new NotFoundHttpException('The requested page does not exist.'); } }
php
BSD-3-Clause
d8d6c35890b5d3ebb00b0cc6ace20deea99974b1
2026-01-05T04:42:11.286050Z
false
thecodeholic/Yii2-Youtube-Clone
https://github.com/thecodeholic/Yii2-Youtube-Clone/blob/d8d6c35890b5d3ebb00b0cc6ace20deea99974b1/backend/controllers/VideoController.php
backend/controllers/VideoController.php
<?php namespace backend\controllers; use Yii; use common\models\Video; use yii\data\ActiveDataProvider; use yii\filters\AccessControl; use yii\web\Controller; use yii\web\NotFoundHttpException; use yii\filters\VerbFilter; use yii\web\UploadedFile; /** * VideoController implements the CRUD actions for Video model. */ class VideoController extends Controller { /** * {@inheritdoc} */ public function behaviors() { return [ 'access' => [ 'class' => AccessControl::class, 'rules' => [ [ 'allow' => true, 'roles' => ['@'] ] ] ], 'verbs' => [ 'class' => VerbFilter::className(), 'actions' => [ 'delete' => ['POST'], ], ], ]; } /** * Lists all Video models. * * @return mixed */ public function actionIndex() { $dataProvider = new ActiveDataProvider([ 'query' => Video::find() ->creator(Yii::$app->user->id) ->latest(), ]); return $this->render('index', [ 'dataProvider' => $dataProvider, ]); } /** * Creates a new Video model. * If creation is successful, the browser will be redirected to the 'view' page. * * @return mixed */ public function actionCreate() { $model = new Video(); $model->video = UploadedFile::getInstanceByName('video'); if (Yii::$app->request->isPost && $model->save()) { return $this->redirect(['update', 'id' => $model->video_id]); } return $this->render('create', [ 'model' => $model, ]); } /** * Updates an existing Video model. * If update is successful, the browser will be redirected to the 'view' page. * * @param string $id * @return mixed * @throws NotFoundHttpException if the model cannot be found */ public function actionUpdate($id) { $model = $this->findModel($id); $model->thumbnail = UploadedFile::getInstanceByName('thumbnail'); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['update', 'id' => $model->video_id]); } return $this->render('update', [ 'model' => $model, ]); } /** * Deletes an existing Video model. * If deletion is successful, the browser will be redirected to the 'index' page. * * @param string $id * @return mixed * @throws \Throwable * @throws \yii\db\StaleObjectException * @throws \yii\web\NotFoundHttpException if the model cannot be found */ public function actionDelete($id) { $this->findModel($id)->delete(); return $this->redirect(['index']); } /** * Finds the Video model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * * @param string $id * @return Video the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (( $model = Video::findOne($id) ) !== null) { return $model; } throw new NotFoundHttpException('The requested page does not exist.'); } }
php
BSD-3-Clause
d8d6c35890b5d3ebb00b0cc6ace20deea99974b1
2026-01-05T04:42:11.286050Z
false
thecodeholic/Yii2-Youtube-Clone
https://github.com/thecodeholic/Yii2-Youtube-Clone/blob/d8d6c35890b5d3ebb00b0cc6ace20deea99974b1/backend/controllers/SiteController.php
backend/controllers/SiteController.php
<?php namespace backend\controllers; use common\models\Subscriber; use common\models\Video; use common\models\VideoView; use Yii; use yii\web\Controller; use yii\filters\VerbFilter; use yii\filters\AccessControl; use common\models\LoginForm; /** * Site controller */ class SiteController extends Controller { /** * {@inheritdoc} */ public function behaviors() { return [ 'access' => [ 'class' => AccessControl::className(), 'rules' => [ [ 'actions' => ['login', 'error'], 'allow' => true, ], [ 'actions' => ['logout', 'index'], 'allow' => true, 'roles' => ['@'], ], ], ], 'verbs' => [ 'class' => VerbFilter::className(), 'actions' => [ 'logout' => ['post'], ], ], ]; } /** * {@inheritdoc} */ public function actions() { return [ 'error' => [ 'class' => 'yii\web\ErrorAction', ], ]; } /** * Displays homepage. * * @return string */ public function actionIndex() { $user = Yii::$app->user->identity; $userId = $user->id; $latestVideo = Video::find() ->latest() ->creator($userId) ->limit(1) ->one(); $numberOfView = VideoView::find() ->alias('vv') ->innerJoin(Video::tableName() . ' v', 'v.video_id = vv.video_id') ->andWhere(['v.created_by' => $userId]) ->count(); $numberOfSubscribers = Yii::$app->cache->get('subscribers-'.$userId); if (!$numberOfSubscribers) { $numberOfSubscribers = $user->getSubscribers()->count(); Yii::$app->cache->set('subscribers-'.$userId, $numberOfSubscribers); } $subscribers = Subscriber::find() ->with('user') ->andWhere(['channel_id' => $userId]) ->orderBy('created_at DESC') ->limit(3) ->all(); return $this->render('index', [ 'latestVideo' => $latestVideo, 'numberOfView' => $numberOfView, 'numberOfSubscribers' => $numberOfSubscribers, 'subscribers' => $subscribers, ]); } /** * Login action. * * @return string */ public function actionLogin() { $this->layout = 'auth'; if (!Yii::$app->user->isGuest) { return $this->goHome(); } $model = new LoginForm(); if ($model->load(Yii::$app->request->post()) && $model->login()) { return $this->goBack(); } else { $model->password = ''; return $this->render('login', [ 'model' => $model, ]); } } /** * Logout action. * * @return string */ public function actionLogout() { Yii::$app->user->logout(); return $this->goHome(); } }
php
BSD-3-Clause
d8d6c35890b5d3ebb00b0cc6ace20deea99974b1
2026-01-05T04:42:11.286050Z
false
thecodeholic/Yii2-Youtube-Clone
https://github.com/thecodeholic/Yii2-Youtube-Clone/blob/d8d6c35890b5d3ebb00b0cc6ace20deea99974b1/backend/models/CommentSearch.php
backend/models/CommentSearch.php
<?php namespace backend\models; use yii\base\Model; use yii\data\ActiveDataProvider; use common\models\Comment; /** * CommentSearch represents the model behind the search form of `common\models\Comment`. */ class CommentSearch extends Comment { /** * {@inheritdoc} */ public function rules() { return [ [['id', 'parent_id', 'pinned', 'created_at', 'updated_at', 'created_by'], 'integer'], [['comment', 'video_id'], 'safe'], ]; } /** * {@inheritdoc} */ public function scenarios() { // bypass scenarios() implementation in the parent class return Model::scenarios(); } /** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params, $userId) { $query = Comment::find() ->with('video') ->parent() ->byChannel($userId) ->latest(); // add conditions that should always apply here $dataProvider = new ActiveDataProvider([ 'query' => $query, ]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } // grid filtering conditions $query->andFilterWhere([ 'id' => $this->id, 'parent_id' => $this->parent_id, 'pinned' => $this->pinned, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'created_by' => $this->created_by, ]); $query->andFilterWhere(['like', 'comment', $this->comment]) ->andFilterWhere(['like', 'video_id', $this->video_id]); return $dataProvider; } }
php
BSD-3-Clause
d8d6c35890b5d3ebb00b0cc6ace20deea99974b1
2026-01-05T04:42:11.286050Z
false
thecodeholic/Yii2-Youtube-Clone
https://github.com/thecodeholic/Yii2-Youtube-Clone/blob/d8d6c35890b5d3ebb00b0cc6ace20deea99974b1/backend/views/site/login.php
backend/views/site/login.php
<?php /* @var $this yii\web\View */ /* @var $form yii\bootstrap4\ActiveForm */ /* @var $model \common\models\LoginForm */ use yii\helpers\Html; use yii\bootstrap4\ActiveForm; $this->title = 'Login'; $this->params['breadcrumbs'][] = $this->title; ?> <div class="site-login"> <h1><?= Html::encode($this->title) ?></h1> <p>Please fill out the following fields to login:</p> <div class="row"> <div class="col-lg-5"> <?php $form = ActiveForm::begin(['id' => 'login-form']); ?> <?= $form->field($model, 'username')->textInput(['autofocus' => true]) ?> <?= $form->field($model, 'password')->passwordInput() ?> <?= $form->field($model, 'rememberMe')->checkbox() ?> <div class="form-group"> <?= Html::submitButton('Login', ['class' => 'btn btn-primary', 'name' => 'login-button']) ?> </div> <?php ActiveForm::end(); ?> </div> </div> </div>
php
BSD-3-Clause
d8d6c35890b5d3ebb00b0cc6ace20deea99974b1
2026-01-05T04:42:11.286050Z
false
thecodeholic/Yii2-Youtube-Clone
https://github.com/thecodeholic/Yii2-Youtube-Clone/blob/d8d6c35890b5d3ebb00b0cc6ace20deea99974b1/backend/views/site/index.php
backend/views/site/index.php
<?php /* @var $this yii\web\View */ /** @var $latestVideo \common\models\Video */ /** @var $numberOfView integer */ /** @var $numberOfSubscribers integer */ /** @var $subscribers \common\models\Subscriber[] */ $this->title = Yii::$app->name; ?> <div class="site-index d-flex"> <div class="card m-2" style="width: 14rem;"> <?php if ($latestVideo): ?> <div class="embed-responsive embed-responsive-16by9 mb-3"> <video class="embed-responsive-item" poster="<?php echo $latestVideo->getThumbnailLink() ?>" src="<?php echo $latestVideo->getVideoLink() ?>"></video> </div> <div class="card-body"> <h6 class="card-title"><?php echo $latestVideo->title ?></h6> <p class="card-text"> Likes: <?php echo $latestVideo->getLikes()->count() ?><br> Views: <?php echo $latestVideo->getViews()->count() ?> </p> <a href="<?php echo \yii\helpers\Url::to(['/video/update', 'id' => $latestVideo->video_id]) ?>" class="btn btn-primary"> Edit </a> </div> <?php else: ?> <div class="card-body"> You don't have uploaded videos yet </div> <?php endif; ?> </div> <div class="card m-2" style="width: 14rem;"> <div class="card-body"> <h6 class="card-title">Total Views</h6> <p class="card-text" style="font-size: 48px"> <?php echo $numberOfView ?> </p> </div> </div> <div class="card m-2" style="width: 14rem;"> <div class="card-body"> <h6 class="card-title">Total Subscribers</h6> <p class="card-text" style="font-size: 48px"> <?php echo $numberOfSubscribers ?> </p> </div> </div> <div class="card m-2" style="width: 14rem;"> <div class="card-body"> <h6 class="card-title">Latest Subscribers</h6> <?php foreach ($subscribers as $subscriber): ?> <div> <?php echo $subscriber->user->username ?> </div> <?php endforeach; ?> </div> </div> </div>
php
BSD-3-Clause
d8d6c35890b5d3ebb00b0cc6ace20deea99974b1
2026-01-05T04:42:11.286050Z
false
thecodeholic/Yii2-Youtube-Clone
https://github.com/thecodeholic/Yii2-Youtube-Clone/blob/d8d6c35890b5d3ebb00b0cc6ace20deea99974b1/backend/views/site/error.php
backend/views/site/error.php
<?php /* @var $this yii\web\View */ /* @var $name string */ /* @var $message string */ /* @var $exception Exception */ use yii\helpers\Html; $this->title = $name; ?> <div class="site-error"> <h1><?= Html::encode($this->title) ?></h1> <div class="alert alert-danger"> <?= nl2br(Html::encode($message)) ?> </div> <p> The above error occurred while the Web server was processing your request. </p> <p> Please contact us if you think this is a server error. Thank you. </p> </div>
php
BSD-3-Clause
d8d6c35890b5d3ebb00b0cc6ace20deea99974b1
2026-01-05T04:42:11.286050Z
false
thecodeholic/Yii2-Youtube-Clone
https://github.com/thecodeholic/Yii2-Youtube-Clone/blob/d8d6c35890b5d3ebb00b0cc6ace20deea99974b1/backend/views/comment/_item.php
backend/views/comment/_item.php
<?php /** * User: TheCodeholic * Date: 11/14/2020 * Time: 9:45 AM */ /** @var $this \yii\web\View */ /** @var $model \common\models\Comment */ ?> <div class="d-flex"> <div class="comment-wrapper"> <?php echo $this->render('_comment_item', [ 'model' => $model ]) ?> </div> <div class="video-wrapper"> <?php echo $this->render('@backend/views/video/_video_item', [ 'model' => $model->video ]) ?> </div> </div>
php
BSD-3-Clause
d8d6c35890b5d3ebb00b0cc6ace20deea99974b1
2026-01-05T04:42:11.286050Z
false
thecodeholic/Yii2-Youtube-Clone
https://github.com/thecodeholic/Yii2-Youtube-Clone/blob/d8d6c35890b5d3ebb00b0cc6ace20deea99974b1/backend/views/comment/_form.php
backend/views/comment/_form.php
<?php use yii\helpers\Html; use yii\widgets\ActiveForm; /* @var $this yii\web\View */ /* @var $model common\models\Comment */ /* @var $form yii\widgets\ActiveForm */ ?> <div class="comment-form"> <?php $form = ActiveForm::begin(); ?> <?= $form->field($model, 'comment')->textarea(['rows' => 6]) ?> <?= $form->field($model, 'video_id')->textInput(['maxlength' => true]) ?> <?= $form->field($model, 'parent_id')->textInput() ?> <?= $form->field($model, 'pinned')->textInput() ?> <?= $form->field($model, 'created_at')->textInput() ?> <?= $form->field($model, 'updated_at')->textInput() ?> <?= $form->field($model, 'created_by')->textInput() ?> <div class="form-group"> <?= Html::submitButton('Save', ['class' => 'btn btn-success']) ?> </div> <?php ActiveForm::end(); ?> </div>
php
BSD-3-Clause
d8d6c35890b5d3ebb00b0cc6ace20deea99974b1
2026-01-05T04:42:11.286050Z
false
thecodeholic/Yii2-Youtube-Clone
https://github.com/thecodeholic/Yii2-Youtube-Clone/blob/d8d6c35890b5d3ebb00b0cc6ace20deea99974b1/backend/views/comment/_comment_item.php
backend/views/comment/_comment_item.php
<?php /** * User: TheCodeholic * Date: 11/14/2020 * Time: 10:36 AM */ /** @var $this \yii\web\View */ /** @var $model \common\models\Comment */ ?> <div class="media media-comment comment-item" data-id="<?php echo $model->id ?>"> <img class="mr-3 comment-avatar" src="/img/avatar.svg" alt="" style="width: 50px"> <div class="media-body"> <h6 class="mt-0"> <?php echo \common\helpers\Html::channelLink($model->createdBy) ?> <small class="text-muted"> <?php echo Yii::$app->formatter->asRelativeTime($model->created_at) ?> <?php if ($model->created_at !== $model->updated_at): ?> (edited) <?php endif; ?> </small> </h6> <div class="comment-text"> <div class="text-wrapper"> <?php if ($model->mention): ?> <span class="badge bg-info"><?php echo '@' . $model->mention ?></span> <?php endif; ?> <?php echo $model->comment ?> </div> <div class="bottom-actions my-2"> <button data-action="<?php echo \yii\helpers\Url::to(['/comment/reply']) ?>" class="btn btn-sm btn-light btn-reply"> REPLY </button> <div class="btn-group comment-actions"> <button class="btn dropdown-toggle" type="button" id="dropdownMenuButton" data-toggle="dropdown"> <i class="fas fa-ellipsis-v"></i> </button> <div class="dropdown-menu dropdown-menu-right" aria-labelledby="dropdownMenuButton"> <a class="dropdown-item item-delete-comment" href="<?php echo \yii\helpers\Url::to(['/comment/delete', 'id' => $model->id]) ?>"> <i class="fas fa-trash"></i> Delete </a> </div> </div> </div> <div class="reply-section"> </div> <div class="sub-comments"> <?php foreach ($model->comments as $comment): ?> <?php echo $this->render('_comment_item', ['model' => $comment]) ?> <?php endforeach; ?> </div> </div> </div> </div>
php
BSD-3-Clause
d8d6c35890b5d3ebb00b0cc6ace20deea99974b1
2026-01-05T04:42:11.286050Z
false
thecodeholic/Yii2-Youtube-Clone
https://github.com/thecodeholic/Yii2-Youtube-Clone/blob/d8d6c35890b5d3ebb00b0cc6ace20deea99974b1/backend/views/comment/view.php
backend/views/comment/view.php
<?php use yii\helpers\Html; use yii\widgets\DetailView; /* @var $this yii\web\View */ /* @var $model common\models\Comment */ $this->title = $model->id; $this->params['breadcrumbs'][] = ['label' => 'Comments', 'url' => ['index']]; $this->params['breadcrumbs'][] = $this->title; \yii\web\YiiAsset::register($this); ?> <div class="comment-view"> <h1><?= Html::encode($this->title) ?></h1> <p> <?= Html::a('Update', ['update', 'id' => $model->id], ['class' => 'btn btn-primary']) ?> <?= Html::a('Delete', ['delete', 'id' => $model->id], [ 'class' => 'btn btn-danger', 'data' => [ 'confirm' => 'Are you sure you want to delete this item?', 'method' => 'post', ], ]) ?> </p> <?= DetailView::widget([ 'model' => $model, 'attributes' => [ 'id', 'comment:ntext', 'video_id', 'parent_id', 'pinned', 'created_at', 'updated_at', 'created_by', ], ]) ?> </div>
php
BSD-3-Clause
d8d6c35890b5d3ebb00b0cc6ace20deea99974b1
2026-01-05T04:42:11.286050Z
false
thecodeholic/Yii2-Youtube-Clone
https://github.com/thecodeholic/Yii2-Youtube-Clone/blob/d8d6c35890b5d3ebb00b0cc6ace20deea99974b1/backend/views/comment/index.php
backend/views/comment/index.php
<?php use yii\helpers\Html; use yii\grid\GridView; /* @var $this yii\web\View */ /* @var $searchModel backend\models\CommentSearch */ /* @var $dataProvider yii\data\ActiveDataProvider */ $this->title = 'Comments'; $this->params['breadcrumbs'][] = $this->title; ?> <div class="comment-index"> <h1><?= Html::encode($this->title) ?></h1> <?php // echo $this->render('_search', ['model' => $searchModel]); ?> <?= \yii\widgets\ListView::widget([ 'dataProvider' => $dataProvider, 'itemView' => '_item', 'pager' => [ 'class' => \yii\bootstrap4\LinkPager::class ], 'layout' => '<div class="mt-4">{items}</div>{pager}' ]); ?> </div>
php
BSD-3-Clause
d8d6c35890b5d3ebb00b0cc6ace20deea99974b1
2026-01-05T04:42:11.286050Z
false
thecodeholic/Yii2-Youtube-Clone
https://github.com/thecodeholic/Yii2-Youtube-Clone/blob/d8d6c35890b5d3ebb00b0cc6ace20deea99974b1/backend/views/comment/_search.php
backend/views/comment/_search.php
<?php use yii\helpers\Html; use yii\widgets\ActiveForm; /* @var $this yii\web\View */ /* @var $model backend\models\CommentSearch */ /* @var $form yii\widgets\ActiveForm */ ?> <div class="comment-search"> <?php $form = ActiveForm::begin([ 'action' => ['index'], 'method' => 'get', ]); ?> <?= $form->field($model, 'id') ?> <?= $form->field($model, 'comment') ?> <?= $form->field($model, 'video_id') ?> <?= $form->field($model, 'parent_id') ?> <?= $form->field($model, 'pinned') ?> <?php // echo $form->field($model, 'created_at') ?> <?php // echo $form->field($model, 'updated_at') ?> <?php // echo $form->field($model, 'created_by') ?> <div class="form-group"> <?= Html::submitButton('Search', ['class' => 'btn btn-primary']) ?> <?= Html::resetButton('Reset', ['class' => 'btn btn-outline-secondary']) ?> </div> <?php ActiveForm::end(); ?> </div>
php
BSD-3-Clause
d8d6c35890b5d3ebb00b0cc6ace20deea99974b1
2026-01-05T04:42:11.286050Z
false
thecodeholic/Yii2-Youtube-Clone
https://github.com/thecodeholic/Yii2-Youtube-Clone/blob/d8d6c35890b5d3ebb00b0cc6ace20deea99974b1/backend/views/comment/update.php
backend/views/comment/update.php
<?php use yii\helpers\Html; /* @var $this yii\web\View */ /* @var $model common\models\Comment */ $this->title = 'Update Comment: ' . $model->id; $this->params['breadcrumbs'][] = ['label' => 'Comments', 'url' => ['index']]; $this->params['breadcrumbs'][] = ['label' => $model->id, 'url' => ['view', 'id' => $model->id]]; $this->params['breadcrumbs'][] = 'Update'; ?> <div class="comment-update"> <h1><?= Html::encode($this->title) ?></h1> <?= $this->render('_form', [ 'model' => $model, ]) ?> </div>
php
BSD-3-Clause
d8d6c35890b5d3ebb00b0cc6ace20deea99974b1
2026-01-05T04:42:11.286050Z
false
thecodeholic/Yii2-Youtube-Clone
https://github.com/thecodeholic/Yii2-Youtube-Clone/blob/d8d6c35890b5d3ebb00b0cc6ace20deea99974b1/backend/views/comment/create.php
backend/views/comment/create.php
<?php use yii\helpers\Html; /* @var $this yii\web\View */ /* @var $model common\models\Comment */ $this->title = 'Create Comment'; $this->params['breadcrumbs'][] = ['label' => 'Comments', 'url' => ['index']]; $this->params['breadcrumbs'][] = $this->title; ?> <div class="comment-create"> <h1><?= Html::encode($this->title) ?></h1> <?= $this->render('_form', [ 'model' => $model, ]) ?> </div>
php
BSD-3-Clause
d8d6c35890b5d3ebb00b0cc6ace20deea99974b1
2026-01-05T04:42:11.286050Z
false
thecodeholic/Yii2-Youtube-Clone
https://github.com/thecodeholic/Yii2-Youtube-Clone/blob/d8d6c35890b5d3ebb00b0cc6ace20deea99974b1/backend/views/layouts/main.php
backend/views/layouts/main.php
<?php /* @var $this \yii\web\View */ /* @var $content string */ use backend\assets\AppAsset; use yii\helpers\Html; use yii\bootstrap4\Nav; use yii\bootstrap4\NavBar; use yii\widgets\Breadcrumbs; use common\widgets\Alert; AppAsset::register($this); $this->beginContent('@backend/views/layouts/base.php'); ?> <main class="d-flex"> <?php echo $this->render('_sidebar') ?> <div class="content-wrapper p-3"> <?= Alert::widget() ?> <?= $content ?> </div> </main> <?php $this->endContent() ?>
php
BSD-3-Clause
d8d6c35890b5d3ebb00b0cc6ace20deea99974b1
2026-01-05T04:42:11.286050Z
false
thecodeholic/Yii2-Youtube-Clone
https://github.com/thecodeholic/Yii2-Youtube-Clone/blob/d8d6c35890b5d3ebb00b0cc6ace20deea99974b1/backend/views/layouts/base.php
backend/views/layouts/base.php
<?php /* @var $this \yii\web\View */ /* @var $content string */ use backend\assets\AppAsset; use yii\helpers\Html; use yii\bootstrap4\Nav; use yii\bootstrap4\NavBar; use yii\widgets\Breadcrumbs; use common\widgets\Alert; AppAsset::register($this); ?> <?php $this->beginPage() ?> <!DOCTYPE html> <html lang="<?= Yii::$app->language ?>"> <head> <meta charset="<?= Yii::$app->charset ?>"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1"> <?php $this->registerCsrfMetaTags() ?> <title><?= Html::encode($this->title) ?></title> <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.13.0/css/all.min.css" rel="stylesheet"> <?php $this->head() ?> </head> <body> <?php $this->beginBody() ?> <div class="wrap h-100 d-flex flex-column"> <div class="wrap h-100 d-flex flex-column"> <?php echo $this->render('_header') ?> <?php echo $content ?> </div> </div> <?php $this->endBody() ?> </body> </html> <?php $this->endPage() ?>
php
BSD-3-Clause
d8d6c35890b5d3ebb00b0cc6ace20deea99974b1
2026-01-05T04:42:11.286050Z
false
thecodeholic/Yii2-Youtube-Clone
https://github.com/thecodeholic/Yii2-Youtube-Clone/blob/d8d6c35890b5d3ebb00b0cc6ace20deea99974b1/backend/views/layouts/_sidebar.php
backend/views/layouts/_sidebar.php
<?php /** * User: TheCodeholic * Date: 4/17/2020 * Time: 9:20 AM */ ?> <aside class="shadow"> <?php echo \yii\bootstrap4\Nav::widget([ 'options' => [ 'class' => 'd-flex flex-column nav-pills' ], 'items' => [ [ 'label' => 'Dashboard', 'url' => ['/site/index'] ], [ 'label' => 'Videos', 'url' => ['/video/index'] ], [ 'label' => 'Comments', 'url' => ['/comment/index'] ] ] ]) ?> </aside>
php
BSD-3-Clause
d8d6c35890b5d3ebb00b0cc6ace20deea99974b1
2026-01-05T04:42:11.286050Z
false
thecodeholic/Yii2-Youtube-Clone
https://github.com/thecodeholic/Yii2-Youtube-Clone/blob/d8d6c35890b5d3ebb00b0cc6ace20deea99974b1/backend/views/layouts/_header.php
backend/views/layouts/_header.php
<?php /** * User: TheCodeholic * Date: 4/17/2020 * Time: 9:20 AM */ use yii\bootstrap4\Nav; use yii\bootstrap4\NavBar; NavBar::begin([ 'brandLabel' => Yii::$app->name, 'brandUrl' => Yii::$app->homeUrl, 'options' => ['class' => 'navbar-expand-lg navbar-light bg-light shadow-sm'], 'innerContainerOptions' => [ 'class' => 'container-fluid' ] ]); $menuItems = [ ['label' => 'Create', 'url' => ['/video/create']], ]; if (Yii::$app->user->isGuest) { $menuItems[] = ['label' => 'Login', 'url' => ['/site/login']]; } else { $menuItems[] = [ 'label' => 'Logout (' . Yii::$app->user->identity->username . ')', 'url' => ['/site/logout'], 'linkOptions' => [ 'data-method' => 'post' ] ]; } echo Nav::widget([ 'options' => ['class' => 'navbar-nav ml-auto'], 'items' => $menuItems, ]); NavBar::end();
php
BSD-3-Clause
d8d6c35890b5d3ebb00b0cc6ace20deea99974b1
2026-01-05T04:42:11.286050Z
false
thecodeholic/Yii2-Youtube-Clone
https://github.com/thecodeholic/Yii2-Youtube-Clone/blob/d8d6c35890b5d3ebb00b0cc6ace20deea99974b1/backend/views/layouts/auth.php
backend/views/layouts/auth.php
<?php /* @var $this \yii\web\View */ /* @var $content string */ use backend\assets\AppAsset; use yii\helpers\Html; use yii\bootstrap4\Nav; use yii\bootstrap4\NavBar; use yii\widgets\Breadcrumbs; use common\widgets\Alert; AppAsset::register($this); $this->beginContent('@backend/views/layouts/base.php'); ?> <main class="d-flex"> <div class="content-wrapper p-3"> <?= Alert::widget() ?> <?= $content ?> </div> </main> <?php $this->endContent() ?>
php
BSD-3-Clause
d8d6c35890b5d3ebb00b0cc6ace20deea99974b1
2026-01-05T04:42:11.286050Z
false
thecodeholic/Yii2-Youtube-Clone
https://github.com/thecodeholic/Yii2-Youtube-Clone/blob/d8d6c35890b5d3ebb00b0cc6ace20deea99974b1/backend/views/video/_form.php
backend/views/video/_form.php
<?php use yii\helpers\Html; use yii\bootstrap4\ActiveForm; /* @var $this yii\web\View */ /* @var $model common\models\Video */ /* @var $form yii\bootstrap4\ActiveForm */ \backend\assets\TagsInputAsset::register($this); ?> <div class="video-form"> <?php $form = ActiveForm::begin([ 'options' => ['enctype' => 'multipart/form-data'] ]); ?> <div class="row"> <div class="col-sm-8"> <?php echo $form->errorSummary($model) ?> <?= $form->field($model, 'title')->textInput(['maxlength' => true]) ?> <?= $form->field($model, 'description')->textarea(['rows' => 6]) ?> <div class="form-group"> <label><?php echo $model->getAttributeLabel('thumbnail') ?></label> <div class="custom-file"> <input type="file" class="custom-file-input" id="thumbnail" name="thumbnail"> <label class="custom-file-label" for="thumbnail">Choose file</label> </div> </div> <?= $form->field($model, 'tags', [ 'inputOptions' => ['data-role' => 'tagsinput'] ])->textInput(['maxlength' => true]) ?> </div> <div class="col-sm-4"> <div class="embed-responsive embed-responsive-16by9 mb-3"> <video class="embed-responsive-item" poster="<?php echo $model->getThumbnailLink() ?>" src="<?php echo $model->getVideoLink() ?>" controls></video> </div> <div class="mb-3"> <div class="text-muted">Video Link</div> <a href="<?php echo $model->getVideoLink() ?>"> Open Video </a> </div> <div class="mb-3"> <div class="text-muted">Video Name</div> <?php echo $model->video_name ?> </div> <?= $form->field($model, 'status')->dropDownList($model->getStatusLabels()) ?> </div> </div> <div class="form-group"> <?= Html::submitButton('Save', ['class' => 'btn btn-success']) ?> </div> <?php ActiveForm::end(); ?> </div>
php
BSD-3-Clause
d8d6c35890b5d3ebb00b0cc6ace20deea99974b1
2026-01-05T04:42:11.286050Z
false
thecodeholic/Yii2-Youtube-Clone
https://github.com/thecodeholic/Yii2-Youtube-Clone/blob/d8d6c35890b5d3ebb00b0cc6ace20deea99974b1/backend/views/video/_video_item.php
backend/views/video/_video_item.php
<?php /** * User: TheCodeholic * Date: 4/17/2020 * Time: 11:23 AM */ /** @var $model \common\models\Video */ use \yii\helpers\StringHelper; use yii\helpers\Url; ?> <div class="media"> <a href="<?php echo Url::to(['/video/update', 'id' => $model->video_id]) ?>"> <div class="embed-responsive embed-responsive-16by9 mr-2" style="width: 120px"> <video class="embed-responsive-item" poster="<?php echo $model->getThumbnailLink() ?>" src="<?php echo $model->getVideoLink() ?>"></video> </div> </a> <div class="media-body"> <h6 class="mt-0"><?php echo $model->title ?></h6> <?php echo StringHelper::truncateWords($model->description, 10) ?> </div> </div>
php
BSD-3-Clause
d8d6c35890b5d3ebb00b0cc6ace20deea99974b1
2026-01-05T04:42:11.286050Z
false
thecodeholic/Yii2-Youtube-Clone
https://github.com/thecodeholic/Yii2-Youtube-Clone/blob/d8d6c35890b5d3ebb00b0cc6ace20deea99974b1/backend/views/video/index.php
backend/views/video/index.php
<?php use yii\helpers\Html; use yii\grid\GridView; /* @var $this yii\web\View */ /* @var $dataProvider yii\data\ActiveDataProvider */ $this->title = 'Videos'; $this->params['breadcrumbs'][] = $this->title; ?> <div class="video-index"> <h1><?= Html::encode($this->title) ?></h1> <p> <?= Html::a('Create Video', ['create'], ['class' => 'btn btn-success']) ?> </p> <?= GridView::widget([ 'dataProvider' => $dataProvider, 'columns' => [ ['class' => 'yii\grid\SerialColumn'], [ 'attribute' => 'title', 'content' => function ($model) { return $this->render('_video_item', ['model' => $model]); } ], [ 'attribute' => 'status', 'content' => function ($model) { return $model->getStatusLabels()[$model->status]; } ], //'has_thumbnail', //'video_name', 'created_at:datetime', 'updated_at:datetime', //'created_by', [ 'class' => 'yii\grid\ActionColumn', 'buttons' => [ 'delete' => function ($url) { return Html::a('Delete', $url, [ 'data-method' => 'post', 'data-confirm' => 'Are you sure?' ]); } ] ], ], ]); ?> </div>
php
BSD-3-Clause
d8d6c35890b5d3ebb00b0cc6ace20deea99974b1
2026-01-05T04:42:11.286050Z
false
thecodeholic/Yii2-Youtube-Clone
https://github.com/thecodeholic/Yii2-Youtube-Clone/blob/d8d6c35890b5d3ebb00b0cc6ace20deea99974b1/backend/views/video/update.php
backend/views/video/update.php
<?php use yii\helpers\Html; /* @var $this yii\web\View */ /* @var $model common\models\Video */ $this->title = 'Update Video: ' . $model->title; $this->params['breadcrumbs'][] = ['label' => 'Videos', 'url' => ['index']]; $this->params['breadcrumbs'][] = ['label' => $model->title, 'url' => ['view', 'id' => $model->video_id]]; $this->params['breadcrumbs'][] = 'Update'; ?> <div class="video-update"> <h1><?= Html::encode($this->title) ?></h1> <?= $this->render('_form', [ 'model' => $model, ]) ?> </div>
php
BSD-3-Clause
d8d6c35890b5d3ebb00b0cc6ace20deea99974b1
2026-01-05T04:42:11.286050Z
false
thecodeholic/Yii2-Youtube-Clone
https://github.com/thecodeholic/Yii2-Youtube-Clone/blob/d8d6c35890b5d3ebb00b0cc6ace20deea99974b1/backend/views/video/create.php
backend/views/video/create.php
<?php use yii\helpers\Html; /* @var $this yii\web\View */ /* @var $model common\models\Video */ $this->title = 'Create Video'; $this->params['breadcrumbs'][] = ['label' => 'Videos', 'url' => ['index']]; $this->params['breadcrumbs'][] = $this->title; ?> <div class="video-create"> <h1><?= Html::encode($this->title) ?></h1> <div class="d-flex flex-column justify-content-center align-items-center"> <div class="upload-icon"> <i class="fas fa-upload"></i> </div> <br> <p class="m-0">Drag and drop a file you want to upload <p> <p class="text-muted">Your video will be private until you publish it</p> <?php $form = \yii\bootstrap4\ActiveForm::begin([ 'options' => ['enctype' => 'multipart/form-data'] ]) ?> <?php echo $form->errorSummary($model) ?> <button class="btn btn-primary btn-file"> Select File <input type="file" id="videoFile" name="video"> </button> <?php \yii\bootstrap4\ActiveForm::end() ?> </div> </div>
php
BSD-3-Clause
d8d6c35890b5d3ebb00b0cc6ace20deea99974b1
2026-01-05T04:42:11.286050Z
false
thecodeholic/Yii2-Youtube-Clone
https://github.com/thecodeholic/Yii2-Youtube-Clone/blob/d8d6c35890b5d3ebb00b0cc6ace20deea99974b1/backend/assets/AppAsset.php
backend/assets/AppAsset.php
<?php namespace backend\assets; use yii\web\AssetBundle; /** * Main backend application asset bundle. */ class AppAsset extends AssetBundle { public $basePath = '@webroot'; public $baseUrl = '@web'; public $css = [ 'css/site.css', ]; public $js = [ 'app.js' ]; public $depends = [ 'yii\web\YiiAsset', 'yii\bootstrap4\BootstrapAsset', ]; }
php
BSD-3-Clause
d8d6c35890b5d3ebb00b0cc6ace20deea99974b1
2026-01-05T04:42:11.286050Z
false
thecodeholic/Yii2-Youtube-Clone
https://github.com/thecodeholic/Yii2-Youtube-Clone/blob/d8d6c35890b5d3ebb00b0cc6ace20deea99974b1/backend/assets/TagsInputAsset.php
backend/assets/TagsInputAsset.php
<?php /** * User: TheCodeholic * Date: 4/17/2020 * Time: 11:12 AM */ namespace backend\assets; use yii\web\AssetBundle; use yii\web\JqueryAsset; /** * Class TagsInputAsset * * @author Zura Sekhniashvili <zurasekhniashvili@gmail.com> * @package backend\assets */ class TagsInputAsset extends AssetBundle { public $basePath = '@webroot/tagsinput'; public $baseUrl = '@web/tagsinput'; public $css = [ 'tagsinput.css' ]; public $js = [ 'tagsinput.js' ]; public $depends = [ JqueryAsset::class ]; }
php
BSD-3-Clause
d8d6c35890b5d3ebb00b0cc6ace20deea99974b1
2026-01-05T04:42:11.286050Z
false
thecodeholic/Yii2-Youtube-Clone
https://github.com/thecodeholic/Yii2-Youtube-Clone/blob/d8d6c35890b5d3ebb00b0cc6ace20deea99974b1/backend/config/main.php
backend/config/main.php
<?php $params = array_merge( require __DIR__ . '/../../common/config/params.php', require __DIR__ . '/../../common/config/params-local.php', require __DIR__ . '/params.php', require __DIR__ . '/params-local.php' ); return [ 'id' => 'app-backend', 'name' => 'FreeCodeTube Studio', 'basePath' => dirname(__DIR__), 'controllerNamespace' => 'backend\controllers', 'bootstrap' => ['log'], 'modules' => [], 'language' => 'en-US', 'components' => [ 'request' => [ 'csrfParam' => '_csrf-backend', ], 'user' => [ 'identityClass' => 'common\models\User', 'enableAutoLogin' => true, 'identityCookie' => ['name' => '_identity-backend', 'httpOnly' => true], ], 'session' => [ // this is the name of the session cookie used for login on the backend 'name' => 'advanced-backend', ], 'log' => [ 'traceLevel' => YII_DEBUG ? 3 : 0, 'targets' => [ [ 'class' => 'yii\log\FileTarget', 'levels' => ['error', 'warning'], ], ], ], 'errorHandler' => [ 'errorAction' => 'site/error', ], 'urlManager' => [ 'enablePrettyUrl' => true, 'showScriptName' => false, 'rules' => [ 'video/update/<id>' => 'video/update' ], ], 'assetManager' => [ 'appendTimestamp' => true ] ], 'params' => $params, ];
php
BSD-3-Clause
d8d6c35890b5d3ebb00b0cc6ace20deea99974b1
2026-01-05T04:42:11.286050Z
false
thecodeholic/Yii2-Youtube-Clone
https://github.com/thecodeholic/Yii2-Youtube-Clone/blob/d8d6c35890b5d3ebb00b0cc6ace20deea99974b1/backend/config/params.php
backend/config/params.php
<?php return [ 'adminEmail' => 'admin@example.com', ];
php
BSD-3-Clause
d8d6c35890b5d3ebb00b0cc6ace20deea99974b1
2026-01-05T04:42:11.286050Z
false
thecodeholic/Yii2-Youtube-Clone
https://github.com/thecodeholic/Yii2-Youtube-Clone/blob/d8d6c35890b5d3ebb00b0cc6ace20deea99974b1/backend/config/test.php
backend/config/test.php
<?php return [ 'id' => 'app-backend-tests', 'components' => [ 'assetManager' => [ 'basePath' => __DIR__ . '/../web/assets', ], 'urlManager' => [ 'showScriptName' => true, ], 'request' => [ 'cookieValidationKey' => 'test', ], ], ];
php
BSD-3-Clause
d8d6c35890b5d3ebb00b0cc6ace20deea99974b1
2026-01-05T04:42:11.286050Z
false
thecodeholic/Yii2-Youtube-Clone
https://github.com/thecodeholic/Yii2-Youtube-Clone/blob/d8d6c35890b5d3ebb00b0cc6ace20deea99974b1/backend/config/bootstrap.php
backend/config/bootstrap.php
<?php
php
BSD-3-Clause
d8d6c35890b5d3ebb00b0cc6ace20deea99974b1
2026-01-05T04:42:11.286050Z
false
thecodeholic/Yii2-Youtube-Clone
https://github.com/thecodeholic/Yii2-Youtube-Clone/blob/d8d6c35890b5d3ebb00b0cc6ace20deea99974b1/common/mail/emailVerify-html.php
common/mail/emailVerify-html.php
<?php use yii\helpers\Html; /* @var $this yii\web\View */ /* @var $user common\models\User */ $verifyLink = Yii::$app->urlManager->createAbsoluteUrl(['site/verify-email', 'token' => $user->verification_token]); ?> <div class="verify-email"> <p>Hello <?= Html::encode($user->username) ?>,</p> <p>Follow the link below to verify your email:</p> <p><?= Html::a(Html::encode($verifyLink), $verifyLink) ?></p> </div>
php
BSD-3-Clause
d8d6c35890b5d3ebb00b0cc6ace20deea99974b1
2026-01-05T04:42:11.286050Z
false
thecodeholic/Yii2-Youtube-Clone
https://github.com/thecodeholic/Yii2-Youtube-Clone/blob/d8d6c35890b5d3ebb00b0cc6ace20deea99974b1/common/mail/subscriber-text.php
common/mail/subscriber-text.php
<?php /** * User: TheCodeholic * Date: 4/18/2020 * Time: 10:27 AM */ /** @var $channel \common\models\User */ /** @var $user \common\models\User */ ?> Hello <?php echo $channel->username ?> User <?php echo $user->username ?> has subscribed to you FreeCodeTube team
php
BSD-3-Clause
d8d6c35890b5d3ebb00b0cc6ace20deea99974b1
2026-01-05T04:42:11.286050Z
false
thecodeholic/Yii2-Youtube-Clone
https://github.com/thecodeholic/Yii2-Youtube-Clone/blob/d8d6c35890b5d3ebb00b0cc6ace20deea99974b1/common/mail/passwordResetToken-text.php
common/mail/passwordResetToken-text.php
<?php /* @var $this yii\web\View */ /* @var $user common\models\User */ $resetLink = Yii::$app->urlManager->createAbsoluteUrl(['site/reset-password', 'token' => $user->password_reset_token]); ?> Hello <?= $user->username ?>, Follow the link below to reset your password: <?= $resetLink ?>
php
BSD-3-Clause
d8d6c35890b5d3ebb00b0cc6ace20deea99974b1
2026-01-05T04:42:11.286050Z
false
thecodeholic/Yii2-Youtube-Clone
https://github.com/thecodeholic/Yii2-Youtube-Clone/blob/d8d6c35890b5d3ebb00b0cc6ace20deea99974b1/common/mail/subscriber-html.php
common/mail/subscriber-html.php
<?php /** * User: TheCodeholic * Date: 4/18/2020 * Time: 10:27 AM */ /** @var $channel \common\models\User */ /** @var $user \common\models\User */ ?> <p>Hello <?php echo $channel->username ?></p> <p>User <?php echo \common\helpers\Html::channelLink($user, true) ?> has subscribed to you</p> <p>FreeCodeTube team</p>
php
BSD-3-Clause
d8d6c35890b5d3ebb00b0cc6ace20deea99974b1
2026-01-05T04:42:11.286050Z
false
thecodeholic/Yii2-Youtube-Clone
https://github.com/thecodeholic/Yii2-Youtube-Clone/blob/d8d6c35890b5d3ebb00b0cc6ace20deea99974b1/common/mail/mention-html.php
common/mail/mention-html.php
<?php /** * User: TheCodeholic * Date: 11/15/2020 * Time: 4:52 PM */ /** @var $channel \common\models\User */ /** @var $user \common\models\User */ /** @var $comment string */ ?> <p>Hello <?php echo $channel->username ?></p> <p>User <?php echo \common\helpers\Html::channelLink($user, true) ?> has mention you in the following comment</p> <blockquote> <?php echo $comment ?> </blockquote> <p>FreeCodeTube team</p>
php
BSD-3-Clause
d8d6c35890b5d3ebb00b0cc6ace20deea99974b1
2026-01-05T04:42:11.286050Z
false
thecodeholic/Yii2-Youtube-Clone
https://github.com/thecodeholic/Yii2-Youtube-Clone/blob/d8d6c35890b5d3ebb00b0cc6ace20deea99974b1/common/mail/emailVerify-text.php
common/mail/emailVerify-text.php
<?php /* @var $this yii\web\View */ /* @var $user common\models\User */ $verifyLink = Yii::$app->urlManager->createAbsoluteUrl(['site/verify-email', 'token' => $user->verification_token]); ?> Hello <?= $user->username ?>, Follow the link below to verify your email: <?= $verifyLink ?>
php
BSD-3-Clause
d8d6c35890b5d3ebb00b0cc6ace20deea99974b1
2026-01-05T04:42:11.286050Z
false
thecodeholic/Yii2-Youtube-Clone
https://github.com/thecodeholic/Yii2-Youtube-Clone/blob/d8d6c35890b5d3ebb00b0cc6ace20deea99974b1/common/mail/mention-text.php
common/mail/mention-text.php
<?php /** * User: TheCodeholic * Date: 11/15/2020 * Time: 4:52 PM */ ?> <?php /** * User: TheCodeholic * Date: 11/15/2020 * Time: 4:52 PM */ /** @var $channel \common\models\User */ /** @var $user \common\models\User */ /** @var $comment string */ ?> Hello <?php echo $channel->username ?> User <?php echo \common\helpers\Html::channelLink($user, true) ?> has mention you in the following comment <?php echo $comment ?> FreeCodeTube team
php
BSD-3-Clause
d8d6c35890b5d3ebb00b0cc6ace20deea99974b1
2026-01-05T04:42:11.286050Z
false
thecodeholic/Yii2-Youtube-Clone
https://github.com/thecodeholic/Yii2-Youtube-Clone/blob/d8d6c35890b5d3ebb00b0cc6ace20deea99974b1/common/mail/passwordResetToken-html.php
common/mail/passwordResetToken-html.php
<?php use yii\helpers\Html; /* @var $this yii\web\View */ /* @var $user common\models\User */ $resetLink = Yii::$app->urlManager->createAbsoluteUrl(['site/reset-password', 'token' => $user->password_reset_token]); ?> <div class="password-reset"> <p>Hello <?= Html::encode($user->username) ?>,</p> <p>Follow the link below to reset your password:</p> <p><?= Html::a(Html::encode($resetLink), $resetLink) ?></p> </div>
php
BSD-3-Clause
d8d6c35890b5d3ebb00b0cc6ace20deea99974b1
2026-01-05T04:42:11.286050Z
false
thecodeholic/Yii2-Youtube-Clone
https://github.com/thecodeholic/Yii2-Youtube-Clone/blob/d8d6c35890b5d3ebb00b0cc6ace20deea99974b1/common/mail/layouts/text.php
common/mail/layouts/text.php
<?php use yii\helpers\Html; /** @var \yii\web\View $this view component instance */ /** @var \yii\mail\MessageInterface $message the message being composed */ /** @var string $content main view render result */ ?> <?php $this->beginPage() ?> <?php $this->beginBody() ?> <?= $content ?> <?php $this->endBody() ?> <?php $this->endPage() ?>
php
BSD-3-Clause
d8d6c35890b5d3ebb00b0cc6ace20deea99974b1
2026-01-05T04:42:11.286050Z
false
thecodeholic/Yii2-Youtube-Clone
https://github.com/thecodeholic/Yii2-Youtube-Clone/blob/d8d6c35890b5d3ebb00b0cc6ace20deea99974b1/common/mail/layouts/html.php
common/mail/layouts/html.php
<?php use yii\helpers\Html; /* @var $this \yii\web\View view component instance */ /* @var $message \yii\mail\MessageInterface the message being composed */ /* @var $content string main view render result */ ?> <?php $this->beginPage() ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=<?= Yii::$app->charset ?>" /> <title><?= Html::encode($this->title) ?></title> <?php $this->head() ?> </head> <body> <?php $this->beginBody() ?> <?= $content ?> <?php $this->endBody() ?> </body> </html> <?php $this->endPage() ?>
php
BSD-3-Clause
d8d6c35890b5d3ebb00b0cc6ace20deea99974b1
2026-01-05T04:42:11.286050Z
false
thecodeholic/Yii2-Youtube-Clone
https://github.com/thecodeholic/Yii2-Youtube-Clone/blob/d8d6c35890b5d3ebb00b0cc6ace20deea99974b1/common/helpers/Html.php
common/helpers/Html.php
<?php /** * User: TheCodeholic * Date: 4/18/2020 * Time: 10:18 AM */ namespace common\helpers; use yii\helpers\Url; /** * Class Html * * @author Zura Sekhniashvili <zurasekhniashvili@gmail.com> * @package common\helpers */ class Html { public static function channelLink($user, $schema = false) { return \yii\helpers\Html::a($user->username, Url::to(['/channel/view', 'username' => $user->username], $schema), ['class' => 'text-dark channel-link']); } }
php
BSD-3-Clause
d8d6c35890b5d3ebb00b0cc6ace20deea99974b1
2026-01-05T04:42:11.286050Z
false
thecodeholic/Yii2-Youtube-Clone
https://github.com/thecodeholic/Yii2-Youtube-Clone/blob/d8d6c35890b5d3ebb00b0cc6ace20deea99974b1/common/fixtures/UserFixture.php
common/fixtures/UserFixture.php
<?php namespace common\fixtures; use yii\test\ActiveFixture; class UserFixture extends ActiveFixture { public $modelClass = 'common\models\User'; }
php
BSD-3-Clause
d8d6c35890b5d3ebb00b0cc6ace20deea99974b1
2026-01-05T04:42:11.286050Z
false
thecodeholic/Yii2-Youtube-Clone
https://github.com/thecodeholic/Yii2-Youtube-Clone/blob/d8d6c35890b5d3ebb00b0cc6ace20deea99974b1/common/tests/_bootstrap.php
common/tests/_bootstrap.php
<?php defined('YII_DEBUG') or define('YII_DEBUG', true); defined('YII_ENV') or define('YII_ENV', 'test'); defined('YII_APP_BASE_PATH') or define('YII_APP_BASE_PATH', __DIR__.'/../../'); require_once __DIR__ . '/../../vendor/autoload.php'; require_once __DIR__ . '/../../vendor/yiisoft/yii2/Yii.php'; require __DIR__ . '/../config/bootstrap.php';
php
BSD-3-Clause
d8d6c35890b5d3ebb00b0cc6ace20deea99974b1
2026-01-05T04:42:11.286050Z
false
thecodeholic/Yii2-Youtube-Clone
https://github.com/thecodeholic/Yii2-Youtube-Clone/blob/d8d6c35890b5d3ebb00b0cc6ace20deea99974b1/common/tests/_data/user.php
common/tests/_data/user.php
<?php return [ [ 'username' => 'bayer.hudson', 'auth_key' => 'HP187Mvq7Mmm3CTU80dLkGmni_FUH_lR', //password_0 'password_hash' => '$2y$13$EjaPFBnZOQsHdGuHI.xvhuDp1fHpo8hKRSk6yshqa9c5EG8s3C3lO', 'password_reset_token' => 'ExzkCOaYc1L8IOBs4wdTGGbgNiG3Wz1I_1402312317', 'created_at' => '1402312317', 'updated_at' => '1402312317', 'email' => 'nicole.paucek@schultz.info', ], ];
php
BSD-3-Clause
d8d6c35890b5d3ebb00b0cc6ace20deea99974b1
2026-01-05T04:42:11.286050Z
false
thecodeholic/Yii2-Youtube-Clone
https://github.com/thecodeholic/Yii2-Youtube-Clone/blob/d8d6c35890b5d3ebb00b0cc6ace20deea99974b1/common/tests/unit/models/LoginFormTest.php
common/tests/unit/models/LoginFormTest.php
<?php namespace common\tests\unit\models; use Yii; use common\models\LoginForm; use common\fixtures\UserFixture; /** * Login form test */ class LoginFormTest extends \Codeception\Test\Unit { /** * @var \common\tests\UnitTester */ protected $tester; /** * @return array */ public function _fixtures() { return [ 'user' => [ 'class' => UserFixture::className(), 'dataFile' => codecept_data_dir() . 'user.php' ] ]; } public function testLoginNoUser() { $model = new LoginForm([ 'username' => 'not_existing_username', 'password' => 'not_existing_password', ]); expect('model should not login user', $model->login())->false(); expect('user should not be logged in', Yii::$app->user->isGuest)->true(); } public function testLoginWrongPassword() { $model = new LoginForm([ 'username' => 'bayer.hudson', 'password' => 'wrong_password', ]); expect('model should not login user', $model->login())->false(); expect('error message should be set', $model->errors)->hasKey('password'); expect('user should not be logged in', Yii::$app->user->isGuest)->true(); } public function testLoginCorrect() { $model = new LoginForm([ 'username' => 'bayer.hudson', 'password' => 'password_0', ]); expect('model should login user', $model->login())->true(); expect('error message should not be set', $model->errors)->hasntKey('password'); expect('user should be logged in', Yii::$app->user->isGuest)->false(); } }
php
BSD-3-Clause
d8d6c35890b5d3ebb00b0cc6ace20deea99974b1
2026-01-05T04:42:11.286050Z
false
thecodeholic/Yii2-Youtube-Clone
https://github.com/thecodeholic/Yii2-Youtube-Clone/blob/d8d6c35890b5d3ebb00b0cc6ace20deea99974b1/common/tests/_support/UnitTester.php
common/tests/_support/UnitTester.php
<?php namespace common\tests; /** * Inherited Methods * @method void wantToTest($text) * @method void wantTo($text) * @method void execute($callable) * @method void expectTo($prediction) * @method void expect($prediction) * @method void amGoingTo($argumentation) * @method void am($role) * @method void lookForwardTo($achieveValue) * @method void comment($description) * @method \Codeception\Lib\Friend haveFriend($name, $actorClass = NULL) * * @SuppressWarnings(PHPMD) */ class UnitTester extends \Codeception\Actor { use _generated\UnitTesterActions; /** * Define custom actions here */ }
php
BSD-3-Clause
d8d6c35890b5d3ebb00b0cc6ace20deea99974b1
2026-01-05T04:42:11.286050Z
false
thecodeholic/Yii2-Youtube-Clone
https://github.com/thecodeholic/Yii2-Youtube-Clone/blob/d8d6c35890b5d3ebb00b0cc6ace20deea99974b1/common/models/Video.php
common/models/Video.php
<?php namespace common\models; use Imagine\Image\Box; use Yii; use yii\behaviors\BlameableBehavior; use yii\behaviors\TimestampBehavior; use yii\helpers\FileHelper; use yii\imagine\Image; /** * This is the model class for table "{{%video}}". * * @property string $video_id * @property string $title * @property string|null $description * @property string|null $tags * @property int|null $status * @property int|null $has_thumbnail * @property string|null $video_name * @property int|null $created_at * @property int|null $updated_at * @property int|null $created_by * * @property User $createdBy * @property \common\models\VideoLike[] $likes * @property \common\models\VideoLike[] $dislikes */ class Video extends \yii\db\ActiveRecord { const STATUS_UNLISTED = 0; const STATUS_PUBLISHED = 1; /** * @var \yii\web\UploadedFile */ public $video; /** * @var \yii\web\UploadedFile */ public $thumbnail; /** * {@inheritdoc} */ public static function tableName() { return '{{%video}}'; } public function behaviors() { return [ TimestampBehavior::class, [ 'class' => BlameableBehavior::class, 'updatedByAttribute' => false ] ]; } /** * {@inheritdoc} */ public function rules() { return [ [['video_id', 'title'], 'required'], [['description'], 'string'], [['status', 'has_thumbnail', 'created_at', 'updated_at', 'created_by'], 'integer'], [['video_id'], 'string', 'max' => 16], [['title', 'tags', 'video_name'], 'string', 'max' => 512], [['video_id'], 'unique'], ['has_thumbnail', 'default', 'value' => 0], ['status', 'default', 'value' => self::STATUS_UNLISTED], ['thumbnail', 'image', 'minWidth' => 1280], ['video', 'file', 'extensions' => ['mp4']], [['created_by'], 'exist', 'skipOnError' => true, 'targetClass' => User::className(), 'targetAttribute' => ['created_by' => 'id']], ]; } /** * {@inheritdoc} */ public function attributeLabels() { return [ 'video_id' => 'Video ID', 'title' => 'Title', 'description' => 'Description', 'tags' => 'Tags', 'status' => 'Status', 'has_thumbnail' => 'Has Thumbnail', 'video_name' => 'Video Name', 'created_at' => 'Created At', 'updated_at' => 'Updated At', 'created_by' => 'Created By', 'thumbnail' => 'Thumbnail' ]; } public function getStatusLabels() { return [ self::STATUS_UNLISTED => 'Unlisted', self::STATUS_PUBLISHED => 'Published', ]; } /** * Gets query for [[CreatedBy]]. * * @return \yii\db\ActiveQuery|\common\models\query\UserQuery */ public function getCreatedBy() { return $this->hasOne(User::className(), ['id' => 'created_by']); } /** * @return \yii\db\ActiveQuery */ public function getViews() { return $this->hasMany(VideoView::class, ['video_id' => 'video_id']); } /** * @return \yii\db\ActiveQuery */ public function getLikes() { return $this->hasMany(VideoLike::class, ['video_id' => 'video_id']) ->liked(); } /** * @return \yii\db\ActiveQuery */ public function getDislikes() { return $this->hasMany(VideoLike::class, ['video_id' => 'video_id']) ->disliked(); } /** * @return \common\models\query\CommentQuery */ public function getComments() { return $this->hasMany(Comment::class, ['video_id' => 'video_id']); } /** * {@inheritdoc} * @return \common\models\query\VideoQuery the active query used by this AR class. */ public static function find() { return new \common\models\query\VideoQuery(get_called_class()); } public function save($runValidation = true, $attributeNames = null) { $isInsert = $this->isNewRecord; if ($isInsert) { $this->video_id = Yii::$app->security->generateRandomString(8); $this->title = $this->video->name; $this->video_name = $this->video->name; } if ($this->thumbnail) { $this->has_thumbnail = 1; } $saved = parent::save($runValidation, $attributeNames); if (!$saved) { return false; } if ($isInsert) { $videoPath = Yii::getAlias('@frontend/web/storage/videos/' . $this->video_id . '.mp4'); if (!is_dir(dirname($videoPath))) { FileHelper::createDirectory(dirname($videoPath)); } $this->video->saveAs($videoPath); } if ($this->thumbnail) { $thumbnailPath = Yii::getAlias('@frontend/web/storage/thumbs/' . $this->video_id . '.jpg'); if (!is_dir(dirname($thumbnailPath))) { FileHelper::createDirectory(dirname($thumbnailPath)); } $this->thumbnail->saveAs($thumbnailPath); Image::getImagine() ->open($thumbnailPath) ->thumbnail(new Box(1280, 1280)) ->save(); } return true; } public function getVideoLink() { return Yii::$app->params['frontendUrl'] . 'storage/videos/' . $this->video_id . '.mp4'; } public function getThumbnailLink() { return $this->has_thumbnail ? Yii::$app->params['frontendUrl'] . 'storage/thumbs/' . $this->video_id . '.jpg' : ''; } public function afterDelete() { parent::afterDelete(); $videoPath = Yii::getAlias('@frontend/web/storage/videos/' . $this->video_id . '.mp4'); unlink($videoPath); $thumbnailPath = Yii::getAlias('@frontend/web/storage/thumbs/' . $this->video_id . '.jpg'); if (file_exists($thumbnailPath)) { unlink($thumbnailPath); } } public function isLikedBy($userId) { return VideoLike::find() ->userIdVideoId($userId, $this->video_id) ->liked() ->one(); } public function isDislikedBy($userId) { return VideoLike::find() ->userIdVideoId($userId, $this->video_id) ->disliked() ->one(); } public function belongsTo($userId) { return $this->created_by === $userId; } }
php
BSD-3-Clause
d8d6c35890b5d3ebb00b0cc6ace20deea99974b1
2026-01-05T04:42:11.286050Z
false