function sc_sitebutton($parm = null) { if ($_POST['sitebutton'] && $_POST['ajax_used']) { $path = e107::getParser()->replaceConstants($_POST['sitebutton']); } else { $path = strstr(SITEBUTTON, 'http:') ? SITEBUTTON : e_IMAGE . SITEBUTTON; } if ($parm['type'] == 'email' || $parm == 'email') { $h = !empty($parm['h']) ? $parm['h'] : 100; $path = e107::getConfig()->get('sitebutton'); $realPath = e107::getParser()->replaceConstants($path); if (defined('e_MEDIA') && is_writeable(e_MEDIA . "temp/") && ($resized = e107::getMedia()->resizeImage($path, e_MEDIA . "temp/" . basename($realPath), 'h=' . $h))) { $path = e107::getParser()->createConstants($resized); } } if (!empty($path)) { return '<a href="' . SITEURL . '" class="sitebutton"><img src="' . $path . '" alt="' . SITENAME . '" /></a>'; } }
function showImages($cat) { $mes = e107::getMessage(); $tp = e107::getParser(); $template = e107::getTemplate('gallery'); $sc = e107::getScBatch('gallery', TRUE); $sc->total = e107::getMedia()->countImages($cat); $sc->amount = 12; // TODO Add Pref. amount per page. $sc->curCat = $cat; $sc->from = $_GET['frm'] ? intval($_GET['frm']) : 0; $list = e107::getMedia()->getImages($cat, $sc->from, $sc->amount); $catname = $tp->toHtml($this->catList[$cat]['media_cat_title'], false, 'defs'); $inner = ""; foreach ($list as $row) { $sc->setVars($row); $inner .= $tp->parseTemplate($template['LIST_ITEM'], TRUE); } $text = $tp->parseTemplate($template['LIST_START'], TRUE); $text .= $inner; $text .= $tp->parseTemplate($template['LIST_END'], TRUE); e107::getRender()->tablerender("Gallery :: " . $catname, $mes->render() . $text); }
function showImages($cat) { $mes = e107::getMessage(); $tp = e107::getParser(); $template = e107::getTemplate('gallery'); $template = array_change_key_case($template); $sc = e107::getScBatch('gallery', TRUE); if (defset('BOOTSTRAP') === true || defset('BOOTSTRAP') === 2) { $template['list_start'] = str_replace('row', 'row-fluid', $template['list_start']); } $sc->total = e107::getMedia()->countImages($cat); $sc->amount = 12; // TODO Add Pref. amount per page. $sc->curCat = $cat; $sc->from = $_GET['frm'] ? intval($_GET['frm']) : 0; $list = e107::getMedia()->getImages($cat, $sc->from, $sc->amount); $catname = $tp->toHtml($this->catList[$cat]['media_cat_title'], false, 'defs'); $inner = ""; foreach ($list as $row) { $sc->setVars($row); $inner .= $tp->parseTemplate($template['list_item'], TRUE, $sc); } $text = $tp->parseTemplate($template['list_start'], TRUE, $sc); $text .= $inner; $text .= $tp->parseTemplate($template['list_end'], TRUE, $sc); e107::getRender()->tablerender(LAN_PLUGIN_GALLERY_TITLE, $mes->render() . $text); }
function PreImage_Select($formid = 'preimage_selector') { global $bbcode_imagedir; $med = e107::getMedia(); $text = "<!-- Start of PreImage selector -->"; $text .= $med->imageSelect($bbcode_imagedir, $formid); return $text; }
function getPath($mime) { return e107::getMedia()->getPath($mime); /* $mes = e107::getMessage(); list($pmime,$tmp) = explode('/',$mime); if(!vartrue($this->mimePaths[$pmime])) { $text = str_replace('[x]',$mime,IMALAN_111); $mes->add($text, E_MESSAGE_ERROR); return FALSE; } $dir = $this->mimePaths[$pmime].date("Y-m"); if(!is_dir($dir)) { if(!mkdir($dir, 0755)) { $text = str_replace('[x]',$dir,IMALAN_112); $mes->add($text, E_MESSAGE_ERROR); return FALSE; }; } return $dir;*/ }
function processUploadUrl($import = false, $cat = '_common') { $fl = e107::getFile(); $mes = e107::getMessage(); if (vartrue($_POST['upload_remote_url'])) { $fileName = basename($_POST['upload_url']); if (strpos($fileName, '?') !== false) { list($fileName, $bla) = explode("?", $fileName); } if (!$fl->getRemoteFile($_POST['upload_url'], $fileName, 'import')) { $mes->addError("There was a problem grabbing the file"); } elseif ($import == true) { $result = e107::getMedia()->importFile($fileName, $cat); } } }
function init() { $effects = array('scrollHorz' => 'slide left', 'scrollVert' => 'slide down', 'fade' => 'fade'); $this->prefs['slideshow_effect']['writeParms'] = $effects; $this->prefs['slideshow_effect']['readParms'] = $effects; // // $transitions = array('sinoidal'=>'sinoidal','spring'=>'spring'); // $this->prefs['slideshow_transition']['writeParms'] = $transitions; // $this->prefs['slideshow_transition']['readParms'] = $transitions; $categories = e107::getMedia()->getCategories('gallery'); $cats = array(); foreach ($categories as $k => $var) { $id = preg_replace("/[^0-9]/", '', $k); $cats[$id] = $var['media_cat_title']; } $this->prefs['slideshow_category']['writeParms'] = $cats; $this->prefs['slideshow_category']['readParms'] = $cats; $mes = e107::getMessage(); $message = "<b>Gallery</b> is active. Simply import and assign images to the gallery categories using the <a href='" . e_ADMIN . "image.php'>Media Manager</a>"; $mes->addInfo($message); }
function loadSubmitted($id) { $sql = e107::getDb(); $tp = e107::getParser(); if ($sql->select("submitnews", "*", "submitnews_id=" . intval($id))) { $row = $sql->fetch(); $data['news_title'] = $tp->dataFilter($row['submitnews_title']); $data['news_body'] = $row['submitnews_item']; $data['news_category'] = intval($row['submitnews_category']); $data['news_body'] .= "\n[[b]" . NWSLAN_49 . " {$row['submitnews_name']}[/b]]"; $thumbs = array(); if ($row['submitnews_file']) { $files = explode(",", $row['submitnews_file']); foreach ($files as $f) { if ($bbpath = e107::getMedia()->importFile($f, 'news')) { $thumbs[] = $bbpath; // $data['news_body'] .= "\n\n[img]".$bbpath."[/img]"; } } } $data['news_thumbnail'] = implode(",", $thumbs); $data['submitted_id'] = $id; foreach ($data as $k => $v) { $this->getModel()->setData($k, $v); // Override Table data. } } }
/** * All possible parameters * {GALLERY_SLIDES=4|limit=16&template=MY_SLIDESHOW_SLIDE_ITEM} * first parameter is always number of slides, default is 3 * limit - (optional) total limit of pcitures to be shown * template - (optional) template - name of template to be used for parsing the slideshow item */ function sc_gallery_slides($parm) { $tp = e107::getParser(); $this->slideMode = TRUE; $parms = eHelper::scDualParams($parm); $amount = $parms[1] ? intval($parms[1]) : 3; // vartrue(e107::getPlugPref('gallery','slideshow_perslide'),3); $parms = $parms[2]; $limit = (int) vartrue($parms['limit'], 16); $list = e107::getMedia()->getImages('gallery_' . $this->sliderCat . '|gallery_image_' . $this->sliderCat, 0, $limit); $tmpl = e107::getTemplate('gallery', 'gallery'); $tmpl = array_change_key_case($tmpl); // change template key to lowercase (BC fix) $tmpl_key = vartrue($parms['template'], 'slideshow_slide_item'); $item_template = $tmpl[$tmpl_key]; // e107::getTemplate('gallery','gallery', vartrue($parms['template'], 'SLIDESHOW_SLIDE_ITEM')); $catList = e107::getMedia()->getCategories('gallery'); $cat = $catList['gallery_' . $this->sliderCat]; $count = 1; foreach ($list as $row) { $this->setVars($row)->addVars($cat); $inner .= $count == 1 ? "\n\n<!-- SLIDE " . $count . " -->\n<div class='slide' id='gallery-item-" . $this->slideCount . "'>\n" : ""; $inner .= "\n\t" . $tp->parseTemplate($item_template, TRUE) . "\n"; $inner .= $count == $amount ? "\n</div>\n\n" : ""; if ($count == $amount) { $count = 1; $this->slideCount++; } else { $count++; } } $inner .= $count != 1 ? "</div><!-- END SLIDES -->" : ""; return $inner; }
function loadSubmitted($id) { $sql = e107::getDb(); $tp = e107::getParser(); if ($sql->db_Select("submitnews", "*", "submitnews_id=" . intval($id), TRUE)) { //list($id, $submitnews_name, $submitnews_email, $_POST['news_title'], $submitnews_category, $_POST['news_body'], $submitnews_datestamp, $submitnews_ip, $submitnews_auth, $submitnews_file) = $sql->db_Fetch(); $row = $sql->db_Fetch(); $_POST['news_title'] = $row['submitnews_title']; $_POST['news_body'] = $row['submitnews_item']; $_POST['cat_id'] = $row['submitnews_category']; if (defsettrue('e_WYSIWYG')) { if (substr($_POST['news_body'], -7, 7) == '[/html]') { $_POST['news_body'] = substr($_POST['news_body'], 0, -7); } if (substr($_POST['news_body'], 0, 6) == '[html]') { $_POST['news_body'] = substr($_POST['news_body'], 6); } $_POST['news_body'] .= "<br /><b>" . NWSLAN_49 . " {$row['submitnews_name']}</b>"; $_POST['news_body'] .= $row['submitnews_file'] ? "<br /><br /><img src='{e_NEWSIMAGE}{$row['submitnews_file']}' class='f-right' />" : ''; } else { $_POST['news_body'] .= "\n[[b]" . NWSLAN_49 . " {$row['submitnews_name']}[/b]]"; if ($row['submitnews_file']) { $files = explode(",", $row['submitnews_file']); foreach ($files as $f) { if ($bbpath = e107::getMedia()->importFile($f, 'news')) { $_POST['news_body'] .= "\n\n[img]" . $bbpath . "[/img]"; } } } } $_POST['data'] = $tp->dataFilter($_POST['data']); // Filter any nasties $_POST['news_title'] = $tp->dataFilter($_POST['news_title']); } }
/** Download and Import remote images and update body text with local relative-links. eg. {e_MEDIA} * @param returns text-body with remote links replaced with local ones for the images downloaded. */ function saveImages($body, $cat = 'news') { $mes = e107::getMessage(); $med = e107::getMedia(); $tp = e107::getParser(); $search = array(); $replace = array(); // echo htmlentities($body); preg_match_all("/(((http:\\/\\/www)|(http:\\/\\/)|(www))[-a-zA-Z0-9@:%_\\+.~#?&\\/\\/=]+)\\.(jpg|jpeg|gif|png|svg)/im", $body, $matches); $fl = e107::getFile(); if (is_array($matches[0])) { $relPath = 'images/' . md5($this->feedUrl); if (!is_dir(e_MEDIA . $relPath)) { mkdir(e_MEDIA . $relPath, '0755'); } foreach ($matches[0] as $link) { if (file_exists($relPath . "/" . $filename)) { continue; } $filename = basename($link); $fl->getRemoteFile($link, $relPath . "/" . $filename); $search[] = $link; $replace[] = $tp->createConstants(e_MEDIA . $relPath . "/" . $filename, 1); } } if (count($search)) { $med->import($cat, e_MEDIA . $relPath); } return str_replace($search, $replace, $body); }
function mediaSelectUpload($type = 'image') { $frm = e107::getForm(); $bbcodeMode = $this->getQuery('bbcode') == 'img' ? 'bbcode=img' : FALSE; $text = "\n\t\t\t<div class='admintabs' id='tab-container'>\n\t\t\t<ul class='e-tabs' id='core-emote-tabs'>\n\t\t\t\t<li id='tab-select'><a href='#core-media-select'>Choose from Library</a></li>\n\t\t\t\t<li id='tab-upload'><a href='#core-media-upload'>Upload a File</a></li>"; if ($bbcodeMode) { $text .= "<li id='tab-style'><a href='#core-media-style'>Appearance</a></li>\n"; } if ($_GET['from']) { $bbcodeMode .= "&from=" . intval($_GET['from']); } $text .= "\n\t\t\t</ul>\n\t\t\t<fieldset id='core-media-select'>\n\t\t\t<legend>Library</legend>\n\t\t\t<table class='table adminform'>\n\t\t\t<tbody><tr><td>\n\t\t\t"; $tag = $bbcodeMode ? "" : $this->getQuery('tagid'); if ($type == 'file') { $this->perPage = 0; $this->getTreeModel()->setParam('db_query', $this->_modifyListQry(false, false, false, false, $this->listQry))->load(); $text .= $this->getUI()->getList(); } else { $text .= e107::getMedia()->mediaSelect($this->getQuery('for'), $this->getQuery('tagid'), $bbcodeMode); // eg. news, news-thumbnail } $text .= "\n\t\t\t</td></tr>\n\t\t\t</tbody></table>\n\t\t\t</fieldset>\n\t\t\t\n\t\t\t<fieldset id='core-media-upload'>\n\t\t\t<legend>Upload</legend>"; $this->fields['media_category']['readonly'] = TRUE; $this->fields['media_url']['noedit'] = TRUE; $this->fields['media_userclass']['noedit'] = TRUE; $text .= $this->uploadPage(); // To test upload script with plupload // $text .= $this->CreatePage(); // comment me out to test plupload $text .= "\t\n\t\t\t</fieldset>"; /* In BBCODE-Mode this dialog rerturns an [img] bbcode to the 'tagid' container with the appropriate parms generated. * eg. [img style=float:left;margin-right:3px]{e_MEDIA_IMAGE}someimage.jpg[/img] * Then the dialog may be used as a bbcode img popup and within TinyMce also. * */ if ($bbcodeMode) { $text .= "<fieldset id='core-media-style'>\n\t\t\t\t<legend>Appearance</legend>\n\t\t\t\t<table class='table adminform'>\n\t\t\t\t<colgroup>\n\t\t\t\t\t<col class='col-label' />\n\t\t\t\t\t<col class='col-control' />\n\t\t\t\t</colgroup>\n\t\t\t\t<tbody>\n\t\t\t\t\t<tr>\n\t\t\t\t\t\t<td>Dimensions: </td>\n\t\t\t\t\t\t<td>\n\t\t\t\t\t\t<input type='text' class='e-media-attribute' id='width' name='width' size='4' style='width:50px' value='' /> px\n\t\t\t\t\t\t X <input type='text' class='e-media-attribute' id='height' name='height' size='4' style='width:50px' value='' /> px\n\t\t\t\t\t\t</td>\n\t\t\t\t\t</tr>\n\t\t\t\n\t\t\t\t\t<tr>\n\t\t\t\t\t\t<td>Text flow: </td>\n\t\t\t\t\t\t<td>" . $frm->selectbox('float', array('default' => 'Default', 'left' => 'Right', 'right' => "Left")) . "</td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t\n\t\t\t\t\t<tr>\n\t\t\t\t\t\t<td>Margin-Left: </td>\n\t\t\t\t\t\t<td><input class='e-media-attribute' type='text' id='margin-left' name='margin_left' value='' /></td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t\n\t\t\t\t\t<tr>\n\t\t\t\t\t\t<td>Margin-Right: </td>\n\t\t\t\t\t\t<td><input class='e-media-attribute' type='text' id='margin-right' name='margin_right' value='' /></td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t\n\t\t\t\t\t<tr>\n\t\t\t\t\t\t<td>Margin-Top: </td>\n\t\t\t\t\t\t<td><input class='e-media-attribute' type='text' id='margin-top' name='margin_top' value='' /></td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t\n\t\t\t\t\t<tr>\n\t\t\t\t\t\t<td>Margin-Bottom: </td>\n\t\t\t\t\t\t<td><input class='e-media-attribute' type='text' id='margin-bottom' name='margin_bottom' value='' /></td>\n\t\t\t\t\t</tr>\n\t\t\n\t\t\t</tbody></table>\n\t\t\t<table><tr><td>Preview<br /></td></tr>\n\t\t\t<tr><td style='text-align:center'>\n\t\t\t<img id='preview' src='" . e_IMAGE_ABS . "generic/blank.gif' style='border:1px solid silver; min-width:220px; min-height:180px;' />\n\t\t\t\n\t\t\t</td></tr></table>\n\t\t\t</fieldset>"; } $text .= "</div>"; // For BBCODE mode. //TODO image-float. if ($bbcodeMode) { $text .= "<div style='text-align:right;padding:5px'>\n\t\t\t\n\t\t\t<button type='submit' class='btn btn-success submit e-dialog-save e-dialog-close' data-target='" . $this->getQuery('tagid') . "' name='save_image' value='Save it' >\n\t\t\t<span>Save</span>\n\t\t\t</button>\n\t\t\t<button type='submit' class='btn submit e-dialog-close' name='cancel_image' value='Cancel' >\n\t\t\t<span>Cancel</span>\n\t\t\t</button>\n\t\t\t</div>"; // TODO to eventually be hidden. $text .= "bbcode: <input title='bbcode' type='text' readonly='readonly' style='border:0px; width:700px' id='bbcode_holder' name='bbcode_holder' value='' />\n\t\t\t<input title='html' type='hidden' style='width:800px' id='html_holder' name='html_holder' value='' />\n\t\t\t<input title='src' type='hidden' style='width:600px' id='src' name='src' value='' />\n\t\t\t<input title='path' type='hidden' style='width:600px' id='path' name='path' value='' />\t\t\t\t\n\t\t\t"; } return $text; }
/** Download and Import remote images and update body text with local relative-links. eg. {e_MEDIA} * @param returns text-body with remote links replaced with local ones for the images downloaded. */ function saveImages($body, $cat = 'news') { $mes = e107::getMessage(); $med = e107::getMedia(); $tp = e107::getParser(); $search = array(); $replace = array(); $fl = e107::getFile(); $result = $tp->getTags($body, 'img'); if ($result) { $relPath = 'images/' . substr(md5($this->feedUrl), 0, 10); if (!is_dir(e_MEDIA . $relPath)) { mkdir(e_MEDIA . $relPath, '0755'); } foreach ($result['img'] as $att) { $filename = basename($att['src']); if (file_exists(e_MEDIA . $relPath . "/" . $filename)) { continue; } $fl->getRemoteFile($att['src'], $relPath . "/" . $filename, 'media'); if (filesize(e_MEDIA . $relPath . "/" . $filename) > 0) { $search[] = $att['src']; $replace[] = $tp->createConstants(e_MEDIA . $relPath . "/" . $filename, 1); } } } else { $mes->addDebug("No Images Found: " . print_a($result, true)); } if (count($search)) { $mes->addDebug("Found: " . print_a($search, true)); $mes->addDebug("Replaced: " . print_a($replace, true)); $med->import($cat, e_MEDIA . $relPath); } return str_replace($search, $replace, $body); // echo htmlentities($body); preg_match_all("/(((http:\\/\\/www)|(http:\\/\\/)|(www))[-a-zA-Z0-9@:%_\\+.~#?&\\/\\/=]+)\\.(jpg|jpeg|gif|png|svg)/im", $body, $matches); $fl = e107::getFile(); if (is_array($matches[0])) { $relPath = 'images/' . substr(md5($this->feedUrl), 0, 10); if (!is_dir(e_MEDIA . $relPath)) { mkdir(e_MEDIA . $relPath, '0755'); } foreach ($matches[0] as $link) { $filename = basename($link); if (file_exists($relPath . "/" . $filename)) { continue; } $fl->getRemoteFile($link, $relPath . "/" . $filename, 'media'); $search[] = $link; $replace[] = $tp->createConstants(e_MEDIA . $relPath . "/" . $filename, 1); } } if (count($search)) { $med->import($cat, e_MEDIA . $relPath); } return str_replace($search, $replace, $body); }
function liboptions($arr, $prefix = '', $sel = '') { $buf = ""; $array = e107::getMedia()->getCategories(); foreach ($array as $value => $text) { $selected = $value == $_POST['lib'] ? "selected='selected'" : ""; $buf .= "<option value='" . $value . "' {$selected}>" . $text . '</option>' . "\n"; } return $buf; // $buf = ''; // foreach($arr as $lib) // { // $buf .= '<option value="'.$lib['value'].'"'.(($lib['value'] == $sel)?' selected="selected"':'').'>'.$prefix.$lib['text'].'</option>'."\n"; // } // return $buf; }
function processUploadUrl($import = false, $cat = '_common') { $fl = e107::getFile(); $mes = e107::getMessage(); if (vartrue($_POST['upload_remote_url'])) { $fileName = basename($_POST['upload_url']); if (strpos($fileName, '?') !== false) { list($fileName, $bla) = explode("?", $fileName); } // remove script extensions. if (substr($fileName, -4) == ".php" || substr($fileName, -4) == ".htm" || substr($fileName, -5) == ".html" || substr($fileName, -4) == ".asp") { $fileName = empty($_POST['upload_caption']) ? str_replace(array(".php", ".html", ".asp", ".htm"), '', $fileName) . "_" . time() : eHelper::dasherize(strtolower($_POST['upload_caption'])); } if (!$fl->getRemoteFile($_POST['upload_url'], $fileName, 'import')) { $mes->addError("There was a problem grabbing the file"); } elseif ($import == true) { $data = array('media_caption' => e107::getParser()->filter($_POST['upload_caption'], 'str')); $result = e107::getMedia()->importFile($fileName, $cat, null, $data); } } }
while ($buff = fread($in, 4096)) { fwrite($out, $buff); } } else { die('{"jsonrpc" : "2.0", "error" : {"code": 101, "message": "Failed to open input stream."}, "id" : "id"}'); } fclose($in); fclose($out); } else { die('{"jsonrpc" : "2.0", "error" : {"code": 102, "message": "Failed to open output stream."}, "id" : "id"}'); } } // Check if file has been uploaded if (!$chunks || $chunk == $chunks - 1) { // Strip the temp .part suffix off rename("{$filePath}.part", $filePath); } // rename($targetDir.$fileName,e_MEDIA."images/2012-05/",$fileName); if ($_GET['for'] != '') { $result = e107::getMedia()->importFile($fileName, $_GET['for']); } $log = $_GET; $log['filepath'] = $filePath; $log['filename'] = $fileName; $log['status'] = $result ? 'ok' : 'failed'; $type = $result ? E_LOG_INFORMATIVE : E_LOG_WARNING; e107::getLog()->add('Media Upload', print_r($log, true), $type, MEDIA_01); $array = array("jsonrpc" => "2.0", "result" => $result, "id" => "id"); echo json_encode($array); // Return JSON-RPC response // die('{"jsonrpc" : "2.0", "result" : null, "id" : "id"}');
/** * Display a Video file. * @param string $file - format: id.type eg. x123dkax.youtube * @param boolean $thumbnail - set to 'tag' to return an image thumbnail and 'src' to return the src url or 'video' for a small video thumbnail. */ function toVideo($file, $parm = array()) { if (empty($file)) { return false; } list($id, $type) = explode(".", $file, 2); $thumb = vartrue($parm['thumb']); $pref = e107::getPref(); $ytpref = array(); foreach ($pref as $k => $v) { if (substr($k, 0, 8) == 'youtube_') { $key = substr($k, 8); $ytpref[$key] = $v; } } unset($ytpref['bbcode_responsive']); // do not include in embed code. if (!empty($ytpref['cc_load_policy'])) { $ytpref['cc_lang_pref'] = e_LAN; // switch captions with chosen user language. } $ytqry = http_build_query($ytpref); $defClass = deftrue('BOOTSTRAP') ? "embed-responsive embed-responsive-16by9" : "video-responsive"; // levacy backup. if ($type == 'youtube') { // $thumbSrc = "https://i1.ytimg.com/vi/".$id."/0.jpg"; $thumbSrc = "http://i1.ytimg.com/vi/" . $id . "/mqdefault.jpg"; $video = '<iframe class="embed-responsive-item" width="560" height="315" src="//www.youtube.com/embed/' . $id . '?' . $ytqry . '" style="background-size: 100%;background-image: url(' . $thumbSrc . ');border:0px" allowfullscreen></iframe>'; if ($thumb == 'tag') { return "<img class='img-responsive' src='" . $thumbSrc . "' alt='Youtube Video' style='width:" . vartrue($parm['w'], '80') . "px'/>"; } if ($thumb == 'email') { $thumbSrc = "http://i1.ytimg.com/vi/" . $id . "/maxresdefault.jpg"; // 640 x 480 $filename = 'temp/yt-thumb-' . md5($id) . ".jpg"; $filepath = e_MEDIA . $filename; $url = 'http://youtu.be/' . $id; if (!file_exists($filepath)) { e107::getFile()->getRemoteFile($thumbSrc, $filename, 'media'); } return "<a href='" . $url . "'><img class='video-responsive video-thumbnail' src='{e_MEDIA}" . $filename . "' alt='Youtube Video' title='Click to view on Youtube' />\n\t\t\t\t<div class='video-thumbnail-caption'><small>Click to watch video</small></div></a>"; } if ($thumb == 'src') { return $thumbSrc; } if ($thumb == 'video') { return '<div class="' . $defClass . ' video-thumbnail thumbnail">' . $video . '</div>'; } return '<div class="' . $defClass . ' ' . vartrue($parm['class']) . '">' . $video . '</div>'; } if ($type == 'youtubepl') { if ($thumb == 'tag') { $thumbSrc = e107::getMedia()->getThumb($id); if (empty($thumbSrc)) { $thumbSrc = e_IMAGE_ABS . "generic/playlist_120.png"; } return "<img class='img-responsive' src='" . $thumbSrc . "' alt='Youtube Video Playlist' style='width:" . vartrue($parm['w'], '80') . "px'/>"; } if ($thumb == 'src') { $thumb = e107::getMedia()->getThumb($id); if (!empty($thumb)) { return $thumb; } else { // return "https://cdn0.iconfinder.com/data/icons/internet-2-2/64/youtube_playlist_videos_vid_web_online_internet-256.png"; return e_IMAGE_ABS . "generic/playlist_120.png"; } } $video = '<iframe width="560" height="315" src="https://www.youtube.com/embed/videoseries?list=' . $id . '" style="border:0" allowfullscreen></iframe>'; return '<div class="' . $defClass . ' ' . vartrue($parm['class']) . '">' . $video . '</div>'; } if ($type == 'mp4') { return ' <div class="video-responsive"> <video width="320" height="240" controls> <source src="' . $file . '" type="video/mp4"> Your browser does not support the video tag. </video> </div>'; } return false; }
/** * Evaluates the message and returns modifications for inline images and backgrounds * Also creates an alternative plain text part (unless $this->AltBody already non-empty) * Modification of standard PHPMailer function (which it overrides) * @access public * * @param string $message - the mail body to send * @basedir string - optional 'root part' of paths specified in email - prepended as necessary * * @return string none (message saved ready to send) */ public function MsgHTML($message, $basedir = '') { $tp = e107::getParser(); $message = $tp->toEmail($message, false, 'rawtext'); preg_match_all("/(src|background)=([\"\\'])(.*)\\2/Ui", $message, $images); // Modified to accept single quotes as well if (isset($images[3]) && $this->previewMode === false) { if ($this->debug) { echo "<h4>Detected Image Paths</h4>"; print_a($images[3]); } foreach ($images[3] as $i => $url) { // do not change urls for absolute images (thanks to corvuscorax) if (!preg_match('#^[A-z]+://#', $url)) { $url = $tp->replaceConstants($url); // resize on the fly. if ($resized = e107::getMedia()->resizeImage($url, e_TEMP . basename($url), 'w=800')) { $url = $resized; } $delim = $images[2][$i]; // Will be single or double quote $filename = basename($url); $directory = dirname($url); if ($directory == '.') { $directory = ''; } if (strpos($directory, e_HTTP) === 0) { $directory = substr(SERVERBASE, 0, -1) . $directory; // Convert to absolute server reference $basedir = ''; } if ($this->debug) { echo "<br />CID file {$filename} in {$directory}. Base = " . SERVERBASE . "< BaseDir = {$basedir}<br />"; } $cid = 'cid:' . md5($filename); $ext = pathinfo($filename, PATHINFO_EXTENSION); $mimeType = self::_mime_types($ext); if (strlen($basedir) > 1 && substr($basedir, -1) != '/' && substr($basedir, -1) != '\\') { $basedir .= '/'; } if (strlen($directory) > 1 && substr($directory, -1) != '/' && substr($directory, -1) != '\\') { $directory .= '/'; } //echo "Add image: {$basedir}|{$directory}|{$filename}<br />"; if ($this->AddEmbeddedImage($basedir . $directory . $filename, md5($filename), $filename, 'base64', $mimeType)) { // $images[1][$i] contains 'src' or 'background' $message = preg_replace("/" . $images[1][$i] . "=" . $delim . preg_quote($images[3][$i], '/') . $delim . "/Ui", $images[1][$i] . "=" . $delim . $cid . $delim, $message); } else { if ($this->debug) { echo "Add embedded image {$url} failed<br />"; echo "<br />basedir=" . $basedir; echo "<br />dir=" . $directory; echo "<br />file=" . $filename; echo "<br />"; } } } elseif ($this->debug) { echo "<br />Absolute Image: " . $url; } } } if ($this->previewMode === true) { $message = $tp->replaceConstants($message, 'abs'); } $this->IsHTML(true); $this->Body = $message; //print_a($message); $textMsg = str_replace("\n", "", $message); $textMsg = str_replace(array('<br />', '<br>'), "\n", $textMsg); // Modified to make sure newlines carried through $textMsg = preg_replace('#^.*?<body.*?>#', '', $textMsg); // Knock off everything up to and including the body statement (if present) $textMsg = preg_replace('#</body.*?>.*$#', '', $textMsg); // Knock off everything after and including the </body> (if present) $textMsg = trim(strip_tags(preg_replace('/<(head|title|style|script)[^>]*>.*?<\\/\\1>/s', '', $textMsg))); if ($this->debug) { echo "<h2>" . __METHOD__ . ' $textMsg<small> Line: ' . __LINE__ . '</small></h2>'; print_a($textMsg); } if (!empty($textMsg)) { $this->AltBody = html_entity_decode($textMsg); } if (empty($this->AltBody)) { $this->AltBody = 'To view this email message, enable HTML!' . "\n\n"; } }
protected function move2download($upload) { if (!$upload['upload_active']) { return 0; } $media = e107::getMedia(); $uploadPath = e_UPLOAD; if (!file_exists($uploadPath . $upload['upload_file'])) { $this->getModel()->addValidationError(LAN_FILE_NOT_FOUND); return false; } $downloadPath = $media->importFile($upload['upload_file'], 'download_file', $uploadPath . $upload['upload_file'], array('media_caption' => $upload['upload_name'])); if (false === $downloadPath) { $this->getModel()->addValidationError(UPLLAN_66); return false; } $imagePath = null; if ($upload['upload_ss'] && file_exists($uploadPath . $upload['upload_ss'])) { $imagePath = $media->importFile($upload['upload_ss'], '_common_image', $uploadPath . $upload['upload_ss'], array('media_caption' => $upload['upload_name'] . ' ' . LAN_PREVIEW)); } $author = $upload['upload_poster'] ? e107::getSystemUser($upload['upload_poster'])->getRealName() : LAN_ANONYMOUS; $dl = array('download_name' => $upload['upload_name'], 'download_url' => $downloadPath, 'download_sef' => eHelper::title2sef($upload['upload_name']), 'download_author' => $author, 'download_author_email' => $upload['upload_email'], 'download_author_website' => $upload['upload_website'], 'download_description' => $upload['upload_description'], 'download_keywords' => null, 'download_filesize' => $upload['upload_filesize'], 'download_requested' => 0, 'download_category' => $upload['upload_category'], 'download_active' => 1, 'download_datestamp' => $upload['upload_datestamp'], 'download_thumb' => null, 'download_image' => $imagePath, 'download_comment' => 1, 'download_class' => e_UC_MEMBER, 'download_visible' => e_UC_MEMBER, 'download_mirror' => null, 'download_mirror_type' => 0); $sql = e107::getDb('activate'); $id = $sql->insert('download', $dl); if (!$id) { $this->getModel()->addValidationError(UPLLAN_68 . ' #' . $sql->getLastErrorNumber() . ' ' . $sql->getLastErrorText()); e107::getMessage()->addDebug($sql->getLastQuery()); return; } return $id; }
/** * Set Theme as Main Theme. * * @param string $name [optional] name (folder) of the theme to set. * @return boolean TRUE on success, FALSE otherwise */ function setTheme($name = '', $contentCheck = true) { $core = e107::getConfig('core'); $sql = e107::getDb(); $mes = e107::getMessage(); $themeArray = $this->getThemes("id"); $name = $name ? $name : vartrue($themeArray[$this->id]); $layout = $pref['sitetheme_layouts'] = is_array($this->themeArray[$name]['layouts']) ? $this->themeArray[$name]['layouts'] : array(); $deflayout = $this->findDefault($name); $customPages = $this->themeArray[$name]['custompages']; $version = $this->themeArray[$name]['version']; $core->set('sitetheme', $name); $core->set('themecss', 'style.css'); $core->set('sitetheme_layouts', $layout); $core->set('sitetheme_deflayout', $deflayout); $core->set('sitetheme_custompages', $customPages); $core->set('sitetheme_version', $version); if (!empty($this->themeArray[$name]['preferences'])) { $core->set('sitetheme_pref', $this->themeArray[$name]['preferences']); } // $core->set('sitetheme_releaseUrl', $this->themeArray[$name]['releaseUrl']); if ($contentCheck === true) { $sql->db_Delete("menus", "menu_layout !='' "); } e107::getCache()->clear(); if ($core->save()) { //TODO LANs $mes->addDebug("Default Layout: " . $deflayout); $mes->addDebug("Custom Pages: " . print_a($customPages, true)); $med = e107::getMedia(); $med->import('_common_image', e_THEME . $name, "^.*?logo.*?(\\.png|\\.jpeg|\\.jpg|\\.JPG|\\.GIF|\\.PNG)\$"); $med->import('_common_image', e_THEME . $name, '', 'min-size=20000'); if ($contentCheck === true) { $this->installContentCheck($name); } $this->theme_adminlog('01', $name . ', style.css'); return TRUE; } else { // $mes->add(TPVLAN_3." <b>'".$name."'</b>", E_MESSAGE_ERROR); return FALSE; } }
function XmlMediaCategories($function, $tag) { $mes = e107::getMessage(); // print_a($tag); $folder = $tag['folder']; $prevType = ""; //print_a($tag); switch ($function) { case 'install': $c = 1; foreach ($tag['mediaCategories']['category'] as $v) { $type = $v['@attributes']['type']; if (strpos($type, 'image') !== 0 && strpos($type, 'file') !== 0 && strpos($type, 'video') !== 0) { continue; } if ($c == 4 || $prevType == $type) { $mes->addDebug("Only 3 Media Categories are permitted during install. One for images and one for files."); break; } $prevType = $type; $data['owner'] = $folder; $data['image'] = vartrue($v['@attributes']['image']); $data['category'] = $folder . "_" . $type; $data['title'] = $v['@value']; $data['sef'] = vartrue($v['@attributes']['sef']); // $data['type'] = $v['@attributes']['type']; //TODO $data['class'] = $this->getPerm($v['@attributes']['perm'], 'member'); $status = e107::getMedia()->createCategory($data) ? E_MESSAGE_SUCCESS : E_MESSAGE_ERROR; $mes->add("Adding Media Category: {$data['category']}", $status); e107::getMedia()->import($data['category'], e_PLUGIN . $folder, false, 'min-size=20000'); $c++; } break; case 'uninstall': // Probably best to leave well alone $status = e107::getMedia()->deleteAllCategories($folder) ? E_MESSAGE_SUCCESS : E_MESSAGE_ERROR; $mes->add("Deleting All Media Categories owned by : {$folder}", $status); break; } }
/** * Display a Video file. * @param string $file - format: id.type eg. x123dkax.youtube * @param boolean $thumbnail - set to 'tag' to return an image thumbnail and 'src' to return the src url or 'video' for a small video thumbnail. */ function toVideo($file, $parm = array()) { list($id, $type) = explode(".", $file, 2); $thumb = vartrue($parm['thumb']); $pref = e107::getPref(); $ytpref = array(); foreach ($pref as $k => $v) { if (substr($k, 0, 8) == 'youtube_') { $key = substr($k, 8); $ytpref[$key] = $v; } } $ytqry = http_build_query($ytpref); if ($type == 'youtube') { // $thumbSrc = "https://i1.ytimg.com/vi/".$id."/0.jpg"; $thumbSrc = "http://i1.ytimg.com/vi/" . $id . "/mqdefault.jpg"; $video = '<iframe width="560" height="315" src="//www.youtube.com/embed/' . $id . '?' . $ytqry . '" style="background-size: 100%;background-image: url(' . $thumbSrc . ');border:0px" allowfullscreen></iframe>'; if ($thumb == 'tag') { return "<img class='img-responsive' src='" . $thumbSrc . "' alt='Youtube Video' style='width:" . vartrue($parm['w'], '80') . "px'/>"; } if ($thumb == 'email') { $thumbSrc = "http://i1.ytimg.com/vi/" . $id . "/maxresdefault.jpg"; // 640 x 480 $filename = 'temp/yt-thumb-' . md5($id) . ".jpg"; $filepath = e_MEDIA . $filename; $url = 'http://youtu.be/' . $id; if (!file_exists($filepath)) { e107::getFile()->getRemoteFile($thumbSrc, $filename, 'media'); } return "<a href='" . $url . "'><img class='video-responsive video-thumbnail' src='{e_MEDIA}" . $filename . "' alt='Youtube Video' title='Click to view on Youtube' />\n\t\t\t\t<div class='video-thumbnail-caption'><small>Click to watch video</small></div></a>"; } if ($thumb == 'src') { return $thumbSrc; } if ($thumb == 'video') { return '<div class="video-responsive video-thumbnail thumbnail">' . $video . '</div>'; } return '<div class="video-responsive ' . vartrue($parm['class']) . '">' . $video . '</div>'; } if ($type == 'youtubepl') { if ($thumb == 'tag') { $thumbSrc = e107::getMedia()->getThumb($id); return "<img class='img-responsive' src='" . $thumbSrc . "' alt='Youtube Video Playlist' style='width:" . vartrue($parm['w'], '80') . "px'/>"; } if ($thumb == 'src') { return e107::getMedia()->getThumb($id); } $video = '<iframe width="560" height="315" src="https://www.youtube.com/embed/videoseries?list=' . $id . '" style="border:0" allowfullscreen></iframe>'; return '<div class="video-responsive ' . vartrue($parm['class']) . '">' . $video . '</div>'; } if ($type == 'mp4') { return ' <div class="video-responsive"> <video width="320" height="240" controls> <source src="' . $file . '" type="video/mp4"> Your browser does not support the video tag. </video> </div>'; } return false; }
function pluginConfirmUninstall() { global $plugin; $frm = e107::getForm(); $tp = e107::getParser(); $mes = e107::getMessage(); $plug = $plugin->getinfo($this->id); if ($plug['plugin_installflag'] == true) { if ($plugin->parse_plugin($plug['plugin_path'])) { $plug_vars = $plugin->plug_vars; } else { return FALSE; } } else { return FALSE; } $userclasses = ''; $eufields = ''; if (isset($plug_vars['userClasses'])) { if (isset($plug_vars['userclass']['@attributes'])) { $plug_vars['userclass'][0]['@attributes'] = $plug_vars['userclass']['@attributes']; unset($plug_vars['userclass']['@attributes']); } $spacer = ''; foreach ($plug_vars['userClasses']['class'] as $uc) { $userclasses .= $spacer . $uc['@attributes']['name'] . ' - ' . $uc['@attributes']['description']; $spacer = '<br />'; } } if (isset($plug_vars['extendedFields'])) { if (isset($plug_vars['extendedFields']['@attributes'])) { $plug_vars['extendedField'][0]['@attributes'] = $plug_vars['extendedField']['@attributes']; unset($plug_vars['extendedField']['@attributes']); } $spacer = ''; foreach ($plug_vars['extendedFields']['field'] as $eu) { $eufields .= $spacer . 'plugin_' . $plug_vars['folder'] . '_' . $eu['@attributes']['name']; $spacer = '<br />'; } } if (is_writable(e_PLUGIN . $plug['plugin_path'])) { $del_text = $frm->select('delete_files', 'yesno', 0); } else { $del_text = "\n\t\t\t\t" . EPL_ADLAN_53 . "\n\t\t\t\t<input type='hidden' name='delete_files' value='0' />\n\t\t\t\t"; } $text = "\n\t\t\t<form action='" . e_SELF . "?" . e_QUERY . "' method='post'>\n\t\t\t<fieldset id='core-plugin-confirmUninstall'>\n\t\t\t<legend>" . EPL_ADLAN_54 . " " . $tp->toHtml($plug_vars['@attributes']['name'], "", "defs,emotes_off, no_make_clickable") . "</legend>\n <table class='table adminform'>\n \t<colgroup>\n \t\t<col class='col-label' />\n \t\t<col class='col-control' />\n \t</colgroup>\n \t\t\t<tr>\n\t\t\t\t<td>" . EPL_ADLAN_55 . "</td>\n\t\t\t\t<td>" . LAN_YES . "</td>\n\t\t\t</tr>"; $opts = array(); $opts['delete_tables'] = array('label' => EPL_ADLAN_57, 'helpText' => EPL_ADLAN_58, 'itemList' => array(1 => LAN_YES, 0 => LAN_NO), 'itemDefault' => 1); if ($userclasses) { $opts['delete_userclasses'] = array('label' => EPL_ADLAN_78, 'preview' => $userclasses, 'helpText' => EPL_ADLAN_79, 'itemList' => array(1 => LAN_YES, 0 => LAN_NO), 'itemDefault' => 1); } if ($eufields) { $opts['delete_xfields'] = array('label' => EPL_ADLAN_80, 'preview' => $eufields, 'helpText' => EPL_ADLAN_79, 'itemList' => array(1 => LAN_YES, 0 => LAN_NO), 'itemDefault' => 0); } $med = e107::getMedia(); $icons = $med->listIcons(e_PLUGIN . $plug['plugin_path']); if (count($icons) > 0) { foreach ($icons as $key => $val) { $iconText .= "<img src='" . $tp->replaceConstants($val) . "' alt='' />"; } $opts['delete_ipool'] = array('label' => 'Remove icons from Media-Manager', 'preview' => $iconText, 'helpText' => EPL_ADLAN_79, 'itemList' => array(1 => LAN_YES, 0 => LAN_NO), 'itemDefault' => 1); } if (is_readable(e_PLUGIN . $plug['plugin_path'] . "/" . $plug['plugin_path'] . "_setup.php")) { include_once e_PLUGIN . $plug['plugin_path'] . "/" . $plug['plugin_path'] . "_setup.php"; $mes->add("Loading " . e_PLUGIN . $plug['plugin_path'] . "/" . $plug['plugin_path'] . "_setup.php", E_MESSAGE_DEBUG); $class_name = $plug['plugin_path'] . "_setup"; if (class_exists($class_name)) { $obj = new $class_name(); if (method_exists($obj, 'uninstall_options')) { $arr = call_user_func(array($obj, 'uninstall_options'), $this); foreach ($arr as $key => $val) { $newkey = $plug['plugin_path'] . "_" . $key; $opts[$newkey] = $val; } } } } foreach ($opts as $key => $val) { $text .= "<tr>\n<td class='top'>" . $tp->toHTML($val['label'], FALSE, 'TITLE'); $text .= varset($val['preview']) ? "<div class='indent'>" . $val['preview'] . "</div>" : ""; $text .= "</td>\n<td>" . $frm->select($key, $val['itemList'], $val['itemDefault']); $text .= varset($val['helpText']) ? "<div class='field-help'>" . $val['helpText'] . "</div>" : ""; $text .= "</td>\n</tr>\n"; } $text .= "<tr>\n\t\t\t<td>" . EPL_ADLAN_59 . "</td>\n\t\t\t<td>{$del_text}\n\t\t\t<div class='field-help'>" . EPL_ADLAN_60 . "</div>\n\t\t\t</td>\n\t\t\t</tr>\n\t\t\t</table>\n\t\t\t<div class='buttons-bar center'>"; $text .= $frm->admin_button('uninstall_confirm', EPL_ADLAN_3, 'submit'); $text .= $frm->admin_button('uninstall_cancel', EPL_ADLAN_62, 'cancel'); /* $text .= "<input class='btn' type='submit' name='uninstall_confirm' value=\"".EPL_ADLAN_3."\" /> <input class='btn' type='submit' name='uninstall_cancel' value='".EPL_ADLAN_62."' onclick=\"location.href='".e_SELF."'; return false;\"/>"; */ // $frm->admin_button($name, $value, $action = 'submit', $label = '', $options = array()); $text .= "</div>\n\t\t\t</fieldset>\n\t\t\t</form>\n\t\t\t"; e107::getRender()->tablerender(EPL_ADLAN_63 . SEP . $tp->toHtml($plug_vars['@attributes']['name'], "", "defs,emotes_off, no_make_clickable"), $mes->render() . $text); }
public function actionList() { $request = $this->getRequest(); // use only filtered variables $cid = $request->getRequestParam('cat'); if ($cid && !isset($this->catList[$cid])) { // get ID by SEF $_cid = null; foreach ($this->catList as $id => $row) { if ($cid === $row['media_cat_sef']) { $_cid = $id; break; } } $cid = $_cid; } if (empty($cid) || !isset($this->catList[$cid])) { $this->_forward('category'); return; } $tp = e107::getParser(); $template = e107::getTemplate('gallery'); $template = array_change_key_case($template); $sc = e107::getScBatch('gallery', TRUE); if (defset('BOOTSTRAP') === true || defset('BOOTSTRAP') === 2) { $template['list_start'] = str_replace('row', 'row-fluid', $template['list_start']); } $sc->total = e107::getMedia()->countImages($cid); $sc->amount = e107::getPlugPref('gallery', 'perpage', 12); // TODO Add Pref. amount per page. $sc->curCat = $cid; $sc->from = $request->getRequestParam('frm', 0); $list = e107::getMedia()->getImages($cid, $sc->from, $sc->amount); $catname = $tp->toHtml($this->catList[$cid]['media_cat_title'], false, 'defs'); $cat = $this->catList[$cid]; $inner = ""; foreach ($list as $row) { $sc->setVars($row)->addVars($cat); $inner .= $tp->parseTemplate($template['list_item'], TRUE, $sc); } $text = $tp->parseTemplate($template['list_start'], TRUE, $sc); $text .= $inner; $text .= $tp->parseTemplate($template['list_end'], TRUE, $sc); if (isset($template['list_caption'])) { $title = $tp->parseTemplate($template['list_caption'], TRUE, $sc); $this->addTitle($title)->addBody($text); } else { $this->addTitle($catname)->addTitle(LAN_PLUGIN_GALLERY_TITLE)->addBody($text); } }
function update_706_to_800($type = '') { global $pref, $e107info; global $sysprefs, $eArrayStorage; //$mes = new messageLog; // Combined logging and message displaying handler //$mes = e107::getMessage(); $log = e107::getAdminLog(); // Used for combined logging and message displaying $sql = e107::getDb(); $sql2 = e107::getDb('sql2'); $tp = e107::getParser(); $ns = e107::getRender(); e107::getCache()->clearAll('db'); e107::getCache()->clearAll('system'); // List of unwanted $pref values which can go $obs_prefs = array('frontpage_type', 'rss_feeds', 'log_lvcount', 'zone', 'upload_allowedfiletype', 'real', 'forum_user_customtitle', 'utf-compatmode', 'frontpage_method', 'standards_mode', 'image_owner', 'im_quality', 'signup_option_timezone', 'modules', 'plug_sc', 'plug_bb', 'plug_status', 'plug_latest', 'subnews_hide_news', 'upload_storagetype'); // List of DB tables not required (includes a few from 0.6xx) $obs_tables = array('flood', 'headlines', 'stat_info', 'stat_counter', 'stat_last', 'session', 'preset', 'tinymce'); // List of DB tables newly required (defined in core_sql.php) (The existing dblog table gets renamed) // No Longer required. - automatically checked against core_sql.php. // $new_tables = array('audit_log', 'dblog', 'news_rewrite', 'core_media', 'core_media_cat','cron', 'mail_recipients', 'mail_content'); // List of core prefs that need to be converted from serialized to e107ArrayStorage. $serialized_prefs = array("'emote'", "'menu_pref'", "'search_prefs'", "'emote_default'", "'pm_prefs'"); $create_dir = array(e_MEDIA, e_SYSTEM, e_CACHE, e_CACHE_CONTENT, e_CACHE_IMAGE, e_CACHE_DB, e_LOG, e_BACKUP, e_CACHE_URL, e_TEMP, e_IMPORT); foreach ($create_dir as $dr) { if (!is_dir($dr)) { mkdir($dr, 0755); } } // List of changed DB tables (defined in core_sql.php) // No Longer required. - automatically checked against core_sql.php. // (primarily those which have changed significantly; for the odd field write some explicit code - it'll run faster) // $changed_tables = array('user', 'dblog', 'admin_log', 'userclass_classes', 'banlist', 'menus', // 'plugin', 'news', 'news_category', 'online', 'page', 'links', 'comments'); // List of changed DB tables from core plugins (defined in pluginname_sql.php file) // key = plugin directory name. Data = comma-separated list of tables to check // (primarily those which have changed significantly; for the odd field write some explicit code - it'll run faster) // No Longer required. - automatically checked by db-verify /* $pluginChangedTables = array('linkwords' => 'linkwords', 'featurebox' => 'featurebox', 'links_page' => 'links_page', 'poll' => 'polls', 'content' => 'pcontent' ); */ /* $setCorePrefs = array( //modified prefs during upgrade. 'adminstyle' => 'infopanel', 'admintheme' => 'bootstrap', 'admincss' => 'admin_style.css', 'resize_dimensions' => array( 'news-image' => array('w' => 250, 'h' => 250), 'news-bbcode' => array('w' => 250, 'h' => 250), 'page-bbcode' => array('w' => 250, 'h' => 250) ) ); */ $do_save = TRUE; // List of changed menu locations. $changeMenuPaths = array(array('oldpath' => 'siteinfo_menu', 'newpath' => 'siteinfo', 'menu' => 'sitebutton_menu'), array('oldpath' => 'siteinfo_menu', 'newpath' => 'siteinfo', 'menu' => 'compliance_menu'), array('oldpath' => 'siteinfo_menu', 'newpath' => 'siteinfo', 'menu' => 'powered_by_menu'), array('oldpath' => 'siteinfo_menu', 'newpath' => 'siteinfo', 'menu' => 'sitebutton_menu'), array('oldpath' => 'siteinfo_menu', 'newpath' => 'siteinfo', 'menu' => 'counter_menu'), array('oldpath' => 'siteinfo_menu', 'newpath' => 'siteinfo', 'menu' => 'latestnews_menu'), array('oldpath' => 'compliance_menu', 'newpath' => 'siteinfo', 'menu' => 'compliance_menu'), array('oldpath' => 'powered_by_menu', 'newpath' => 'siteinfo', 'menu' => 'powered_by_menu'), array('oldpath' => 'sitebutton_menu', 'newpath' => 'siteinfo', 'menu' => 'sitebutton_menu'), array('oldpath' => 'counter_menu', 'newpath' => 'siteinfo', 'menu' => 'counter_menu'), array('oldpath' => 'usertheme_menu', 'newpath' => 'user', 'menu' => 'usertheme_menu'), array('oldpath' => 'userlanguage_menu', 'newpath' => 'user', 'menu' => 'userlanguage_menu'), array('oldpath' => 'lastseen_menu', 'newpath' => 'online', 'menu' => 'lastseen_menu'), array('oldpath' => 'other_news_menu', 'newpath' => 'news', 'menu' => 'other_news_menu'), array('oldpath' => 'other_news_menu', 'newpath' => 'news', 'menu' => 'other_news2_menu'), array('oldpath' => 'user_menu', 'newpath' => 'user', 'menu' => 'usertheme_menu'), array('oldpath' => 'user_menu', 'newpath' => 'user', 'menu' => 'userlanguage_menu'), array('oldpath' => 'poll_menu', 'newpath' => 'poll', 'menu' => 'poll_menu'), array('oldpath' => 'banner_menu', 'newpath' => 'banner', 'menu' => 'banner_menu'), array('oldpath' => 'online_menu', 'newpath' => 'online', 'menu' => 'online_menu')); // List of DB tables (key) and field (value) which need changing to accommodate IPV6 addresses $ip_upgrade = array('download_requests' => 'download_request_ip', 'submitnews' => 'submitnews_ip', 'tmp' => 'tmp_ip', 'chatbox' => 'cb_ip'); $db_parser = new db_table_admin(); // Class to read table defs and process them $do_save = FALSE; // Set TRUE to update prefs when update complete $updateMessages = array(); // Used to log actions for the admin log - TODO: will go once all converted to new class $just_check = $type == 'do' ? FALSE : TRUE; // TRUE if we're just seeing whether an update is needed // if (!$just_check) // { // foreach(vartrue($setCorePrefs) as $k=>$v) // { // $pref[$k] = $v; // } // } if (!$just_check) { $log->logMessage(LAN_UPDATE_14 . $e107info['e107_version'], E_MESSAGE_NODISPLAY); } $statusTexts = array(E_MESSAGE_SUCCESS => 'Success', E_MESSAGE_ERROR => 'Fail', E_MESSAGE_INFO => 'Info'); if (isset($pref['forum_user_customtitle']) && !isset($pref['signup_option_customtitle'])) { if ($just_check) { return update_needed('pref: forum_user_customtitle needs to be renamed'); } $pref['signup_option_customtitle'] = $pref['forum_user_customtitle']; unset($pref['forum_user_customtitle']); $log->logMessage(LAN_UPDATE_20 . 'customtitle', E_MESSAGE_SUCCESS); $do_save = TRUE; } // convert all serialized core prefs to e107 ArrayStorage; $serialz_qry = "SUBSTRING( e107_value,1,5)!='array' AND e107_value !='' "; $serialz_qry .= "AND e107_name IN (" . implode(",", $serialized_prefs) . ") "; if (e107::getDb()->select("core", "*", $serialz_qry)) { if ($just_check) { return update_needed('Convert serialized core prefs'); } while ($row = e107::getDb()->fetch(MYSQL_ASSOC)) { $status = e107::getDb('sql2')->update('core', "e107_value=\"" . convert_serialized($row['e107_value']) . "\" WHERE e107_name='" . $row['e107_name'] . "'") ? E_MESSAGE_SUCCESS : E_MESSAGE_ERROR; $log->addDebug(LAN_UPDATE_22 . $row['e107_name'] . ": " . $status); } } if (e107::getDb()->select("core", "*", "e107_name='pm_prefs' LIMIT 1")) { if ($just_check) { return update_needed('Rename the pm prefs'); } e107::getDb()->update("core", "e107_name='plugin_pm' WHERE e107_name = 'pm_prefs'"); } //@TODO de-serialize the user_prefs also. // Banlist if (!$sql->field('banlist', 'banlist_id')) { if ($just_check) { return update_needed('Banlist table requires updating.'); } $sql->gen("ALTER TABLE #banlist DROP PRIMARY KEY"); $sql->gen("ALTER TABLE `#banlist` ADD `banlist_id` INT( 11 ) unsigned NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST"); } // Move the maximum online counts from menu prefs to a separate pref - 'history' e107::getCache()->clearAll('system'); $menuConfig = e107::getConfig('menu', true, true); if ($menuConfig->get('most_members_online') || $menuConfig->get('most_guests_online') || $menuConfig->get('most_online_datestamp')) { $status = E_MESSAGE_DEBUG; if ($just_check) { return update_needed('Move online counts from menupref'); } $newPrefs = e107::getConfig('history'); foreach (array('most_members_online', 'most_guests_online', 'most_online_datestamp') as $v) { if (FALSE === $newPrefs->get($v, FALSE)) { if (FALSE !== $menuConfig->get($v, FALSE)) { $newPrefs->set($v, $menuConfig->get($v)); } else { $newPrefs->set($v, 0); } } $menuConfig->remove($v); } $result = $newPrefs->save(false, true, false); if ($result === TRUE) { $resultMessage = 'Historic member counts updated'; $result = $menuConfig->save(false, true, false); // Only re-save if successul. } elseif ($result === FALSE) { $resultMessage = 'moving historic member counts'; $status = E_MESSAGE_ERROR; } else { // No change $resultMessage = 'Historic member counts already updated'; $status = E_MESSAGE_INFO; } // $result = $menuConfig->save(false, true, false); // Save updated menuprefs - without the counts - don't delete them if it fails. //$updateMessages[] = $statusTexts[$status].': '.$resultMessage; // Admin log message $log->logMessage($resultMessage, $status); // User message } // ++++++++ Modify Menu Paths +++++++. if (varset($changeMenuPaths)) { foreach ($changeMenuPaths as $val) { $qry = "SELECT menu_path FROM `#menus` WHERE menu_name = '" . $val['menu'] . "' AND (menu_path='" . $val['oldpath'] . "' || menu_path='" . $val['oldpath'] . "/' ) LIMIT 1"; if ($sql->gen($qry)) { if ($just_check) { return update_needed('Menu path changed required: ' . $val['menu'] . ' '); } $updqry = "menu_path='" . $val['newpath'] . "/' WHERE menu_name = '" . $val['menu'] . "' AND (menu_path='" . $val['oldpath'] . "' || menu_path='" . $val['oldpath'] . "/' ) "; $status = $sql->update('menus', $updqry) ? E_MESSAGE_DEBUG : E_MESSAGE_ERROR; $log->logMessage(LAN_UPDATE_23 . '<b>' . $val['menu'] . '</b> : ' . $val['oldpath'] . ' => ' . $val['newpath'], $status); // LAN_UPDATE_25; // catch_error($sql); } } } // Leave this one here.. just in case.. //delete record for online_extended_menu (now only using one online menu) if ($sql->db_Select('menus', '*', "menu_path='online_extended_menu' || menu_path='online_extended_menu/'")) { if ($just_check) { return update_needed("The Menu table needs to have some paths corrected in its data."); } $row = $sql->db_Fetch(); //if online_extended is activated, we need to activate the new 'online' menu, and delete this record if ($row['menu_location'] != 0) { $status = $sql->update('menus', "menu_name='online_menu', menu_path='online/' WHERE menu_path='online_extended_menu' || menu_path='online_extended_menu/' ") ? E_MESSAGE_DEBUG : E_MESSAGE_ERROR; $log->logMessage(LAN_UPDATE_23 . "<b>online_menu</b> : online/", $status); } else { //else if the menu is not active //we need to delete the online_extended menu row, and change the online_menu to online $sql->delete('menus', " menu_path='online_extended_menu' || menu_path='online_extended_menu/' "); $log->logMessage(LAN_UPDATE_31, E_MESSAGE_DEBUG); } catch_error($sql); } //change menu_path for online_menu (if it still exists) if ($sql->db_Select('menus', 'menu_path', "menu_path='online_menu' || menu_path='online_menu/'")) { if ($just_check) { return update_needed('change menu_path for online menu'); } $status = $sql->update('menus', "menu_path='online/' WHERE menu_path='online_menu' || menu_path='online_menu/' ") ? E_MESSAGE_DEBUG : E_MESSAGE_ERROR; $log->logMessage(LAN_UPDATE_23 . "<b>online_menu</b> : online/", $status); catch_error($sql); } if (!$just_check) { // Alert Admin to delete deprecated menu folders. $chgPath = array(); foreach ($changeMenuPaths as $cgpArray) { if (is_dir(e_PLUGIN . $cgpArray['oldpath'])) { if (!in_array($cgpArray['oldpath'], $chgPath)) { $chgPath[] = $cgpArray['oldpath']; } } } if (count($chgPath)) { $log->addWarning(LAN_UPDATE_57 . ' '); array_unique($chgPath); asort($chgPath); foreach ($chgPath as $cgp) { $log->addWarning(e_PLUGIN_ABS . "<b>" . $cgp . "</b>"); } } } //--------------------------------------------------------- // Comments - split user field //--------------------------------------------------------- if ($sql->db_Field('comments', 'comment_author')) { if ($just_check) { return update_needed('Comment table author field update'); } if (!$sql->db_Field('comments', 'comment_author_id') && !$sql->gen("ALTER TABLE `#comments`\r\n\t\t\t\tADD COLUMN comment_author_id int(10) unsigned NOT NULL default '0' AFTER `comment_author`,\r\n\t\t\t\tADD COLUMN comment_author_name varchar(100) NOT NULL default '' AFTER `comment_author_id`")) { // Flag error // $commentMessage = LAN_UPDAXXTE_34; $log->logMessage(LAN_UPDATE_21 . "comments", E_MESSAGE_ERROR); } else { if (FALSE === $sql->update('comments', "comment_author_id=SUBSTRING_INDEX(`comment_author`,'.',1), comment_author_name=SUBSTRING(`comment_author` FROM POSITION('.' IN `comment_author`)+1)")) { // Flag error $log->logMessage(LAN_UPDATE_21 . 'comments', E_MESSAGE_ERROR); } else { // Delete superceded field - comment_author if (!$sql->gen("ALTER TABLE `#comments` DROP COLUMN `comment_author`")) { // Flag error $log->logMessage(LAN_UPDATE_24 . 'comments - comment_author', E_MESSAGE_ERROR); } } } $log->logMessage(LAN_UPDATE_21 . 'comments', E_MESSAGE_DEBUG); } // Add index to download history // Deprecated by db-verify-class // if (FALSE !== ($temp = addIndexToTable('download_requests', 'download_request_datestamp', $just_check, $updateMessages))) // { // if ($just_check) // { // return update_needed($temp); // } // } // Extra index to tmp table // Deprecated by db-verify-class // if (FALSE !== ($temp = addIndexToTable('tmp', 'tmp_time', $just_check, $updateMessages))) // { // if ($just_check) // { // return update_needed($temp); // } // } // Extra index to rss table (if used) // Deprecated by db-verify-class // if (FALSE !== ($temp = addIndexToTable('rss', 'rss_name', $just_check, $updateMessages, TRUE))) // { // if ($just_check) // { // return update_needed($temp); // } // } // Front page prefs (logic has changed) if (!isset($pref['frontpage_force'])) { if ($just_check) { return update_needed('Change front page prefs'); } $pref['frontpage_force'] = array(e_UC_PUBLIC => ''); $fpdef = vartrue($pref['frontpage']['all']) == 'index.php' ? 'index.php' : 'news.php'; $pref['frontpage'] = array(e_UC_PUBLIC => $fpdef); // $_pdateMessages[] = LAN_UPDATE_38; //FIXME $log->logMessage(LAN_UPDATE_20 . "frontpage", E_MESSAGE_DEBUG); $do_save = TRUE; } // Check need for user timezone before we delete the field if (vartrue($pref['signup_option_timezone'])) { if ($sql->db_Field('user', 'user_timezone', '', TRUE) && !$sql->db_Field('user_extended', 'user_timezone', '', TRUE)) { if ($just_check) { return update_needed('Move user timezone info'); } if (!copy_user_timezone()) { // Error doing the transfer //$updateMessages[] = LAN_UPDATE_42; $log->logMessage(LAN_UPDATE_42, E_MESSAGE_ERROR); return FALSE; } //$updateMessages[] = LAN_UPDATE_41; $log->logMessage(LAN_UPDATE_41, E_MESSAGE_DEBUG); } } // Tables defined in core_sql.php to be RENAMED. // Next bit will be needed only by the brave souls who used an early CVS - probably delete before release if ($sql->isTable('rl_history') && !$sql->isTable('dblog')) { if ($just_check) { return update_needed('Rename rl_history to dblog'); } $sql->gen('ALTER TABLE `' . MPREFIX . 'rl_history` RENAME `' . MPREFIX . 'dblog`'); //$updateMessages[] = LAN_UPDATE_44; $log->logMessage(LAN_UPDATE_44, E_MESSAGE_DEBUG); catch_error($sql); } //--------------------------------- if ($sql->isTable('dblog') && !$sql->isTable('admin_log')) { if ($just_check) { return update_needed('Rename dblog to admin_log'); } $sql->gen('ALTER TABLE `' . MPREFIX . 'dblog` RENAME `' . MPREFIX . 'admin_log`'); catch_error($sql); //$updateMessages[] = LAN_UPDATE_43; $log->logMessage(LAN_UPDATE_43, E_MESSAGE_DEBUG); } // New tables required (list at top. Definitions in core_sql.php) // ALL DEPRECATED by db_verify class.. see below. /* foreach ($new_tables as $nt) { if (!$sql->isTable($nt)) { if ($just_check) return update_needed('Add table: '.$nt); // Get the definition $defs = $db_parser->get_table_def($nt,e_ADMIN.'sql/core_sql.php'); if (count($defs)) // **** Add in table here { $status = $sql->gen('CREATE TABLE `'.MPREFIX.$defs[0][1].'` ('.$defs[0][2].') TYPE='.$defs[0][3]) ? E_MESSAGE_SUCCESS : E_MESSAGE_ERROR; // $updateMessages[] = LAN_UPDATE_45.$defs[0][1]; $log->logMessage(LAN_UPDATE_27.$defs[0][1], $status); // catch_error($sql); } else { // error parsing defs file $log->logMessage(LAN_UPDATE_46.$defs[0][1], E_MESSAGE_ERROR); } unset($defs); } } // Tables whose definition needs changing significantly $debugLevel = E107_DBG_SQLDETAILS; foreach ($changed_tables as $ct) { $req_defs = $db_parser->get_table_def($ct,e_ADMIN."sql/core_sql.php"); $req_fields = $db_parser->parse_field_defs($req_defs[0][2]); // Required definitions if ($debugLevel) { $log->logMessage("Required table structure: <br />".$db_parser->make_field_list($req_fields), E_MESSAGE_DEBUG); } if ((($actual_defs = $db_parser->get_current_table($ct)) === FALSE) || !is_array($actual_defs)) // Adds current default prefix { $log->logMessage("Couldn't get table structure: ".$ct, E_MESSAGE_DEBUG); } else { // echo $db_parser->make_table_list($actual_defs); $actual_fields = $db_parser->parse_field_defs($actual_defs[0][2]); if ($debugLevel) { $log->logMessage("Actual table structure: <br />".$db_parser->make_field_list($actual_fields), E_MESSAGE_DEBUG); } $diffs = $db_parser->compare_field_lists($req_fields,$actual_fields); if (count($diffs[0])) { // Changes needed if ($just_check) return update_needed("Field changes rqd; table: ".$ct); // Do the changes here if ($debugLevel) { $log->logMessage("List of changes found:<br />".$db_parser->make_changes_list($diffs), E_MESSAGE_DEBUG); } $qry = 'ALTER TABLE '.MPREFIX.$ct.' '.implode(', ',$diffs[1]); if ($debugLevel) { $log->logMessage("Update Query used: ".$qry, E_MESSAGE_DEBUG); } $status = $sql->gen($qry) ? E_MESSAGE_SUCCESS : E_MESSAGE_ERROR; $log->logMessage(LAN_UPDATE_21.$ct, $status); catch_error($sql); } } } // Plugin tables whose definition needs changing significantly foreach ($pluginChangedTables as $plugName => $plugList) { if (e107::isInstalled($plugName)) { $ttc = explode(',',$plugList); foreach ($ttc as $ct) { $sqlDefs = e_PLUGIN.$plugName.'/'.str_replace('_menu','',$plugName).'_sql.php'; // Filename containing definitions // echo "Looking at file: {$sqlDefs}, table {$ct}<br />"; $req_defs = $db_parser->get_table_def($ct,$sqlDefs); if (!is_array($req_defs)) { echo "Couldn't get definitions from file {$sqlDefs}<br />"; continue; } $req_fields = $db_parser->parse_field_defs($req_defs[0][2]); // Required definitions if (E107_DBG_SQLDETAILS) { $message = "Required plugin table structure: <br />".$db_parser->make_field_list($req_fields); $log->logMessage($message, E_MESSAGE_DEBUG); } if ((($actual_defs = $db_parser->get_current_table($ct)) === FALSE) || !is_array($actual_defs)) // Adds current default prefix { // echo "Couldn't get table structure: {$ct}<br />"; } else { // echo $db_parser->make_table_list($actual_defs); $actual_fields = $db_parser->parse_field_defs($actual_defs[0][2]); if (E107_DBG_SQLDETAILS) { $message= "Actual table structure: <br />".$db_parser->make_field_list($actual_fields); $log->logMessage($message, E_MESSAGE_DEBUG); } $diffs = $db_parser->compare_field_lists($req_fields,$actual_fields); if (count($diffs[0])) { // Changes needed if (E107_DBG_SQLDETAILS) { $message = "List of changes found:<br />".$db_parser->make_changes_list($diffs); $log->logMessage($message, E_MESSAGE_DEBUG); } if ($just_check) return update_needed("Field changes rqd; plugin table: ".$ct); // Do the changes here $qry = 'ALTER TABLE '.MPREFIX.$ct.' '.implode(', ',$diffs[1]); if (E107_DBG_SQLDETAILS) { $message = "Update Query used: ".$qry."<br />"; $log->logMessage($message, E_MESSAGE_DEBUG); } $sql->gen($qry); $updateMessages[] = LAN_UPDATE_51.$ct; $log->logMessage(LAN_UPDATE_51.$ct, E_MESSAGE_SUCCESS); catch_error($sql); } } } } } */ // Obsolete tables (list at top) $sql->mySQLtableList = false; // clear the cached table list. foreach ($obs_tables as $ot) { if ($sql->isTable($ot)) { if ($just_check) { return update_needed("Delete table: " . $ot); } $status = $sql->gen('DROP TABLE `' . MPREFIX . $ot . '`') ? E_MESSAGE_DEBUG : E_MESSAGE_ERROR; $log->logMessage(LAN_UPDATE_25 . $ot, $status); } } // Tables where IP address field needs updating to accommodate IPV6 // Set to varchar(45) - just in case something uses the IPV4 subnet (see http://en.wikipedia.org/wiki/IPV6#Notation) foreach ($ip_upgrade as $t => $f) { if ($sql->isTable($t)) { // Check for table - might add some core plugin tables in here if ($field_info = $sql->db_Field($t, $f, '', TRUE)) { if (strtolower($field_info['Type']) != 'varchar(45)') { if ($just_check) { return update_needed('Update IP address field ' . $f . ' in table ' . $t); } $status = $sql->gen("ALTER TABLE `" . MPREFIX . $t . "` MODIFY `{$f}` VARCHAR(45) NOT NULL DEFAULT '';") ? E_MESSAGE_DEBUG : E_MESSAGE_ERROR; $log->logMessage(LAN_UPDATE_26 . $t . ' - ' . $f, $status); // catch_error($sql); } } else { // Got a strange error here } } } // Obsolete prefs (list at top) // Intentionally do this last - we may check some of them during the update $accum = array(); foreach ($obs_prefs as $p) { if (isset($pref[$p])) { if ($just_check) { return update_needed('Remove obsolete prefs'); } unset($pref[$p]); $do_save = TRUE; $log->addDebug('Removed obsolete pref: ' . $p); // $accum[] = $p; } } /* -------------- Upgrade Entire Table Structure - Multi-Language Supported ----------------- */ // ONLY ever add fields, never deletes. require_once e_HANDLER . "db_verify_class.php"; $dbv = new db_verify(); if ($plugUpgradeReq = e107::getPlugin()->updateRequired()) { $exclude = array_keys($plugUpgradeReq); // search xxxxx_setup.php and check for 'upgrade_required()' == true. asort($exclude); } else { $exclude = false; } $dbv->compareAll($exclude); // core & plugins, but not plugins calling for an update with xxxxx_setup.php if (count($dbv->errors)) { if ($just_check) { $mes = e107::getMessage(); $log->addDebug(print_a($dbv->errors, true)); return update_needed("Database Tables require updating."); } $dbv->compileResults(); $dbv->runFix(); // Fix entire core database structure and plugins too. } // print_a($dbv->results); // print_a($dbv->fixList); //TODO - send notification messages to Log. if ($sql->field('page', 'page_theme') && $sql->gen("SELECT * FROM `#page` WHERE page_theme != '' AND menu_title = '' LIMIT 1")) { if ($just_check) { return update_needed("Pages/Menus Table requires updating."); } if ($sql->update('page', "menu_name = page_theme, menu_title = page_title, menu_text = page_text, menu_template='default', page_title = '', page_text = '' WHERE page_theme !='' AND menu_title = '' AND menu_text = '' ")) { $sql->gen("ALTER TABLE `#page` DROP page_theme "); $mes = e107::getMessage(); $log->addDebug("Successfully updated pages/menus table to new format. "); } } if ($sql->field('plugin', 'plugin_releaseUrl')) { if ($just_check) { return update_needed('plugin_releaseUrl is deprecated and needs to be removed. '); } if ($sql->gen("ALTER TABLE `#plugin` DROP `plugin_releaseUrl`")) { $log->addDebug("Successfully removed plugin_releaseUrl. "); } } // --- Notify Prefs // $notify_prefs = $sysprefs -> get('notify_prefs'); // $notify_prefs = $eArrayStorage -> ReadArray($notify_prefs); e107::getCache()->clearAll('system'); $notify_prefs = e107::getConfig('notify', true, true)->getPref(); $nt_changed = 0; if (vartrue($notify_prefs['event'])) { foreach ($notify_prefs['event'] as $e => $d) { if (isset($d['type'])) { if ($just_check) { return update_needed('Notify pref: ' . $e . ' outdated'); } switch ($d['type']) { case 'main': $notify_prefs['event'][$e]['class'] = e_UC_MAINADMIN; break; case 'class': // Should already have class defined break; case 'email': $notify_prefs['event'][$e]['class'] = 'email'; break; case 'off': // Need to disable // Need to disable default: $notify_prefs['event'][$e]['class'] = e_UC_NOBODY; // Just disable if we don't know what else to do } $nt_changed++; $notify_prefs['event'][$e]['legacy'] = 1; unset($notify_prefs['event'][$e]['type']); } } } if ($nt_changed) { $s_prefs = $tp->toDB($notify_prefs); $s_prefs = $eArrayStorage->WriteArray($s_prefs); // Could we use $sysprefs->set($s_prefs,'notify_prefs') instead - avoids caching problems ???? $status = $sql->update("core", "e107_value='" . $s_prefs . "' WHERE e107_name='notify_prefs'") !== FALSE ? E_MESSAGE_DEBUG : E_MESSAGE_ERROR; $message = str_replace('--COUNT--', $nt_changed, LAN_UPDATE_20); $log->logMessage($message, $status); } // --------------- Saved emails - copy across if (!$just_check && $sql->db_Select('generic', '*', "gen_type='massmail'")) { if ($just_check) { return update_needed('Copy across saved emails'); } require_once e_HANDLER . 'mail_manager_class.php'; $mailHandler = new e107MailManager(); $i = 0; while ($row = $sql->db_Fetch(MYSQL_ASSOC)) { $mailRecord = array('mail_create_date' => $row['gen_datestamp'], 'mail_creator' => $row['gen_user_id'], 'mail_title' => $row['gen_ip'], 'mail_subject' => $row['gen_ip'], 'mail_body' => $row['gen_chardata'], 'mail_content_status' => MAIL_STATUS_SAVED); $mailHandler->mailtoDb($mailRecord, TRUE); $mailHandler->saveEmail($mailRecord, TRUE); $sql2->delete('generic', 'gen_id=' . intval($row['gen_id'])); // Delete as we go in case operation fails part way through $i++; } unset($mailHandler); $log->logMessage(str_replace('--COUNT--', $i, LAN_UPDATE_28)); } // ------------------- Populate Plugin Table With Changes ------------------ if (!isset($pref['shortcode_legacy_list'])) { if ($just_check) { return update_needed('Legacy shortcode conversion'); } // Reset, legacy and new shortcode list will be generated in plugin update routine $pref['shortcode_legacy_list'] = array(); $pref['shortcode_list'] = array(); save_prefs(); $ep = e107::getPlugin(); $ep->update_plugins_table($mode); // scan for e_xxx changes and save to plugin table. $ep->save_addon_prefs($mode); // generate global e_xxx_list prefs from plugin table. } // This has to be done after the table is upgraded if ($sql->select('plugin', 'plugin_category', "plugin_category = ''")) { if ($just_check) { return update_needed('Update plugin table'); } require_once e_HANDLER . 'plugin_class.php'; $ep = new e107plugin(); $ep->update_plugins_table('update'); // $_pdateMessages[] = LAN_UPDATE_XX24; // catch_error($sql); } //-- Media-manger import -------------------------------------------------- // Autogenerate filetypes.xml if not found. if (!is_readable(e_SYSTEM . "filetypes.xml")) { $data = '<?xml version="1.0" encoding="utf-8"?> <e107Filetypes> <class name="253" type="zip,gz,jpg,jpeg,png,gif,xml" maxupload="2M" /> </e107Filetypes>'; file_put_contents(e_SYSTEM . "filetypes.xml", $data); } $root_media = str_replace(basename(e_MEDIA) . "/", "", e_MEDIA); $user_media_dirs = array("images", "avatars", "avatars/default", "avatars/upload", "files", "temp", "videos", "icons"); // check for old paths and rename. if (is_dir($root_media . "images") || is_dir($root_media . "temp")) { foreach ($user_media_dirs as $md) { @rename($root_media . $md, e_MEDIA . $md); } } // create sub-directories if they do not exist. if (!is_dir(e_MEDIA . "images") || !is_dir(e_MEDIA . "temp") || !is_dir(e_AVATAR_UPLOAD) || !is_dir(e_AVATAR_DEFAULT)) { foreach ($user_media_dirs as $md) { if (!is_dir(e_MEDIA . $md)) { mkdir(e_MEDIA . $md); } } } // Move Avatars to new location $av1 = e107::getFile()->get_files(e_FILE . 'public/avatars', '.jpg|.gif|.png|.GIF|.jpeg|.JPG|.PNG'); $av2 = e107::getFile()->get_files(e_IMAGE . 'avatars', '.jpg|.gif|.png|.GIF|.jpeg|.JPG|.PNG'); $avatar_images = array_merge($av1, $av2); if (count($avatar_images)) { if ($just_check) { return update_needed('Avatar paths require updating.'); } foreach ($avatar_images as $av) { $apath = strstr($av['path'], 'public/') ? e_AVATAR_UPLOAD : e_AVATAR_DEFAULT; @rename($av['path'] . $av['fname'], $apath . $av['fname']); } } // ------------------------------- if (!e107::isInstalled('download') && $sql->gen("SELECT * FROM #links WHERE link_url LIKE 'download.php%' AND link_class != '" . e_UC_NOBODY . "' LIMIT 1")) { if ($just_check) { return update_needed('Download Plugin needs to be installed.'); } // e107::getSingleton('e107plugin')->install('download',array('nolinks'=>true)); e107::getSingleton('e107plugin')->refresh('download'); } if (!e107::isInstalled('banner') && $sql->isTable('banner')) { if ($just_check) { return update_needed('Banner Table found, but plugin not installed. Needs to be refreshed.'); } e107::getSingleton('e107plugin')->refresh('banner'); } // --------------------------------- $med = e107::getMedia(); // Media Category Update if ($sql->db_Field("core_media_cat", "media_cat_nick")) { $count = $sql->gen("SELECT * FROM `#core_media_cat` WHERE media_cat_nick = '_common' "); if ($count == 1) { if ($just_check) { return update_needed('Media-Manager Categories needs to be updated.'); } $sql->update('core_media_cat', "media_cat_owner = media_cat_nick, media_cat_category = media_cat_nick WHERE media_cat_nick REGEXP '_common|news|page|_icon_16|_icon_32|_icon_48|_icon_64' "); $sql->update('core_media_cat', "media_cat_owner = '_icon', media_cat_category = media_cat_nick WHERE media_cat_nick REGEXP '_icon_16|_icon_32|_icon_48|_icon_64' "); $sql->update('core_media_cat', "media_cat_owner = 'download', media_cat_category='download_image' WHERE media_cat_nick = 'download' "); $sql->update('core_media_cat', "media_cat_owner = 'download', media_cat_category='download_thumb' WHERE media_cat_nick = 'downloadthumb' "); $sql->update('core_media_cat', "media_cat_owner = 'news', media_cat_category='news_thumb' WHERE media_cat_nick = 'newsthumb' "); $log->addDebug("core-media-cat Categories and Ownership updated"); if ($sql->gen("ALTER TABLE `" . MPREFIX . "core_media_cat` DROP `media_cat_nick`")) { $log->addDebug("core-media-cat `media_cat_nick` field removed."); } // $query = "INSERT INTO `".MPREFIX."core_media_cat` (`media_cat_id`, `media_cat_owner`, `media_cat_category`, `media_cat_title`, `media_cat_diz`, `media_cat_class`, `media_cat_image`, `media_cat_order`) VALUES // (0, 'gallery', 'gallery_1', 'Gallery 1', 'Visible to the public at /gallery.php', 0, '', 0); /// "; // // if(mysql_query($query)) // { // $log->addDebug("Added core-media-cat Gallery."); // } } } // Media Update $count = $sql->gen("SELECT * FROM `#core_media` WHERE media_category = 'newsthumb' OR media_category = 'downloadthumb' LIMIT 1 "); if ($count == 1) { if ($just_check) { return update_needed('Media-Manager Data needs to be updated.'); } $sql->update('core_media', "media_category='download_image' WHERE media_category = 'download' "); $sql->update('core_media', "media_category='download_thumb' WHERE media_category = 'downloadthumb' "); $sql->update('core_media', "media_category='news_thumb' WHERE media_category = 'newsthumb' "); $log->addDebug("core-media Category names updated"); } // Media Update - core media and core-file. $count = $sql->gen("SELECT * FROM `#core_media` WHERE media_category = '_common' LIMIT 1 "); if ($count == 1) { if ($just_check) { return update_needed('Media-Manager Category Data needs to be updated.'); } $sql->update('core_media', "media_category='_common_image' WHERE media_category = '_common' "); $log->addDebug("core-media _common Category updated"); } // Media Update - core media and core-file. CATEGORY $count = $sql->gen("SELECT * FROM `#core_media_cat` WHERE media_cat_category = '_common' LIMIT 1 "); if ($count == 1) { if ($just_check) { return update_needed('Media-Manager Category Data needs to be updated.'); } $sql->update('core_media_cat', "media_cat_category='_common_image' WHERE media_cat_category = '_common' "); $sql->gen("INSERT INTO `" . MPREFIX . "core_media_cat` VALUES(0, '_common', '_common_file', '(Common Area)', 'Media in this category will be available in all areas of admin. ', 253, '', 0);"); $sql->gen("INSERT INTO `" . MPREFIX . "core_media_cat` VALUES(0, 'download', 'download_file', 'Download Files', '', 253, '', 0);"); $log->addDebug("core-media-cat _common Category updated"); } $count = $sql->gen("SELECT * FROM `#core_media_cat` WHERE `media_cat_owner` = '_common' LIMIT 1 "); if ($count != 1) { if ($just_check) { return update_needed('Add Media-Manager Categories and Import existing images.'); } $e107_core_media_cat = array(array('media_cat_id' => 0, 'media_cat_owner' => '_common', 'media_cat_category' => '_common_image', 'media_cat_title' => '(Common Images)', 'media_cat_sef' => '', 'media_cat_diz' => 'Media in this category will be available in all areas of admin.', 'media_cat_class' => '253', 'media_cat_image' => '', 'media_cat_order' => '0'), array('media_cat_id' => 0, 'media_cat_owner' => '_common', 'media_cat_category' => '_common_file', 'media_cat_title' => '(Common Files)', 'media_cat_sef' => '', 'media_cat_diz' => 'Media in this category will be available in all areas of admin.', 'media_cat_class' => '253', 'media_cat_image' => '', 'media_cat_order' => '0'), array('media_cat_id' => 0, 'media_cat_owner' => 'news', 'media_cat_category' => 'news', 'media_cat_title' => 'News', 'media_cat_sef' => '', 'media_cat_diz' => 'Will be available in the news area.', 'media_cat_class' => '253', 'media_cat_image' => '', 'media_cat_order' => '1'), array('media_cat_id' => 0, 'media_cat_owner' => 'page', 'media_cat_category' => 'page', 'media_cat_title' => 'Custom Pages', 'media_cat_sef' => '', 'media_cat_diz' => 'Will be available in the custom pages area of admin.', 'media_cat_class' => '253', 'media_cat_image' => '', 'media_cat_order' => '0'), array('media_cat_id' => 0, 'media_cat_owner' => 'download', 'media_cat_category' => 'download_image', 'media_cat_title' => 'Download Images', 'media_cat_sef' => '', 'media_cat_diz' => '', 'media_cat_class' => '253', 'media_cat_image' => '', 'media_cat_order' => '0'), array('media_cat_id' => 0, 'media_cat_owner' => 'download', 'media_cat_category' => 'download_thumb', 'media_cat_title' => 'Download Thumbnails', 'media_cat_sef' => '', 'media_cat_diz' => '', 'media_cat_class' => '253', 'media_cat_image' => '', 'media_cat_order' => '0'), array('media_cat_id' => 0, 'media_cat_owner' => 'download', 'media_cat_category' => 'download_file', 'media_cat_title' => 'Download Files', 'media_cat_sef' => '', 'media_cat_diz' => '', 'media_cat_class' => '253', 'media_cat_image' => '', 'media_cat_order' => '0'), array('media_cat_id' => 0, 'media_cat_owner' => 'news', 'media_cat_category' => 'news_thumb', 'media_cat_title' => 'News Thumbnails (Legacy)', 'media_cat_sef' => '', 'media_cat_diz' => 'Legacy news thumbnails.', 'media_cat_class' => '253', 'media_cat_image' => '', 'media_cat_order' => '1')); foreach ($e107_core_media_cat as $insert) { $sql->insert('core_media_cat', $insert); } // $sql->gen("INSERT INTO `".MPREFIX."core_media_cat` VALUES(0, '_common', '_common_image', '(Common Images)', '', 'Media in this category will be available in all areas of admin. ', 253, '', 1);"); // $sql->gen("INSERT INTO `".MPREFIX."core_media_cat` VALUES(0, '_common', '_common_file', '(Common Files)', '', 'Media in this category will be available in all areas of admin. ', 253, '', 2);"); // $sql->gen("INSERT INTO `".MPREFIX."core_media_cat` VALUES(0, 'news', 'news', 'News', '', 'Will be available in the news area. ', 253, '', 3);"); // $sql->gen("INSERT INTO `".MPREFIX."core_media_cat` VALUES(0, 'page', 'page', 'Custom Pages', '', 'Will be available in the custom pages area of admin. ', 253, '', 4);"); // $sql->gen("INSERT INTO `".MPREFIX."core_media_cat` VALUES(0, 'download', 'download_image','', 'Download Images', '', 253, '', 5);"); // $sql->gen("INSERT INTO `".MPREFIX."core_media_cat` VALUES(0, 'download', 'download_thumb', '', 'Download Thumbnails', '', 253, '', 6);"); // $sql->gen("INSERT INTO `".MPREFIX."core_media_cat` VALUES(0, 'download', 'download_file', '', 'Download Files', '', 253, '', 7);"); // mysql_query("INSERT INTO `".MPREFIX."core_media_cat` VALUES(0, 'gallery', 'gallery_1', 'Gallery', 'Visible to the public at /gallery.php', 0, '', 0);"); // $sql->gen("INSERT INTO `".MPREFIX."core_media_cat` VALUES(0, 'news', 'news_thumb', 'News Thumbnails (Legacy)', '', 'Legacy news thumbnails. ', 253, '', 8);"); $med->import('news_thumb', e_IMAGE . 'newspost_images', "^thumb_"); $med->import('news', e_IMAGE . 'newspost_images'); $med->import('page', e_IMAGE . 'custom'); } else { // $log->addDebug("Media COUNT was ".$count. " LINE: ".__LINE__); } // Check for Legacy Download Images. $fl = e107::getFile(); $dl_images = $fl->get_files(e_FILE . 'downloadimages'); if (count($dl_images) && !$sql->gen("SELECT * FROM `#core_media` WHERE `media_category` = 'download_image' ")) { if ($just_check) { return update_needed('Import Download Images into Media Manager'); } $med->import('download_image', e_FILE . 'downloadimages'); $med->import('download_thumb', e_FILE . 'downloadthumbs'); } $dl_files = $fl->get_files(e_FILE . 'downloads', "", "standard", 5); // don't use e_DOWNLOAD or a loop may occur. $publicFilter = array('_FT', '^thumbs\\.db$', '^Thumbs\\.db$', '.*\\._$', '^\\.htaccess$', '^\\.cvsignore$', '^\\.ftpquota$', '^index\\.html$', '^null\\.txt$', '\\.bak$', '^.tmp'); // Default file filter (regex format) // $publicFilter = array(1); $public_files = $fl->get_files(e_FILE . 'public', '', $publicFilter); if ((count($dl_files) || count($public_files)) && !$sql->gen("SELECT * FROM `#core_media` WHERE `media_category` = 'download_file' ")) { if ($just_check) { return update_needed('Import ' . count($dl_files) . ' Download File(s) and ' . count($public_files) . ' Public File(s) into Media Manager'); } if ($sql->gen("SELECT download_url FROM `#download` ")) { $allowed_types = array(); while ($row = $sql->fetch()) { $ext = strrchr($row['download_url'], "."); $suffix = ltrim($ext, "."); if (!isset($allowed_types[$suffix])) { $allowed_types[$suffix] = $suffix; } } $allowed_types = array_unique($allowed_types); } else { $allowed_types = array('zip', 'gz', 'pdf'); } $fmask = '[a-zA-z0-9_-]+\\.(' . implode('|', $allowed_types) . ')$'; $med->import('download_file', e_DOWNLOAD, $fmask); $med->import('_common_file', e_FILE . 'public', $fmask); } $count = $sql->gen("SELECT * FROM `#core_media_cat` WHERE media_cat_owner='_icon' "); if (!$count) { if ($just_check) { return update_needed('Add icons to media-manager'); } $query = "INSERT INTO `" . MPREFIX . "core_media_cat` (`media_cat_id`, `media_cat_owner`, `media_cat_category`, `media_cat_title`, `media_cat_diz`, `media_cat_class`, `media_cat_image`, `media_cat_order`) VALUES\r\n\t\t(0, '_icon', '_icon_16', 'Icons 16px', 'Available where icons are used in admin. ', 253, '', 0),\r\n\t\t(0, '_icon', '_icon_32', 'Icons 32px', 'Available where icons are used in admin. ', 253, '', 0),\r\n\t\t(0, '_icon', '_icon_48', 'Icons 48px', 'Available where icons are used in admin. ', 253, '', 0),\r\n\t\t(0, '_icon', '_icon_64', 'Icons 64px', 'Available where icons are used in admin. ', 253, '', 0);\r\n\t\t"; if (!$sql->gen($query)) { // echo "mysyql error"; // error or already exists. } $med->importIcons(e_PLUGIN); $med->importIcons(e_IMAGE . "icons/"); $med->importIcons(e_THEME . $pref['sitetheme'] . "/images/"); $log->addDebug("Icon category added"); } // Search Clean up ---------------------------------- $searchPref = e107::getConfig('search'); if ($searchPref->getPref('core_handlers/news')) { if ($just_check) { return update_needed('Core search handlers need to be updated.'); } $searchPref->removePref('core_handlers/news')->save(false, true, false); } if ($searchPref->getPref('core_handlers/downloads')) { if ($just_check) { return update_needed('Core search handlers need to be updated.'); } $searchPref->removePref('core_handlers/downloads')->save(false, true, false); } if ($searchPref->getPref('core_handlers/pages')) { if ($just_check) { return update_needed('Core search handlers need to be updated.'); } $searchPref->removePref('core_handlers/pages')->save(false, true, false); e107::getSingleton('e107plugin')->refresh('page'); } // Clean up news keywords. - remove spaces between commas. if ($sql->select('news', 'news_id', "news_meta_keywords LIKE '%, %' LIMIT 1")) { if ($just_check) { return update_needed('News keywords contain spaces between commas and needs to be updated. '); } $sql->update('news', "news_meta_keywords = REPLACE(news_meta_keywords, ', ', ',')"); } // Any other images should be imported manually via Media Manager batch-import. // ------------------------------------------------------------------ // Check that custompages have been imported from current theme.php file if (!$just_check) { if (!is_array($pref['sitetheme_layouts']) || !vartrue($pref['sitetheme_deflayout'])) { $th = e107::getSingleton('themeHandler'); $tmp = $th->getThemeInfo($pref['sitetheme']); if ($th->setTheme($pref['sitetheme'], false)) { $log->addDebug("Updated SiteTheme prefs"); } else { $log->addDebug("Couldn't update SiteTheme prefs"); } } $log->toFile('upgrade_v1_to_v2'); if ($do_save) { save_prefs(); $log->logMessage(LAN_UPDATE_50); // $log->logMessage(implode(', ', $accum), E_MESSAGE_NODISPLAY); //$updateMessages[] = LAN_UPDATE_50.implode(', ',$accum); // Note for admin log } $log->flushMessages('UPDATE_01'); // Write admin log entry, update message handler } else { $log->toFile('upgrade_v1_to_v2_check'); } //FIXME grab message-stack from $log for the log. //if ($just_check) return TRUE; //e107::getLog()->add('UPDATE_01',LAN_UPDATE_14.$e107info['e107_version'].'[!br!]'.implode('[!br!]',$updateMessages),E_LOG_INFORMATIVE,''); // Log result of actual update return $just_check; }
public function actionList() { $request = $this->getRequest(); // use only filtered variables $cid = $request->getRequestParam('cat'); if ($cid && !isset($this->catList[$cid])) { // get ID by SEF $_cid = null; foreach ($this->catList as $id => $row) { if ($cid === $row['media_cat_title']) { $_cid = $id; break; } } $cid = $_cid; } if (empty($cid) || !isset($this->catList[$cid])) { $this->_forward('category'); return; } $tp = e107::getParser(); $template = e107::getTemplate('gallery'); $sc = e107::getScBatch('gallery', TRUE); $sc->total = e107::getMedia()->countImages($cid); $sc->amount = e107::getPlugPref('gallery', 'perpage', 12); // TODO Add Pref. amount per page. $sc->curCat = $cid; $sc->from = $request->getRequestParam('frm', 0); $list = e107::getMedia()->getImages($cid, $sc->from, $sc->amount); $catname = $tp->toHtml($this->catList[$cid]['media_cat_title'], false, 'defs'); $cat = $this->catList[$cid]; $inner = ""; foreach ($list as $row) { $sc->setVars($row)->addVars($cat); $inner .= $tp->parseTemplate($template['LIST_ITEM'], TRUE); } $text = $tp->parseTemplate($template['LIST_START'], TRUE); $text .= $inner; $text .= $tp->parseTemplate($template['LIST_END'], TRUE); $this->addTitle($catname)->addTitle(GALLERY_LAN_TITLE)->addBody($text); }