예제 #1
0
 public function add($title, $link, $style = '')
 {
     $i = new XhtmlMenuItem();
     $i->title = $title;
     $i->link = relurl($link);
     $i->style = $style;
     $this->items[] = $i;
 }
예제 #2
0
 function render()
 {
     if (!$this->name) {
         throw new \Exception('must set a name');
     }
     $header = XhtmlHeader::getInstance();
     $header->includeCss('core_dev/js/ext/yui/2.9.0/build/fonts/fonts-min.css');
     $header->includeCss('core_dev/js/ext/yui/2.9.0/build/button/assets/skins/sam/button.css');
     $header->includeCss('core_dev/js/ext/yui/2.9.0/build/container/assets/skins/sam/container.css');
     $header->includeCss('core_dev/js/ext/yui/2.9.0/build/calendar/assets/skins/sam/calendar.css');
     $header->includeJs('core_dev/js/ext/yui/2.9.0/build/yahoo-dom-event/yahoo-dom-event.js');
     $header->includeJs('core_dev/js/ext/yui/2.9.0/build/dragdrop/dragdrop-min.js');
     $header->includeJs('core_dev/js/ext/yui/2.9.0/build/element/element-min.js');
     $header->includeJs('core_dev/js/ext/yui/2.9.0/build/button/button-min.js');
     $header->includeJs('core_dev/js/ext/yui/2.9.0/build/container/container-min.js');
     $header->includeJs('core_dev/js/ext/yui/2.9.0/build/calendar/calendar-min.js');
     $header->embedCss('#container .bd form {' . 'clear:left;' . '}' . '#container .bd {' . 'padding:0;' . '}' . '#container .hd {' . 'text-align:left;' . '}' . '#container .ft .button-group {' . 'text-align:center;' . '}' . '#container_c.yui-overlay-hidden table {' . '*display:none;' . '}' . '#cal {' . 'border:none;' . 'padding:1em;' . '}');
     $locale = LocaleHandler::getInstance();
     $button_name = 'yui_dp_show_' . mt_rand();
     $res = 'YAHOO.util.Event.onDOMReady(function(){' . 'var Event = YAHOO.util.Event,' . 'Dom = YAHOO.util.Dom,' . 'dialog,' . 'calendar;' . 'var showBtn = Dom.get("' . $button_name . '");' . 'Event.on(showBtn, "click", function() {' . 'if (!dialog) {' . 'Event.on(document, "click", function(e) {' . 'var el = Event.getTarget(e);' . 'var dialogEl = dialog.element;' . 'if (el != dialogEl && !Dom.isAncestor(dialogEl, el) && el != showBtn && !Dom.isAncestor(showBtn, el)) {' . 'dialog.hide();' . '}' . '});' . 'function resetHandler() {' . 'var selDates = calendar.getSelectedDates();' . 'var resetDate;' . 'if (selDates.length > 0) {' . 'resetDate = selDates[0];' . '} else {' . 'resetDate = calendar.today;' . '}' . 'calendar.cfg.setProperty("pagedate", resetDate);' . 'calendar.render();' . '}' . 'function closeHandler() {' . 'dialog.hide();' . '}' . 'dialog = new YAHOO.widget.Dialog("container", {' . 'visible:false,' . 'context:["' . $button_name . '", "tl", "bl"],' . 'buttons:[ {text:"Reset", handler: resetHandler, isDefault:true}, {text:"Close", handler: closeHandler}],' . 'draggable:false,' . 'close:true' . '});' . 'dialog.setHeader("Pick A Date");' . 'dialog.setBody(\'<div id="cal"></div>\');' . 'dialog.render(document.body);' . 'dialog.showEvent.subscribe(function() {' . 'if (YAHOO.env.ua.ie) {' . 'dialog.fireEvent("changeContent");' . '}' . '});' . '}' . 'if (!calendar) {' . 'calendar = new YAHOO.widget.Calendar("cal", {' . 'iframe:false,' . 'hide_blank_weeks:true,' . ($this->selected_date ? 'selected:"' . js_date($this->selected_date) . '",' . 'pagedate:"' . date('n/Y', $this->selected_date) . '",' : '') . 'start_weekday:' . $this->start_weekday . ',' . 'MONTHS_SHORT:' . Json::encode($locale->handle->month_short, false) . ',' . 'MONTHS_LONG:' . Json::encode($locale->handle->month_long, false) . ',' . 'WEEKDAYS_1CHAR:' . Json::encode($locale->handle->weekday_1char, false) . ',' . 'WEEKDAYS_SHORT:' . Json::encode($locale->handle->weekday_short, false) . ',' . 'WEEKDAYS_MEDIUM:' . Json::encode($locale->handle->weekday_medium, false) . ',' . 'WEEKDAYS_LONG:' . Json::encode($locale->handle->weekday_long, false) . ',' . '});' . 'calendar.render();' . 'calendar.selectEvent.subscribe(function() {' . 'if (calendar.getSelectedDates().length > 0) {' . 'var selDate = calendar.getSelectedDates()[0];' . 'Dom.get("' . $this->name . '").value = selDate.getFullYear() + "-" + (selDate.getMonth() + 1) + "-" + selDate.getDate();' . '} else {' . 'Dom.get("' . $this->name . '").value = "";' . '}' . 'dialog.hide();' . '});' . 'calendar.renderEvent.subscribe(function() {' . 'dialog.fireEvent("changeContent");' . '});' . '}' . 'var seldate = calendar.getSelectedDates();' . 'if (seldate.length > 0) {' . 'calendar.cfg.setProperty("pagedate", seldate[0]);' . 'calendar.render();' . '}' . 'dialog.show();' . '});' . '});';
     return xhtmlInput($this->name, sql_date($this->selected_date), 8) . ' ' . '<button type="button" id="' . $button_name . '" title="Pick a date">' . '<img src="' . relurl('core_dev/gfx/icon_date-picker.png') . '" alt="Pick a date"/>' . '</button>' . js_embed($res);
 }
예제 #3
0
<?php

/**
 * Shows page load time & other information
 */
//TODO: $_SERVER['REQUEST_TIME'] är ett bättre "page start" värde (???)
namespace cd;

// measure time at page "start execute" event
$header->embedJs('var beforeload=new Date();');
// measure time when page finished loading
$header->embedJsOnload('document.getElementById("span_rendertime").innerHTML=(new Date()-beforeload)/1000;');
$container_id = 'cdc_' . mt_rand();
$wrapper_id = 'cdw_' . mt_rand();
$header->embedCss('#' . $wrapper_id . '{' . 'z-index:999;' . 'position:fixed;' . 'right:0;' . 'bottom:0;' . 'margin:2px;' . 'padding:2px;' . 'padding-top:0px;' . 'border:1px dashed #aaa;' . 'color:#000;' . 'background-color:#fafafa;' . 'font:9px verdana;' . '}' . 'a.closebtn' . '{' . 'display:block;' . 'float:right;' . 'width:7px;' . 'height:7px;' . 'margin-left:4px;' . 'margin-top:4px;' . 'background:url("' . relurl('core_dev/gfx/close.gif') . '");' . '}' . 'a.closebtn:hover' . '{' . 'background-position:0px -7px;' . '}' . 'a.expandbtn' . '{' . 'display:block;' . 'float:left;' . 'width:7px;' . 'height:7px;' . 'margin-right:4px;' . 'margin-top:4px;' . 'background:url("' . relurl('core_dev/gfx/close.gif') . '");' . 'background-position:0px -28px;' . '}' . 'a.expandbtn:hover' . '{' . '}');
echo '<div id="' . $wrapper_id . '">';
// outer wrapper
echo ahref_js('', "return toggle_el('" . $container_id . "');", 'expandbtn');
echo 'core_dev';
echo '<div id="' . $container_id . '" style="display:none;">';
// inner container
if (class_exists('cd\\SqlHandler')) {
    $view = new ViewModel('views/profiler/mysql.php');
    echo $view->render();
}
if (class_exists('cd\\TempStore')) {
    $view = new ViewModel('views/profiler/tempstore.php');
    echo $view->render();
}
$prof_id = 'prof_' . mt_rand();
$total_time = microtime(true) - $page->getStartTime();
예제 #4
0
 public function testRelUrl()
 {
     $this->assertEquals(relurl('/'), '/');
     $this->assertEquals(relurl('?val'), '?val');
     $this->assertEquals(relurl('abp://subscribe'), 'abp://subscribe');
 }
예제 #5
0
     $page->disableDesign();
     echo '1';
     break;
 case 'show':
     //child = poll id
     if (!$this->child) {
         throw new \Exception('no id set');
     }
     $poll = PollItem::get($this->child);
     if (!$poll) {
         die('meh');
     }
     $header = XhtmlHeader::getInstance();
     $header->embedCss('.poll_item{' . 'background-color:#eee;' . 'padding:5px;' . 'cursor:pointer;' . '}');
     $header->includeJs('http://yui.yahooapis.com/3.4.1/build/yui/yui-min.js');
     $header->embedJs('function submit_poll(id,opt)' . '{' . 'YUI().use("io-base", function(Y) {' . 'var uri = "' . relurl('') . 'u/polls/vote/" + id + "/" + opt;' . 'Y.on("io:complete", function(id,o){' . 'var id = id;' . 'var data = o.responseText;' . 'if (data==1) return;' . 'alert("Voting error " + data);' . '});' . 'var request = Y.io(uri);' . '});' . 'hide_el("poll"+id);' . 'show_el("poll_voted"+id);' . '}');
     $active = false;
     if (time() >= ts($poll->time_start) && time() <= ts($poll->time_end)) {
         $active = true;
     }
     if (!$poll->time_start) {
         $active = true;
     }
     echo '<div class="item">';
     if ($active) {
         echo 'Active poll: ';
     }
     echo $poll->text . '<br/><br/>';
     echo '<div id="poll' . $this->child . '">';
     if ($poll->time_start) {
         echo 'Starts: ' . $poll->time_start . ', ends ' . $poll->time_end . '<br/>';
예제 #6
0
//FIXME: ratings:ratingChange js event  never triggers!
//XXX: make it read-only after you clicked it once
namespace cd;

switch ($this->view) {
    case 'handle':
        // handle user rating
        // owner = item type
        // child = item id
        $type = $this->owner;
        $id = $this->child;
        $header->includeJs('http://yui.yahooapis.com/3.4.1/build/yui/yui-min.js');
        $header->includeCss($page->getRelativeCoreDevUrl() . 'js/ext/gallery-ratings/assets/gallery-ratings-core.css');
        $widget_id = 'rate_' . mt_rand();
        $max_stars = 5;
        $js = 'YUI({' . 'modules:{' . '"gallery-ratings":{' . 'fullpath:"' . relurl($page->getRelativeCoreDevUrl()) . 'js/ext/gallery-ratings/gallery-ratings-min.js",' . 'requires:["base","widget"]' . '}' . '},' . 'filter: "raw"' . '}).use("gallery-ratings", function(Y){' . 'var ratings = new Y.Ratings({' . 'max:' . $max_stars . ',' . 'srcNode: "#' . $widget_id . '"' . '});' . 'Y.log("rator created");' . 'Y.on("ratings:ratingChange",function(e){' . 'Y.log("ww2");' . 'YUI().use("io-base", function(Y){' . 'var uri = "u/rate/vote/' . $type . '/' . $id . '/" + e.newVal;' . 'Y.log(uri);' . 'Y.on("io:complete", function(id,o){' . 'var id = id;' . 'var data = o.responseText;' . 'if (data==1) return;' . 'alert("Voting error " + data);' . '});' . 'var request = Y.io(uri);' . '});' . '});' . '});';
        $avg = Rating::getAverage($type, $id);
        echo js_embed($js) . '<span id="' . $widget_id . '">' . round($avg, 1) . '</span>';
        break;
    case 'vote':
        // owner = type
        // child = item id
        // child2 = option id
        echo 'WOWOWsls';
        if (!empty($_GET['rate_vote']) && !empty($_GET['opt'])) {
            if (!$session->id || !is_numeric($_GET['opt'])) {
                die('XXX');
            }
            $page->disableDesign();
            Rating::addVote($type, $_GET['rate_vote'], $_GET['opt']);
            ob_clean();
예제 #7
0
 public function setFavicon($uri)
 {
     if (substr($uri, 0, 1) != '/') {
         $uri = relurl($uri);
     }
     $this->addRel('icon', $uri, file_get_mime_by_suffix($uri));
 }
예제 #8
0
/**
 * Decorates input string with smiley images
 */
function str_add_smileys($s)
{
    // http://en.wikipedia.org/wiki/List_of_emoticons
    $root = relurl('core_dev/gfx/smileys/');
    $s = str_replace(array(':-)', ':)'), '<img align="absmiddle" src="' . $root . 'smile.png"/>', $s);
    $s = str_replace(array(';-)', ';)'), '<img align="absmiddle" src="' . $root . 'wink.png"/>', $s);
    $s = str_replace(array(':-(', ':('), '<img align="absmiddle" src="' . $root . 'sad.png"/>', $s);
    $s = str_replace(array(':-D', ':D'), '<img align="absmiddle" src="' . $root . 'smile_big.png"/>', $s);
    $s = str_replace(array(':-~', ':~'), '<img align="absmiddle" src="' . $root . 'crying.png"/>', $s);
    $s = str_replace(array('}:-)', '}:)'), '<img align="absmiddle" src="' . $root . 'devil.png"/>', $s);
    $s = str_replace(array('O:-)'), '<img align="absmiddle" src="' . $root . 'angel.png"/>', $s);
    $s = str_replace(array('8-)'), '<img align="absmiddle" src="' . $root . 'glasses.png"/>', $s);
    $s = str_replace(array(':-*'), '<img align="absmiddle" src="' . $root . 'kiss.png"/>', $s);
    $s = str_replace(array(':-O'), '<img align="absmiddle" src="' . $root . 'surprised.png"/>', $s);
    $s = str_replace(array(':-P'), '<img align="absmiddle" src="' . $root . 'grin.png"/>', $s);
    $s = str_replace(array(':-|'), '<img align="absmiddle" src="' . $root . 'indifferent.png"/>', $s);
    $s = str_replace(array('<3'), '<img align="absmiddle" src="' . $root . 'heart.png"/>', $s);
    return $s;
}
예제 #9
0
 function setXhrUrl($s)
 {
     $this->xhr_url = relurl($s);
 }
예제 #10
0
 function render()
 {
     if (!$this->columns) {
         throw new \Exception('no columns');
     }
     $header = XhtmlHeader::getInstance();
     if ($this->show_paginator) {
         $header->includeCss('core_dev/js/ext/yui/2.9.0/build/paginator/assets/skins/sam/paginator.css');
     }
     $header->includeCss('core_dev/js/ext/yui/2.9.0/build/datatable/assets/skins/sam/datatable.css');
     $header->includeJs('core_dev/js/ext/yui/2.9.0/build/yahoo-dom-event/yahoo-dom-event.js');
     $header->includeJs('core_dev/js/ext/yui/2.9.0/build/connection/connection-min.js');
     $header->includeJs('core_dev/js/ext/yui/2.9.0/build/datasource/datasource-min.js');
     $header->includeJs('core_dev/js/ext/yui/2.9.0/build/element/element-min.js');
     if ($this->show_paginator) {
         $header->includeJs('core_dev/js/ext/yui/2.9.0/build/paginator/paginator-min.js');
     }
     $header->includeJs('core_dev/js/ext/yui/2.9.0/build/datatable/datatable-min.js');
     $header->includeJs('core_dev/js/ext/yui/2.9.0/build/json/json-min.js');
     $div_holder = 'yui_dt' . mt_rand();
     $data_var = 'yui_dt_data' . mt_rand();
     $pag_holder = 'yui_pag' . mt_rand();
     $res = 'YAHOO.util.Event.addListener(window, "load", function() {' . 'YAHOO.example.Basic = function() {' . 'this.formatLink = function(elLiner, oRecord, oColumn, oData) {' . 'if (!oData) return;' . 'var prefix = oColumn["extra_data"];' . 'var col_label_name = oColumn["col_label"];' . 'var col_label = oRecord._oData[col_label_name];' . 'elLiner.innerHTML = "<a href=\\"" + prefix + oData + "\\">" + (col_label ? col_label : oData) + "</a>";' . '};' . 'this.formatDate = function(elLiner, oRecord, oColumn, oData) {' . 'if (!oData) return;' . 'var a1 = oData.substr(0,10).split("-");' . 'elLiner.innerHTML = a1[0]+"-"+a1[1]+"-"+a1[2];' . '};' . 'this.formatTime = function(elLiner, oRecord, oColumn, oData) {' . 'if (!oData) return;' . 'var a1 = oData.substr(0,10).split("-");' . 'var a2 = oData.substr(11,8).split(":");' . 'elLiner.innerHTML = a1[0]+"-"+a1[1]+"-"+a1[2]+" "+a2[0]+":"+a2[1]+":"+a2[2];' . '};' . 'this.formatMoney = function(elLiner, oRecord, oColumn, oData) {' . 'var val = Number(oData) / 100;' . 'elLiner.innerHTML = val.toFixed(2);' . '};' . 'this.formatBool = function(elLiner, oRecord, oColumn, oData) {' . 'elLiner.innerHTML = \'<img src="' . relurl('core_dev/gfx/icon_ok') . '\' + ( oData == 1 ? "" : "_gray") + \'.png"/>\';' . '};';
     for ($i = 0; $i < count($this->embed_arrays); $i++) {
         $res .= 'this.formatArray' . $i . ' = function(elLiner, oRecord, oColumn, oData) {' . 'var a=' . Json::encodeObject($this->embed_arrays[$i]) . ';' . 'elLiner.innerHTML = a[oData];' . '};' . 'YAHOO.widget.DataTable.Formatter.formatArray' . $i . ' = this.formatArray' . $i . ';';
     }
     $res .= 'YAHOO.widget.DataTable.Formatter.formatLink = this.formatLink;' . 'YAHOO.widget.DataTable.Formatter.formatDate = this.formatDate;' . 'YAHOO.widget.DataTable.Formatter.formatTime = this.formatTime;' . 'YAHOO.widget.DataTable.Formatter.formatMoney = this.formatMoney;' . 'YAHOO.widget.DataTable.Formatter.formatBool = this.formatBool;' . 'myColumnDefs = ' . Json::encode($this->columns) . ';' . "\n" . (is_array($this->data_source) ? 'var ' . $data_var . ' = ' . Json::encode($this->data_source) . ';' . "\n" . 'var myDataSource = new YAHOO.util.DataSource(' . $data_var . ');' . 'myDataSource.responseType = YAHOO.util.DataSource.TYPE_JSARRAY;' . 'myDataSource.responseSchema = { fields:' . Json::encode($this->response_fields, false) . '};' : 'var myDataSource = new YAHOO.util.DataSource("' . $this->data_source . '");' . 'myDataSource.responseType = YAHOO.util.DataSource.TYPE_JSON;' . 'myDataSource.responseSchema = {' . 'resultsList: "records",' . 'fields: ' . Json::encode($this->response_fields, false) . ',' . 'metaFields: { totalRecords:"totalRecords" }' . '};');
     if ($this->color_rows) {
         // Define a custom row formatter function
         $res .= 'var myRowFormatter = function(elTr, oRecord) {';
         foreach ($this->color_rows as $col) {
             $c1 = is_numeric($col->c1) ? $col->c1 : 'parseInt( oRecord.getData("' . $col->c1 . '") )';
             $c2 = is_numeric($col->c2) ? $col->c2 : 'parseInt( oRecord.getData("' . $col->c2 . '") )';
             $res .= 'if (' . $c1 . ' ' . $col->comparison . ' ' . $c2 . ') YAHOO.util.Dom.addClass(elTr, "' . $col->css . '");';
             //                        'alert( '.$c1.' + " '.$col->comparison.' " + '.$c2.' + " = " + ('.$c1.' '.$col->comparison.' '.$c2.')   );';
         }
         $res .= 'return true;' . '};';
     }
     $res .= 'var myConfigs = {' . 'caption:"' . $this->caption . '",' . ($this->pixel_width ? 'width:"' . $this->pixel_width . 'px",' : '') . ($this->pixel_height ? 'height:"' . $this->pixel_height . 'px",' : '') . ($this->sort_order ? 'sortedBy: {' . 'key:"' . $this->columns[$this->sort_column]->key . '",' . 'dir:YAHOO.widget.DataTable.' . ($this->sort_order == 'asc' ? 'CLASS_ASC' : 'CLASS_DESC') . '},' : '') . ($this->color_rows ? 'formatRow: myRowFormatter,' : '') . ($this->show_paginator ? 'paginator: new YAHOO.widget.Paginator({' . (is_array($this->data_source) ? 'totalRecords:' . count($this->data_source) . ',' : '') . 'rowsPerPage:' . $this->rows_per_page . ',' . 'rowsPerPageOptions:[' . implode(',', $this->rpp_opts) . '],' . 'containers:["' . $pag_holder . '"],' . 'template:"{FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} &nbsp; {CurrentPageReport} {RowsPerPageDropdown} per page",' . 'pageReportTemplate:"Showing items {startRecord} - {endRecord} of {totalRecords}",' . '}),' : '') . (!is_array($this->data_source) ? 'dynamicData:true,' . 'initialRequest:"startIndex=0' . ($this->sort_column !== false ? '&sort=' . $this->columns[$this->sort_column]->key : '') . ($this->sort_order ? '&dir=' . $this->sort_order : '') . '&results=' . $this->rows_per_page . '"' : '') . '};';
     $tbl_type = $this->pixel_width || $this->pixel_height ? 'ScrollingDataTable' : 'DataTable';
     $res .= 'tbl = new YAHOO.widget.' . $tbl_type . '("' . $div_holder . '",myColumnDefs, myDataSource, myConfigs);' . (!is_array($this->data_source) ? 'tbl.handleDataReturnPayload = function(oRequest, oResponse, oPayload) {' . 'oPayload.totalRecords = oResponse.meta.totalRecords;' . 'return oPayload;' . '};' : '') . 'tbl.subscribe("rowMouseoverEvent", tbl.onEventHighlightRow);' . 'tbl.subscribe("rowMouseoutEvent", tbl.onEventUnhighlightRow);' . 'return {' . 'oDS: myDataSource,' . 'oDT: tbl' . '};' . '}();' . '});';
     return '<div id="' . $pag_holder . '"></div>' . '<div id="' . $div_holder . '"></div>' . js_embed($res);
 }