public function newID()
 {
     //$str = DATA_ROOT.'/'.$folder.'/';
     //$str = tempnam(DATA_ROOT.'/'.$folder.'/', 'foo');
     $str = strtoupper(date('Y-m-d-His') . '-' . eatStatic::createRandomString(5));
     return $str;
 }
 function __construct()
 {
     global $stub, $path, $file_name, $gallery, $width, $url;
     switch ($path[1]) {
         case "":
             /**
              * this should be a folder, so if it isn't there, return page not found
              */
             $stub = "";
             break;
         default:
             switch ($path[2]) {
                 case "":
                     $stub = "";
                     break;
                 default:
                     /**
                      * this should be a filename
                      */
                     if (!eatStatic::fileNameOK($path[2])) {
                         $stub = "";
                     } else {
                         /**
                          * images URL's are expected to be in format:-
                          * /images/(galleryname)/(filename)_(width).jpg
                          * e.g. /images/misc/mypic_500.jpg
                          */
                         if (preg_match('|^/images/([^/.]+)/([^/]+)_([0-9]+).([^/]+)|', $url, $matches)) {
                             //print_r($matches);
                             $file_name = $matches[2] . '.' . $matches[4];
                             $gallery = $matches[1];
                             $width = $matches[3];
                             //print_r($matches);
                             //die('ok');
                             $stub = "scripts/image_cache.php";
                         } else {
                             $stub = "";
                             //die('here');
                         }
                     }
                     break;
                     // /scripts/image_cache.php?file_name=$2.$4&gallery=$1&width=$3
             }
             break;
     }
 }
 /**
  * @desc return file type based on extension
  */
 function getFileType($filename)
 {
     switch (strtolower(eatStatic::getExtension($filename))) {
         case "jpg":
             $type = 'image/jpeg';
             break;
         case "gif":
             $type = 'image/gif';
             break;
         case "png":
             $type = 'image/png';
             break;
         case "mov":
             $type = 'video/quicktime';
             break;
     }
     return $type;
 }
 private function listContents($sub_path = '')
 {
     $lib = new eatStaticMediaLibrary(DATA_ROOT . '/images/', $sub_path . '/');
     $page = new adminPage('images.php');
     // handle image upload
     if (eatStatic::getValue('postback', 'post') == "1") {
         $image = $lib->upload('images', $sub_path, 'file', 'image');
         if ($image != '') {
             $page->context['message'] = $image . ' uploaded';
         } else {
             $page->context['message'] = 'file not uploaded';
         }
     }
     // create new folder
     if (eatStatic::getValue('postback', 'post') == "2") {
         if (eatStatic::getValue('folder', 'post')) {
             $folder = $lib->createSubFolder(eatStatic::getValue('folder', 'post'));
         }
     }
     $page->context['contents'] = $lib->getContents();
     $page->context['title'] = "Images";
     $page->context['sub_path'] = $sub_path;
     $page->render();
 }
Exemple #5
0
<?php

eatStatic::template('page_top.php');
eatStatic::template('body_top.php');
?>
<div class="post">
<?php 
echo $page->content;
?>
</div>
<?php 
eatStatic::template('body_bottom.php');
eatStatic::template('page_bottom.php');
Exemple #6
0
<?php

require '../eatStatic_config.php';
// check data folder exists
if (file_exists(DATA_ROOT)) {
    echo 'Data folder exists at: ' . DATA_ROOT . '<br />';
} else {
    echo 'Data folder does not exist at: ' . DATA_ROOT . '<br />';
}
// check data folder is writable
if (eatStatic::write_file('setup test (written by /scripts/setup.php)', DATA_ROOT . '/.setup-test.txt')) {
    echo 'Data folder is writeable <br />';
} else {
    echo 'Data folder is not writeable <br />';
}
if (unlink(DATA_ROOT . '/.setup-test.txt')) {
    echo 'Data folder content can be deleted <br />';
}
// check cache folder exists
if (file_exists(DATA_ROOT . '/cache')) {
    echo 'Cache folder exists <br />';
} else {
    echo 'Cache folder does not exist - creating.. <br />';
    if (mkdir(DATA_ROOT . '/cache', 0775)) {
        echo 'Cache folder created <br />';
    }
}
// check cache/tags folder exists
if (file_exists(DATA_ROOT . '/cache/tags')) {
    echo 'Tag cache folder exists <br />';
} else {
Exemple #7
0
 case "feed":
     $stub = "rss.php";
     break;
     /**
      * if we haven't found a match yet, try against simple page engine
      */
 /**
  * if we haven't found a match yet, try against simple page engine
  */
 default:
     $stub = "";
     // in case no other matches are found below, set this so the user gets a 404
     /**
      * simple page engine - see if there is a file named e.g. page_<slug>.php in the root
      */
     if (eatStatic::slugFormatOk($path[0]) && file_exists(ROOT . "/page_" . $path[0] . ".php")) {
         $stub = "page_" . $path[0] . ".php";
     }
     /**
      * [TODO]: here is where we could redirect to EatStaticCMS engine 
      * looking for matching folder paths
      */
     if ($stub == '') {
         require_once EATSTATIC_ROOT . "/eatStaticTree.class.php";
         $tree = new eatStaticTree(DATA_ROOT . '/pages/');
         $page = $tree->getPage(trim($url, "/"));
         if (is_object($page)) {
             $stub = 'base_page.php';
         }
     }
     break;
Exemple #8
0
    						 <a class="btn btn-primary" href="/about">Read More</a>
    						</div>
    						<?php 
}
?>
    					<a class="twitter-timeline" href="https://twitter.com/campervanthings" data-widget-id="301036070043262976">Tweets by @campervanthings</a>
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>

    				</div>
    			</div><!-- /.row-fluid -->				

				<hr />
				<footer>
			
					<?php 
echo eatStatic::block("footer");
?>

				</footer>
				
		</div><!-- container -->

	<?php 
// if(DISQUS_ENABLED){
// 	require ROOT.'/skin/global/templates/disqus_js_embed.php';
// }
?>
	<script type="text/javascript">
	var galleries = Array();
	<?php 
if (isset($blog)) {
 function __construct($path)
 {
     require_once EATSTATIC_ROOT . '/eatStaticCSRF.class.php';
     $csrf = new eatStaticCSRF();
     switch ($path[2]) {
         case "":
             $page = new adminPage('login_form.php');
             if (eatStatic::getValue('postback', 'post') == '1') {
                 $csrf->verifyRequest();
                 $email = eatStatic::getValue('email', 'post');
                 $password = eatStatic::getValue('password', 'post');
                 if ($this->validUser($email, $password)) {
                     $_SESSION['admin'] = 1;
                     $_SESSION['admin_user'] = $email;
                     eatStaticAdminController::redirect("");
                 } else {
                     $page->context['error_message'] = 'Invalid username or password';
                 }
             }
             $page->context['title'] = "Log in";
             $page->context['show_navbar'] = false;
             $page->context['body_class'] = 'login-page';
             $page->context['csrf'] = $csrf;
             $page->render();
             break;
     }
 }
 private function deletePost($slug)
 {
     $post = new eatStaticBlogPost();
     if (file_exists(DATA_ROOT . '/posts/' . $slug . '.txt')) {
         $post->data_file_path = DATA_ROOT . '/posts/' . $slug . '.txt';
     }
     if (file_exists(DATA_ROOT . '/posts/' . $slug . '.md')) {
         $post->data_file_path = DATA_ROOT . '/posts/' . $slug . '.md';
     }
     if (file_exists($post->data_file_path)) {
         $post->hydrate();
         copy($post->data_file_path, DATA_ROOT . '/posts/backup/' . $post->file_name . '.' . eatStatic::timestamp() . '.bak');
         unlink($post->data_file_path);
         header('location:' . ADMIN_ROOT . 'posts/');
         die;
     }
 }
 /**
  * @desc convenience method to get a link to cached image
  */
 function imgLink($filename, $path, $width)
 {
     $cached_filename = str_replace('.' . eatStatic::getExtension($filename), '_' . $width . '.' . strtolower(eatStatic::getExtension($filename)), $filename);
     return $path . $cached_filename;
 }
 function hydrate()
 {
     $this->raw_data = $this->read_file($this->data_file_path);
     if ($this->raw_data == '') {
         // no post content found
     }
     $ext = $this->getExtension($this->data_file_path);
     if ($ext == 'md') {
         $this->source_format = 'markdown';
         require_once LIB_ROOT . "/php-markdown/Markdown.inc.php";
     }
     $parts = explode("\n", $this->raw_data);
     $str = '';
     $format_str = '';
     // get title from first line
     $this->title = $parts[0];
     $body = true;
     $meta = false;
     $raw_body = '';
     $raw_meta = '';
     // the rest is body
     for ($i = 1; $i < sizeof($parts); $i++) {
         $str = $str . $parts[$i];
         if ($i > 1) {
             // the body section can be the rest of the file,
             // or you can mark the end of the body section with --
             // you can then put meta data fields in the file
             if (eatStatic::stripLineBreaks($parts[$i]) == '--' && $meta == false) {
                 $body = false;
                 $meta = true;
             }
             if ($body) {
                 $raw_body = $raw_body . $parts[$i] . "\n";
                 // formatted body - for text format, line breaks need to be replaced with br, but not between html elements
                 if ($this->source_format == 'text') {
                     if (substr($parts[$i], -1) != '>') {
                         $format_str = $format_str . $parts[$i] . "<br />\n";
                     } else {
                         $format_str = $format_str . $parts[$i] . "\n";
                     }
                 }
             }
             // get meta info
             if ($meta && eatStatic::stripLineBreaks($parts[$i]) != '--') {
                 //die('meta:'.$parts[$i]);
                 if ($parts[$i] != '') {
                     $this->handleMeta($parts[$i]);
                     $raw_meta = $raw_meta . $parts[$i] . "\n";
                 }
             }
         }
     }
     if ($this->source_format == 'markdown') {
         // remove hashes from title
         $this->title = str_replace('#', '', $this->title);
         // parse the markdown into HTML
         $this->formatted_body = Michelf\Markdown::defaultTransform($raw_body);
     } else {
         $this->formatted_body = $format_str;
     }
     $this->raw_body = $raw_body;
     $this->raw_meta = $raw_meta;
     $this->body = $str;
     $this->file_name = basename($this->data_file_path);
     if ($this->source_format == 'markdown') {
         $this->slug = str_replace('.md', '', $this->file_name);
     } else {
         $this->slug = str_replace('.txt', '', $this->file_name);
     }
     $this->date = substr($this->file_name, 0, 10);
     $this->slug_trimmed = str_replace($this->date . '-', '', $this->slug);
     $this->nice_date = date(NICE_DATE_FORMAT, strtotime($this->date));
     $this->timestamp = strtotime($this->date);
     // get gallery items if there are any
     $gallery = new eatStaticGallery($this->slug . '/');
     $this->gallery_items = $gallery->gallery_items;
     // set up the URI
     if (WP_URLS) {
         $date_str = date('Y', strtotime($this->date)) . '-' . date('m', strtotime($this->date)) . '-' . date('d', strtotime($this->date));
         $this->uri = SITE_ROOT . date('Y', strtotime($this->date)) . '/' . date('m', strtotime($this->date)) . '/' . date('d', strtotime($this->date)) . '/' . str_replace($date_str . '-', '', $this->slug) . '/';
     } else {
         $this->uri = SITE_ROOT . 'posts/' . $this->slug . PAGE_EXT;
     }
     // get the next and previous urls
     $blog = new eatStaticBlog();
     $blog->getPostFiles();
     foreach ($blog->post_files as $key => $val) {
         if ($val == $this->data_file_path) {
             if ($key > 0) {
                 $this->prev_url = $this->uriFromFilename(basename($blog->post_files[$key - 1]));
             }
             if ($key < count($blog->post_files) - 1) {
                 $this->next_url = $this->uriFromFilename(basename($blog->post_files[$key + 1]));
             }
         }
     }
 }
 public function save()
 {
     $json_file = CACHE_ROOT . '/tags/' . $this->fileNameFromName();
     if (file_exists($json_file)) {
         // TODO make backup - timestamp + username in filename
     }
     eatStatic::write_file(json_encode($this), $json_file);
 }