function importskinform_submit(Pieform $form, $values) { global $USER, $SESSION; require_once get_config('docroot') . 'artefact/file/lib.php'; // Open XML file and import Skin(s)... $filename = $values['file']['tmp_name']; $contents = file_get_contents($filename); $xmldoc = new DOMDocument('1.0', 'UTF-8'); //$xmldoc->load($filename); $xmldoc->loadXML($contents); $skinsdata = $xmldoc->getElementsByTagName('skin'); $siteskin = $values['skintype'] == 'site'; // A non-admin can't create a site skin. if ($siteskin && !$USER->get('admin')) { $values['skintype'] = 'private'; $siteskin = false; } foreach ($skinsdata as $skindata) { db_begin(); // Join all view skin css/formating data to array... $skin = array(); // Body element... $items = $skindata->getElementsByTagName('body'); foreach ($items as $item) { $skin = array_merge($skin, array('body_background_color' => $item->getAttribute('background-color'))); $skin = array_merge($skin, array('body_background_image' => 0)); $skin = array_merge($skin, array('body_background_repeat' => Skin::background_repeat_value_to_number($item->getAttribute('background-repeat')))); $skin = array_merge($skin, array('body_background_attachment' => $item->getAttribute('background-attachment'))); $skin = array_merge($skin, array('body_background_position' => Skin::background_position_value_to_number($item->getAttribute('background-position')))); } // Header element... $items = $skindata->getElementsByTagName('header'); foreach ($items as $item) { $skin = array_merge($skin, array('header_background_color' => $item->getAttribute('background-color'))); $skin = array_merge($skin, array('header_text_font_color' => $item->getAttribute('font-color'))); $skin = array_merge($skin, array('header_link_normal_color' => $item->getAttribute('normal-color'))); if ($item->getAttribute('normal-decoration') == 'none') { $skin = array_merge($skin, array('header_link_normal_underline' => 0)); } else { $skin = array_merge($skin, array('header_link_normal_underline' => 1)); } $skin = array_merge($skin, array('header_link_hover_color' => $item->getAttribute('hover-color'))); if ($item->getAttribute('hover-decoration') == 'none') { $skin = array_merge($skin, array('header_link_hover_underline' => 0)); } else { $skin = array_merge($skin, array('header_link_hover_underline' => 1)); } $skin = array_merge($skin, array('header_logo_image' => $item->getAttribute('logo-image'))); } // View element... $items = $skindata->getElementsByTagName('view'); foreach ($items as $item) { $skin = array_merge($skin, array('view_background_color' => $item->getAttribute('background-color'))); $skin = array_merge($skin, array('view_background_image' => 0)); $skin = array_merge($skin, array('view_background_repeat' => Skin::background_repeat_value_to_number($item->getAttribute('background-repeat')))); $skin = array_merge($skin, array('view_background_attachment' => $item->getAttribute('background-attachment'))); $skin = array_merge($skin, array('view_background_position' => Skin::background_position_value_to_number($item->getAttribute('background-position')))); $skin = array_merge($skin, array('view_background_width' => str_replace("%", "", $item->getAttribute('width')))); // odstrani znak %! $skin = array_merge($skin, array('view_background_margin' => $item->getAttribute('margin-top'))); } // Text element... $items = $skindata->getElementsByTagName('text'); foreach ($items as $item) { $skin = array_merge($skin, array('view_text_font_family' => $item->getAttribute('text-font'))); $skin = array_merge($skin, array('view_heading_font_family' => $item->getAttribute('heading-font'))); $skin = array_merge($skin, array('view_text_font_size' => $item->getAttribute('font-size'))); $skin = array_merge($skin, array('view_text_font_color' => $item->getAttribute('font-color'))); $skin = array_merge($skin, array('view_text_heading_color' => $item->getAttribute('heading-color'))); $skin = array_merge($skin, array('view_text_emphasized_color' => $item->getAttribute('emphasized-color'))); } // Link element... $items = $skindata->getElementsByTagName('link'); foreach ($items as $item) { $skin = array_merge($skin, array('view_link_normal_color' => $item->getAttribute('normal-color'))); if ($item->getAttribute('normal-decoration') == 'none') { $skin = array_merge($skin, array('view_link_normal_underline' => 0)); } else { $skin = array_merge($skin, array('view_link_normal_underline' => 1)); } $skin = array_merge($skin, array('view_link_hover_color' => $item->getAttribute('hover-color'))); if ($item->getAttribute('hover-decoration') == 'none') { $skin = array_merge($skin, array('view_link_hover_underline' => 0)); } else { $skin = array_merge($skin, array('view_link_hover_underline' => 1)); } } // Table element... $items = $skindata->getElementsByTagName('table'); foreach ($items as $item) { $skin = array_merge($skin, array('view_table_border_color' => $item->getAttribute('border-color'))); $skin = array_merge($skin, array('view_table_odd_row_color' => $item->getAttribute('odd-row-color'))); $skin = array_merge($skin, array('view_table_even_row_color' => $item->getAttribute('even-row-color'))); } // Custom CSS element... $items = $skindata->getElementsByTagName('customcss'); foreach ($items as $item) { $skin['view_custom_css'] = clean_css(unserialize($item->getAttribute('contents')), $preserve_css = true); } // Image element... // TODO: Background image file support for site skins if ($siteskin) { $skin['body_background_image'] = 0; $skin['view_background_image'] = 0; } else { $items = $skindata->getElementsByTagName('image'); foreach ($items as $item) { // Write necessary data in 'artefact' table... // TODO: When we rework the file upload code to make it more general, // rewrite this to reuse content from filebrowser.php $now = date("Y-m-d H:i:s"); $artefact = (object) array_merge((array) unserialize($item->getAttribute('artefact')), (array) unserialize($item->getAttribute('artefact_file_files')), (array) unserialize($item->getAttribute('artefact_file_image'))); unset($artefact->id); unset($artefact->fileid); $artefact->owner = $USER->get('id'); $artefact->author = $USER->get('id'); $artefact->atime = $now; $artefact->ctime = $now; $artefact->mtime = $now; $artobj = new ArtefactTypeImage(0, $artefact); $artobj->commit(); $id = $artobj->get('id'); // Create folder and file inside it. then write contents into it... $imagedir = get_config('dataroot') . ArtefactTypeFile::get_file_directory($id); if (!check_dir_exists($imagedir, true, true)) { throw new SystemException("Unable to create folder {$imagedir}"); } else { // Write contents to a file... $imagepath = $imagedir . '/' . $id; $contents = base64_decode($item->getAttribute('contents')); $fp = fopen($imagepath, 'w'); fwrite($fp, $contents); fclose($fp); // We can keep going, but the skin will be missing one of its files if ($clamerror = mahara_clam_scan_file($imagepath)) { $SESSION->add_error_msg($clamerror); } chmod($imagepath, get_config('filepermissions')); } $type = $item->getAttribute('type'); if ($type == 'body-background-image') { $skin['body_background_image'] = $id; } if ($type == 'view-background-image') { $skin['view_background_image'] = $id; } } } $viewskin = array(); if ($skindata->getAttribute('title') != '') { $viewskin['title'] = $skindata->getAttribute('title'); } $viewskin['description'] = $skindata->getAttribute('description'); $viewskin['owner'] = $USER->get('id'); $viewskin['type'] = $values['skintype']; $viewskin['viewskin'] = $skin; // Fonts element... // Only admins can install site fonts if ($USER->get('admin')) { $fonts = $skindata->getElementsByTagName('font'); foreach ($fonts as $font) { $fontname = preg_replace("#[^A-Za-z0-9]#", "", $font->getAttribute('name')); $fontname = Skin::new_font_name($fontname); // Only upload font if it doesn't already exist on the site if (!Skin::font_exists($font->getAttribute('title'))) { $fontdata = array('name' => $fontname, 'title' => $font->getAttribute('title'), 'licence' => $font->getAttribute('font-licence'), 'previewfont' => $font->getAttribute('font-preview'), 'variants' => base64_decode($font->getAttribute('font-variants')), 'fonttype' => $font->getAttribute('font-type'), 'onlyheading' => $font->getAttribute('heading-font-only'), 'fontstack' => $font->getAttribute('font-stack'), 'genericfont' => $font->getAttribute('generic-font')); insert_record('skin_fonts', $fontdata); $fontpath = get_config('dataroot') . 'skins/fonts/' . $fontdata['name'] . '/'; if (!check_dir_exists($fontpath, true, true)) { throw new SystemException("Unable to create folder {$fontpath}"); } else { $files = $font->getElementsByTagName('file'); foreach ($files as $file) { // Read the filename and the contents of each file from XML... $filename = $file->getAttribute('name'); $contents = base64_decode($file->getAttribute('contents')); // Import and copy each file to the appropriate folder... $fp = fopen($fontpath . $filename, 'wb'); fwrite($fp, $contents); fclose($fp); // We can keep going, but the skin will be missing one of its files if ($clamerror = mahara_clam_scan_file($fontpath . $filename)) { $SESSION->add_error_msg($clamerror); } chmod($fontpath . $filename, get_config('filepermissions')); } } } } } Skin::create($viewskin); db_commit(); } $SESSION->add_ok_msg(get_string('skinimported', 'skin')); if ($values['skintype'] == 'site') { redirect('/admin/site/skins.php'); } else { redirect('/skin/index.php'); } }
public static function getRecordDataById($type, $id) { global $USER; $sql = 'SELECT a.id, a.artefacttype, a.parent, a.owner, a.title, a.description, a.institution, a.group, a.author, p.artefacttype AS parent_artefacttype, p.title AS parent_title, p.description AS parent_description, a.license, afi.width, afi.height, a.note FROM {artefact} a LEFT OUTER JOIN {artefact} p ON p.id = a.parent LEFT OUTER JOIN {artefact_file_image} afi ON afi.artefact = a.id WHERE a.id = ?'; $record = get_record_sql($sql, array($id)); if (!$record) { return false; } $record->title = str_replace(array("\r\n", "\n", "\r"), ' ', strip_tags($record->title)); $record->description = str_replace(array("\r\n", "\n", "\r"), ' ', strip_tags($record->description)); // If user is owner if ($USER->get('id') == $record->owner) { switch ($record->artefacttype) { case 'image': case 'video': case 'audio': case 'file': $record->link = 'artefact/file'; if (isset($record->parent) && intval($record->parent) > 0) { $record->link .= '/index.php?folder=' . $record->parent; } break; case 'blogpost': if (isset($record->parent) && intval($record->parent) > 0) { $record->link = 'artefact/blog/view/index.php?id=' . $record->parent; } break; case 'blog': $record->link = 'artefact/blog/view/index.php'; if ($USER->get_account_preference('multipleblogs')) { $record->link .= '?id=' . $record->id; } break; case 'coverletter': case 'personalinformation': $record->link = 'artefact/resume/index.php'; break; case 'educationhistory': case 'employmenthistory': $record->link = 'artefact/resume/employment.php'; break; case 'book': case 'certification': case 'membership': $record->link = 'artefact/resume/achievements.php'; break; case 'academicgoal': case 'careergoal': case 'personalgoal': case 'personalinformation': case 'academicskill': case 'personalskill': case 'workskill': $record->link = 'artefact/resume/goalsandskills.php'; break; case 'interest': $record->link = 'artefact/resume/interests.php'; break; case 'plan': $record->link = 'artefact/plans/plan.php?id=' . $record->id; break; case 'task': if (isset($record->parent) && intval($record->parent) > 0) { $record->link = 'artefact/plans/plan.php?id=' . $record->parent; } break; case 'socialprofile': $record->note = str_replace(array("\r\n", "\n", "\r"), ' ', strip_tags($record->note)); $socialprofile = new ArtefactTypeSocialprofile($record->id); $icons = $socialprofile->get_profile_icons(array($record)); if (!empty($icons)) { $record->link = $icons[0]->link; $record->icon = $icons[0]->icon; } break; } } // VIEWS get all the views the artefact is included into. // artefact parents are folder, blog, plan, cpd $sql = 'SELECT COALESCE(v.id, vp.id) AS id, COALESCE(v.title, vp.title) AS title FROM {artefact} a LEFT OUTER JOIN {view_artefact} va ON va.artefact = a.id LEFT OUTER JOIN {view} v ON v.id = va.view LEFT OUTER JOIN {artefact} parent ON parent.id = a.parent LEFT OUTER JOIN {view_artefact} vap ON vap.artefact = parent.id LEFT OUTER JOIN {view} vp ON vp.id = vap.view WHERE a.id = ?'; $views = get_records_sql_array($sql, array($id)); if ($views) { $record_views = array(); foreach ($views as $view) { if (isset($view->id)) { $record_views[$view->id] = $view->title; } } $record_views = self::views_by_artefact_acl_filter($record_views); $record->views = $record_views; } // Tags $tags = get_records_array('artefact_tag', 'artefact', $id); if ($tags != false) { foreach ($tags as $tag) { $record->tags[] = $tag->tag; } } else { $record->tags = null; } // Created by if (intval($record->author) > 0) { $record->createdby = get_record('usr', 'id', $record->author); $record->createdbyname = display_name($record->createdby); } // Thumb if ($record->artefacttype == 'image') { if (isset($record->width) && isset($record->height) && intval($record->width) > 0 && intval($record->height) > 0) { if ($record->width > $record->height) { $size = '80x' . intval($record->height * 80 / $record->width); } else { $size = intval($record->width * 80 / $record->height) . 'x80'; } } $record->thumb = ArtefactTypeImage::get_icon(array('id' => $id, 'size' => $size)); } return $record; }
public static function bulk_delete($artefactids) { global $USER; parent::bulk_delete($artefactids); if (in_array($USER->get('profileicon'), $artefactids)) { $USER->profileicon = null; $USER->commit(); } }
public function __construct($id = 0, $data = null) { parent::__construct($id, $data); if (empty($this->id)) { $this->allowcomments = 0; } }