Beispiel #1
0
 function showTitle($id_node, $id_type_modul)
 {
     $l = dibi::fetch("SELECT * FROM " . self::TABLE . " WHERE id_node=%i", $id_node);
     $title = '
 <h1>
 	<a href="?id_menu_item=' . $_GET['id_menu_item'] . '&amp;id_type_modul=' . $id_type_modul . '&amp;id_modul=' . $id_node . '">
 		';
     $l['text'] == "" ? $title .= "Nedefinovane" : ($title .= NStrings::truncate(strip_tags($l['text']), 100));
     $title .= '</a>
 </h1>';
     return $title;
 }
Beispiel #2
0
 public function generovatUsername($id)
 {
     $zaznam = $this->findById($id);
     $jmeno = NStrings::webalize($zaznam->jmeno);
     $prijmeni = NStrings::webalize($zaznam->prijmeni);
     $username = NStrings::webalize($prijmeni);
     if (!$this->findByUsername($username)) {
         return $username;
     }
     $username = $prijmeni . NStrings::truncate($jmeno, 1, '');
     if (!$this->findByUsername($username)) {
         return $username;
     }
     $username = $prijmeni . $jmeno;
     if (!$this->findByUsername($username)) {
         return $username;
     }
     for ($i = 1; 1 == 1; $i++) {
         $username = $prijmeni . $jmeno . $i;
         if (!$this->findByUsername($username)) {
             return $username;
         }
     }
 }
Beispiel #3
0
 /**
  * renders the body
  * @return string
  */
 public function renderBody()
 {
     $body = \NHtml::el('tbody');
     $body->class[] = 'tabella-body';
     if ($this->params['filter']) {
         foreach ($this->params['filter'] as $column => $value) {
             if ((string) $value == '') {
                 continue;
             }
             if (!isset($this->cols[$column]->params['filterHandler'])) {
                 // filtering by column, which is not shown
                 $fh = function ($source, $value, $column) {
                     return $source->where('%n = %s', $column, $value);
                 };
             } else {
                 $fh = $this->cols[$column]->params['filterHandler'];
             }
             $fh($this->source, $value, $column);
         }
     }
     //		dump($this->params);
     $count_source = clone $this->source;
     $this->source->offset(($this->params['offset'] - 1) * $this->params['limit'])->limit($this->params['limit'])->orderBy($this->params['order'], $this->params['sorting'])->fetchAll();
     //		exit;
     $this->count = count($count_source);
     foreach ($this->source as $row) {
         $rR = $this->params['rowRenderer'];
         $r = $rR($row);
         if (isset($row->{$this->params['id_table']})) {
             $r->{"data-id"} = $row->{$this->params['id_table']};
         }
         foreach ($this->cols as $col) {
             if ($col->params['type'] == self::DELETE) {
                 $r->add(\NHtml::el("td class=delete"));
                 continue;
             }
             if (!isset($row[$col->colName])) {
                 $str = "";
             } else {
                 $str = $row[$col->colName];
                 if ($col->params['translate'] && ($t = $this->params['translator'])) {
                     $str = $t->translate($str);
                 }
             }
             // in case of own rendering
             if ($c = $col->params['renderer']) {
                 $c = $c($row);
                 // or default rendering method
             } else {
                 $c = \NHtml::el('td');
                 $c->style['width'] = $col->params['width'] . "px";
                 $c->class = array();
                 if ($col->params['editable']) {
                     $c->class[] = 'editable';
                     $c->{'data-editable'} = $str;
                     $c->{'data-type'} = $col->params['type'];
                     $c->{'data-name'} = $col->colName;
                 }
                 switch ($col->params['type']) {
                     case self::CHECKBOX:
                         $el = \NHtml::el('input type=checkbox')->disabled(true);
                         $el->checked = $str ? true : false;
                         $c->add($el);
                         $str = '';
                         break;
                     case self::TEXT:
                         $str = $col->params['truncate'] ? \NStrings::truncate($str, $col->params['truncate']) : $str;
                         break;
                     case self::TIME:
                         // we format the time online if defined as UNIX timestamp
                         if (is_numeric($str)) {
                             $str = strftime($col->params['timeFormat'], $str);
                         }
                         break;
                     case self::DATE:
                         if (is_numeric($str)) {
                             $str = strftime($col->params['dateFormat'], $str);
                         }
                         $c->{'data-format'} = $col->params['dateFormat'];
                         break;
                     case self::DATETIME:
                         if (is_numeric($str)) {
                             $str = strftime($col->params['datetimeFormat'], $str);
                         }
                         break;
                     case self::SELECT:
                         if (is_array(@$col->params['options']) && isset($col->params['options'][$str])) {
                             $str = $col->params['options'][$str];
                         }
                         break;
                 }
                 $c->add($str)->{'data-shown'} = $str;
                 $c->class = array_merge($c->class, is_array($col->params['class']) ? $col->params['class'] : array($col->params['class']));
             }
             $r->add($c);
         }
         $body->add($r);
     }
     return $body;
 }
Beispiel #4
0
 public function setObsah($obsah)
 {
     $this->obsah = $obsah;
     if (!$this->perex) {
         $perex = str_replace("\n", ' ', str_replace('&nbsp;', ' ', strip_tags($obsah)));
         $this->setPerex(NStrings::truncate(html_entity_decode(preg_replace('~&(lt|gt|amp);~', '&amp;\\1;', $perex), ENT_NOQUOTES, "utf-8"), 250, ''));
     }
 }
Beispiel #5
0
 function getInfoFromMyPage($url)
 {
     //odtrasni posledne lomitko
     $url = trim($url, '/');
     $html = new DOMDocument();
     // scrape html from page running on localhost
     $content_array = self::get_url_content($url);
     $page_html = $this->strip_script($content_array['content']);
     //if (!@$html->loadHTMLFile($url))
     if (!@$html->loadHTML($page_html)) {
         throw new StatsException('stranka neexistuje');
     }
     $xpath = new DOMXPath($html);
     $results = array('url' => $url);
     $keyword_limit = $this->keyword_limit;
     // search meta elements elements with attributes
     $search_tags = array('heading_title' => 'title', 'heading_description' => 'meta[@name="description"];content', 'heading_keywords' => 'meta[@name="keywords"];content', 'h1' => 'h1', 'h2' => 'h2', 'h3' => 'h3', 'h4' => 'h4');
     foreach ($search_tags as $key => $tag) {
         //if (empty($results[$key])) $results[$key] = array();
         $attrs = explode(';', $tag);
         $xpath_results = $xpath->query("//" . $attrs[0]);
         if (empty($xpath_results)) {
             continue;
         }
         foreach ($xpath_results as $r) {
             if (is_int($key)) {
                 $key = $tag;
             }
             $content = NULL;
             if (count($attrs) > 2) {
                 $new_attrs = $attrs;
                 array_shift($new_attrs);
                 foreach ($new_attrs as $attr) {
                     $content[$attr] = $r->getAttribute($attr);
                 }
             } else {
                 if (isset($attrs[1])) {
                     $content = $r->getAttribute($attrs[1]);
                 } else {
                     $content = $r->nodeValue;
                 }
             }
             if (!empty($content)) {
                 $results[$key][] = $content;
             }
         }
     }
     print_r($results);
     if (!empty($results['heading_top_keywords'][0])) {
         // clean up script tags and style tags
         $page_content = $results['heading_top_keywords'][0];
         //				echo "<pre style=\"text-align: left;\">";
         //				print_r($page_content);
         //				echo "</pre>";
         //				$page_content = $this->strip_word_html($page_content);
         //				echo 1;print_r($page_content);exit;
         $page_content = str_replace("\n", " ", $page_content);
         $page_words = preg_split("/[\\s,\\.]+/", $page_content);
         //				print_r($page_words);exit;
         $page_words_count = array();
         foreach ($page_words as $word) {
             if (ctype_alnum($word)) {
                 if (empty($page_words_count[$word]) && strlen($word) > 3) {
                     $page_words_count[$word] = 0;
                 }
                 if (strlen($word) > 3) {
                     $page_words_count[$word] += 1;
                 }
             }
         }
         uasort($page_words_count, array(&$this, '_sort_word_density'));
         $page_words_count_limited = array_slice($page_words_count, 0, $keyword_limit);
         $results['heading_top_keywords'] = $page_words_count_limited;
     }
     // format First 100 words
     if (!empty($results['heading_first_100_words'])) {
         $results['heading_first_100_words'] = \NStrings::truncate(implode(' ', $results['heading_first_100_words']), 100);
     }
     // format image alt tags
     if (!empty($results['heading_image_alt'])) {
         foreach ($results['heading_image_alt'] as $key => $img) {
             if (substr($img['src'], 0, 4) != 'http') {
                 //ak nie je prvy lomitko prida ho
                 if (strpos($img['src'], '/') == 0) {
                     $img['src'] = $url . $img['src'];
                 } else {
                     $img['src'] = $url . '/' . $img['src'];
                 }
             }
             if (empty($img['alt'])) {
                 $img['alt'] = 'seo_image_alt_empty';
             }
             $results['heading_image_alt'][$key] = $this->anchor($img['src'], $img['alt']);
         }
     }
     // format links
     $formatted_links = array();
     $local_hostname = parse_url('http://' . $this->context->httpRequest->url->host);
     if (!empty($results['Links'])) {
         foreach ($results['Links'] as $key => $link) {
             $link = str_replace(array('#', 'javascript:;', 'javascript:void(0);'), '', $link);
             if (!empty($link) && substr($link, 0, 7) != 'mailto:') {
                 $href = $url . $link;
                 if (substr($href, 0, 4) != 'http') {
                     $href = $url . $link;
                 }
                 $formatted_links[] = $link;
                 $link_parsed = parse_url($link);
                 if ($link_parsed and isset($link_parsed['host']) and !empty($link_parsed['host']) && $link_parsed['host'] != $local_hostname['host']) {
                     $results['heading_outbound_links'][] = $this->anchor($link);
                 }
             }
         }
         $results['Links'] = $formatted_links;
     }
     unset($results['Links']);
     // change errors back to original settings
     libxml_clear_errors();
     $results['keywords'] = $this->getKeyword($results);
     return $results;
 }
Beispiel #6
0
	private function error($message = "Unexpected '%s'")
	{
		list(, $line, $col) = self::$tokenizer->getOffset($this->n);
		$token = isset(self::$tokenizer->tokens[$this->n])
			? str_replace("\n", '<new line>', NStrings::truncate(self::$tokenizer->tokens[$this->n], 40))
			: 'end';
		throw new NNeonException(str_replace('%s', $token, $message) . " on line $line, column $col.");
	}
Beispiel #7
0
	public function getPanel()
	{
		$this->disabled = TRUE;
		$s = '';
		foreach ($this->queries as $i => $query) {
			list($sql, $params, $time, $rows, $connection, $source) = $query;

			$explain = NULL; // EXPLAIN is called here to work SELECT FOUND_ROWS()
			if ($this->explain && preg_match('#\s*\(?\s*SELECT\s#iA', $sql)) {
				try {
					$cmd = is_string($this->explain) ? $this->explain : 'EXPLAIN';
					$explain = $connection->queryArgs("$cmd $sql", $params)->fetchAll();
				} catch (PDOException $e) {}
			}

			$s .= '<tr><td>' . sprintf('%0.3f', $time * 1000);
			if ($explain) {
				static $counter;
				$counter++;
				$s .= "<br /><a href='#' class='nette-toggler' rel='#nette-DbConnectionPanel-row-$counter'>explain&nbsp;&#x25ba;</a>";
			}

			$s .= '</td><td class="nette-DbConnectionPanel-sql">' . NDatabaseHelpers::dumpSql(self::$maxLength ? NStrings::truncate($sql, self::$maxLength) : $sql);
			if ($explain) {
				$s .= "<table id='nette-DbConnectionPanel-row-$counter' class='nette-collapsed'><tr>";
				foreach ($explain[0] as $col => $foo) {
					$s .= '<th>' . htmlSpecialChars($col) . '</th>';
				}
				$s .= "</tr>";
				foreach ($explain as $row) {
					$s .= "<tr>";
					foreach ($row as $col) {
						$s .= '<td>' . htmlSpecialChars($col) . '</td>';
					}
					$s .= "</tr>";
				}
				$s .= "</table>";
			}
			if ($source) {
				$s .= NDebugHelpers::editorLink($source[0], $source[1])->class('nette-DbConnectionPanel-source');
			}

			$s .= '</td><td>';
			foreach ($params as $param) {
				$s .= NDebugger::dump($param, TRUE);
			}

			$s .= '</td><td>' . $rows . '</td></tr>';
		}

		return empty($this->queries) ? '' :
			'<style class="nette-debug"> #nette-debug td.nette-DbConnectionPanel-sql { background: white !important }
			#nette-debug .nette-DbConnectionPanel-source { color: #BBB !important } </style>
			<h1 title="' . htmlSpecialChars($connection->getDsn()) . '">Queries: ' . count($this->queries)
			. ($this->totalTime ? ', time: ' . sprintf('%0.3f', $this->totalTime * 1000) . ' ms' : '') . ', ' . htmlSpecialChars($this->name) . '</h1>
			<div class="nette-inner nette-DbConnectionPanel">
			<table>
				<tr><th>Time&nbsp;ms</th><th>SQL Statement</th><th>Params</th><th>Rows</th></tr>' . $s . '
			</table>
			</div>';
	}
Beispiel #8
0
 /**
 		 * renders the body
 * @return NString
 */
 public function renderBody()
 {
     $body = NHtml::el("tbody");
     $body->class[] = "tabella-body";
     if ($this->params['filter']) {
         foreach ($this->params['filter'] as $col => $val) {
             if ("{$val}" == "") {
                 continue;
             }
             $fh = $this->cols[$col]->params['filterHandler'];
             $this->source->where($fh($val, '`' . $col . '`'));
         }
     }
     $this->count = $this->source->count();
     $this->source->applyLimit($this->params['limit'], ($this->params['offset'] - 1) * $this->params['limit'])->orderBy($this->params['order'], $this->params['sorting']);
     foreach ($this->source->fetchAll() as $row) {
         $rR = $this->params['rowRenderer'];
         $r = $rR($row);
         if (isset($row->{$this->params['id_table']})) {
             $r->{"data-id"} = $row->{$this->params['id_table']};
         }
         foreach ($this->cols as $col) {
             if ($col->params['type'] == self::DELETE) {
                 $r->add(NHtml::el("td class=delete"));
                 continue;
             }
             if (!isset($row[$col->colName])) {
                 $str = "";
             } else {
                 $str = $row[$col->colName];
                 if ($t = $this->params['translator']) {
                     $str = $t->translate($str);
                 }
             }
             // in case of own rendering
             if ($c = $col->params['renderer']) {
                 $c = $c($row);
                 // or default rendering method
             } else {
                 $c = NHtml::el("td");
                 $c->style['width'] = $col->params['width'] . "px";
                 $c->class = array();
                 if ($col->params['editable']) {
                     $c->class[] = "editable";
                     $c->{"data-editable"} = $str;
                     $c->{"data-type"} = $col->params['type'];
                     $c->{"data-name"} = $col->colName;
                 }
                 switch ($col->params['type']) {
                     case self::TEXT:
                         $str = $col->params['truncate'] ? NStrings::truncate($str, $col->params['truncate']) : $str;
                         break;
                     case self::TIME:
                         // we format the time online if defined as UNIX timestamp
                         if (is_numeric($str)) {
                             $str = strftime($col->params['timeFormat'], $str);
                         }
                         break;
                     case self::DATE:
                         if (is_numeric($str)) {
                             $str = strftime($col->params['dateFormat'], $str);
                         }
                         $c->{"data-format"} = $col->params['dateFormat'];
                         break;
                     case self::DATETIME:
                         if (is_numeric($str)) {
                             $str = strftime($col->params['datetimeFormat'], $str);
                         }
                         break;
                     case self::SELECT:
                         break;
                 }
                 $c->add($str)->{"data-shown"} = $str;
                 $c->class = array_merge($c->class, is_array($col->params['class']) ? $col->params['class'] : array($col->params['class']));
             }
             $r->add($c);
         }
         $body->add($r);
     }
     return $body;
 }