Exemple #1
0
function printPartnerTable($partner_list)
{
    $str = "<tr style='color:white; background-color:gray;' ><td style='width:50px'>id</td>" . "<td style='width:200px;'>name</td>" . "<td>type</td>" . "<td>url</td>" . "<td>age</td>" . "<td>views</td>" . "<td>plays</td>" . "<td>entries</td></tr>";
    $i = 0;
    foreach ($partner_list as $p) {
        $i++;
        $url = $p->getUrl1();
        $str .= "<tr style='background-color: " . ($i % 2 ? "lightgray" : "lightblue") . "'>" . "<td>" . $p->getId() . "</td>" . "<td>" . substr($p->getPartnerName(), 0, 50) . "</td>" . "<td>" . partnerType($p) . "</td>" . "<td>" . "<a href='{$url}'>{$url}</a>" . "</td>" . "<td>" . age($p) . "</td>" . "<td>" . prop($p, "views") . "</td>" . "<td>" . prop($p, "plays") . "</td>" . "<td>" . prop($p, "entries") . "</td>" . "</tr>";
    }
    return $str;
}
function addRow($partner_stat, $even_row)
{
    $email = @$partner_stat["email"];
    $description = @$partner_stat["description"];
    $url = @$partner_stat["url1"];
    if ($url) {
        $url = "<a href='javascript:newWindow(\"{$url}\");'>{$url}</a>";
    }
    $widget_count = @$partner_stat["widgets"] > 0;
    $s = '<tr ' . ($even_row ? 'class="even" ' : '') . '>' . '<td>' . ($widget_count ? '<a href="javascript:referer( \'' . $partner_stat["id"] . '\');">' . $partner_stat["id"] . '</a>' : $partner_stat["id"]) . '</td>' . '<td style="text-align:left;">' . @$partner_stat["name"] . '</td>' . '<td style="text-align:left;">' . $email . '</td>' . '<td style="text-align:left;">' . $url . '</td>' . '<td style="text-align:left;">' . $description . '</td>' . '<td>' . prop($partner_stat, "categories") . '</td>' . '<td>' . prop($partner_stat, "created") . '</td>' . '<td>' . prop($partner_stat, "views", true) . '</td>' . '<td>' . prop($partner_stat, "plays", true) . '</td>' . '<td>' . prop($partner_stat, "rcs", true) . '</td>' . '<td>' . prop($partner_stat, "widgets", true) . '</td>' . '<td>' . prop($partner_stat, "entries", true) . '</td>' . '<td>' . @$partner_stat["videos"] . '</td>' . '<td>' . @$partner_stat["audios"] . '</td>' . '<td>' . @$partner_stat["images"] . '</td>' . '<td>' . @$partner_stat["activeSite7"] . '</td>' . '<td>' . @$partner_stat["activeSite30"] . '</td>' . '<td>' . @$partner_stat["activeSite180"] . '</td>' . '<td>' . @$partner_stat["activePublisher7"] . '</td>' . '<td>' . @$partner_stat["activePublisher30"] . '</td>' . '<td>' . @$partner_stat["activePublisher180"] . '</td>' . '<td>' . @$partner_stat["bandwidth"] . '</td>' . '<td>' . @$partner_stat["bandwidth_gt"] . '</td>' . '</tr>';
    return $s;
}
Exemple #3
0
 function get_index($type = null, $object = null)
 {
     $object = (int) $object;
     $parent = $this->in('parent', null);
     if (!$this->accessible('list', $object, $parent)) {
         return false;
     }
     $rows = Post::with('author')->where('type', '=', $type)->where('object', '=', $object)->order_by('created_at', 'desc');
     "{$parent}" === '' or $rows->where('parent', '=', $parent ?: null);
     $rows = $rows->get();
     if ($rows and !$this->can('post.hidefiles')) {
         $files = File::fromLists('post', prop('id', $rows));
         $rows = S($rows, function ($model) use($files) {
             $attachments = (array) array_get($files, $model->id);
             return compact('attachments') + $model->withHTML()->to_array();
         });
     }
     return compact('rows');
 }
function node_controller()
{
    global $mysqli, $redis, $session, $route, $feed_settings, $user;
    $result = false;
    if (!isset($session['read'])) {
        return array('content' => $result);
    }
    include "Modules/feed/feed_model.php";
    $feed = new Feed($mysqli, $redis, $feed_settings);
    require "Modules/input/input_model.php";
    // 295
    $input = new Input($mysqli, $redis, $feed);
    require "Modules/input/process_model.php";
    // 886
    $process = new Process($mysqli, $input, $feed);
    $process->set_timezone_offset($user->get_timezone($session['userid']));
    include "Modules/node/node_model.php";
    $node = new Node($mysqli, $redis, $process);
    if ($route->format == 'html') {
        if ($route->action == "list" && $session['write']) {
            $result = view("Modules/node/node_view.php", array());
        }
        if ($route->action == "api" && $session['write']) {
            $result = view("Modules/node/node_api.php", array());
        }
    }
    if ($route->format == 'json') {
        if ($route->action == 'set' && $session['write']) {
            $data = explode(",", get('data'));
            for ($i = 0; $i < count($data); $i++) {
                $data[$i] = (int) $data[$i];
            }
            $result = $node->set($session['userid'], get('nodeid'), get('time'), $data);
        }
        if ($route->action == 'multiple' && $session['write']) {
            $data = json_decode(prop('data'));
            $len = count($data);
            if ($len > 0 && isset($data[$len - 1][0])) {
                // Sent at mode: input/bulk.json?data=[[45,16,1137],[50,17,1437,3164],[55,19,1412,3077]]&sentat=60
                if (isset($_GET['sentat'])) {
                    $time_ref = time() - (int) $_GET['sentat'];
                } elseif (isset($_POST['sentat'])) {
                    $time_ref = time() - (int) $_POST['sentat'];
                } elseif (isset($_GET['offset'])) {
                    $time_ref = time() - (int) $_GET['offset'];
                } elseif (isset($_POST['offset'])) {
                    $time_ref = time() - (int) $_POST['offset'];
                } elseif (isset($_GET['time'])) {
                    $time_ref = (int) $_GET['time'];
                } elseif (isset($_POST['time'])) {
                    $time_ref = (int) $_POST['time'];
                } else {
                    $time_ref = time() - (int) $data[$len - 1][0];
                }
                foreach ($data as $item) {
                    if (count($item) > 2) {
                        // check for correct time format
                        $itemtime = (int) $item[0];
                        $time = $time_ref + (int) $itemtime;
                        $nodeid = $item[1];
                        $bytevalues = array();
                        for ($i = 2; $i < count($item); $i++) {
                            $bytevalues[] = (int) $item[$i];
                        }
                        $result = $node->set($session['userid'], $nodeid, $time, $bytevalues);
                    }
                }
            }
        }
        if ($route->action == 'setdecoder' && $session['write']) {
            $result = $node->set_decoder($session['userid'], get('nodeid'), get('decoder'));
        }
        if ($route->action == 'getall' && $session['write']) {
            $result = $node->get_all($session['userid']);
        }
    }
    /*
    // Sent at mode: data= [[45,16,1137]] &sentat=60
        // Offset mode:  data= [[-10,16,1137]] &offset=-10
        // Time mode:    data= [[-10,16,1137]] &time=1387729425
        // Legacy mode:  data= [[0,16,1137]]
    // Sent at mode: data= [[45,16,1137],[50,17,1437,3164],[55,19,1412,3077]] &sentat=60
        // Offset mode:  data= [[-10,16,1137],[-8,17,1437,3164],[-6,19,1412,3077]] &offset=-10
        // Time mode:    data= [[-10,16,1137],[-8,17,1437,3164],[-6,19,1412,3077]] &time=1387729425
        // Legacy mode:  data= [[0,16,1137],[2,17,1437,3164],[4,19,1412,3077]]
    */
    return array('content' => $result);
}
Exemple #5
0
 /**
  * Perform cURL requests and throw appropriate exceptions.
  *
  * An array of parameters used in a curl_setopt_array,
  * multiple calls can be passed in.
  *
  * This function make use of curl_multi no matter it is
  * single request or not.
  *
  * Callbacks are used to handle results inside the array.
  *
  * $option['callbacks'] = array(
  *   'progress' => [Function]
  * , 'success' => [Function]
  * , 'failure' => [Function]
  * , 'always'  => [Function]
  * );
  *
  * @return void
  */
 public static function curlRequest($options)
 {
     $options = Utility::wrapAssoc(array_values((array) $options));
     $multiHandle = curl_multi_init();
     // Initialize cUrl options
     array_walk($options, function (&$option) {
         // 1. Request headers
         $option['response'] = array('headers' => '');
         $option[CURLOPT_HEADERFUNCTION] = function ($curl, $data) use(&$option) {
             $option['response']['headers'] .= $data;
             return strlen($data);
         };
         // 2. Progress function
         $progressCallback =& $option['callbacks']['progress'];
         if ($progressCallback) {
             $option[CURLOPT_NOPROGRESS] = false;
             $option[CURLOPT_PROGRESSFUNCTION] = function () use(&$progressCallback) {
                 if (func_num_args() == 4) {
                     list($dSize, $dLen, $uSize, $uLen) = func_get_args();
                 } else {
                     list($req, $dSize, $dLen, $uSize, $uLen) = func_get_args();
                 }
                 if ($dSize || $dLen) {
                     static $_dLen = 0;
                     if ($_dLen != $dLen) {
                         $_dLen = $dLen;
                         /*! Note by Vicary @ 2.Oct.2012
                          *  Total download size is often 0 if server doesn't
                          *  response with a Content-Length header.
                          *
                          *  Total size guessing logic:
                          *  1. if $dLen < 1M, assume 1M.
                          *  2. if $dLen < 10M, assume 10M.
                          *  3. if $dLen < 100M, assume 100M.
                          *  4. if $dLen < 1G, assume 1G.
                          */
                         if (!$dSize) {
                             // Do not assume when size under 1K
                             if ($dLen < 5000) {
                                 return;
                             } elseif ($dLen < 10000000) {
                                 $dSize = 20000000;
                             } elseif ($dLen < 100000000) {
                                 $dSize = 200000000;
                             } elseif ($dLen < 1000000000) {
                                 $dSize = 2000000000;
                             } else {
                                 $dSize = 20000000000;
                             }
                             // $dSize = $dLen / .05;
                         }
                         // Download progress, from 0 to 1.
                         $progressArgs = array($dLen / $dSize, $dLen, $dSize);
                     }
                 } else {
                     if ($uSize) {
                         static $_uLen = 0;
                         if ($_uLen != $uLen) {
                             $_uLen = $uLen;
                             $uSize *= -1;
                             $uLen += $uSize;
                             // Upload progress, from -1 to 0.
                             $progressArgs = array($uLen / $uSize, $uLen, $uSize);
                         }
                     }
                 }
                 // Fire the event for each µSeconds.
                 static $_tOffset = 0;
                 $tOffset = microtime(1);
                 if (isset($progressArgs) && $tOffset - $_tOffset > self::progressInterval()) {
                     $_tOffset = $tOffset;
                     Utility::forceInvoke($progressCallback, $progressArgs);
                 }
             };
         }
         unset($progressCallback);
         // 3. Apply cUrl options, numeric keys only.
         $option['handle'] = curl_init();
         curl_setopt_array($option['handle'], array_filter_keys($option, 'is_int'));
     });
     $requestIndex = 0;
     while ($requestIndex < self::$maximumRequests && isset($options[$requestIndex])) {
         curl_multi_add_handle($multiHandle, $options[$requestIndex++]['handle']);
     }
     // Start the multi request
     do {
         $status = curl_multi_exec($multiHandle, $active);
         /* Added by Vicary @ 6.Nov.2012
               Blocks until there is a message arrives.
            */
         curl_multi_select($multiHandle);
         do {
             $info = curl_multi_info_read($multiHandle, $queueLength);
             if ($info === FALSE) {
                 continue;
             }
             $optionIndex = array_search($info['handle'], array_map(prop('handle'), $options));
             if ($optionIndex === FALSE) {
                 continue;
             }
             $curlOption =& $options[$optionIndex];
             $callbacks =& $curlOption['callbacks'];
             // Success handler
             if ($info['result'] === CURLE_OK) {
                 // Fire a 100% downloaded event.
                 if (@$callbacks['progress']) {
                     Utility::forceInvoke($callbacks['progress'], array(1, 1, 1));
                     usleep(self::progressInterval() * 1000000);
                 }
                 // Append HTTP status code
                 $curlOption['status'] = curl_getinfo($info['handle'], CURLINFO_HTTP_CODE);
                 Utility::forceInvoke(@$callbacks['success'], array(curl_multi_getcontent($info['handle']), $curlOption));
             } else {
                 $errorNumber = curl_errno($info['handle']);
                 $errorMessage = curl_error($info['handle']);
                 // libcurl errors, try to parse it.
                 if ($errorNumber === 0) {
                     if (preg_match('/errno: (\\d+)/', $errorMessage, $matches)) {
                         $errorNumber = (int) $matches[1];
                         $curlErrors = unserialize(FRAMEWORK_NET_CURL_ERRORS);
                         if (isset($curlErrors[$errorNumber])) {
                             $errorMessage = $curlErrors[$errorNumber];
                         }
                     }
                 }
                 Utility::forceInvoke(@$callbacks['failure'], array($errorNumber, $errorMessage, $curlOption));
                 unset($errorNumber, $errorMessage);
             }
             // Always handler
             Utility::forceInvoke(@$callbacks['always'], array($curlOption));
             if (isset($options[$requestIndex])) {
                 curl_multi_add_handle($multiHandle, $options[$requestIndex++]['handle']);
                 // Keep the loop alive.
                 $active = TRUE;
             }
             curl_multi_remove_handle($multiHandle, $info['handle']);
             curl_close($info['handle']);
             unset($info, $callbacks, $curlOption, $options[$optionIndex], $optionIndex);
         } while ($queueLength > 0);
     } while ($status === CURLM_CALL_MULTI_PERFORM || $active);
     curl_multi_close($multiHandle);
 }
Exemple #6
0
 function get_by_list($name = 'main', $slides = false)
 {
     if ($name === '*') {
         if ($route = \Vane\Route::current() and $route->lastServer) {
             $name = \Bundle::element($route->lastServer->name);
             $name = S::tryUnprefix(strtok($name, '@'), 'block.');
         } else {
             $name = null;
         }
     }
     $default = $this->in('default', 'main');
     if (!$name and !$default) {
         return E_INPUT;
     }
     $query = ProductListItem::order_by('sort');
     $name and $query->where('type', '=', $name);
     $default and $query->or_where('type', '=', $default);
     if ($list = $query->get()) {
         if ($default and !S::first($list, array('?->type === ?', $name))) {
             $type = $default;
         } else {
             $type = $name;
         }
         $list = S::keep($list, array('?->type === ?', $type));
         $goods = S::keys(Product::all(prop('product', $list)), '?->id');
         $ordered = array();
         foreach ($list as $item) {
             $product =& $goods[$item->product];
             if ($product and (!$slides or $product->image)) {
                 $product->extra = $item->extra;
                 $ordered[] = $product;
             }
         }
         $this->layout = $slides ? '.slides' : '.index';
         return static::listResponse($slides ? 1000 : 320, $ordered);
     }
 }
echo $version;
?>
" readonly="readonly" />
		<span style="color: blue;"><?php 
echo $version_text;
?>
</span>
	</td>
	<td style="color:gray; font-size:11px; font-family:arial;">THIS CANNOT BE EDITED HERE, TO MIGRATE OLD PARTNER TO KMC 2 PLEASE CONTACT R&D</td>
</tr>
<?php 
echo prop($partner, "liveStreamEnabled", "select", "1", "0", "boolean_int_type", "Live-Stream enabled");
echo prop($partner, "enableAnalyticsTab", "select", "1", "0", "boolean_int_type", "Reports and Analytics tab enabled");
echo prop($partner, "enableSilverLight", "select", "1", "0", "boolean_int_type", "Silver Light players enabled");
echo prop($partner, "enableVast", "select", "1", "0", "boolean_int_type", "VAST support in app-studio enabled");
echo prop($partner, "enable508Players", "select", "1", "0", "boolean_int_type", "508 players in the KMC preview&embed are available");
if (class_exists('MetadataPlugin')) {
    ?>
			<tr class='prop'>
				<td>Enable Metadata</td>
				<td>
					<select id="partner_enableMetadata" style="font-family:arial; font-size:12px;" name="partner_enableMetadata" onkeyup="updateSelect( this )" onchange="updateSelect( this )">
					<?php 
    $list = array("" => "", "1" => "true", "0" => "false");
    $default_value = '0';
    if ($partner) {
        $default_value = $partner->getPluginEnabled(MetadataPlugin::PLUGIN_NAME);
    }
    $default_value_selected = "";
    foreach ($list as $value => $option) {
        // not always the default value is found
Exemple #8
0
            $date = strtok($date->format($query->grammar->datetime), ' ');
            $query->where(\DB::raw('DATE(created_at)'), $op, $date)->or_where(\DB::raw('DATE(updated_at)'), $op, $date);
        });
    }
    if ($names = $block->in('names', '')) {
        $query->where(function ($query) use($names) {
            $query->raw_where('LOCATE(?, name) = 1', array($names))->raw_or_where('LOCATE(?, surname) = 1', array($names));
        });
    }
    $can['filter'] += compact('date', 'names');
});
// Fired to add extra attributes to Orders retrieved with order.list.query.
//
//* $orders array of Order
Event::listen(VANE_NS . 'order.list.populate', function (array &$orders, Block_Order $block, array &$vars) {
    $counts = OrderProduct::where_in('order', prop('id', $orders))->group_by('order')->select(array('*', \DB::raw('COUNT(1) AS count')))->get();
    $counts = S::keys($counts, '?->order');
    foreach ($orders as $order) {
        $order->count = $counts[$order->id]->count;
    }
});
Event::listen(VANE_NS . 'order.list.populate', function (array &$orders, Block_Order $block, array &$vars) {
    $recentTime = time() - 3 * 24 * 3600;
    foreach ($orders as $order) {
        $order->recent = $order->updated_at >= $recentTime;
    }
});
// Fired to do final preparations of variables returned to client/given to template.
Event::listen(VANE_NS . 'order.list.populate', function (array &$vars, Block_Order $block) {
});
/*-----------------------------------------------------------------------
echo prop($conv_params, "profileTypeIndex", "text", "15", "", "", "the order in which this set of params will be used in a the profile");
echo prop($conv_params, "commercialTranscoder", "select", "1", "", "boolean_int_type", "");
echo prop($conv_params, "width", "text", "15", "");
echo prop($conv_params, "height", "text", "15", "");
echo prop($conv_params, "aspectRatio", "select", "1", "1", "aspect_ratio", "");
echo prop($conv_params, "gopSize", "text", "15", "", "", "once every X frames will force a keyframe");
echo prop($conv_params, "bitrate", "text", "15", "");
echo prop($conv_params, "qscale", "text", "15", "", "", "quality scale: 1-31, 1 is best. If should be the same as original, use 'sameq' in the extra params");
echo prop($conv_params, "framerate", "text", "15", "25", "", "default should be 25");
echo prop($conv_params, "audioBitrate", "text", "15", "", "", "NUMBER ONLY, Can leave empty, can be 64,80,96,112,128,160,192,224,256,288,320");
echo prop($conv_params, "audioSamplingRate", "text", "15", "", "", "NUMBER ONLY in Hz, can be 22050/44100");
echo prop($conv_params, "audioChannels", "select", "1", "2", "audio_channels_type", "");
echo prop($conv_params, "fileSuffix", "text", "15", "", "", "The suffix of the file - MUST NOT be empty when using 'profileTypeIndex' > 1");
echo prop($conv_params, "ffmpegParams", "text", "25", "");
echo prop($conv_params, "mencoderParams", "text", "25", "");
echo prop($conv_params, "flixParams", "text", "25", "");
?>
</table>
</div>
<div style="width:100%; text-align: right">
<?php 
if ($conv_params->getId() == "" || $conv_params->getId() > 100 || $ok_to_save) {
    ?>
<input type="submit" name="save" value="save" onclick="return saveConvParams()">
<?php 
} else {
    ?>
<span style='background-color:red; color:white; text-align: center' ><b>System</b> Conversion Params cannot be modified</span> 
<?php 
}
?>
Exemple #10
0
/**
 * @desc Build project
 * @deps runtests
 */
function task_build()
{
    sysmsg("Building project '" . prop('PROJECT_DIR') . "'...\n");
}
Exemple #11
0
<?php

/*! HeadlessWorker.php | Takes care of headless process ahead. */
require_once '.private/scripts/Initialize.php';
use core\Database;
use core\Log;
use framework\Bayeux;
use framework\Configuration as conf;
use framework\Service;
use models\WorkInstance;
use models\TaskInstance;
$taskInstance = new TaskInstance();
// Consumes Headless tasks ahead.
$tasks = Database::fetchArray('SELECT `nextTask` FROM `WorkInstance`
  WHERE `nextTask` IN (SELECT `uuid` FROM `TaskInstance` WHERE `type` = \'Headless\')
    AND `state` = \'Open\';');
$tasks = array_map(compose('core\\Utility::unpackUuid', prop('nextTask')), $tasks);
if ($tasks) {
    Log::debug(sprintf('%d headless tasks found!', count($tasks)), $tasks);
}
$serviceOptions = array('resolver' => new framework\Resolver());
$serviceOptions['resolver']->registerResolver(new resolvers\WebServiceResolver(array('prefix' => conf::get('web::resolvers.service.prefix', '/service'))));
foreach ($tasks as $taskUuid) {
    // renew response object for each call
    $serviceOptions['response'] = new framework\Response(array('autoOutput' => false));
    Service::call('_/WorkInstance', 'process', array($taskUuid), $serviceOptions);
    // todo: send bayeux update message to notify related users about the task update.
}
<br>
<span style='color:red;'>Leave id empty to create new Conversion Profile</span>
<br>
<table>
<tr><td style="font-weight:bold; " colspan="3"><hr/>General</td></tr>
<?php 
echo prop($conv_profile, "partnerId", "text", "15", "");
echo prop($conv_profile, "name", "text", "15", "");
echo prop($conv_profile, "enabled", "select", "1", "", "boolean_int_type", "make this profile usable or not");
echo prop($conv_profile, "profileType", "text", "15", "", "", "* together with the partnerId, primary key to define the params that will be selected");
echo prop($conv_profile, "profileTypeSuffix", "text", "15", "", "", "* together with the partnerId and profileType , secondary key to define the params that will be selected");
echo prop($conv_profile, "bypassFlv", "select", "1", "", "boolean_int_type", "");
echo prop($conv_profile, "commercialTranscoder", "select", "1", "", "boolean_int_type", "");
echo prop($conv_profile, "width", "text", "15", "");
echo prop($conv_profile, "height", "text", "15", "");
echo prop($conv_profile, "aspectRatio", "select", "1", "1", "aspect_ratio", "");
?>
</table>
</div>
<br/>
<?php 
if ($conv_profile_id == "" || $conv_profile_id > 2000 || $ok_to_save) {
    ?>
<input type="submit" name="save" value="save" onclick="return saveConvParams()">
<?php 
} else {
    ?>
<span style='background-color:red; color:white; text-align: center' ><b>System</b> Conversion Profile cannot be modified</span> 
<?php 
}
?>
<script>
function openPartner ( pid )
{
	url = '<?php 
echo url_for("/system");
?>
' + "/partners?partner_id=" + pid + "&go=go";
	var handle = window.open ( url , "partner" ); 
}
</script>
<div style='font-family:verdana; font-size:12px;'>
<form method="get">
	keyword: <input type="text" name="hint" value="<?php 
echo $hint;
?>
">
	<input type="submit" name="search" value="search"/>
	Use the '%' character as a wild-char between words
</form>
<table border=1 cellpadding=2 cellspacing=0>
	<tr>
		<td>id</td><td>name</td><td>description</td><td>admin email</td><td>created at</td><td>package</td>
	</tr>
<?php 
foreach ($partner_list as $p) {
    echo "<tr>" . prop($p, "id") . "</a>" . prop($p, "partnername") . prop($p, "description", 80) . prop($p, "adminemail") . prop($p, "createdat") . prop($p, "partnerpackage") . "</tr>";
}
?>
</table>
</div>
Exemple #14
0
 /**
  * Because POST can be JSON, or other formats in the future, we cannot simply
  * use $_REQUEST.
  *
  * Another difference with $_REQUEST is this also counts $_COOKIE.
  */
 public function param($name = null, $type = null)
 {
     /*! Note @ 23 Apr, 2015
      *  POST validation should be simple, just match it with some hash key stored in sessions.
      */
     // TODO: Do form validation, take reference from form key of Magento.
     $result = $this->_param($type);
     if (is_array($result)) {
         // remove meta keys and sensitive values
         $result = array_filter_keys($result, funcAnd(notIn([ini_get('session.name')]), compose('not', startsWith($this->metaPrefix))));
     }
     if ($name === null) {
         return $result;
     } else {
         $fx = prop($name);
         return $fx($result);
     }
 }
Exemple #15
0
 /**
  * @protected
  *
  * Returns all composer.json, this respects list range and list order, but
  * filtering is not supported.
  */
 function find(array $filter = array())
 {
     // list tasks modules
     $modules = glob('.private/modules/*/*/composer.json');
     $modules = array_map(compose('core\\ContentDecoder::json', 'file_get_contents'), $modules);
     $modules = array_map(function ($module) {
         return (new Task($module))->afterLoad();
     }, $modules);
     // @sorter, list order
     if (isset($filter['@sorter'])) {
         $sorter = array();
         foreach ($filter['@sorter'] as $key => $value) {
             // numeric key, use value as ASC sorting
             if (is_numeric($key) && is_string($value)) {
                 $key = $value;
                 $value = true;
             }
             $sorter[] = array_map(prop($key), $modules);
             $sorter[] = $value ? SORT_ASC : SORT_DESC;
         }
         $sorter[] =& $modules;
         call_user_func_array('array_multisort', $sorter);
         unset($sorter);
     }
     // @limits, list range
     if (isset($filter['@limits'])) {
         $modules = call_user_func_array('array_slice', array_merge(array($modules), $filter['@limits']));
     }
     return $modules;
 }
Exemple #16
0
 function get_goods($id = null)
 {
     if ($result = $this->ajax($id)) {
         $this->layout = 'vanemart::block.cart.goods';
         $goods = $result->order_by('group')->get();
         // cache connected images all at once.
         File::all(prop('image', $goods));
         if ($this->in('grouped', 1)) {
             $groups = Group::where_in('id', prop('group', $goods))->lists('title', 'id');
         } else {
             $groups = array();
         }
         $rows = S($goods, function ($product) use($groups) {
             return array('image' => $product->image(200), 'group' => array_get($groups, $product->group)) + $product->to_array();
         });
         return compact('rows') + array('showGroups' => true);
     } else {
         return $result;
     }
 }
Exemple #17
0
function propIn($prop, array $values, $strict = false)
{
    return compose(in($values, $strict), prop($prop));
}
Exemple #18
0
        return $_GET[$getvar];
    } else {
        return $default;
    }
}
if (!$ajax) {
    print "<h1>Unofficial SkyMiles calculator &mdash; results</h1>\n";
}
$total_gc_miles = 0;
$total_mqm = str_replace(",", "", prop("start_mqm", 0));
update_elite_status($total_mqm, "DL");
$total_rdm = str_replace(",", "", prop("start_rdm", 0));
$elite = prop("elite", "peon");
$default_carrier = strtoupper(prop("default_carrier", "DL"));
$default_fare = strtoupper(prop("default_fare", "T"));
$whole_route = trim(prop("route", ""));
$lines = preg_split("/[\n\r]+/", $whole_route);
if (!$ajax) {
    print "<div class=\"results\">\n";
    print "Beginning with " . c("miles-eqm", $total_mqm) . " MQM, " . c("miles-rdm", $total_rdm) . " redeemable miles, and " . c("elite-" . $elite, $elite) . " status.";
    print "<hr/>";
}
foreach ($lines as $line) {
    # Allow user to specify negative numbers for bonus miles
    # JFK-5000: gained 5000 miles
    # JFK--5000: lost 5000 miles
    # JFK- -5000: lost
    # JFK -5000: lost
    $line = preg_replace("/[\\-\\s]\\-([0-9])/", '-_$1', $line);
    $line = preg_replace("/^-/", '_', $line);
    # Grab a line of the whole route and tokenize it.
Exemple #19
0
 static function fromSKU($skus)
 {
     $result = array();
     $skus and Event::fire('cart.from_skus', array(&$result, &$skus));
     return $result ? array_combine(prop('id', $result), $result) : array();
 }
Exemple #20
0
 /**
  * Gets fields with specified key type.
  */
 public static function getFields($tables, $key = null, $nameOnly = true)
 {
     $tables = Utility::wrapAssoc($tables);
     $cache =& self::$schemaCache;
     // Clear the cache on expire
     if (@$cache['timestamp'] < strtotime('-30min')) {
         unset($cache['collections']);
         $cache['timestamp'] = microtime(1);
     }
     array_walk($tables, function ($tableName) use(&$cache) {
         if (!Database::hasTable($tableName)) {
             throw new \PDOException("Table {$tableName} doesn't exists!");
         }
         if (@$cache['collections'][$tableName]) {
             return;
         }
         $res = Database::fetchArray('SHOW COLUMNS FROM ' . static::escapeField($tableName));
         $res = array_combine(array_map(prop('Field'), $res), array_map(removes('Field'), $res));
         $res = array_map(function ($info) {
             $info['Key'] = preg_split('/\\s*,\\s*/', $info['Key']);
             foreach ($info as &$value) {
                 switch ($value) {
                     case 'YES':
                         $value = true;
                         break;
                     case 'NO':
                         $value = false;
                         break;
                 }
             }
             return $info;
         }, $res);
         $cache['collections'][$tableName] = $res;
     });
     $tables = array_map(function ($tableName) use($cache, $key, $nameOnly) {
         $cache = $cache['collections'][$tableName];
         if ($key !== null) {
             $key = Utility::wrapAssoc($key);
             $cache = array_filter($cache, propHas('Key', $key));
         }
         return $cache;
     }, $tables);
     $tables = array_reduce($tables, function ($result, $fields) {
         return array_merge($result, (array) $fields);
     }, array());
     if ($nameOnly) {
         $tables = array_unique(array_keys($tables));
     }
     return $tables;
 }
                if (isset($heating->schedule)) {
                    save("app/heating/schedule", $heating->schedule);
                }
                print "ok";
            }
            if ($key == "app/heating/state") {
                save("app/heating/state", prop('val'));
            }
            if ($key == "app/heating/manualsetpoint") {
                save("app/heating/manualsetpoint", prop('val'));
            }
            if ($key == "app/heating/mode") {
                save("app/heating/mode", prop('val'));
            }
            if ($key == "app/heating/schedule") {
                save("app/heating/schedule", prop('val'));
            }
        }
}
function prop($index)
{
    $val = null;
    if (isset($_GET[$index])) {
        $val = $_GET[$index];
    }
    if (isset($_POST[$index])) {
        $val = $_POST[$index];
    }
    if (get_magic_quotes_gpc()) {
        $val = stripslashes($val);
    }
Exemple #22
0
 function subgroups($depth = -1, $withSelf = true)
 {
     $all = $next = array($this);
     while ($next and --$depth != 0) {
         $next = static::where_in('parent', prop('id', $next))->get();
         $all = array_merge($all, $next);
     }
     return $withSelf ? $all : S::slice($all);
 }