Exemplo n.º 1
0
function AppDirs($app)
{
    if ($app == 'andro') {
        $sq = "SELECT dirname FROM appdirs WHERE flag_copy='Y'";
    } else {
        $sq = "SELECT dirname FROM appdirs \n            WHERE flag_copy='Y' and flag_lib='N'";
    }
    return array_Keys(SQL_allRows($sq, 'dirname'));
}
Exemplo n.º 2
0
 public function testAssemberGet()
 {
     $dataPath = realpath(__DIR__) . '/data/mockManifest.json';
     $config = ["testconfig" => ["flags" => ["loggingEnabled" => false]]];
     $json = json_decode(file_get_contents($dataPath), true);
     if (!is_array($json)) {
         throw new Exception('Manifest Test: data not ready. Data path: ' . $dataPath);
     }
     $fileLoaderMock = \Mockery::mock('JHM\\FileLoaderInterface')->shouldReceive('load')->with('viewManifest.json', true)->once()->andReturn($json)->getMock();
     $this->mockDeps('Manifest', 'JHM\\FileLoaderInterface', 'substitutions', $fileLoaderMock);
     $this->obj->addRule('Logger', [], ['constructParams' => ['testconfig', $config]]);
     $assembler = $this->obj->get('Assembler');
     $this->AssertInstanceOf(\JHM\Assembler::class, $assembler);
     $clone = (array) $assembler;
     $this->assertEquals("*manifest", array_Keys($clone)[0]);
     // protected propertie keys get prepended with \0*\0 when cast to Array, private \0Class_name\0
     $this->assertInstanceOf(\JHM\TemplateFactoryInterface::class, $clone["*templateFactory"]);
     $this->assertInstanceOf(\JHM\ManifestInterface::class, $clone["*manifest"]);
 }
Exemplo n.º 3
0
/**
 * A re-implementation of the array splice function.
 * 
 * @param type $input
 * @param type $start
 * @param type $length
 * @param type $replacement
 * @return type 
 */
function array_splic(&$input, $start, $length = 0, $replacement = null)
{
    $keys = array_Keys($input);
    $values = array_Values($input);
    if ($replacement !== null) {
        $replacement = (array) $replacement;
        $rKeys = array_Keys($replacement);
        $rValues = array_Values($replacement);
    }
    // optional arguments
    if ($replacement !== null) {
        array_splice($keys, $start, $length, $rKeys);
        array_splice($values, $start, $length, $rValues);
    } else {
        array_splice($keys, $start, $length);
        array_splice($values, $start, $length);
    }
    $input = array_Combine($keys, $values);
    return $input;
}
 public function __construct(Kwf_Component_Generator_Box_StaticSelect $generator)
 {
     $this->_generator = $generator;
     parent::__construct();
     $this->setModel($generator->getModel());
     $label = $generator->getSetting('boxName');
     if (!$label) {
         $label = trlKwf('Type');
     }
     $select = $this->add(new Kwf_Form_Field_Select('component', $label));
     $select->setWidth(400);
     $select->setAllowBlank(false);
     $countContentComponents = 0;
     foreach ($generator->getSetting('component') as $k => $c) {
         if (is_instance_of($c, 'Kwc_Basic_ParentContent_Component')) {
         } else {
             if (is_instance_of($c, 'Kwc_Basic_None_Component')) {
             } else {
                 $countContentComponents++;
             }
         }
     }
     $values = array();
     foreach ($generator->getSetting('component') as $k => $c) {
         if (is_instance_of($c, 'Kwc_Basic_ParentContent_Component')) {
             $t = trlKwf('Inherit from parent page');
         } else {
             if (is_instance_of($c, 'Kwc_Basic_None_Component')) {
                 $t = trlKwf('No content');
             } else {
                 $t = trlKwf('Own settings for this page');
                 if ($countContentComponents > 1) {
                     $t .= ': ' . Kwf_Trl::getInstance()->trlStaticExecute(Kwc_Abstract::getSetting($c, 'componentName'));
                 }
             }
         }
         $values[$k] = $t;
     }
     $select->setValues($values);
     $select->setDefaultValue(array_shift(array_Keys($values)));
 }
Exemplo n.º 5
0
/**
 * Check that either category parent is 0 or a category shared in the same context.
 * Fix any categories to point to grand or grand grand parent etc in the same context or 0.
 */
function question_category_checking($question_categories)
{
    //make an array that is easier to search
    $newparents = array();
    foreach ($question_categories as $id => $category) {
        $newparents[$id] = question_category_next_parent_in($category->contextid, $question_categories, $id);
    }
    foreach (array_Keys($question_categories) as $id) {
        $question_categories[$id]->parent = $newparents[$id];
    }
    return $question_categories;
}
Exemplo n.º 6
0
 public static function array_insert(&$original = array(), $insert = null, $position = 'after', $key = null, $sens = true)
 {
     if (!empty($insert)) {
         $after = $position == 'after' ? true : false;
         $insert = (array) $insert;
         $assoc = array_keys($insert) !== range(0, count($insert) - 1);
         $keep_keys = is_string($insert) || !$assoc || $sens;
         if (!empty($key) && array_key_exists($key, $original)) {
             $start = self::key_offset($original, $key);
             $start = $after ? $start + 1 : $start;
             if (!$keep_keys) {
                 array_Splice($original, $start, 0, $insert);
             } else {
                 $keys = array_Keys($original);
                 $values = array_Values($original);
                 $insert = (array) $insert;
                 $rKeys = array_Keys($insert);
                 $rValues = array_Values($insert);
                 array_Splice($keys, $start, 0, $rKeys);
                 array_Splice($values, $start, 0, $rValues);
                 $original = array_Combine($keys, $values);
             }
         } else {
             $original = $after ? array_merge($original, $insert) : array_merge($insert, $original);
         }
     }
 }
Exemplo n.º 7
0
 public function getNode($nid, $cState = false, $force = false)
 {
     global $system;
     global $MainTreeMasterArray;
     global $CSType;
     $preHeader = "<?php /*\r\n";
     $preFooter = "\r\n*/ ?>";
     $filePrefix = "";
     $PrefetchPath = $system["systemFilePath"] . "pre/";
     $tmpPath = $system["systemFilePath"] . "tmp/";
     if ($cState) {
         $dbQuery = "SELECT * FROM mt_main WHERE mt_main_Node_id='" . $nid . "' ORDER BY mt_main_Review DESC;";
     } else {
         $dbQuery = "SELECT * FROM mt_main WHERE mt_main_Node_id='" . $nid . "' AND mt_main_Review='0';";
     }
     $dbRecord = mysql_query($dbQuery, $system["dbCon"]);
     if (mysql_num_rows($dbRecord)) {
         $DBContent = mysql_fetch_assoc($dbRecord);
         if (!isset($CSType) || $DBContent["mt_main_Type"] != $CSType) {
             $CSType = $DBContent["mt_main_Type"];
             $MainTreeMasterArray = array();
         }
         $nodeInfo = array();
         $MapFilename = $PrefetchPath . $filePrefix . $CSType . "_map.php";
         if (!file_exists($MapFilename)) {
             $fp = fopen($MapFilename, "w");
             if (flock($fp, LOCK_EX)) {
                 fwrite($fp, $preHeader . $preFooter);
                 flock($fp, LOCK_UN);
             } else {
                 fwrite($fp, $preHeader . $preFooter);
             }
             fclose($fp);
             @chmod($MapFilename, $system["targetFileMode"]);
             clearstatcache();
         }
         if (!isset($MainTreeMasterArray["Map"])) {
             $MainTreeMasterArray["Map"] = array();
             $fileData = file_get_contents($MapFilename);
             if (strlen($fileData) > strlen($preHeader . $preFooter)) {
                 $MainTreeMasterArray["Map"] = unserialize(substr($fileData, strlen($preHeader)));
             }
         }
         if (isset($MainTreeMasterArray["Map"][$nid])) {
             $Filename = $PrefetchPath . $filePrefix . $CSType . "_" . $MainTreeMasterArray["Map"][$nid] . ".php";
         } else {
             $partNum = -1;
             $Filename = $PrefetchPath . $filePrefix . $CSType . "_0.php";
             if (!file_exists($Filename)) {
                 $fp = fopen($Filename, "w");
                 if (flock($fp, LOCK_EX)) {
                     fwrite($fp, $preHeader . $preFooter);
                     flock($fp, LOCK_UN);
                 } else {
                     fwrite($fp, $preHeader . $preFooter);
                 }
                 fclose($fp);
                 @chmod($Filename, $system["targetFileMode"]);
                 clearstatcache();
             }
             while ($partNum < 50 && file_exists($Filename) && filesize($Filename) > $system["maxPrefetchFileSize"]) {
                 $partNum++;
                 $Filename = $PrefetchPath . $filePrefix . $CSType . "_" . $partNum . ".php";
             }
             if ($partNum < 0) {
                 $partNum = 0;
             }
             $MainTreeMasterArray["Map"][$nid] = $partNum;
             $tmpfname = $tmpPath . "prefetch_" . date("YmdHis") . "_" . rand() . ".tmp";
             $fp = fopen($tmpfname, "w");
             fwrite($fp, $preHeader . serialize($MainTreeMasterArray["Map"]) . $preFooter);
             fclose($fp);
             copy($tmpfname, $MapFilename);
             unlink($tmpfname);
         }
         if (decoct(fileperms($Filename)) != "100" . $system["targetFileMode"]) {
             @chmod($Filename, $system["targetFileMode"]);
             clearstatcache();
         }
         $TypeMainTreeMasterArray = array();
         $TypeMainTreeMasterArrayChange = TRUE;
         if (isset($MainTreeMasterArray[$nid]) && $MainTreeMasterArray[$nid]["node"]["Update"] == $DBContent["mt_main_Update"]) {
             $TypeMainTreeMasterArray[$nid] = $MainTreeMasterArray[$nid];
         } else {
             if (!file_exists($Filename)) {
                 $fp = fopen($Filename, "w");
                 fwrite($fp, $preHeader . $preFooter);
                 fclose($fp);
             }
             $m = $system["maxFileWaitTime"];
             while ($m > 0 && !file_exists($Filename)) {
                 usleep(1000);
                 $m--;
             }
             $fileData = file_get_contents($Filename);
             if (strlen($fileData) > strlen($preHeader . $preFooter)) {
                 $TypeMainTreeMasterArray = unserialize(substr($fileData, strlen($preHeader)));
             }
             if ($TypeMainTreeMasterArray) {
                 $MainTreeMasterArray = $MainTreeMasterArray + $TypeMainTreeMasterArray;
             }
         }
         if (isset($force) && $force || $cState || !isset($TypeMainTreeMasterArray[$nid]) || $TypeMainTreeMasterArray[$nid]["node"]["Update"] != $DBContent["mt_main_Update"]) {
             // ################ Read Data ################
             $keys = array();
             $keys = array_Keys($DBContent);
             for ($i = 0; $i < count($keys); $i++) {
                 $nodeInfo["node"][str_replace("mt_main_", "", $keys[$i])] = $DBContent[$keys[$i]];
             }
             $nodeInfo["rights"] = array();
             $nodeInfo["data"] = array("Review" => 0, "Rights" => "", "Dependancies" => "", "Values" => array());
             $nodeType = $nodeInfo["node"]["Type"];
             if (isset($system["Types"][$nodeType]["__Fields__"]) && count($system["Types"][$nodeType]["__Fields__"])) {
                 $dbQuery = "SELECT * FROM mt_data WHERE mt_data_Node_id='" . $nid . "'";
                 if ($cState) {
                     $dbQuery .= " ORDER BY mt_data_Review DESC;";
                 } else {
                     $dbQuery .= " AND mt_data_Review='0';";
                 }
                 $dbRecord = mysql_query($dbQuery, $system["dbCon"]);
                 if (mysql_num_rows($dbRecord)) {
                     $dbContent = mysql_fetch_assoc($dbRecord);
                     $nodeInfo["data"]["Review"] = $dbContent["mt_data_Review"];
                     $nodeInfo["data"]["Rights"] = unserialize($dbContent["mt_data_Rights"]);
                     $nodeInfo["data"]["Dependancies"] = " " . trim($dbContent["mt_data_Dependencies"]) . " ";
                     $data = unserialize(trim($dbContent["mt_data_Value"]));
                 }
                 $fields = $system["Types"][$nodeType]["__Fields__"];
                 $keys_fields = array_keys($system["Types"][$nodeType]["__Fields__"]);
                 $keys_language = array_keys($system["Languages"]);
                 for ($i = 0; $i < count($keys_language); $i++) {
                     $lang = translateIds2old("Languages", $keys_language[$i]);
                     for ($j = 0; $j < count($fields); $j++) {
                         $fieldName = $fields[$keys_fields[$j]]["__Name__"];
                         $fieldId = $fields[$keys_fields[$j]]["Id"];
                         // ALTLAST
                         $fieldMono = $fields[$keys_fields[$j]]["Monolingual"];
                         if (!$fieldId) {
                             $fieldId = $keys_fields[$j];
                         }
                         if ($fieldMono == 1) {
                             $attLang = translateIds2old("Languages", $system["default"]["language"]);
                         } else {
                             $attLang = $lang;
                         }
                         if (isset($data[$attLang][$fieldId])) {
                             $value = $data[$attLang][$fieldId];
                         } else {
                             $value = "";
                         }
                         $nodeInfo["data"]["Values"][$lang][$fieldName] = $value;
                     }
                 }
             }
             // #################### ####################
             if (!$cState) {
                 $TypeMainTreeMasterArray[$nid] = $nodeInfo;
                 $MainTreeMasterArray[$nid] = $nodeInfo;
                 $fp = fopen($Filename, "w");
                 if (flock($fp, LOCK_EX)) {
                     fwrite($fp, $preHeader . serialize($TypeMainTreeMasterArray) . $preFooter);
                     flock($fp, LOCK_UN);
                 } else {
                     fclose($fp);
                     $tmpfname = $tmpPath . "prefetch_" . date("YmdHis") . "_" . rand() . ".tmp";
                     $fp = fopen($tmpfname, "w");
                     fwrite($fp, $preHeader . serialize($TypeMainTreeMasterArray) . $preFooter);
                     copy($tmpfname, $Filename);
                     unlink($tmpfname);
                 }
                 fclose($fp);
             }
         } else {
             $nodeInfo = $TypeMainTreeMasterArray[$nid];
         }
         if (!isset($nodeInfo["data"]["Rights"])) {
             $nodeInfo["data"]["Rights"] = array();
         }
         $nodeInfo["rights"] = $nodeInfo["data"]["Rights"];
     } else {
         $nodeInfo = FALSE;
     }
     return $nodeInfo;
 }