Example #1
0
function object_area($l, $w, $h)
{
    $parts = array($l * $w, $w * $h, $h * $l);
    $min = min($parts);
    $area = 0;
    foreach ($parts as $part) {
        $area += 2 * $part;
    }
    $area += $min;
    return $area;
}
function volume($l, $w, $h)
{
    return $l * $w * $h;
}
function smallest_perimeter($l, $w, $h)
{
    return min([2 * ($l + $w), 2 * ($w + $h), 2 * ($l + $h)]);
}
$lines = file(__DIR__ . '/input/2');
$lines = array_map('trim', $lines);
$total = 0;
$ribbon = 0;
foreach ($lines as $line) {
    $dimensions = dimensions($line);
    $total += call_user_func_array('object_area', $dimensions);
    $ribbon += call_user_func_array('volume', $dimensions) + call_user_func_array('smallest_perimeter', $dimensions);
}
echo "TOTAL: " . $total;
echo '<br><br>';
echo "RIBBON: " . $ribbon;
Example #2
0
function getGeneralDetails($tag, $typeString = '', $whatItDoes = '')
{
    global $tagLibrary, $tagTypes, $container, $usedTriggers, $trigLibrary, $trigTypes, $untriggeredTags, $userIdUsed, $legacyTags, $folderArray, $usedUdvs, $udvUsage;
    $technicalDetails = '';
    $rawHTML = getParam($tag, 'html');
    $deets = '<table class="table table-bordered table-striped">';
    $deets = $deets . '<tr><th>Name</th><td>' . $tag['name'] . '</td></tr>';
    $deets = $deets . '<tr><th>Type</th><td>' . $typeString . '</td></tr>';
    $deets = $deets . '<tr><th>What it does</th>';
    if ($whatItDoes === '') {
        if ($rawHTML !== '') {
            $containsScript = strpos($rawHTML, '<script') > -1 ? 'contains JavaScript' : 'contains HTML';
            $deets = $deets . '<td>This tag ' . $containsScript . '. Being a custom tag, you need to make sure this is carefully reviewed by your developers.<br />';
            $deets = $deets . '<textarea class="form-control" rows="10" cols="60" disabled="disabled">' . $rawHTML . '</textarea></td></tr>';
            if (getParam($tag, 'supportDocumentWrite') === 'true') {
                $deets = $deets . '<tr><th></th><td>This tag supports document.write.</td></tr>';
            }
        }
        if (getParam($tag, 'trackType') !== '') {
            $deets = $deets . humanDetails(getParam($tag, 'trackType'), $tag);
        }
        if (getParam($tag, 'enableEcommerce') === 'true') {
            $deets = $deets . '<br />This tag uses Enhanced Ecommerce tracking features.<br />';
            if (getParam($tag, 'useEcommerceDataLayer') === 'true') {
                $deets = $deets . 'The Data Layer is used to record the Enhanced Ecommerce data (<b>Technical!</b>)<br />';
            } else {
                if (getParamTemplate($tag, 'ecommerceMacroData') !== '' && array_key_exists('value', getParamTemplate($tag, 'ecommerceMacroData'))) {
                    $deets = $deets . variablise(getParamTemplate($tag, 'ecommerceMacroData')['value'], $tag, true) . ' is used to record the Enhanced Ecommerce data (<b>Technical!</b>)<br />';
                }
            }
            $deets = $deets . '</td></tr>';
        } else {
            $deets = $deets . '</tr>';
        }
        if (getParam($tag, 'trackingId') !== '') {
            $deets = $deets . '<tr><th>The GA property ID is</th><td>' . translateToHuman(getParam($tag, 'trackingId'), $tag, true) . '</td></tr>';
        }
    } else {
        $deets = $deets . $whatItDoes;
    }
    $deets = $deets . '<tr><th>When it does it</th>';
    /******************************************************************************
       Firing triggers
       ******************************************************************************/
    if (array_key_exists('firingTriggerId', $tag) && count($tag['firingTriggerId']) > 0) {
        $triggerFound = false;
        $triggerLink = '';
        $firingTrigArray = [];
        if (count($tag['firingTriggerId']) > 1) {
            $triggerLink = '<td>This tag is fired by the following triggers:<ul>';
            foreach ($tag['firingTriggerId'] as $tagFiringKey => $tagFiringVal) {
                if (!array_search($tag['firingTriggerId'][$tagFiringKey], $usedTriggers)) {
                    array_push($usedTriggers, $tag['firingTriggerId'][$tagFiringKey]);
                }
                $triggerFound = false;
                foreach ($trigTypes as $trigTypeKey => $trigTypeVal) {
                    foreach ($trigLibrary[$trigTypeVal] as $trigKey => $trigVal) {
                        if ($tag['firingTriggerId'][$tagFiringKey] === $trigLibrary[$trigTypeVal][$trigKey]['triggerId']) {
                            $triggerLink = $triggerLink . buildTriggerLink($tag['firingTriggerId'][$tagFiringKey], '<li>', '</li> ', $trigLibrary, $trigTypes);
                            $triggerFound = true;
                        }
                    }
                }
                if ($triggerFound === false) {
                    $triggerLink = $triggerLink . '<li>Built-in <span title="This tag will fire on literally ALL PAGES!" style="background-color: #CCC"><b>All Pages</b></span> trigger.</li>';
                }
            }
            $deets = $deets . $triggerLink . '</ul></td></tr>';
        } else {
            if (!array_search($tag['firingTriggerId'][0], $usedTriggers)) {
                array_push($usedTriggers, $tag['firingTriggerId'][0]);
            }
            $triggerLink = buildTriggerLink($tag['firingTriggerId'][0], '<td>This tag is fired by the ', ' trigger. </td></tr>', $trigLibrary, $trigTypes);
            if ($triggerLink === '') {
                $deets = $deets . '<td>This tag is fired by the built-in <span title="This tag will fire on literally ALL PAGES!" style="background-color: #CCC"><b>All Pages</b></span> trigger.</td></tr>';
            } else {
                $deets = $deets . $triggerLink;
            }
        }
    } else {
        $deets = $deets . '<td>This tag <i>appears</i> to have <span title="This tag will NOT fire." style="background-color: #CCC"><b>no firing triggers</b></span>.</td></tr>';
        array_push($untriggeredTags, $tag);
    }
    /******************************************************************************
       Blocking triggers
       ******************************************************************************/
    if (array_key_exists('blockingTriggerId', $tag) && count($tag['blockingTriggerId']) > 0) {
        $deets = $deets . '<tr><th>When it is <b>stopped</b> from doing it</th>';
        $triggerFound = false;
        $blockingTrigArray = [];
        if (count($tag['blockingTriggerId']) > 1) {
            $triggerLink = '<td>This tag is blocked by the following triggers.<ul>';
            foreach ($tag['blockingTriggerId'] as $blockingTrigKey => $blockingTrigVal) {
                $triggerFound = false;
                foreach ($trigTypes as $trigTypeKey => $trigTypeVal) {
                    foreach ($trigLibrary[$trigTypeVal] as $trigKey => $trigVal) {
                        if ($tag['blockingTriggerId'][$blockingTrigKey] === $trigLibrary[$trigTypeVal][$trigKey]['triggerId']) {
                            $triggerLink = $triggerLink . buildTriggerLink($tag['blockingTriggerId'][$blockingTrigKey], '<li>', '</li> ');
                            $triggerFound = true;
                        }
                    }
                }
                if ($triggerFound === false) {
                    $triggerLink = $triggerLink . '<li>Built-in <span title="This tag will be blocked on literally ALL PAGES!" style="background-color: #CCC"><b>All Pages</b></span> trigger.</li>';
                }
            }
            $deets = $deets . $triggerLink . '</ul></td></tr>';
        } else {
            $triggerLink = buildTriggerLink($tag['blockingTriggerId'][0], '<td>This tag is <b>BLOCKED</b> by the ', ' trigger. </td></tr>', $trigLibrary, $trigTypes);
            if ($triggerLink === '') {
                $deets = $deets . '<td>This tag is <b>BLOCKED</b> by the built-in <span title="This tag be blocked on literally ALL PAGES!" style="background-color: #CCC"><b>All Pages</b></span> trigger.</td></tr>';
            } else {
                $deets = $deets . $triggerLink;
            }
        }
    }
    if (array_key_exists('scheduleStartMs', $tag)) {
        $deets = $deets . '<tr><th>Custom firing schedule start</th><td>The tag will only be live from ' . date('Y-m-d H:i:s', (int) $tag['scheduleStartMs'] / 1000);
        $nowDate = new DateTime();
        $startDate = new DateTime();
        $startDate->setTimestamp((int) $tag['scheduleStartMs'] / 1000);
        $interval = date_diff($nowDate, $startDate);
        if ($interval->invert === 1) {
            $deets = $deets . ' - this tag went live ' . $interval->format('%a days ago') . '.</td><tr>';
        }
        if ($interval->invert === 0) {
            $deets = $deets . ' - this will go live in ' . $interval->format('%a days') . '.</td><tr>';
        }
    }
    if (array_key_exists('scheduleEndMs', $tag)) {
        $deets = $deets . '<tr><th>Custom firing schedule end</th><td>The tag will only be live before ' . date('Y-m-d H:i:s', (int) $tag['scheduleEndMs'] / 1000);
        $nowDate = new DateTime();
        $endDate = new DateTime();
        $endDate->setTimestamp((int) $tag['scheduleEndMs'] / 1000);
        $interval = date_diff($nowDate, $endDate);
        if ($interval->invert === 1) {
            $deets = $deets . ' - this tag ended ' . $interval->format('%a days ago') . '. </td><tr>';
        }
        if ($interval->invert === 0) {
            $deets = $deets . ' - this tag will end in ' . $interval->format('%a days') . '.</td><tr>';
        }
    }
    /******************************************************************************
       Sequencing
       ******************************************************************************/
    $deets = $deets . sequence($tag);
    /******************************************************************************
       Firing priority
       ******************************************************************************/
    $deets = $deets . priority($tag);
    /******************************************************************************
       Firing Options
       ******************************************************************************/
    $humanFiringOption = array_key_exists('tagFiringOption', $tag) ? translateToHuman($tag['tagFiringOption'], $tag) : false;
    if ($humanFiringOption !== false) {
        $deets = $deets . '<tr><th></th><td>' . $humanFiringOption . '</td></tr>';
    }
    /******************************************************************************
       Published containers
       ******************************************************************************/
    if ($tag['liveOnly'] === 'true') {
        $deets = $deets . '<tr><th></th><td>This tag will only fire in published containers</td></tr>';
    }
    $deets = $deets . '<tr><th>Where it lives</th>';
    if (array_key_exists('parentFolderId', $tag)) {
        $deets = $deets . '<td>' . folderisation($tag['parentFolderId'], 'tag') . '</td></tr>';
    } else {
        $deets = $deets . '<td>' . folderisation(null, 'tag') . '</td></tr>';
    }
    if ($rawHTML !== '') {
        $varRefs = getVarRefs($rawHTML, $tag);
        if ($varRefs !== '') {
            $technicalDetails = $technicalDetails . 'Variables referenced in this tag:<br />' . $varRefs;
        }
    }
    /******************************************************************************
       Fields to Set (UA only)
       ******************************************************************************/
    $technicalDetails = $technicalDetails . fieldsToSet($tag);
    /******************************************************************************
       Custom Dimensions
       ******************************************************************************/
    $technicalDetails = $technicalDetails . dimensions($tag);
    /******************************************************************************
       Custom Metrics
       ******************************************************************************/
    $technicalDetails = $technicalDetails . metrics($tag);
    /******************************************************************************
       Custom Variables
       ******************************************************************************/
    $technicalDetails = $technicalDetails . cvars($tag);
    /******************************************************************************
       Mop up gnarly details
       ******************************************************************************/
    $technicalDetails = $technicalDetails . getGnarlyDetails($tag);
    if ($technicalDetails !== '') {
        $deets = $deets . '<tr><th></th><td>' . $technicalDetails . '</td></tr>';
    }
    $deets = $deets . '</table><br />';
    return $deets;
}