コード例 #1
0
ファイル: Helper.php プロジェクト: noikiy/inovi
 function arrayFlatten($array)
 {
     $flat = array();
     foreach ($array as $key => $value) {
         if (Arrays::is($value)) {
             $flat += arrayFlatten($value);
         } else {
             $flat[$key] = $value;
         }
     }
     return $flat;
 }
コード例 #2
0
 public static function addData($file, $post)
 {
     // if file doesn't exists, save in new file
     if (!file_exists($file)) {
         $h = fopen($file, "w") or die("Unable to open file " . $file);
         $data = array();
         foreach ($post as $value) {
             $data[] = $value;
         }
         fwrite($h, json_encode($data));
         fclose($h);
     } else {
         $data = MetaDataWriter::getFileData($file);
         $array[] = $data;
         $array[] = $post;
         $array = arrayFlatten($array);
         $array = array_unique($array);
         self::writeData($file, $array);
     }
 }
コード例 #3
0
 protected function generateCategoryTagFiles($mustache, $data, $type)
 {
     if (!file_exists($this->publicDir . $type) && !mkdir($this->publicDir . $type)) {
         echo "Error: could not make {$type} directory in public folder";
         exit;
     }
     if ($type === 'category') {
         $items = $data['categories'];
         foreach ($items as $item) {
             $itemRootDir = $this->publicDir . $type . '/';
             $itemData = array();
             foreach ($data['posts'] as $post) {
                 if ($post[$type] === $item['category']) {
                     $itemData[] = $post;
                 }
             }
             $data['categoryPosts'] = $itemData;
             $template = $mustache->loadTemplate($type);
             $html = $template->render($data);
             $fileName = getSlugName($item['category']);
             $folderPath = $itemRootDir . $fileName;
             if (!file_exists($folderPath) && !mkdir($folderPath)) {
                 echo "Error: could not make {$folderPath} directory";
                 exit;
             }
             if (file_put_contents($folderPath . "/index.html", $html)) {
                 // add to generate log
                 $this->generateLog['categories'][] = $folderPath . "/index.html";
             }
         }
     } else {
         $items = array();
         foreach ($data['posts'] as $post) {
             $items[] = $post['tags'];
         }
         $items = arrayFlatten($items);
         $items = array_unique($items);
         foreach ($items as $item) {
             $itemRootDir = $this->publicDir . $type . '/';
             $itemData = array();
             foreach ($data['posts'] as $post) {
                 foreach ($post['tags'] as $tag) {
                     if ($tag === $item) {
                         $itemData[] = $post;
                     }
                 }
             }
             $data['tagPosts'] = $itemData;
             $template = $mustache->loadTemplate($type);
             $html = $template->render($data);
             $fileName = getSlugName($item);
             $folderPath = $itemRootDir . $fileName;
             if (!file_exists($folderPath) && !mkdir($folderPath)) {
                 echo "Error: could not make {$folderPath} directory";
                 exit;
             }
             if (file_put_contents($folderPath . "/index.html", $html)) {
                 // add to generate log
                 $this->generateLog['tags'][] = $folderPath . "/index.html";
             }
         }
     }
 }
コード例 #4
0
function getFilterData($array)
{
    $data = '';
    $array = arrayFlatten($array);
    foreach ($array as $value) {
        $data .= '"' . $value . '",';
    }
    return rtrim($data, ',');
}
コード例 #5
0
ファイル: Post.php プロジェクト: sarfraznawaz2005/bloggercms
 public function update()
 {
     global $app;
     $data = MetaDataWriter::getFileData($this->metaFile);
     $post = $app->request()->post();
     // sort posts by latest first
     $dates = array();
     foreach ($data as $key => $value) {
         $dates[] = strtotime($value['dated']);
     }
     array_multisort($dates, SORT_DESC, SORT_NUMERIC, $data);
     $params = $app->router()->getCurrentRoute()->getParams();
     $id = $params['param'];
     // update values
     foreach ($post as $key => $value) {
         $data[$id][$key] = $value;
     }
     // reset post published date if it was draft before and now published
     if ($post['status'] === self::STATUS_PUBLISHED && $post['prevStatus'] === self::STATUS_DRAFT) {
         $data[$id]['dated'] = date($app->view()->getData('dateFormat'));
     }
     $data[$id]['slug'] = getSlugName($post['title']);
     $data[$id]['categoryslug'] = getSlugName($post['category']);
     $data[$id]['summary'] = $this->getSummary($post['body'], 300);
     MetaDataWriter::writeData($this->metaFile, $data);
     // update categories
     $array[] = MetaDataWriter::getFileData($this->categoriesFile);
     $array[] = $post['category'];
     $array = arrayFlatten($array);
     $array = array_unique($array);
     MetaDataWriter::writeData($this->categoriesFile, $array);
     // also write tags file
     $array[] = MetaDataWriter::getFileData($this->tagsFile);
     $array[] = $post['tags'];
     $array = arrayFlatten($array);
     $array = array_unique($array);
     MetaDataWriter::writeData($this->tagsFile, $array);
     $app->flash('info', 'Saved Successfully');
     $app->redirect($_SERVER['HTTP_REFERER']);
 }
コード例 #6
0
ファイル: index.php プロジェクト: bubach/VisualQuery
    $json[]['word'] = $datavalue;
}
@file_put_contents('tables.json', json_encode($json));
$tables = Presenter::listTables($data);
Flight::set('tables', $tables);
if (false !== strpos($_SERVER['REQUEST_URI'], '/table')) {
    $currentTableKey = array_search(Flight::get('lastSegment'), $data, true);
    unset($data[$currentTableKey]);
    // remove current table
    // make dropdown options
    Flight::set('tablesOptions', getOptions($data));
}
// get an array of databases
$stmt = $db->query("SHOW DATABASES");
$data = $stmt->fetchAll(PDO::FETCH_NUM);
$data = arrayFlatten($data);
Flight::set('databaseOptions', getOptions($data, true, null, $database));
// setup custom 404 page
Flight::map('notFound', function () {
    //include 'errors/404.html';
    header("HTTP/1.0 404 Not Found");
    exit('404 Not Found');
});
// set global variables
Flight::set('appname', $config['appname']);
///////// setup routes /////////////
require_once 'routes.php';
// auto-logout after inactivity for 10 minutes
timeoutLogout(60);
// flight now
Flight::start();
コード例 #7
0
ファイル: MyBootstrap.php プロジェクト: robksawyer/grabitdown
/**
 * Flattens an array, or returns FALSE on fail.
 * 2011-07-02 ms
 */
function arrayFlatten($array)
{
    trigger_error('deprecated - use Tools.Utility instead');
    if (!is_array($array)) {
        return false;
    }
    $result = array();
    foreach ($array as $key => $value) {
        if (is_array($value)) {
            $result = array_merge($result, arrayFlatten($value));
        } else {
            $result[$key] = $value;
        }
    }
    return $result;
}