Example #1
0
 /**
  * display one articles.
  *
  * renders a template with one articles.
  *
  * @param Request
  * @param Application
  *
  * @return an article template.
  */
 public function oneArticleAction(Request $request, Application $app, $pageRoute, $contentId)
 {
     $db = new DbRepository($app['dbh']);
     $result = $db->showOne($contentId);
     $allContent = $db->getAllPagesContent();
     $args_array = array('allContent' => $allContent, 'contentId' => $result->getContentId(), 'pageName' => $result->getPageName(), 'title' => $result->getContentitemtitle(), 'article' => $result->getContentitem(), 'image' => $result->getImagePath(), 'created' => $result->getCreated());
     $templateName = 'onearticle';
     return $app['twig']->render($templateName . '.html.twig', $args_array);
 }
Example #2
0
 /**
  * A controller for adding images to an article.
  *
  * @param request object
  * @param app object
  *
  * @return twig template
  */
 public function addImageAction(Request $request, Application $app)
 {
     $db = new DbRepository($app['dbh']);
     $contentId = $app['request']->get('contentId');
     $imagePath = $app['request']->get('imagePath');
     $result = $db->addImage($imagePath, $contentId);
     $content = $db->showOne($contentId);
     $args_array = array('user' => $app['session']->get('user'), 'image' => $content->getImagePath(), 'contentitemtitle' => $content->getContentItemTitle(), 'contentitem' => $content->getContentItem(), 'created' => $content->getCreated(), 'contentid' => $content->getContentId(), 'result' => $result);
     $templateName = '_singleContent';
     return $app['twig']->render($templateName . '.html.twig', $args_array);
 }
Example #3
0
 public function userAction(Request $request, Application $app, $contentId)
 {
     $db = new DbRepository($app['dbh']);
     $content = $db->showOne($contentId);
     $user = $app['session']->get('user');
     if ($user == false) {
         $allContent = $db->getAllPagesContent();
         $args_array = array('allContent' => $allContent, 'contentId' => $content->getContentId(), 'pageName' => $content->getPageName(), 'title' => $content->getContentitemtitle(), 'article' => $content->getContentitem(), 'image' => $content->getImagePath(), 'created' => $content->getCreated());
         $templateName = 'onearticle';
         return $app['twig']->render($templateName . '.html.twig', $args_array);
     } else {
         $args_array = array('user' => $app['session']->get('user'), 'pagename' => $content->getPageName(), 'contentitemtitle' => $content->getContentItemTitle(), 'contentitem' => $content->getContentItem(), 'created' => $content->getCreated(), 'contentid' => $content->getContentId());
         $templateName = '_singleContent';
         return $app['twig']->render($templateName . '.html.twig', $args_array);
     }
 }
Example #4
0
 public function processEditContentAction(Request $request, Application $app)
 {
     $db = new DbRepository($app['dbh']);
     $contentId = $app['request']->get('contentId');
     $pageName = $app['request']->get('pageName');
     $contentType = $app['request']->get('contentType');
     $contentItemTitle = $app['request']->get('contentItemTitle');
     $contentItem = $app['request']->get('contentItem');
     $result = $db->editContent($contentId, $pageName, $contentType, $contentItemTitle, $contentItem);
     $args_array = array('user' => $app['session']->get('user'), 'result' => $result);
     $templateName = '_dashboard';
     return $app['twig']->render($templateName . '.html.twig', $args_array);
 }
Example #5
0
 /**
  * A controller for processing the upload images form.
  * Validations: a jpg or png, under 1M and file must not already exist.
  * The image path will be stored in the db.
  *
  * @param request object
  * @param app object
  *
  * @return twig template
  */
 public function processImageUploadAction(Request $request, Application $app)
 {
     $file = $request->files->get('image');
     $pic = $file->getClientOriginalName();
     $constraint = new Assert\Image(array('mimeTypes' => array('image/jpeg', 'image/png'), 'maxSize' => '2M'));
     $validfile = true;
     $message = '';
     $errors = $app['validator']->validate($file, $constraint);
     if (count($errors) > 0) {
         foreach ($errors as $error) {
             $message = $error->getPropertyPath() . ' ' . $error->getMessage() . "\n";
         }
         $validfile = false;
     }
     if (file_exists($request->getBasePath() . 'images/' . $file->getClientOriginalName())) {
         $message = 'Sorry, file already exists';
         $validfile = false;
     }
     # if the validation variable is false, re-render the upload form with an error message
     if ($validfile == false) {
         $args_array = array('user' => $app['session']->get('user'), 'result' => $message);
         $templateName = '_uploadImageForm';
         return $app['twig']->render($templateName . '.html.twig', $args_array);
     } elseif ($validfile == true) {
         $file->move($request->getBasePath() . 'images/', $file->getClientOriginalName());
         $path = $file->getClientOriginalName();
         $newImage = new Image();
         $newImage->setImagePath($path);
         $image = $newImage->getImagePath();
         $db = new DbRepository($app['dbh']);
         $result = $db->uploadImage($image);
         $images = $db->viewImages();
         $content = $db->getAllPagesContent();
         $args_array = array('user' => $app['session']->get('user'), 'result' => $result, 'images' => $images, 'content' => $content);
         $templateName = '_viewImages';
         return $app['twig']->render($templateName . '.html.twig', $args_array);
     }
 }
Example #6
0
 /**
  * A controller to process deleting a web page.
  * 
  * @param request object
  * @param app, the application object ($app)
  * 
  * @return processes and re-renders the delete page form.
  */
 public function processDeletePageAction(Request $request, Application $app)
 {
     $db = new DbRepository($app['dbh']);
     $pageName = $app['request']->get('pageName');
     $pageTemplate = $app['request']->get('pageTemplate');
     $result = $db->deletePage($pageName, $pageTemplate);
     $args_array = array('user' => $app['session']->get('user'), 'result' => $result);
     $templateName = '_dashboard';
     return $app['twig']->render($templateName . '.html.twig', $args_array);
 }
Example #7
0
# $loggerPath = dirname(__DIR__).'/logs';
$app = new Silex\Application();
$app['title'] = '';
if (isset($config['title']['title'])) {
    $app['title'] = $config['title']['title'];
}
$app['image'] = '';
if (isset($config['bg-image']['image'])) {
    $app['image'] = '/images/' . $config['bg-image']['image'];
}
# store regularly used variables(services?) in the app container
$dbmanager = new DbManager();
# app['dbh'] is a connection instance and is passed to the constructor
# of the database repository.
$app['dbh'] = $dbmanager->getPdoInstance();
$db = new DbRepository($app['dbh']);
# The $pages variable will be accessible in twig templates as app.pages.
# and will (usually) be an array of page objects
# so you can loop through with a twig for loop.
# e.g {% for page in app.pages %}{{ page.pageName or page.pageTemplate }}
# this will save having to query the database every time you want to access
# the page objects.
$app['pages'] = $db->getAllPages();
$app['images'] = $db->viewImages();
# twig loaders for templates: a database loader for dynamically created templates,
# and a filesystem loader for templates stored on the filesystem.
$app['loader1'] = new Twig_Loader_Filesystem(array($myTemplatesPath1, $myTemplatesPath2));
$app['loader2'] = new DatabaseTwigLoader($app['dbh']);
$app['debug'] = true;
# ______________________________________________________________
#              ADD PROVIDERS HERE