示例#1
0
 public function getContent()
 {
     $url = URL::assemble(Config::getSiteRoot(), $this->fetchConfig('globals_url', null, null, false, false));
     $content = ContentService::getContentByUrl($url);
     $content = current($content->extract());
     return $content;
 }
示例#2
0
 /**
  * Retrieve the parent page
  * @return Array Array containing the content of the parent page
  */
 private function getParent()
 {
     $parent = URL::assemble(URL::popLastSegment(URL::getCurrent()));
     if (Taxonomy::isTaxonomyURL($parent)) {
         $parent = URL::popLastSegment($parent);
     }
     return Content::get($parent);
 }
 public function index()
 {
     // we need the local path
     if (!isset($this->context['_local_path'])) {
         return '';
     }
     // local path exists, return the correct format
     $path = Config::get('_admin_path') . '.php/publish?path=' . substr($this->context['_local_path'], 1, strrpos($this->context['_local_path'], '.') - 1);
     return URL::assemble(Config::getSiteRoot(), $path);
 }
示例#4
0
	public function render()
	{
		// Let's make sure they set an upload destination
		if (array_get($this->field_config, 'destination', false) === false) {
			throw new Exception("You need to set a destination for your File field.");
		}

		// Normalize the destination
		$this->destination = trim(array_get($this->field_config, 'destination'), '/') . '/';

		// Allow a string or an array, but we want an array
		$has_data = ($this->field_data != '');
		$this->field_data = Helper::ensureArray($this->field_data);

		// Clean up {{ _site_root }} and lack of leading slash existence
		foreach ($this->field_data as $i => $file) {
			$this->field_data[$i] = URL::tidy('/' . str_replace('{{ _site_root }}', '', $file));
		}

		// Whether or not to allow the browse existing files functionality
		$allow_browse = array_get($this->field_config, 'browse', true);

		// Resizing config
		if ($resize = array_get($this->field_config, 'resize')) {
			$resize['resize'] = true;
			$resize = http_build_query($resize);
		}

		// If we're in a subdirectory, prepend it to all the filenames
		if (($site_root = Config::getSiteRoot()) != '/') {
			foreach ($this->field_data as $i => $file) {
				$this->field_data[$i] = URL::assemble($site_root, $file);
			}
		}

		// Send data to the view
		$vars = array(
			'field_id'     => $this->field_id,
			'field_name'   => $this->fieldname,
			'tabindex'     => $this->tabindex,
			'has_data'     => $has_data,
			'field_data'   => $this->field_data,
			'field_config' => $this->field_config,
			'destination'  => $this->destination,
			'allow_browse' => $allow_browse,
			'server_files' => ($allow_browse) ? json_encode($this->tasks->generateModal($this->field_config, $this->destination)) : null,
			'file_thumb'   => URL::assemble(Config::getSiteRoot(), Config::get('admin_path'), 'themes', Config::get('admin_theme'), '/img/file.png'),
			'resize'       => $resize
		);
		$template = File::get($this->getAddonLocation() . 'views/fieldtype.html');

		return Parse::template($template, $vars);
	}
 public function render()
 {
     // Generate a hash unique to this field's config and data
     $hash = Helper::makeHash($this->field_config, $this->field_data);
     // If we've already saved the output, grab it from blink's cache
     // and avoid further processing.
     if ($this->blink->exists($hash)) {
         $html = $this->blink->get($hash);
         return $this->renderFieldReplacements($html);
     }
     // Let's make sure they set an upload destination
     if (array_get($this->field_config, 'destination', false) === false) {
         throw new Exception("You need to set a destination for your File field.");
     }
     // Normalize the destination
     $this->destination = trim(array_get($this->field_config, 'destination'), '/') . '/';
     // Allow a string or an array, but we want an array
     $has_data = $this->field_data != '';
     $this->field_data = Helper::ensureArray($this->field_data);
     // Clean up {{ _site_root }} and lack of leading slash existence
     foreach ($this->field_data as $i => $file) {
         $this->field_data[$i] = URL::tidy('/' . str_replace('{{ _site_root }}', '', $file));
     }
     // Whether or not to allow the browse existing files functionality
     $allow_browse = array_get($this->field_config, 'browse', true);
     // Resizing config
     if ($resize = array_get($this->field_config, 'resize')) {
         $resize['resize'] = true;
         $resize = http_build_query($resize);
     }
     // If we're in a subdirectory, prepend it to all the filenames
     if (($site_root = Config::getSiteRoot()) != '/') {
         foreach ($this->field_data as $i => $file) {
             $this->field_data[$i] = URL::assemble($site_root, $file);
         }
     }
     // Send data to the view
     $vars = array('field_id' => $this->field_id, 'field_name' => $this->fieldname, 'tabindex' => $this->tabindex, 'has_data' => $has_data, 'field_data' => $this->field_data, 'field_config' => $this->field_config, 'destination' => $this->destination, 'allow_browse' => $allow_browse, 'browse_url' => URL::assemble(Config::getSiteRoot(), Config::get('admin_path') . '.php/files?config=' . rawurlencode(Helper::encrypt(serialize($this->field_config)))), 'file_thumb' => $this->tasks->defaultFileThumbnail(), 'resize' => $resize);
     // Get the view template from the file
     $template = File::get($this->getAddonLocation() . 'views/fieldtype.html');
     // Parse it
     $html = Parse::template($template, $vars);
     // Save it to cache for other similar fields
     $this->blink->set($hash, $html);
     // Output!
     return $this->renderFieldReplacements($html);
 }
 /**
  * Will return the sharable image for the page.
  */
 private function getShareableImage()
 {
     try {
         // if an image variable was passed directly
         if ($this->fetch('image')) {
             return $this->fetch('image');
         }
         // if there was an og image specified on the page, use it (or get first image from array)
         if (isset($this->page['og_image'])) {
             $image = "";
             if (is_array($this->page['og_image'])) {
                 $image = $this->page['og_image'][0];
             } else {
                 $image = $this->page['og_image'];
             }
             return URL::assemble($this->site_url, $image);
         }
         // if another image is specified as the source
         if ($this->shareable_image_source && isset($this->page[$this->sharable_image_source])) {
             if (is_array($this->page[$this->sharable_image_source])) {
                 $image = $this->page[$this->sharable_image_source][0];
             } else {
                 $image = $this->page[$this->sharable_image_source];
             }
             return URL::assemble($this->site_url, $image);
         }
         // if there's a default image
         if ($this->sharable_image_default) {
             return $this->sharable_image_default;
         }
         // and if all else fails return an empty string
         return "";
     } catch (Exception $e) {
         return "<!-- Exception occured: " . $e->getMessage() . " -->";
     }
 }
示例#7
0
 /**
  * Logs a user out
  * 
  * @return void
  */
 public function member__logout()
 {
     $return = Request::get('return', Config::getSiteRoot());
     Auth::logout();
     URL::redirect(URL::assemble(Config::getSiteRoot(), $return));
 }
示例#8
0
 public function img()
 {
     $src = $this->fetchParam('src', null, null, false, false);
     $file = $this->theme_path . $this->theme_assets_path . 'img/' . $src;
     $alt = $this->fetchParam('alt', null, null, false, false);
     $tag = $this->fetchParam('tag', false, null, true, false);
     $cache_bust = $this->fetchParam('cache_bust', Config::get('theme_cache_bust', false), false, true, true);
     if ($alt) {
         $alt = ' alt="' . $alt . '"';
     }
     if ($cache_bust && File::exists($file)) {
         $file .= '?v=' . ($last_modified = filemtime($file));
     }
     $filename = URL::assemble($this->site_root, $file);
     return $tag ? '<img src="' . $filename . '" ' . $alt . '>' : $filename;
 }
 public function defaultFileThumbnail()
 {
     return URL::assemble(Config::getSiteRoot(), Config::get('admin_path'), 'themes', Config::get('admin_theme'), '/img/file.png');
 }
示例#10
0
文件: routes.php 项目: nob/joi
        $file = $content_root . "/" . $path . "." . $content_type;
        File::delete($file);
    }
    if ($count > 1) {
        $admin_app->flash('success', 'Entries successfully deleted!');
    } else {
        $admin_app->flash('success', 'Entry successfully deleted!');
    }
    $url = $admin_app->urlFor('entries') . "?path=" . dirname($path);
    $admin_app->redirect($url);
})->name('delete_entry')->via('GET', 'POST');
// GET: DELETE PAGE
$admin_app->get('/delete/page', function () use($admin_app) {
    authenticateForRole('admin');
    doStatamicVersionCheck($admin_app);
    $path = URL::assemble(BASE_PATH, Config::getContentRoot(), $admin_app->request()->get('path'));
    $type = $admin_app->request()->get('type');
    if ($type == "folder" && Folder::exists($path)) {
        Folder::delete($path);
        $admin_app->flash('success', 'Page successfully deleted!');
    } else {
        if (!Pattern::endsWith($path, Config::getContentType())) {
            $path .= Config::getContentType();
        }
        if (File::exists($path)) {
            File::delete($path);
            $admin_app->flash('success', 'Page successfully deleted!');
        } else {
            $admin_app->flash('failure', 'Unable to delete page.');
        }
    }
示例#11
0
文件: statamic.php 项目: nob/joi
 /**
  * Load the config (yaml) files in a specified order:
  *
  * 1. Loose per-site configs
  * 2. Routes
  * 3. Settings
  * 4. Theme overrides
  */
 public static function loadAllConfigs($admin = FALSE)
 {
     /*
     |--------------------------------------------------------------------------
     | YAML Mode
     |--------------------------------------------------------------------------
     |
     | We need to know the YAML mode first (loose, strict, transitional),
     | so we parse the settings file once to check before doing anything else.
     |
     */
     $preload_config = YAML::parse(Config::getConfigPath() . '/settings.yaml');
     $yaml_mode = array_get($preload_config, '_yaml_mode', 'loose');
     /*
     |--------------------------------------------------------------------------
     | Default Settings
     |--------------------------------------------------------------------------
     |
     | We keep a set of default options that the user config overrides, allowing
     | us to always have clean defaults.
     |
     */
     $default_config = YAML::parse(Config::getAppConfigPath() . '/default.settings.yaml');
     /*
     |--------------------------------------------------------------------------
     | User Site Settings
     |--------------------------------------------------------------------------
     |
     | Next we parse and override the user's settings.
     |
     */
     $user_config = YAML::parse(Config::getConfigPath() . '/settings.yaml', $yaml_mode);
     $config = array_merge($default_config, $user_config);
     /*
     |--------------------------------------------------------------------------
     | Routes and vanity URLs
     |--------------------------------------------------------------------------
     |
     | Any URL can be manipulated by routes or vanity urls. We need this info
     | early on, before content parsing begins.
     |
     */
     $routes = array();
     if (File::exists(Config::getConfigPath() . '/routes.yaml')) {
         $routes['_routes'] = YAML::parse('_config/routes.yaml', $yaml_mode);
     }
     // check for vanity URLs first, we may need to redirect
     $vanity = array();
     if (File::exists(Config::getConfigPath() . '/vanity.yaml')) {
         $vanity['_vanity_urls'] = YAML::parse(Config::getConfigPath() . '/vanity.yaml', $yaml_mode);
     }
     $config = array_merge($config, $routes, $vanity);
     /*
     |--------------------------------------------------------------------------
     | Global Variables
     |--------------------------------------------------------------------------
     |
     | We parse all the yaml files in the root (except settings and routes) of
     | the config folder and make them available as global template variables.
     |
     */
     if (Folder::exists($config_files_location = Config::getConfigPath())) {
         $finder = new Finder();
         $files = $finder->files()->in($config_files_location)->name('*.yaml')->notName('routes.yaml')->notName('vanity.yaml')->notName('settings.yaml')->depth(0);
         if (iterator_count($files) > 0) {
             foreach ($files as $file) {
                 $config = array_merge($config, YAML::parse($file->getRealPath(), $yaml_mode));
             }
         }
     }
     /*
     |--------------------------------------------------------------------------
     | Theme Variables
     |--------------------------------------------------------------------------
     |
     | Theme variables need to specifically parsed later so they can override
     | any site/global defaults.
     |
     */
     $themes_path = array_get($config, '_themes_path', '_themes');
     $theme_name = array_get($config, '_theme', 'denali');
     if (Folder::exists($theme_files_location = URL::assemble(BASE_PATH, $themes_path, $theme_name))) {
         $finder = new Finder();
         // clear previous Finder interator results
         $theme_files = $finder->files()->in($theme_files_location)->name('*.yaml')->depth(0);
         if (iterator_count($theme_files) > 0) {
             foreach ($theme_files as $file) {
                 $config = array_merge($config, YAML::parse($file->getRealPath(), $yaml_mode));
             }
         }
     }
     /*
     |--------------------------------------------------------------------------
     | MIME Types
     |--------------------------------------------------------------------------
     */
     $config = array_merge($config, array('_mimes' => require Config::getAppConfigPath() . '/mimes.php'));
     /*
     |--------------------------------------------------------------------------
     | Localization
     |--------------------------------------------------------------------------
     |
     | We load up English by default. We're American after all. Doesn't the
     | world revolve around us? Hello? Bueller? More hamburgers please.
     |
     */
     $config['_translations'] = array();
     $config['_translations']['en'] = YAML::parse(Config::getAppConfigPath() . '/default.en.yaml');
     /*
     |--------------------------------------------------------------------------
     | Set Slim Config
     |--------------------------------------------------------------------------
     |
     | Slim needs to be initialized with a set of config options, so these
     | need to be set earlier than the set_default_tags() method.
     |
     */
     // $config['view'] = new Statamic_View();
     $config['cookies.lifetime'] = $config['_cookies.lifetime'];
     if ($admin) {
         $admin_theme = array_get($config, '_admin_theme', 'ascent');
         if (!Folder::exists(Path::tidy('/' . $config['_admin_path'] . '/' . 'themes/' . $admin_theme))) {
             $admin_theme = 'ascent';
         }
         $theme_path = Path::tidy('/' . $config['_admin_path'] . '/' . 'themes/' . $admin_theme . '/');
         $config['_admin_path'] = $config['_admin_path'];
         $config['theme_path'] = $theme_path;
         $config['templates.path'] = '.' . $theme_path;
     } else {
         $public_path = isset($config['_public_path']) ? $config['_public_path'] : '';
         $config['theme_path'] = '_themes/' . $config['_theme'] . "/";
         $config['templates.path'] = Path::tidy($public_path . '_themes/' . $config['_theme'] . "/");
     }
     return $config;
 }
示例#12
0
文件: addon.php 项目: nob/joi
 /**
  * Returns the full path of a given script
  *
  * @param string  $file  Script file to find
  * @return string
  */
 public function get($file)
 {
     $file_location = Config::getAddOnPath($this->context->addon_name) . '/';
     if (File::exists(BASE_PATH . $file_location . $file)) {
         return URL::assemble(Config::getSiteRoot(), $file_location, $file);
     } elseif (File::exists(BASE_PATH . $file_location . 'assets/' . $file)) {
         return URL::assemble(Config::getSiteRoot(), $file_location, 'assets', $file);
     }
     $this->context->log->error("Asset file `" . $file . "` doesn't exist.");
     return "";
 }
    echo $modal;
})->name('files');
// Delete file
$admin_app->get('/file/delete', function () use($admin_app) {
    authenticateForRole('admin');
    doStatamicVersionCheck($admin_app);
    $result = Addon::getAPI('file')->deleteFile();
    $response = $admin_app->response();
    $response['Content-Type'] = 'application/json';
    $response->status(200);
    $response->body(json_encode($result));
})->name('delete_file');
$admin_app->get('/url/unique', function () use($admin_app) {
    $folder = Request::get('folder');
    $url = Request::get('url');
    $path = URL::assemble($folder, $url);
    $data = array('exists' => Content::exists(Path::resolve($path)));
    $response = $admin_app->response();
    $response['Content-Type'] = 'application/json';
    $response->body(json_encode($data));
});
/*
|--------------------------------------------------------------------------
| Hook: Add Routes
|--------------------------------------------------------------------------
|
| Allows add-ons to add their own hooks to the control panel.
|
*/
Hook::run('control_panel', 'add_routes');
// GET: 404
示例#14
0
文件: config.php 项目: nob/joi
 /**
  * Returns the path for a given $addon relative to the BASE_PATH
  *
  * @param string  $addon  Add-on to use
  * @return string
  */
 public static function getAddOnPath($addon)
 {
     return URL::assemble(self::getAddOnsPath(), $addon);
 }
示例#15
0
文件: path.php 项目: nob/joi
 /**
  * Finds a given path on the server, adding in any ordering elements missing
  *
  * @param string  $path  Path to resolve
  * @return string
  */
 public static function resolve($path)
 {
     $content_root = Config::getContentRoot();
     $content_type = Config::getContentType();
     if (strpos($path, "/") === 0) {
         $parts = explode("/", substr($path, 1));
     } else {
         $parts = explode("/", $path);
     }
     $fixedpath = "/";
     foreach ($parts as $part) {
         if (!File::exists(URL::assemble($content_root, $path . '.' . $content_type)) && !is_dir(URL::assemble($content_root, $part))) {
             // check folders
             $list = Statamic::get_content_tree($fixedpath, 1, 1, FALSE, TRUE, FALSE);
             foreach ($list as $item) {
                 $t = basename($item['slug']);
                 if (Slug::isNumeric($t)) {
                     $nl = strlen(Slug::getOrderNumber($t)) + 1;
                     if (strlen($part) >= strlen($item['slug']) - $nl && Pattern::endsWith($item['slug'], $part)) {
                         $part = $item['slug'];
                         break;
                     }
                 } else {
                     if (Pattern::endsWith($item['slug'], $part)) {
                         if (strlen($part) >= strlen($t)) {
                             $part = $item['slug'];
                             break;
                         }
                     }
                 }
             }
             // check files
             $list = Statamic::get_file_list($fixedpath);
             foreach ($list as $key => $item) {
                 if (Pattern::endsWith($key, $part)) {
                     $t = basename($item);
                     $offset = 0;
                     if (Pattern::startsWith($key, '__')) {
                         $offset = 2;
                     } elseif (Pattern::startsWith($key, '_')) {
                         $offset = 1;
                     }
                     if (Config::getEntryTimestamps() && Slug::isDateTime($t)) {
                         if (strlen($part) >= strlen($key) - 16 - $offset) {
                             $part = $key;
                             break;
                         }
                     } elseif (Slug::isDate($t)) {
                         if (strlen($part) >= strlen($key) - 12 - $offset) {
                             $part = $key;
                             break;
                         }
                     } elseif (Slug::isNumeric($t)) {
                         $nl = strlen(Slug::getOrderNumber($key)) + 1;
                         if (strlen($part) >= strlen($key) - $nl - $offset) {
                             $part = $key;
                             break;
                         }
                     } else {
                         $t = basename($item);
                         if (strlen($part) >= strlen($t) - $offset) {
                             $part = $key;
                             break;
                         }
                     }
                 }
             }
         }
         if ($fixedpath != '/') {
             $fixedpath .= '/';
         }
         $fixedpath .= $part;
     }
     // /2-blog/hidden
     return $fixedpath;
 }
示例#16
0
 public function logout_url()
 {
     $return = $this->fetchParam('return', '/');
     return URL::assemble(Config::getSiteRoot(), "TRIGGER", 'member', "logout?return={$return}");
 }
示例#17
0
          </li>
          <?php 
}
?>


          <?php 
foreach (CP_Helper::addon_nav_items() as $item) {
    ?>

            <li id="item-<?php 
    echo $item;
    ?>
">
              <a href="<?php 
    echo URL::assemble($app->request()->getRootUri(), $item);
    ?>
"<?php 
    if ($route === $item) {
        ?>
 class="active"<?php 
    }
    ?>
>
                <span class="ss-icon">
                  <?php 
    if (Localization::fetch('nav_icon_' . $item) !== 'nav_icon_' . $item) {
        ?>
                    <?php 
        echo Localization::fetch('nav_icon_' . $item);
        ?>
示例#18
0
    /**
     * Returns the full path of a given script
     *
     * @param string  $file  Script file to find
     * @return string
     */
    public function get($file)
    {
        $bundle_location = "/core/bundles/" . $this->context->getAddonName() . "/";
        $file_location = Config::getAddOnPath($this->context->getAddonName()) . '/';

        if (File::exists(APP_PATH . $bundle_location . $file)) {
            return URL::assemble(Config::getSiteRoot(), ENVIRONMENT_PATH_PREFIX, $file_location, $file);
        } elseif (File::exists(APP_PATH . $bundle_location . 'assets/' . $file)) {
            return URL::assemble(Config::getSiteRoot(), ENVIRONMENT_PATH_PREFIX, $file_location, 'assets', $file);
        } elseif (File::exists(BASE_PATH . $file_location . $file)) {
            return URL::assemble(Config::getSiteRoot(), $file_location, $file);
        } elseif (File::exists(BASE_PATH . $file_location . 'assets/' . $file)) {
            return URL::assemble(Config::getSiteRoot(), $file_location, 'assets', $file);
        }

        Log::error("Asset file `" . $file . "` doesn't exist.", $this->context->getAddonName(), $this->context->getAddonType());
        return "";
    }