File: /home/safarimaris/home/safarimaris/console/controllers/SystemController.php
<?php
namespace console\controllers;
use common\components\UserRole;
use common\models\User;
use Yii;
use yii\console\Controller;
use yii\imagine\Image;
class SystemController extends Controller
{
public function actionCheck301()
{
$xml = simplexml_load_file('http://safarimaris.com/sitemap.xml');
foreach ($xml as $x) {
$oldUrl = (string)$x->loc;
if (strpos($oldUrl, 'http://safarimaris.com/yachts/') !== 0) {
continue;
}
$redirectUrl = $this->get_web_page(str_replace('.com', '.lof', $oldUrl));
//echo $oldUrl."\n".$redirectUrl."\n";
if ($oldUrl == str_replace('.lof', '.com', $redirectUrl)) {
echo $redirectUrl."\n";
//exit;
}
}
}
protected function get_web_page( $url )
{
$options = array(
CURLOPT_RETURNTRANSFER => true, // return web page
CURLOPT_HEADER => true, // return headers
CURLOPT_FOLLOWLOCATION => true, // follow redirects
CURLOPT_ENCODING => "", // handle all encodings
CURLOPT_USERAGENT => "spider", // who am i
CURLOPT_AUTOREFERER => true, // set referer on redirect
CURLOPT_CONNECTTIMEOUT => 120, // timeout on connect
CURLOPT_TIMEOUT => 120, // timeout on response
CURLOPT_MAXREDIRS => 10, // stop after 10 redirects
CURLOPT_MAXREDIRS => 10, // stop after 10 redirects
);
$ch = curl_init( $url );
curl_setopt_array( $ch, $options );
$content = curl_exec( $ch );
$err = curl_errno( $ch );
$errmsg = curl_error( $ch );
$header = curl_getinfo( $ch, CURLINFO_EFFECTIVE_URL );
//curl_getinfo($ch,CURLINFO_EFFECTIVE_URL )
curl_close( $ch );
//$header['errno'] = $err;
//$header['errmsg'] = $errmsg;
//$header['content'] = $content;
return $header;
}
public function actionImg60()
{
$this->img60(Yii::getAlias('@web').'/images/country/');
$this->img60(Yii::getAlias('@web').'/images/entity/');
$this->img60(Yii::getAlias('@web').'/images/entity_boat/');
$this->img60(Yii::getAlias('@web').'/images/product/');
$this->img60(Yii::getAlias('@web').'/images/site/');
}
function img60($dir)
{
echo $dir."\n";
if($handler = opendir($dir)) {
$i = 0;
while (($sub = readdir($handler)) !== FALSE) {
if ($sub != "." && $sub != ".." && $sub != "Thumb.db") {
if(is_file($dir."/".$sub)) {
Image::getImagine()->open($dir."/".$sub)->save($dir."/".$sub, ['quality' => 60]);
}elseif(is_dir($dir."/".$sub)){
$this->img60($dir."/".$sub);
}
}
$i++;
echo "$i\r";
}
closedir($handler);
}
}
public function actionRegInstructor()
{
if (($handle = fopen(Yii::$app->basePath.'/data/instructor.csv', "r")) !== FALSE) {
$list = fgetcsv($handle, 10000, ";");
fclose($handle);
$fp = fopen(Yii::$app->basePath.'/data/instructor_password.csv', 'w');
$return = [];
$i = 1;
foreach ($list as $email) {
$i++;
echo $i." of ".sizeof($list)."\r";
$pwd = bin2hex(openssl_random_pseudo_bytes(4));
$user = User::findByUsername($email);
if (!$user) {
$user = new User();
}
$user->username = $email;
$user->email = $email;
$user->role = UserRole::INSTRUCTOR;
$user->setPassword($pwd);
$user->generateAuthKey();
$user->save();
fputcsv($fp, [$email, $pwd], ';');
array_push($return, [$email, $pwd]);
}
fclose($fp);
}
}
}