function actions()
 {
     $urlArray = $this->basicInformationObject->getUriArray();
     $searchedUser = $urlArray[2];
     $root = $urlArray[0];
     $msqlObject = new mysqlModule();
     $returnString = '';
     $queryResult = $msqlObject->queryDataBase('SELECT * FROM users WHERE name = "' . $searchedUser . '"');
     if (!isset($queryResult[0]['name'])) {
         header('Location: ' . $root . '/404');
     }
     $fetchProfilePicPath = $msqlObject->queryDataBase('SELECT path FROM profile_images WHERE id = "' . $queryResult[0]['img_id'] . '"');
     $this->model->addAttribute('USERNAME', $queryResult[0]['name']);
     $this->model->addAttribute('USERMAIL', $queryResult[0]['email']);
     $this->model->addAttribute('USERLEVEL', $queryResult[0]['tutorialDone'] ? 'Advanced User' : 'Beginner');
     $this->model->addAttribute('USERIMAGE', $fetchProfilePicPath[0]['path']);
     $storyQueryResult = $msqlObject->queryDataBase('SELECT * FROM story WHERE user = "******"');
     $stories = '';
     $loggedIn = false;
     if ($this->sessionObject->getLogState() && $this->sessionObject->encodeKey($this->basicInformationObject->getUriArray()[2]) === $this->sessionObject->getSafeHash()) {
         $loggedIn = true;
     }
     if (isset($storyQueryResult[0]['name'])) {
         for ($i = 0; $i < sizeof($storyQueryResult); $i++) {
             if ($storyQueryResult[$i]['isPublished'] === '1' || $storyQueryResult[$i]['isPublished'] === '0' && $loggedIn) {
                 $fetchStoryPicPath = $msqlObject->queryDataBase('SELECT path FROM story_images WHERE id = "' . $storyQueryResult[$i]['img_id'] . '"');
                 $storyImagePath = $root . '/public/images/story/' . $fetchStoryPicPath[0]['path'];
                 $stories .= '<div class="storyPicFrame clearfix">' . "\n";
                 $stories .= '<a href="' . $root . '/users/' . $searchedUser . '/' . $storyQueryResult[$i]['name'] . '"><img class="storyPic" src="' . $storyImagePath . '" alt="story" />' . "\n";
                 $stories .= '<p class="storyTitle">' . $storyQueryResult[$i]['name'] . '</p></a>' . "\n";
                 if ($searchedUser === $this->sessionObject->getUserName()) {
                     $stories .= '<div class="buttonFrameContainerStory"><a href="' . $root . '/users/' . $searchedUser . '/' . $storyQueryResult[$i]['name'] . '/edit"><input class="buttonStory" type="submit" value="EDIT"/></a></div>' . "\n";
                 }
                 $stories .= '</div>' . "\n";
             }
         }
     }
     if ($searchedUser === $this->sessionObject->getUserName()) {
         $returnString .= '<div class="buttonFrameContainerStoryInfo"><a class="fancybox fancybox.ajax" href="../data/templates/uploadTestForm.html"><input class="buttonStoryInfo" type="submit" value="EDIT PROFILE"/></a></div>';
     }
     $addStory = '';
     if ($loggedIn) {
         $addStory .= '<div class="storyPicFrame">';
         $addStory .= '<a class="fancybox fancybox.ajax" href="../data/templates/newStoryTemplate.html">';
         $addStory .= '<img class="storyPic" src="/Storytelling/public/images/dummyNewStory.jpg" alt="newStory" />';
         $addStory .= '<p class="storyTitle">NEW STORY</p>';
         $addStory .= '</a>';
         $addStory .= '</div>';
     }
     $this->model->addLogState($this->sessionObject);
     $this->model->addAttribute('INFO', $returnString);
     $this->model->addAttribute('STORIES', $stories);
     $this->model->addAttribute('ADDSTORY', $addStory);
 }
Exemplo n.º 2
0
function SearchDeleteConnection($movingIDs, $storyID, $con, $result)
{
    $mysqlObject = new mysqlModule();
    for ($i = 0; $i < sizeof($movingIDs); $i++) {
        $indexedOnly = $mysqlObject->queryDataBase("SELECT id,level,NextPageID1,NextPageID2,NextPageID3,NextPageID4 FROM page WHERE NextPageID1 = " . $movingIDs[$i] . " OR NextPageID2 = " . $movingIDs[$i] . " OR NextPageID3 = " . $movingIDs[$i] . " OR NextPageID4 = " . $movingIDs[$i] . " AND story = " . $storyID);
        $IDs = $mysqlObject->queryDataBase("SELECT id,level FROM page WHERE id = " . $movingIDs[$i] . " AND story = " . $storyID);
        // echo json_encode($indexedOnly);
        // echo json_encode($IDs);
        for ($a = 0; $a < sizeof($indexedOnly); $a++) {
            //echo json_encode($IDs[0]['level'] - $indexedOnly[$a]['level']);
            if ($IDs[0]['level'] - $indexedOnly[$a]['level'] != -1 && $IDs[0]['level'] - $indexedOnly[$a]['level'] != 1) {
                if ($indexedOnly[$a]['NextPageID1'] == $movingIDs[$i]) {
                    $indexedOnly[$a]['NextPageID1'] = $indexedOnly[$a]['NextPageID2'];
                    $indexedOnly[$a]['NextPageID2'] = $indexedOnly[$a]['NextPageID3'];
                    $indexedOnly[$a]['NextPageID3'] = $indexedOnly[$a]['NextPageID4'];
                    $indexedOnly[$a]['NextPageID4'] = 0;
                }
                if ($indexedOnly[$a]['NextPageID2'] == $movingIDs[$i]) {
                    $indexedOnly[$a]['NextPageID2'] = $indexedOnly[$a]['NextPageID3'];
                    $indexedOnly[$a]['NextPageID3'] = $indexedOnly[$a]['NextPageID4'];
                    $indexedOnly[$a]['NextPageID4'] = 0;
                }
                if ($indexedOnly[$a]['NextPageID3'] == $movingIDs[$i]) {
                    $indexedOnly[$a]['NextPageID3'] = $indexedOnly[$a]['NextPageID4'];
                    $indexedOnly[$a]['NextPageID4'] = 0;
                }
                if ($indexedOnly[$a]['NextPageID4'] == $movingIDs[$i]) {
                    $indexedOnly[$a]['NextPageID4'] = 0;
                }
                $sql = "UPDATE page SET NextPageID1 = " . $indexedOnly[$a]['NextPageID1'] . " , NextPageID2 = " . $indexedOnly[$a]['NextPageID2'] . " ,\n              NextPageID3 = " . $indexedOnly[$a]['NextPageID3'] . " , NextPageID4 = " . $indexedOnly[$a]['NextPageID4'] . "\n              WHERE id = " . $indexedOnly[$a]['id'] . "  AND story = " . $storyID;
                // echo json_encode($sql);
                if ($result == true) {
                    $result = mysqli_query($con, $sql);
                } else {
                    mysqli_query($con, $sql);
                }
                if ($result == false) {
                    mysqli_rollback($con);
                    // transaction rolls back
                    echo "Error: Transaction rolled back";
                    exit;
                } else {
                    mysqli_commit($con);
                    // transaction is committed
                    // echo "Successfully updated!";
                }
            }
        }
    }
    for ($i = 0; $i < sizeof($movingIDs); $i++) {
        $indexedOnly = $mysqlObject->queryDataBase("SELECT id,level,NextPageID1,NextPageID2,NextPageID3,NextPageID4 FROM page WHERE NextPageID1 = " . $movingIDs[$i] . " OR NextPageID2 = " . $movingIDs[$i] . " OR NextPageID3 = " . $movingIDs[$i] . " OR NextPageID4 = " . $movingIDs[$i] . " AND story = " . $storyID);
        for ($a = 0; $a < sizeof($indexedOnly); $a++) {
            if ($indexedOnly[$a]['NextPageID1'] != 0) {
                $sql = "UPDATE page SET position=1 WHERE id = " . $indexedOnly[$a]['NextPageID1'] . " AND story = " . $storyID;
                if ($result == true) {
                    $result = mysqli_query($con, $sql);
                } else {
                    mysqli_query($con, $sql);
                }
            }
            if ($indexedOnly[$a]['NextPageID2'] != 0) {
                $sql = "UPDATE page SET position=2 WHERE id = " . $indexedOnly[$a]['NextPageID2'] . " AND story = " . $storyID;
                if ($result == true) {
                    $result = mysqli_query($con, $sql);
                } else {
                    mysqli_query($con, $sql);
                }
            }
            if ($indexedOnly[$a]['NextPageID3'] != 0) {
                $sql = "UPDATE page SET position=3 WHERE id = " . $indexedOnly[$a]['NextPageID3'] . " AND story = " . $storyID;
                if ($result == true) {
                    $result = mysqli_query($con, $sql);
                } else {
                    mysqli_query($con, $sql);
                }
            }
            if ($indexedOnly[$a]['NextPageID4'] != 0) {
                $sql = "UPDATE page SET position=4 WHERE id = " . $indexedOnly[$a]['NextPageID4'] . " AND story = " . $storyID;
                if ($result == true) {
                    $result = mysqli_query($con, $sql);
                } else {
                    mysqli_query($con, $sql);
                }
            }
        }
    }
    if ($result == false) {
        mysqli_rollback($con);
        // transaction rolls back
        echo "Error: Transaction rolled back";
        exit;
    } else {
        mysqli_commit($con);
        // transaction is committed
        // echo "Successfully updated!";
    }
    do {
        mysqli_store_result($con);
    } while (mysqli_next_result($con));
}
    // resize the original image to size of editor
    $resizedImage = imagecreatetruecolor($imgW, $imgH);
    imagecopyresampled($resizedImage, $source_image, 0, 0, 0, 0, $imgW, $imgH, $imgInitW, $imgInitH);
    // rotate the rezized image
    $rotated_image = imagerotate($resizedImage, -$angle, 0);
    // find new width & height of rotated image
    $rotated_width = imagesx($rotated_image);
    $rotated_height = imagesy($rotated_image);
    // diff between rotated & original sizes
    $dx = $rotated_width - $imgW;
    $dy = $rotated_height - $imgH;
    // crop rotated image to fit into original rezized rectangle
    $cropped_rotated_image = imagecreatetruecolor($imgW, $imgH);
    imagecolortransparent($cropped_rotated_image, imagecolorallocate($cropped_rotated_image, 0, 0, 0));
    imagecopyresampled($cropped_rotated_image, $rotated_image, 0, 0, $dx / 2, $dy / 2, $imgW, $imgH, $imgW, $imgH);
    // crop image into selected area
    $final_image = imagecreatetruecolor($cropW, $cropH);
    imagecolortransparent($final_image, imagecolorallocate($final_image, 0, 0, 0));
    imagecopyresampled($final_image, $cropped_rotated_image, 0, 0, $imgX1, $imgY1, $cropW, $cropH, $cropW, $cropH);
    // finally output png image
    //imagepng($final_image, $output_filename.$type, $png_quality);
    $mysqlObject = new mysqlModule();
    $sessionObject = new sessionModule();
    $mysqlObject->commandDataBase('INSERT INTO `page_images` (`page`, `path`) VALUES ("' . $sessionObject->getPage() . '", "' . $filename . $type . '")');
    imagejpeg($final_image, $output_filename . $type, $jpeg_quality);
    $response = array("status" => 'success', "url" => $real_filename . $type);
}
$realImageName = str_replace('../../images/temp/', '', $imgUrl);
rename('../../images/page/original/' . $realImageName, '../../images/page/original/' . $filename . $type);
unlink($imgUrl);
print json_encode($response);
} else {
    // resize the original image to size of editor
    $resizedImage = imagecreatetruecolor($imgW, $imgH);
    imagecopyresampled($resizedImage, $source_image, 0, 0, 0, 0, $imgW, $imgH, $imgInitW, $imgInitH);
    // rotate the rezized image
    $rotated_image = imagerotate($resizedImage, -$angle, 0);
    // find new width & height of rotated image
    $rotated_width = imagesx($rotated_image);
    $rotated_height = imagesy($rotated_image);
    // diff between rotated & original sizes
    $dx = $rotated_width - $imgW;
    $dy = $rotated_height - $imgH;
    // crop rotated image to fit into original rezized rectangle
    $cropped_rotated_image = imagecreatetruecolor($imgW, $imgH);
    imagecolortransparent($cropped_rotated_image, imagecolorallocate($cropped_rotated_image, 0, 0, 0));
    imagecopyresampled($cropped_rotated_image, $rotated_image, 0, 0, $dx / 2, $dy / 2, $imgW, $imgH, $imgW, $imgH);
    // crop image into selected area
    $final_image = imagecreatetruecolor($cropW, $cropH);
    imagecolortransparent($final_image, imagecolorallocate($final_image, 0, 0, 0));
    imagecopyresampled($final_image, $cropped_rotated_image, 0, 0, $imgX1, $imgY1, $cropW, $cropH, $cropW, $cropH);
    // finally output png image
    //imagepng($final_image, $output_filename.$type, $png_quality);
    $mysqlObject = new mysqlModule();
    $sessionObject = new sessionModule();
    $profileImageId = $mysqlObject->queryDataBase('SELECT id FROM users WHERE name = "' . $sessionObject->getUserName() . '"')[0]['id'];
    $mysqlObject->commandDataBase('INSERT INTO `story_images` (`story`, `path`) VALUES ("' . $sessionObject->getStory() . '", "' . $filename . $type . '")');
    imagejpeg($final_image, $output_filename . $type, $jpeg_quality);
    $response = array("status" => 'success', "url" => $real_filename . $type);
}
unlink($imgUrl);
print json_encode($response);
Exemplo n.º 5
0
function handleFileUpload()
{
    $mysqlObject = new mysqlModule();
    $sessionObject = new sessionModule();
    $allowedExts = array('gif', 'jpeg', 'jpg', 'png');
    $temp = explode('.', $_FILES['file']['name']);
    $extension = end($temp);
    if (($_FILES['file']['type'] == 'image/jpeg' || $_FILES['file']['type'] == 'image/jpg' || $_FILES['file']['type'] == 'image/png') && $_FILES['file']['size'] < 2000000 && in_array($extension, $allowedExts)) {
        if ($_FILES['file']['error'] > 0) {
            echo 'Return Code: ' . $_FILES['file']['error'] . '<br>';
        } else {
            $date = new DateTime();
            $dateString = sha1(str_replace(' ', '', $date->format('Y-m-d H:i:s')));
            $fileending = $_FILES['file']['type'] == 'image/jpeg' || $_FILES['file']['type'] == 'image/jpg' ? '.jpg' : '.png';
            $filename = $dateString . $fileending;
            /*echo "Upload: " . $_FILES["file"]["name"] . "<br>";
            		echo "Type: " . $_FILES['file']['type'] . "<br>";
            		echo "Size: " . ($_FILES["file"]["size"] / 1024) . " kB<br>";
            		echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br>";*/
            $profileImageId = $mysqlObject->queryDataBase('SELECT id FROM users WHERE name = "' . $sessionObject->getUserName() . '"')[0]['id'];
            $mysqlObject->commandDataBase('INSERT INTO `profile_images` (`user`, `path`) VALUES ("' . $profileImageId . '", "' . $filename . '")');
            move_uploaded_file($_FILES['file']['tmp_name'], '../images/profile/' . $filename);
            echo 'Successfull upload!';
        }
    } else {
        echo 'Invalid file';
    }
}
Exemplo n.º 6
0
function loadFirstPage()
{
    $mysqlObject = new mysqlModule();
    $page_id = $mysqlObject->queryDataBase('SELECT firstPage FROM story WHERE name = "' . $_POST['story'] . '"')[0]['firstPage'];
    loadTargetPage($page_id);
}