예제 #1
0
파일: upgrade.php 프로젝트: phpsa/CoreCMS
 public function mysql()
 {
     $config = $this->config;
     $db = new \Core\Db($config->get('DB_DRIVER'), $config->get('DB_HOSTNAME'), $config->get('DB_USERNAME'), $config->get('DB_PASSWORD'), $config->get('DB_DATABASE'), $config->get('DB_PREFIX'));
     $k = $this->db->query("select value from #__setting where code='_version_' and key='_version_");
     $version = isset($k->row['value']) ? $k->row['value'] : '1.0.1';
     while (VERSION != $version) {
         $file = DIR_APPLICATION . 'upgrades/ ' . $version . '.sql';
         $lines = file($file);
         if ($lines) {
             $sql = '';
             foreach ($lines as $line) {
                 if ($line && substr($line, 0, 2) != '--' && substr($line, 0, 1) != '#') {
                     $sql .= $line;
                     if (preg_match('/;\\s*$/', $line)) {
                         $db->query($sql);
                         $sql = '';
                     }
                 }
             }
             $k = $this->db->query("select value from #__setting where code='_version_' and key='_version_");
             $version = $k->row['value'];
         } else {
             die("missing Upgrade File");
             exit;
         }
     }
 }
 /**
  * Process the upload of an image
  * @return type  string       response page
  */
 public static function upload()
 {
     $error = array('status' => 0, 'msg' => '');
     $post = Core\Input::post();
     //var_dump($post);
     //exit;
     $files = Core\Input::files();
     $imageType = $files["fileToUpload"]['type'];
     $fileName = $files["fileToUpload"]['name'];
     $imageSize = $files["fileToUpload"]['size'];
     $target_dir = GROUP_UPLOAD_PATH . '/';
     $target_file = $target_dir . $fileName;
     // the full path we want the image uploaded to
     $imageFileType = pathinfo($target_file, PATHINFO_EXTENSION);
     // extension and path info
     if (isset($post["submit"]) && $error['status'] === 0 && !empty($files["fileToUpload"]["tmp_name"])) {
         $check = getimagesize($files["fileToUpload"]["tmp_name"]);
         // image dimensions and other data
         if ($check !== false) {
             // File is an image
             if (file_exists($target_file)) {
                 // File with at target path already exists, try to create a new unique target path
                 $name = explode('.', $fileName);
                 if ($name !== false) {
                     $fileName = $name[0] . '_' . time() . '.' . $imageFileType;
                     $target_file = $target_dir . $fileName;
                 } else {
                     $fileName = microtime() . '.' . $imageFileType;
                     $target_file = $target_dir . $fileName;
                 }
             }
             if (!file_exists($target_file)) {
                 // File does not exist on target path, yet
                 // Check file size
                 if ($files["fileToUpload"]["size"] > 10000000) {
                     // 10mb max
                     $error['status'] = 1;
                     $error['msg'] = "Sorry, the file is too large.";
                 } else {
                     // Allow certain file formats
                     if ($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg" && $imageFileType != "gif") {
                         $error['status'] = 1;
                         $error['msg'] = "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
                     } else {
                         if (move_uploaded_file($files["fileToUpload"]["tmp_name"], $target_file)) {
                             // move uploaded file from temporary directory to target path
                             // Get new dimensions
                             list($width_orig, $height_orig) = getimagesize($target_file);
                             $width_lrg = $width_orig;
                             $height_lrg = $height_orig;
                             $target_file_lrg_name = $fileName;
                             $target_file_lrg = $target_dir . $target_file_lrg_name;
                             // Resample uploaded image
                             switch ($imageFileType) {
                                 case 'jpeg':
                                     $image = imagecreatefromjpeg($target_file);
                                     break;
                                 case 'jpg':
                                     $image = imagecreatefromjpeg($target_file);
                                     break;
                                 case 'png':
                                     $image = imagecreatefrompng($target_file);
                                     break;
                                 case 'gif':
                                     $image = imagecreatefromgif($target_file);
                                     break;
                                 default:
                                     die("Image not supported");
                             }
                             $name = explode('.', $fileName);
                             $width_med = $width_orig * 0.75;
                             $height_med = $height_orig * 0.75;
                             /*
                              $rgba = imagecolorat($image, 0, 0);
                              $alpha = ($rgba & 0x7F000000) >> 24;
                             */
                             $image_med = imagecreatetruecolor($width_med, $height_med);
                             // create a black background
                             if ($imageFileType === 'png') {
                                 imagesavealpha($image_med, true);
                                 $trans_colour = imagecolorallocatealpha($image_med, 0, 0, 0, 127);
                                 imagefill($image_med, 0, 0, $trans_colour);
                             }
                             imagecopyresampled($image_med, $image, 0, 0, 0, 0, $width_med, $height_med, $width_orig, $height_orig);
                             // overlay resampled image
                             $size = '_' . round($width_med) . 'x' . round($height_med);
                             $name = isset($name[0]) ? $name[0] : microtime();
                             $target_file_med_name = $name . $size . '.' . $imageFileType;
                             $target_file_med = $target_dir . $target_file_med_name;
                             $width_sm = $width_orig * 0.5;
                             $height_sm = $height_orig * 0.5;
                             $image_sm = imagecreatetruecolor($width_sm, $height_sm);
                             if ($imageFileType === 'png') {
                                 imagesavealpha($image_sm, true);
                                 $trans_colour = imagecolorallocatealpha($image_sm, 0, 0, 0, 127);
                                 imagefill($image_sm, 0, 0, $trans_colour);
                             }
                             imagecopyresampled($image_sm, $image, 0, 0, 0, 0, $width_sm, $height_sm, $width_orig, $height_orig);
                             $size = '_' . round($width_sm) . 'x' . round($height_sm);
                             $target_file_sm_name = $name . $size . '.' . $imageFileType;
                             $target_file_sm = $target_dir . $target_file_sm_name;
                             // Capture image data
                             ob_start();
                             switch ($imageFileType) {
                                 case 'jpeg':
                                     imagejpeg($image_med);
                                     break;
                                 case 'jpg':
                                     imagejpeg($image_med);
                                     break;
                                 case 'png':
                                     imagepng($image_med);
                                     break;
                                 case 'gif':
                                     imagejpeg($image_med);
                                     break;
                                 default:
                                     die("Image not supported");
                             }
                             $med = ob_get_contents();
                             ob_end_clean();
                             ob_start();
                             switch ($imageFileType) {
                                 case 'jpeg':
                                     imagejpeg($image_sm);
                                     break;
                                 case 'jpg':
                                     imagejpeg($image_sm);
                                     break;
                                 case 'png':
                                     imagepng($image_sm);
                                     break;
                                 case 'gif':
                                     imagejpeg($image_sm);
                                     break;
                                 default:
                                     die("Image not supported");
                             }
                             $sm = ob_get_contents();
                             ob_end_clean();
                             // Write image data to local files
                             //$bytesWrittenLrg = file_put_contents($target_file_lrg, $lrg);
                             $bytesWrittenMed = file_put_contents($target_file_med, $med);
                             $bytesWrittenSm = file_put_contents($target_file_sm, $sm);
                             // JSON structure to store thumbnail data
                             $thumbnails = array('med' => array('dimensions' => '', 'fileName' => ''), 'sm' => array('dimensions' => '', 'fileName' => ''));
                             $thumbnails['med']['dimensions'] = $bytesWrittenMed > 0 ? $width_med . 'x' . $height_med : '';
                             $thumbnails['sm']['dimensions'] = $bytesWrittenSm > 0 ? $width_sm . 'x' . $height_sm : '';
                             $thumbnails['med']['fileName'] = $bytesWrittenMed > 0 ? $target_file_med_name : '';
                             $thumbnails['sm']['fileName'] = $bytesWrittenSm > 0 ? $target_file_sm_name : '';
                             $thumbnailsJSON = json_encode($thumbnails);
                             //var_dump($json);
                             //exit;
                             $petName = isset($post['petName']) ? trim($post['petName']) : '';
                             $description = isset($post['petDescription']) ? trim($post['petDescription']) : '';
                             $petSpecialNeeds = isset($post['petSpecialNeeds']) ? trim($post['petSpecialNeeds']) : '';
                             $weight = isset($post['weight']) && $post['weight'] !== '' ? trim($post['weight']) : 'DEFAULT';
                             $species = isset($post['species']) ? $post['species'] : '';
                             $breed = isset($post['breed']) ? $post['breed'] : 'DEFAULT';
                             $age = isset($post['age']) && $post['age'] !== '' ? trim($post['age']) : "DEFAULT";
                             $sex = isset($post['sex']) && $post['sex'] !== '' ? $post['sex'] : 'none';
                             if (!isset($_SESSION['user'])) {
                                 throw new Exception("User must be logged in to post a pet for adoption");
                             }
                             $userId = $_SESSION['user'];
                             $adoptionId = '';
                             $created = time();
                             $updated = time();
                             $visibility = 'y';
                             $approved = 0;
                             $pet = new Pet($petName, $description, $petSpecialNeeds, $weight, $species, $breed, $age, $sex, $userId, $adoptionId, $created, $updated, $visibility, $approved);
                             $petTableRowId = $pet->save();
                             //exit;
                             if ($petTableRowId === false) {
                                 // log errors
                                 $msg = Core\Db::getErrorMessage();
                                 //error_log("\n" . date('Y-m-d H:i:s', time()) . ": " . $msg, 3, LOG_PATH . '/mysql_error_log');
                                 throw new Exception($msg);
                             }
                             // Create Image object, which creates a record in the DB of its class members
                             $petId = 'pet:' . $petTableRowId;
                             $newImage = new Image('', '', $fileName, $imageType, $imageSize, $width_orig, $height_orig, $thumbnailsJSON, $petId);
                             $imageTableRowId = $newImage->save();
                             if ($imageTableRowId === false) {
                                 // log errors
                                 $msg = Core\Db::getErrorMessage();
                                 //error_log("\n" . date('Y-m-d H:i:s', time()) . ": " . $msg, 3, LOG_PATH . '/mysql_error_log');
                                 throw new Exception($msg);
                             }
                             imagedestroy($image);
                             // free up resources
                         } else {
                             $error['status'] = 1;
                             $error['msg'] = "Sorry, there was an error uploading your file.";
                         }
                     }
                 }
             } else {
                 $msg = "The file {$fileName} already exists. ";
                 $error['status'] = 1;
                 $error['msg'] = $msg;
             }
         } else {
             $msg = "Failed to calculate image metadata";
             $error['status'] = 1;
             $error['msg'] = $msg;
         }
     }
     if ($error['status'] === 1) {
         return self::index(array('error' => $error['msg']));
     }
     return self::myPets();
 }
예제 #3
0
파일: App.php 프로젝트: JerwinPRO/phpfox
 public function get($id)
 {
     $app = [];
     if (substr($id, 0, 9) == '__module_') {
         $id = substr_replace($id, '', 0, 9);
         $db = new \Core\Db();
         $module = $db->select('m.*, p.*')->from(':module', 'm')->join(':product', 'p', 'p.product_id = m.product_id')->where(['m.module_id' => $id])->get();
         if ($module['product_id'] == 'phpfox') {
             $module['version'] = \Phpfox::getVersion();
         }
         $app = ['id' => '__module_' . $id, 'name' => \Phpfox_Locale::instance()->translate($id, 'module'), 'path' => null, 'is_module' => true, 'version' => $module['version']];
     } else {
         if (!isset($this->_apps[$id])) {
             throw new \Exception('App not found "' . $id . '".');
         }
         $app = $this->_apps[$id];
     }
     return new App\Object($app);
 }
예제 #4
0
파일: Object.php 프로젝트: JerwinPRO/phpfox
 public function merge()
 {
     $flavorId = $this->flavor_id;
     $id = $this->theme_id;
     $path = PHPFOX_DIR_SITE . 'themes/' . $id . '/';
     $File = \Phpfox_File::instance();
     $copy = [];
     $dirs = [];
     $files = $File->getAllFiles(PHPFOX_DIR . 'theme/default/');
     foreach ($files as $file) {
         if (!in_array($File->extension($file), ['html', 'js', 'css', 'less'])) {
             continue;
         }
         $parts = pathinfo($file);
         $dirs[] = str_replace(PHPFOX_DIR . 'theme/default/', '', $parts['dirname']);
         $copy[] = $file;
     }
     foreach ($copy as $file) {
         $newFile = $path . str_replace(PHPFOX_DIR . 'theme/default/', '', $file);
         if (in_array($File->extension($file), ['less', 'css'])) {
             $newFile = str_replace('default.' . $File->extension($file), $flavorId . '.' . $File->extension($file), $newFile);
         }
         copy($file, $newFile);
         // p($file . ' -> ' . $newFile);
         if ($File->extension($file) == 'less') {
             $content = file_get_contents($newFile);
             $content = str_replace('../../../', '../../../../PF.Base/', $content);
             file_put_contents($newFile, $content);
         }
     }
     $Db = new \Core\Db();
     $Cache = new \Core\Cache();
     $Db->update(':setting', array('value_actual' => (int) \Phpfox::getParam('core.css_edit_id') + 1), 'var_name = \'css_edit_id\'');
     $Cache->del('setting');
     // exit;
     return true;
 }
예제 #5
0
 public function merge()
 {
     $flavorId = $this->flavor_folder;
     if (!$flavorId) {
         throw new \Exception('Cannot merge a theme without a flavor.');
     }
     $id = $this->theme_id;
     //get folder name
     $Db = new \Core\Db();
     $folderName = (string) $Db->select('folder')->from(':theme')->where('theme_id=' . (int) $id)->count();
     if (empty($folderName)) {
         $folderName = $id;
     }
     $path = PHPFOX_DIR_SITE . 'themes/' . $folderName . '/';
     $File = \Phpfox_File::instance();
     $copy = [];
     $dirs = [];
     $themeFile = strtolower($folderName) == 'bootstrap' ? 'bootstrap' : 'default';
     $files = $File->getAllFiles(PHPFOX_DIR . 'theme/' . $themeFile . '/');
     foreach ($files as $file) {
         if (!in_array($File->extension($file), ['html', 'js', 'css', 'less'])) {
             continue;
         }
         $parts = pathinfo($file);
         $dirs[] = str_replace(PHPFOX_DIR . 'theme/default/', '', $parts['dirname']);
         $copy[] = $file;
     }
     foreach ($copy as $file) {
         $newFile = $path . str_replace(PHPFOX_DIR . 'theme/' . $themeFile . '/', '', $file);
         if (in_array($File->extension($file), ['less', 'css'])) {
             $newFile = str_replace('default.' . $File->extension($file), $flavorId . '.' . $File->extension($file), $newFile);
         }
         copy($file, $newFile);
         // p($file . ' -> ' . $newFile);
         if ($File->extension($file) == 'less') {
             $content = file_get_contents($newFile);
             $content = str_replace('../../../', '../../../../PF.Base/', $content);
             file_put_contents($newFile, $content);
         }
     }
     $Cache = new \Core\Cache();
     $Db->update(':setting', array('value_actual' => (int) \Phpfox::getParam('core.css_edit_id') + 1), 'var_name = \'css_edit_id\'');
     $Cache->del('setting');
     // exit;
     return true;
 }
예제 #6
0
 /**
  * Create an array of Images associated with this Pet instance
  * @throws Exception
  */
 public function loadImages()
 {
     $petId = 'pet:' . $this->id;
     $res = Model\Image::getImagesByPetId($petId);
     if ($res === false) {
         // log errors
         $msg = Core\Db::getErrorMessage();
         error_log("\n" . date('Y-m-d H:i:s', time()) . ": " . $msg, 3, LOG_PATH . '/mysql_error_log');
         throw new Exception($msg);
     }
     $this->images = array();
     foreach ($res as $imageRow) {
         $this->images[] = Image::constructByRow($imageRow);
     }
 }
예제 #7
0
/**
 *
 * For this app we return a callable function, which passes the current $App object
 */
return function (Core\App\Object $App, Twig_Environment $View) {
    // Check if user is logged in, if not don't load the event below
    $auth = new Core\Auth\User();
    if (!$auth->isLoggedIn()) {
        return false;
    }
    /**
     * Attach an event to the loading of all blocks
     */
    new Core\Event('lib_module_get_blocks', function (Phpfox_Module $object) use($View) {
        $db = new Core\Db();
        // $cache = new Core\Cache();
        $limit = (int) setting('pfu_total_to_feature', 6);
        $cond = [];
        $featured = $db->select('*')->from(':user_featured')->limit($limit)->order('ordering DESC')->all();
        if ($featured) {
            $users = '';
            foreach ($featured as $user) {
                $users[] = (int) $user['user_id'];
            }
            $cond = ['user_id' => ['in' => implode(',', $users)]];
        }
        $users = new Api\User();
        $users->limit(setting('pfu_total_to_feature', 6));
        $users->where($cond);
        // $users->order('RAND()');
예제 #8
0
<?php

require_once CORE_PATH . '/classes/uri.php';
require_once CORE_PATH . '/classes/input.php';
require_once CORE_PATH . '/classes/route.php';
require_once CORE_PATH . '/classes/db.php';
require_once CORE_PATH . '/classes/controller.php';
require_once APP_PATH . '/classes/model/image.php';
require_once APP_PATH . '/classes/model/pet.php';
require_once APP_PATH . '/classes/model/user.php';
require_once APP_PATH . '/classes/model/basket.php';
require_once APP_PATH . '/classes/model/message.php';
require_once APP_PATH . '/classes/user.php';
require_once APP_PATH . '/classes/basket.php';
require_once APP_PATH . '/classes/pet.php';
require_once APP_PATH . '/classes/image.php';
require_once APP_PATH . '/classes/message.php';
require_once APP_PATH . '/classes/threadedMessage.php';
try {
    Core\Db::connect();
} catch (Exception $ex) {
    echo $ex->getMessage();
}
echo Core\Route::execute();
예제 #9
0
파일: install.php 프로젝트: phpsa/CoreCMS
 public function database($data)
 {
     $db = new \Core\Db($data['db_driver'], $data['db_host'], $data['db_user'], $data['db_password'], $data['db_name']);
     $file = DIR_APPLICATION . 'db.sql';
     if (!file_exists($file)) {
         exit('Could not load sql file: ' . $file);
     }
     $lines = file($file);
     if ($lines) {
         $sql = '';
         foreach ($lines as $line) {
             if ($line && substr($line, 0, 2) != '--' && substr($line, 0, 1) != '#') {
                 $sql .= $line;
                 if (preg_match('/;\\s*$/', $line)) {
                     $sql = str_replace("#__", $data['db_prefix'], $sql);
                     $sql = str_replace("{{{config_url}}}", HTTP_CORECMS, $sql);
                     $db->query($sql);
                     $sql = '';
                 }
             }
         }
         $db->query("SET CHARACTER SET utf8");
         $db->query("SET @@session.sql_mode = 'MYSQL40'");
         $db->query("DELETE FROM `" . $data['db_prefix'] . "user` WHERE user_id = '1'");
         $db->query("INSERT INTO `" . $data['db_prefix'] . "user` SET user_id = '1', user_group_id = '1', username = '******'username']) . "', salt = '" . $db->escape($salt = substr(md5(uniqid(rand(), true)), 0, 9)) . "', password = '******'password'])))) . "', status = '1', email = '" . $db->escape($data['email']) . "', date_added = NOW()");
         $db->query("DELETE FROM `" . $data['db_prefix'] . "setting` WHERE `key` = 'config_email'");
         $db->query("INSERT INTO `" . $data['db_prefix'] . "setting` SET `code` = 'config', `key` = 'config_email', value = '" . $db->escape($data['email']) . "'");
         $db->query("DELETE FROM `" . $data['db_prefix'] . "setting` WHERE `key` = 'config_encryption'");
         $db->query("INSERT INTO `" . $data['db_prefix'] . "setting` SET `code` = 'config', `key` = 'config_encryption', value = '" . $db->escape(md5(mt_rand())) . "'");
         $characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
         $api_username = '';
         $api_password = '';
         for ($i = 0; $i < 64; $i++) {
             $api_username .= $characters[rand(0, strlen($characters) - 1)];
         }
         for ($i = 0; $i < 256; $i++) {
             $api_password .= $characters[rand(0, strlen($characters) - 1)];
         }
         $db->query("INSERT INTO `" . $data['db_prefix'] . "api` SET username = '******', `password` = '" . $db->escape($api_password) . "', status = 1, date_added = NOW(), date_modified = NOW()");
     }
 }