private function get_how_to_use_content($f3)
 {
     $content = "How to use content.";
     $file = F3::instance()->read('help/README.md');
     $html = Markdown::instance()->convert($file);
     $f3->set('how_to_use_content', $html);
     return $content;
 }
Exemple #2
0
 function __construct()
 {
     global $f3;
     $this->f3 = $f3;
     $this->log = new Log('error.log');
     $this->db = new \DB\SQL('mysql:host=' . $this->dbinfo['dbhost'] . ';port=' . $this->dbinfo['dbport'] . ';dbname=' . $this->dbinfo['dbname'], $this->dbinfo['dbuser'], $this->dbinfo['dbpass']);
     $this->smtp = new SMTP($this->EmailInfo['host'], $this->EmailInfo['port'], $this->EmailInfo['scheme'], $this->EmailInfo['user'], $this->EmailInfo['pass']);
     $this->smtp->set('Errors-to', '');
     $this->smtp->set('From', '');
     $this->smtp->set('CC', '');
     $this->smtp->set('In-Reply-To', '');
     $this->geo = \Web\Geo::instance();
     $this->md = \Markdown::instance();
     $this->audit = \Audit::instance();
     $this->theme = new theme();
     $this->theme->set_siteURL($this->site);
     $this->request['ip-address'] = $this->get_remote_address();
 }
Exemple #3
0
 /**
  * get release information from  GitHub
  * @param $f3
  */
 public function releases($f3)
 {
     $cacheKey = 'CACHE_GITHUB_RELEASES';
     $ttl = 60 * 30;
     // 30min
     $releaseCount = 3;
     if (!$f3->exists($cacheKey)) {
         $apiPath = $this->getF3()->get('PATHFINDER.API.GIT_HUB') . '/repos/exodus4d/pathfinder/releases';
         // build request URL
         $options = $this->getRequestOptions();
         $apiResponse = \Web::instance()->request($apiPath, $options);
         if ($apiResponse['body']) {
             // request succeeded -> format "Markdown" to "HTML"
             // result is JSON formed
             $releasesData = (array) json_decode($apiResponse['body']);
             // check max release count
             if (count($releasesData) > $releaseCount) {
                 $releasesData = array_slice($releasesData, 0, $releaseCount);
             }
             $md = \Markdown::instance();
             foreach ($releasesData as &$releaseData) {
                 if (isset($releaseData->body)) {
                     // convert list style
                     $body = str_replace(' - ', '* ', $releaseData->body);
                     $releaseData->body = $md->convert($body);
                 }
             }
             $f3->set($cacheKey, $releasesData, $ttl);
         } else {
             // request failed -> cache failed result (respect API request limit)
             $f3->set($cacheKey, false, 60 * 5);
         }
     }
     // set 503 if service unavailable or temp cached data = false
     if (!$f3->get($cacheKey)) {
         $f3->status(503);
     }
     echo json_encode($f3->get($cacheKey));
 }
Exemple #4
0
 function info($f3)
 {
     $this->D->with('ORDER BY displayname ASC')->ownDocs;
     // Render Notes as Markdown
     $md = \Markdown::instance();
     $f3->set('data.notes', $md->convert($this->D->notes));
     $f3->set('training_levels', $this->D->training_level_array());
     $images = \R::find('images', 'tools_id=? ORDER BY thumb DESC, id ASC', array($this->D->id));
     if ($images) {
         $f3->set('images', $images);
     }
     $f3->set('multiple_images', count($images) > 1);
     // Build Array of Training Records
     $trainings = \R::find('trainings', 'tools_id=?', array($this->D->id));
     $f3->set('trainings', $trainings ? reset($trainings)->build_lookup($trainings) : false);
     // Build Array of All Active Users in Groups
     $users = \R::find('users', 'active=1 ORDER BY usergroup ASC, displayname ASC');
     $f3->set('usergroups', $users ? reset($users)->group($users) : false);
     // Check if User can Train
     $f3->set('can_train', $f3->get('SESSION.active') && $f3->get('SESSION.admin') || \R::findOne('trainings', 'users_id=? AND tools_id=? AND level=?', array($f3->get('SESSION.id'), $this->D->id, 'T')));
     parent::info($f3);
 }
 protected function addMarkDownAndLinks($text)
 {
     return \Markdown::instance()->scan($this->makeLinks($text));
 }
Exemple #6
0
	<article>
		<h2><?php 
    echo HTML::anchor('post/' . $post->slug, HTML::chars($post->name));
    ?>
</h2>
		<p><small>
			Category : <?php 
    echo HTML::anchor('category/' . $post->category->slug, HTML::chars($post->category->name));
    ?>
,
			by <?php 
    echo HTML::anchor('author/' . $post->author->id, HTML::chars($post->author->username));
    ?>
 
				on <em><?php 
    echo date("D dS Y", strtotime($post->created));
    ?>
</em>
		</small></p>
		<p><?php 
    echo Text::limit_chars(HTML::chars(strip_tags(Markdown::instance()->transform($post->content))), 450);
    ?>
</p>
		<p class="text-right"><?php 
    echo HTML::anchor('post/' . $post->slug, 'Read more...', array('class' => 'btn btn-primary'));
    ?>
</p>
	</article>
	<hr>
<?php 
}
Exemple #7
0
 /**
  * Notify bucket owners and followers of a new comment
  * 
  * @return	void
  */
 public static function notify_new_bucket_comment($comment, $bucket)
 {
     $html = View::factory('emails/html/comment');
     $text = View::factory('emails/text/comment');
     $html->is_drop = $text->is_drop = FALSE;
     $html->from_name = $text->from_name = $comment->user->name;
     $html->avatar = Swiftriver_Users::gravatar($comment->user->email, 80);
     $html->from_link = URL::site($comment->user->account->account_path, TRUE);
     $html->asset = $text->asset = 'bucket';
     $html->asset_name = $text->asset_name = $bucket->bucket_name;
     $html->asset_link = $text->asset_link = URL::site($bucket->get_base_url(), TRUE);
     $html->link = $text->link = URL::site($bucket->get_base_url() . '/discussion#comment-' . $comment->id, TRUE);
     $text->comment = $comment->comment_content;
     $html->comment = Markdown::instance()->transform($comment->comment_content);
     $subject = __(':from commented on the ":name" bucket.', array(":from" => $comment->user->name, ":name" => $bucket->bucket_name));
     // Add owner of the bucket first
     $emails = array($bucket->user->email);
     // Then collaborators
     foreach ($bucket->get_collaborators(TRUE) as $collaborator) {
         $emails[] = $collaborator['email'];
     }
     // Then followers
     foreach ($bucket->subscriptions->find_all() as $follower) {
         $emails[] = $follower->email;
     }
     $text_body = $text->render();
     $html_body = $html->render();
     $site_email = Swiftriver_Mail::get_default_address();
     $from = '"' . $comment->user->name . '" <notifications@' . Swiftriver_Mail::get_email_domain() . '>';
     $token_data = array('bucket_id' => $comment->bucket_id);
     $token = Model_Auth_Token::create_token('bucket-comment', $token_data);
     $reply_to = 'bucket-comment-' . $token->token . '@' . Swiftriver_Mail::get_comments_email_domain();
     foreach ($emails as $email) {
         if ($email != $comment->user->email) {
             Swiftriver_Mail::send($email, $subject, $text_body, $html_body, $from, array('Reply-To' => $reply_to));
         }
     }
 }
Exemple #8
0
				Category : <?php 
echo HTML::anchor('category/' . $post->category->slug, HTML::chars($post->category->name));
?>
,
				by <?php 
echo HTML::anchor('author/' . $post->author->id, HTML::chars($post->author->username));
?>
 on <em><?php 
echo date("D dS Y", strtotime($post->created));
?>
</em>
			</small></p>
		</div>

		<article><?php 
echo Markdown::instance()->transform($post->content);
?>
</article>

		<hr>

		<section id="comments" class="comments">
			<h3>Comment this post</h3>

			<?php 
if (Session::instance()->get('flash_errors') != NULL) {
    $errors = Session::instance()->get_once('flash_errors');
    ?>
				<div class="alert alert-danger">
					<h4><strong>Oh snap !</strong> you did some errors</h4>
					<?php 
Exemple #9
0
/**
 * fat-free framework application
 * execute with call to FFMVC\App\Run();.
 *
 * @author Vijay Mahrra <*****@*****.**>
 * @copyright (c) Copyright 2013 Vijay Mahrra
 * @license GPLv3 (http://www.gnu.org/licenses/gpl-3.0.html)
 */
function Run()
{
    // @see http://fatfreeframework.com/quick-reference#autoload
    $f3 = (require_once 'lib/bcosca/fatfree-core/base.php');
    $f3->set('AUTOLOAD', __DIR__ . ';bcosca/fatfree-core/;lib/');
    // initialise application
    Main::start($f3);
    // user feedback messages helper, inisialise so methods can be called statically
    $messages = Helpers\Messages::instance();
    $messages->init();
    // setup database connection params
    // @see http://fatfreeframework.com/databases
    $db = null;
    if (!empty($f3->get('db.driver') || $f3->get('db.dsn') || $f3->get('db.http_dsn'))) {
        if ($http_dsn = $f3->get('db.http_dsn')) {
            if (preg_match('/^(?<driver>[^:]+):\\/\\/(?<username>[^:]+):(?<password>[^@]+)@(?<hostname>[^:]+):(?<port>[\\d]+)?\\/(?<database>.+)/', $http_dsn, $m)) {
                $f3->set('db.dsn', sprintf('%s:host=%s;port=%d;dbname=%s', $m['driver'], $m['hostname'], $m['port'], $m['database']));
                $f3->mset(array('db.driver' => $m['driver'], 'db.hostname' => $m['hostname'], 'db.port' => $m['port'], 'db.name' => $m['database'], 'db.username' => $m['username'], 'db.password' => $m['password']));
            }
        } elseif (empty($f3->get('db.dsn'))) {
            $f3->set('db.dsn', sprintf('%s:host=%s;port=%d;dbname=%s', $f3->get('db.driver'), $f3->get('db.hostname'), $f3->get('db.port'), $f3->get('db.name')));
        }
        if ($f3->get('db.driver') !== 'sqlite') {
            if ($dsn = $f3->get('db.dsn')) {
                $db = new \DB\SQL($dsn, $f3->get('db.username'), $f3->get('db.password'));
            }
        } else {
            $dsn = $f3->get('db.dsn');
            $dsn = substr($dsn, 0, strpos($dsn, '/')) . realpath('../') . substr($dsn, strpos($dsn, '/'));
            $db = new \DB\SQL($dsn);
            // attach any other sqlite databases - this example uses the full pathname to the db
            if ($f3->exists('db.sqlite.attached')) {
                $attached = $f3->get('db.sqlite.attached');
                $st = $db->prepare('ATTACH :filename AS :dbname');
                foreach ($attached as $dbname => $filename) {
                    $st->execute(array(':filename' => $filename, ':dbname' => $dbname));
                }
            }
        }
    }
    \Registry::set('db', $db);
    // cli start
    if (PHP_SAPI == 'cli') {
        $f3->route('GET /doc/@page', function ($f3, $params) {
            $filename = 'doc/' . strtoupper($params['page']) . '.md';
            if (!file_exists($filename)) {
                die("Documentation Error!\n\nNo such document exists!\n");
            } else {
                echo $f3->read($filename);
            }
        });
        // @see http://fatfreeframework.com/routing-engine
        //load routes from ini file
        $f3->config('config/routes-cli.ini');
    } else {
        // web start
        // custom error handler if debugging
        $f3->set('ONERROR', function () use($f3) {
            // recursively clear existing output buffers:
            while (ob_get_level()) {
                ob_end_clean();
            }
            if ($f3->get('ERROR.code') == '404' && stristr($f3->get('PATH'), '/api') == false) {
                include_once 'templates/www/error/404.phtml';
            } else {
                $debug = $f3->get('DEBUG');
                if (stristr($f3->get('PATH'), '/api') !== false) {
                    $response = Helpers\Response::instance();
                    $data = array('service' => 'API', 'version' => 1, 'time' => time(), 'method' => $f3->get('VERB'));
                    $e = $f3->get('ERROR');
                    $data['error'] = array('code' => substr($f3->snakecase(str_replace(' ', '', $e['status'])), 1), 'description' => $e['code'] . ' ' . $e['text']);
                    if ($debug == 3) {
                        // show the $e['trace'] but it's in HTML!
                    }
                    $params = array('http_status' => $e['code']);
                    $return = $f3->get('REQUEST.return');
                    switch ($return) {
                        case 'xml':
                            $response->xml($data, $params);
                            break;
                        default:
                        case 'json':
                            $response->json($data, $params);
                    }
                } else {
                    include_once $debug < 3 ? 'templates/www/error/error.phtml' : 'templates/www/error/debug.phtml';
                }
            }
            // http://php.net/manual/en/function.ob-end-flush.php
            ob_end_flush();
        });
        // clean ALL incoming user input by default
        foreach (array('GET', 'POST') as $var) {
            $input = $f3->get($var);
            if (is_array($input) && count($input)) {
                $cleaned = array();
                $request = array();
                foreach ($input as $k => $v) {
                    $k = strtolower(trim($f3->clean($k)));
                    $v = $f3->clean($v);
                    $cleaned[$k] = $v;
                    $request[$k] = $v;
                }
                $f3->set($var, $cleaned);
                $f3->set('REQUEST', array_merge($f3->get('COOKIE', array()), $request));
            }
        }
        // @see http://fatfreeframework.com/optimization
        $f3->route('GET /minify/@type', function ($f3, $args) {
            $type = $args['type'];
            $path = $f3->get('UI') . $type . '/';
            $files = str_replace('../', '', $_GET['files']);
            // close potential hacking attempts
            echo \Web::instance()->minify($files, null, true, $path);
        }, $f3->get('minify.ttl'));
        $f3->route('GET /doc/@page', function ($f3, $params) {
            $filename = 'doc/' . strtoupper($params['page']) . '.md';
            echo \View::instance()->render('www/header.phtml');
            if (!file_exists($filename)) {
                echo '<h1>Documentation Error</h1><p>No such document exists!</p>';
                $f3->status(404);
            } else {
                echo \Markdown::instance()->convert($f3->read($filename));
            }
            echo \View::instance()->render('www/footer.phtml');
        }, $f3->get('doc.ttl'));
        $f3->config('config/routes.ini');
    }
    $f3->run();
    // terminate application
    Main::finish($f3);
}