Giter Site home page Giter Site logo

cockpit-lib-skeleton's Introduction

Cockpit CMS library skeleton

If you want to keep your docs root clean while using Cockpit, you can use this skeleton to rearrange the file structure and to include cockpit as a library. You can use cockpit like before - with some advantages:

  • Add your own favicon.
  • Add your own files to the root without messing up the cockpit installation.
  • You can use your root as an own git repository.
  • ...

File structure

After doing all steps described under Installation, your file structure should look like this:

.
├── cpdata
│   ├── addons
│   ├── config
│   └── storage
├── lib
│   └── cockpit
│   .htaccess
│   bootstrap.php
│   cp
│   defines.php
│   index.php
│   ...

Installation

Navigate to your docs root or to the sub folder, where you want to run cockpit.

# cd into docs root
cd ~/html

Copy the files inside /html from this repository into your docs root:

# load repo, unzip, copy into current dir and delete temp files
wget -q -O temp.zip https://github.com/raffaelj/cockpit-lib-skeleton/archive/master.zip
unzip -q temp.zip && mv cockpit-lib-skeleton-master/html/{.[!.],}* .

# optional: delete the unzipped folder
# rm -r cockpit-lib-skeleton-master

# delete temp file
rm temp.zip

Copy Cockpit into /lib/cockpit:

# clone latest cockpit (next branch)
git clone https://github.com/agentejo/cockpit.git lib/cockpit

# change environment root
cat > defines.php <<EOF
<?php
define('COCKPIT_ENV_ROOT', str_replace(DIRECTORY_SEPARATOR, '/', __DIR__) . '/cpdata');
EOF

Create cpdata folder, create config and addons directories in it and copy the core storage folder. You can delete the .gitignore files.

mkdir -p cpdata/{config,addons}

# copy storage folder and remove .gitignore files
cp -r lib/cockpit/storage cpdata
find cpdata/storage/ -name .gitignore -exec rm {} +

Optional: clone addons into /cpdata/addons, e. g.:

git clone https://github.com/raffaelj/cockpit_UniqueSlugs.git cpdata/addons/UniqueSlugs

Create a config file:

cat > cpdata/config/config.yaml <<EOF
app.name: cp lib
EOF

You can't run the install routine in the browser via example.com/lib/cockpit/install, because the access is denied via .htaccess and the constant COCKPIT_ENV_ROOT wouldn't be recognized. Create the first admin user with password "admin" via command line instead.

# generate hashed password
./cp account/generate-password --passwd admin

# copy/paste the output and create account
./cp account/create --user admin --email '[email protected]' --passwd '$2y$10$fGd3stGM8YASqLsTCQWr0uq/OikGiZeUTXqynqJYMKdzFuPV9ytTK'

Now open your site in the web browser, e. g. example.com and you should be redirected to example.com/auth/login, where you can login with admin/admin.

How to build the skeleton from scratch

Copy some files from the orginal cockpit repository:

  • cp
  • index.php
  • .htaccess

Modify .htaccess and add the following line(s) to the top of the file

# Deny direct access to library files
RedirectMatch 403 ^.*/lib/(.*)\.php$

Create a file bootstrap.php:

  • include optional defines.php
  • define COCKPIT_DOCS_ROOT, COCKPIT_BASE_URL and COCKPIT_BASE_ROUTE. You can copy the snippets from the core bootstrap file.
  • bootstrap Cockpit with require(__DIR__.'/lib/cockpit/bootstrap.php');
  • hook into the app.layout.header event and add a js snippet to fix wrong paths in the admin ui.
$cockpit->on('app.layout.header', function() {
    echo '<script>
        App.base_url = (App.base_url + "/lib/cockpit/").replace(/\/$/, "");
        App.env_url = "'. $this->pathToUrl(COCKPIT_ENV_ROOT) .'";
        App.base = function(url) {
            return url.indexOf("/addons") === 0 || url.indexOf("/config") === 0 ? this.env_url+url : this.base_url+url;
        };
        App.route = function(url) {
            if (url.indexOf("/assets") === 0 && url.indexOf("/assetsmanager") !== 0) {
                return this.base_route+"/lib/cockpit"+url;
            }
            if (url.indexOf("/addons") === 0 || url.indexOf("/config") === 0) {
                return this.env_url+url;
            }
            return this.base_route+url;
        };
    </script>';
});

Credits/License

Some files and snippets are copied from the core Cockpit CMS, author: Artur Heinze, www.agentejo.com, MIT License

Everything else: Raffael Jesche, MIT License

cockpit-lib-skeleton's People

Contributors

raffaelj avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

cockpit-lib-skeleton's Issues

How to instantiate cockpit inside a class?

I am trying to use this template with an existing code. I am confused how can I instantiate cockpit inside my class? Please help. Currently, I am using following structure. Is there any more object oriented way to do so by inheriting?

class A
{
    private $cockpit;
    public function __construct()
    {
        include_once(__DIR__.'/bootstrap.php');
        $this->cockpit=getCP();
    }
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.