function profileEdit() { // Authorize user $id = $_GET['id']; if ($this->_user['is_authorized']) { if (!($this->_user['id'] == $id)) { $this->set('authorized', false); die('You are not allowed to edit this profile!'); } else { $this->set('authorized', true); } } else { $this->set('authorized', false); die('You are not allowed to edit this profile!'); } // get all necessary user data $user = new User(); $user->createFromID($id); $email = $user->getEmail(); $language = $user->getDefaultLanguage(); $this->set('default_language', $language); // notification_interval is rewritten if any POST data is present $notification_interval = $user->getNotificationInterval(); $default_theme = $user->getDefaultTheme(); //if any POST data in - update profile $style = new Style(); $styles_list = $style->getAll(); $this->set('styles', $styles_list); $this->set('notification_interval', $notification_interval); $this->set('default_theme', $default_theme); $this->set('profile', $user); $this->set('email', $email); $this->set('page_title', "Edit User - " . $user->username); }
public function style($src, $media = null) { $asset = new Style($src, $media); if ($asset->isLess()) { $asset->setPublicRoot($this->manager->getPublicRoot()); } $this->styleAssets[] = $asset; return $this; }
/** * @covers Geissler\CSL\Style\Style::readXml */ public function testReadXml1() { $xml = '<style xmlns="http://purl.org/net/xbiblio/csl" class="note" version="1.0"> <info> <id /> <title /> <updated>2009-08-10T04:49:00+09:00</updated> </info> <locale lang="fr"> </locale> <citation> <layout> <text value="Oops"/> </layout> </citation> <bibliography initialize-with=". "> <layout> <names variable="author"> <name /> </names> </layout> </bibliography> </style>'; $this->assertInstanceOf($this->class, $this->object->readXml(new \SimpleXMLElement($xml))); }
protected function _tag($code) { if ($this->tag === true) { return Style::open() . $code . Style::close(); } return $code; }
public function validate_style_id() { $errors = array(); if (!is_integer($this->style_id) || !Style::find($this->style_id)) { $errors[] = "style does not exist"; } return $errors; }
function __toString() { // Skip empty text frames // if ( $this->is_text_node() && // preg_replace("/\s/", "", $this->_node->data) === "" ) // return ""; $str = "<b>" . $this->_node->nodeName . ":</b><br/>"; //$str .= spl_object_hash($this->_node) . "<br/>"; $str .= "Id: " . $this->get_id() . "<br/>"; $str .= "Class: " . get_class($this) . "<br/>"; if ($this->is_text_node()) { $tmp = htmlspecialchars($this->_node->nodeValue); $str .= "<pre>'" . mb_substr($tmp, 0, 70) . (mb_strlen($tmp) > 70 ? "..." : "") . "'</pre>"; } elseif ($css_class = $this->_node->getAttribute("class")) { $tmp = htmlspecialchars($css_class); $str .= "CSS class: '{$css_class}'<br/>"; } if ($this->_parent) { $str .= "\nParent:" . $this->_parent->_node->nodeName . " (" . spl_object_hash($this->_parent->_node) . ") " . "<br/>"; } if ($this->_prev_sibling) { $str .= "Prev: " . $this->_prev_sibling->_node->nodeName . " (" . spl_object_hash($this->_prev_sibling->_node) . ") " . "<br/>"; } if ($this->_next_sibling) { $str .= "Next: " . $this->_next_sibling->_node->nodeName . " (" . spl_object_hash($this->_next_sibling->_node) . ") " . "<br/>"; } $d = $this->get_decorator(); while ($d && $d != $d->get_decorator()) { $str .= "Decorator: " . get_class($d) . "<br/>"; $d = $d->get_decorator(); } $str .= "Position: " . pre_r($this->_position, true); $str .= "\nContaining block: " . pre_r($this->_containing_block, true); $str .= "\nMargin width: " . pre_r($this->get_margin_width(), true); $str .= "\nMargin height: " . pre_r($this->get_margin_height(), true); $str .= "\nStyle: <pre>" . $this->_style->__toString() . "</pre>"; if ($this->_decorator instanceof Block_Frame_Decorator) { $str .= "Lines:<pre>"; foreach ($this->_decorator->get_line_boxes() as $line) { foreach ($line->get_frames() as $frame) { if ($frame instanceof Text_Frame_Decorator) { $str .= "\ntext: "; $str .= "'" . htmlspecialchars($frame->get_text()) . "'"; } else { $str .= "\nBlock: " . $frame->get_node()->nodeName . " (" . spl_object_hash($frame->get_node()) . ")"; } } $str .= "\ny => " . $line->y . "\n" . "w => " . $line->w . "\n" . "h => " . $line->h . "\n" . "left => " . $line->left . "\n" . "right => " . $line->right . "\n"; } $str .= "</pre>"; } $str .= "\n"; if (php_sapi_name() === "cli") { $str = strip_tags(str_replace(array("<br/>", "<b>", "</b>"), array("\n", "", ""), $str)); } return $str; }
function createStyle($deck) { $style = new Style(); $this->css = $style->getStyle($deck->default_theme); $deck_name = $this->sluggify($deck->title); $css = ROOT . DS . 'tmp' . DS . $this->root_deck_name . DS . $deck_name . DS . 'default.css'; if (!file_exists($css)) { $fp = fopen($css, "wb"); fwrite($fp, $this->css['css']); fclose($fp); } else { unlink($css); $fp = fopen($css, "wb"); fwrite($fp, $this->css['css']); fclose($fp); } $this->common_resources[] = $deck_name . DS . 'default.css'; }
public function run() { $row = 0; if (($handle = fopen(storage_path() . "/csvs/styles.csv", "r")) !== FALSE) { while (($data = fgetcsv($handle)) !== FALSE) { $row++; if ($row > 1) { try { $style = new Style(); $style->style_name = $data[2]; // $beer->beer_id = $data[0]; $style->save(); } catch (Exception $e) { } } } fclose($handle); } }
/** * Sets the style * @param String $paramStyle path of the style folder */ public static function setStyle($paramStyle) { try { getDatabase()->query('TRUNCATE TABLE `style_data`'); Style::install(ROOT . "/themes/" . $paramStyle . "/info.xml"); } catch (Exception $e) { throw $e; } getDatabase()->update("settings", array("value" => $paramStyle), "setting = 'website_style'"); }
function PrintHtmlHeader($logout) { $style = new Style(); echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">' . "\n"; echo '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" >' . "\n"; echo ' <head>' . "\n"; echo ' <title>Shrew Gallery</title>' . "\n"; echo ' <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />' . "\n"; echo '<style type="text/css">' . "\n"; echo $style->Generate(); echo '</style>' . "\n"; echo ' </head>' . "\n"; echo ' <body>' . "\n"; echo ' <div id="page">' . "\n"; if ($logout) { echo ' <div id=logout><a href=index.php?want=logout >Déconnection</a></div>' . "\n"; } echo ' <h1>Shrew gallery</h1>' . "\n"; }
public static function Check() { if (empty(self::$Default)) { self::$Default = CFG_STYLE_DEFAULT; } // TODO: Read user style from Database and use it if (empty(self::$Style)) { self::$Style = self::$Default; } }
public function run() { $settings = Style::getSettings(); //Reverse the Menu, we've right float getMenu()->flip(); foreach ($settings as $setting => $value) { if ($value != null) { getDisplay()->setTemplateVariable($settings, $value); } } }
/** * @see DatabaseObject::handleData() */ protected function handleData($data) { parent::handleData($data); // calculate page logo path if (!empty($this->data['variables']['page.logo.image']) && !FileUtil::isURL($this->data['variables']['page.logo.image']) && StringUtil::substring($this->data['variables']['page.logo.image'], 0, 1) !== '/') { $this->data['variables']['page.logo.image'] = RELATIVE_WCF_DIR . $this->data['variables']['page.logo.image']; } // load icon cache WCF::getCache()->addResource('icon-' . PACKAGE_ID . '-' . $this->styleID, WCF_DIR . 'cache/cache.icon-' . PACKAGE_ID . '-' . $this->styleID . '.php', WCF_DIR . 'lib/system/cache/CacheBuilderIcon.class.php'); $this->iconCache = WCF::getCache()->get('icon-' . PACKAGE_ID . '-' . $this->styleID); }
public function run() { $tags = Style::model()->findStyleWeights($this->limit, $this->singer_id); foreach ($tags as $tag => $options) { //$color = '#'.dechex(rand(100, 255)).dechex(rand(0, 200)).dechex(rand(50, 100)); $text = CHtml::encode($tag); //$id_hidden = CHtml::hiddenField('style_'.$options['id'], $options['id']); //$content = $link.$id_hidden; echo CHtml::tag('span', array('id' => $options['id'], 'style' => "font-size:{$options['weight']}pt; color: #2E3CA3; cursor: pointer;"), $text) . "\n"; } }
/** * 从堆栈中弹出一个样式 * @param Style|null $style * @return Style * @throws \InvalidArgumentException */ public function pop(Style $style = null) { if (empty($this->styles)) { return $this->emptyStyle; } if (null === $style) { return array_pop($this->styles); } /** * @var int $index * @var Style $stackedStyle */ foreach (array_reverse($this->styles, true) as $index => $stackedStyle) { if ($style->apply('') === $stackedStyle->apply('')) { $this->styles = array_slice($this->styles, 0, $index); return $stackedStyle; } } throw new \InvalidArgumentException('Incorrectly nested style tag found.'); }
function __toString() { // Skip empty text frames if ($this->_node->nodeName == "#text" && preg_replace("/\\s/", "", $this->_node->data) === "") { return ""; } $str = "<b>" . $this->_node->nodeName . ":</b><br/>"; $str .= (string) $this->_node . "<br/>"; $str .= "Id: " . $this->get_id() . "<br/>"; $str .= "Class: " . get_class($this) . "<br/>"; if ($this->_node->nodeName == "#text") { $tmp = htmlspecialchars($this->_node->nodeValue); $str .= "<pre>'" . mb_substr($tmp, 0, 70) . (mb_strlen($tmp) > 70 ? "..." : "") . "'</pre>"; } if ($this->_parent) { $str .= "\nParent:" . $this->_parent->_node->nodeName . " (" . (string) $this->_parent->_node . ") " . "<br/>"; } if ($this->_prev_sibling) { $str .= "Prev: " . $this->_prev_sibling->_node->nodeName . " (" . (string) $this->_prev_sibling->_node . ") " . "<br/>"; } if ($this->_next_sibling) { $str .= "Next: " . $this->_next_sibling->_node->nodeName . " (" . (string) $this->_next_sibling->_node . ") " . "<br/>"; } $d = $this->get_decorator(); while ($d && $d != $d->get_decorator()) { $str .= "Decorator: " . get_class($d) . "<br/>"; $d = $d->get_decorator(); } $str .= "Position: " . pre_r($this->_position, true); $str .= "\nContaining block: " . pre_r($this->_containing_block, true); $str .= "\nMargin width: " . pre_r($this->get_margin_width(), true); $str .= "\nMargin height: " . pre_r($this->get_margin_height(), true); $str .= "\nStyle: <pre>" . $this->_style->__toString() . "</pre>"; if ($this->_decorator instanceof Block_Frame_Decorator) { $str .= "Lines:<pre>"; foreach ($this->_decorator->get_lines() as $line) { foreach ($line["frames"] as $frame) { if ($frame instanceof Text_Frame_Decorator) { $str .= "\ntext: "; $str .= htmlspecialchars($frame->get_text()); } else { $str .= "\nBlock: " . $frame->get_node()->nodeName . " (" . (string) $frame->get_node() . ")"; } } $str .= "\ny => " . $line["y"] . "\n" . "w => " . $line["w"] . "\n" . "h => " . $line["h"] . "\n"; } $str .= "</pre>"; } $str .= "\n"; if (php_sapi_name() == "cli") { $str = strip_tags(str_replace(array("<br/>", "<b>", "</b>"), array("\n", "", ""), $str)); } return $str; }
public function run() { //Filter::initialization(); //error_log(print_r(Yii::app()->basePath,true)); $data = array(); $event = Events::$even; if (Filter::getSortByDate()) { usort($event, "Events::sortByDate"); } elseif (Filter::getSortByPopularity()) { usort($event, "Events::sortByPopularity"); } //error_log(print_r($this->controller->getViewFile('poster'),true)); $data['ajaxContent'] = $this->controller->renderPartial('poster', array('parameters' => $event), true); $data['main_menu'] = $this->controller->renderPartial('main_menu', array(), true); $location = new Location(); $style = new Style(); $data['country'] = $location->selectContry(); if (!Filter::getCountryId()) { Filter::setCountryId(current(array_keys($data['country']))); } $data['city'] = $location->selectCity(Filter::getCountryId()); if (!Filter::getCityId()) { Filter::setCityId(0); } //Filter::setCityId(current(array_keys($data['city']))); $data['style'] = $style->selectStyle(); if (!Filter::getStyleId()) { Filter::setStyleId(current(array_keys($data['style']))); } /*Filter::getStyleId()*/ $data['genre'] = $style->selectGenre(Filter::getStyleId()); if (!Filter::getGenreId()) { Filter::setGenreId(current(array_keys($data['genre']))); } $data['model'] = new FilterForm(); $this->controller->render('index', $data); //$this->controller->render('translationUser', array('row'=>0)); }
function __construct() { $this->CI =& get_instance(); $this->style = Style::getInstance(); $this->CI->config->load('style'); if ($this->CI->config->item('default_style') == NULL || $this->CI->config->item('default_style') == "") { $this->style = NULL; } else { if (!is_dir(VIEWPATH . $this->CI->config->item('theme_dir') . '/' . $this->CI->config->item('default_style'))) { show_error("Default Theme directory not found"); } } $this->defaultThemeDirectory = $this->CI->config->item('theme_dir') . '/' . $this->CI->config->item('default_style'); }
public function searchElement($element_name, $text = null) { $html = ""; $elements = []; $db_elements = DB::table($element_name)->where('name', 'like', "%" . $text . "%")->get(); foreach ($db_elements as $db_element) { switch ($element_name) { case "beer": $elements[] = Beer::find($db_element->id); break; case "brewer": $elements[] = Brewer::find($db_element->id); break; case "locality": $elements[] = Locality::find($db_element->id); break; case "style": $elements[] = Style::find($db_element->id); break; } } foreach ($elements as $element) { $html .= '<li class="list-group-item clearfix">'; if ($element_name == "locality" && $element->flag()) { $html .= '<img src="' . $element->flag()->path . '" style="height:15px"> '; } elseif ($element_name == "brewer" && $element->logo()) { $html .= '<img src="' . $element->logo()->path . '" style="height:15px"> '; } $html .= '<span>' . $element->name . '</span>' . '<div class="btn-group pull-right">'; if ($element_name == "brewer" || $element_name == "beer") { $html .= '<a href="' . URL::to('/dashboard/' . $element_name . 's/edit/' . $element->id) . '">'; } $html .= '<button type="button" class="btn btn-info" '; if ($element_name != "brewer" && $element_name == "beer") { $html .= 'onclick="editElement(' . $element->id . ')"'; } $html .= '>Edit</button>'; if ($element_name == "brewer" || $element_name == "beer") { $html .= '</a>'; } $html .= '<a href="' . URL::to('/dashboard/' . $element_name . 's/delete/' . $element->id) . '"><button type="button" class="btn btn-danger">Delete</button></a>'; $html .= '</div></li>'; } return Response::json(['html' => $html]); }
public function selectBySingerId($singer_id) { $criteria = new CDbCriteria(); $criteria->select = '*'; $criteria->condition = 'id=:singer_id'; $criteria->params = array(':singer_id' => $singer_id); $result = Singer::model()->find($criteria); $image = Image::model()->selectByRow('singer', $singer_id); $style = Style::model()->selectBySingerId($singer_id); $result = $result['attributes']; if ($image) { $result['path'] = $image->path; } if ($style) { $result['style'] = $style; } return $result; }
/** * Style Object * @param String $paramPrefix Prefix for the folder, sub-folders use this * @param String $paramStyleFolder Folder where info.xml and template files are located * @author Jaco Ruit */ public function __construct($paramStyleFolder) { self::$constructed = true; $this->styleFolder = $paramStyleFolder; $filePath = ROOT . '/themes/' . $this->styleFolder . '/info.xml'; if (file_exists($filePath) == false) { throw new Exception("Unable to load the style. <br /> The info.xml file of the style doesn't exist!"); } $xml = @simplexml_load_file($filePath); $this->stylePath = ROOT . '/themes/' . $this->styleFolder . "/"; $json = @json_encode($xml); $info = @json_decode($json, true); $this->styleName = $info['style']['name']; $this->styleCopyright = $info['style']['copyright']; $this->authorName = $info['style']['author']['name']; $this->authorWebsite = $info['style']['author']['website']; $this->usePHP = $info['style']['use_php'] == 'true' ? true : false; $this->phpFile = $this->usePHP ? $info['style']['php_file'] : null; if ($this->usePHP) { try { $pathString = ROOT . '/themes/' . $this->getStyleFolder() . '/' . $this->getPHPFile(); if (!file_exists($pathString)) { throw new ClassLoadException(); } require ROOT . '/themes/' . $this->getStyleFolder() . '/' . $this->getPHPFile(); if (!class_exists($info['style']['main_class'])) { throw new ClassLoadException($info['style']['main_class'] . " class doesn't exist!"); } $this->mainClass = new $info['style']['main_class'](); if ($this->mainClass instanceof IOrongoStyle == false) { throw new Exception(); } } catch (Exception $e) { throw new ClassLoadException("Unable to load the style. <br /> Please check the info.xml of the activated style for errors."); } } else { $this->mainClass = null; } $this->doHTMLArticle = $info['style']['own_article_html'] == "true" ? true : false; $this->doHTMLComment = $info['style']['own_comment_html'] == "true" ? true : false; }
public function actionGenre() { // error_log('genre_id ' . Yii::app()->request->getPost('genre')); Filter::setGenreId(Yii::app()->request->getPost('genre')); $tagList = ''; if (Filter::getGenreId() != 0) { $data = Style::model()->selectStyleAllParameters(); $tagList .= CHtml::tag('option', array('value' => $data[Filter::getGenreId()]['style_id'], 'selected' => true), CHtml::encode($data[Filter::getGenreId()]['name']), true) . "\n"; } else { $data = Style::model()->selectStyle(); //Filter::setStyleId(0); foreach ($data as $key => $value) { if (Filter::getStyleId() == $key) { $tagList .= CHtml::tag('option', array('value' => $key, 'selected' => true), CHtml::encode($value), true) . "\n"; } else { $tagList .= CHtml::tag('option', array('value' => $key), CHtml::encode($value), true) . "\n"; } } $this->responceAjax($tagList); Yii::app()->end(); /*$nameStyle=$data[0]; echo CHtml::tag('option', array('value'=>0), CHtml::encode($data[0]), true) . "\n";*/ } //error_log(print_r($data,true)); $name = ''; //echo CHtml::tag('option', array('value'=>0, 'selected'=>true), CHtml::encode('All genre'), true) . "\n"; $nameStyle = $data[Filter::getGenreId()]['name']; // error_log($nameStyle); Filter::setStyleId($data[Filter::getGenreId()]['style_id']); //error_log(Filter::getStyleId()); foreach ($data as $key => $value) { if ($name == $value['name'] || $nameStyle == $value['name']) { continue; } $tagList .= CHtml::tag('option', array('value' => $value['style_id']), CHtml::encode($value['name']), true) . "\n"; $name = $value['name']; } $this->responceAjax($tagList); }
/** * Set inherited properties in this style using values in $parent * * @param Style $parent */ function inherit(Style $parent) { // Set parent font size $this->_parent_font_size = $parent->get_font_size(); foreach (self::$_inherited as $prop) { if (!isset($this->_props[$prop]) && isset($parent->_props[$prop])) { $this->_props[$prop] = $parent->_props[$prop]; } } foreach (array_keys($this->_props) as $prop) { if ($this->_props[$prop] == "inherit") { $this->{$prop} = $parent->{$prop}; } } return $this; }
/** * Set inherited properties in this style using values in $parent * * @param Style $parent * * @return Style */ function inherit(Style $parent) { // Set parent font size $this->_parent_font_size = $parent->get_font_size(); foreach (self::$_inherited as $prop) { //inherit the !important property also. //if local property is also !important, don't inherit. if (isset($parent->_props[$prop]) && (!isset($this->_props[$prop]) || isset($parent->_important_props[$prop]) && !isset($this->_important_props[$prop]))) { if (isset($parent->_important_props[$prop])) { $this->_important_props[$prop] = true; } //see __set and __get, on all assignments clear cache! $this->_prop_cache[$prop] = null; $this->_props[$prop] = $parent->_props[$prop]; } } foreach ($this->_props as $prop => $value) { if ($value === "inherit") { if (isset($parent->_important_props[$prop])) { $this->_important_props[$prop] = true; } //do not assign direct, but //implicite assignment through __set, redirect to specialized, get value with __get //This is for computing defaults if the parent setting is also missing. //Therefore do not directly assign the value without __set //set _important_props before that to be able to propagate. //see __set and __get, on all assignments clear cache! //$this->_prop_cache[$prop] = null; //$this->_props[$prop] = $parent->_props[$prop]; //props_set for more obvious explicite assignment not implemented, because //too many implicite uses. // $this->props_set($prop, $parent->$prop); $this->__set($prop, $parent->__get($prop)); } } return $this; }
/** * Render a background image over a rectangular area * * @param string $img The background image to load * @param float $x The left edge of the rectangular area * @param float $y The top edge of the rectangular area * @param float $width The width of the rectangular area * @param float $height The height of the rectangular area * @param Style $style The associated Style object */ protected function _background_image($url, $x, $y, $width, $height, $style) { $sheet = $style->get_stylesheet(); // Skip degenerate cases if ($width == 0 || $height == 0) { return; } //debugpng if (DEBUGPNG) { print '[_background_image ' . $url . ']'; } list($img, $ext) = Image_Cache::resolve_url($url, $sheet->get_protocol(), $sheet->get_host(), $sheet->get_base_path()); // Bail if the image is no good if ($img === DOMPDF_LIB_DIR . "/res/broken_image.png") { return; } //Try to optimize away reading and composing of same background multiple times //Postponing read with imagecreatefrom ...() //final composition paramters and name not known yet //Therefore read dimension directly from file, instead of creating gd object first. //$img_w = imagesx($src); $img_h = imagesy($src); list($img_w, $img_h) = getimagesize($img); if (!isset($img_w) || $img_w == 0 || !isset($img_h) || $img_h == 0) { return; } $repeat = $style->background_repeat; $bg_color = $style->background_color; //Increase background resolution and dependent box size according to image resolution to be placed in //Then image can be copied in without resize $bg_width = round((double) ($width * DOMPDF_DPI) / 72); $bg_height = round((double) ($height * DOMPDF_DPI) / 72); //Need %bg_x, $bg_y as background pos, where img starts, converted to pixel list($bg_x, $bg_y) = $style->background_position; if (is_percent($bg_x)) { // The point $bg_x % from the left edge of the image is placed // $bg_x % from the left edge of the background rectangle $p = (double) $bg_x / 100.0; $x1 = $p * $img_w; $x2 = $p * $bg_width; $bg_x = round($x2 - $x1); } else { $bg_x = round((double) ($style->length_in_pt($bg_x) * DOMPDF_DPI) / 72); } if (is_percent($bg_y)) { // The point $bg_y % from the left edge of the image is placed // $bg_y % from the left edge of the background rectangle $p = (double) $bg_y / 100.0; $y1 = $p * $img_h; $y2 = $p * $bg_height; $bg_y = round($y2 - $y1); } else { $bg_y = round((double) ($style->length_in_pt($bg_y) * DOMPDF_DPI) / 72); } //clip background to the image area on partial repeat. Nothing to do if img off area //On repeat, normalize start position to the tile at immediate left/top or 0/0 of area //On no repeat with positive offset: move size/start to have offset==0 //Handle x/y Dimensions separately if ($repeat !== "repeat" && $repeat !== "repeat-x") { //No repeat x if ($bg_x < 0) { $bg_width = $img_w + $bg_x; } else { $x += $bg_x * 72 / DOMPDF_DPI; $bg_width = $bg_width - $bg_x; if ($bg_width > $img_w) { $bg_width = $img_w; } $bg_x = 0; } if ($bg_width <= 0) { return; } $width = (double) ($bg_width * 72) / DOMPDF_DPI; } else { //repeat x if ($bg_x < 0) { $bg_x = -(-$bg_x % $img_w); } else { $bg_x = $bg_x % $img_w; if ($bg_x > 0) { $bg_x -= $img_w; } } } if ($repeat !== "repeat" && $repeat !== "repeat-y") { //no repeat y if ($bg_y < 0) { $bg_height = $img_h + $bg_y; } else { $y += $bg_y * 72 / DOMPDF_DPI; $bg_height = $bg_height - $bg_y; if ($bg_height > $img_h) { $bg_height = $img_h; } $bg_y = 0; } if ($bg_height <= 0) { return; } $height = (double) ($bg_height * 72) / DOMPDF_DPI; } else { //repeat y if ($bg_y < 0) { $bg_y = -(-$bg_y % $img_h); } else { $bg_y = $bg_y % $img_h; if ($bg_y > 0) { $bg_y -= $img_h; } } } //Optimization, if repeat has no effect if ($repeat === "repeat" && $bg_y <= 0 && $img_h + $bg_y >= $bg_height) { $repeat = "repeat-x"; } if ($repeat === "repeat" && $bg_x <= 0 && $img_w + $bg_x >= $bg_width) { $repeat = "repeat-y"; } if ($repeat === "repeat-x" && $bg_x <= 0 && $img_w + $bg_x >= $bg_width || $repeat === "repeat-y" && $bg_y <= 0 && $img_h + $bg_y >= $bg_height) { $repeat = "no-repeat"; } //Use filename as indicator only //different names for different variants to have different copies in the pdf //This is not dependent of background color of box! .'_'.(is_array($bg_color) ? $bg_color["hex"] : $bg_color) //Note: Here, bg_* are the start values, not end values after going through the tile loops! $filedummy = $img; /* //Make shorter strings with limited characters for cache associative array index - needed? //Strip common base path - server root, explicite temp, default temp; remove unwanted characters; $filedummy = strtr($filedummy,"\\:","//"); $p = strtr($_SERVER["DOCUMENT_ROOT"],"\\:","//"); $l = strlen($p); if ( substr($filedummy,0,$l) == $p) { $filedummy = substr($filedummy,$l); } else { $p = strtr(DOMPDF_TEMP_DIR,"\\:","//"); $l = strlen($p); if ( substr($filedummy,0,$l) == $p) { $filedummy = substr($filedummy,$l); } else { $p = strtr(sys_get_temp_dir(),"\\:","//"); $l = strlen($p); if ( substr($filedummy,0,$l) == $p) { $filedummy = substr($filedummy,$l); } } } */ $filedummy .= '_' . $bg_width . '_' . $bg_height . '_' . $bg_x . '_' . $bg_y . '_' . $repeat; //debugpng //if (DEBUGPNG) print '<pre>[_background_image name '.$filedummy.']</pre>'; //Optimization to avoid multiple times rendering the same image. //If check functions are existing and identical image already cached, //then skip creation of duplicate, because it is not needed by addImagePng if (method_exists($this->_canvas, "get_cpdf") && method_exists($this->_canvas->get_cpdf(), "addImagePng") && method_exists($this->_canvas->get_cpdf(), "image_iscached") && $this->_canvas->get_cpdf()->image_iscached($filedummy)) { $bg = null; //debugpng //if (DEBUGPNG) print '[_background_image skip]'; } else { // Create a new image to fit over the background rectangle $bg = imagecreatetruecolor($bg_width, $bg_height); //anyway default //imagealphablending($img, true); switch (strtolower($ext)) { case "png": $src = imagecreatefrompng($img); break; case "jpg": case "jpeg": $src = imagecreatefromjpeg($img); break; case "gif": $src = imagecreatefromgif($img); break; default: return; // Unsupported image type } if ($src == null) { return; } //Background color if box is not relevant here //Non transparent image: box clipped to real size. Background non relevant. //Transparent image: The image controls the transparency and lets shine through whatever background. //However on transparent imaage preset the composed image with the transparency color, //to keep the transparency when copying over the non transparent parts of the tiles. $ti = imagecolortransparent($src); if ($ti >= 0) { $tc = imagecolorsforindex($src, $ti); $ti = imagecolorallocate($bg, $tc['red'], $tc['green'], $tc['blue']); imagefill($bg, 0, 0, $ti); imagecolortransparent($bg, $ti); } //This has only an effect for the non repeatable dimension. //compute start of src and dest coordinates of the single copy if ($bg_x < 0) { $dst_x = 0; $src_x = -$bg_x; } else { $src_x = 0; $dst_x = $bg_x; } if ($bg_y < 0) { $dst_y = 0; $src_y = -$bg_y; } else { $src_y = 0; $dst_y = $bg_y; } //For historical reasons exchange meanings of variables: //start_* will be the start values, while bg_* will be the temporary start values in the loops $start_x = $bg_x; $start_y = $bg_y; // Copy regions from the source image to the background if ($repeat === "no-repeat") { // Simply place the image on the background imagecopy($bg, $src, $dst_x, $dst_y, $src_x, $src_y, $img_w, $img_h); } else { if ($repeat === "repeat-x") { for ($bg_x = $start_x; $bg_x < $bg_width; $bg_x += $img_w) { if ($bg_x < 0) { $dst_x = 0; $src_x = -$bg_x; $w = $img_w + $bg_x; } else { $dst_x = $bg_x; $src_x = 0; $w = $img_w; } imagecopy($bg, $src, $dst_x, $dst_y, $src_x, $src_y, $w, $img_h); } } else { if ($repeat === "repeat-y") { for ($bg_y = $start_y; $bg_y < $bg_height; $bg_y += $img_h) { if ($bg_y < 0) { $dst_y = 0; $src_y = -$bg_y; $h = $img_h + $bg_y; } else { $dst_y = $bg_y; $src_y = 0; $h = $img_h; } imagecopy($bg, $src, $dst_x, $dst_y, $src_x, $src_y, $img_w, $h); } } else { if ($repeat === "repeat") { for ($bg_y = $start_y; $bg_y < $bg_height; $bg_y += $img_h) { for ($bg_x = $start_x; $bg_x < $bg_width; $bg_x += $img_w) { if ($bg_x < 0) { $dst_x = 0; $src_x = -$bg_x; $w = $img_w + $bg_x; } else { $dst_x = $bg_x; $src_x = 0; $w = $img_w; } if ($bg_y < 0) { $dst_y = 0; $src_y = -$bg_y; $h = $img_h + $bg_y; } else { $dst_y = $bg_y; $src_y = 0; $h = $img_h; } imagecopy($bg, $src, $dst_x, $dst_y, $src_x, $src_y, $w, $h); } } } else { print 'Unknown repeat!'; } } } } } /* End optimize away creation of duplicates */ //img: image url string //img_w, img_h: original image size in px //width, height: box size in pt //bg_width, bg_height: box size in px //x, y: left/top edge of box on page in pt //start_x, start_y: placement of image relativ to pattern //$repeat: repeat mode //$bg: GD object of result image //$src: GD object of original image //When using cpdf and optimization to direct png creation from gd object is available, //don't create temp file, but place gd object directly into the pdf if (method_exists($this->_canvas, "get_cpdf") && method_exists($this->_canvas->get_cpdf(), "addImagePng")) { //Note: CPDF_Adapter image converts y position $this->_canvas->get_cpdf()->addImagePng($filedummy, $x, $this->_canvas->get_height() - $y - $height, $width, $height, $bg); } else { $tmp_file = tempnam(DOMPDF_TEMP_DIR, "bg_dompdf_img_") . '.png'; //debugpng if (DEBUGPNG) { print '[_background_image ' . $tmp_file . ']'; } imagepng($bg, $tmp_file); $this->_canvas->image($tmp_file, "png", $x, $y, $width, $height); //debugpng if (DEBUGPNG) { print '[_background_image unlink ' . $tmp_file . ']'; } if (!DEBUGKEEPTEMP) { unlink($tmp_file); } } }
<body> <div class="container"> <?php include '../menu_top.php'; ?> <h2>Update brewery</h2> <?php require_once '../../models/style.php'; if (isset($_POST['newName']) && isset($_POST['description']) && isset($_POST['id'])) { $id = $_POST['id']; $newName = $_POST['newName']; $description = $_POST['description']; if (empty($newName) || empty($description) || empty($id)) { echo "<br><div class='alert alert-info col-md-8'>All fields are required!</div>"; } else { $style = new Style(); echo "asdasd"; if ($up = $style->update($id, $newName, $description)) { header('Location: index.php'); die; } } } ?> <form id='new-style-form' action='', method='POST'> <div class="col-md-8"> <table class="table table-striped"> <tr> <th>Name:</th> <td> <input type='text' name='newName' value="<?php
/** * parse regular CSS blocks * * _parse_properties() creates a new Style object based on the provided * CSS rules. * * @param string $str CSS rules * @return Style */ private function _parse_properties($str) { $properties = preg_split("/;(?=(?:[^\\(]*\\([^\\)]*\\))*(?![^\\)]*\\)))/", $str); if (DEBUGCSS) { print '[_parse_properties'; } // Create the style $style = new Style($this); foreach ($properties as $prop) { // If the $prop contains an url, the regex may be wrong // @todo: fix the regex so that it works everytime /*if (strpos($prop, "url(") === false) { if (preg_match("/([a-z-]+)\s*:\s*[^:]+$/i", $prop, $m)) $prop = $m[0]; }*/ //A css property can have " ! important" appended (whitespace optional) //strip this off to decode core of the property correctly. //Pass on in the style to allow proper handling: //!important properties can only be overridden by other !important ones. //$style->$prop_name = is a shortcut of $style->__set($prop_name,$value);. //If no specific set function available, set _props["prop_name"] //style is always copied completely, or $_props handled separately //Therefore set a _important_props["prop_name"]=true to indicate the modifier /* Instead of short code, prefer the typical case with fast code $important = preg_match("/(.*?)!\s*important/",$prop,$match); if ( $important ) { $prop = $match[1]; } $prop = trim($prop); */ if (DEBUGCSS) { print '('; } $important = false; $prop = trim($prop); if (substr($prop, -9) === 'important') { $prop_tmp = rtrim(substr($prop, 0, -9)); if (substr($prop_tmp, -1) === '!') { $prop = rtrim(substr($prop_tmp, 0, -1)); $important = true; } } if ($prop == "") { if (DEBUGCSS) { print 'empty)'; } continue; } $i = mb_strpos($prop, ":"); if ($i === false) { if (DEBUGCSS) { print 'novalue' . $prop . ')'; } continue; } $prop_name = rtrim(mb_strtolower(mb_substr($prop, 0, $i))); $value = ltrim(mb_substr($prop, $i + 1)); if (DEBUGCSS) { print $prop_name . ':=' . $value . ($important ? '!IMPORTANT' : '') . ')'; } //New style, anyway empty //if ($important || !$style->important_get($prop_name) ) { //$style->$prop_name = array($value,$important); //assignment might be replaced by overloading through __set, //and overloaded functions might check _important_props, //therefore set _important_props first. if ($important) { $style->important_set($prop_name); } //For easier debugging, don't use overloading of assignments with __set $style->{$prop_name} = $value; //$style->props_set($prop_name, $value); } if (DEBUGCSS) { print '_parse_properties]'; } return $style; }
<div class="col-md-8"> <table class="table table-striped"> <tr> <th>Name:</th> <td><input type='text', name='name', class='form-control'></td> </tr> <tr> <th>Description:</th> <td><textarea name='description' form='new-style-form' class='form-control'></textarea></td> </tr> <tr> <th>Style:</th> <td> <select name ='style_id' class='form-control'> <?php $styles = Style::getAll(); foreach ($styles as $style) { echo "<option value={$style->id}>{$style->name}</option>"; } ?> </select> </td> </tr> <tr> <th>Brewery:</th> <td> <select name='brewery_id' class='form-control'> <?php $breweries = Brewery::getAll(); foreach ($breweries as $brewery) { echo "<option value={$brewery->id}>{$brewery->name}</option>";
/** * Render a background image over a rectangular area * * @param string $url The background image to load * @param float $x The left edge of the rectangular area * @param float $y The top edge of the rectangular area * @param float $width The width of the rectangular area * @param float $height The height of the rectangular area * @param Style $style The associated Style object * * @throws Exception */ protected function _background_image($url, $x, $y, $width, $height, $style) { if (!function_exists("imagecreatetruecolor")) { throw new Exception("The PHP GD extension is required, but is not installed."); } $sheet = $style->get_stylesheet(); // Skip degenerate cases if ($width == 0 || $height == 0) { return; } $box_width = $width; $box_height = $height; //debugpng if (DEBUGPNG) { print '[_background_image ' . $url . ']'; } list($img, $type, ) = Image_Cache::resolve_url($url, $sheet->get_protocol(), $sheet->get_host(), $sheet->get_base_path(), $this->_dompdf); // Bail if the image is no good if (Image_Cache::is_broken($img)) { return; } //Try to optimize away reading and composing of same background multiple times //Postponing read with imagecreatefrom ...() //final composition parameters and name not known yet //Therefore read dimension directly from file, instead of creating gd object first. //$img_w = imagesx($src); $img_h = imagesy($src); list($img_w, $img_h) = dompdf_getimagesize($img); if (!isset($img_w) || $img_w == 0 || !isset($img_h) || $img_h == 0) { return; } $repeat = $style->background_repeat; $dpi = $this->_dompdf->get_option("dpi"); //Increase background resolution and dependent box size according to image resolution to be placed in //Then image can be copied in without resize $bg_width = round((double) ($width * $dpi) / 72); $bg_height = round((double) ($height * $dpi) / 72); //Need %bg_x, $bg_y as background pos, where img starts, converted to pixel list($bg_x, $bg_y) = $style->background_position; if (is_percent($bg_x)) { // The point $bg_x % from the left edge of the image is placed // $bg_x % from the left edge of the background rectangle $p = (double) $bg_x / 100.0; $x1 = $p * $img_w; $x2 = $p * $bg_width; $bg_x = $x2 - $x1; } else { $bg_x = (double) ($style->length_in_pt($bg_x) * $dpi) / 72; } $bg_x = round($bg_x + $style->length_in_pt($style->border_left_width) * $dpi / 72); if (is_percent($bg_y)) { // The point $bg_y % from the left edge of the image is placed // $bg_y % from the left edge of the background rectangle $p = (double) $bg_y / 100.0; $y1 = $p * $img_h; $y2 = $p * $bg_height; $bg_y = $y2 - $y1; } else { $bg_y = (double) ($style->length_in_pt($bg_y) * $dpi) / 72; } $bg_y = round($bg_y + $style->length_in_pt($style->border_top_width) * $dpi / 72); //clip background to the image area on partial repeat. Nothing to do if img off area //On repeat, normalize start position to the tile at immediate left/top or 0/0 of area //On no repeat with positive offset: move size/start to have offset==0 //Handle x/y Dimensions separately if ($repeat !== "repeat" && $repeat !== "repeat-x") { //No repeat x if ($bg_x < 0) { $bg_width = $img_w + $bg_x; } else { $x += $bg_x * 72 / $dpi; $bg_width = $bg_width - $bg_x; if ($bg_width > $img_w) { $bg_width = $img_w; } $bg_x = 0; } if ($bg_width <= 0) { return; } $width = (double) ($bg_width * 72) / $dpi; } else { //repeat x if ($bg_x < 0) { $bg_x = -(-$bg_x % $img_w); } else { $bg_x = $bg_x % $img_w; if ($bg_x > 0) { $bg_x -= $img_w; } } } if ($repeat !== "repeat" && $repeat !== "repeat-y") { //no repeat y if ($bg_y < 0) { $bg_height = $img_h + $bg_y; } else { $y += $bg_y * 72 / $dpi; $bg_height = $bg_height - $bg_y; if ($bg_height > $img_h) { $bg_height = $img_h; } $bg_y = 0; } if ($bg_height <= 0) { return; } $height = (double) ($bg_height * 72) / $dpi; } else { //repeat y if ($bg_y < 0) { $bg_y = -(-$bg_y % $img_h); } else { $bg_y = $bg_y % $img_h; if ($bg_y > 0) { $bg_y -= $img_h; } } } //Optimization, if repeat has no effect if ($repeat === "repeat" && $bg_y <= 0 && $img_h + $bg_y >= $bg_height) { $repeat = "repeat-x"; } if ($repeat === "repeat" && $bg_x <= 0 && $img_w + $bg_x >= $bg_width) { $repeat = "repeat-y"; } if ($repeat === "repeat-x" && $bg_x <= 0 && $img_w + $bg_x >= $bg_width || $repeat === "repeat-y" && $bg_y <= 0 && $img_h + $bg_y >= $bg_height) { $repeat = "no-repeat"; } //Use filename as indicator only //different names for different variants to have different copies in the pdf //This is not dependent of background color of box! .'_'.(is_array($bg_color) ? $bg_color["hex"] : $bg_color) //Note: Here, bg_* are the start values, not end values after going through the tile loops! $filedummy = $img; $is_png = false; $filedummy .= '_' . $bg_width . '_' . $bg_height . '_' . $bg_x . '_' . $bg_y . '_' . $repeat; //Optimization to avoid multiple times rendering the same image. //If check functions are existing and identical image already cached, //then skip creation of duplicate, because it is not needed by addImagePng if ($this->_canvas instanceof CPDF_Adapter && $this->_canvas->get_cpdf()->image_iscached($filedummy)) { $bg = null; } else { // Create a new image to fit over the background rectangle $bg = imagecreatetruecolor($bg_width, $bg_height); switch (strtolower($type)) { case IMAGETYPE_PNG: $is_png = true; imagesavealpha($bg, true); imagealphablending($bg, false); $src = imagecreatefrompng($img); break; case IMAGETYPE_JPEG: $src = imagecreatefromjpeg($img); break; case IMAGETYPE_GIF: $src = imagecreatefromgif($img); break; case IMAGETYPE_BMP: $src = imagecreatefrombmp($img); break; default: return; // Unsupported image type } if ($src == null) { return; } //Background color if box is not relevant here //Non transparent image: box clipped to real size. Background non relevant. //Transparent image: The image controls the transparency and lets shine through whatever background. //However on transparent image preset the composed image with the transparency color, //to keep the transparency when copying over the non transparent parts of the tiles. $ti = imagecolortransparent($src); if ($ti >= 0) { $tc = imagecolorsforindex($src, $ti); $ti = imagecolorallocate($bg, $tc['red'], $tc['green'], $tc['blue']); imagefill($bg, 0, 0, $ti); imagecolortransparent($bg, $ti); } //This has only an effect for the non repeatable dimension. //compute start of src and dest coordinates of the single copy if ($bg_x < 0) { $dst_x = 0; $src_x = -$bg_x; } else { $src_x = 0; $dst_x = $bg_x; } if ($bg_y < 0) { $dst_y = 0; $src_y = -$bg_y; } else { $src_y = 0; $dst_y = $bg_y; } //For historical reasons exchange meanings of variables: //start_* will be the start values, while bg_* will be the temporary start values in the loops $start_x = $bg_x; $start_y = $bg_y; // Copy regions from the source image to the background if ($repeat === "no-repeat") { // Simply place the image on the background imagecopy($bg, $src, $dst_x, $dst_y, $src_x, $src_y, $img_w, $img_h); } else { if ($repeat === "repeat-x") { for ($bg_x = $start_x; $bg_x < $bg_width; $bg_x += $img_w) { if ($bg_x < 0) { $dst_x = 0; $src_x = -$bg_x; $w = $img_w + $bg_x; } else { $dst_x = $bg_x; $src_x = 0; $w = $img_w; } imagecopy($bg, $src, $dst_x, $dst_y, $src_x, $src_y, $w, $img_h); } } else { if ($repeat === "repeat-y") { for ($bg_y = $start_y; $bg_y < $bg_height; $bg_y += $img_h) { if ($bg_y < 0) { $dst_y = 0; $src_y = -$bg_y; $h = $img_h + $bg_y; } else { $dst_y = $bg_y; $src_y = 0; $h = $img_h; } imagecopy($bg, $src, $dst_x, $dst_y, $src_x, $src_y, $img_w, $h); } } else { if ($repeat === "repeat") { for ($bg_y = $start_y; $bg_y < $bg_height; $bg_y += $img_h) { for ($bg_x = $start_x; $bg_x < $bg_width; $bg_x += $img_w) { if ($bg_x < 0) { $dst_x = 0; $src_x = -$bg_x; $w = $img_w + $bg_x; } else { $dst_x = $bg_x; $src_x = 0; $w = $img_w; } if ($bg_y < 0) { $dst_y = 0; $src_y = -$bg_y; $h = $img_h + $bg_y; } else { $dst_y = $bg_y; $src_y = 0; $h = $img_h; } imagecopy($bg, $src, $dst_x, $dst_y, $src_x, $src_y, $w, $h); } } } else { print 'Unknown repeat!'; } } } } imagedestroy($src); } /* End optimize away creation of duplicates */ $this->_canvas->clipping_rectangle($x, $y, $box_width, $box_height); //img: image url string //img_w, img_h: original image size in px //width, height: box size in pt //bg_width, bg_height: box size in px //x, y: left/top edge of box on page in pt //start_x, start_y: placement of image relative to pattern //$repeat: repeat mode //$bg: GD object of result image //$src: GD object of original image //When using cpdf and optimization to direct png creation from gd object is available, //don't create temp file, but place gd object directly into the pdf if (!$is_png && $this->_canvas instanceof CPDF_Adapter) { // Note: CPDF_Adapter image converts y position $this->_canvas->get_cpdf()->addImagePng($filedummy, $x, $this->_canvas->get_height() - $y - $height, $width, $height, $bg); } else { $tmp_dir = $this->_dompdf->get_option("temp_dir"); $tmp_name = tempnam($tmp_dir, "bg_dompdf_img_"); @unlink($tmp_name); $tmp_file = "{$tmp_name}.png"; //debugpng if (DEBUGPNG) { print '[_background_image ' . $tmp_file . ']'; } imagepng($bg, $tmp_file); $this->_canvas->image($tmp_file, $x, $y, $width, $height); imagedestroy($bg); //debugpng if (DEBUGPNG) { print '[_background_image unlink ' . $tmp_file . ']'; } if (!DEBUGKEEPTEMP) { unlink($tmp_file); } } $this->_canvas->clipping_end(); }
/** * Adds a heading style definition to styles.xml * * @param int $depth * @param mixed $fontStyle * @param mixed $paragraphStyle * @return \PhpOffice\PhpWord\Style\Font */ public function addTitleStyle($depth, $fontStyle, $paragraphStyle = null) { return Style::addTitleStyle($depth, $fontStyle, $paragraphStyle); }