コード例 #1
0
ファイル: boilerplate.php プロジェクト: robkaper/kiki
 public static function navMenu(&$user, $level = 1)
 {
     // FIXME: add exact match boolean for url/context checking
     $menu = array();
     $context = null;
     $matches = array();
     $requestUri = isset($_GET['uri']) ? $_GET['uri'] : isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : null;
     preg_match('#(/(.*))/((.*)(\\.php)?)#', $requestUri, $matches);
     $active = null;
     if (count($matches)) {
         $context = $matches[2];
         $active = $matches[4];
     }
     $paths = explode("/", $context);
     $db = Core::getDb();
     $qLevel = $db->escape($level);
     $qContext = $db->escape($context);
     if ($context) {
         $q = "select title, url, level, admin, class, icon from menu_items where level={$qLevel} and ('{$qContext}' like concat('%', context, '%') or context is null) order by sortorder asc";
     } else {
         $q = "select title, url, level, admin, class, icon from menu_items where level={$qLevel} and context is null order by sortorder asc";
     }
     $rs = $db->query($q);
     if ($rs && $db->numRows($rs)) {
         while ($o = $db->fetchObject($rs)) {
             $menuItem = Boilerplate::navMenuItem($user, $o);
             if ($menuItem) {
                 $menu[] = $menuItem;
             }
         }
     }
     return $menu;
 }
コード例 #2
0
ファイル: core.php プロジェクト: robkaper/kiki
 public static function setTemplateData()
 {
     // Basic and fundamental variables that should always be available in templates.
     self::$templateData = array();
     // Request values
     self::$templateData['get'] = $_GET;
     self::$templateData['post'] = $_POST;
     // Config values
     self::$templateData['config'] = array();
     foreach (get_class_vars('Kiki\\Config') as $configKey => $configValue) {
         // Lame security check, but better safe than sorry until a proper
         // audit has been done that in no way unauthorised user content get
         // parsed as template itself, through parsing recursion or otherwise.
         // Should mostly be careful about direct assignment of any of it to
         // 'content'.
         if (!preg_match('~(^db|pass|secret)~i', $configKey)) {
             self::$templateData['config'][$configKey] = $configValue;
         }
     }
     if (Config::$customCss) {
         self::$templateData['stylesheets'] = array(Config::$customCss);
     }
     // Is that all we want?
     self::$templateData['server'] = array('requestUri' => isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : "");
     self::$templateData['user'] = self::$user ? self::$user->templateData() : null;
     // Account service(s). Although multiple routing entries are technically
     // possible, templateData currently only populates one: the first found or else
     // the internal fallback in the Kiki controller.
     $accountServices = array_values(Router::getBaseUris('account'));
     $baseUri = isset($accountServices[0]) ? $accountServices[0]->base_uri : Config::$kikiPrefix . "/account";
     $title = isset($accountServices[0]) ? $accountServices[0]->title : _("Account");
     self::$templateData['accountService'] = array('url' => $baseUri, 'title' => $title);
     // Active connections. Only typing laziness explains why this isn't simply in {$user.connections}.
     self::$templateData['activeConnections'] = array();
     $connectedServices = array();
     if (self::$user) {
         foreach (self::$user->connections() as $connection) {
             self::$templateData['activeConnections'][] = array('serviceName' => $connection->serviceName(), 'screenName' => $connection->screenName(), 'userName' => $connection->name(), 'pictureUrl' => $connection->picture(), 'subAccounts' => $connection->subAccounts(), 'permissions' => $connection->permissions());
             $connectedServices[] = $connection->serviceName();
         }
     }
     // Log::debug( "user cons: ". print_r(self::$user->connections(),true) );
     // Inactive connections. Might as well be in {$user) as well,
     // potentially in {$user.connections} with an {active} switch, although
     // the separation at this level is not the worst.
     // Log::debug( "config: ". print_r(Config::$connectionServices, true) );
     // Log::debug( "connected: ". print_r($connectedServices,true) );
     foreach (Config::$connectionServices as $name) {
         if (!in_array($name, $connectedServices)) {
             $connection = ConnectionService\Factory::getInstance($name);
             self::$templateData['inactiveConnections'][] = array('serviceName' => $connection->name(), 'loginUrl' => $connection->loginUrl());
         }
     }
     // Log::debug( "active Con: ". print_r(self::$templateData['activeConnections'],true) );
     // Log::debug( "inactive Con: ". print_r(self::$templateData['inactiveConnections'],true) );
     // Menu and submenu. This feels like it the default controller (with the
     // option for children to reimplement or amend) should do through a Menu
     // class.
     self::$templateData['menu'] = Boilerplate::navMenu(self::$user);
     self::$templateData['subMenu'] = Boilerplate::navMenu(self::$user, 2);
     // @todo Allow starttime and execution time from Log(::init) to be
     // queried and assign them.  Just in case someone wants to output it in
     // a template.
     self::$templateData['now'] = time();
 }
コード例 #3
0
ファイル: boilerplate.php プロジェクト: prosatya/boilerplate
/**
 * Begins execution of the plugin.
 *
 * Since everything within the plugin is registered via hooks,
 * then kicking off the plugin from this point in the file does
 * not affect the page life cycle.
 *
 * @since    1.0.0
 */
function run_Boilerplate()
{
    $plugin = new Boilerplate();
    $plugin->run();
}
コード例 #4
0
ファイル: controller.php プロジェクト: robkaper/kiki
 public function output()
 {
     if (PHP_SAPI == 'cli') {
         $template = Template::getInstance();
         $template->assign('footerText', Boilerplate::copyright());
         $template->load($this->template());
         $template->assign('title', $this->title());
         $template->assign('content', $this->content());
         $template->fetch();
         print_r($template->data());
         return;
     }
     Http::sendHeaders($this->status(), $this->altContentType());
     switch ($this->status()) {
         case 301:
         case 302:
         case 303:
             Router::redirect($this->content(), $this->status());
             break;
         default:
             if (isset($_REQUEST['dialog']) || !$this->template()) {
                 echo $this->content();
                 return;
             }
             $template = Template::getInstance();
             $template->assign('footerText', Boilerplate::copyright());
             $template->load($this->template());
             $template->assign('title', $this->title());
             $template->assign('content', $this->content());
             echo $template->content();
             break;
     }
 }
コード例 #5
0
ファイル: update.php プロジェクト: robkaper/kiki
$content = $_GET['content'];
$ids = array();
foreach ($content as $id) {
    $ids[] = "'" . $db->escape($id) . "'";
    $data = '';
    switch ($id) {
        case 'accountLink':
            $data = User::anyUser() ? Boilerplate::accountLink() : null;
            break;
        case 'address':
            $data = User::anyUser() ? Boilerplate::address() : Boilerplate::login();
            break;
        default:
            if (preg_match('/^commentFormWrapper_/', $id)) {
                list($dummy, $objectId) = explode('_', $id);
                $data = $user->id() ? Boilerplate::commentForm($user, $objectId) : Boilerplate::login();
            } else {
                if (preg_match('/^navMenu-/', $id)) {
                    list($dummy, $level) = explode('-', $id);
                    $data = Boilerplate::navMenu($user, $level);
                }
            }
            break;
    }
    $response['content'][] = array('id' => $id, 'html' => $data);
}
$qIds = join($ids, ',');
$q = "select * from json_content where id in ({$qIds})";
// $response['q'] = $q;
header('Content-type: application/json');
echo json_encode($response);