コード例 #1
0
ファイル: cc-uploadify.php プロジェクト: alecgorge/TopHat
 public function __construct($src, $default_callbacks = array())
 {
     if ($src instanceof Uploader) {
         $this->post_field = $src->getName();
     } elseif (is_string($src)) {
         $this->post_field = $name;
     }
     $this->callbacks = (array) $default_callbacks;
     if (array_key_exists($this->post_field, $_FILES)) {
         Hooks::bind('system_ready', array($this, 'runCallbacks'));
     }
 }
コード例 #2
0
ファイル: cc-timers.php プロジェクト: alecgorge/TopHat
    public static function add($time, $callback, $specificTime = false)
    {
        if (!is_callable($callback)) {
            error_log('$callback is not a valid callback in Timer::add', E_USER_ERROR);
        }
        $orig = $time;
        if (is_numeric($time) && !$specificTime) {
            $time = time() + $time;
        } else {
            if (is_string($time) && !$specificTime) {
                $time = strtotime($time);
            }
        }
        self::$timers[] = array('time' => (int) $time, 'orig-time' => $orig, 'callback' => $callback);
    }
    public static function callTimers()
    {
        $time = time();
        foreach (self::$timers as $t) {
            if ($time >= $t['time']) {
                call_user_func_array($t['callback'], array($t['orig-time']));
            }
        }
    }
}
function timer($time, $callback, $specificTime = false)
{
    Timers::add($time, $callback, $specificTime);
}
Hooks::bind("system_ready", "Timers::callTimers");
コード例 #3
0
ファイル: cc-plugins.php プロジェクト: alecgorge/TopHat
 /**
  * A wrapper for Hooks::bind();
  */
 public function bind($hook, $callback, $priority = 0)
 {
     $this->binds[] = array($hook, $callback);
     Hooks::bind($hook, $callback, $priority);
 }
コード例 #4
0
ファイル: cc-tokenizer.php プロジェクト: alecgorge/TopHat
    public static function register($name, $value = null)
    {
        if (is_array($name)) {
            if (is_null($value)) {
                foreach ($name as $key => $val) {
                    self::$tokens[$key] = $val;
                }
            } else {
                foreach ($name as $key => $val) {
                    self::$tokens[$val] = $value[$key];
                }
            }
        } else {
            self::$tokens[$name] = $value;
        }
    }
    public static function registerDefaults()
    {
        Tokens::register(array("theme_dir" => Themes::$curr_theme->getPublicPath(), "public_root" => TH_PUB_ROOT, "root" => TH_ROOT, "public_content_dir" => TH_PUB_ROOT . TH_CONTENT, "content_dir" => TH_ROOT . TH_CONTENT, "uploads_dir" => TH_ROOT . TH_UPLOADS, "public_uploads_dir" => TH_PUB_ROOT . TH_UPLOADS));
    }
    public static function fetch($name)
    {
        return self::$tokens[$name];
    }
    public static function filter($value)
    {
        return Tokenizer::perform($value, self::$tokens);
    }
}
Hooks::bind("system_after_themes_load", "Tokens::registerDefaults");
Filters::bind("content_get_inital", "Tokens::filter");
コード例 #5
0
ファイル: cc-hooks.php プロジェクト: alecgorge/TopHat
     */
    protected static function getAllHooks()
    {
        return self::$hooks;
    }
    /**
     * Sets up hooks for form submission.
     */
    public static function setupPostHandles()
    {
        if (!empty($_POST['cc_form'])) {
            Hooks::execute('post_' . $_POST['cc_form']);
        }
    }
}
Hooks::bind('system_ready', 'Hooks::setupPostHandles');
/**
 * Wrapper for Hooks::execute().
 */
function plugin($name, $args = array())
{
    return Hooks::execute($name, $args);
}
/**
 * Fundamentally the same as Hooks, but modifies the variable each time and returns the new value.
 */
class Filters extends Hooks
{
    /**
     * @var array The list of registered filters.
     */
コード例 #6
0
ファイル: cc-admin.php プロジェクト: alecgorge/TopHat
    }
    /**
     * A wrapper for Admin->registerSubpage
     */
    public static function registerSubpage()
    {
        $args = func_get_args();
        return call_user_func_array(array(self::$handle, '_registerSubpage'), $args);
    }
    /**
     * Logs the user out.
     */
    public static function logout()
    {
        Users::logout();
        cc_redirect(TH_PUB_ROOT);
        exit;
    }
    public static function isPage($page)
    {
        return $_GET['page'] == $page;
    }
    public static function doIncludeDesign()
    {
        self::$handle->includeDesign();
    }
}
Hooks::bind('admin_logout', 'Admin::logout', 100);
Hooks::bind('system_complete', 'Admin::bootstrap');
Hooks::bind('system_complete', 'Admin::doIncludeDesign', 100);
コード例 #7
0
ファイル: cc-editors.php プロジェクト: alecgorge/TopHat
        return array_keys(self::$registered);
    }
    public static function getEditorObj()
    {
        if (array_key_exists(self::$editor, self::$registered)) {
            return self::$registered[self::$editor];
        } else {
            trigger_error(self::$editor . " is not a valid editor.", E_USER_ERROR);
        }
    }
    public static function create($name, $contents)
    {
        return self::getEditorObj()->run('create', array($name, $contents));
    }
}
Hooks::bind('system_ready', 'Editors::bootstrap');
class Editor
{
    public $name, $version, $author, $binds = array();
    public function __construct($name, $version, $author)
    {
        $this->name = $name;
        $this->version = $version;
        $this->author = $author;
    }
    public function bind_create($callback)
    {
        if (!is_callable($callback)) {
            trigger_error("{$callback} is not callable!");
        }
        $this->binds['create'] = $callback;
コード例 #8
0
ファイル: cc-content.php プロジェクト: alecgorge/TopHat
            } else {
                $this->info['theme'] = Settings::get('site', 'theme', true);
            }
        }
        return filter('node_theme', $this->info['theme']);
    }
    protected function checkRow($raw_row = null)
    {
        if (empty($this->db_row)) {
            $row = $raw_row;
            $this->id = $row['id'];
            $row = filter('page_checkrow', $row);
            $this->db_row = $row;
            $this->info['content'] = $row['content'];
            $this->info['name'] = $row['name'];
            $this->info['settings'] = unserialize($row['settings']);
            $this->info['title'] = $row['title'];
            $this->info['created'] = $row['created'];
            $this->info['last_modified'] = $row['last_modified'];
            $this->info['weight'] = $row['weight'];
            $this->info['menutitle'] = $row['menutitle'];
            $this->info['parent_id'] = $row['parent_id'];
            $this->info['type'] = $row['type'];
            $this->info['slug'] = $row['slug'];
        }
    }
}
// admin has its own way of doing things
if (!CC_IS_ADMIN) {
    Hooks::bind('system_after_content_load', 'Content::bootstrap');
}
コード例 #9
0
ファイル: cc-i18n.php プロジェクト: alecgorge/TopHat
    /**
     * Gets the translations array
     */
    public function getTranslations()
    {
        return $this->translations;
    }
    /**
     * Returns the list of registered locales (locales may be incomplete)
     */
    public static function getLocales()
    {
        return array_keys(self::$handle->getTranslations());
    }
}
Hooks::bind('system_ready', 'i18n::boostrap', -50);
/**
 * A wrapper for i18n::translate();
 *
 * You can use it as if it has 2 arguments and then pass the rest of the arguments as arguments to go to sprintf.
 */
function __($section, $key = null, $locale = 'DEFAULT')
{
    if (func_num_args() > 3 || func_num_args() > 2 && $locale !== 'DEFAULT') {
        $args = func_get_args();
        return call_user_func_array('i18n::translate', $args);
    }
    return i18n::translate($section, $key, $locale);
}
/**
 * Like __() but echos the output.
コード例 #10
0
ファイル: cc-urlmap.php プロジェクト: alecgorge/TopHat
                    return;
                }
                $parts = array_remove_empty(explode("/", ltrim($url, "/")));
                preg_match_all("#:([a-zA-Z_]+)#", $url, $matches);
                $expecting = count($matches[1]);
                // if there is a blank at the end it will be one longer
                if (count($url_parts) == count($parts) || count($url_parts) - 1 == count($parts)) {
                    foreach ($parts as $k => $v) {
                        if ($v == "*") {
                            $ret_vals[] = implode("/", array_slice($url_parts, $k));
                        } elseif (substr($v, 0, 1) == ":") {
                            $ret_vals[substr($v, 1)] = $url_parts[$k];
                        } elseif ($url_parts[$k] == $v) {
                            continue;
                        } else {
                            break;
                        }
                    }
                    if (count($ret_vals) == $expecting) {
                        call_user_func($callback, $ret_vals);
                        return;
                    }
                } else {
                    continue;
                }
            }
        }
    }
}
Hooks::bind("system_after_content_load", "URLMap::process", 100);