function __construct ($name) { $apps = Frix::config('APPS'); // Check if app is installed or throw an exception if (!array_key_exists($name, $apps)) { throw new AppException(sprintf('Application "%s" not installed!', $name)); } // Set name $this->name = $name; // Use the class-name to create verbose_name if it's not set $v_name = preg_replace('/App$/', '', get_class($this)); def($this->verbose_name, $v_name); // Configure the application path // $this->path = join_path(array(Frix::config('ROOT'), $apps[$name])); $this->path = $apps[$name]; // Setup models and views path def($this->views_path, join_path(array($this->path, 'views.php'))); def($this->models_path, join_path(array($this->path, 'models'))); }
function find_template ($template) { // Template param may be a string or an array // If it's not an array, put the string in a new array if (!is_array($template)) { $template = array($template); } // Loop through template paths config foreach (Frix::config('TEMPLATE_PATHS') as $path) { foreach ($template as $template_file) { $template_path = join_path(array($path, $template_file . '.php')); if (file_exists($template_path)) { return $template_path; } } } // No template found? Throw an exception. // debug($template); throw new TemplateException(sprintf('Template(s) "%s" not found!', implode('", "', $template))); }
function create_fields () { // Load CmsPage related model (fix this...) // TODO: find out a way to get the app module through the model $app = Frix::model('cms', 'CmsPage'); $this->add_fields(array( 'parent' => new ForeignKey('Parent Page', array('model_name' => 'CmsPage', 'null' => True)), 'name' => new CharField('Name', array('length' => 80)), 'file' => new FileField('File', array('length' => 100, 'path' => 'cms/file')), // 'visible' => new BooleanField('Visible'), )); }
static function flash ($src, $width, $height, $get = '', $params = array()) { $src = url(Frix::config('MEDIA_URL'), $src); $get = ($get ? '?' : '') . $get; $context = array( 'src' => $src . $get, 'src_no_ext' => dirname($src) . '/' . basename($src, '.swf') . $get, 'width' => $width, 'height' => $height, ); // Load template and render $t = new Template('frix/html/flash'); return $t->render($context); }
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title><?php echo Frix::config('PROJECT_TITLE'); ?> -- Error <?php echo $error_code; ?> </title> </head> <body> <h1>Error: <?php echo $error_code; ?> </h1> <p><?php echo $error_msg; ?> </p> </body> </html>
function get_absolute_url () { return url(Frix::config('WEB_ROOT'), $this->slug); }
static function model ($app_name, $name) { Frix::app($app_name)->load_model($name); }
<? Frix::model('cms', 'CmsFile'); class CmsImage extends CmsFile { function setup ($meta) { $meta->verbose_name = 'Image'; } function create_fields () { parent::create_fields(); $this->add_field( 'file', new ImageField('File', array('length' => 100, 'path' => 'cms/image')) ); } static public function meta() { return ModelMeta::meta(get_class()); } } ?>
<? /* PLEASE DON'T CODE HERE! This file is a placeholder to your project-root and the link between your project and the Frix framework. You may specify a different config file using: Frix::start('path/to/config/file.php'); */ // Load Frix and required libs require_once('../frix/main.php'); // Start FRIXing Frix::start(); ?>
<? $this->extend('frix/admin/base') ?> <? block('scripts') ?> <script type="text/javascript" src="<?php echo url(Frix::config('FRIX_MEDIA'), 'gz.php?file=admin/js/j.js'); ?> "></script> <script type="text/javascript" src="<?php echo url(Frix::config('FRIX_MEDIA'), 'gz.php?file=admin/js/add_change.js'); ?> "></script> <? end_block() ?> <? $this->block('contents') ?> <form <?php echo Template::attrs($form->attrs); ?> enctype="multipart/form-data"> <?php echo $form->render_fields(); ?> <? foreach ($inlines as $inline): ?> <fieldset class="inline"> <h3><?php echo $inline->meta->verbose_name_plural; ?> </h3> <table> <?
redir('../?msg=changed'); } } // Get form and password field $f = $this->get_form(); $password = $f->fields['password']; // Enable and clear password field $password->editable = true; $password->value = ''; // Move password field to the end unset($f->fields['password']); $f->fields['password'] = $password; // Add password confirmation field $f->add_field('password_conf', new PasswordField('Confirm')); $context['form'] = $f; $context['inlines'] = $this->get_inlines(); } } // Register Frix::app('admin')->register('AuthUser', 'AuthUserOptions'); ?>
function get_thumb ($width = null, $height = null) { load('Image'); $path = $this->get_real_path(); // Value to append to the thumbnail filename $extra = '_t'; // Append width and/or height if size changed if ($width) { $extra .= '_w' . $width; } if ($height) { $extra .= '_h' . $height; } // Split file path and change file name $path_info = pathinfo($path); $path_info['filename'] .= $extra; // Join path together $new_path = sprintf('%s/%s.%s', $path_info['dirname'], $path_info['filename'], $path_info['extension']); // If the thumbnail doesn't exists or the original has been modified if (!file_exists($new_path) || (filemtime($path) > filemtime($new_path))) { // Create image object $i = Image::open($path); // Adjust size $i->fit($width, $height); $i->save_as($new_path); } return url(Frix::config('MEDIA_URL'), $this->path, sprintf('%s.%s', $path_info['filename'], $path_info['extension'])); }
<? // Get models Frix::model('settings', 'SettingsProperty'); class SettingsPropertyOptions extends AdminOptions { public $list_display = array('name', 'value'); public $can_add = false; public $can_delete = false; public $can_change = true; } // Register Frix::app('admin')->register('SettingsProperty', 'SettingsPropertyOptions'); ?>
function app ($app_name) { // Get the app $this->context_app($app_name); $registry = Frix::app('admin')->registry[$app_name]; // If there's only one model, redirect to the model page if (count($registry) == 1) { $first = reset($registry); redir(self::$root . $first->meta->admin_url); } // Get the meta models // $models = array(); // foreach ($registry as $k => $options) { // $models[$k] = $options->meta; // } // Save model-list into the context self::$context['models_options'] = $registry; $t = new Template( sprintf('frix/admin/%s/app', $app_name), 'frix/admin/app' ); echo $t->render(self::$context); }
<? endforeach; ?> </ul> </div> </div> <div id="main"> <div id="contents"> <? block('contents') ?><? end_block() ?> </div> <div id="sidebar"> <? block('sidebar') ?> <div class="box"> <h3>Pages</h3> <ul> <? foreach (Frix::app('cms')->get_root_pages() as $item): ?> <li><a href="<?php echo $item->slug; ?> /"><?php echo $item->title; ?> </a></li> <? endforeach; ?> </ul> </div> <? end_block() ?> </div> </div> </div>
function contact () { if ($_GET['sent']) { return $this->page('contact', array('sent' => True)); } $f = new Form(); $f->add_fields(array( 'name' => new CharField('Name', array('length' => 100)), 'email' => new CharField('E-mail', array('length' => 100)), 'message' => new TextField('Message'), )); $context = array( 'contact_form' => $f, ); if ($_SERVER['REQUEST_METHOD'] == 'POST') { $f->input($_POST); if ( !($_POST['name'] && $_POST['email'] && $_POST['message']) ) { $context['error'] = 'All fields are required. Please complete the form.'; } elseif (!validate_email($_POST['email'])) { $context['error'] = 'Invalid e-mail address.'; } else { // Get e-mail address from the Settings app $to = Frix::app('settings')->get('contact_email'); // Send the e-mail $ok = send_mail('Contact', $f->get_message(), $f->get_email(), $to); // Error sending the message? if (!$ok) { $context['error'] = 'Couldn\'t send message, please try again later.'; } else { redir('./?sent=1'); } } } return $this->page('contact', $context); }
function run_view () { // Get an instance of an app and load the views $this->app = Frix::app($this->app_name); // Check if the class is valid and the method exists if (method_exists($this->app->views, $this->view_name)) { // Call the view method passing params found by check_route call_user_func_array(array(&$this->app->views, $this->view_name), $this->params); // Return success return true; } // No view found, throw an error! throw new RouterNoViewException(sprintf('View "%s" not found on app "%s".', $this->view_name, $this->app_name)); }
<? // Get models Frix::model('cms', 'CmsPage'); Frix::model('cms', 'CmsFile'); Frix::model('cms', 'CmsImage'); Frix::model('cms', 'CmsVideo'); Frix::model('cms', 'CmsMenu'); Frix::model('cms', 'CmsMenuItem'); class CmsPageOptions extends AdminOptions { public $inlines = array('CmsFile', 'CmsImage', 'CmsVideo'); public $list_display = array('title', 'slug', 'visible'); public $custom_position = 'pos'; } class CmsMenuOptions extends AdminOptions { public $inlines = array('CmsMenuItem'); } // Register Frix::app('admin')->register('CmsPage', 'CmsPageOptions'); Frix::app('admin')->register('CmsMenu', 'CmsMenuOptions'); ?>
<? extend('frix/admin/base') ?> <? if ($popup): ?> <? block('body_attr') ?> id="filebrowser" class="popup"<? end_block() ?> <? block('scripts') ?> <script type="text/javascript" src="<?php echo url(Frix::config('FRIX_MEDIA'), 'gz.php?file=admin/js/j.js'); ?> "></script> <? end_block() ?> <? else: ?> <? block('body_attr') ?> id="filebrowser"<? end_block() ?> <? endif; ?> <? block('contents') ?> <div id="quick_forms"> <form action="./" method="post"> <p> <label> <input type="text" name="dir_name" /> </label> <span class="button"><input type="submit" name="new_dir" value="Create Folder" /></span> </p> </form> <form action="./" method="post" enctype="multipart/form-data"> <p> <label> <input type="file" name="file" /> </label> <span class="button"><input type="submit" name="new_file" value="Upload File" /></span>