public function execute() { // Check if logged in user has enough permissions to run command $authenticationCenter = LTAuthenticationCenter::sharedCenter(); if (!$authenticationCenter->validate() || 1 > LTAuthenticationCenter::user()->level()) { throw new Exception('You do not have permissions to execute this command'); } $title = strtolower(trim(strip_tags(urldecode(stripslashes($_POST['title']))))); $body = strtolower(trim(strip_tags(urldecode(stripslashes($_POST['body']))))); // Test Title // Test Body $db = new LTMySQL(); $db->connect(LTRWDBConfig::HOST, LTRWDBConfig::USER, LTRWDBConfig::PASS); $db->selectdb(LTRWDBConfig::DB); $db->query('insert into ehead set author=\'' . LTAuthenticationCenter::user()->id() . '\',title=\'' . $title . '\',added=unix_timestamp(),edit=unix_timestamp();'); if (1 !== $db->numrows()) { throw new RuntimeException('Failed to add message. Try later.'); } // Get ID of newly created entry $id = $db->insertid(); $db->query("insert into entry set id={$id},body='{$body}';"); if (1 !== $db->numrows()) { $db->query("delete from ehead where id={$id};"); throw new RuntimeException('Failed to add message. Try later.'); } return new LTJsonMessage('Entry was successfully added.'); }
public static function &sharedCenter() { return self::$sharedCenter ? self::$sharedCenter : (self::$sharedCenter = new self()); }
<?php /* * index.php * Latte * * Created by Samvel Khalatian on January 5, 2010. * Copyright 2009, Your Company All rights reserved. */ session_start(); define("TLDIR_INDEX", $_SERVER['DOCUMENT_ROOT']); @(include_once TLDIR_INDEX . '/php/LTAuthenticationCenter.php'); @(include_once TLDIR_INDEX . '/php/LTJson.php'); try { $authenticationCenter = LTAuthenticationCenter::sharedCenter(); $authenticationCenter->invalidate(); LTJsonCenter::sharedCenter()->chain(new LTJsonMessage('You are logged out.')); } catch (Exception $exception) { LTJsonCenter::sharedCenter()->chain(new LTJsonError($exception->getMessage())); } echo LTJsonCenter::sharedCenter();