Пример #1
0
<?php

/**
 * Morfy Redirect Plugin
 *
 * (c) Romanenko Sergey / Awilum <*****@*****.**>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
Morfy::addAction('before_render', function () {
    if (isset(Morfy::$page['redirect'])) {
        Request::redirect(Morfy::$page['redirect']);
    }
});
    // Get current URI segments
    $path = Url::getUriSegments();
    array_pop($path);
    $path = implode('/', $path);
    // Get all posts
    $all_pages = Morfy::getPages($path, 'date', 'DESC', array('404', 'index'));
    // Count total posts
    $total_pages = count($all_pages);
    // Get current page path
    $current_path = Url::getUriString();
    // Get current page data
    $current_page = Morfy::getPage($current_path);
    // Testing...
    // echo $current_page['date'];
    // Find next and previous link from current page
    $prev_page = $next_page = false;
    for ($i = 0; $i < $total_pages; $i++) {
        if ($current_page['date'] == $all_pages[$i]['date']) {
            $prev_page = isset($all_pages[$i - 1]['url']) && !empty($all_pages[$i - 1]['url']) ? $all_pages[$i - 1]['url'] : false;
            $next_page = isset($all_pages[$i + 1]['url']) && !empty($all_pages[$i + 1]['url']) ? $all_pages[$i + 1]['url'] : false;
        }
    }
    unset($all_pages);
    // Pagination
    $nextprev_template->display('nav.tpl', array('config' => $nextprev_config, 'current' => 1, 'total' => $total_pages, 'prev' => $prev_page, 'next' => $next_page));
});
// Conditional action between `index_nextprev` and `item_nextprev`
Morfy::addAction('nextprev', function () {
    $path = trim(Url::getUriString(), '/');
    Morfy::runAction((file_exists(PAGES_PATH . '/' . $path . '/index.md') ? 'index' : 'item') . '_nextprev');
});
Пример #3
0
Morfy::addAction('Media', function () {
    // id of media item
    $id = Request::get('id');
    // Obtain json file on public folder
    $json = array();
    $mediaFile = ROOT_DIR . '/public/media/mdb.json';
    if (File::exists($mediaFile)) {
        /*
         *   Json Template 
         *   {
         *       "5606e4ad88ed0": { // id of album
         *           "id": "5606e4ad88ed0", // id of image folder album
         *           "title": "Album title", // title of album
         *           "desc": "Album description", // diescription of album
         *           "thumb": "/public/media/album_thumbs/album_5606e4ad88ed0.jpg", // image preview of album
         *           "images": "/public/media/albums/album_5606e4ad88ed0", // images album
         *           "tag": "Nature", // tag of album for filter with javascript
         *           "width": "700", // style width of tumb
         *           "height": "400" // style height of tumb
         *       }
         *   }
         *
         */
        $json = json_decode(File::getContent($mediaFile), true);
    } else {
        die('OOps Whrere is media.json file!');
    }
    // get single id of album or all albums
    if (Request::get('action') == 'view' && Request::get('id')) {
        // id of album
        $id = Request::get('id');
        if ($id) {
            // get id on json
            $media = $json[$id];
            // get all images of this album
            $mediaImages = File::scan(ROOT_DIR . $media['images']);
            // get images of this album
            $albumImages = '';
            // check files
            if (count($mediaImages) > 0) {
                foreach ($mediaImages as $image) {
                    $albumImages .= '<img class="thumbnail img-responsive" src="public/media/albums/album_' . $id . '/' . File::name($image) . '.' . File::ext($image) . '">';
                }
            }
            // template
            $templateSingle = '<h3>' . toHtml($media['title']) . '</h3>
            ' . toHtml($media['desc']) . '
            <p><b>Tag: </b><span class="label label-info">' . toHtml($media['tag']) . '</span></p>' . $albumImages;
            // return
            echo $templateSingle;
        }
    } else {
        // all media files
        $templateAll = '';
        foreach ($json as $media) {
            $templateAll .= '<figure>
                <img width="' . $media['width'] . '" height="' . $media['height'] . '" src="' . Morfy::$site['url'] . $media['thumb'] . '"/>
                <figcaption>
                    <a href="' . Morfy::$site['url'] . '/media?action=view&id=' . $media['id'] . '" title="' . toHtml($media['title']) . '">' . toHtml($media['title']) . '</a>
                </figcaption>
            </figure>';
        }
        // check json file if not empty
        if (count($json) > 0) {
            echo $templateAll;
        } else {
            echo '<div class="alert alert-danger">Empty Media albums</div>';
        }
    }
});
Пример #4
0
<?php

/**
 * Morfy Sitemap Plugin
 *
 * (c) Romanenko Sergey / Awilum <*****@*****.**>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
if (Url::getUriSegment(0) == 'sitemap.xml') {
    Morfy::addAction('before_render', function () {
        $fenom = Fenom::factory(PLUGINS_PATH . '/sitemap/templates/', CACHE_PATH . '/fenom/', Morfy::$fenom);
        $fenom->setOptions(array("strip" => false));
        $pages = Morfy::getPages('', 'date', 'DESC', array('404'));
        Response::status(200);
        Request::setHeaders('Content-Type: text/xml; charset=utf-8');
        $fenom->display('sitemap.tpl', array('pages' => $pages));
        Request::shutdown();
    });
}
Пример #5
0
<?php

/**
 *  Statistics plugin for Morfy
 *
 *  @package Morfy
 *  @subpackage Plugins
 *  @author Pavel Belousov / pafnuty
 *  @version 2.0.0
 *  @license https://github.com/pafnuty/morfy-statistics/blob/master/LICENSE MIT
 *
 */
require_once PLUGINS_PATH . '/statistics/ShowStatistics.php';
Morfy::addAction('plugins_loaded', function () {
    global $statistics;
    $statistics = new ShowStatistics();
});
Morfy::addAction('after_render', function () {
    global $statistics;
    echo $statistics->showStat();
});
Пример #6
0
<?php

/**
 *  Asset Plugin
 *
 *  @package Morfy
 *  @subpackage Plugins
 *  @author Pavel Belousov / pafnuty
 *  @version 1.1.0
 *  @license https://github.com/pafnuty/morfy-plugin-asset/blob/master/LICENSE MIT
 */
require_once PLUGINS_PATH . '/asset/asset.class.php';
Morfy::addAction('asset_folder', function (array $folders = array(), array $excludes = array()) {
    $assetConfig = Morfy::$plugins['asset'];
    $folders = array_unique(array_filter(array_merge($folders, (array) $assetConfig['folders'])));
    $excludes = array_unique(array_filter(array_merge($excludes, (array) $assetConfig['excludes'])));
    foreach ($folders as $k => $folder) {
        $folders[$k] = '/themes/' . Morfy::$site['theme'] . $folder;
    }
    Asset::add($folders, $excludes);
});
Morfy::addAction('asset_file', function ($fileName = '', $attributes = '') {
    if ($fileName != '') {
        $fileName = '/themes/' . Morfy::$site['theme'] . $fileName;
        Asset::addFile($fileName, $attributes);
    }
});