Esempio n. 1
0
 public function generate()
 {
     //	Will we be able to write to the cache?
     if (!is_writable(DEPLOY_CACHE_DIR)) {
         $this->_set_error('Cache is not writeable.');
         return FALSE;
     }
     // --------------------------------------------------------------------------
     $_map = new stdClass();
     $_map->meta = new stdClass();
     $_map->meta->generated = date(DATE_ATOM);
     $_map->pages = array();
     foreach ($this->_writers as $slug => $method) {
         if (is_callable(array($method[0], $method[1]))) {
             $_result = call_user_func(array($method[0], $method[1]));
             if (is_array($_result)) {
                 $_map->pages = array_merge($_map->pages, $_result);
             }
         }
     }
     // --------------------------------------------------------------------------
     //	Sort the array into a vaguely sensible order
     $this->load->helper('array');
     array_sort_multi($_map->pages, 'location');
     // --------------------------------------------------------------------------
     //	Save this data as JSON and XML files
     $this->load->helper('file');
     //	JSON, easy
     if (!write_file(DEPLOY_CACHE_DIR . $this->_filename_json, json_encode($_map))) {
         $this->_set_error('Failed to write ' . $this->_filename_json . '.');
         return FALSE;
     }
     //	XML file is a little more complex
     $_fh = fopen(DEPLOY_CACHE_DIR . $this->_filename_xml, 'w');
     if (!$_fh) {
         $this->_set_error('Failed to write ' . $this->_filename_xml . ': Could not open file for writing.');
         return FALSE;
     }
     $_xml = '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
     $_xml .= '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' . "\n";
     if (fwrite($_fh, $_xml)) {
         for ($i = 0; $i < count($_map->pages); $i++) {
             $_xml = '<url>' . "\n";
             $_xml .= '<loc>' . $_map->pages[$i]->location . '</loc>' . "\n";
             $_xml .= !empty($_map->pages[$i]->lastmod) ? '<lastmod>' . $_map->pages[$i]->lastmod . '</lastmod>' . "\n" : '';
             $_xml .= !empty($_map->pages[$i]->changefreq) ? '<changefreq>' . $_map->pages[$i]->changefreq . '</changefreq>' . "\n" : '';
             $_xml .= !empty($_map->pages[$i]->priority) ? '<priority>' . $_map->pages[$i]->priority . '</priority>' . "\n" : '';
             $_xml .= '</url>' . "\n";
             if (!fwrite($_fh, $_xml)) {
                 @unlink(DEPLOY_CACHE_DIR . $this->_filename_xml);
                 $this->_set_error('Failed to write ' . $this->_filename_xml . ': Could write to file - #2.');
                 return FALSE;
             }
         }
         //	finally, close <urlset>
         $_xml = '</urlset>' . "\n";
         if (!fwrite($_fh, $_xml)) {
             @unlink(DEPLOY_CACHE_DIR . $this->_filename_xml);
             $this->_set_error('Failed to write ' . $this->_filename_xml . ': Could write to file - #3.');
             return FALSE;
         }
         return TRUE;
     } else {
         @unlink(DEPLOY_CACHE_DIR . $this->_filename_xml);
         $this->_set_error('Failed to write ' . $this->_filename_xml . ': Could write to file - #1.');
         return FALSE;
     }
 }
Esempio n. 2
0
 function tagForeach($Item = array())
 {
     if (!$this->is("[data-template]")) {
         $this->addTemplate();
     }
     $srcItem = $Item;
     $pagination = "";
     $sort = $this->attr("sort");
     $dsort = $this->attr("data-sort");
     $pagination = "ajax";
     if ($this->attr("data-pagination") > "") {
         $size = $this->attr("data-pagination");
         $pagination = "js";
     }
     if ($this->attr("data-size") > "") {
         $size = $this->attr("data-size");
         $pagination = "ajax";
     } else {
         $size = "false";
     }
     $mode = $this->attr("mode");
     $dmode = $this->attr("data-mode");
     if ($dmode == "") {
         $dmode = "list";
     }
     $desc = $this->attr("desc");
     $ddesc = $this->attr("data-desc");
     $rand = $this->attr("rand");
     $step = $this->attr("step");
     $page = $this->attr("data-page");
     if ($page == "") {
         $page = 1;
     }
     $cache = $this->attr("data-cache");
     $dList = $this->attr("data-list");
     if ($dList == "") {
         $dList = false;
     } else {
         $dList = aikiReadList($dList);
     }
     $limit = $this->attr("limit");
     $call = $this->attr("call");
     $oconv = $this->attr("oconv");
     $item = $this->attr("item");
     $where = $this->attr("where");
     if ($where == "") {
         $where = NULL;
     }
     $field = $this->attr("field");
     $from = $this->attr("from");
     $find = $this->attr("data-find");
     // контекстный поиск
     $tplid = $this->attr("data-template");
     $beforeShow = $this->attr("data-before-show");
     if ($from > "" && !isset($Item[$from])) {
         $tmp = "";
         eval('$tmp=$Item' . $from . ";");
         if ($tmp > "") {
             $Item[$from] = $tmp;
         }
     }
     if ($from > "" && isset($Item[$from]) && $this->hasRole("foreach") && $cache == "") {
         if ($this->attr("form") == "" && isset($Item["form"])) {
             $form = $Item["form"];
         } else {
             $form = "";
         }
         if ($this->attr("item") == "" && isset($Item["id"])) {
             $item = $Item["id"];
         } else {
             $item = "";
         }
         $Item = $Item[$from];
         if (!is_array($Item)) {
             $Item = json_decode($Item, true);
         }
         if ($field > "") {
             $Item = $Item[$field];
         }
         if (!is_array($Item)) {
             $Item = json_decode($Item, true);
         }
         if ($where > "") {
             $Item = aikiWhere($Item);
         }
     } else {
         $Item = array();
     }
     $vars = $this->attr("vars");
     if ($vars > "") {
         $Item = attrAddData($vars, $Item);
     }
     $json = $this->attr("json");
     if ($json > "") {
         $Item = json_decode($json, true);
     }
     $index = $this->attr("index");
     if (($this->attr("form") > "" or $this->attr("data-form") > "") && $from == "" && $cache == "") {
         $form = $this->attr("form");
         if ($form == "") {
             $form = $this->attr("data-form");
         }
         $type = $this->attr("data-type");
         if ($type > "") {
             $_SESSION[$form]["data-type-tmp"] = $type;
         }
         formCurrentInclude($form);
         $datatype = "file";
         $func = $form . "DataType";
         if (is_callable($func)) {
             $datatype = $func();
         }
         if ($item > "") {
             $Item[0] = aikiReadItem($form, $item);
             if ($field > "") {
                 $Item = $Item[0][$field];
                 if (is_string($Item)) {
                     $Item = json_decode($Item, true);
                 }
                 if (isset($Item[0]["img"]) && isset($Item[0]["visible"])) {
                     $Item = array_filter_value($Item, "visible", "1");
                 }
             }
         } else {
             $list = aikiListItems($form, $where);
             $Item = array();
             $Item = $list["result"];
         }
     }
     if (is_string($Item)) {
         $Item = json_decode($Item, true);
     }
     if (!is_array($Item)) {
         $Item = array($Item);
     }
     if ($cache > "" && isset($_SESSION["data"]["foreach"][$cache])) {
         $Item = $_SESSION["data"]["foreach"][$cache];
         $first = array_shift($Item);
         array_unshift($Item, $first);
         if (isset($first["form"])) {
             $form = $first["form"];
             formCurrentInclude($form);
         }
     }
     if ($sort > "") {
         // старый формат
         if ($desc == "true") {
             $stype = SORT_DESC;
         } else {
             $stype = SORT_ASC;
         }
         $Item = array_sort($Item, $sort, $stype);
     }
     if ($dsort > "") {
         $Item = array_sort_multi($Item, $dsort);
         if ($cache !== "") {
             $_SESSION["data"]["foreach"][$cache] = $Item;
         }
     }
     if ($ddesc == "true") {
         $Item = array_reverse($Item);
     }
     if ($rand == "true") {
         shuffle($Item);
     }
     if (is_callable($call)) {
         $Item = $call($Item);
     }
     $tpl = $this->innerHtml();
     $inner = "";
     $this->html("");
     if ($step > 0) {
         $steptpl = $this->clone();
         $stepcount = 0;
     }
     if ($tplid == "") {
         $tplid = "tpl" . newIdRnd();
     }
     $ndx = 0;
     $fdx = 0;
     $n = 0;
     $count = count($Item);
     if ($size == "false") {
         $pagination = "js";
     }
     if ($this->tag() !== "select" && $size == "" && $count > 200) {
         $pagination = "ajax";
         $size = 10;
         $page = 1;
         $this->attr("data-size", $size);
     }
     if ($count && $Item !== array(0 => "")) {
         $cacheList = array();
         $inner = "";
         $srcVal = array();
         foreach ($srcItem as $k => $v) {
             $srcVal["%{$k}"] = $v;
         }
         unset($v);
         $ndx = 0;
         $n = 0;
         $f = 0;
         $tmptpl = aikiFromString($tpl);
         foreach ($Item as $key => $val) {
             if (!isset($val["id"])) {
                 $lid = $key;
             } else {
                 $lid = $val["id"];
             }
             if ($dList == false or in_array($lid, $dList)) {
                 $n++;
                 $cacheVal = $val;
                 if ($limit == "" or $limit * 1 > $ndx * 1) {
                     if (!is_array($val)) {
                         $tmp = json_decode($val, true);
                         if ($tmp) {
                             $val = $tmp;
                         } else {
                             $val = array($val);
                         }
                     }
                     // именно так и никак иначе
                     if ($vars > "") {
                         $val = attrAddData($vars, $val);
                     }
                     if ($val !== NULL && ($where == NULL or aikiWhereItem($val, $where))) {
                         // если не обнулено в вызываемой ранее функцией (например, если стоит флаг скрытия в списке)
                         if ($cache == "" && $size !== "false" && $size !== "") {
                             $cacheList[$key] = $cacheVal;
                         }
                         if ($pagination == "ajax" && ($size == "false" or $size == "")) {
                             $size = 999999999;
                         }
                         if ($pagination == "ajax" and ($size > "" && $cache > "" && ($n > $page * $size - $size && $n <= $page * $size) or $size > "" && $cache == "" && $ndx < $size or $find > "") or $size == "" or $pagination == "js") {
                             $itemform = "";
                             if (isset($val["form"])) {
                                 $itemform = $val["form"];
                             } else {
                                 $itemform = $_GET["form"];
                             }
                             $text = $tmptpl->clone();
                             $val = (array) $srcVal + (array) $val;
                             // сливаем массивы
                             if ($beforeShow !== "false") {
                                 $val = aikiBeforeShowItem($val, $dmode, $itemform);
                             }
                             if (is_callable($oconv)) {
                                 $val = $oconv($val);
                             }
                             $text->find(":first")->attr("idx", $key);
                             $val["_idx"] = $_SESSION["foreach_idx"] = $key;
                             $val["_ndx"] = $_SESSION["foreach_ndx"] = $ndx;
                             $val["_num"] = $_SESSION["foreach_num"] = $ndx + 1;
                             $text->contentSetData($val);
                             if ($find == "") {
                                 $flag = true;
                             } else {
                                 $flag = aikiInString(strip_tags($text->innerHtml()), $find);
                                 if ($flag) {
                                     $f++;
                                 }
                             }
                             if ($find == "" or $size == "false" or $size == "" or $find > "" && ($f > $page * $size - $size && $f <= $page * $size)) {
                                 $tmp;
                             } else {
                                 $flag = false;
                             }
                             if ($flag == true) {
                                 $ndx++;
                                 if ($step > 0) {
                                     // если степ, то работаем с объектом
                                     if ($stepcount == 0) {
                                         $t_step = $steptpl->clone();
                                         $t_step->addClass($tplid);
                                         $this->append($t_step);
                                     }
                                     $this->find(".{$tplid}:last")->append(clearValueTags($text->outerHtml()));
                                     $stepcount++;
                                     //$stepcount=$this->find(".{$tplid}:last")->children()->length;
                                     if ($stepcount == $step) {
                                         $stepcount = 0;
                                     }
                                 } else {
                                     // иначе строим строку
                                     $inner .= clearValueTags($text->outerHtml());
                                 }
                             } else {
                                 $n--;
                             }
                             $text->remove();
                         }
                     }
                 }
             }
         }
         if ($step > 0) {
             foreach ($this->find(".{$tplid}") as $tid) {
                 $tid->removeClass($tplid);
             }
             unset($tid);
         } else {
             $this->html($inner);
         }
         unset($val, $ndx, $t_step, $string, $text, $func, $inner, $tmptpl);
     }
     if ($this->tag() == "select") {
         if (!is_array($result)) {
             $this->outerHtml("");
         }
         $plhr = $this->attr("placeholder");
         if ($plhr > "") {
             $this->prepend("<option value=''>{$plhr}</option>");
         }
     } else {
         $data_group = $this->attr("data-group");
         $data_total = $this->attr("data-total");
         if ($data_total > "" or $data_group > "") {
             aikiTableProcessor($this);
             $size = "";
         }
         if ($size > "" && $size !== "false" && $pagination == "js") {
             $this->tagDataPagination($size);
         }
         if ($size > "" && $size !== "false" && $pagination == "ajax") {
             if ($cache > "") {
                 $cacheId = $cache;
             } else {
                 $cacheId = md5($from . $form . $where . $tplid . $sort . $rand . $dsort . $limit . $item . $field . $call . $oconv . $vars . $json . implode("-", $_GET));
             }
             if ($cache == "" && isset($cacheList)) {
                 $_SESSION["data"]["foreach"][$cacheId] = $cacheList;
             }
             unset($cacheList);
             if ($find > "") {
                 $count = $f;
             } else {
                 $count = count($_SESSION["data"]["foreach"][$cacheId]);
             }
             $pages = ceil($count / $size);
             //if (round($pages)<$pages) {$pages=round($pages)+1;}
             $this->tagDataPagesAjax($size, $page, $pages, $cacheId, $count, $find);
         }
     }
     unset($Item, $tpl);
     gc_collect_cycles();
 }