Skip to content

Commit

Permalink
Merge pull request #31 from b4oshany/production
Browse files Browse the repository at this point in the history
closed #30 - Added an image uploader and improve vecni backend.
  • Loading branch information
b4oshany committed Dec 22, 2014
2 parents f753889 + cbed154 commit b3ea428
Show file tree
Hide file tree
Showing 29 changed files with 1,265 additions and 212 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@
*.DS_Store
*.swp
.DS_Store
app/configs/settings.ini.php
app/static/css/gen/*
25 changes: 14 additions & 11 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
[submodule "app/plugins/twig"]
path = app/plugins/twig
url = git://github.com/fabpot/Twig.git
path = app/plugins/twig
url = git://github.com/fabpot/Twig.git
[submodule "app/plugins/mailer"]
path = app/plugins/mailer
url = [email protected]:PHPMailer/PHPMailer.git
[submodule "app/plugins/less"]
path = app/plugins/less
url = [email protected]:leafo/lessphp.git
path = app/plugins/mailer
url = [email protected]:PHPMailer/PHPMailer.git
[submodule "app/plugins/error"]
path = app/plugins/error
url = [email protected]:JosephLenton/PHP-Error.git
path = app/plugins/error
url = [email protected]:JosephLenton/PHP-Error.git
[submodule "app/plugins/less"]
path = app/plugins/less
url = [email protected]:leafo/lessphp.git
[submodule "app/static/ext/sweetalert"]
path = app/static/ext/sweetalert
url = [email protected]:t4t5/sweetalert.git
path = app/static/ext/sweetalert
url = [email protected]:t4t5/sweetalert.git
[submodule "app/static/ext/jsuploader"]
path = app/static/ext/jsuploader
url = [email protected]:b4oshany/AJAX-Uploader.git
1 change: 1 addition & 0 deletions .htaccess
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ RewriteEngine On
# Redirect requests to index.php
RewriteCond %{REQUEST_URI} !=index\.php
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* index.php?%{QUERY_STRING} [L]
43 changes: 34 additions & 9 deletions app/controller/user/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
namespace controller\user;
use libs\vecni\Object;
use libs\mysql\PDOConnector;
use libs\vecni\Vecni;
use libs\vecni\Vecni as app;

/**
* @package user
Expand All @@ -21,13 +21,38 @@
*/

class User extends Object{
public $user_id; // username of user
public $first_name; // user first name
public $last_name; // user last name
public $email; // user email
public $is_login; // user login status
public $status; // user registration status
public $dob; // user date of birth
public $user_id; // id of user.
public $first_name; // user first name.
public $last_name; // user last name.
public $email; // user email.
public $is_login; // user login status.
public $status; // user registration status.
public $dob; // user date of birth.
public $profile_pic; // user profile picture.

/**
* Return the full name of the user.
* @return string - full name, i.e. first and last name of the user.
*/
public function get_fullname(){
return "$this->first_name $this->last_name";
}

/**
* Return the url of the user profile picture.
* @return string - url of picture.
*/
public function get_profile_pic(){
if(!empty($this->profile_pic)){
return $this->profile_pic;
}
return self::get_default_profile_pic();
}


public static function get_default_profile_pic(){
return "static/src/img/icons/user.png";
}

/**
* Login user with their normal user account
Expand Down Expand Up @@ -124,7 +149,7 @@ public static function start_session(array $data = null){
*/
public static function get_current_user(){
if(isset($_SESSION['uid'])){
return self::object_cast($_SESSION['uid']);
return self::quick_cast($_SESSION['uid']);
}else{
return null;
}
Expand Down
27 changes: 27 additions & 0 deletions app/libs/mysql/MysqlAutoloader.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php
if (!function_exists('autoload')) {
function autoload($className){
$module_container = "etc".DIRECTORY_SEPARATOR;
$module = $className;
$className = ltrim($className, '\\');
$fileName = '';
$namespace = '';
if ($lastNsPos = strrpos($className, '\\')) {
$namespace = substr($className, 0, $lastNsPos);
$className = substr($className, $lastNsPos + 1);
$fileName = str_replace('\\', DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR;
}
$fileName .= $className.'.php';
$fileName = $module_container.$fileName;
for($i = 0; $i < 5; $i++){
//echo $fileName."<br/>";
if(file_exists($fileName)){
require_once $fileName;
break;
}else
$fileName = "..".DIRECTORY_SEPARATOR.$fileName;
}
}
spl_autoload_register('\autoload');
}
?>
2 changes: 1 addition & 1 deletion app/libs/mysql/PDOConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require_once "MysqlAutoloader.php";
class PDOConnector{
//privilige user for the database
protected static $database_user;
public static $database_user;
protected static $database_pass;

//set the database to use
Expand Down
100 changes: 100 additions & 0 deletions app/libs/scifile/File.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
<?php
namespace libs\scifile;

class File{
protected $data_file, $accept_types, $type, $min_size, $max_size;
protected static $relative_storage = null;
protected static $absolute_storage = null;
public static $base = null;
protected $name, $title, $extension;

public function __construct($data_file, $title=""){
$this->data_file = $data_file;
if(!empty($this->data_file)){
$this->name = $this->getName();
$this->extension = $this->getExtension();
}
$this->title = $title;
}

/**
* Set storage location of images.
* @param string $absolute - absolute path to storage folder.
* @param string $relative - relative path to storage folder base on the app root.
*/
public static function register_location($absolute, $relative=null){
self::$relative_storage = $relative;
self::$absolute_storage = $absolute;
self::mkdir(self::$absolute_storage);
}

/**
* Builds a file path with the appropriate directory separator.
* @param string $segments,... unlimited number of path segments
* @return string Path
*/
public static function build_path() {
return join(DIRECTORY_SEPARATOR, func_get_args());
}

/**
* Make director recursively, where applicable.
* @param string $dir - Path to make if not exists. It is Default to empty string.
* @return bool - True if the directory has been created or already exists, else
* false.
*/
public static function mkdir($dir=""){
if(!$dir){
$dir = self::$absolute_storage;
}
if(!is_dir($dir)){
return mkdir($dir, 0775, true);
}
return true;
}

/**
* Get storage location of images.
* @param string $type - type of storage to get, i.e. absolute or relative path.
*/
public static function getStorage($type="absolute"){
if($type=="absolute")
return self::$absoluteStorage;
return self::$relativeStorage;
}

/**
* Get the name of the file.
* @return string - name of the file.
*/
public function getName(){
if(strripos($this->data_file,'/') != false){
$name = substr($this->data_file, strripos($this->data_file,'/')+1, (strlen($this->data_file) - strripos($this->data_file,'.') + 1));
}else{
$name = substr($this->data_file, 0, strripos($this->data_file,'.'));
}
return $name;
}

/**
* Get the file extension.
* @return string - file extension.
*/
public function getExtension(){
return strtolower(strrchr($this->data_file, '.'));
}

/**
* Change from absolute to relative path based on the app root.
* @param string $path - Absolute path of file/folder.
* @return string - Relative path of file/folder.
*/
public static function getRelativeFromAbsolute($path){
if(!empty(self::$base)){
return str_replace(self::$base, "", $path);
}
return $path;
}
}

?>
33 changes: 33 additions & 0 deletions app/libs/scifile/Image.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php
namespace libs\scifile;

class Image extends File{
public $image_id;
public $description;
public $category;
public $title;
public $date_created;
public $thumb_url;
public $photo_url;

private $thumbnail_extension = "-resized";

public function get_location($thumbnail=false){
if($thumbnail)
return $this->thumb_url;
return $this->photo_url;
}

public function get($format="xml"){
$thumbnail = $this->get_location(true);
$fullsize = $this->get_location(false);
$name = $this->name;
$title = $this->title;
switch($format){
default:
return "<img src='$thumbnail' data-target='$fullsize' alt='$title' title='$title' />";
}
}
}

?>
Loading

0 comments on commit b3ea428

Please sign in to comment.