/**
  * validateAddPortfolio
  *
  * Validate new portfolio
  * @param($_POST)
  * @return(boolean)
  */
 public function validateAddPortfolio()
 {
     # get the modal
     $oPortfolio = singleton::getInstance('Portfolio');
     # the slug
     $page_slug = $_POST['page_slug'];
     # create empty error
     $aErrors = array();
     if (strlen($_POST['portfolio_title']) >= 30) {
         $aErrors['title'] = true;
     }
     if (strlen($_POST['portfolio_description']) >= 1000) {
         $aErrors['description'] = true;
     }
     if (strlen($_POST['portfolio_github_link']) >= 100) {
         $aErrors['github'] = true;
     }
     if (strlen($_POST['portfolio_website_link']) >= 100) {
         $aErrors['portfolio_website_link'] = true;
     }
     if (strlen($_POST['portfolio_meta_title']) >= 100) {
         $aErrors['portfolio_meta_title'] = true;
     }
     if (strlen($_POST['portfolio_meta_keyword']) >= 1000) {
         $aErrors['portfolio_meta_title'] = true;
     }
     if (strlen($_POST['portfolio_meta_desc']) >= 2) {
         $aErrors['portfolio_meta_desc'] = true;
     }
     if (strlen($page_slug) >= 25) {
         $aErrors['page_slug_too_long'] = true;
     }
     # check regex
     if (!preg_match('/^[a-z0-9-]+$/', $page_slug)) {
         $aErrors['not_a_valid_regex'] = true;
     }
     # check if availble
     if (!$oPortfolio->checkSlugAvailable($page_slug)) {
         $aErrors['slug_not_available'] = true;
     }
     if ($aErrors) {
         return var_dump($aErrors);
     } else {
         return true;
     }
 }
 public static function getInstance($v4a8a08f09d37b73795649038408b5f33 = NULL)
 {
     return parent::getInstance(__CLASS__);
 }
Beispiel #3
0
 public static function getInstance()
 {
     return parent::getInstance(get_class());
 }
<?php

$oPortfolio = singleton::getInstance('Portfolio');
$oFile = singleton::getInstance('FileModel');
# get the portfolios amount
$countPortfolios = $oPortfolio->countPortfolios();
$oSmarty->assign('countPortfolios', $countPortfolios);
# get the users file amount
if ($oUser->isAdmin()) {
    $oSmarty->assign('countFiles', $oFile->countFiles($id = $oUser->getUserId(), $deleted = true));
} else {
    $oSmarty->assign('countFiles', $oFile->countFiles($id = $oUser->getUserId()));
}
writeln('');

$bookBorrower2->borrowBook();
writeln('BookBorrower2 asked to borrow the book');
writeln('BookBorrower2 Author and Title: ');
writeln($bookBorrower2->getAuthorAndTitle());
writeln('');

$bookBorrower1->returnBook();
writeln('BookBorrower1 returned the book');
writeln('');

$bookBorrower2->borrowBook();
writeln('BookBorrower2 Author and Title: ');
writeln($bookBorrower1->getAuthorAndTitle());
writeln('');

writeln('END TESTING SINGLETON PATTERN');

function writeln($line_in) {
	echo $line_in.'<br/>';
}
*/
$connect = singleton::getInstance();
$query = $connect->sendQuery("select * from polo");
var_dump($connect);
$connect2 = singleton::getInstance();
var_dump($connect2);
while ($row = $connect->fetchArray($query)) {
    echo $row["nom"] . "<br>";
}
 /**
  * count all the files a user have
  * if and id is givin in it will get them from a specific user otherwise it will get them from the current user
  * if we also want to count the deleted files we can assign true to also get them
  * @param(int)
  * @return(int)
  */
 public function countFiles($idFromSlug = null, $deleted = false)
 {
     $oUser = singleton::getInstance('User');
     # the query
     $query = 'SELECT count(*) as countFiles FROM 
               files LEFT JOIN users on users.id = files.users_id ';
     # if idFromSlug specified get them from the user id
     if ($idFromSlug) {
         $query .= ' WHERE users.id = ' . $idFromSlug;
     } else {
         $query .= ' WHERE users.id = ' . $oUser->getUserId();
     }
     # get deleted files?
     if ($deleted) {
         $query .= ' and files.deleted = 0 ';
     }
     echo $query;
     exit;
     # execute
     $oResult = $this->mysqli->query($query);
     # fetch it
     $result = parent::fetchResultAssoc($oResult);
     # and return
     return $result[0]['countFiles'];
 }
<?php

if (!$_FILES && !$_POST) {
    echo "No direct access allowed";
    exit;
}
header('Content-type: application/json');
if (!empty($_FILES)) {
    // Get the file classes necessary to handle this request
    $oFileCtrl = Singleton::getInstance('FileController');
    // Controller
    $oFile = Singleton::getInstance('FileModel');
    // Model
    $oUpload = singleton::getInstance('Upload');
    // Utility
    # get the user file quota limit and check if he didn't pass it if he did we quit :)
    if (!$oFile->getUserQuota()) {
        header('HTTP/1.1 500 Internal Server Error');
        header('Content-type: text/plain');
        $msg = "Quota limit reached";
        exit($msg);
    }
    # get the file properties in an array
    $aFileInfo = $oUpload->getFileProperties($_FILES);
    # the tmp file properties
    $sExtension = $aFileInfo['sFileExt'];
    $sTmpName = $aFileInfo['sTmp_name'];
    $iFilesize = $aFileInfo['iFileSize'];
    $sOrg_fileName = $aFileInfo['sFilename'];
    # check if the extension is allowed exit script if not
    //$bFileExtensionStatus = $oFile->checkExtension($sExtension);
 public function ValidateFinishForm()
 {
     # NO POST? exit
     if (!$_POST) {
         header('HTTP/1.1 500 Internal Server Error');
         header('Content-type: text/plain');
         $msg = "SORRY YOU CAN'T SUBMIT THIS FORM RIGHT NOW PLEASE COMEBACK LATER.";
         exit($msg);
     }
     $aErrors = array();
     # Load validation Module
     $oValidate = singleton::getInstance('Validation');
     # validate fields
     $oValidate->stringLength($_POST['first_name'], 3, 15);
     $oValidate->stringLength($_POST['last_name'], 3, 30);
     $oValidate->stringLength($_POST['facebook'], 0, 100);
     $oValidate->stringLength($_POST['instagram'], 0, 100);
     $oValidate->stringLength($_POST['twitter'], 0, 100);
     $oValidate->stringLength($_POST['website'], 0, 100);
     $oValidate->stringLength($_POST['linkedin'], 0, 100);
     # check firstname
     // if(strlen($_POST['first_name']) >= 15)
     //   $aErrors['first_name'] = true;
     // # check lastname
     // if(strlen($_POST['last_name']) >= 30)
     //   $aErrors['last_name'] = true;
     // # check pwd
     // if($_POST['password'] != $_POST['rpassword'])
     //   $aErrors['no_pwd_match'] = true;
     // # facebook
     // if(strlen($_POST['facebook']) >= 100)
     //   $aErrors['facebook'] = true;
     // # instagram
     // if(strlen($_POST['instagram']) >= 100)
     //   $aErrors['instagram'] = true;
     // # twitter
     // if(strlen($_POST['twitter']) >= 100)
     //   $aErrors['twitter'] = true;
     // # website
     // if(strlen($_POST['website']) >= 100)
     //   $aErrors['website'] = true;
     // # linkedin
     // if(strlen($_POST['linkedin']) >= 100)
     //   $aErrors['linkedin'] = true;
     #if there are errors return them now
     if ($aErrors) {
         return $aErrors;
     }
     $oUser = Singleton::getInstance('User');
     # get the id we do it here since the instance is already initaliazed
     $id = $oUser->getUserId();
     # if succeed redirect the user to the dashboard
     if ($oUser->finishAccount($id)) {
         return true;
     }
 }
 /**
  * Получить экземпляр коллекци
  * @return permissionsCollection экземпляр класса permissionsCollection
  */
 public static function getInstance($c = NULL)
 {
     return parent::getInstance(__CLASS__);
 }
Beispiel #10
0
<?php

$oUserCtrl = singleton::getInstance('UserController');
# check if the user has changed some of his settings
if ($_POST['firstname'] || $_POST['lastname'] || $_POST['mobile'] || $_POST['job-title'] || $_POST['text-area']) {
    $aErrors = $oUserCtrl->validateUserInfo();
    $oSmarty->assign('aErrors', $aErrors);
}
#require the check
require_once '../login_check.php';
require 'profile.inc.php';
# give page meta
$aMeta = array('title' => Language::getByName('instellingen'));
$oSmarty->assign('aMeta', $aMeta);
# give active class
$oSmarty->assign('activeClass', 'profile');
$oSmarty->assign('subActiveClass', 'settings');
# ok
$oSmarty->display('admin/profile/settings.tpl');
Beispiel #11
0
        $pos = 0;
        // 判断该类是否是第一次被实例化
        if (self::$instance == NULL) {
            self::$instance = new singleton();
            for ($i = 1; $i <= $location; $i++) {
                $pos = strpos($sql, '?', $pos + 1);
            }
        } else {
            for ($i = 1; $i <= $location - 1; $i++) {
                $pos = strpos($sql, '?', $pos + 1);
            }
        }
        return $sql = substr($sql, 0, $pos) . $var . substr($sql, $pos + 1);
    }
}
$dsn = "mysql:host=localhost;dbname=learnsql;charset=utf8";
$user = "******";
$pwd = "123456";
$pdo = new PDO($dsn, $user, $pwd);
$pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
$pdo->exec("SET NAMES UTF8");
$uid = 10086;
$pwd = "pwd";
$uname = "yaohuang";
$sql = "SELECT*FROM tables WHERE uid=? AND uname=? AND pwd=?";
echo singleton::getInstance($sql, 1, $uid, 'INT');
echo "\n";
echo singleton::getInstance($sql, 3, $pwd, 'STRING');
echo "\n";
echo singleton::getInstance($sql, 2, $uname, 'STRING');