function printPostCode($user_id, $name, $surname, $description, $post_id, $sharing_date, $like, $likes, $img_url)
{
    if ($img_url == "") {
        $img_url = "img/user.png";
    }
    $data = new MysqlConnector();
    $data->connectMysql();
    #LOAD COMMENTS OF THE CURRENT POST
    $comments = $data->getComments($post_id);
    #CHECK IF THERE ARE COMMENTS AND PRINT THEM
    $num_of_comments = $comments->num_rows;
    if ($like) {
        $class_like = "glyphicon glyphicon-heart";
    } else {
        $class_like = "glyphicon glyphicon-heart-empty";
    }
    echo "\n      <div class='row post-box' id=" . $post_id . ">\n        <div class='col-lg-12 col-xs-12'>\n          <div class='panel'>\n            <div class='panel-heading'>\n              <div class='row'>\n                <div class='col-lg-1 col-xs-2 img-container'>\n                  <img class='img-rounded user-img' \n                       src='" . $img_url . "' >\n                </div>\n                <div class='col-lg-11 col-xs-10'>\n                  <strong class='author'>" . $surname . " " . $name . "</strong>\n                  <br> \n                  <span class='text-muted date'>\n                    posted on: " . $sharing_date . "</span>\n                </div>\n              </div>\n          </div><!-- /panel-heading -->\n          <div class='panel-body text'>\n            <h3 class='text'>" . $description . "</h3>\n          </div><!-- /panel-body -->\n          <div class='panel-footer'>\n            <button class='like'>\n              <span class='" . $class_like . "'></span>\n              <strong>\n                <span class='like-num'>" . $likes . "</span> \n                likes\n              </strong>\n            </button>\n            \n            <button class='comm'>\n              <span class='glyphicon glyphicon-comment'></span>\n              <strong>\n                <span class='comm-num'>" . $num_of_comments . "</span>\n                comments\n              </strong>\n            </button>\n            \n            <button class='reblog pull-right'>\n              <span class='glyphicon glyphicon-plus'></span>\n            </button>\n    ";
    echo " \n      <div class='write-comment'>\n        <div class='panel-body'>\n          <form class='comment-form' action='' method='post'>\n            <textarea class='form-control elastic-box \n                             insert-comment' \n                      style='resize: none;' \n                      rows='2' name='comment'  \n                      placeholder='Insert a comment...'></textarea>\n\n            <button type='button' \n                    class='btn btn-default btn-xs comment-button pull-right' \n            > <span class='glyphicon glyphicon-pencil'></span> Comment </button>\n          </form>\n        </div>\n      </div>\n    ";
    echo "<div class='all-comments'>";
    if ($num_of_comments !== 0) {
        #PRINT COMMENTS OF THE POST
        while ($comment = $comments->fetch_assoc()) {
            printCommentCode($comment['user_id'], $comment['name'], $comment['surname'], $comment['description'], $comment['sharing_date'], $comment['img_url']);
        }
    }
    $data->disconnectMysql();
    echo "</div>";
    #close /all-comments
    echo "\n      </div><!-- /panel-footer -->\n    </div><!-- /panel -->\n    ";
    echo "     \n      </div><!-- col-lg-5 col-xs-12 -->\n    </div><!-- /row -->\n    ";
}
예제 #2
0
 /**
  * Methode de recuperation unique de l'instance
  * @author Valentin CARRUESCO
  * @category Singleton
  * @param <Aucun>
  * @return <mysql> $instance
  */
 public static function getInstance()
 {
     if (MysqlConnector::$instance === null) {
         MysqlConnector::$instance = new self();
     }
     return MysqlConnector::$instance;
 }
예제 #3
0
 /**
  * 执行sql
  * @return bool|mixed
  */
 public function execute()
 {
     if (!$this->prepare) {
         return false;
     }
     $res = $this->mysql->query($this->prepare);
     return $res;
 }
예제 #4
0
 /**
  * 绑定数据
  *
  * @return bool|mixed
  */
 public function bind()
 {
     if (func_num_args() == 0) {
         return false;
     }
     $args = func_get_args();
     #绑定数据
     $type = join('', $this->types[1]);
     array_unshift($args, $type);
     $mysql = $this->mysql->connect();
     $prepare = $mysql->prepare($this->sql);
     if (!$prepare) {
         return false;
     }
     $this->prepare =& $prepare;
     //使用反射,避免参数引用错误
     $method = new \ReflectionMethod($prepare, 'bind_param');
     return $method->invokeArgs($prepare, $args);
 }
예제 #5
0
 /**
  * 释放资源
  */
 public function free()
 {
     if ($this->result) {
         $this->result->free();
         $mysql = $this->mysql->connect();
         while ($mysql->more_results() && $mysql->next_result()) {
             $result = $mysql->store_result();
             if ($result) {
                 $result->free();
             }
         }
     }
 }
예제 #6
0
<?php

/**
 * @author Christian Rizza
 * www.crizza.com
 * email: christian@crizza.com
 */
session_start();
define('BASE_PATH', "./");
include BASE_PATH . "config.php";
if (!isset($_SESSION['admin'])) {
    header("Location: index.php");
}
$conn = new MysqlConnector();
$conn->connect();
$student = new Student();
$student->setConnector($conn);
$lista = $student->getList();
foreach ($lista as $entry) {
    echo "Email: " . $entry->email . " ";
    $entry->setConnector($conn);
    if ($entry->generatePassword()) {
        echo "[Errore di invio] <br>";
    } else {
        echo "[OK] <br>";
    }
    $counter++;
}
$conn->disconnect();
?>
<?php

include 'php_functions.php';
include 'html_code_functions.php';
$data = new MysqlConnector();
$data->connectMysql();
$users = $data->getUsers($_POST['text']);
$followed_users = $data->getFollowedUsers();
$data->disconnectMysql();
while ($followed = $followed_users->fetch_assoc()) {
    $followed_list[] = $followed;
}
while ($user = $users->fetch_assoc()) {
    $user['follow'] = 1;
    foreach ($followed_list as $followed) {
        if ($user['user_id'] === $followed['followed_id']) {
            $user['follow'] = 0;
        }
    }
    printUserRow($user);
}
예제 #8
0
                    placeholder='Insert some text...'></textarea>
          
          <button class='btn btn-default post-submit'
                  type='button'
                  ><span class="glyphicon glyphicon-pencil"></span></button>
                 
        </form>
      </div>
    </div> 
    
    <div class='events'></div>
        
    <!-- Container of Posts -->
    <div class='posts-container'>
      <?php 
$data = new MysqlConnector();
$data->connectMysql();
#LOAD ALL POSTS
$result = $data->getPosts();
#PRINT EACH LOADED POST WITH ITS COMMENTS
while ($post = $result->fetch_assoc()) {
    //check if the logged user likes the current post
    $like = $data->isLiked($post['post_id']);
    //count how many like the post has
    $likes = $data->getNumOfLikes($post['post_id']);
    printPostCode($post['user_id'], $post['name'], $post['surname'], $post['description'], $post['post_id'], $post['sharing_date'], $like, $likes, $post['img_url']);
}
?>
    </div>
  </div>
  
<?php

include 'php_functions.php';
$pass = $_POST['pass'];
$email = $_POST['email'];
$data = new MysqlConnector();
$data->connectMysql();
#if authenticated
if ($data->logIn($email, $pass)) {
    echo "Authenticated.";
    exit;
}
#else come back to login.html
$data->disconnectMysql();
echo "*Invalid email or password.";
예제 #10
0
<?php

require 'connect_mysql.php';
$mysqlConnector = new MysqlConnector();
$mysqlConnector->createDatabase();
$mysqlConnector->useDatabase();
$mysqlConnector->loadDatabaseSchema();
$mysqlConnector->deleteDatabaseConnection();
예제 #11
0
<?php

include 'php_functions.php';
$data = new MysqlConnector();
$data->connectMysql();
$data->unfollow($_POST['user_to_unfollow']);
$data->disconnectMysql();
$name = $_POST['name'];
$surname = $_POST['surname'];
$pass = $_POST['pass'];
$pass2 = $_POST['pass2'];
$email = $_POST['email'];
/******** CHECK PASSWORDS **********/
if (strlen($pass) < 8) {
    echo "*Please insert a password equal or longer than 8 characters.";
    exit;
}
if ($pass2 !== $pass) {
    echo "*Please insert equal passwords.";
    exit;
}
/********** CHECK EMAIL *********/
$data = new MysqlConnector();
$data->connectMysql();
if ($data->isRegistered($email)) {
    echo "*Email already exists.";
    exit;
}
/************ CHECK PICTURE ************/
$img_name = $_FILES['imgToUpdate']['name'];
if ($img_name !== "") {
    //Check if the file is bigger than 300kb
    if ($_FILES['imgToUpdate']['size'] > 300000) {
        echo "*Please insert a picture with a size smaller than 300Kb.";
        exit;
    }
    \Cloudinary::config(getCloudinaryCredentials());
    $img_url = \Cloudinary\Uploader::upload($_FILES['imgToUpdate']['tmp_name'], array("crop" => "lfill", "width" => "400", "height" => "400"));
예제 #13
0
<?php

include 'php_functions.php';
$data = new MysqlConnector();
$data->connectMysql();
$data->addComment();
$data->disconnectMysql();
<?php

include 'php_functions.php';
$data = new MysqlConnector();
$data->connectMysql();
echo $data->findLastPostId();
$data->disconnectMysql();
예제 #15
0
 public function __construct()
 {
     $this->dbconnector = MysqlConnector::getInstance();
 }
예제 #16
0
          PRIMARY KEY(follower_id, followed_id),
          FOREIGN KEY(follower_id) REFERENCES Users(user_id),
          FOREIGN KEY(followed_id) REFERENCES Users(user_id) );
        ', 'CREATE TABLE Likes (
           post_id INT UNSIGNED NOT NULL,
           user_id SMALLINT UNSIGNED NOT NULL,
           PRIMARY KEY(post_id, user_id),
           FOREIGN KEY(post_id) REFERENCES Posts(post_id),
           FOREIGN KEY(user_id) REFERENCES Users(user_id) 
         );
        ');
    return $creator[$n_statement];
}
#####################Calls methods########################
#Create Mysql object
$installer = new MysqlConnector();
#Connect to mysql
$installer->connectMysql();
#Uninstall old tables
for ($i = 0; $i < 5; $i++) {
    if ($installer->connection->query(deleteTables($i)) === TRUE) {
        echo "Deleted <br>";
    } else {
        echo $installer->connection->error . '<br>';
    }
}
#Install new tables
for ($i = 0; $i < 5; $i++) {
    if ($installer->connection->query(addTables($i)) === TRUE) {
        echo "Created <br>";
    } else {
예제 #17
0
 public function __construct()
 {
     MysqlConnector::getInstance();
 }
예제 #18
0
<?php

include 'php_functions.php';
$data = new MysqlConnector();
$data->connectMysql();
$data->like($_POST['post_id']);
예제 #19
0
<?php

include 'php_functions.php';
$data = new MysqlConnector();
$data->connectMysql();
$data->addPost();
$data->disconnectMysql();
예제 #20
0
<?php

require 'connect_mysql.php';
$mysqlConnector = new MysqlConnector();
$mysqlConnector->dropDatabase();
$mysqlConnector->createDatabase();
$mysqlConnector->useDatabase();
$mysqlConnector->loadDatabaseSchema();
$mysqlConnector->loadTestFixtures();
$mysqlConnector->deleteDatabaseConnection();