Skip to content

Commit

Permalink
New Version
Browse files Browse the repository at this point in the history
  • Loading branch information
peter-tharwat committed Jan 28, 2022
1 parent 3527d9e commit b0b3495
Show file tree
Hide file tree
Showing 595 changed files with 41,366 additions and 297 deletions.
6 changes: 5 additions & 1 deletion app/Exceptions/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ class Handler extends ExceptionHandler
public function register()
{
$this->reportable(function (Throwable $e) {
//
\MainHelper::make_error_report([
'error'=>$e->getMessage(),
'error_code'=>500,
'details'=>"Error : ".$e->getFile()." Line : ". $e->getLine() . json_encode(request()->instance())
]);
});
}
}
85 changes: 59 additions & 26 deletions app/Helpers/MainHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,36 +34,69 @@ public function notify_user(
}
}

public static function generate()
{
$failCount = 0;
do {
$redVector = rand(0, 1);
$greenVector = rand(0, 1);
$blueVector = rand(!($redVector || $greenVector), (int)(($redVector xor $greenVector) || !($redVector || $greenVector)));
$quantiles = floor((self::$upperLimit - self::$lowerLimit) / self::$colorGap);

$red = $redVector * (rand(0, $quantiles) * self::$colorGap + self::$lowerLimit);
$green = $greenVector * (rand(0, $quantiles) * self::$colorGap + self::$lowerLimit);
$blue = $blueVector * (rand(0, $quantiles) * self::$colorGap + self::$lowerLimit);
$failCount++;
} while (isset(self::$generated["$red,$green,$blue"]) && $failCount < 1000);

return self::rgb($red, $green, $blue);
public function make_error_report(
$options=[]
){
$options = array_merge([
'error'=>"",
'error_code'=>"",
'details'=>json_encode(request()->instance())
],$options);
\App\Models\ReportError::create([
'user_id'=>(auth()->check()?auth()->user()->id:null),
'title'=>$options['error'],
'code'=>$options['error_code'],
'url'=>url()->previous(),
'ip'=>\UserSystemInfoHelper::get_ip(),
'user_agent'=>request()->header('User-Agent'),
'request'=>json_encode(request()->all()),
'description'=>$options['details']
]);
}
protected static function rgb($red, $green, $blue)
public static function binaryToString($binary)
{
$red = base_convert($red, 10, 16);
$red = str_pad($red, 2, '0', STR_PAD_LEFT);

$green = base_convert($green, 10, 16);
$green = str_pad($green, 2, '0', STR_PAD_LEFT);

$blue = base_convert($blue, 10, 16);
$blue = str_pad($blue, 2, '0', STR_PAD_LEFT);
$binaries = explode(' ', $binary);

$string = null;
foreach ($binaries as $binary) {
$string .= pack('H*', dechex(bindec($binary)));
}

return $string;
}

return '#' . $red . $green . $blue;
public static function focus_urls($string)
{
$url_regex = '~(http|ftp)s?://[a-z0-9.-]+\.[a-z]{2,7}(/\S*)?~i';
return preg_replace($url_regex, " <a href='$0' target='_blank' rel='nofollow' style='font-family: inherit;'>$0</a> ",urldecode(htmlspecialchars($string)));
}

public static function slug($string){
$t = $string;
$specChars = array(
' ' => '-', '!' => '', '"' => '',
'#' => '', '$' => '', '%' => '',
'&amp;' => '','&nbsp;' => '',
'\'' => '', '(' => '',
')' => '', '*' => '', '+' => '',
',' => '', '' => '', '.' => '',
'/-' => '', ':' => '', ';' => '',
'<' => '', '=' => '', '>' => '',
'?' => '', '@' => '', '[' => '',
'\\' => '', ']' => '', '^' => '',
'_' => '', '`' => '', '{' => '',
'|' => '', '}' => '', '~' => '',
'-----' => '-', '----' => '-', '---' => '-',
'/' => '', '--' => '-', '/_' => '-',
);
foreach ($specChars as $k => $v) {
$t = str_replace($k, $v, $t);
}

return substr($t,0,230);
}




}
39 changes: 34 additions & 5 deletions app/Helpers/UserSystemInfoHelper.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,37 @@
<?php

/**
*
*/
namespace App\Helpers;


class UserSystemInfoHelper
{
private static function get_user_agent(){






public $countries = [
"SA" =>'السعودية',"ET" =>'إثيوبيا',"AZ" =>'أذربيجان',"AM" =>'أرمينيا',"AW" =>'أروبا',"ER" =>'إريتريا',"ES" =>'أسبانيا',"AU" =>'أستراليا',"EE" =>'إستونيا',"IL" =>'فلسطين',"AF" =>'أفغانستان',"IO" =>'إقليم المحيط الهندي البريطاني',"EC" =>'إكوادور',"AR" =>'الأرجنتين',"JO" =>'الأردن',"AE" =>'الإمارات',"AL" =>'ألبانيا',"BR" =>'البرازيل',"PT" =>'البرتغال',"BA" =>'البوسنة والهرسك',"GA" =>'الجابون',"DZ" =>'الجزائر',"DK" =>'الدانمارك',"CV" =>'الرأس الأخضر',"PS" =>'فلسطين',"SV" =>'السلفادور',"SN" =>'السنغال',"SD" =>'السودان',"SE" =>'السويد',"SO" =>'الصومال',"CN" =>'الصين',"IQ" =>'العراق',"PH" =>'الفلبين',"CM" =>'الكاميرون',"CG" =>'الكونغو',"CD" =>'الكونغو (جمهورية الكونغو الديمقراطية)',"KW" =>'الكويت',"DE" =>'ألمانيا',"HU" =>'المجر',"MA" =>'المغرب',"MX" =>'المكسيك',"UK" =>'المملكة المتحدة',"TF" =>'المناطق الفرنسية الجنوبية ومناطق انتراكتيكا',"NO" =>'النرويج',"AT" =>'النمسا',"NE" =>'النيجر',"IN" =>'الهند',"US" =>'الولايات المتحدة',"JP" =>'اليابان',"YE" =>'اليمن',"GR" =>'اليونان',"AQ" =>'أنتاركتيكا',"AG" =>'أنتيغوا وبربودا',"AD" =>'أندورا',"ID" =>'إندونيسيا',"AO" =>'أنغولا',"AI" =>'أنغويلا',"UY" =>'أوروجواي',"UZ" =>'أوزبكستان',"UG" =>'أوغندا',"UA" =>'أوكرانيا',"IR" =>'إيران',"IE" =>'أيرلندا',"IS" =>'أيسلندا',"IT" =>'إيطاليا',"PG" =>'بابوا-غينيا الجديدة',"PY" =>'باراجواي',"BB" =>'باربادوس',"PK" =>'باكستان',"PW" =>'بالاو',"BM" =>'برمودا',"BN" =>'بروناي',"BE" =>'بلجيكا',"BG" =>'بلغاريا',"BD" =>'بنجلاديش',"PA" =>'بنما',"BJ" =>'بنين',"BT" =>'بوتان',"BW" =>'بوتسوانا',"PR" =>'بورتو ريكو',"BF" =>'بوركينا فاسو',"BI" =>'بوروندي',"PL" =>'بولندا',"BO" =>'بوليفيا',"PF" =>'بولينزيا الفرنسية',"PE" =>'بيرو',"BY" =>'بيلاروس',"BZ" =>'بيليز',"TH" =>'تايلاند',"TW" =>'تايوان',"TM" =>'تركمانستان',"TR" =>'تركيا',"TT" =>'ترينيداد وتوباجو',"TD" =>'تشاد',"CL" =>'تشيلي',"TZ" =>'تنزانيا',"TG" =>'توجو',"TV" =>'توفالو',"TK" =>'توكيلاو',"TO" =>'تونجا',"TN" =>'تونس',"TP" =>'تيمور الشرقية (تيمور الشرقية)',"JM" =>'جامايكا',"GM" =>'جامبيا',"GI" =>'جبل طارق',"GL" =>'جرينلاند',"AN" =>'جزر الأنتيل الهولندية',"PN" =>'جزر البتكارين',"BS" =>'جزر البهاما',"VG" =>'جزر العذراء البريطانية',"VI" =>'جزر العذراء، الولايات المتحدة',"KM" =>'جزر القمر',"CC" =>'جزر الكوكوس (كيلين)',"MV" =>'جزر المالديف',"TC" =>'جزر تركس وكايكوس',"AS" =>'جزر ساموا الأمريكية',"SB" =>'جزر سولومون',"FO" =>'جزر فايرو',"UM" =>'جزر فرعية تابعة للولايات المتحدة',"FK" =>'جزر فوكلاند (أيزلاس مالفيناس)',"FJ" =>'جزر فيجي',"KY" =>'جزر كايمان',"CK" =>'جزر كوك',"MH" =>'جزر مارشال',"MP" =>'جزر ماريانا الشمالية',"CX" =>'جزيرة الكريسماس',"BV" =>'جزيرة بوفيه',"IM" =>'جزيرة مان',"NF" =>'جزيرة نورفوك',"HM" =>'جزيرة هيرد وجزر ماكدونالد',"CF" =>'جمهورية أفريقيا الوسطى',"CZ" =>'جمهورية التشيك',"DO" =>'جمهورية الدومينيكان',"ZA" =>'جنوب أفريقيا',"GT" =>'جواتيمالا',"GP" =>'جواديلوب',"GU" =>'جوام',"GE" =>'جورجيا',"GS" =>'جورجيا الجنوبية وجزر ساندويتش الجنوبية',"GY" =>'جيانا',"GF" =>'جيانا الفرنسية',"DJ" =>'جيبوتي',"JE" =>'جيرسي',"GG" =>'جيرنزي',"VA" =>'دولة الفاتيكان',"DM" =>'دومينيكا',"RW" =>'رواندا',"RU" =>'روسيا',"RO" =>'رومانيا',"RE" =>'ريونيون',"ZM" =>'زامبيا',"ZW" =>'زيمبابوي',"WS" =>'ساموا',"SM" =>'سان مارينو',"PM" =>'سانت بيير وميكولون',"VC" =>'سانت فينسنت وجرينادينز',"KN" =>'سانت كيتس ونيفيس',"LC" =>'سانت لوشيا',"SH" =>'سانت هيلينا',"ST" =>'ساوتوماي وبرينسيبا',"SJ" =>'سفالبارد وجان ماين',"SK" =>'سلوفاكيا',"SI" =>'سلوفينيا',"SG" =>'سنغافورة',"SZ" =>'سوازيلاند',"SY" =>'سوريا',"SR" =>'سورينام',"CH" =>'سويسرا',"SL" =>'سيراليون',"LK" =>'سيريلانكا',"SC" =>'سيشل',"RS" =>'صربيا',"TJ" =>'طاجيكستان',"OM" =>'عمان',"GH" =>'غانا',"GD" =>'غرينادا',"GN" =>'غينيا',"GQ" =>'غينيا الاستوائية',"GW" =>'غينيا بيساو',"VU" =>'فانواتو',"FR" =>'فرنسا',"VE" =>'فنزويلا',"FI" =>'فنلندا',"VN" =>'فيتنام',"CY" =>'قبرص',"QA" =>'قطر',"KG" =>'قيرقيزستان',"KZ" =>'كازاخستان',"NC" =>'كاليدونيا الجديدة',"KH" =>'كامبوديا',"HR" =>'كرواتيا',"CA" =>'كندا',"CU" =>'كوبا',"CI" =>'كوت ديفوار (ساحل العاج)',"KR" =>'كوريا',"KP" =>'كوريا الشمالية',"CR" =>'كوستاريكا',"CO" =>'كولومبيا',"KI" =>'كيريباتي',"KE" =>'كينيا',"LV" =>'لاتفيا',"LA" =>'لاوس',"LB" =>'لبنان',"LI" =>'لختنشتاين',"LU" =>'لوكسمبورج',"LY" =>'ليبيا',"LR" =>'ليبيريا',"LT" =>'ليتوانيا',"LS" =>'ليسوتو',"MQ" =>'مارتينيك',"MO" =>'ماكاو',"FM" =>'ماكرونيزيا',"MW" =>'مالاوي',"MT" =>'مالطا',"ML" =>'مالي',"MY" =>'ماليزيا',"YT" =>'مايوت',"MG" =>'مدغشقر',"EG" =>'مصر',"MK" =>'مقدونيا، جمهورية يوغوسلافيا السابقة',"BH" =>'البحرين',"MN" =>'منغوليا',"MR" =>'موريتانيا',"MU" =>'موريشيوس',"MZ" =>'موزمبيق',"MD" =>'مولدوفا',"MC" =>'موناكو',"MS" =>'مونتسيرات',"ME" =>'مونتينيغرو',"MM" =>'ميانمار',"NA" =>'ناميبيا',"NR" =>'ناورو',"NP" =>'نيبال',"NG" =>'نيجيريا',"NI" =>'نيكاراجوا',"NU" =>'نيوا',"NZ" =>'نيوزيلندا',"HT" =>'هايتي',"HN" =>'هندوراس',"NL" =>'هولندا',"HK" =>'هونغ كونغ SAR',"WF" =>'واليس وفوتونا',"GB" =>'المملكة المتحدة'
];
public function get_country_from_ip($ip)
{
try{
$location = \Location::get($ip);
$country=$this->countries[$location->countryCode];
return [
'country'=>$country,
'country_code'=>$location->countryCode
];
}catch(\Exception $e){ }
return [
'country'=>"غير محدد",
'country_code'=>"404"
];

}


private static function get_user_agent(){
return $_SERVER['HTTP_USER_AGENT'];
}

Expand All @@ -25,11 +50,14 @@ public static function get_ip(){
$ipaddress = $_SERVER['HTTP_FORWARDED'];
else if(isset($_SERVER['REMOTE_ADDR']))
$ipaddress = $_SERVER['REMOTE_ADDR'];
else if(request()->ip()!=null)
$ipaddress = request()->ip();
else
$ipaddress = 'UNKNOWN';
return $ipaddress;

}


public static function get_os(){

Expand Down Expand Up @@ -164,4 +192,5 @@ public static function get_device(){
}

}

}
112 changes: 100 additions & 12 deletions app/Http/Controllers/ArticleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,23 @@
namespace App\Http\Controllers;

use App\Models\Article;
use App\Models\Category;
use Illuminate\Http\Request;

class ArticleController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()


public function index(Request $request)
{
return view('admin.articles.index');
$articles = Article::where(function($q)use($request){
if($request->id!=null)
$q->where('id',$request->id);
if($request->q!=null)
$q->where('title','LIKE','%'.$request->q.'%')->orWhere('description','LIKE','%'.$request->q.'%');
})->orderBy('id','DESC')->paginate();

return view('admin.articles.index',compact('articles'));
}

/**
Expand All @@ -24,7 +29,8 @@ public function index()
*/
public function create()
{
return view('admin.articles.create');
$categories= Category::orderBy('id','DESC')->get();
return view('admin.articles.create',compact('categories'));
}

/**
Expand All @@ -35,7 +41,45 @@ public function create()
*/
public function store(Request $request)
{
//
$request->merge([
'slug'=>\MainHelper::slug($request->slug)
]);

$request->validate([
'slug'=>"required|max:190|unique:articles,slug",
'category_id'=>"required|exists:categories,id",
'is_featured'=>"required|in:0,1",
'title'=>"required|max:190",
'description'=>"nullable|max:100000",
'meta_description'=>"nullable|max:10000",
]);
$article = Article::create([
'user_id'=>auth()->user()->id,
"slug"=>$request->slug,
"category_id"=>$request->category_id,
"is_featured"=>$request->is_featured==1?1:0,
"title"=>$request->title,
"description"=>$request->description,
"meta_description"=>$request->meta_description,
]);
if($request->hasFile('main_image')){
$file = $this->store_file([
'source'=>$request->main_image,
'validation'=>"image",
'path_to_save'=>'/uploads/articles/',
'type'=>'ARTICLE',
'user_id'=>\Auth::user()->id,
'resize'=>[500,1000],
'small_path'=>'small/',
'visibility'=>'PUBLIC',
'file_system_type'=>env('FILESYSTEM_DRIVER'),
/*'watermark'=>true,*/
'compress'=>'auto'
]);
$article->update(['main_image'=>$file['filename']]);
}
notify()->success('تم إضافة المقال بنجاح','عملية ناجحة');
return redirect()->route('admin.articles.index');
}

/**
Expand All @@ -57,7 +101,9 @@ public function show(Article $article)
*/
public function edit(Article $article)
{
//
if(!auth()->user()->has_access_to('update',$article))abort(403);
$categories= Category::orderBy('id','DESC')->get();
return view('admin.articles.edit',compact('article','categories'));
}

/**
Expand All @@ -69,7 +115,46 @@ public function edit(Article $article)
*/
public function update(Request $request, Article $article)
{
//
$request->merge([
'slug'=>\MainHelper::slug($request->slug)
]);

if(!auth()->user()->has_access_to('update',$article))abort(403);
$request->validate([
'slug'=>"required|max:190|unique:articles,slug,".$article->id,
'category_id'=>"required|exists:categories,id",
'is_featured'=>"required|in:0,1",
'title'=>"required|max:190",
'description'=>"nullable|max:100000",
'meta_description'=>"nullable|max:10000",
]);
$article->update([
'user_id'=>auth()->user()->id,
"slug"=>$request->slug,
"category_id"=>$request->category_id,
"is_featured"=>$request->is_featured==1?1:0,
"title"=>$request->title,
"description"=>$request->description,
"meta_description"=>$request->meta_description,
]);
if($request->hasFile('main_image')){
$file = $this->store_file([
'source'=>$request->main_image,
'validation'=>"image",
'path_to_save'=>'/uploads/articles/',
'type'=>'ARTICLE',
'user_id'=>\Auth::user()->id,
'resize'=>[500,1000],
'small_path'=>'small/',
'visibility'=>'PUBLIC',
'file_system_type'=>env('FILESYSTEM_DRIVER'),
/*'watermark'=>true,*/
'compress'=>'auto'
]);
$article->update(['main_image'=>$file['filename']]);
}
notify()->success('تم تحديث المقال بنجاح','عملية ناجحة');
return redirect()->route('admin.articles.index');
}

/**
Expand All @@ -80,6 +165,9 @@ public function update(Request $request, Article $article)
*/
public function destroy(Article $article)
{
//
if(!auth()->user()->has_access_to('delete',$article))abort(403);
$article->delete();
notify()->success('تم حذف المقال بنجاح','عملية ناجحة');
return redirect()->route('admin.articles.index');
}
}
Loading

0 comments on commit b0b3495

Please sign in to comment.