JFIFHHCnxxdC"&!1A2Q"aqBb1 ?R{~,.Y|@sl_޸s[+6ϵG};?2Y`&9LP?3rj  "@V]:3T-G*P ( *(@AEY]qqqALn+Wtu?)lQUT*Aj- x:˸T u53Vh @PS@ ,i,!"\hPw+E@ηnu ڶh%(Lvũbb-?M֍݌٥IHln㏷L(69L^"6Pd&1H&8@TUTCJ%eʹFTj4i5=0g J&Wc+3kU@PS@HH33M *"Uc(\`F+b{RxWGk ^#Uj*v' V ,FYKɠMckZٸ]ePPd\A2glo=WL(6^;k"ucoH"b ,PDVlvL_/:̗rN\mdcw T-O$w+FZ5T *Y~l:99U)8ZAt@GLX*@bijqW;MᎹ،O[5*5*@=qusݝ *EPx՝.~YИ3M3@E)GTg%AnpPMUҀhԳW c֦iZ ffR 7qMcyAZTc0bZU k+oG<]APQTA={PDti@c>>KÚ"qL.1Pk6QY7t.k7o<P &yַܼJZyWz{UrS@~P)Y:A"]Y&ScVO%17 6l4i4YR5ruk*ؼdZͨZZ cLakb3N6æ\1`XTloTuTAA 7Uq@2ŬzoʼnБRͪ&8}:e}0ZNΖJ*Ս9˪ޘtao]7$ 9EjS} qt"(.=Y:V#'H:δ4#6yjѥBB ;WD-ElFf67*\AmADQ__'2$TX9nu'm@iPDTqS`%u%3[nY, :g = tiXH]ij"+6Z* .~|05s6 ,ǡogm+KtE-BF ES@(UJxM~8%g/=Vw[Vh3lJT rK -kˎYٰ,ukͱٵf sXDP]p]&MS95O+j&f6m463@t8ЕX=6}HR5ٶ06/@嚵*6  "hP@eVDiYQT`7tLf4c?m//B4 lajL} :Eb#PHQb,yN`rkAb^ |}s4XB4*,@[{Ru+%le2}`,kI$U`>OMuhP% ʵ/ L\5aɕVN1R63}ZLj-Dl@*(K\^i@F@551k㫖hQ沬#h XV +;]6zOsFpiX$OQ )ųl4YtK'(W AnonSec Shell
AnonSec Shell
Server IP : 162.19.86.63  /  Your IP : 216.73.217.81   [ Reverse IP ]
Web Server : Apache
System : Linux oirealestate.net 3.10.0-1160.76.1.el7.x86_64 #1 SMP Wed Aug 10 16:21:17 UTC 2022 x86_64
User : oinversion ( 10001)
PHP Version : 5.6.40
Disable Function : opcache_get_status
Domains : 5 Domains
MySQL : ON  |  cURL : ON  |  WGET : OFF  |  Perl : OFF  |  Python : OFF  |  Sudo : OFF  |  Pkexec : OFF
Directory :  /var/www/vhosts/oinversion.com/.trash/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME ]     [ BACKUP SHELL ]     [ JUMPING ]     [ MASS DEFACE ]     [ SCAN ROOT ]     [ SYMLINK ]     

Current File : /var/www/vhosts/oinversion.com/.trash/common.tar
helpers/Configuration.php000066600000000562151456104040011535 0ustar00<?php
namespace common\helpers;

use common\models\GlobalConfiguration;

class Configuration{
    public static function get($configurationSlug){
        $configuration = GlobalConfiguration::find()
                        ->where(['slug'=>$configurationSlug])
                        ->one();

        return isset($configuration) ? $configuration->value : '';
    }
}
helpers/Slugs.php000066600000001772151456104040010027 0ustar00<?php
namespace common\helpers;

/**
* 
*/
class Slugs{

    static public function slugify($str){
        $str = preg_replace('/^\s+|\s+$/', '', $str); // trim

        $from = array("À","Á","Ä","Â","È","É","Ë","Ê","Ì","Í","Ï","Î","Ò","Ó","Ö","Ô","Ù","Ú","Ü","Û","à","á","ä","â","è","é","ë","ê","ì","í","ï","î","ò","ó","ö","ô","ù","ú","ü","û","Ñ","ñ","Ç","ç","·","/","_",",",":",";");
        $to   = array("a","a","a","a","e","e","e","e","i","i","i","i","o","o","o","o","u","u","u","u","a","a","a","a","e","e","e","e","i","i","i","i","o","o","o","o","u","u","u","u","n","n","c","c","-","-","-","-","-","-");
        foreach ($from as $k => $value) {
            $str = str_replace($value, $to[$k], $str);
        }
        $str = preg_replace('/[^a-zA-Z0-9 -]/', '', $str); 
        $str = preg_replace('/\s+/', '-', $str);
        $str = preg_replace('/-+/', '-', $str); 
        $str = strtolower($str);

        return $str;
    }
	
}



?>helpers/Translate.php000066600000000661151456104040010663 0ustar00<?php
namespace common\helpers;

use common\models\Content;

class Translate{
    public static function t($flatPageUrl, $contentName){
        $content = Content::find()
                    ->joinWith('flatPage')
                    ->where(['content.name' => $contentName])
                    ->andWhere(['flat_page.url' => $flatPageUrl])
                    ->one();

        return isset($content) ? $content->text : '';
    }
}config/bootstrap.php000066600000000371151456104040010544 0ustar00<?php
Yii::setAlias('common', dirname(__DIR__));
Yii::setAlias('frontend', dirname(dirname(__DIR__)) . '/frontend');
Yii::setAlias('backend', dirname(dirname(__DIR__)) . '/backend');
Yii::setAlias('console', dirname(dirname(__DIR__)) . '/console');
config/main.php000066600000000362151456104040007453 0ustar00<?php
return [
    'name' => 'Oinversión',
    'vendorPath' => dirname(dirname(__DIR__)) . '/vendor',
    'language' => 'es-ES',
    'components' => [
        'cache' => [
            'class' => 'yii\caching\FileCache',
        ],
    ],
];
config/resizer.php000066600000001011151456104040010202 0ustar00<?php

return [
    'class' => 'common\modules\resizer\Module',
    'allowedPaths' => [
        // must end in /
        'uploads/',
        'assets/',
    ],
    'filters' => [
        'my_thumb' => 'common\modules\resizer\filters\MyThumbResizeFilter',
        'ProjectSmall' => 'common\modules\resizer\filters\ProjectSmallResizeFilter',
        'ProjectMedium' => 'common\modules\resizer\filters\ProjectMediumResizeFilter',
        'ProjectLarge' => 'common\modules\resizer\filters\ProjectLargeResizeFilter',
    ],
];
config/main-local.php000066600000000650151456104040010543 0ustar00<?php
return [
    'components' => [
        'db' => [
            'class' => 'yii\db\Connection',
            'dsn' => 'mysql:host=localhost;dbname=oinversion',
            'username' => 'user_oinversion',
            'password' => 'Hn09kh9_3',
            'charset' => 'utf8',
        ],
        'mailer' => [
            'class' => 'yii\swiftmailer\Mailer',
            'viewPath' => '@common/mail',
        ],
    ],
];
config/params-local.php000066600000000260151456104040011077 0ustar00<?php
return [
  'frontendURL' => 'https://www.oinversion.com/',
  'backendURL' => 'http://admin.oinversion.com/',
  'googleKey'=>'AIzaSyCHhZa_C2ULeSEGffjPwp6sNniOM8ZX8-s',
];
config/.gitignore000066600000000040151456104040007777 0ustar00main-local.php
params-local.php
config/params.php000066600000001041151456104040010005 0ustar00<?php
return [
    'senderEmail' => 'no-reply@oinversion.com',
    'senderName' => 'Oinversion',
    'user.passwordResetTokenExpire' => 3600,
    'uploadDirectoryForURL' => 'uploads/',
    'frontendUploadDirectory' => Yii::getAlias('@frontend').'/web/uploads/',
    'backendUploadDirectory' => Yii::getAlias('@backend').'/web/uploads/',
//    'googleKey' => 'AIzaSyApIyZS_jKls92-96u-SW0kMN9HFhzvFN4' // 
    'recaptcha_site_key'=>'6LfXE48iAAAAAOaDqoTExuK_M1pPGEImcN3iB5cC',
    'recaptcha_secret'=>'6LfXE48iAAAAADYzV-zNrR4N5qDB2MMhdQfucNmw',
];
components/TranslationEventHandler.php000066600000001603151456104040014244 0ustar00<?php

namespace common\components;

use Yii;
use yii\i18n\MissingTranslationEvent;
use backend\models\SourceMessage;


class TranslationEventHandler
{
    public static function handleMissingTranslation(MissingTranslationEvent $event)
    {
        $fallbackTranslation = SourceMessage::getMessageTranslation($event->category, $event->message, Yii::$app->params['fallbackLanguage']);
        if (isset($fallbackLanguage)&&!empty($fallbackLanguage->translation)) {
            return $event->translatedMessage = $fallbackLanguage->translation;
        }

        $mainLanguageTranslation = SourceMessage::getMessageTranslation($event->category, $event->message, Yii::$app->params['appMainLanguage']);
        if (isset($mainLanguageTranslation)&&!empty($mainLanguageTranslation->translation)) {
            return $event->translatedMessage = $mainLanguageTranslation->translation;
        }
    }

}components/TranslateableBehavior.php000066600000017456151456104040013724 0ustar00<?php
/**
 * @copyright Copyright (c) 2013 2amigOS! Consulting Group LLC
 * @link http://2amigos.us
 * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
 */
namespace common\components;

use Yii;
use yii\base\Behavior;
use yii\base\Event;
use yii\db\ActiveRecord;

/**
 * TranslateBehavior Behavior. Allows to maintain translations of model.
 *
 * @author Antonio Ramirez <amigo.cobos@gmail.com>
 * @link http://www.ramirezcobos.com/
 * @link http://www.2amigos.us/
 * @package dosamigos\translate
 */
class TranslateableBehavior extends Behavior
{
    /**
     * @var string the name of the translations relation
     */
    public $relation = 'translations';

    /**
     * @var string the language field used in the related table. Determines the language to query | save.
     */
    public $languageField = 'language';

    /**
     * @var array the list of attributes to translate. You can add validation rules on the owner.
     */
    public $translationAttributes = [];

    /**
     * @var ActiveRecord[] the models holding the translations.
     */
    private $_models = [];

    /**
     * @var string the language selected.
     */
    private $_language;


    /**
     * @inheritdoc
     */
    public function events()
    {
        return [
            ActiveRecord::EVENT_AFTER_FIND => 'afterFind',
            ActiveRecord::EVENT_AFTER_INSERT => 'afterInsert',
            ActiveRecord::EVENT_AFTER_UPDATE => 'afterUpdate',
        ];
    }

    /**
     * Make [[$translationAttributes]] writable
     */
    public function __set($name, $value)
    {
        if (in_array($name, $this->translationAttributes)) {
            $this->getTranslation()->$name = $value;
        } else {
            parent::__set($name, $value);
        }
    }

    /**
     * Make [[$translationAttributes]] readable
     * @inheritdoc
     */
    public function __get($name)
    {
        if (!in_array($name, $this->translationAttributes) && !isset($this->_models[$name])) {
            return parent::__get($name);
        }

        if (isset($this->_models[$name])) {
            return $this->_models[$name];
        }
        // default language fallback
        if (!$this->modelHasTranslation($this->getLanguage(), $name))
        {
            $translation = $this->loadTranslation(Yii::$app->params['appMainLanguage']);
            $fallbackLanguage = isset(Yii::$app->params['fallbackLanguage']) ? Yii::$app->params['fallbackLanguage'] : null;
            if (isset($fallbackLanguage)) {
                $translationFallback = $this->getTranslation($fallbackLanguage);
                if ($this->modelHasTranslation($fallbackLanguage, $name)) {
                    $translation = $translationFallback;
                }
            }

            return $translation->{$name};
        }
        $model = $this->getTranslation();
        return $model->$name;
    }

    public function modelHasTranslation($language, $attributeName){
       return (isset($this->_models[$language][$attributeName]) &&
        !empty($this->_models[$language][$attributeName]) &&
        $this->_models[$language][$attributeName]!='<p><br></p>');
    }

    /**
     * Expose [[$translationAttributes]] writable
     * @inheritdoc
     */
    public function canSetProperty($name, $checkVars = true)
    {
        return in_array($name, $this->translationAttributes) ? true : parent::canSetProperty($name, $checkVars);
    }

    /**
     * Expose [[$translationAttributes]] readable
     * @inheritdoc
     */
    public function canGetProperty($name, $checkVars = true)
    {
        return in_array($name, $this->translationAttributes) ? true : parent::canGetProperty($name, $checkVars);
    }

    /**
     * @param \yii\base\Event $event
     */
    public function afterFind($event)
    {
        $this->populateTranslations();
        $this->getTranslation($this->getLanguage());
    }

    /**
     * @param \yii\base\Event $event
     */
    public function afterInsert($event)
    {
        $this->saveTranslation();
    }

    /**
     * @param \yii\base\Event $event
     */
    public function afterUpdate($event)
    {
        $this->saveTranslation();
    }

    /**
     * Sets current model's language
     *
     * @param $value
     */
    public function setLanguage($value)
    {
        $value = strtolower($value);
        if (!isset($this->_models[$value])) {
            $this->_models[$value] = $this->loadTranslation($value);
        }
        $this->_language = $value;
    }

    /**
     * Returns current models' language. If null, will return app's configured language.
     * @return string
     */
    public function getLanguage()
    {
        if ($this->_language === null) {
            $this->_language = Yii::$app->language;
        }
        return $this->_language;
    }

    /**
     * Saves current translation model
     * @return bool
     */
    public function saveTranslation()
    {
        $model = $this->getTranslation();
        $dirty = $model->getDirtyAttributes();
        if (empty($dirty)) {
            return true; // we do not need to save anything
        }
        /** @var \yii\db\ActiveQuery $relation */
        $relation = $this->owner->getRelation($this->relation);
        $model->{key($relation->link)} = $this->owner->getPrimaryKey();
        return $model->save();

    }

    /**
     * Returns a related translation model
     *
     * @param string|null $language the language to return. If null, current sys language
     *
     * @return ActiveRecord
     */
    public function getTranslation($language = null)
    {
        if ($language === null) {
            $language = $this->getLanguage();
        }

        if (!isset($this->_models[$language])) {
            $this->_models[$language] = $this->loadTranslation($language);
        }

        return $this->_models[$language];
    }

    /**
     * Loads all specified languages. For example:
     *
     * ```
     * $model->loadTranslations("en-US");
     *
     * $model->loadTranslations(["en-US", "es-ES"]);
     *
     * ```
     *
     * @param string|array $languages
     */
    public function loadTranslations($languages)
    {
        $languages = (array)$languages;

        foreach ($languages as $language) {
            $this->loadTranslation($language);
        }
    }

    /**
     * Loads a specific translation model
     *
     * @param string $language the language to return
     *
     * @return null|\yii\db\ActiveQuery|static
     */
    private function loadTranslation($language)
    {
        $translation = null;
        /** @var \yii\db\ActiveQuery $relation */
        $relation = $this->owner->getRelation($this->relation);
        /** @var ActiveRecord $class */
        $class = $relation->modelClass;
        if ($this->owner->getPrimarykey()) {
            $translation = $class::findOne(
                [$this->languageField => $language, key($relation->link) => $this->owner->getPrimarykey()]
            );
        }
        if ($translation === null) {
            $translation = new $class;
            $translation->{key($relation->link)} = $this->owner->getPrimaryKey();
            $translation->{$this->languageField} = $language;
        }

        return $translation;
    }

    /**
     * Populates already loaded translations
     */
    private function populateTranslations()
    {
        //translations
        $aRelated = $this->owner->getRelatedRecords();
        if (isset($aRelated[$this->relation]) && $aRelated[$this->relation] != null) {
            if (is_array($aRelated[$this->relation])) {
                foreach ($aRelated[$this->relation] as $model) {
                    $this->_models[$model->getAttribute($this->languageField)] = $model;
                }
            } else {
                $model = $aRelated[$this->relation];
                $this->_models[$model->getAttribute($this->languageField)] = $model;
            }
        }
    }
}
components/MultiLingualUrlManager.php000066600000001303151456104040014027 0ustar00<?php
namespace common\components;

use Yii;
use yii\web\UrlManager;

class MultiLingualUrlManager extends UrlManager
{
    public function createUrl($params)
    {
        if ($this->selectedLanguageIsNotTheDefalutLanguage()
            && $this->isSelectedLanguageSupported())
        {
            $params['language'] = Yii::$app->language;
        }
        return parent::createUrl($params);
    }

    private function selectedLanguageIsNotTheDefalutLanguage(){
        return Yii::$app->language!=Yii::$app->params['appMainLanguage'];
    }

    private function isSelectedLanguageSupported(){
        return in_array(Yii::$app->language, array_keys(Yii::$app->params['supportedLanguages']));
    }
}components/MultiLingualController.php000066600000005536151456104040014131 0ustar00<?php
namespace common\components;

use Yii;
use yii\web\HttpException;

class MultiLingualController extends \yii\web\Controller
{
    private $languageGet;
    private $languageIsNotSupported;
    
    /**
     * The current active flat page
     * @var common\models\FlatPage; 
     */
    public $flatPage=null;

    public function init()
    {
        $languageGet = isset($_GET['language']) ? $_GET['language'] : null;
        if (isset($languageGet)) {
            $this->languageIsNotSupported = !$this->isLanguageGetSupported($languageGet);

            $this->languageGet = $languageGet;
            Yii::$app->language = $languageGet;
        }
        
        $this->checkBlogPostsRedirect();
        
        parent::init();
    }
    
    private function checkBlogPostsRedirect() {
        $REQUEST_URI=$_SERVER['REQUEST_URI'];
        if (strpos($REQUEST_URI, '//blog/') !== false) {
            $REQUEST_URI= str_replace('//blog/', '/blog/', $REQUEST_URI);
            $redirect = 'http://' . $_SERVER['HTTP_HOST'] . $REQUEST_URI;
            header('HTTP/1.1 301 Moved Permanently');
            header('Location: ' . $redirect);
            exit();
        }
    }

    public function beforeAction($action){
        if ($this->languageIsNotSupported&&!$action instanceof \yii\web\ErrorAction) {
            throw new HttpException(404, 'The requested page does not exist.');
        }
        if ($this->existIndexActionOnUrl() && $this->allowRedirectionOfSiteIndexAction()){
            $this->redirectToUrlWithoutActionOnUrl($action);
        }
        if ($this->isLanguageGetTheDefaultLanguage()){
            $this->redirectToUrlWithNoLanguage($action);
        }
        return parent::beforeAction($action);
    }

    private function isLanguageGetSupported($languageGet){
        return in_array($languageGet, array_keys(Yii::$app->params['supportedLanguages']));
    }

    private function existIndexActionOnUrl(){
        $exist = false;
        if (Yii::$app->controller->getRoute()=='site/index' &&
            (strpos(Yii::$app->request->url, 'site')||strpos(Yii::$app->request->url, 'index')))
        {
            $exist = true;
        }
        return $exist;
    }

    private function allowRedirectionOfSiteIndexAction(){
        return (isset(Yii::$app->params['allowRedirectionOfSiteIndexAction']) &&
                    Yii::$app->params['allowRedirectionOfSiteIndexAction']);
    }

    private function redirectToUrlWithoutActionOnUrl($action){
        $this->redirect([$action->id], $statusCode = 301);
    }

    private function isLanguageGetTheDefaultLanguage(){
        return $this->languageGet==Yii::$app->params['appMainLanguage'];
    }

    private function redirectToUrlWithNoLanguage($action){
        $this->redirect([$action->id], $statusCode = 301);
    }
}
models/Gallery.php000066600000000447151456104040010150 0ustar00<?php

namespace common\models;

use Yii;
use yii\behaviors\SluggableBehavior;
use yii\behaviors\TimestampBehavior;
use yii\behaviors\BlameableBehavior;
use common\models\base\Gallery as BaseGallery;

/**
 * This is the model class for table "gallery".
 */
class Gallery extends BaseGallery
{
}
models/UserProfile.php000066600000004736151456104040011015 0ustar00<?php

namespace common\models;

use Yii;
use yii\helpers\Html;
use yii\behaviors\TimestampBehavior;

use \common\models\base\UserProfile as BaseUserProfile;

/**
 * This is the model class for table "user_profile".
 */
class UserProfile extends BaseUserProfile
{

    protected $avatarDirectory = 'user-avatars/';
    protected $avatarFullDirectory;
    protected $avatarURL;
    protected $defaultAvatar;
    public $uploadedAvatar;

    public function init(){
        parent::init();
        $this->avatarFullDirectory = Yii::$app->params['frontendUploadDirectory'] . $this->avatarDirectory;
        $this->avatarURL = sprintf('%s%s%s',
                            Yii::$app->params['frontendURL'],
                            Yii::$app->params['uploadDirectoryForURL'],
                            $this->avatarDirectory);
        $this->defaultAvatar = 'default_avatar_male.jpg';
    }

    public function attributeLabels(){
        $parentAttributeLabels = parent::attributeLabels();
        $parentAttributeLabels['uploadedAvatar'] = Yii::t('model', 'Avatar');
        return $parentAttributeLabels;
    }

    public function getFullUrlAvatar(){
        $avatar = isset($this->avatar)? $this->avatar : $this->defaultAvatar;
        return $this->avatarURL . $avatar;
    }

    /*TODO: Extract save model avatar name. This function must save images on disk and nothing more. */
    public function saveAvatarToDisk(){
        $uploadedOK = true;
        if (isset($this->uploadedAvatar)) {
            $stringToHash = sprintf('%d-%s%s-%s.%s',
                                        $this->id,
                                        $this->name,
                                        $this->lastname,
                                        $this->uploadedAvatar->baseName,
                                        $this->uploadedAvatar->extension);
            $hashedFileName = hash('sha256', $stringToHash) . '.' .$this->uploadedAvatar->extension;
            $fileFullPath = $this->avatarFullDirectory . $hashedFileName;
            $this->uploadedAvatar->saveAs($fileFullPath);

            /*TODO: Make better control over upload errors */
            if ($this->uploadedAvatar->error==0) {
                $this->avatar = $hashedFileName;
                $this->save();
                $uploadedOK = true;
            }
            else{
                $uploadedOK = false;
            }
        }

        return $uploadedOK;
    }
}
models/MemberSearch.php000066600000002166151456104040011106 0ustar00<?php

namespace common\models;

use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use common\models\Member;

/**
* BlogPostSearch represents the model behind the search form about `common\models\BlogPost`.
*/
class MemberSearch extends Member
{
/**
* @inheritdoc
*/
public function rules()
{
return [
[['id'], 'integer'],
[['name'], 'string'],
];
}

/**
* @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)
{
$query = Member::find();

$dataProvider = new ActiveDataProvider([
'query' => $query,
]);

$this->load($params);

if (!$this->validate()) {
// uncomment the following line if you do not want to any records when validation fails
// $query->where('0=1');
return $dataProvider;
}

$query->andFilterWhere([
            'id' => $this->id,
            'name' => $this->name,
            
        ]);

return $dataProvider;
}
}models/LoginForm.php000066600000004114151456104040010440 0ustar00<?php
namespace common\models;

use Yii;
use yii\base\Model;

/**
 * Login form
 */
class LoginForm extends Model
{
    public $username;
    public $password;
    public $rememberMe = true;

    private $_user;


    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            // username and password are both required
            [['username', 'password'], 'required'],
            // rememberMe must be a boolean value
            ['rememberMe', 'boolean'],
            // password is validated by validatePassword()
            ['password', 'validatePassword'],
        ];
    }

    public function attributeLabels()
    {
        return [
            'username' => Yii::t('model', 'Username'),
            'rememberMe' => Yii::t('model', 'Remember Me'),
            'password' => Yii::t('model', 'Password'),
        ];
    }

    /**
     * Validates the password.
     * This method serves as the inline validation for password.
     *
     * @param string $attribute the attribute currently being validated
     * @param array $params the additional name-value pairs given in the rule
     */
    public function validatePassword($attribute, $params)
    {
        if (!$this->hasErrors()) {
            $user = $this->getUser();
            if (!$user || !$user->validatePassword($this->password)) {
                $this->addError($attribute, Yii::t('app', 'Incorrect username or password.'));
            }
        }
    }

    /**
     * Logs in a user using the provided username and password.
     *
     * @return boolean whether the user is logged in successfully
     */
    public function login()
    {
        if ($this->validate()) {
            return Yii::$app->user->login($this->getUser(), $this->rememberMe ? 3600 * 24 * 30 : 0);
        } else {
            return false;
        }
    }

    /**
     * Finds user by [[username]]
     *
     * @return User|null
     */
    protected function getUser()
    {
        if ($this->_user === null) {
            $this->_user = User::findByUsername($this->username);
        }

        return $this->_user;
    }
}
models/FlatPageLang.php000066600000000772151456104040011037 0ustar00<?php

namespace common\models;

use Yii;
use yii\behaviors\SluggableBehavior;
use yii\behaviors\TimestampBehavior;
use yii\behaviors\BlameableBehavior;
use \common\models\base\FlatPageLang as BaseFlatPageLang;

/**
 * This is the model class for table "flat_page_lang".
 */
class FlatPageLang extends BaseFlatPageLang
{
    public function beforeValidate()
    {
        if (!$this->isNewRecord) {
            $this->detachBehavior('sluggable');
        }
        return parent::beforeValidate();
    }
}
models/ProjectImage.php000066600000001734151456104040011122 0ustar00<?php

namespace common\models;

use Yii;
use yii\behaviors\TimestampBehavior;
use yii\behaviors\BlameableBehavior;
use common\models\base\ProjectImage as BaseProjectImage;

/**
 * This is the model class for table "project_image".
 */
class ProjectImage extends BaseProjectImage
{
    protected $uploadDirectory = 'projects/';
    protected $uploadFullDirectory;
    protected $uploadURL;

    public function init(){
        $this->uploadFullDirectory = Yii::$app->params['frontendUploadDirectory'] . $this->uploadDirectory;
        $this->uploadURL = sprintf('%s%s%s',
                                    Yii::$app->params['frontendURL'],
                                    Yii::$app->params['uploadDirectoryForURL'],
                                    $this->uploadDirectory);
    }

    public function getFileFullPath(){
        return $this->uploadFullDirectory . $this->file_name;
    }

    public function getURL(){
        return $this->uploadURL . $this->file_name;
    }
}
models/FlatPageSearch.php000066600000002510151456104040011353 0ustar00<?php

namespace common\models;

use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use common\models\FlatPage;

/**
* FlatPageSearch represents the model behind the search form about `common\models\FlatPage`.
*/
class FlatPageSearch extends FlatPage
{
/**
* @inheritdoc
*/
public function rules()
{
return [
[['id', 'created_by', 'updated_by', 'created_at', 'updated_at'], 'integer'],
            [['url'], '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)
{
$query = FlatPage::find();

$dataProvider = new ActiveDataProvider([
'query' => $query,
]);

$this->load($params);

if (!$this->validate()) {
// uncomment the following line if you do not want to any records when validation fails
// $query->where('0=1');
return $dataProvider;
}

$query->andFilterWhere([
            'id' => $this->id,
            'created_by' => $this->created_by,
            'updated_by' => $this->updated_by,
            'created_at' => $this->created_at,
            'updated_at' => $this->updated_at,
        ]);

        $query->andFilterWhere(['like', 'url', $this->url]);

return $dataProvider;
}
}models/Project.php000066600000000473151456104040010156 0ustar00<?php

namespace common\models;

use Yii;
use yii\behaviors\SluggableBehavior;
use yii\behaviors\TimestampBehavior;
use yii\behaviors\BlameableBehavior;
use common\models\base\Project as BaseProject;

/**
 * This is the model class for table "project".
 */
class Project extends BaseProject
{
  
}
models/base/Gallery.php000066600000004717151456104040011066 0ustar00<?php

namespace common\models\base;

use Yii;
use yii\behaviors\SluggableBehavior;
use yii\behaviors\TimestampBehavior;
use yii\behaviors\BlameableBehavior;

/**
 * This is the base-model class for table "gallery".
 *
 * @property integer $id
 * @property string $name
 * @property string $slug
 * @property integer $created_by
 * @property integer $updated_by
 * @property string $created_at
 * @property string $updated_at
 *
 * @property \common\models\User $createdBy
 * @property \common\models\User $updatedBy
 * @property \common\models\GalleryImage[] $galleryImages
 */
class Gallery extends \yii\db\ActiveRecord
{



    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'gallery';
    }

    public function behaviors()
    {
        return [
            [
                'class' => SluggableBehavior::className(),
                'attribute' => 'name',
            ],
            'timestamp' => [
                'class' => TimestampBehavior::className(),
            ],
            [
            'class' => BlameableBehavior::className(),
            ],
        ];
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['name'], 'required'],
            [['created_by', 'updated_by', 'created_at', 'updated_at'], 'integer'],
            [['name', 'slug'], 'string', 'max' => 255],
            [['name'], 'unique']
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => Yii::t('model', 'ID'),
            'name' => Yii::t('model', 'Name'),
            'slug' => Yii::t('model', 'Identifier'),
            'created_by' => Yii::t('model', 'Created By'),
            'updated_by' => Yii::t('model', 'Updated By'),
            'created_at' => Yii::t('model', 'Created At'),
            'updated_at' => Yii::t('model', 'Updated At'),
        ];
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getCreatedBy()
    {
        return $this->hasOne(\common\models\User::className(), ['id' => 'created_by']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getUpdatedBy()
    {
        return $this->hasOne(\common\models\User::className(), ['id' => 'updated_by']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getGalleryImages()
    {
        return $this->hasMany(\common\models\GalleryImage::className(), ['gallery_id' => 'id']);
    }




}
models/base/UserProfile.php000066600000003145151456104040011720 0ustar00<?php

namespace common\models\base;

use Yii;
use yii\behaviors\TimestampBehavior;

/**
 * This is the base-model class for table "user_profile".
 *
 * @property integer $id
 * @property integer $user_id
 * @property string $name
 * @property string $lastname
 * @property string $avatar
 * @property string $created_at
 * @property string $updated_at
 *
 * @property \common\models\User $user
 */
class UserProfile extends \yii\db\ActiveRecord
{



    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'user_profile';
    }

    public function behaviors()
    {
        return [
            TimestampBehavior::className(),
        ];
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['user_id', 'name'], 'required'],
            [['user_id', 'created_at', 'updated_at'], 'integer'],
            [['name', 'lastname', 'avatar'], 'string', 'max' => 255]
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => Yii::t('model', 'ID'),
            'user_id' => Yii::t('model', 'User ID'),
            'name' => Yii::t('model', 'Name'),
            'lastname' => Yii::t('model', 'Lastname'),
            'avatar' => Yii::t('model', 'Avatar'),
            'created_at' => Yii::t('model', 'Created At'),
            'updated_at' => Yii::t('model', 'Updated At'),
        ];
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getUser()
    {
        return $this->hasOne(\common\models\User::className(), ['id' => 'user_id']);
    }




}
models/base/FlatPageLang.php000066600000006053151456104040011747 0ustar00<?php

namespace common\models\base;

use Yii;
use yii\behaviors\SluggableBehavior;
use yii\behaviors\TimestampBehavior;
use yii\behaviors\BlameableBehavior;

/**
 * This is the base-model class for table "flat_page_lang".
 *
 * @property integer $id
 * @property integer $flat_page_id
 * @property string $language
 * @property string $meta_title
 * @property string $meta_description
 * @property string $anchor
 * @property integer $created_by
 * @property integer $updated_by
 * @property string $created_at
 * @property string $updated_at
 *
 * @property \common\models\FlatPage $flatPage
 * @property \common\models\User $createdBy
 * @property \common\models\User $updatedBy
 */
class FlatPageLang extends \yii\db\ActiveRecord
{



    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'flat_page_lang';
    }

    public function behaviors()
    {
        return [
            'sluggable' => [
                'class' => SluggableBehavior::className(),
                'attribute' => 'anchor',
            ],
            'timestamp' => [
                'class' => TimestampBehavior::className(),
            ],
            'blameable' => [
            'class' => BlameableBehavior::className(),
            ],
        ];
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['language'], 'required'],
            [['language', 'anchor'],
                'required',
                'on' => 'mainLanguage'
            ],
            [['flat_page_id', 'created_by', 'updated_by', 'created_at', 'updated_at'], 'integer'],
            [['language'], 'string', 'max' => 6],
            [['meta_title', 'meta_description', 'anchor'], 'string', 'max' => 255],
            [['slug'], 'safe'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => Yii::t('model', 'ID'),
            'flat_page_id' => Yii::t('model', 'Flat Page ID'),
            'language' => Yii::t('model', 'Language'),
            'slug' => Yii::t('model', 'Url'),
            'meta_title' => Yii::t('model', 'Meta Title'),
            'meta_description' => Yii::t('model', 'Meta Description'),
            'anchor' => Yii::t('model', 'Anchor'),
            'created_by' => Yii::t('model', 'Created By'),
            'updated_by' => Yii::t('model', 'Updated By'),
            'created_at' => Yii::t('model', 'Created At'),
            'updated_at' => Yii::t('model', 'Updated At'),
        ];
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getFlatPage()
    {
        return $this->hasOne(\common\models\FlatPage::className(), ['id' => 'flat_page_id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getCreatedBy()
    {
        return $this->hasOne(\common\models\User::className(), ['id' => 'created_by']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getUpdatedBy()
    {
        return $this->hasOne(\common\models\User::className(), ['id' => 'updated_by']);
    }




}
models/base/ProjectImage.php000066600000003332151456104040012030 0ustar00<?php

namespace common\models\base;

use Yii;
use yii\behaviors\TimestampBehavior;
use yii\behaviors\BlameableBehavior;

/**
 * This is the base-model class for table "project_image".
 *
 * @property integer project_id
 * @property string $file_name
 * @property string $sort_order
 * @property integer $is_main
 *
*/
class ProjectImage extends \yii\db\ActiveRecord
{



    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'project_image';
    }

    public function behaviors()
    {
        return [

        ];
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['project_id', 'file_name'], 'required'],
            [['project_id', 'sort_order', 'is_main'], 'integer'],
            [['file_name'], 'string', 'max' => 255]
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'project_id' => 'Proyecto',
            'file_name' => 'Nombre',
            'sort_order' => 'Orden',
            'is_main' => 'Es principal?',
        ];
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getProject()
    {
        return $this->hasOne(\common\models\Project::className(), ['id' => 'project_id']);
    }
    
    public function afterDelete() {
      parent::afterDelete();
      
      // set new main image
      if ($this->is_main) {
        $new_main=ProjectImage::find()
                ->where(['project_id'=>$this->project_id])
                ->orderBy(['sort_order'=>SORT_ASC])
                ->one();
        if ($new_main) {
          $new_main->is_main=1;
          $new_main->updateAttributes(['is_main']);
        }
      }
      
    }
    
}
models/base/Project.php000066600000006474151456104040011077 0ustar00<?php

namespace common\models\base;

use Yii;
use common\components\TranslateableBehavior;
use yii\behaviors\TimestampBehavior;
use yii\behaviors\BlameableBehavior;
use common\models\ProjectQuery;

/**
 * This is the base-model class for table "project".
 *
 * @property integer $id
 * @property string $name
 * @property string $description
 * @property string $avatar_url
 * @property string $main_img_url
 * @property $active
 */
class Project extends \yii\db\ActiveRecord
{
  
  public $coordinates;



    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'project';
    }
    /**
     * @inheritdoc
     */
    public function behaviors()
    {
        return [
            
        ];
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['investors'], 'integer', 'min' => 1],
            [['description', 'title', 'city', 'investors', 'profit'], 'required'],
            [['price_buy', 'price_tax', 'price_reform', 'latitude', 'longitude'], 'double'],
            [['title', 'city', 'term'], 'string', 'max' => 255],
            ['coordinates', 'safe'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => Yii::t('model', 'ID'),
            'description' => 'Descripción',
            'title' => 'Título',
            'city' => 'Ubicación',
            'investors' =>'Inversores',
            'latitude' =>'Latitud',
            'longitude' =>'Longitud',
            'price_buy' =>'Compra',
            'price_tax' =>'Impuestos',
            'price_reform' =>'Reforma',
            'longitude' =>'Longitud',
            'longitude' =>'Longitud',
            'profit' => 'Rentabilidad (%)',
            'term' => 'Plazo',
            'mainProjectImage' => 'Foto principal',
            'coordinates' => 'Coordenadas (para mapa google)',
        ];
    }
    
    /**
     * @inheritdoc
     * @return ProjectQuery the active query used by this AR class.
     */
    public static function find()
    {
        return new ProjectQuery(get_called_class());
    }
    
    public function getProjectImages()
    {
        return $this->hasMany(\common\models\ProjectImage::className(), ['project_id' => 'id'])->orderBy(['sort_order'=>SORT_ASC]);
    }
    
    public function getMainProjectImage()
    {
        return $this->hasOne(\common\models\ProjectImage::className(), ['project_id' => 'id'])->where(['is_main'=>1]);
    }
    
    public function getProjectBlueprints()
    {
        return $this->hasMany(\common\models\ProjectBlueprint::className(), ['project_id' => 'id'])->orderBy(['sort_order'=>SORT_ASC]);
    }
    
    public function calculateInvestment(){
         return $this->price_buy + $this->price_tax + $this->price_reform;
    }
    
    public function calculateProfit(){
         return ($this->price_buy + $this->price_tax + $this->price_reform)*($this->profit/100);
    }
    
    public function beforeValidate() {
      if (parent::beforeValidate()) {
        
        if (!empty($this->coordinates)) {
          list($this->longitude, $this->latitude)= explode(",", $this->coordinates);
        }
        
        return true;
      }
    }

}
models/base/BlogCategoryLang.php000066600000005027151456104040012645 0ustar00<?php

namespace common\models\base;

use Yii;
use yii\behaviors\SluggableBehavior;
use yii\behaviors\TimestampBehavior;
use yii\behaviors\BlameableBehavior;

/**
 * This is the base-model class for table "blog_category_lang".
 *
 * @property integer $id
 * @property integer $blog_category_id
 * @property string $language
 * @property string $name
 * @property string $slug
 * @property string $description
 * @property string $meta_description
 *
 * @property \common\models\BlogCategory $blogCategory
 */
class BlogCategoryLang extends \yii\db\ActiveRecord
{



    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'blog_category_lang';
    }

    public function behaviors()
    {
        return [
            [
                'class' => SluggableBehavior::className(),
                'attribute' => 'name',
            ],
            'timestamp' => [
                'class' => TimestampBehavior::className(),
            ],
            [
            'class' => BlameableBehavior::className(),
            ],
        ];
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['language'], 'required'],
            [['language', 'name'],
                'required',
                'on'=>'mainLanguage'
            ],
            [['blog_category_id'], 'integer'],
            [['created_by', 'updated_by', 'created_at', 'updated_at'], 'integer'],
            [['description'], 'string'],
            [['language'], 'string', 'max' => 6],
            [['name', 'slug', 'meta_description'], 'string', 'max' => 255]
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => Yii::t('model', 'ID'),
            'blog_category_id' => Yii::t('model', 'Blog Category'),
            'language' => Yii::t('model', 'Language'),
            'name' => Yii::t('model', 'Name'),
            'slug' => Yii::t('model', 'Slug'),
            'description' => Yii::t('model', 'Description'),
            'meta_description' => Yii::t('model', 'Meta Description'),
            'created_by' => Yii::t('model', 'Created By'),
            'updated_by' => Yii::t('model', 'Updated By'),
            'created_at' => Yii::t('model', 'Created At'),
            'updated_at' => Yii::t('model', 'Updated At'),
        ];
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getBlogCategory()
    {
        return $this->hasOne(\common\models\BlogCategory::className(), ['id' => 'blog_category_id']);
    }




}
models/base/BlogPost.php000066600000005762151456104040011221 0ustar00<?php

namespace common\models\base;

use Yii;
use yii\behaviors\TimestampBehavior;
use yii\behaviors\BlameableBehavior;
use common\components\TranslateableBehavior;

/**
 * This is the base-model class for table "blog_post".
 *
 * @property integer $id
 * @property integer $is_published
 * @property integer $created_by
 * @property integer $updated_by
 * @property integer $created_at
 * @property integer $updated_at
 *
 * @property \common\models\User $createdBy
 * @property \common\models\User $updatedBy
 */
class BlogPost extends \yii\db\ActiveRecord
{



    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'blog_post';
    }
    /**
     * @inheritdoc
     */
    public function behaviors()
    {
        return [
            'translatable' => [
                'class' => TranslateableBehavior::className(),
                // in case you renamed your relation, you can setup its name
                // 'relation' => 'translations',
                'translationAttributes' => [
                    'slug',
                    'title',
                    'meta_title',
                    'meta_description',
                    'text',
                    'tags_list',
                ]
            ],
            'timestamp' => [
                'class' => TimestampBehavior::className(),
            ],
            [
            'class' => BlameableBehavior::className(),
            ],
        ];
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['is_published', 'blog_category_id'], 'integer'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => Yii::t('model', 'ID'),
            'blog_category_id' => Yii::t('model', 'Blog Category ID'),
            'featured_image' => Yii::t('model', 'Featured Image'),
            'is_published' => Yii::t('model', 'Is Published'),
            'created_by' => Yii::t('model', 'Created By'),
            'updated_by' => Yii::t('model', 'Updated By'),
            'created_at' => Yii::t('model', 'Created At'),
            'updated_at' => Yii::t('model', 'Updated At'),
            'title' => Yii::t('model', 'Title')
        ];
    }


    /**
     * @return \yii\db\ActiveQuery
     */
    public function getBlogCategory()
    {
        return $this->hasOne(\common\models\BlogCategory::className(), ['id' => 'blog_category_id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getCreatedBy()
    {
        return $this->hasOne(\common\models\User::className(), ['id' => 'created_by']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getUpdatedBy()
    {
        return $this->hasOne(\common\models\User::className(), ['id' => 'updated_by']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getTranslations()
    {
        return $this->hasMany(\common\models\BlogPostLang::className(), ['blog_post_id' => 'id']);
    }



}
models/base/User.php000066600000013233151456104040010376 0ustar00<?php

namespace common\models\base;

use Yii;
use yii\base\NotSupportedException;
use yii\behaviors\TimestampBehavior;
use yii\db\ActiveRecord;
use yii\web\IdentityInterface;
use common\models\UserProfile;
/**
 * This is the base-model class for table "user".
 *
 * @property integer $id
 * @property string $username
 * @property string $auth_key
 * @property string $password_hash
 * @property string $password_reset_token
 * @property string $email
 * @property integer $status
 * @property integer $created_at
 * @property integer $updated_at
 *
 * @property \common\models\Slider[] $sliders
 * @property \common\models\Slider[] $sliders0
 * @property \common\models\SliderImage[] $sliderImages
 * @property \common\models\SliderImage[] $sliderImages0
 * @property \common\models\UserProfile[] $userProfiles
 */
class User extends ActiveRecord implements IdentityInterface
{

    const STATUS_DELETED = 0;
    const STATUS_ACTIVE = 10;


    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return '{{%user}}';
    }

    /**
     * @inheritdoc
     */
    public function behaviors()
    {
        return [
            TimestampBehavior::className(),
        ];
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['username', 'auth_key', 'password_hash', 'email'], 'required'],
            [['status', 'created_at', 'updated_at'], 'integer'],
            [['username', 'password_hash', 'password_reset_token', 'email'], 'string', 'max' => 255],
            [['auth_key'], 'string', 'max' => 32],
            [['username'], 'unique'],
            [['email'], 'unique'],
            [['password_reset_token'], 'unique'],
            ['status', 'default', 'value' => self::STATUS_ACTIVE],
            ['status', 'in', 'range' => [self::STATUS_ACTIVE, self::STATUS_DELETED]],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => Yii::t('model', 'ID'),
            'username' => Yii::t('model', 'Username'),
            'auth_key' => Yii::t('model', 'Auth Key'),
            'password_hash' => Yii::t('model', 'Password Hash'),
            'password_reset_token' => Yii::t('model', 'Password Reset Token'),
            'email' => Yii::t('model', 'Email'),
            'status' => Yii::t('model', 'Status'),
            'created_at' => Yii::t('model', 'Created At'),
            'updated_at' => Yii::t('model', 'Updated At'),
        ];
    }

    /**
     * @inheritdoc
     */
    public static function findIdentity($id)
    {
        return static::findOne(['id' => $id, 'status' => self::STATUS_ACTIVE]);
    }

    /**
     * @inheritdoc
     */
    public static function findIdentityByAccessToken($token, $type = null)
    {
        throw new NotSupportedException('"findIdentityByAccessToken" is not implemented.');
    }

    /**
     * Finds user by username
     *
     * @param string $username
     * @return static|null
     */
    public static function findByUsername($username)
    {
        return static::findOne(['username' => $username, 'status' => self::STATUS_ACTIVE]);
    }

    /**
     * Finds user by password reset token
     *
     * @param string $token password reset token
     * @return static|null
     */
    public static function findByPasswordResetToken($token)
    {
        if (!static::isPasswordResetTokenValid($token)) {
            return null;
        }

        return static::findOne([
            'password_reset_token' => $token,
            'status' => self::STATUS_ACTIVE,
        ]);
    }

    /**
     * Finds out if password reset token is valid
     *
     * @param string $token password reset token
     * @return boolean
     */
    public static function isPasswordResetTokenValid($token)
    {
        if (empty($token)) {
            return false;
        }

        $timestamp = (int) substr($token, strrpos($token, '_') + 1);
        $expire = Yii::$app->params['user.passwordResetTokenExpire'];
        return $timestamp + $expire >= time();
    }

    /**
     * @inheritdoc
     */
    public function getId()
    {
        return $this->getPrimaryKey();
    }

    /**
     * @inheritdoc
     */
    public function getAuthKey()
    {
        return $this->auth_key;
    }

    /**
     * @inheritdoc
     */
    public function validateAuthKey($authKey)
    {
        return $this->getAuthKey() === $authKey;
    }

    /**
     * Validates password
     *
     * @param string $password password to validate
     * @return boolean if password provided is valid for current user
     */
    public function validatePassword($password)
    {
        return Yii::$app->security->validatePassword($password, $this->password_hash);
    }

    /**
     * Generates password hash from password and sets it to the model
     *
     * @param string $password
     */
    public function setPassword($password)
    {
        $this->password_hash = Yii::$app->security->generatePasswordHash($password);
    }

    /**
     * Generates "remember me" authentication key
     */
    public function generateAuthKey()
    {
        $this->auth_key = Yii::$app->security->generateRandomString();
    }

    /**
     * Generates new password reset token
     */
    public function generatePasswordResetToken()
    {
        $this->password_reset_token = Yii::$app->security->generateRandomString() . '_' . time();
    }

    /**
     * Removes password reset token
     */
    public function removePasswordResetToken()
    {
        $this->password_reset_token = null;
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getUserProfile()
    {
        return $this->hasOne(UserProfile::className(), ['user_id' => 'id']);
    }




}
models/base/BlogPostLang.php000066600000006124151456104040012014 0ustar00<?php

namespace common\models\base;

use Yii;
use yii\behaviors\SluggableBehavior;
use yii\behaviors\TimestampBehavior;
use yii\behaviors\BlameableBehavior;

/**
 * This is the base-model class for table "blog_post_lang".
 *
 * @property integer $id
 * @property string $slug
 * @property integer $blog_post_id
 * @property string $language
 * @property string $title
 * @property string $meta_description
 * @property string $text
 * @property integer $created_by
 * @property integer $updated_by
 * @property string $created_at
 * @property string $updated_at
 *
 * @property \common\models\BlogPost $blogPost
 * @property \common\models\User $createdBy
 * @property \common\models\User $updatedBy
 */
class BlogPostLang extends \yii\db\ActiveRecord
{



    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'blog_post_lang';
    }

    public function behaviors()
    {
        return [
            [
                'class' => SluggableBehavior::className(),
                'attribute' => 'title',
            ],
            'timestamp' => [
                'class' => TimestampBehavior::className(),
            ],
            [
            'class' => BlameableBehavior::className(),
            ],
        ];
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['language'], 'required'],
            [['language', 'title'],
                'required',
                'on'=>'mainLanguage'
            ],
            [['blog_post_id', 'created_by', 'updated_by', 'created_at', 'updated_at'], 'integer'],
            [['text'], 'string'],
            [['slug', 'title', 'meta_title', 'meta_description','tags_list'], 'string', 'max' => 255],
            [['language'], 'string', 'max' => 6]
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => Yii::t('model', 'ID'),
            'slug' => Yii::t('model', 'Slug'),
            'blog_post_id' => Yii::t('model', 'Blog Post'),
            'language' => Yii::t('model', 'Language'),
            'title' => Yii::t('model', 'Title'),
            'meta_description' => Yii::t('model', 'Meta Description'),
            'text' => Yii::t('model', 'Text'),
            'tags_list' => Yii::t('model', 'Tags'),
            'created_by' => Yii::t('model', 'Created By'),
            'updated_by' => Yii::t('model', 'Updated By'),
            'created_at' => Yii::t('model', 'Created At'),
            'updated_at' => Yii::t('model', 'Updated At'),
        ];
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getBlogPost()
    {
        return $this->hasOne(\common\models\BlogPost::className(), ['id' => 'blog_post_id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getCreatedBy()
    {
        return $this->hasOne(\common\models\User::className(), ['id' => 'created_by']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getUpdatedBy()
    {
        return $this->hasOne(\common\models\User::className(), ['id' => 'updated_by']);
    }




}
models/base/GalleryImage.php000066600000004706151456104040012027 0ustar00<?php

namespace common\models\base;

use Yii;
use yii\behaviors\TimestampBehavior;
use yii\behaviors\BlameableBehavior;

/**
 * This is the base-model class for table "gallery_image".
 *
 * @property integer $gallery_id
 * @property string $file_name
 * @property string $sort_order
 * @property integer $is_active
 * @property integer $created_by
 * @property integer $updated_by
 * @property string $created_at
 * @property string $updated_at
 *
 * @property \common\models\Gallery $gallery
 * @property \common\models\User $createdBy
 * @property \common\models\User $updatedBy
 */
class GalleryImage extends \yii\db\ActiveRecord
{



    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'gallery_image';
    }

    public function behaviors()
    {
        return [
            'timestamp' => [
                'class' => TimestampBehavior::className(),
            ],
            [
            'class' => BlameableBehavior::className(),
            ],
        ];
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['gallery_id', 'file_name'], 'required'],
            [['gallery_id', 'sort_order', 'is_active', 'created_by', 'updated_by', 'created_at', 'updated_at'], 'integer'],
            [['file_name'], 'string', 'max' => 255]
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'gallery_id' => Yii::t('model', 'Gallery ID'),
            'file_name' => Yii::t('model', 'File Name'),
            'sort_order' => Yii::t('model', 'Sort Order'),
            'is_active' => Yii::t('model', 'Is Active'),
            'created_by' => Yii::t('model', 'Created By'),
            'updated_by' => Yii::t('model', 'Updated By'),
            'created_at' => Yii::t('model', 'Created At'),
            'updated_at' => Yii::t('model', 'Updated At'),
        ];
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getGallery()
    {
        return $this->hasOne(\common\models\Gallery::className(), ['id' => 'gallery_id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getCreatedBy()
    {
        return $this->hasOne(\common\models\User::className(), ['id' => 'created_by']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getUpdatedBy()
    {
        return $this->hasOne(\common\models\User::className(), ['id' => 'updated_by']);
    }




}
models/base/GlobalConfiguration.php000066600000004515151456104040013413 0ustar00<?php

namespace common\models\base;

use Yii;
use yii\behaviors\SluggableBehavior;
use yii\behaviors\TimestampBehavior;
use yii\behaviors\BlameableBehavior;

/**
 * This is the base-model class for table "global_configuration".
 *
 * @property integer $id
 * @property string $name
 * @property string $slug
 * @property string $value
 * @property integer $created_by
 * @property integer $updated_by
 * @property string $created_at
 * @property string $updated_at
 *
 * @property \common\models\User $createdBy
 * @property \common\models\User $updatedBy
 */
class GlobalConfiguration extends \yii\db\ActiveRecord
{



    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'global_configuration';
    }

    public function behaviors()
    {
        return [
            [
                'class' => SluggableBehavior::className(),
                'attribute' => 'name',
                'immutable' => true,
            ],
            'timestamp' => [
                'class' => TimestampBehavior::className(),
            ],
            [
            'class' => BlameableBehavior::className(),
            ],
        ];
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['name', 'slug'], 'required'],
            [['created_by', 'updated_by', 'created_at', 'updated_at'], 'integer'],
            [['name', 'slug', 'value'], 'string', 'max' => 255]
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => Yii::t('model', 'ID'),
            'name' => Yii::t('model', 'Name'),
            'slug' => Yii::t('model', 'Slug'),
            'value' => Yii::t('model', 'Value'),
            'created_by' => Yii::t('model', 'Created By'),
            'updated_by' => Yii::t('model', 'Updated By'),
            'created_at' => Yii::t('model', 'Created At'),
            'updated_at' => Yii::t('model', 'Updated At'),
        ];
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getCreatedBy()
    {
        return $this->hasOne(\common\models\User::className(), ['id' => 'created_by']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getUpdatedBy()
    {
        return $this->hasOne(\common\models\User::className(), ['id' => 'updated_by']);
    }




}
models/base/ContentLang.php000066600000005267151456104040011704 0ustar00<?php

namespace common\models\base;

use Yii;
use yii\behaviors\TimestampBehavior;
use yii\behaviors\BlameableBehavior;

/**
 * This is the base-model class for table "content_lang".
 *
 * @property integer $id
 * @property integer $content_id
 * @property string $language
 * @property string $text
 * @property integer $created_by
 * @property integer $updated_by
 * @property string $created_at
 * @property string $updated_at
 *
 * @property \common\models\Content $content
 * @property \common\models\User $createdBy
 * @property \common\models\User $updatedBy
 */
class ContentLang extends \yii\db\ActiveRecord
{



    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'content_lang';
    }

    public function behaviors()
    {
        return [
            'timestamp' => [
                'class' => TimestampBehavior::className(),
            ],
            [
            'class' => BlameableBehavior::className(),
            ],
        ];
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['language'], 'required'],
            [['language', 'text'], 'required', 'on' => 'mainLanguage'],
            [['content_id', 'created_by', 'updated_by', 'created_at', 'updated_at'], 'integer'],
            [['text'], 'string'],
            [['text'], 'compare', 'compareValue'=>'<p><br></p>', 'operator'=>'!=',
                        'on'=>'mainLanguage',
                        'message'=>Yii::t('yii', '{attribute} cannot be blank.')
            ],
            [['language'], 'string', 'max' => 6]
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => Yii::t('model', 'ID'),
            'content_id' => Yii::t('model', 'Content ID'),
            'language' => Yii::t('model', 'Language'),
            'text' => Yii::t('model', 'Text'),
            'created_by' => Yii::t('model', 'Created By'),
            'updated_by' => Yii::t('model', 'Updated By'),
            'created_at' => Yii::t('model', 'Created At'),
            'updated_at' => Yii::t('model', 'Updated At'),
        ];
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getContent()
    {
        return $this->hasOne(\common\models\Content::className(), ['id' => 'content_id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getCreatedBy()
    {
        return $this->hasOne(\common\models\User::className(), ['id' => 'created_by']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getUpdatedBy()
    {
        return $this->hasOne(\common\models\User::className(), ['id' => 'updated_by']);
    }




}
models/base/FlatPage.php000066600000006051151456104040011143 0ustar00<?php

namespace common\models\base;

use Yii;
use yii\behaviors\TimestampBehavior;
use yii\behaviors\BlameableBehavior;
use common\components\TranslateableBehavior;

/**
 * This is the base-model class for table "flat_page".
 *
 * @property integer $id
 * @property string $url
 * @property integer $created_by
 * @property integer $updated_by
 * @property string $created_at
 * @property string $updated_at
 *
 * @property \common\models\Content[] $contents
 * @property \common\models\User $createdBy
 * @property \common\models\User $updatedBy
 */
class FlatPage extends \yii\db\ActiveRecord
{

    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'flat_page';
    }
    /**
     * @inheritdoc
     */
    public function behaviors()
    {
        return [
            'translatable' => [
                'class' => TranslateableBehavior::className(),
                // in case you renamed your relation, you can setup its name
                // 'relation' => 'translations',
                'translationAttributes' => [
                    'slug',
                    'meta_title',
                    'meta_description',
                    'anchor',
                ]
            ],
            'timestamp' => [
                'class' => TimestampBehavior::className(),
            ],
            [
            'class' => BlameableBehavior::className(),
            ],
        ];
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['url'], 'required'],
            [['is_active', 'display_on_menu', 'created_by', 'updated_by', 'created_at', 'updated_at'], 'integer'],
            [['url'], 'string', 'max' => 255],
            [['url'], 'unique']
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => Yii::t('model', 'ID'),
            'url' => Yii::t('model', 'Unique ID'),
            'is_active' => Yii::t('model', 'Is Active'),
            'display_on_menu' => Yii::t('model', 'Display on Menu'),
            'created_by' => Yii::t('model', 'Created By'),
            'updated_by' => Yii::t('model', 'Updated By'),
            'created_at' => Yii::t('model', 'Created At'),
            'updated_at' => Yii::t('model', 'Updated At'),
        ];
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getContents()
    {
        return $this->hasMany(\common\models\Content::className(), ['flat_page_id' => 'id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getCreatedBy()
    {
        return $this->hasOne(\common\models\User::className(), ['id' => 'created_by']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getUpdatedBy()
    {
        return $this->hasOne(\common\models\User::className(), ['id' => 'updated_by']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getTranslations()
    {
        return $this->hasMany(\common\models\FlatPageLang::className(), ['flat_page_id' => 'id']);
    }



}
models/base/ProjectBlueprint.php000066600000003502151456104040012751 0ustar00<?php

namespace common\models\base;

use Yii;
use yii\behaviors\TimestampBehavior;
use yii\behaviors\BlameableBehavior;

/**
 * This is the base-model class for table "project_blueprint".
 *
 * @property integer project_id
 * @property string $file_name
 * @property string $sort_order
 * @property integer $is_main
 *
*/
class ProjectBlueprint extends \yii\db\ActiveRecord
{



    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'project_blueprint';
    }

    public function behaviors()
    {
        return [

        ];
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['project_id', 'file_name'], 'required'],
            [['project_id', 'sort_order', 'is_main'], 'integer'],
            [['file_name'], 'string', 'max' => 255]
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'project_id' => 'Proyecto',
            'file_name' => 'Nombre',
            'sort_order' => 'Orden',
            'is_main' => 'Es principal?',
        ];
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getProject()
    {
        return $this->hasOne(\common\models\Project::className(), ['id' => 'project_id']);
    }
    
    public function afterDelete() {
      parent::afterDelete();
      
      // set new main image
      if ($this->is_main) {
        $new_main=ProjectBlueprint::find()
                ->where(['project_id'=>$this->project_id])
                ->orderBy(['sort_order'=>SORT_ASC])
                ->one();
        if ($new_main) {
          $new_main->is_main=1;
          $new_main->updateAttributes(['is_main']);
        }
      }
      
    }
    
}
models/base/Member.php000066600000003161151456104040010666 0ustar00<?php

namespace common\models\base;

use Yii;
use common\components\TranslateableBehavior;
use yii\behaviors\TimestampBehavior;
use yii\behaviors\BlameableBehavior;

/**
 * This is the base-model class for table "member".
 *
 * @property integer $id
 * @property string $name
 * @property string $position
 * @property string $image
 * @property string $twitter
 * @property string $linkedin
 * @property string $mail
 */
class Member extends \yii\db\ActiveRecord
{



    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'member';
    }
    /**
     * @inheritdoc
     */
    public function behaviors()
    {
        return [
            
        ];
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['name', 'position'], 'required'],
            [['description'], 'string'],
            [['name', 'position', 'image', 'twitter', 'linkedin', 'mail'], 'string', 'max' => 255],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => Yii::t('model', 'ID'),
            'name' => 'Nombre',
            'position' => 'Cargo',
            'image' => 'Foto',
            'twitter' =>'Twitter',
            'linkedin' =>'LinkedIn',
            'mail' =>'Correo',
            'description' => 'Resumen',
        ];
    }
    
    public function addhttp($url) {
        if (!preg_match("~^(?:f|ht)tps?://~i", $url)) {
            $url = "http://" . $url;
        }
        return $url;
    }
    
}
models/base/BlogCategory.php000066600000005431151456104040012042 0ustar00<?php

namespace common\models\base;

use Yii;
use common\components\TranslateableBehavior;
use yii\behaviors\TimestampBehavior;
use yii\behaviors\BlameableBehavior;


/**
 * This is the base-model class for table "blog_category".
 *
 * @property integer $id
 * @property integer $created_by
 * @property integer $updated_by
 * @property string $created_at
 * @property string $updated_at
 *
 * @property \common\models\User $createdBy
 * @property \common\models\User $updatedBy
 * @property \common\models\BlogPost[] $blogPosts
 */
class BlogCategory extends \yii\db\ActiveRecord
{



    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'blog_category';
    }
    /**
     * @inheritdoc
     */
    public function behaviors()
    {
        return [
            'translatable' => [
                'class' => TranslateableBehavior::className(),
                // in case you renamed your relation, you can setup its name
                // 'relation' => 'translations',
                'translationAttributes' => [
                    'name',
                    'slug',
                    'description',
                    'meta_description'
                ]
            ],
            'timestamp' => [
                'class' => TimestampBehavior::className(),
            ],
            [
            'class' => BlameableBehavior::className(),
            ],
        ];
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['created_by', 'updated_by', 'created_at', 'updated_at'], 'integer'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => Yii::t('model', 'ID'),
            'created_by' => Yii::t('model', 'Created By'),
            'updated_by' => Yii::t('model', 'Updated By'),
            'created_at' => Yii::t('model', 'Created At'),
            'updated_at' => Yii::t('model', 'Updated At'),
            'name' => Yii::t('model', 'Name'),
        ];
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getCreatedBy()
    {
        return $this->hasOne(\common\models\User::className(), ['id' => 'created_by']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getUpdatedBy()
    {
        return $this->hasOne(\common\models\User::className(), ['id' => 'updated_by']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getBlogPosts()
    {
        return $this->hasMany(\common\models\BlogPost::className(), ['blog_category_id' => 'id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getTranslations()
    {
        return $this->hasMany(\common\models\BlogCategoryLang::className(), ['blog_category_id' => 'id']);
    }



}
models/base/Content.php000066600000006172151456104040011076 0ustar00<?php

namespace common\models\base;

use Yii;
use common\components\TranslateableBehavior;
use yii\behaviors\TimestampBehavior;
use yii\behaviors\BlameableBehavior;

/**
 * This is the base-model class for table "content".
 *
 * @property integer $id
 * @property integer $flat_page_id
 * @property string $name
 * @property integer $created_by
 * @property integer $updated_by
 * @property string $created_at
 * @property string $updated_at
 *
 * @property \common\models\User $createdBy
 * @property \common\models\User $updatedBy
 * @property \common\models\FlatPage $flatPage
 */
class Content extends \yii\db\ActiveRecord
{



    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'content';
    }
    /**
     * @inheritdoc
     */
    public function behaviors()
    {
        return [
            'translatable' => [
                'class' => TranslateableBehavior::className(),
                // in case you renamed your relation, you can setup its name
                // 'relation' => 'translations',
                'translationAttributes' => [
                    'text',
                ]
            ],
            'timestamp' => [
                'class' => TimestampBehavior::className(),
            ],
            [
            'class' => BlameableBehavior::className(),
            ],
        ];
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['name'], 'required'],
            [['flat_page_id', 'created_by', 'updated_by', 'created_at', 'updated_at'], 'integer'],
            [['name'], 'string', 'max' => 255],
            [['name', 'flat_page_id'],
              'unique', 'targetAttribute' => ['name', 'flat_page_id'], 
              'message' => 'The combination of Flat Page ID and Name has already been taken.'
            ]
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => Yii::t('model', 'ID'),
            'flat_page_id' => Yii::t('model', 'Flat Page ID'),
            'name' => Yii::t('model', 'Name'),
            'created_by' => Yii::t('model', 'Created By'),
            'updated_by' => Yii::t('model', 'Updated By'),
            'created_at' => Yii::t('model', 'Created At'),
            'updated_at' => Yii::t('model', 'Updated At'),
            'flatPage' => Yii::t('model', 'Page')
        ];
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getCreatedBy()
    {
        return $this->hasOne(\common\models\User::className(), ['id' => 'created_by']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getUpdatedBy()
    {
        return $this->hasOne(\common\models\User::className(), ['id' => 'updated_by']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getFlatPage()
    {
        return $this->hasOne(\common\models\FlatPage::className(), ['id' => 'flat_page_id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getTranslations()
    {
        return $this->hasMany(\common\models\ContentLang::className(), ['content_id' => 'id']);
    }



}
models/BlogCategoryLang.php000066600000000350151456104040011725 0ustar00<?php

namespace common\models;

use Yii;
use \common\models\base\BlogCategoryLang as BaseBlogCategoryLang;

/**
 * This is the model class for table "blog_category_lang".
 */
class BlogCategoryLang extends BaseBlogCategoryLang
{
}
models/BlogPost.php000066600000010136151456104040010276 0ustar00<?php
/*TODO: Make better organization of blog post image folders */
/*TODO: Generalize upload of one image to a Trait, to use it on: User Profile (avatar) and BlogPost (featured_image) */
/*TODO: Allow creation of subdirectories when uploading an image */
/*TODO: Add support for tags */
namespace common\models;

use Yii;
use yii\helpers\Url;
use yii\helpers\StringHelper;
use common\models\base\BlogPost as BaseBlogPost;
use common\models\traits\Translation;

/**
 * This is the model class for table "blog_post".
 */
class BlogPost extends BaseBlogPost
{
    use Translation;

    protected $featuredImageDirectory = 'blog-post/';
    protected $featuredImageFullDirectory;
    protected $featuredImageURL;
    protected $defaultFeaturedImage;
    public $uploadedFeaturedImage;

    public static function findBySlug($slug, $language = null){
        $language = isset($language) ? $language : Yii::$app->language;
        return self::find()
                ->joinWith('translations')
                ->where(['blog_post_lang.slug'=>$slug])
                ->andWhere(['blog_post_lang.language'=>$language])
                ->one();
    }

    public function init(){
        $this->featuredImageFullDirectory = Yii::$app->params['frontendUploadDirectory'] . $this->featuredImageDirectory;
        $this->featuredImageURL = sprintf('%s%s%s',
                            Yii::$app->params['frontendURL'],
                            Yii::$app->params['uploadDirectoryForURL'],
                            $this->featuredImageDirectory);
        $this->defaultFeaturedImage = 'default_featured_image.jpg';
    }

    public function attributeLabels(){
        $parentAttributeLabels = parent::attributeLabels();
        $parentAttributeLabels['uploadedFeaturedImage'] = Yii::t('model', 'Featured Image');
        return $parentAttributeLabels;
    }

    public function getFullUrlFeaturedImage(){
        $featuredImage = isset($this->featured_image) ? $this->featured_image : $this->defaultFeaturedImage;
        return $this->featuredImageURL . $featuredImage;
    }

    public function saveFeaturedImageToDisk(){
        $uploadedOK = true;
        if (isset($this->uploadedFeaturedImage)) {
            $fileName = sprintf('%d-featured-%s.%s',
                    $this->id,
                    $this->uploadedFeaturedImage->baseName,
                    $this->uploadedFeaturedImage->extension);
            $fileFullPath = $this->featuredImageFullDirectory . $fileName;
            $this->uploadedFeaturedImage->saveAs($fileFullPath);

            /*TODO: Make better control over upload errors */
            if ($this->uploadedFeaturedImage->error==0) {
                $this->featured_image = $fileName;
                $this->save();
                $uploadedOK = true;
            }
            else{
                $uploadedOK = false;
            }
        }

        return $uploadedOK;
    }

    public function saveImageToDisk($image){
        $fileName = sprintf('%d-featured-%s.%s',
            $this->id,
            $image->baseName,
            $image->extension);
        $fileFullPath = $this->featuredImageFullDirectory . $fileName;
        $image->saveAs($fileFullPath);

        return $this->featuredImageURL . $fileName;
    }

    /*TODO: remove double slash i.e.: http://heavycms.dev//site/contact*/
    public function getFullUrl(){
        return Yii::$app->params['frontendURL'] . $this->getUrl();
    }

    public function getUrl(){
        return Url::toRoute(['blog/view', 'slug'=>$this->slug]);
    }

    public function getBriefText($asHtml = true){
        return StringHelper::truncateWords($this->text, 40, $suffix = '...', $asHtml);
    }
    
    public function getAllTags() {
      $allTags=array();
      $tags_array=  explode(",", $this->tags_list);

      foreach ($tags_array as $tag) {
        $tag=trim($tag);
        if (!empty($tag)) {
          if (!isset($allTags[$tag])) {
            $allTags[$tag]=1;
          } else {
            $allTags[$tag] = $allTags[$tag] +1;
          }
        }
      }
      
      arsort($allTags);
        
      $allTags=array_keys($allTags);
      
      return $allTags;
        
    }
}
models/User.php000066600000001072151456104040007462 0ustar00<?php
namespace common\models;

use Yii;
use common\models\base\User as BaseUser;
use common\models\UserProfile;

class User extends BaseUser{

    public function afterSave($insert, $changedAttributes){
        parent::afterSave($insert, $changedAttributes);
        if ($insert) {
            $userProfile = new UserProfile;
            $userProfile->name = $this->username;
            $this->link('userProfile', $userProfile);
        }
    }

    public function getFullName(){
        return $this->userProfile->name . ' ' . $this->userProfile->lastname;
    }

}
models/ProjectSearch.php000066600000002316151456104040011302 0ustar00<?php

namespace common\models;

use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use common\models\Project;

/**
* GlobalConfigurationSearch represents the model behind the search form about `common\models\Project`.
*/
class ProjectSearch extends Project
{
/**
* @inheritdoc
*/
public function rules()
{
return [
[['id'], 'integer'],
            [['title'], '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)
{
$query = Project::find();

$dataProvider = new ActiveDataProvider([
'query' => $query,
]);

$this->load($params);

if (!$this->validate()) {
// uncomment the following line if you do not want to any records when validation fails
// $query->where('0=1');
return $dataProvider;
}

$query->andFilterWhere([
            'id' => $this->id,
        ]);

        $query->andFilterWhere(['like', 'title', $this->title]);
        $query->orderBy(['id'=>SORT_DESC]);

return $dataProvider;
}
}models/BlogPostLang.php000066600000000503151456104040011075 0ustar00<?php

namespace common\models;

use Yii;
use yii\behaviors\SluggableBehavior;
use yii\behaviors\TimestampBehavior;
use yii\behaviors\BlameableBehavior;
use \common\models\base\BlogPostLang as BaseBlogPostLang;

/**
 * This is the model class for table "blog_post_lang".
 */
class BlogPostLang extends BaseBlogPostLang
{
}
models/ContentSearch.php000066600000002610151456104040011303 0ustar00<?php

namespace common\models;

use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use common\models\Content;

/**
* ContentSearch represents the model behind the search form about `common\models\Content`.
*/
class ContentSearch extends Content
{
/**
* @inheritdoc
*/
public function rules()
{
return [
[['id', 'flat_page_id', 'created_by', 'updated_by', 'created_at', 'updated_at'], 'integer'],
            [['name'], '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)
{
$query = Content::find();

$dataProvider = new ActiveDataProvider([
'query' => $query,
]);

$this->load($params);

if (!$this->validate()) {
// uncomment the following line if you do not want to any records when validation fails
// $query->where('0=1');
return $dataProvider;
}

$query->andFilterWhere([
            'id' => $this->id,
            'flat_page_id' => $this->flat_page_id,
            'created_by' => $this->created_by,
            'updated_by' => $this->updated_by,
            'created_at' => $this->created_at,
            'updated_at' => $this->updated_at,
        ]);

        $query->andFilterWhere(['like', 'name', $this->name]);

return $dataProvider;
}
}models/GallerySearch.php000066600000002611151456104040011271 0ustar00<?php

namespace common\models;

use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use common\models\Gallery;

/**
* GallerySearch represents the model behind the search form about `common\models\Gallery`.
*/
class GallerySearch extends Gallery
{
/**
* @inheritdoc
*/
public function rules()
{
return [
[['id', 'created_by', 'updated_by', 'created_at', 'updated_at'], 'integer'],
            [['name', 'slug'], '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)
{
$query = Gallery::find();

$dataProvider = new ActiveDataProvider([
'query' => $query,
]);

$this->load($params);

if (!$this->validate()) {
// uncomment the following line if you do not want to any records when validation fails
// $query->where('0=1');
return $dataProvider;
}

$query->andFilterWhere([
            'id' => $this->id,
            'created_by' => $this->created_by,
            'updated_by' => $this->updated_by,
            'created_at' => $this->created_at,
            'updated_at' => $this->updated_at,
        ]);

        $query->andFilterWhere(['like', 'name', $this->name])
            ->andFilterWhere(['like', 'slug', $this->slug]);

return $dataProvider;
}
}models/GalleryImage.php000066600000001735151456104040011114 0ustar00<?php

namespace common\models;

use Yii;
use yii\behaviors\TimestampBehavior;
use yii\behaviors\BlameableBehavior;
use common\models\base\GalleryImage as BaseGalleryImage;

/**
 * This is the model class for table "gallery_image".
 */
class GalleryImage extends BaseGalleryImage
{
    protected $uploadDirectory = 'galleries/';
    protected $uploadFullDirectory;
    protected $uploadURL;

    public function init(){
        $this->uploadFullDirectory = Yii::$app->params['frontendUploadDirectory'] . $this->uploadDirectory;
        $this->uploadURL = sprintf('%s%s%s',
                                    Yii::$app->params['frontendURL'],
                                    Yii::$app->params['uploadDirectoryForURL'],
                                    $this->uploadDirectory);
    }

    public function getFileFullPath(){
        return $this->uploadFullDirectory . $this->file_name;
    }

    public function getURL(){
        return $this->uploadURL . $this->file_name;
    }
}
models/GlobalConfiguration.php000066600000000544151456104040012477 0ustar00<?php
namespace common\models;

use Yii;
use yii\behaviors\SluggableBehavior;
use yii\behaviors\TimestampBehavior;
use yii\behaviors\BlameableBehavior;
use \common\models\base\GlobalConfiguration as BaseGlobalConfiguration;

/**
 * This is the model class for table "global_configuration".
 */
class GlobalConfiguration extends BaseGlobalConfiguration
{
}
models/BlogCategorySearch.php000066600000002403151456104040012252 0ustar00<?php

namespace common\models;

use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use common\models\BlogCategory;

/**
* BlogCategorySearch represents the model behind the search form about `common\models\BlogCategory`.
*/
class BlogCategorySearch extends BlogCategory
{
/**
* @inheritdoc
*/
public function rules()
{
return [
[['id', 'created_by', 'updated_by', 'created_at', 'updated_at'], 'integer'],
];
}

/**
* @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)
{
$query = BlogCategory::find();

$dataProvider = new ActiveDataProvider([
'query' => $query,
]);

$this->load($params);

if (!$this->validate()) {
// uncomment the following line if you do not want to any records when validation fails
// $query->where('0=1');
return $dataProvider;
}

$query->andFilterWhere([
            'id' => $this->id,
            'created_by' => $this->created_by,
            'updated_by' => $this->updated_by,
            'created_at' => $this->created_at,
            'updated_at' => $this->updated_at,
        ]);

return $dataProvider;
}
}models/traits/Translation.php000066600000002055151456104040012352 0ustar00<?php
namespace common\models\traits;

use Yii;

trait Translation{
    public function saveTranslations($translations){
        foreach ($translations as $translation) {
            if ($translation->isNewRecord) {
                $translation->{key($this->getObjectRelation()->link)} = $this->getPrimaryKey();
            }
            $translation->save(false);
        }
    }

    public function initializeTranslations(){
        $translations = [];
        foreach (Yii::$app->params['frontendLanguages'] as $languageCode => $languageName) {
            $translation = $this->getTranslation($languageCode);
            if ($languageCode == Yii::$app->params['appMainLanguage']) {
                $translation->scenario = 'mainLanguage';
            }
            $translations[] = $translation;
        }
        return $translations;
    }

    private function getObjectRelation(){
        return $this->getRelation($this->getRelationName());
    }

    private function getRelationName(){
        return $this->getBehavior('translatable')->relation;
    }

}
models/ContentLang.php000066600000000430151456104040010755 0ustar00<?php

namespace common\models;

use Yii;
use yii\behaviors\TimestampBehavior;
use yii\behaviors\BlameableBehavior;
use \common\models\base\ContentLang as BaseContentLang;

/**
 * This is the model class for table "content_lang".
 */
class ContentLang extends BaseContentLang
{
}
models/FlatPage.php000066600000006144151456104040010234 0ustar00<?php

namespace common\models;

use Yii;
use yii\helpers\Url;
use yii\helpers\ArrayHelper;
use common\models\base\FlatPage as BaseFlatPage;
use common\models\traits\Translation;

/**
 * This is the model class for table "flat_page".
 */
class FlatPage extends BaseFlatPage
{
    use Translation;

    public static function getMappedArray(){
        $models = self::find()->all();
        return ArrayHelper::map($models, 'id', 'anchor');
    }

    public static function getUrlFor($flatPageUrl){
        $flatPage = FlatPage::findOne(['url' => $flatPageUrl]);
        return isset($flatPage) ? $flatPage->getUrl() : '#';
    }

    public static function findBySlugFallback($slug, $currentLanguage = null) {
        $currentLanguage = isset($currentLanguage) ? $currentLanguage : Yii::$app->language;
        $flatPageCurrentLanguage = self::findBySlug($slug, $currentLanguage);
        if (isset($flatPageCurrentLanguage)) {
            return $flatPageCurrentLanguage;
        }

        $flatPageFallbackLanguage = self::findBySlug($slug, Yii::$app->params['fallbackLanguage']);
        if (isset($flatPageFallbackLanguage)&&!$flatPageFallbackLanguage->modelHasTranslation($currentLanguage, 'slug')) {
            return $flatPageFallbackLanguage;
        }

        $flatPageMainLanguage = self::findBySlug($slug, Yii::$app->params['appMainLanguage']);
        if (isset($flatPageMainLanguage)
            &&!$flatPageMainLanguage->modelHasTranslation($currentLanguage, 'slug')
            &&!$flatPageMainLanguage->modelHasTranslation(Yii::$app->params['fallbackLanguage'], 'slug')
        ) {
            return $flatPageMainLanguage;
        }

        return null;
    }

    public static function findBySlug($slug, $language = null){
        $language = isset($language) ? $language : Yii::$app->language;
        return self::find()
            ->joinWith('translations')
            ->where(['flat_page_lang.slug'=>$slug])
            ->andWhere(['flat_page_lang.language'=>$language])
            ->one();
    }

    public function matchRequestedRoute(){
        if (Yii::$app->requestedRoute=='site/index'&&$this->url=='index') {
            return true;
        }
        if (Yii::$app->controller->id=='blog'&&$this->url=='blog') {
            return true;
        }

        $urlSlug = isset(Yii::$app->controller->module->requestedAction->controller->actionParams['slug']) ?
            Yii::$app->controller->module->requestedAction->controller->actionParams['slug']:
            null;
        return $urlSlug == $this->slug;
    }

    public function getFullUrl(){
        return substr(Yii::$app->params['frontendURL'], 0, -1) . Yii::$app->urlManagerFrontend->createUrl($this->getRoute());
    }

    public function getUrl(){
        return Url::toRoute($this->getRoute());
    }

    public function getRoute(){
        $route = ['flat-page/select', 'slug' => $this->slug];
        if ($this->url == 'blog') {
            $route = ['blog/index'];
        }
        elseif ($this->url == 'index') {
            $route = ['site/index'];
        }
        return $route;
    }

    public function __toString(){
        return $this->url;
    }
}
models/ProjectBlueprint.php000066600000002034151456104040012036 0ustar00<?php

namespace common\models;

use Yii;
use yii\behaviors\TimestampBehavior;
use yii\behaviors\BlameableBehavior;
use common\models\base\ProjectBlueprint as BaseProjectBlueprint;

/**
 * This is the model class for table "project_blueprint".
 */
class ProjectBlueprint extends BaseProjectBlueprint
{
    protected $uploadDirectory = 'projects-blueprint/';
    protected $uploadFullDirectory;
    protected $uploadURL;

    public function init(){
        $this->uploadFullDirectory = Yii::$app->params['frontendUploadDirectory'] . $this->uploadDirectory;
        $this->uploadURL = sprintf('%s%s%s',
                                    Yii::$app->params['frontendURL'],
                                    Yii::$app->params['uploadDirectoryForURL'],
                                    $this->uploadDirectory);
    }

    public function getFileFullPath(){
        return $this->uploadFullDirectory . $this->file_name;
    }

    public function getURL(){
        return $this->uploadURL . $this->file_name;
    }
}
models/BlogPostSearch.php000066600000002456151456104040011432 0ustar00<?php

namespace common\models;

use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use common\models\BlogPost;

/**
* BlogPostSearch represents the model behind the search form about `common\models\BlogPost`.
*/
class BlogPostSearch extends BlogPost
{
/**
* @inheritdoc
*/
public function rules()
{
return [
[['id', 'is_published', 'created_by', 'updated_by', 'created_at', 'updated_at'], 'integer'],
];
}

/**
* @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)
{
$query = BlogPost::find();

$dataProvider = new ActiveDataProvider([
'query' => $query,
]);

$this->load($params);

if (!$this->validate()) {
// uncomment the following line if you do not want to any records when validation fails
// $query->where('0=1');
return $dataProvider;
}

$query->andFilterWhere([
            'id' => $this->id,
            'is_published' => $this->is_published,
            'created_by' => $this->created_by,
            'updated_by' => $this->updated_by,
            'created_at' => $this->created_at,
            'updated_at' => $this->updated_at,
        ]);

return $dataProvider;
}
}models/Member.php000066600000005555151456104040007765 0ustar00<?php
/*TODO: Make better organization of blog post image folders */
/*TODO: Generalize upload of one image to a Trait, to use it on: User Profile (avatar) and BlogPost (featured_image) */
/*TODO: Allow creation of subdirectories when uploading an image */
/*TODO: Add support for tags */
namespace common\models;

use Yii;
use yii\helpers\Url;
use yii\helpers\StringHelper;
use common\models\base\Member as BaseMember;
use common\models\traits\Translation;

/**
 * This is the model class for table "member".
 */
class Member extends BaseMember
{
    use Translation;

    protected $featuredImageDirectory = 'profile/';
    protected $featuredImageFullDirectory;
    protected $featuredImageURL;
    protected $defaultFeaturedImage;
    public $uploadedFeaturedImage;

    public function init(){
        $this->featuredImageFullDirectory = Yii::$app->params['frontendUploadDirectory'] . $this->featuredImageDirectory;
        $this->featuredImageURL = sprintf('%s%s%s',
                            Yii::$app->params['frontendURL'],
                            Yii::$app->params['uploadDirectoryForURL'],
                            $this->featuredImageDirectory);
        $this->defaultFeaturedImage = 'default_featured_image.jpg';
    }

    public function attributeLabels(){
        $parentAttributeLabels = parent::attributeLabels();
        $parentAttributeLabels['uploadedFeaturedImage'] = Yii::t('model', 'Imagen');
        return $parentAttributeLabels;
    }

    public function getFullUrlFeaturedImage(){
        $featuredImage = isset($this->image) ? $this->image : $this->defaultFeaturedImage;
        return $this->featuredImageURL . $featuredImage;
    }

    public function saveFeaturedImageToDisk(){
        $uploadedOK = true;
        if (isset($this->uploadedFeaturedImage)) {
            $fileName = sprintf('%d-%s.%s',
                    $this->id,
                    $this->uploadedFeaturedImage->baseName,
                    $this->uploadedFeaturedImage->extension);
            $fileFullPath = $this->featuredImageFullDirectory . $fileName;
            $this->uploadedFeaturedImage->saveAs($fileFullPath);

            /*TODO: Make better control over upload errors */
            if ($this->uploadedFeaturedImage->error==0) {
                $this->image = $fileName;
                $this->save();
                $uploadedOK = true;
            }
            else{
                $uploadedOK = false;
            }
        }

        return $uploadedOK;
    }

    public function saveImageToDisk($image){
        $fileName = sprintf('%d-%s.%s',
            $this->id,
            $image->baseName,
            $image->extension);
        $fileFullPath = $this->featuredImageFullDirectory . $fileName;
        $image->saveAs($fileFullPath);

        return $this->featuredImageURL . $fileName;
    }

   
}
models/GlobalConfigurationSearch.php000066600000003030151456104040013616 0ustar00<?php

namespace common\models;

use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use common\models\GlobalConfiguration;

/**
* GlobalConfigurationSearch represents the model behind the search form about `common\models\GlobalConfiguration`.
*/
class GlobalConfigurationSearch extends GlobalConfiguration
{
/**
* @inheritdoc
*/
public function rules()
{
return [
[['id', 'created_by', 'updated_by', 'created_at', 'updated_at'], 'integer'],
            [['name', 'slug', 'value'], '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)
{
$query = GlobalConfiguration::find();

$dataProvider = new ActiveDataProvider([
'query' => $query,
]);

$this->load($params);

if (!$this->validate()) {
// uncomment the following line if you do not want to any records when validation fails
// $query->where('0=1');
return $dataProvider;
}

$query->andFilterWhere([
            'id' => $this->id,
            'created_by' => $this->created_by,
            'updated_by' => $this->updated_by,
            'created_at' => $this->created_at,
            'updated_at' => $this->updated_at,
        ]);

        $query->andFilterWhere(['like', 'name', $this->name])
            ->andFilterWhere(['like', 'slug', $this->slug])
            ->andFilterWhere(['like', 'value', $this->value]);

return $dataProvider;
}
}models/BlogCategory.php000066600000001423151456104040011125 0ustar00<?php

namespace common\models;

use Yii;
use yii\helpers\Url;
use yii\helpers\ArrayHelper;
use common\models\base\BlogCategory as BaseBlogCategory;
use common\models\traits\Translation;

/**
 * This is the model class for table "blog_category".
 */
class BlogCategory extends BaseBlogCategory
{
    use Translation;

    public static function getMappedArray(){
        $models = self::find()->all();
        return ArrayHelper::map($models, 'id', 'name');
    }

    public static function findBySlug($slug){
        return self::find()
                ->joinWith('translations')
                ->where(['blog_category_lang.slug'=>$slug])
                ->one();
    }

    public function getUrl(){
        return Url::toRoute(['blog/category-index', 'slug'=>$this->slug]);
    }
}
models/ProjectQuery.php000066600000000746151456104040011207 0ustar00<?php

namespace common\models;

/**
 * This is the ActiveQuery class for [[Project]].
 *
 * @see Project
 */
class ProjectQuery extends \yii\db\ActiveQuery
{
    /**
     * @inheritdoc
     * @return Project[]|array
     */
    public function all($db = null)
    {
        return parent::all($db);
    }

    /**
     * @inheritdoc
     * @return Project|array|null
     */
    public function one($db = null)
    {
        return parent::one($db);
    }
}models/Content.php000066600000000476151456104040010165 0ustar00<?php

namespace common\models;

use Yii;
use yii\behaviors\TimestampBehavior;
use yii\behaviors\BlameableBehavior;
use \common\models\base\Content as BaseContent;
use common\models\traits\Translation;

/**
 * This is the model class for table "content".
 */
class Content extends BaseContent
{
    use Translation;
}
widgets/LanguageDropdown.php000066600000007275151456104040012202 0ustar00<?php
namespace common\widgets;

use Yii;
use yii\helpers\Url;
use yii\base\Widget;

use common\models\FlatPage;
use common\models\BlogPost;
use common\models\BlogCategory;

class LanguageDropdown extends Widget{

    public $supportedLanguages = [];
    public $activeClass = '';
    public $selectedLanguage = [];

    public function init(){
        parent::init();
    }

    public function run(){
        $currentLanguage = Yii::$app->language;
        foreach (Yii::$app->params['supportedLanguages'] as $localeId => $languageName) {
            $this->changeLanguageToCreateUrlWithUrlManager($localeId);
            $this->supportedLanguages[$localeId]['name'] = $languageName;
            $this->supportedLanguages[$localeId]['url'] = $this->generateURLForSelectedLanguage($currentLanguage);
            $this->supportedLanguages[$localeId]['class'] = $this->getClass($localeId, $currentLanguage);
            $this->setSelectedLanguage($localeId, $currentLanguage);
        }
        $this->returnToCurrentLanguage($currentLanguage);
        return $this->render('_language-dropdown', ['supportedLanguages'=>$this->supportedLanguages,
                                                    'selectedLanguage'=>$this->selectedLanguage]);
    }

    private function changeLanguageToCreateUrlWithUrlManager($localeId){
        Yii::$app->language = $localeId;
    }

    private function returnToCurrentLanguage($currentLanguage){
        Yii::$app->language = $currentLanguage;
    }

    private function generateURLForSelectedLanguage($currentLanguage){
        $params = Yii::$app->request->queryParams;
        $controllerName = Yii::$app->controller->getUniqueId();
        unset($params['language']);
        $routeYii = Yii::$app->controller->getRoute();
        $route = array_merge([$routeYii], $params);
        /*TODO: Refactor this code, it's not semantic an it's messy */
        if ($routeYii=='blog/view') {
            $blogPost = BlogPost::findBySlug($params['slug'], $currentLanguage);
            $params['slug'] = $blogPost->slug;
            if (BlogPost::findBySlug($params['slug'], Yii::$app->language)===null) {
                $routeYii = 'blog/index';
                $params = [];
            }
            $route = array_merge([$routeYii], $params);
        }
        elseif ($routeYii=='blog/category-index'){
            $blogCategory = BlogCategory::findBySlug($params['slug']);
            $blogCategory->setLanguage(Yii::$app->language);
            $params['slug'] = $blogCategory->slug;
            $route = array_merge([$routeYii], $params);
        }
        elseif ($controllerName=='flat-page'&&Yii::$app->id=='app-frontend'){
            $flatPage = FlatPage::findBySlugFallback($params['slug'], $currentLanguage);
            if (isset($flatPage)) {
                $params['slug'] = $flatPage->slug;
            }
            else{
                $params = [];
                $routeYii = 'site/index';
            }
            $route = array_merge([$routeYii], $params);
        }
        elseif ($routeYii=='site/error'){
            $routeYii = 'site/index';
            $params = [];
            $route = array_merge([$routeYii], $params);
        }
        return Url::toRoute($route);
    }
    private function getClass($localeId, $currentLanguage){
        return $this->isSelectedLanguage($localeId, $currentLanguage) ? $this->activeClass : null;
    }

    private function isSelectedLanguage($localeId, $currentLanguage){
        return ($localeId == $currentLanguage);
    }

    private function setSelectedLanguage($localeId, $currentLanguage){
        if ($this->isSelectedLanguage($localeId, $currentLanguage)) {
            $this->selectedLanguage = $this->supportedLanguages[$localeId];
        }
    }
}
widgets/Alert.php000066600000004744151456104040010007 0ustar00<?php
/**
 * @link http://www.yiiframework.com/
 * @copyright Copyright (c) 2008 Yii Software LLC
 * @license http://www.yiiframework.com/license/
 */

namespace common\widgets;

/**
 * Alert widget renders a message from session flash. All flash messages are displayed
 * in the sequence they were assigned using setFlash. You can set message as following:
 *
 * ```php
 * \Yii::$app->session->setFlash('error', 'This is the message');
 * \Yii::$app->session->setFlash('success', 'This is the message');
 * \Yii::$app->session->setFlash('info', 'This is the message');
 * ```
 *
 * Multiple messages could be set as follows:
 *
 * ```php
 * \Yii::$app->session->setFlash('error', ['Error 1', 'Error 2']);
 * ```
 *
 * @author Kartik Visweswaran <kartikv2@gmail.com>
 * @author Alexander Makarov <sam@rmcreative.ru>
 */
class Alert extends \yii\bootstrap\Widget
{
    /**
     * @var array the alert types configuration for the flash messages.
     * This array is setup as $key => $value, where:
     * - $key is the name of the session flash variable
     * - $value is the bootstrap alert type (i.e. danger, success, info, warning)
     */
    public $alertTypes = [
        'error'   => 'alert-danger',
        'danger'  => 'alert-danger',
        'success' => 'alert-success',
        'info'    => 'alert-info',
        'warning' => 'alert-warning'
    ];

    /**
     * @var array the options for rendering the close button tag.
     */
    public $closeButton = [];

    public function init()
    {
        parent::init();

        $session = \Yii::$app->session;
        $flashes = $session->getAllFlashes();
        $appendCss = isset($this->options['class']) ? ' ' . $this->options['class'] : '';

        foreach ($flashes as $type => $data) {
            if (isset($this->alertTypes[$type])) {
                $data = (array) $data;
                foreach ($data as $i => $message) {
                    /* initialize css class for each alert box */
                    $this->options['class'] = $this->alertTypes[$type] . $appendCss;

                    /* assign unique id to each alert box */
                    $this->options['id'] = $this->getId() . '-' . $type . '-' . $i;

                    echo \yii\bootstrap\Alert::widget([
                        'body' => $message,
                        'closeButton' => $this->closeButton,
                        'options' => $this->options,
                    ]);
                }

                $session->removeFlash($type);
            }
        }
    }
}
modules/resizer/helpers/ResizeFilter.php000066600000000557151456104040014474 0ustar00<?php

namespace common\modules\resizer\helpers;

class ResizeFilter {
  /**
   * Returns the url with resize filter
   * @param type $src
   * @param type $filterName
   * @return type
   */
  static public function apply($src, $filterName) {
    $src=ltrim($src, '/');
    return \Yii::$app->params['frontendURL'] . 'uploads/' ."resize/{$filterName}/{$src}";
  }
}
modules/resizer/views/default/index.php000066600000000712151456104040014304 0ustar00<div class="resizer-default-index">
    <h1><?= $this->context->action->uniqueId ?></h1>
    <p>
        This is the view content for action "<?= $this->context->action->id ?>".
        The action belongs to the controller "<?= get_class($this->context) ?>"
        in the "<?= $this->context->module->id ?>" module.
    </p>
    <p>
        You may customize this page by editing the following file:<br>
        <code><?= __FILE__ ?></code>
    </p>
</div>
modules/resizer/components/ResizerUrlRule.php000066600000002601151456104040015536 0ustar00<?php

namespace common\modules\resizer\components;

use yii\web\UrlRuleInterface;
use yii\base\Object;


class ResizerUrlRule extends Object implements UrlRuleInterface
{
    public function createUrl($manager, $route, $params)
    {
//        if ($route === 'car/index') {
//            if (isset($params['manufacturer'], $params['model'])) {
//                return $params['manufacturer'] . '/' . $params['model'];
//            } elseif (isset($params['manufacturer'])) {
//                return $params['manufacturer'];
//            }
//        }
        return false; // this rule does not apply
    }

    public function parseRequest($manager, $request)
    {
        $pathInfo = $request->getPathInfo();
        $pathItems= explode("/", $pathInfo);
        $params=[];
        
        if ($pathItems[0]=="uploads" && $pathItems[1]=="resize") {
          return ['resizer/default/index', $params];
        }
        
//        \yii\helpers\VarDumper::dump($pathItems, 10, true);
//        die();
//        if (preg_match('%^(\w+)(/(\w+))?$%', $pathInfo, $matches)) {
//            // check $matches[1] and $matches[3] to see
//            // if they match a manufacturer and a model in the database.
//            // If so, set $params['manufacturer'] and/or $params['model']
//            // and return ['car/index', $params]
//        }
        return false; // this rule does not apply
    }
}modules/resizer/filters/ProjectLargeResizeFilter.php000066600000000735151456104040017002 0ustar00<?php

namespace common\modules\resizer\filters;

use yii\imagine\Image;

class ProjectLargeResizeFilter {

  public function run($originalFile, $savePath) {
    // frame, rotate and save an image
//    $result = Image::frame($originalFile, 5, '666', 0)
//            ->rotate(-8)
//            ->save($savePath, ['jpeg_quality' => 50]);
    $image = Image::resize($originalFile, 848, null, true);
    $image->save($savePath, ['jpeg_quality' => 80]);
    return $image;
  }

}
modules/resizer/filters/ProjectMediumResizeFilter.php000066600000000736151456104040017171 0ustar00<?php

namespace common\modules\resizer\filters;

use yii\imagine\Image;

class ProjectMediumResizeFilter {

  public function run($originalFile, $savePath) {
    // frame, rotate and save an image
//    $result = Image::frame($originalFile, 5, '666', 0)
//            ->rotate(-8)
//            ->save($savePath, ['jpeg_quality' => 50]);
    $image = Image::resize($originalFile, 460, null, true);
    $image->save($savePath, ['jpeg_quality' => 80]);
    return $image;
  }

}
modules/resizer/filters/MyThumbResizeFilter.php000066600000000471151456104040016003 0ustar00<?php

namespace common\modules\resizer\filters;

use yii\imagine\Image;

class MyThumbResizeFilter {
  public function run($originalFile, $savePath) {
    // frame, rotate and save an image
    return Image::frame($originalFile, 5, '666', 0)
    ->rotate(-8)
    ->save($savePath, ['jpeg_quality' => 50]);
  }
}
modules/resizer/filters/ProjectSmallResizeFilter.php000066600000000735151456104040017020 0ustar00<?php

namespace common\modules\resizer\filters;

use yii\imagine\Image;

class ProjectSmallResizeFilter {

  public function run($originalFile, $savePath) {
    // frame, rotate and save an image
//    $result = Image::frame($originalFile, 5, '666', 0)
//            ->rotate(-8)
//            ->save($savePath, ['jpeg_quality' => 50]);
    $image = Image::resize($originalFile, 200, null, true);
    $image->save($savePath, ['jpeg_quality' => 80]);
    return $image;
  }

}
modules/resizer/Module.php000066600000001137151456104040011643 0ustar00<?php

namespace common\modules\resizer;

/**
 * resizer module definition class
 */
class Module extends \yii\base\Module {

  /**
   * must end in /
   * @var array
   */
  public $allowedPaths=[];
  /**
   * List of filter names and classes
   * @var type 
   */
  public $filters=[];
  /**
   * File to use if image not found
   * @var type 
   */
  public $notFound=false;

  /**
   * @inheritdoc
   */
  public $controllerNamespace = 'common\modules\resizer\controllers';

  /**
   * @inheritdoc
   */
  public function init() {
    parent::init();

    // custom initialization code goes here
  }

}
modules/resizer/controllers/DefaultController.php000066600000007165151456104040016423 0ustar00<?php

namespace common\modules\resizer\controllers;

use yii\web\Controller;
use yii\web\HttpException;

/**
 * Default controller for the `resizer` module
 */
class DefaultController extends Controller {

  /**
   * Renders the index view for the module
   * @return string
   */
  public function actionIndex() {
    
    $request=\Yii::$app->request;
    $pathInfo = $request->getPathInfo();
    
    // Split url into parts
    $url_parts= explode("/", $pathInfo);
    
    
    // Get the resize rule name
    $filterName = $url_parts[2];

    // Remove the unnecesary parts from the beggining and recompose the resize_path
    foreach (range(0, 2) as $r) {
      unset($url_parts[$r]);
    }
    $resize_path = implode("/", $url_parts);
    
//    \yii\helpers\VarDumper::dump($url_parts, 10, true);
//    \yii\helpers\VarDumper::dump($resize_path, 10, true);
    
    // Check path is allowed
    if (!$this->resizeCheckAllowedPath($resize_path)) {
      throw new HttpException(500, "Resize path not allowed: {$resize_path}.");
    }

    // Check filter is defined
    $filters = \Yii::$app->getModule('resizer')->filters;
    if (!isset($filters[$filterName])) {
      throw new HttpException(500, "Resize filter not found: {$filterName}.");
    }
    
//    die();
    
    // Check original file exists
    $resize_absolute_path = \Yii::getAlias('@webroot') . "/" . $resize_path;
//    \yii\helpers\VarDumper::dump($resize_absolute_path, 10, true);
    if (!file_exists($resize_absolute_path) && !empty(\Yii::$app->getModule('resizer')->notFound)) {
      $resize_absolute_path = \Yii::getAlias('@webroot') . "/" . \Yii::$app->getModule('resizer')->notFound;
    }
    
//    \yii\helpers\VarDumper::dump($resize_path, 10, true);
//    \yii\helpers\VarDumper::dump($resize_absolute_path, 10, true);
//    
//    die();
    
    if (!file_exists($resize_absolute_path)) {
      throw new HttpException(404, "Not found");
    }

    // Build destination path
    $destination_parts= explode("/", $pathInfo);

    $destination_filename = array_pop($destination_parts);
    
//    \yii\helpers\VarDumper::dump($destination_parts, 10, true);
//    \yii\helpers\VarDumper::dump($destination_filename, 10, true);
//    die();

    $destination_dir = \Yii::getAlias('@webroot');
    foreach ($destination_parts as $part) {
      $destination_dir .= "/{$part}";
      if (!file_exists($destination_dir)) {
        mkdir($destination_dir, 0777);
        chmod($destination_dir, 0777);
      }
//      echo $destination_dir."<br>";
    }
    
//    die('yay');
    
    $extension=$this->getImageExtension($destination_filename);
    
    $filterClass=$filters[$filterName];
    $filter=new $filterClass;
    $filter->run($resize_absolute_path, $destination_dir . "/" . $destination_filename)->show($extension);
    
//    return 'test';

//    // Resize and save picture
//    $image = Yii::app()->image->load($resize_absolute_path);
//    $resize_method = $rules[$filterName];
//    $cmd = "\$image->{$resize_method};";
//    eval($cmd);
//    $image->save($destination_dir . "/" . $destination_filename, 0644, true);
//    $image->render();
//        return $this->render('index');
  }

  private function resizeCheckAllowedPath($resize_path) {
    $allowed_paths = \Yii::$app->getModule('resizer')->allowedPaths;
    
    foreach ($allowed_paths as $path) {
      if (strpos($resize_path, $path) === 0) {
        return true;
      }
    }
    return false;
  }
  
  private function getImageExtension($filename) {
    $extension=array_pop(explode('.',$filename));
    $extension= strtolower($extension);
    if ($extension=='jpeg') {
      $extension='jpg';
    }
    return $extension;
  }

}
_pages/LoginPage.php000066600000001303151456477640010404 0ustar00<?php

namespace tests\codeception\common\_pages;

use yii\codeception\BasePage;

/**
 * Represents loging page
 * @property \codeception_frontend\AcceptanceTester|\codeception_frontend\FunctionalTester|\codeception_backend\AcceptanceTester|\codeception_backend\FunctionalTester $actor
 */
class LoginPage extends BasePage
{
    public $route = 'site/login';

    /**
     * @param string $username
     * @param string $password
     */
    public function login($username, $password)
    {
        $this->actor->fillField('input[name="LoginForm[username]"]', $username);
        $this->actor->fillField('input[name="LoginForm[password]"]', $password);
        $this->actor->click('login-button');
    }
}
_bootstrap.php000066600000001044151456477640007457 0ustar00<?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', dirname(dirname(dirname(__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');

// set correct script paths
$_SERVER['SERVER_NAME'] = 'localhost';
$_SERVER['SERVER_PORT'] = '80';

Yii::setAlias('@tests', dirname(dirname(__DIR__)));
_support/FixtureHelper.php000066600000003432151456477640011747 0ustar00<?php

namespace tests\codeception\common\_support;

use tests\codeception\common\fixtures\UserFixture;
use Codeception\Module;
use yii\test\FixtureTrait;
use yii\test\InitDbFixture;

/**
 * This helper is used to populate the database with needed fixtures before any tests are run.
 * In this example, the database is populated with the demo login user, which is used in acceptance
 * and functional tests.  All fixtures will be loaded before the suite is started and unloaded after it
 * completes.
 */
class FixtureHelper extends Module
{

    /**
     * Redeclare visibility because codeception includes all public methods that do not start with "_"
     * and are not excluded by module settings, in actor class.
     */
    use FixtureTrait {
        loadFixtures as protected;
        fixtures as protected;
        globalFixtures as protected;
        unloadFixtures as protected;
        getFixtures as protected;
        getFixture as protected;
    }

    /**
     * Method called before any suite tests run. Loads User fixture login user
     * to use in acceptance and functional tests.
     * @param array $settings
     */
    public function _beforeSuite($settings = [])
    {
        $this->loadFixtures();
    }

    /**
     * Method is called after all suite tests run
     */
    public function _afterSuite()
    {
        $this->unloadFixtures();
    }

    /**
     * @inheritdoc
     */
    public function globalFixtures()
    {
        return [
            InitDbFixture::className(),
        ];
    }

    /**
     * @inheritdoc
     */
    public function fixtures()
    {
        return [
            'user' => [
                'class' => UserFixture::className(),
                'dataFile' => '@tests/codeception/common/fixtures/data/init_login.php',
            ],
        ];
    }
}
templates/fixtures/user.php000066600000000706151456477640012134 0ustar00<?php
/**
 * @var $faker \Faker\Generator
 * @var $index integer
 */

$security = Yii::$app->getSecurity();

return [
    'username' => $faker->userName,
    'email' => $faker->email,
    'auth_key' => $security->generateRandomString(),
    'password_hash' => $security->generatePasswordHash('password_' . $index),
    'password_reset_token' => $security->generateRandomString() . '_' . time(),
    'created_at' => time(),
    'updated_at' => time(),
];
_output/.gitignore000066600000000016151456477640010257 0ustar00*
!.gitignore
unit/_bootstrap.php000066600000000104151456477640010432 0ustar00<?php
// Here you can initialize variables that will for your tests
unit/fixtures/data/models/user.php000066600000000676151456477640013317 0ustar00<?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',
    ],
];
unit/DbTestCase.php000066600000000306151456477640010243 0ustar00<?php

namespace tests\codeception\common\unit;

/**
 * @inheritdoc
 */
class DbTestCase extends \yii\codeception\DbTestCase
{
    public $appConfig = '@tests/codeception/config/common/unit.php';
}
unit/models/LoginFormTest.php000066600000005067151456477640012312 0ustar00<?php

namespace tests\codeception\common\unit\models;

use Yii;
use tests\codeception\common\unit\DbTestCase;
use Codeception\Specify;
use common\models\LoginForm;
use tests\codeception\common\fixtures\UserFixture;

/**
 * Login form test
 */
class LoginFormTest extends DbTestCase
{

    use Specify;

    public function setUp()
    {
        parent::setUp();

        Yii::configure(Yii::$app, [
            'components' => [
                'user' => [
                    'class' => 'yii\web\User',
                    'identityClass' => 'common\models\User',
                ],
            ],
        ]);
    }

    protected function tearDown()
    {
        Yii::$app->user->logout();
        parent::tearDown();
    }

    public function testLoginNoUser()
    {
        $model = new LoginForm([
            'username' => 'not_existing_username',
            'password' => 'not_existing_password',
        ]);

        $this->specify('user should not be able to login, when there is no identity', function () use ($model) {
            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',
        ]);

        $this->specify('user should not be able to login with wrong password', function () use ($model) {
            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',
        ]);

        $this->specify('user should be able to login with correct credentials', function () use ($model) {
            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();
        });
    }

    /**
     * @inheritdoc
     */
    public function fixtures()
    {
        return [
            'user' => [
                'class' => UserFixture::className(),
                'dataFile' => '@tests/codeception/common/unit/fixtures/data/models/user.php'
            ],
        ];
    }
}
unit/TestCase.php000066600000000302151456477640007771 0ustar00<?php

namespace tests\codeception\common\unit;

/**
 * @inheritdoc
 */
class TestCase extends \yii\codeception\TestCase
{
    public $appConfig = '@tests/codeception/config/common/unit.php';
}
fixtures/data/init_login.php000066600000000662151456477640012225 0ustar00<?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',
    ],
];
fixtures/UserFixture.php000066600000000305151456477640011440 0ustar00<?php

namespace tests\codeception\common\fixtures;

use yii\test\ActiveFixture;

/**
 * User fixture
 */
class UserFixture extends ActiveFixture
{
    public $modelClass = 'common\models\User';
}
codeception.yml000066600000000412151456477640007607 0ustar00namespace: tests\codeception\common
actor: Tester
paths:
    tests: .
    log: _output
    data: _data
    helpers: _support
settings:
    bootstrap: _bootstrap.php
    suite_class: \PHPUnit_Framework_TestSuite
    colors: true
    memory_limit: 1024M
    log: true
.gitignore000066600000000215151456477640006561 0ustar00# these files are auto generated by codeception build
/unit/UnitTester.php
/functional/FunctionalTester.php
/acceptance/AcceptanceTester.php
unit.suite.yml000066600000000230151456477640007420 0ustar00# Codeception Test Suite Configuration

# suite for unit (internal) tests.
# RUN `build` COMMAND AFTER ADDING/REMOVING MODULES.

class_name: UnitTester
unit.php000066600000000620151456500570006246 0ustar00<?php
/**
 * Application config for common unit tests
 */
return yii\helpers\ArrayHelper::merge(
    require(YII_APP_BASE_PATH . '/common/config/main.php'),
    require(YII_APP_BASE_PATH . '/common/config/main-local.php'),
    require(dirname(__DIR__) . '/config.php'),
    require(dirname(__DIR__) . '/unit.php'),
    [
        'id' => 'app-common',
        'basePath' => dirname(__DIR__),
    ]
);

Anon7 - 2022
AnonSec Team