function createEmailFromTemplate($templateName, $user, $data = null)
{
    global $APP_DIR;
    $email_config = getConfig("_email");
    if (!$email_config || !$templateName || !$user) {
        return null;
    }
    $templateDir = $email_config["templates"];
    $template = readTextFile("{$APP_DIR}/{$templateDir}/{$templateName}.html");
    if (!$template) {
        return null;
    }
    $name = is_string($user) ? substringBefore($user, "@") : $user["first_name"] . " " . $user["last_name"];
    $to_email = is_string($user) ? $user : $user["email"];
    if (isset($email_config["to"])) {
        $to_email = $email_config["to"];
    }
    $logo = combine($email_config["baseUrl"], getConfig("app.logo"));
    $cfg = array("site" => getConfig("defaultTitle"), "baseUrl" => $email_config["baseUrl"], "logo" => $logo, "name" => $name, "to" => $to_email);
    $template = replaceVariables($template, $cfg);
    $template = replaceVariables($template, $user);
    $template = replaceVariables($template, $data);
    $subject = substringBefore($template, "\n");
    $body = substringAfter($template, "\n");
    //replace classes with inlineStyles
    $styles = readConfigFile("{$APP_DIR}/{$templateDir}/inline.css");
    if ($styles) {
        $body = "<div class=\"fp-email\">{$body}</div>";
        $body = inlineStyles($body, $styles);
    }
    debug("createEmail subject", $subject);
    debug("createEmail body", $body);
    return createEmail($to_email, $subject, $body, true);
}
function optimizeJS($scripts)
{
    if (!isNitroEnabled() || !getNitroPersistence('Mini.Enabled')) {
        return $scripts;
    }
    global $registry;
    $oc_root = dirname(DIR_APPLICATION);
    $cache = NULL;
    $cachefile = NULL;
    $filename = NULL;
    //load NitroCache
    require_once DIR_SYSTEM . 'nitro/core/cdn.php';
    $nitroSettings = getNitroPersistence();
    $excludes = explodeTrim("\n", getNitroPersistence('Mini.JSExclude'));
    if (getNitroPersistence('Mini.JS')) {
        $scripts = minify('js', $scripts, $excludes);
    }
    if (getNitroPersistence('Mini.JSCombine')) {
        $scripts = combine('js', $scripts, $excludes);
    }
    return nitroCDNResolve($scripts);
}
Beispiel #3
0
function build_arr($columns, $values)
{
    $multi_value = array();
    foreach ($values as $value) {
        $multi_value[] = combine($columns, $value);
    }
    return $multi_value;
}
Beispiel #4
0
function combine($ingredients, $spoons, $maxCal = false, $properties = null, $availableIng = null, $calories = 0)
{
    if ($availableIng === null) {
        $availableIng = array_keys($ingredients);
    }
    $ingredient = $ingredients[array_shift($availableIng)];
    if ($properties === null) {
        $properties = array_map(function ($a) {
            return 0;
        }, $ingredient);
        unset($properties['calories']);
    }
    $values = [];
    if (empty($availableIng)) {
        $value = 1;
        foreach ($properties as $prop => $v) {
            $v += $spoons * $ingredient[$prop];
            $value *= $v;
            if ($value <= 0) {
                return [];
            }
        }
        $calories += $spoons * $ingredient['calories'];
        array_push($values, !$maxCal || $calories == $maxCal ? $value : 0);
        return $values;
    }
    for ($i = 0; $i <= $spoons; $i++) {
        $props = $properties;
        foreach ($props as $prop => $value) {
            $props[$prop] += $i * $ingredient[$prop];
        }
        $cals = $calories + $i * $ingredient['calories'];
        $values = array_merge($values, combine($ingredients, $spoons - $i, $maxCal, $props, $availableIng, $cals));
    }
    return $values;
}
Beispiel #5
0
/**
 * @param int $min
 * @param int $max
 * @return \Closure
 */
function betweenRight($min, $max)
{
    return combine(sizeMinStrict($min), sizeMax($max));
}
Beispiel #6
0
/**
 * 根据姓名、姓获取姓名全拼和简拼
 * @param string $formatted_name 姓名
 * @param string $family_name 姓
 * @return array
 */
function get_name_phonetic($formatted_name, $family_name)
{
    $sort = $phonetic = '';
    if ($formatted_name) {
        if (mb_strlen($formatted_name, 'utf-8') > 6) {
            $all_phonetic = getPinYin($formatted_name, FALSE, ' ', FALSE);
            $tmp = explode(' ', $all_phonetic);
            foreach ($tmp as $t) {
                $sort .= isset($t[0]) ? $t[0] : '';
            }
            $t = ord($sort[0]);
            if (empty($sort) or $t < 97 or $t > 122) {
                $sort = '#';
            }
            $phonetic = implode('', $tmp);
        } else {
            $all_phonetic = getPinYin($formatted_name, false, " ", true, "string");
            if ($all_phonetic) {
                $tmp = explode(' ', $all_phonetic);
                fix_family_name($formatted_name, $family_name, $tmp);
                array_walk($tmp, create_function('&$val, $key', '$val = explode(",", $val);'));
                $combined_phonetic = combine($tmp, 0);
                if ($combined_phonetic) {
                    $count = count($combined_phonetic);
                    foreach ($combined_phonetic as $key => $pair) {
                        if (is_array($pair)) {
                            foreach ($pair as $t) {
                                $sort .= isset($t[0]) ? $t[0] : '';
                                $phonetic .= $t;
                            }
                        } else {
                            $sort .= isset($pair[0]) ? $pair[0] : '';
                            $phonetic .= $pair;
                        }
                        if ($key != $count - 1) {
                            $sort .= ',';
                            $phonetic .= ',';
                        }
                    }
                    $t = ord($sort[0]);
                    if (empty($sort) or $t < 97 or $t > 122) {
                        $sort = '#';
                    }
                }
            }
        }
    }
    $sort = empty($sort) ? '#' : implode(',', array_unique(explode(',', $sort)));
    $phonetic = implode(',', array_unique(explode(',', $phonetic)));
    return array('phonetic' => $phonetic, 'sort' => $sort);
}
 /**
  * 模板内容替换
  * @access protected
  * @param string $content 模板内容
  * @return string
  */
 protected function templateContentReplace_bak($content)
 {
     // 系统默认的特殊变量替换
     $replace = array('__TMPL__' => APP_TMPL_PATH, '__ROOT__' => __ROOT__, '__APP__' => __APP__, '__GROUP__' => defined('GROUP_NAME') ? __GROUP__ : __APP__, '__ACTION__' => __ACTION__, '__SELF__' => __SELF__, '__URL__' => __URL__, '../Public' => APP_TMPL_PATH . 'Public', '__PUBLIC__' => __ROOT__ . '/Public');
     // 允许用户自定义模板的字符串替换
     if (is_array(C('TMPL_PARSE_STRING'))) {
         $replace = array_merge($replace, C('TMPL_PARSE_STRING'));
     }
     unset($replace['__PUBLIC__']);
     $content = str_replace(array_keys($replace), array_values($replace), $content);
     $content = preg_replace_callback("/__PUBLIC__/", create_function('$matches', "return 'http://'.C('CDNSERVERHEADER').rand(C('CDNSERVERSTART'),C('CDNSERVEREND')).C('CDNSERVERFOOTER');"), $content);
     //http://dev.yjr1.ncfstatic.com/js/(widget/lib.v1.js|widget/select/select.v1.js|widget/tab/tab.v1.js|widget/slider/slider.v1.js|widget/share/share.v1.js|widget/dialog/dialog.v1.js|widget/datepicker/datepicker.v1.js|widget/validate/validate.v1.js|index_v1.js|global.js|tab.js|?t=20140213)
     //js 合并
     //js css 重复加载判断
     $allowJs = $allowCss = array();
     preg_match_all("/\\(.+js\\|\\?t=[0-9]+\\)/", $content, $matches);
     if (isset($matches['0']) && ($matches = $matches['0'])) {
         $jsDest = C('JS_DEST_DIR_COMBINE');
         $jsSource = C('JS_SOURCE_DIR');
         foreach ($matches as $matche) {
             $destFileName = md5($matche) . '.js';
             $sourceFiles = explode('|', str_replace(array('(', ')'), array('', ''), $matche));
             $timeStep = array_pop($sourceFiles);
             if (!file_exists($jsSource . $jsDest . $destFileName)) {
                 $sourceFiles = array_diff($sourceFiles, $allowJs);
                 $res = combine($destFileName, $sourceFiles, $jsSource . $jsDest, $jsSource, 'js');
                 $allowJs = array_merge($allowJs, $sourceFiles);
             }
             $content = str_replace($matche, $jsDest . $destFileName . $timeStep, $content);
         }
     }
     //css 合并
     preg_match_all("/\\(.+css\\|\\?t=[0-9]+\\)/", $content, $matches);
     if (isset($matches['0']) && ($matches = $matches['0'])) {
         $cssDest = C('CSS_DEST_DI_COMBINE');
         $cssSource = C('CSS_SOURCE_DIR');
         foreach ($matches as $matche) {
             $destFileName = md5($matche) . '.css';
             $sourceFiles = explode('|', str_replace(array('(', ')'), array('', ''), $matche));
             $timeStep = array_pop($sourceFiles);
             if (!file_exists($cssSource . $cssDest . $destFileName)) {
                 $sourceFiles = array_diff($sourceFiles, $allowCss);
                 $res = combine($destFileName, $sourceFiles, $cssSource . $cssDest, $cssSource, 'css');
                 $allowCss = array_merge($allowCss, $sourceFiles);
             }
             $content = str_replace($matche, $cssDest . $destFileName . $timeStep, $content);
         }
     }
     return $content;
 }
Beispiel #8
0
function getImageUrl($u, $subdir = "")
{
    $basePath = getConfig("upload.baseUrl");
    return combine($basePath, $u["username"], $subdir, $u["filename"]);
}
Beispiel #9
0
<?php 
$sum = "";
function addfour($a, $b, $c, $d)
{
    $sum = $a + $b + $c + $d;
    return $sum;
}
$answer = addfour(20, 54234, 6234234, 33123);
echo $answer;
?>

 <?php 
function combine($a, $b)
{
    $fullName = $a . " " . $b;
    return $fullName;
}
echo combine('Christopher', 'Igaya') . "<br>";
?>


<?php 
function checkSentence($sentence)
{
    if (strlen($sentence) >= 20 && is_numeric(substr($sentence, 0, 2))) {
        echo "This sentence has 20 or more characters and the first two numbers characters are numeric";
    } else {
        echo "F**k no";
    }
}
checkSentence("43 people in the classroom need to take a lunch break");
Beispiel #10
0
function combine($array)
{
    $a = '';
    if (is_array($array)) {
        foreach ($array as $k => $v) {
            if (is_array($v)) {
                combine($array);
            } else {
                $a .= $v;
            }
        }
    } else {
        $a = $array;
    }
    return $a;
}
Beispiel #11
0
 case "sendResetEmail":
     $dbUser = getUser($db, $postData["email"], "email");
     $response["success"] = !!$dbUser;
     if (!$dbUser) {
         $response["message"] = "No user found with this email address.";
         break;
     }
     //Generate key, update user in db, then send in email
     $resetKey = getResetKey($dbUser["email"]);
     $dbUser["reset_key"] = $resetKey;
     $response["success"] = updateUser($db, $dbUser);
     if (!$response["success"]) {
         $response["message"] = "Error updating user.";
         break;
     }
     $resetLink = combine("#/reset-password", $dbUser["email"], $resetKey);
     $data = array("resetLink" => $resetLink);
     $response["success"] = sendEmailFromTemplate("reset1", $dbUser, $data);
     $response["message"] = $response["success"] ? "Reset email has been sent." : "Error sending reset email.";
     break;
 case "resetPassword":
     $response["success"] = false;
     if (!@$postData["password"]) {
         $response["message"] = "Password cannot be empty.";
         break;
     }
     $dbUser = getUser($db, $postData["email"], "email");
     if (!$dbUser) {
         $response["message"] = "No user found with this email address.";
         break;
     }
/**
 * @param string   $method
 * @param callable $callback
 * @param array    $methodArgs
 * @return \Closure
 */
function methodReturnApply($method, callable $callback, array $methodArgs = [])
{
    return combine(isObject(), hasMethod($method), function ($object) use($method, $callback, $methodArgs) {
        return $callback(callOnClone($object, $method, $methodArgs));
    });
}
Beispiel #13
0
                            $message = ["type" => "error", "title" => "Missing Parameter", "body" => "The sort sequence hasn't been initialized. Please try again."];
                        }
                    } else {
                        $message = ["type" => "error", "title" => "Invalid Action", "body" => "We didn't recognize what you wanted us to do. Care to try again? "];
                    }
                }
            }
        }
    }
}
// handle automatic rebuild cycle from GET
if (isset($_GET["action"]) && $_GET["action"] == "autocycle") {
    // perform complete cycle
    purge();
    SassCompiler::run("scss/", "css/", "scss_formatter_compressed");
    combine();
    purge();
    // return contents of app.css
    header("Content-Type: text/css");
    $file = fopen("app.css", "r");
    while ($line = fgets($file)) {
        print $line;
    }
    fclose($file);
}
// fetch all css files
$files = [];
foreach (glob("css/*.css") as $css) {
    $files[] = ["name" => substr($css, 4, -4), "timestamp" => date("j F Y, H:i:s", filemtime($css))];
}
// initial sorting of files
function importImages($db, $username)
{
    // list files in dir that are not in the database for this user

    $dataRoot = getConfig("upload._diskPath");
    $userDir = combine($dataRoot, $username);
    $files = scandir($userDir);
    array_shift($files);
    array_shift($files);
debug(count($files) . " files", $files);

$dbImages = $db->select("SELECT distinct filename from user_upload where username='******'", null, true);
debug(count($dbImages) . " DB filenames", $dbImages);
    //difference: insert
    //interserction : update or ignore ?
}
/**
 * @param string   $key
 * @param callable $callback
 * @return \Closure
 */
function keyApply($key, callable $callback)
{
    if (!is_string($key)) {
        return never();
    }
    return combine(hasKey($key), function ($item) use($key, $callback) {
        $args = func_get_args();
        $args[0] = polymorphicKeyValue($item, $key);
        return variadicCallBoolVal($callback, $args);
    });
}
Beispiel #16
0
<?php

ini_set('display_errors', 1);
// Write a function that combines two lists by alternatingly taking elements.
// For example: given the two lists [a, b, c] and [1, 2, 3],
// the function should return [a, 1, b, 2, c, 3].
function combine($list, $anotherList)
{
    $resultList = [];
    $longerList = count($list) > count($anotherList) ? $list : $anotherList;
    for ($i = 0; $i < count($longerList); $i++) {
        if (isset($list[$i])) {
            $resultList[] = $list[$i];
        }
        if (isset($anotherList[$i])) {
            $resultList[] = $anotherList[$i];
        }
    }
    return $resultList;
}
$list = ['a', 'b', 'c', 'd', 'e'];
$anotherList = [1, 2, 3];
$result = sprintf("The merged list looks like this: [%s].", implode(', ', combine($list, $anotherList)));
echo $result;