Esempio n. 1
0
 /**
  * Convert a field value to something renderable.
  *
  * @param  array			The field details
  * @param  mixed			The raw value
  * @return mixed			Rendered field (tempcode or string)
  */
 function render_field_value($field, $ev)
 {
     if (is_object($ev)) {
         return $ev;
     }
     if ($ev == '') {
         return '';
     }
     $original_filename = basename($ev);
     $download_url = (url_is_local($ev) ? get_custom_base_url() . '/' : '') . $ev;
     if (strpos($ev, '::') !== false) {
         list($ev, $original_filename) = explode('::', $ev);
         $keep = symbol_tempcode('KEEP');
         $download_url = find_script('catalogue_file') . '?original_filename=' . urlencode($original_filename) . '&file=' . urlencode(basename($ev)) . $keep->evaluate();
     }
     $extension = get_file_extension($ev);
     require_code('mime_types');
     $mime_type = get_mime_type($extension);
     if ((strpos($mime_type, 'video') !== false || strpos($mime_type, 'audio') !== false) && addon_installed('galleries')) {
         // Video/Audio HTML
         switch ($mime_type) {
             case 'video/quicktime':
                 $tpl = 'GALLERY_VIDEO_QT';
                 break;
             case 'audio/x-pn-realaudio':
                 $tpl = 'GALLERY_VIDEO_RM';
                 break;
             default:
                 $tpl = 'GALLERY_VIDEO_GENERAL';
         }
         return do_template($tpl, array('URL' => url_is_local($ev) ? get_custom_base_url() . '/' . $ev : $ev, 'WIDTH' => get_option('default_video_width'), 'HEIGHT' => get_option('default_video_height'), 'MIME_TYPE' => $mime_type));
     }
     return hyperlink($download_url, $original_filename, true, true);
 }
Esempio n. 2
0
 public function __construct($uploads, $uploadDir = 'uploads/')
 {
     foreach ($uploads as $current) {
         $this->uploadFile = $uploadDir . $current->name . "." . get_file_extension($current->name);
         if ($this->upload($current, $this->uploadFile)) {
             echo "Successfully uploaded " . $current->name . "\n";
         }
     }
 }
function get_file_type_icon($file_name)
{
    static $mime;
    $ext = get_file_extension($file_name);
    if (!isset($mime)) {
        require TR_INCLUDE_PATH . 'lib/mime.inc.php';
    }
    if (isset($mime[$ext]) && $mime[$ext][1]) {
        return $mime[$ext][1];
    }
    return 'generic';
}
Esempio n. 4
0
function get_mime($file)
{
    function get_file_extension($file_name)
    {
        return mb_convert_case(substr(strrchr($file_name, '.'), 1), MB_CASE_LOWER, "UTF-8");
    }
    $arr = ["323" => "text/h323", "*" => "application/octet-stream", "acx" => "application/internet-property-stream", "ai" => "application/postscript", "aif" => "audio/x-aiff", "aifc" => "audio/x-aiff", "aiff" => "audio/x-aiff", "asf" => "video/x-ms-asf", "asr" => "video/x-ms-asf", "asx" => "video/x-ms-asf", "au" => "audio/basic", "avi" => "video/x-msvideo", "axs" => "application/olescript", "bas" => "text/plain", "bcpio" => "application/x-bcpio", "bin" => "application/octet-stream", "bmp" => "image/bmp", "c" => "text/plain", "cat" => "application/vnd.ms-pkiseccat", "cdf" => "application/x-cdf", "cdf" => "application/x-netcdf", "cer" => "application/x-x509-ca-cert", "class" => "application/octet-stream", "clp" => "application/x-msclip", "cmx" => "image/x-cmx", "cod" => "image/cis-cod", "cpio" => "application/x-cpio", "crd" => "application/x-mscardfile", "crl" => "application/pkix-crl", "crt" => "application/x-x509-ca-cert", "csh" => "application/x-csh", "css" => "text/css", "dcr" => "application/x-director", "der" => "application/x-x509-ca-cert", "dir" => "application/x-director", "dll" => "application/x-msdownload", "dms" => "application/octet-stream", "doc" => "application/msword", "dot" => "application/msword", "dvi" => "application/x-dvi", "dxr" => "application/x-director", "eps" => "application/postscript", "etx" => "text/x-setext", "evy" => "application/envoy", "exe" => "application/octet-stream", "fif" => "application/fractals", "flr" => "x-world/x-vrml", "gif" => "image/gif", "gtar" => "application/x-gtar", "gz" => "application/x-gzip", "h" => "text/plain", "hdf" => "application/x-hdf", "hlp" => "application/winhlp", "hqx" => "application/mac-binhex40", "hta" => "application/hta", "htc" => "text/x-component", "htm" => "text/html", "html" => "text/html", "htt" => "text/webviewhtml", "ico" => "image/x-icon", "ief" => "image/ief", "iii" => "application/x-iphone", "ins" => "application/x-internet-signup", "isp" => "application/x-internet-signup", "jfif" => "image/pipeg", "jpe" => "image/jpeg", "jpeg" => "image/jpeg", "jpg" => "image/jpeg", "js" => "application/x-javascript", "latex" => "application/x-latex", "lha" => "application/octet-stream", "lsf" => "video/x-la-asf", "lsx" => "video/x-la-asf", "lzh" => "application/octet-stream", "m13" => "application/x-msmediaview", "m14" => "application/x-msmediaview", "m3u" => "audio/x-mpegurl", "man" => "application/x-troff-man", "mdb" => "application/x-msaccess", "me" => "application/x-troff-me", "mht" => "message/rfc822", "mhtml" => "message/rfc822", "mid" => "audio/mid", "mny" => "application/x-msmoney", "mov" => "video/quicktime", "movie" => "video/x-sgi-movie", "mp2" => "video/mpeg", "mp3" => "audio/mpeg", "mpa" => "video/mpeg", "mpe" => "video/mpeg", "mpeg" => "video/mpeg", "mpg" => "video/mpeg", "mpp" => "application/vnd.ms-project", "mpv2" => "video/mpeg", "ms" => "application/x-troff-ms", "msg" => "application/vnd.ms-outlook", "mvb" => "application/x-msmediaview", "nc" => "application/x-netcdf", "nws" => "message/rfc822", "oda" => "application/oda", "p10" => "application/pkcs10", "p12" => "application/x-pkcs12", "p7b" => "application/x-pkcs7-certificates", "p7c" => "application/x-pkcs7-mime", "p7m" => "application/x-pkcs7-mime", "p7r" => "application/x-pkcs7-certreqresp", "p7s" => "application/x-pkcs7-signature", "pbm" => "image/x-portable-bitmap", "pdf" => "application/pdf", "pfx" => "application/x-pkcs12", "pgm" => "image/x-portable-graymap", "pko" => "application/ynd.ms-pkipko", "pma" => "application/x-perfmon", "pmc" => "application/x-perfmon", "pml" => "application/x-perfmon", "pmr" => "application/x-perfmon", "pmw" => "application/x-perfmon", "pnm" => "image/x-portable-anymap", "pot" => "application/vnd.ms-powerpoint", "ppm" => "image/x-portable-pixmap", "pps" => "application/vnd.ms-powerpoint", "ppt" => "application/vnd.ms-powerpoint", "prf" => "application/pics-rules", "ps" => "application/postscript", "pub" => "application/x-mspublisher", "qt" => "video/quicktime", "ra" => "audio/x-pn-realaudio", "ram" => "audio/x-pn-realaudio", "ras" => "image/x-cmu-raster", "rgb" => "image/x-rgb", "rmi" => "audio/mid", "roff" => "application/x-troff", "rtf" => "application/rtf", "rtx" => "text/richtext", "scd" => "application/x-msschedule", "sct" => "text/scriptlet", "setpay" => "application/set-payment-initiation", "setreg" => "application/set-registration-initiation", "sh" => "application/x-sh", "shar" => "application/x-shar", "sit" => "application/x-stuffit", "snd" => "audio/basic", "spc" => "application/x-pkcs7-certificates", "spl" => "application/futuresplash", "src" => "application/x-wais-source", "sst" => "application/vnd.ms-pkicertstore", "stl" => "application/vnd.ms-pkistl", "stm" => "text/html", "sv4cpio" => "application/x-sv4cpio", "sv4crc" => "application/x-sv4crc", "svg" => "image/svg+xml", "swf" => "application/x-shockwave-flash", "t" => "application/x-troff", "tar" => "application/x-tar", "tcl" => "application/x-tcl", "tex" => "application/x-tex", "texi" => "application/x-texinfo", "texinfo" => "application/x-texinfo", "tgz" => "application/x-compressed", "tif" => "image/tiff", "tiff" => "image/tiff", "tr" => "application/x-troff", "trm" => "application/x-msterminal", "tsv" => "text/tab-separated-values", "txt" => "text/plain", "uls" => "text/iuls", "ustar" => "application/x-ustar", "vcf" => "text/x-vcard", "vrml" => "x-world/x-vrml", "wav" => "audio/x-wav", "wcm" => "application/vnd.ms-works", "wdb" => "application/vnd.ms-works", "wks" => "application/vnd.ms-works", "wmf" => "application/x-msmetafile", "wps" => "application/vnd.ms-works", "wri" => "application/x-mswrite", "wrl" => "x-world/x-vrml", "wrz" => "x-world/x-vrml", "xaf" => "x-world/x-vrml", "xbm" => "image/x-xbitmap", "xla" => "application/vnd.ms-excel", "xlc" => "application/vnd.ms-excel", "xlm" => "application/vnd.ms-excel", "xls" => "application/vnd.ms-excel", "xlt" => "application/vnd.ms-excel", "xlw" => "application/vnd.ms-excel", "xof" => "x-world/x-vrml", "xpm" => "image/x-xpixmap", "xwd" => "image/x-xwindowdump", "z" => "application/x-compress", "zip" => "application/zip"];
    try {
        return $arr[get_file_extension($file)];
    } catch (Exception $ex) {
        return $arr["*"];
    }
}
Esempio n. 5
0
function check_extensions($Type, $Name)
{
    global $MusicExtensions, $ComicsExtensions;
    if ($Type == 'Music' || $Type == 'Audiobooks' || $Type == 'Comedy' || $Type == 'E-Books') {
        if (!isset($MusicExtensions[get_file_extension($Name)])) {
            invalid_error($Name);
        }
    } elseif ($Type == 'Comics') {
        if (!isset($ComicsExtensions[get_file_extension($Name)])) {
            invalid_error($Name);
        }
    }
}
Esempio n. 6
0
function get_files($images_dir, $exts = array('jpg'))
{
    $files = array();
    if ($handle = opendir($images_dir)) {
        while (false !== ($file = readdir($handle))) {
            $extension = strtolower(get_file_extension($file));
            if ($extension && in_array($extension, $exts)) {
                $files[] = $file;
            }
        }
        closedir($handle);
    }
    return $files;
}
Esempio n. 7
0
function view_dir_full($root)
{
    $a = 0;
    if (is_dir($root)) {
        if ($dh = opendir($root)) {
            echo "<table >";
            while (($file = readdir($dh)) !== false) {
                if (!($file == "." || $file == "..")) {
                    if (is_dir($root . "/" . $file)) {
                        global $temp;
                        $temp = $file;
                        echo '<tr><td><a href="http://localhost/minor/fms/fms_test.php?col=' . $root . "/" . str_replace(" ", "%20", $file) . '"><img src="../img/folder.png" width="25" height="25" border="0" alt="directory:">' . $file . '</a>';
                        if ($_SESSION['CurrentUserType'] == "admin" || $_SESSION['CurrentUserType'] == "faculty") {
                            echo '&nbsp;&nbsp;&nbsp;</td><td><a href="delete_dir.php?col1=' . $root . '&col2=' . $file . '"><img src="../img/delete.png" width="10" height="10" border="0" alt=""></a>&nbsp;&nbsp;&nbsp;</td><td>';
                        }
                        $a++;
                    } else {
                        $str = $file;
                        if (strlen($str) > 13) {
                            $str = substr($str, 0, 15);
                            $str = $str . "...";
                        }
                        $info = get_file_extension($file);
                        if ($info == "pdf") {
                            echo '<tr><td><img src="../img/filetype_pdf.png" width="25" height="25" border="0" alt=""><a href="' . $root . '/' . $file . '" target="_blank">' . $str . '</a>';
                            if ($_SESSION['CurrentUserType'] == "admin" || $_SESSION['CurrentUserType'] == "faculty") {
                                echo '&nbsp;&nbsp;&nbsp;</td><td><a href="delete_dir.php?col1=' . $root . '&col2=' . $file . '"><img src="../img/delete.png" width="10" height="10" border="0" alt=""></a></td></tr><br>';
                            }
                            $a++;
                        } else {
                            if ($info == "docx") {
                                echo '<tr><td><img src="../img/docx.png" width="25" height="25" border="0" alt=""><a href="' . $root . '/' . $file . '"target="_blank">' . $str . '</a>';
                                if ($_SESSION['CurrentUserType'] == "admin" || $_SESSION['CurrentUserType'] == "faculty") {
                                    echo '</a>&nbsp;&nbsp;&nbsp;</td><td><a href="delete_dir.php?col1=' . $root . '&col2=' . $file . '"><img src="../img/delete.png" width="10" height="10" border="0" alt=""></a></td></tr><br>';
                                }
                                $a++;
                            }
                        }
                    }
                }
            }
            closedir($dh);
        }
    }
    echo '</table>';
}
Esempio n. 8
0
function set_filename($path, $filename)
{
    if (!file_exists($path . $filename)) {
        return $filename;
    }
    $ext = get_file_extension($filename);
    $filename = str_replace($ext, '', $filename);
    $new_filename = '';
    for ($i = 1; $i < 100; $i++) {
        if (!file_exists($path . $filename . $i . $ext)) {
            $new_filename = $filename . $i . $ext;
            break;
        }
    }
    if ($new_filename == '') {
        return FALSE;
    } else {
        return $new_filename;
    }
}
function read_path($dir, $ext = null)
{
    $file = null;
    $files = array();
    if ($root = @opendir($dir)) {
        while ($file = readdir($root)) {
            if ($file == "." || $file == "..") {
                continue;
            }
            if (!is_null($ext)) {
                $extension = get_file_extension($file);
                if ($ext == $extension) {
                    $files[] = $file;
                }
            } else {
                $files[] = $file;
            }
        }
        array_multisort($files, SORT_ASC);
        return $files;
    }
}
Esempio n. 10
0
 public function post_create()
 {
     $file = null;
     $image_name = Opensim\UUID::random();
     $action = Input::get('action');
     if (isset($action) and $action == 'logo') {
         $file = Input::file('logo_image');
         $logo_path = path('public') . 'bundles/splashscreen/img/logo/';
         foreach (glob($logo_path . "logo.*") as $filename) {
             @File::delete($filename);
         }
         $path = $logo_path . $file['name'];
         $logo_parts = explode('.', $file['name']);
         $path = $logo_path;
         $image_name = 'logo.' . $logo_parts['1'];
         $image_path = '/bundles/splashscreen/img/logo/' . $image_name;
         Input::upload('logo_image', $path, $image_name);
         return View::make('splashscreen::backend.imagesbackgrounds.partials.logo', array('image_name' => $image_name, 'path' => $image_path))->render();
         Log::error($path);
     }
     if (isset($action) and $action == 'background') {
         $file = Input::file('background');
         $path = path('public') . 'bundles/splashscreen/img/backgrounds/';
         $ext = get_file_extension($file['name']);
         $image_name = $image_name . '.' . $ext;
         $image_path = '/bundles/splashscreen/img/backgrounds/' . $image_name;
         Input::upload('background', $path, $image_name);
         return View::make('splashscreen::backend.imagesbackgrounds.partials.image', array('image_name' => $image_name, 'path' => $image_path, 'action' => 'background'))->render();
     }
     if (isset($action) and $action == 'daytimebkg') {
         $file = Input::file('daytimebkg');
         $path = path('public') . 'bundles/splashscreen/img/day_time_bkgs/';
         $image_name = $file['name'];
         $image_path = '/bundles/splashscreen/img/day_time_bkgs/' . $image_name;
         Input::upload('daytimebkg', $path, $image_name);
         return View::make('splashscreen::backend.imagesbackgrounds.partials.day_time_bkgs', array('image_name' => $image_name, 'path' => $image_path, 'action' => 'daytimebkg'))->render();
     }
 }
Esempio n. 11
0
/** FINALIZE UPDATE FIRMWARE TASK 
 * 
 * @param $tid - TASK ID
 * @param $status - TASK STATUS (STOPPED - PERFORMED)
 * 
 **/
function finalize_mesh($tid, $status)
{
    //global $log;
    //$log->info('Task #'.$tid.' mesh '.$status);
    //$log->info('Task #'.$tid.' start finalizing');
    //LOAD DB
    $db = new Database();
    //GET TASK
    $task = $db->query('select * from sys_tasks where id=' . $tid);
    //GET TASK ATTRIBUTES
    $attributes = json_decode($task['attributes'], TRUE);
    //MOVE OUTPUT FILE TO OBJECT FOLDER
    $_id_object = $attributes['id_object'];
    $id_file = $attributes['id_new_file'];
    $_output = $attributes['output'];
    $_output_file_name = get_name($_output);
    $_output_extension = get_file_extension($_output);
    $_output_folder_destination = '/var/www/upload/' . str_replace('.', '', $_output_extension) . '/';
    $_output_file_name = set_filename($_output_folder_destination, $_output_file_name);
    // MOVE TO FINALLY FOLDER
    shell_exec('sudo cp ' . $_output . ' ' . $_output_folder_destination . $_output_file_name);
    // ADD PERMISSIONS
    shell_exec('sudo chmod 746 ' . $_output_folder_destination . $_output_file_name);
    // INSERT RECORD TO DB
    $data_file['file_name'] = $_output_file_name;
    $data_file['file_path'] = $_output_folder_destination;
    $data_file['full_path'] = $_output_folder_destination . $_output_file_name;
    $data_file['raw_name'] = str_replace($_output_extension, '', $_output_file_name);
    $data_file['client_name'] = str_replace($_output_extension, '', $_output_file_name);
    $data_file['orig_name'] = $_output_file_name;
    $data_file['file_ext'] = $_output_extension;
    $data_file['file_size'] = filesize($_output_folder_destination . $_output_file_name);
    $data_file['print_type'] = print_type($_output_folder_destination . $_output_file_name);
    $data_file['note'] = 'Reconstructed on ' . date("F j, Y, g:i a");
    $data_file['insert_date'] = 'now()';
    $data_file['file_type'] = 'application/octet-stream';
    // ADD TASK RECORD TO DB
    $db->update('sys_files', array('column' => 'id', 'value' => $id_file, 'sign' => '='), $data_file);
    // ADD ASSOCIATION OBJ FILE
    $data['id_obj'] = $_id_object;
    $data['id_file'] = $id_file;
    $id_ass = $db->insert('sys_obj_files', $data);
    $db->close();
    //UPDATE TASK
    update_task($tid, $status);
    sleep(10);
    //REMOVE ALL TEMPORARY FILES
    shell_exec('sudo rm -rf ' . $attributes['folder']);
    //$log->info('Task #'.$tid.' end finalizing');
}
Esempio n. 12
0
            $date_with_time = nice_format($entry['date'], true);
            if ($is_dir) {
                $tool_content .= "<td>&nbsp;</td><td class='center'>{$date}</td>";
            } else {
                if ($entry['format'] == ".meta") {
                    $size = format_file_size($entry['size']);
                    $tool_content .= "<td class='center'>{$size}</td><td class='center'>{$date}</td>";
                } else {
                    $size = format_file_size($entry['size']);
                    $tool_content .= "<td class='center'>{$size}</td><td class='center' title='{$date_with_time}'>{$date}</td>";
                }
            }
            if (!$is_in_tinymce) {
                if ($can_upload) {
                    $tool_content .= "<td class='option-btn-cell'>";
                    $xmlCmdDirName = $entry['format'] == ".meta" && get_file_extension($cmdDirName) == "xml" ? substr($cmdDirName, 0, -4) : $cmdDirName;
                    $tool_content .= action_button(array(array('title' => $langGroupSubmit, 'url' => "{$urlAppend}modules/work/group_work.php?course={$course_code}&amp;group_id={$group_id}&amp;submit={$cmdDirName}", 'icon' => 'fa-book', 'show' => $subsystem == GROUP and isset($is_member) and $is_member), array('title' => $dload_msg, 'url' => $download_url, 'icon' => 'fa-save'), array('title' => $langVisible, 'url' => "{$base_url}" . ($entry['visible'] ? "mkInvisibl={$cmdDirName}" : "mkVisibl={$cmdDirName}"), 'icon' => $entry['visible'] ? 'fa-eye' : 'fa-eye-slash'), array('title' => $langResourceAccess, 'url' => "{$base_url}limited={$cmdDirName}", 'icon' => 'fa-unlock', 'show' => $course_id > 0 and course_status($course_id) == COURSE_OPEN and $entry['public']), array('title' => $langMove, 'url' => "{$base_url}move={$cmdDirName}", 'icon' => 'fa-arrows', 'show' => $entry['format'] != '.meta'), array('title' => $langRename, 'url' => "{$base_url}rename={$cmdDirName}", 'icon' => 'fa-repeat', 'show' => $entry['format'] != '.meta'), array('title' => $langComments, 'url' => "{$base_url}comment={$cmdDirName}", 'icon' => 'fa-comment-o', 'show' => $entry['format'] != '.meta'), array('title' => $langReplace, 'url' => "{$base_url}replace={$cmdDirName}", 'icon' => 'fa-reply', 'show' => !$is_dir && $entry['format'] != '.meta'), array('title' => $langMetadata, 'url' => "{$base_url}metadata={$xmlCmdDirName}", 'icon' => 'fa-tags', 'show' => get_config("insert_xml_metadata")), array('title' => $langResourceAccess, 'url' => "{$base_url}public={$cmdDirName}", 'icon' => 'fa-lock', 'show' => $course_id > 0 and course_status($course_id) == COURSE_OPEN and !$entry['public']), array('title' => $langDelete, 'url' => "{$base_url}filePath={$cmdDirName}&amp;delete=1", 'icon' => 'fa-times', 'class' => 'delete', 'confirm' => "{$langConfirmDelete} {$entry['filename']}")));
                    $tool_content .= "</td>";
                } else {
                    // student view
                    $tool_content .= "<td class='text-center'>" . icon('fa-save', $dload_msg, $download_url) . "</td>";
                }
            }
            $tool_content .= "</tr>";
        }
    }
    $tool_content .= "</table>\n            </div>\n        </div>\n    </div>";
    if ($can_upload && !$is_in_tinymce) {
        $tool_content .= "<br><div class='text-right'>{$langMaxFileSize} " . ini_get('upload_max_filesize') . "</div>";
    }
}
Esempio n. 13
0
function _rename($dir, $file_src, $file_dest, $force = false)
{
    $oldwd = getcwd();
    chdir(realpath($dir));
    if (!file_exists($file_src)) {
        return false;
    }
    $copy = "";
    $file_name = get_file_name($file_dest);
    $file_ext = get_file_extension($file_dest);
    if (!$force && strtolower($file_src) == $file_dest && substr(PHP_OS, 0, 3) != "WIN") {
        $n = 2;
        while (file_exists($file_name . $copy . "." . $file_ext)) {
            $copy = "_" . $n;
            $n++;
        }
    }
    $file = $file_name . $copy . "." . $file_ext;
    $ok = rename($file_src, $file);
    chdir($oldwd);
    return $ok ? $file : false;
}
Esempio n. 14
0
		$description .= '<tr><td>' . lang('mail BCC') . ':</td><td>' . MailUtilities::displayMultipleAddresses(clean($email->getBcc())) . '</td></tr>';
	}
	$description .= '<tr><td>' . lang('date') . ':</td><td>' . format_datetime($email->getSentDate(), 'l, j F Y - '.$time_format, logged_user()->getTimezone()) . '</td></tr>';
	
	if ($email->getHasAttachments() && is_array($attachments) && count($attachments) > 0) {
		$description .=	'<tr><td colspan=2>	<fieldset>
		<legend class="toggle_collapsed" onclick="og.toggle(\'mv_attachments\',this)">' . lang('attachments') . '</legend>
		<div id="mv_attachments" style="display:none">
		<table>';
		foreach($attachments as $att) {
			if (!array_var($att, 'hide')) {
				$size = $att['size'];//format_filesize(strlen($att["Data"]));
				$fName = str_starts_with($att["FileName"], "=?") ? iconv_mime_decode($att["FileName"], 0, "UTF-8") : utf8_safe($att["FileName"]);
				if (trim($fName) == "" && strlen($att["FileName"]) > 0) $fName = utf8_encode($att["FileName"]);
				$description .= '<tr><td style="padding-right: 10px">';
				$ext = get_file_extension($fName);
				$fileType = FileTypes::getByExtension($ext);
				if (isset($fileType))
					$icon = $fileType->getIcon();
				else
					$icon = "unknown.png";
				$download_url = get_url('mail', 'download_attachment', array('email_id' => $email->getId(), 'attachment_id' => $c));
				include_once ROOT . "/library/browser/Browser.php";
				if (Browser::instance()->getBrowser() == Browser::BROWSER_IE) {
					$download_url = "javascript:location.href = '$download_url';";
				}
	      		$description .=	'<img src="' . get_image_url("filetypes/" . $icon) .'"></td>
				<td><a target="_self" href="' . $download_url . '">' . clean($fName) . " ($size)" . '</a></td></tr>';
			}
      		$c++;
		}
Esempio n. 15
0
 public function frontend()
 {
     if (isset($_GET['debug'])) {
         if ($this->app->make('config')->get('app.debug')) {
             DB::enableQueryLog();
         }
     }
     event_trigger('mw.controller.index');
     if ($this->render_this_url == false and $this->app->url_manager->is_ajax() == false) {
         $page_url = $this->app->url_manager->string();
     } elseif ($this->render_this_url == false and $this->app->url_manager->is_ajax() == true) {
         $page_url = $this->app->url_manager->string(1);
     } else {
         $page_url = $this->render_this_url;
         $this->render_this_url = false;
     }
     if ($this->page_url != false) {
         $page_url = $this->page_url;
     }
     if (strtolower($page_url) == 'index.php') {
         $page_url = '';
     }
     if ($this->create_new_page == true and $this->page_url != false) {
         $page_url = $this->page_url;
     }
     $page = false;
     if ($page == false and !empty($this->page)) {
         $page = $this->page;
     }
     $page_url = rtrim($page_url, '/');
     $is_admin = $this->app->user_manager->is_admin();
     $page_url_orig = $page_url;
     $simply_a_file = false;
     $show_404_to_non_admin = false;
     // if this is a file path it will load it
     if (isset($_REQUEST['view'])) {
         $is_custom_view = $_REQUEST['view'];
     } else {
         $is_custom_view = $this->app->url_manager->param('view');
         if ($is_custom_view and $is_custom_view != false) {
             $is_custom_view = str_replace('..', '', $is_custom_view);
             $page_url = $this->app->url_manager->param_unset('view', $page_url);
         }
     }
     $is_editmode = $this->app->url_manager->param('editmode');
     $is_no_editmode = $this->app->url_manager->param('no_editmode');
     $is_quick_edit = $this->app->url_manager->param('mw_quick_edit');
     if ($is_quick_edit != false) {
         $page_url = $this->app->url_manager->param_unset('mw_quick_edit', $page_url);
     }
     $is_preview_template = $this->app->url_manager->param('preview_template');
     if (!$is_preview_template) {
         $is_preview_template = false;
         if ($this->return_data == false) {
             if (!defined('MW_FRONTEND')) {
                 define('MW_FRONTEND', true);
             }
         }
         if (mw()->user_manager->session_id() and $is_editmode and $is_no_editmode == false) {
             if ($is_editmode == 'n') {
                 $is_editmode = false;
                 $page_url = $this->app->url_manager->param_unset('editmode', $page_url);
                 $this->app->user_manager->session_set('back_to_editmode', true);
                 $this->app->user_manager->session_set('editmode', false);
                 return $this->app->url_manager->redirect($this->app->url_manager->site_url($page_url));
             } else {
                 $editmode_sess = $this->app->user_manager->session_get('editmode');
                 $page_url = $this->app->url_manager->param_unset('editmode', $page_url);
                 if ($is_admin == true) {
                     if ($editmode_sess == false) {
                         $this->app->user_manager->session_set('editmode', true);
                         $this->app->user_manager->session_set('back_to_editmode', false);
                         $is_editmode = false;
                     }
                     return $this->app->url_manager->redirect($this->app->url_manager->site_url($page_url));
                 } else {
                     $is_editmode = false;
                 }
             }
         }
         if (mw()->user_manager->session_id() and !$is_no_editmode) {
             $is_editmode = $this->app->user_manager->session_get('editmode');
         } else {
             $is_editmode = false;
             $page_url = $this->app->url_manager->param_unset('no_editmode', $page_url);
         }
     } else {
         $is_editmode = false;
         $page_url = $this->app->url_manager->param_unset('preview_template', $page_url);
     }
     if ($is_quick_edit == true) {
         $is_editmode = true;
     }
     $preview_module = false;
     $preview_module_template = false;
     $preview_module_id = false;
     $template_relative_layout_file_from_url = false;
     $is_preview_module = $this->app->url_manager->param('preview_module');
     if ($is_preview_module != false) {
         if ($this->app->user_manager->is_admin()) {
             $is_preview_module = module_name_decode($is_preview_module);
             if (is_module($is_preview_module)) {
                 $is_preview_module_skin = $this->app->url_manager->param('preview_module_template');
                 $preview_module_id = $this->app->url_manager->param('preview_module_id');
                 $preview_module = $is_preview_module;
                 if ($is_preview_module_skin != false) {
                     $preview_module_template = module_name_decode($is_preview_module_skin);
                     $is_editmode = false;
                 }
             }
         }
     }
     $is_layout_file = $this->app->url_manager->param('preview_layout');
     if (!$is_layout_file) {
         $is_layout_file = false;
     } else {
         $page_url = $this->app->url_manager->param_unset('preview_layout', $page_url);
     }
     if (isset($_REQUEST['content_id']) and intval($_REQUEST['content_id']) != 0) {
         $page = $this->app->content_manager->get_by_id($_REQUEST['content_id']);
     }
     if ($is_quick_edit or $is_preview_template == true or isset($_REQUEST['isolate_content_field']) or $this->create_new_page == true) {
         if (isset($_REQUEST['content_id']) and intval($_REQUEST['content_id']) != 0) {
             $page = $this->app->content_manager->get_by_id($_REQUEST['content_id']);
         } else {
             $page['id'] = 0;
             $page['content_type'] = 'page';
             if (isset($_REQUEST['content_type'])) {
                 $page['content_type'] = $this->app->database_manager->escape_string($_REQUEST['content_type']);
             }
             if (isset($_REQUEST['subtype'])) {
                 $page['subtype'] = $this->app->database_manager->escape_string($_REQUEST['subtype']);
             }
             template_var('new_content_type', $page['content_type']);
             $page['parent'] = '0';
             if (isset($_REQUEST['parent_id']) and $_REQUEST['parent_id'] != 0) {
                 $page['parent'] = intval($_REQUEST['parent_id']);
             }
             //$page['url'] = $this->app->url_manager->string();
             if (isset($is_preview_template) and $is_preview_template != false) {
                 $page['active_site_template'] = $is_preview_template;
             } else {
             }
             if (isset($is_layout_file) and $is_layout_file != false) {
                 $page['layout_file'] = $is_layout_file;
             }
             if (isset($_REQUEST['inherit_template_from']) and $_REQUEST['inherit_template_from'] != 0) {
                 $page['parent'] = intval($_REQUEST['inherit_template_from']);
                 $inherit_from = $this->app->content_manager->get_by_id($_REQUEST['inherit_template_from']);
                 //$page['parent'] =  $inherit_from ;
                 if (isset($inherit_from['layout_file']) and $inherit_from['layout_file'] == 'inherit') {
                     $inherit_from_id = $this->app->content_manager->get_inherited_parent($inherit_from['id']);
                     $inherit_from = $this->app->content_manager->get_by_id($inherit_from_id);
                 }
                 if (is_array($inherit_from) and isset($inherit_from['active_site_template'])) {
                     $page['active_site_template'] = $inherit_from['active_site_template'];
                     $is_layout_file = $page['layout_file'] = $inherit_from['layout_file'];
                 }
             }
             if (isset($_REQUEST['content_type']) and $_REQUEST['content_type'] != false) {
                 $page['content_type'] = $_REQUEST['content_type'];
             }
             if ($this->content_data != false) {
                 $page = $this->content_data;
             }
             template_var('new_page', $page);
         }
     }
     $output_cache_timeout = false;
     if (isset($is_preview_template) and $is_preview_template != false) {
         if (!defined('MW_NO_SESSION')) {
             define('MW_NO_SESSION', true);
         }
     }
     if (isset($_REQUEST['recart']) and $_REQUEST['recart'] != false) {
         event_trigger('recover_shopping_cart', $_REQUEST['recart']);
     }
     if ($output_cache_timeout != false) {
         $output_cache_id = __FUNCTION__ . crc32($_SERVER['REQUEST_URI']);
         $output_cache_group = 'content/preview';
         $output_cache_content = $this->app->cache_manager->get($output_cache_id, $output_cache_group, $output_cache_timeout);
         if ($output_cache_content != false) {
             echo $output_cache_content;
             return;
         }
     }
     $the_active_site_template = $this->app->option_manager->get('current_template', 'template');
     $date_format = $this->app->option_manager->get('date_format', 'website');
     if ($date_format == false) {
         $date_format = 'Y-m-d H:i:s';
     }
     if ($page == false or $this->create_new_page == true) {
         if (trim($page_url) == '' and $preview_module == false) {
             $page = $this->app->content_manager->homepage();
         } else {
             $found_mod = false;
             $page = $this->app->content_manager->get_by_url($page_url);
             $page_exact = $this->app->content_manager->get_by_url($page_url, true);
             $page_url_segment_1 = $this->app->url_manager->segment(0, $page_url);
             if ($preview_module != false) {
                 $page_url = $preview_module;
             }
             if ($the_active_site_template == false or $the_active_site_template == '') {
                 $the_active_site_template = 'default';
             }
             if ($page_exact == false and $found_mod == false and $this->app->modules->is_installed($page_url) and $page_url != 'settings' and $page_url != 'admin') {
                 $found_mod = true;
                 $page['id'] = 0;
                 $page['content_type'] = 'page';
                 $page['parent'] = '0';
                 $page['url'] = $this->app->url_manager->string();
                 $page['active_site_template'] = $the_active_site_template;
                 template_var('no_edit', 1);
                 $mod_params = '';
                 if ($preview_module_template != false) {
                     $mod_params = $mod_params . " template='{$preview_module_template}' ";
                 }
                 if ($preview_module_id != false) {
                     $mod_params = $mod_params . " id='{$preview_module_id}' ";
                 }
                 $found_mod = $page_url;
                 $page['content'] = '<microweber module="' . $page_url . '" ' . $mod_params . '  />';
                 //  $page['simply_a_file'] = 'clean.php';
                 $page['layout_file'] = 'clean.php';
                 template_var('content', $page['content']);
                 template_var('new_page', $page);
             }
             if ($found_mod == false) {
                 if (empty($page)) {
                     $the_new_page_file = false;
                     $page_url_segment_1 = $this->app->url_manager->segment(0, $page_url);
                     $td = templates_path() . $page_url_segment_1;
                     $td_base = $td;
                     $page_url_segment_2 = $this->app->url_manager->segment(1, $page_url);
                     $directly_to_file = false;
                     $page_url_segment_3 = $this->app->url_manager->segment(-1, $page_url);
                     $page_url_segment_1 = $the_active_site_template = $this->app->option_manager->get('current_template', 'template');
                     $td_base = templates_path() . $the_active_site_template . DS;
                     $page_url_segment_3_str = implode(DS, $page_url_segment_3);
                     if ($page_url_segment_3_str != '') {
                         $page_url_segment_3_str = rtrim($page_url_segment_3_str, DS);
                         $page_url_segment_3_str = rtrim($page_url_segment_3_str, '\\');
                         $page_url_segment_3_str_copy = $page_url_segment_3_str;
                         $is_ext = get_file_extension($page_url_segment_3_str);
                         if ($is_ext == false or $is_ext != 'php') {
                             $page_url_segment_3_str = $page_url_segment_3_str . '.php';
                         }
                         $td_f = $td_base . DS . $page_url_segment_3_str;
                         $td_fd = $td_base . DS . $page_url_segment_3_str_copy;
                         $td_fd2 = $td_base . DS . $page_url_segment_3[0];
                         if (is_file($td_f)) {
                             $the_new_page_file = $page_url_segment_3_str;
                             $simply_a_file = $directly_to_file = $td_f;
                         } else {
                             if (is_dir($td_fd)) {
                                 $td_fd_index = $td_fd . DS . 'index.php';
                                 if (is_file($td_fd_index)) {
                                     $the_new_page_file = $td_fd_index;
                                     $simply_a_file = $directly_to_file = $td_fd_index;
                                 }
                             } else {
                                 $is_ext = get_file_extension($td_fd);
                                 if ($is_ext == false or $is_ext != 'php') {
                                     $td_fd = $td_fd . '.php';
                                 }
                                 $is_ext = get_file_extension($td_fd2);
                                 if ($is_ext == false or $is_ext != 'php') {
                                     $td_fd2 = $td_fd2 . '.php';
                                 }
                                 if (is_file($td_fd)) {
                                     $the_new_page_file = $td_fd;
                                     $simply_a_file = $directly_to_file = $td_fd;
                                 } elseif (is_file($td_fd2)) {
                                     $the_new_page_file = $td_fd2;
                                     $simply_a_file = $directly_to_file = $td_fd2;
                                 } else {
                                     $td_basedef = templates_path() . 'default' . DS . $page_url_segment_3_str;
                                     if (is_file($td_basedef)) {
                                         $the_new_page_file = $td_basedef;
                                         $simply_a_file = $directly_to_file = $td_basedef;
                                     }
                                 }
                             }
                         }
                     }
                     $fname1 = 'index.php';
                     $fname2 = $page_url_segment_2 . '.php';
                     $fname3 = $page_url_segment_2;
                     $tf1 = $td . DS . $fname1;
                     $tf2 = $td . DS . $fname2;
                     $tf3 = $td . DS . $fname3;
                     if ($directly_to_file == false and is_dir($td)) {
                         if (is_file($tf1)) {
                             $simply_a_file = $tf1;
                             $the_new_page_file = $fname1;
                         }
                         if (is_file($tf2)) {
                             $simply_a_file = $tf2;
                             $the_new_page_file = $fname2;
                         }
                         if (is_file($tf3)) {
                             $simply_a_file = $tf3;
                             $the_new_page_file = $fname3;
                         }
                         if ($simply_a_file != false) {
                             $simply_a_file = str_replace('..', '', $simply_a_file);
                             $simply_a_file = normalize_path($simply_a_file, false);
                         }
                     }
                     if ($simply_a_file == false) {
                         //$page = $this->app->content_manager->homepage();
                         $page = false;
                         if (!is_array($page)) {
                             $page = array();
                             $page['id'] = 0;
                             $page['content_type'] = 'page';
                             $page['parent'] = '0';
                             $page['url'] = $this->app->url_manager->string();
                             //  $page['active_site_template'] = $page_url_segment_1;
                             $page['simply_a_file'] = 'clean.php';
                             $page['layout_file'] = 'clean.php';
                             $show_404_to_non_admin = true;
                         }
                         if (is_array($page_url_segment_3)) {
                             foreach ($page_url_segment_3 as $mvalue) {
                                 if ($found_mod == false and $this->app->modules->is_installed($mvalue)) {
                                     $found_mod = true;
                                     $page['id'] = 0;
                                     $page['content_type'] = 'page';
                                     $page['parent'] = '0';
                                     $page['url'] = $this->app->url_manager->string();
                                     $page['active_site_template'] = $page_url_segment_1;
                                     $page['content'] = '<module type="' . $mvalue . '" />';
                                     $page['simply_a_file'] = 'clean.php';
                                     $page['layout_file'] = 'clean.php';
                                     template_var('content', $page['content']);
                                     template_var('new_page', $page);
                                     $show_404_to_non_admin = false;
                                 }
                             }
                         }
                     } else {
                         if (!is_array($page)) {
                             $page = array();
                         }
                         $page['id'] = 0;
                         if (isset($page_data) and isset($page_data['id'])) {
                             //  $page['id'] = $page_data['id'];
                         }
                         $page['content_type'] = 'page';
                         $page['parent'] = '0';
                         $page['url'] = $this->app->url_manager->string();
                         $page['active_site_template'] = $page_url_segment_1;
                         $page['layout_file'] = $the_new_page_file;
                         $page['simply_a_file'] = $simply_a_file;
                         template_var('new_page', $page);
                         template_var('simply_a_file', $simply_a_file);
                     }
                 }
             }
         }
     }
     if ($page['id'] != 0) {
         // if(!isset($page['layout_file']) or $page['layout_file'] == false){
         $page = $this->app->content_manager->get_by_id($page['id']);
         // }
         if ($page['content_type'] == 'post' and isset($page['parent'])) {
             $content = $page;
             $page = $this->app->content_manager->get_by_id($page['parent']);
         } else {
             $content = $page;
         }
     } else {
         $content = $page;
     }
     if (isset($content['created_at']) and trim($content['created_at']) != '') {
         $content['created_at'] = date($date_format, strtotime($content['created_at']));
     }
     if (isset($content['updated_at']) and trim($content['updated_at']) != '') {
         $content['updated_at'] = date($date_format, strtotime($content['updated_at']));
     }
     if ($is_preview_template != false) {
         $is_preview_template = str_replace('____', DS, $is_preview_template);
         $is_preview_template = str_replace('..', '', $is_preview_template);
         $content['active_site_template'] = $is_preview_template;
     }
     if ($is_layout_file != false and $is_admin == true) {
         $is_layout_file = str_replace('____', DS, $is_layout_file);
         if ($is_layout_file == 'inherit') {
             if (isset($_REQUEST['inherit_template_from']) and intval($_REQUEST['inherit_template_from']) != 0) {
                 $inherit_layout_from_this_page = $this->app->content_manager->get_by_id($_REQUEST['inherit_template_from']);
                 if (isset($inherit_layout_from_this_page['layout_file']) and $inherit_layout_from_this_page['layout_file'] != 'inherit') {
                     $is_layout_file = $inherit_layout_from_this_page['layout_file'];
                 }
                 if (isset($inherit_layout_from_this_page['layout_file']) and $inherit_layout_from_this_page['layout_file'] != 'inherit') {
                     $is_layout_file = $inherit_layout_from_this_page['layout_file'];
                 }
             }
         }
         $content['layout_file'] = $is_layout_file;
     }
     if ($is_custom_view and $is_custom_view != false) {
         $content['custom_view'] = $is_custom_view;
     }
     if (isset($content['is_active']) and ($content['is_active'] == 'n' or $content['is_active'] == 0)) {
         if ($this->app->user_manager->is_admin() == false) {
             $page_non_active = array();
             $page_non_active['id'] = 0;
             $page_non_active['content_type'] = 'page';
             $page_non_active['parent'] = '0';
             $page_non_active['url'] = $this->app->url_manager->string();
             $page_non_active['content'] = 'This page is not published!';
             $page_non_active['simply_a_file'] = 'clean.php';
             $page_non_active['layout_file'] = 'clean.php';
             $page_non_active['page_non_active'] = true;
             template_var('content', $page_non_active['content']);
             $content = $page_non_active;
         }
     } elseif (isset($content['is_deleted']) and $content['is_deleted'] == 1) {
         if ($this->app->user_manager->is_admin() == false) {
             $page_non_active = array();
             $page_non_active['id'] = 0;
             $page_non_active['content_type'] = 'page';
             $page_non_active['parent'] = '0';
             $page_non_active['url'] = $this->app->url_manager->string();
             $page_non_active['content'] = 'This page is deleted!';
             $page_non_active['simply_a_file'] = 'clean.php';
             $page_non_active['layout_file'] = 'clean.php';
             $page_non_active['page_is_deleted'] = true;
             template_var('content', $page_non_active['content']);
             $content = $page_non_active;
         }
     }
     if (isset($content['require_login']) and $content['require_login'] == 1) {
         if ($this->app->user_manager->id() == 0) {
             $page_non_active = array();
             $page_non_active['id'] = 0;
             $page_non_active['content_type'] = 'page';
             $page_non_active['parent'] = '0';
             $page_non_active['url'] = $this->app->url_manager->string();
             $page_non_active['content'] = ' <module type="users/login" class="user-require-login-on-view" /> ';
             $page_non_active['simply_a_file'] = 'clean.php';
             $page_non_active['layout_file'] = 'clean.php';
             $page_non_active['page_require_login'] = true;
             template_var('content', $page_non_active['content']);
             $content = $page_non_active;
         }
     }
     if (!defined('IS_HOME')) {
         if (isset($content['is_home']) and $content['is_home'] == 1) {
             define('IS_HOME', true);
         }
     }
     $this->app->content_manager->define_constants($content);
     event_trigger('mw.front', $content);
     event_trigger('mw_frontend', $content);
     $render_file = $this->app->template->get_layout($content);
     $content['render_file'] = $render_file;
     if (defined('TEMPLATE_DIR')) {
         $load_template_functions = TEMPLATE_DIR . 'functions.php';
         if (is_file($load_template_functions)) {
             include_once $load_template_functions;
         }
     }
     if ($this->return_data != false) {
         return $content;
     }
     if (isset($content['original_link']) and $content['original_link'] != '') {
         $content['original_link'] = str_ireplace('{site_url}', $this->app->url_manager->site(), $content['original_link']);
         $redirect = $this->app->format->prep_url($content['original_link']);
         if ($redirect != '') {
             return $this->app->url_manager->redirect($redirect);
         }
     }
     if (!isset($page['title'])) {
         $page['title'] = 'New page';
     }
     if (!isset($content['title'])) {
         $content['title'] = 'New content';
     }
     $category = false;
     if (defined('CATEGORY_ID')) {
         $category = $this->app->category_manager->get_by_id(CATEGORY_ID);
     }
     if ($render_file) {
         $render_params = array();
         if ($show_404_to_non_admin) {
             if (!is_admin()) {
                 $load_template_404 = template_dir() . '404.php';
                 if (is_file($load_template_404)) {
                     $render_file = $load_template_404;
                 }
             }
         }
         $render_params['render_file'] = $render_file;
         $render_params['page_id'] = PAGE_ID;
         $render_params['content_id'] = CONTENT_ID;
         $render_params['post_id'] = POST_ID;
         $render_params['category_id'] = CATEGORY_ID;
         $render_params['content'] = $content;
         $render_params['category'] = $category;
         $render_params['page'] = $page;
         $l = $this->app->template->render($render_params);
         if (is_object($l)) {
             return $l;
         }
         // used for preview from the admin wysiwyg
         if (isset($_REQUEST['isolate_content_field'])) {
             require_once MW_PATH . 'Utils' . DIRECTORY_SEPARATOR . 'lib' . DIRECTORY_SEPARATOR . 'phpQuery.php';
             $pq = \phpQuery::newDocument($l);
             $isolated_head = pq('head')->eq(0)->html();
             $found_field = false;
             if (isset($_REQUEST['isolate_content_field'])) {
                 foreach ($pq['[field=content]'] as $elem) {
                     $isolated_el = $l = pq($elem)->htmlOuter();
                 }
             }
             $is_admin = $this->app->user_manager->is_admin();
             if ($is_admin == true and isset($isolated_el) != false) {
                 $tb = mw_includes_path() . DS . 'toolbar' . DS . 'editor_tools' . DS . 'wysiwyg' . DS . 'index.php';
                 //$layout_toolbar = file_get_contents($filename);
                 $layout_toolbar = new \Microweber\View($tb);
                 $layout_toolbar = $layout_toolbar->__toString();
                 if ($layout_toolbar != '') {
                     if (strstr($layout_toolbar, '{head}')) {
                         if ($isolated_head != false) {
                             $layout_toolbar = str_replace('{head}', $isolated_head, $layout_toolbar);
                         }
                     }
                     if (strpos($layout_toolbar, '{content}')) {
                         $l = str_replace('{content}', $l, $layout_toolbar);
                     }
                     //$layout_toolbar = mw()->parser->process($layout_toolbar, $options = array('no_apc' => 1));
                 }
             }
         }
         $modify_content = event_trigger('on_load', $content);
         if ($is_editmode == true and !defined('IN_EDIT')) {
             define('IN_EDIT', true);
         }
         if (isset($is_quick_edit) and $is_quick_edit == true and !defined('QUICK_EDIT')) {
             define('QUICK_EDIT', true);
         }
         $l = $this->app->parser->process($l, $options = false);
         if ($preview_module_id != false) {
             $_REQUEST['embed_id'] = $preview_module_id;
         }
         if (isset($_REQUEST['embed_id'])) {
             $find_embed_id = trim($_REQUEST['embed_id']);
             $l = $this->app->parser->get_by_id($find_embed_id, $l);
         }
         $apijs_loaded = $this->app->template->get_apijs_url();
         //$apijs_loaded = $this->app->template->get_apijs_url() . '?id=' . CONTENT_ID;
         $is_admin = $this->app->user_manager->is_admin();
         $default_css = '<link rel="stylesheet" href="' . mw_includes_url() . 'default.css" type="text/css" />';
         $headers = event_trigger('site_header', TEMPLATE_NAME);
         $template_headers_append = '';
         $one = 1;
         if (is_array($headers)) {
             foreach ($headers as $modify) {
                 if ($modify != false and is_string($modify) and $modify != '') {
                     $template_headers_append = $template_headers_append . $modify;
                 }
             }
             if ($template_headers_append != false and $template_headers_append != '') {
                 $l = str_ireplace('</head>', $template_headers_append . '</head>', $l, $one);
             }
         }
         $template_headers_src = $this->app->template->head(true);
         $template_footer_src = $this->app->template->foot(true);
         $template_headers_src_callback = $this->app->template->head_callback($page);
         if (is_array($template_headers_src_callback) and !empty($template_headers_src_callback)) {
             foreach ($template_headers_src_callback as $template_headers_src_callback_str) {
                 if (is_string($template_headers_src_callback_str)) {
                     $template_headers_src = $template_headers_src . "\n" . $template_headers_src_callback_str;
                 }
             }
         }
         if (isset($page['created_by'])) {
             $author = $this->app->user_manager->get_by_id($page['created_by']);
             if (is_array($author) and isset($author['profile_url']) and $author['profile_url'] != false) {
                 $template_headers_src = $template_headers_src . "\n" . '<link rel="author" href="' . trim($author['profile_url']) . '" />' . "\n";
             }
         }
         if ($template_headers_src != false and is_string($template_headers_src)) {
             $l = str_ireplace('</head>', $template_headers_src . '</head>', $l, $one);
         }
         if ($template_footer_src != false and is_string($template_footer_src)) {
             $l = str_ireplace('</body>', $template_footer_src . '</body>', $l, $one);
         }
         $l = str_ireplace('<head>', '<head>' . $default_css, $l);
         if (!stristr($l, $apijs_loaded)) {
             //$apijs_settings_loaded = $this->app->template->get_apijs_settings_url() . '?id=' . CONTENT_ID . '&category_id=' . CATEGORY_ID;;
             $apijs_settings_loaded = $this->app->template->get_apijs_settings_url();
             $apijs_settings_script = "\r\n" . '<script src="' . $apijs_settings_loaded . '"></script>' . "\r\n";
             $apijs_settings_script .= '<script src="' . $apijs_loaded . '"></script>' . "\r\n";
             $l = str_ireplace('<head>', '<head>' . $apijs_settings_script, $l);
         }
         if (isset($content['active_site_template']) and $content['active_site_template'] == 'default' and $the_active_site_template != 'default' and $the_active_site_template != 'mw_default') {
             $content['active_site_template'] = $the_active_site_template;
         }
         if (isset($content['active_site_template']) and trim($content['active_site_template']) != '' and $content['active_site_template'] != 'default') {
             if (!defined('CONTENT_TEMPLATE')) {
                 define('CONTENT_TEMPLATE', $content['active_site_template']);
             }
             $custom_live_edit = TEMPLATES_DIR . DS . $content['active_site_template'] . DS . 'live_edit.css';
             $live_edit_css_folder = userfiles_path() . 'css' . DS . $content['active_site_template'] . DS;
             $live_edit_url_folder = userfiles_url() . 'css/' . $content['active_site_template'] . '/';
             $custom_live_edit = $live_edit_css_folder . DS . 'live_edit.css';
         } else {
             if (!defined('CONTENT_TEMPLATE')) {
                 define('CONTENT_TEMPLATE', $the_active_site_template);
             }
             //                if ($the_active_site_template == 'mw_default') {
             //                    $the_active_site_template = 'default';
             //                }
             $custom_live_edit = TEMPLATE_DIR . DS . 'live_edit.css';
             $live_edit_css_folder = userfiles_path() . 'css' . DS . $the_active_site_template . DS;
             $live_edit_url_folder = userfiles_url() . 'css/' . $the_active_site_template . '/';
             $custom_live_edit = $live_edit_css_folder . 'live_edit.css';
         }
         $custom_live_edit = normalize_path($custom_live_edit, false);
         if (is_file($custom_live_edit)) {
             $custom_live_editmtime = filemtime($custom_live_edit);
             $liv_ed_css = '<link rel="stylesheet" href="' . $live_edit_url_folder . 'live_edit.css?version=' . $custom_live_editmtime . '" id="mw-template-settings" type="text/css" />';
             $l = str_ireplace('</head>', $liv_ed_css . '</head>', $l);
         }
         $liv_ed_css = $this->app->template->get_custom_css_url();
         if ($liv_ed_css != false) {
             $liv_ed_css = '<link rel="stylesheet" href="' . $liv_ed_css . '" id="mw-custom-user-css" type="text/css" />';
             $l = str_ireplace('</head>', $liv_ed_css . '</head>', $l);
         }
         $website_head_tags = $this->app->option_manager->get('website_head', 'website');
         $rep_count = 1;
         if ($website_head_tags != false) {
             $l = str_ireplace('</head>', $website_head_tags . '</head>', $l, $rep_count);
         }
         if (defined('MW_VERSION')) {
             $generator_tag = "\n" . '<meta name="generator" content="Microweber" />' . "\n";
             $l = str_ireplace('</head>', $generator_tag . '</head>', $l, $rep_count);
         }
         if ($is_editmode == true and $this->isolate_by_html_id == false and !isset($_REQUEST['isolate_content_field'])) {
             if ($is_admin == true) {
                 $tb = mw_includes_path() . DS . 'toolbar' . DS . 'toolbar.php';
                 $layout_toolbar = new \Microweber\View($tb);
                 $is_editmode_basic = false;
                 $user_data = $this->app->user_manager->get();
                 if (isset($user_data['basic_mode']) and trim($user_data['basic_mode'] == 'y')) {
                     $is_editmode_basic = true;
                 }
                 if (isset($is_editmode_basic) and $is_editmode_basic == true) {
                     $layout_toolbar->assign('basic_mode', true);
                 } else {
                     $layout_toolbar->assign('basic_mode', false);
                 }
                 event_trigger('mw.live_edit');
                 $layout_toolbar = $layout_toolbar->__toString();
                 if ($layout_toolbar != '') {
                     $layout_toolbar = $this->app->parser->process($layout_toolbar, $options = array('no_apc' => 1));
                     $c = 1;
                     $l = str_ireplace('</body>', $layout_toolbar . '</body>', $l, $c);
                 }
                 $custom_live_edit = TEMPLATES_DIR . DS . TEMPLATE_NAME . DS . 'live_edit.php';
                 $custom_live_edit = normalize_path($custom_live_edit, false);
                 if (is_file($custom_live_edit)) {
                     $layout_live_edit = new \Microweber\View($custom_live_edit);
                     $layout_live_edit = $layout_live_edit->__toString();
                     if ($layout_live_edit != '') {
                         $l = str_ireplace('</body>', $layout_live_edit . '</body>', $l, $c);
                     }
                 }
             }
         } elseif ($is_editmode == false and $is_admin == true and mw()->user_manager->session_id() and !(mw()->user_manager->session_all() == false) and mw()->user_manager->session_get('back_to_editmode')) {
             if (!isset($_REQUEST['isolate_content_field']) and !isset($_REQUEST['content_id'])) {
                 $back_to_editmode = $this->app->user_manager->session_get('back_to_editmode');
                 if ($back_to_editmode == true) {
                     $tb = mw_includes_path() . DS . 'toolbar' . DS . 'toolbar_back.php';
                     $layout_toolbar = new \Microweber\View($tb);
                     $layout_toolbar = $layout_toolbar->__toString();
                     if ($layout_toolbar != '') {
                         $layout_toolbar = $this->app->parser->process($layout_toolbar, $options = array('no_apc' => 1));
                         $c = 1;
                         $l = str_ireplace('</body>', $layout_toolbar . '</body>', $l, $c);
                     }
                 }
             }
         }
         $l = str_replace('{TEMPLATE_URL}', TEMPLATE_URL, $l);
         $l = str_replace('{THIS_TEMPLATE_URL}', THIS_TEMPLATE_URL, $l);
         $l = str_replace('{DEFAULT_TEMPLATE_URL}', DEFAULT_TEMPLATE_URL, $l);
         $l = str_replace('%7BTEMPLATE_URL%7D', TEMPLATE_URL, $l);
         $l = str_replace('%7BTHIS_TEMPLATE_URL%7D', THIS_TEMPLATE_URL, $l);
         $l = str_replace('%7BDEFAULT_TEMPLATE_URL%7D', DEFAULT_TEMPLATE_URL, $l);
         $meta = array();
         $meta['content_image'] = '';
         $meta['description'] = '';
         if (is_home()) {
             $meta['content_url'] = site_url();
         } else {
             $meta['content_url'] = $this->app->url_manager->current(1);
         }
         $meta['og_description'] = $this->app->option_manager->get('website_description', 'website');
         $meta['og_type'] = 'website';
         $meta_content_id = PAGE_ID;
         if (CONTENT_ID > 0) {
             $meta_content_id = CONTENT_ID;
         }
         if ($meta_content_id > 0) {
             $meta = $this->app->content_manager->get_by_id($meta_content_id);
             $content_image = $this->app->media_manager->get_picture($meta_content_id);
             if ($content_image) {
                 $meta['content_image'] = $content_image;
             } else {
                 $meta['content_image'] = '';
             }
             $meta['content_url'] = $this->app->content_manager->link($meta_content_id);
             $meta['og_type'] = $meta['content_type'];
             if ($meta['og_type'] != 'page' and trim($meta['subtype']) != '') {
                 $meta['og_type'] = $meta['subtype'];
             }
             if ($meta['description'] != false and trim($meta['description']) != '') {
                 $meta['description'] = $meta['description'];
             } elseif ($meta['content'] != false and trim($meta['content']) != '') {
                 $meta['description'] = str_replace("\n", ' ', $this->app->format->limit($this->app->format->clean_html(strip_tags($meta['content'])), 500));
             }
             if (isset($meta['description']) and $meta['description'] != '') {
                 $meta['og_description'] = $meta['description'];
             } else {
                 $meta['og_description'] = trim($this->app->format->limit($this->app->format->clean_html(strip_tags($meta['content'])), 500));
             }
         } else {
             $meta['title'] = $this->app->option_manager->get('website_title', 'website');
             $meta['description'] = $this->app->option_manager->get('website_description', 'website');
             $meta['content_meta_keywords'] = $this->app->option_manager->get('website_keywords', 'website');
         }
         $meta['og_site_name'] = $this->app->option_manager->get('website_title', 'website');
         if (!empty($meta)) {
             if (isset($meta['content_meta_title']) and $meta['content_meta_title'] != '') {
                 $meta['title'] = $meta['content_meta_title'];
             } elseif (isset($meta['title']) and $meta['title'] != '') {
             } else {
                 $meta['title'] = $this->app->option_manager->get('website_title', 'website');
             }
             if (isset($meta['description']) and $meta['description'] != '') {
             } else {
                 $meta['description'] = $this->app->option_manager->get('website_description', 'website');
             }
             if (isset($meta['description']) and $meta['description'] != '') {
                 $meta['content_meta_description'] = strip_tags($meta['description']);
                 unset($meta['description']);
             } elseif (isset($meta['content']) and $meta['content'] != '') {
                 $meta['content_meta_description'] = strip_tags($meta['content']);
             } elseif (isset($meta['title']) and $meta['title'] != '') {
                 $meta['content_meta_description'] = strip_tags($meta['title']);
             }
             if (isset($meta['title']) and $meta['title'] != '') {
                 $meta['content_meta_title'] = strip_tags($meta['title']);
             } elseif (isset($found_mod) and $found_mod != false) {
                 $meta['content_meta_title'] = ucwords(str_replace('/', ' ', $found_mod));
             } else {
                 $meta['content_meta_title'] = ucwords(str_replace('/', ' ', $this->app->url_manager->segment(0)));
             }
             if (isset($meta['content_meta_keywords']) and $meta['content_meta_keywords'] != '') {
             } else {
                 $meta['content_meta_keywords'] = $this->app->option_manager->get('website_keywords', 'website');
             }
             if (is_array($meta)) {
                 foreach ($meta as $key => $item) {
                     if (is_string($item)) {
                         $item = html_entity_decode($item);
                         $item = strip_tags($item);
                         $item = str_replace('&amp;zwnj;', ' ', $item);
                         $item = str_replace('"', ' ', $item);
                         $item = str_replace("'", ' ', $item);
                         $item = str_replace('>', '', $item);
                         $item = str_replace('&amp;quot;', ' ', $item);
                         $item = str_replace('quot;', ' ', $item);
                         $item = str_replace('&amp;', ' ', $item);
                         $item = str_replace('amp;', ' ', $item);
                         $item = str_replace('nbsp;', ' ', $item);
                         $item = str_replace('#039;', ' ', $item);
                         $item = str_replace('&amp;nbsp;', ' ', $item);
                         $item = str_replace('&', ' ', $item);
                         $item = str_replace(';', ' ', $item);
                         $item = str_replace('  ', ' ', $item);
                         $item = str_replace(' ', ' ', $item);
                         $l = str_replace('{' . $key . '}', $item, $l);
                     } elseif ($item == false) {
                         $l = str_replace('{' . $key . '}', '', $l);
                     }
                 }
             }
         }
         if ($page != false and empty($this->page)) {
             $this->page = $page;
         }
         $l = execute_document_ready($l);
         event_trigger('frontend');
         $is_embed = $this->app->url_manager->param('embed');
         if ($is_embed != false) {
             $this->isolate_by_html_id = $is_embed;
         }
         if ($this->isolate_by_html_id != false) {
             $id_sel = $this->isolate_by_html_id;
             $this->isolate_by_html_id = false;
             require_once MW_PATH . 'Utils' . DIRECTORY_SEPARATOR . 'lib' . DIRECTORY_SEPARATOR . 'phpQuery.php';
             $pq = \phpQuery::newDocument($l);
             foreach ($pq['#' . $id_sel] as $elem) {
                 $l = pq($elem)->htmlOuter();
             }
         }
         if (mw()->user_manager->session_id() and !(mw()->user_manager->session_all() == false) and $is_editmode) {
             session_set('last_content_id', CONTENT_ID);
         }
         if ($output_cache_timeout != false) {
             $this->app->cache_manager->save($l, $output_cache_id, $output_cache_group);
         }
         if (isset($_REQUEST['debug'])) {
             if ($this->app->make('config')->get('app.debug')) {
                 $is_admin = $this->app->user_manager->is_admin();
                 if ($is_admin == true) {
                     include mw_includes_path() . 'debug.php';
                 }
             }
         }
         if ($show_404_to_non_admin) {
             $response = \Response::make($l);
             $response->setStatusCode(404);
             return $response;
         }
         return $l;
     } else {
         echo 'Error! Page is not found? Please login in the admin and make a page.';
         $this->app->cache_manager->clear();
         return;
     }
 }
Esempio n. 16
0
 /**
  * This function will process uploaded file
  *
  * @param array $uploaded_file
  * @param boolean $create_revision Create new revision or update last one
  * @param string $revision_comment Revision comment, if any
  * @return ProjectFileRevision
  */
 function handleUploadedFile($uploaded_file, $create_revision = true, $revision_comment = '')
 {
     $revision = null;
     if (!$create_revision) {
         $revision = $this->getLastRevision();
     }
     // if
     if (!$revision instanceof ProjectFileRevision) {
         $revision = new ProjectFileRevision();
         $revision->setFileId($this->getId());
         $revision->setRevisionNumber($this->getNextRevisionNumber());
         if (trim($revision_comment) == '' && $this->countRevisions() < 1) {
             $revision_comment = lang('initial versions');
         }
         // if
     }
     // if
     $revision->deleteThumb(false);
     // remove thumb
     // We have a file to handle!
     //executes only while uploading files
     if (!is_array($uploaded_file) || !isset($uploaded_file['name']) || !isset($uploaded_file['size']) || !isset($uploaded_file['type']) || (!isset($uploaded_file['tmp_name']) || !is_readable($uploaded_file['tmp_name']))) {
         throw new InvalidUploadError($uploaded_file);
     }
     // if
     if (isset($uploaded_file['error']) && $uploaded_file['error'] > UPLOAD_ERR_OK) {
         throw new InvalidUploadError($uploaded_file);
     }
     // if
     //eyedoc MOD
     $extension = get_file_extension(basename($uploaded_file['name']));
     if ($uploaded_file['type'] == 'application/octet-stream' && $extension == 'eyedoc') {
         $uploaded_file['type'] = 'text/html';
     }
     //eyedoc MOD
     // calculate hash
     if ($revision->columnExists('hash')) {
         $hash = hash_file("sha256", $uploaded_file['tmp_name']);
         $revision->setColumnValue('hash', $hash);
     }
     $repository_id = FileRepository::addFile($uploaded_file['tmp_name'], array('name' => $uploaded_file['name'], 'type' => $uploaded_file['type'], 'size' => $uploaded_file['size']));
     $revision->setRepositoryId($repository_id);
     $revision->deleteThumb(false);
     $revision->setFilesize($uploaded_file['size']);
     if (config_option('detect_mime_type_from_extension')) {
         $type = Mime_Types::instance()->get_type($extension);
         if ($type) {
             $revision->setTypeString($type);
         } else {
             $revision->setTypeString($uploaded_file['type']);
         }
     } else {
         $revision->setTypeString($uploaded_file['type']);
     }
     if (trim($extension)) {
         $file_type = FileTypes::getByExtension($extension);
         if ($file_type instanceof Filetype) {
             $revision->setFileTypeId($file_type->getId());
         }
         // if
     }
     // if
     $revision->setComment($revision_comment);
     $revision->save();
     $this->last_revision = $revision;
     // update last revision
     return $revision;
 }
Esempio n. 17
0
function submit_work($uid, $group_id, $id, $file) {

    global $groupPath, $langUploadError, $langUploadSuccess,
    $langBack, $m, $tool_content, $workPath,
    $group_sql, $webDir, $course_code, $is_editor;

    $ext = get_file_extension($file);
    $local_name = greek_to_latin('Group ' . $group_id . (empty($ext) ? '' : '.' . $ext));
    $original_filename = Database::get()->querySingle("SELECT filename FROM document WHERE $group_sql AND path = ?s", $file)->filename;
    $source = $groupPath . $file;
    $destination = work_secret($id) . "/$local_name";

    delete_submissions_by_uid($uid, $group_id, $id, $destination);

    if (is_dir($source)) {
        $original_filename = $original_filename . '.zip';
        $zip_filename = $webDir . 'courses/temp/' . safe_filename('zip');
        zip_documents_directory($zip_filename, $file, $is_editor);
        $source = $zip_filename;
    }
    if (copy($source, "$workPath/$destination")) {
        Database::get()->query("INSERT INTO assignment_submit (uid, assignment_id, submission_date,
                                submission_ip, file_path, file_name, comments, group_id, grade_comments)
                                VALUES (?d, ?d, NOW(), '$_SERVER[REMOTE_ADDR]', ?s, ?s, ?s, ?d, ''", $uid, $id, $destination, $original_filename, $_POST['comments'], $group_id);

        $tool_content .="<div class='alert alert-success'>$langUploadSuccess
			<br>$m[the_file] \"$original_filename\" $m[was_submitted]<br>
			<a href='index.php?course=$course_code'>$langBack</a></div><br>";
    } else {
        $tool_content .="<div class='alert alert-danger'>$langUploadError<br>
		<a href='index.php?course=$course_code'>$langBack</a></div><br>";
    }
}
Esempio n. 18
0
 public function delete($params)
 {
     if (!is_admin()) {
         error('must be admin');
     }
     $id = $params['id'];
     if ($id == null) {
         return array('error' => 'You have not provided filename to be deleted.');
     }
     $here = $this->get_bakup_location();
     $filename = $here . $id;
     $id = str_replace('..', '', $id);
     $filename = str_replace('..', '', $filename);
     $ext = get_file_extension(strtolower($filename));
     if ($ext != 'zip' and $ext != 'sql') {
         return array('error' => "You are now allowed to delete {$ext} files.");
     }
     if (is_file($filename)) {
         unlink($filename);
         return array('success' => "{$id} was deleted!");
     } else {
         $filename = $here . $id . '.sql';
         if (is_file($filename)) {
             unlink($filename);
             return array('success' => "{$id} was deleted!");
         }
     }
 }
Esempio n. 19
0
 public function save_content($data, $delete_the_cache = true)
 {
     if (is_string($data)) {
         $data = parse_params($data);
     }
     $mw_global_content_memory = array();
     $adm = $this->app->user_manager->is_admin();
     $table = $this->tables['content'];
     $table_data = $this->tables['content_data'];
     $checks = mw_var('FORCE_SAVE_CONTENT');
     $orig_data = $data;
     $stop = false;
     if ($stop == true) {
         return array('error' => 'You are not logged in as admin to save content!');
     }
     $cats_modified = false;
     if (!empty($data)) {
         if (!isset($data['id'])) {
             $data['id'] = 0;
         }
         if ($data['id'] == 0 and !isset($data['is_active'])) {
             $data['is_active'] = 1;
         }
         $this->app->event_manager->trigger('content.before.save', $data);
         if (intval($data['id']) == 0) {
             if (isset($data['subtype']) and $data['subtype'] == 'post' and !isset($data['content_type'])) {
                 $data['subtype'] = 'post';
                 $data['content_type'] = 'post';
             }
             if (!isset($data['subtype'])) {
                 $data['subtype'] = 'post';
             }
             if (!isset($data['content_type'])) {
                 $data['content_type'] = 'post';
             }
         }
     }
     if (isset($data['content_url']) and !isset($data['url'])) {
         $data['url'] = $data['content_url'];
     }
     if (!isset($data['parent']) and isset($data['content_parent'])) {
         $data['parent'] = $data['content_parent'];
     }
     if (isset($data['is_active'])) {
         if ($data['is_active'] === 'y') {
             $data['is_active'] = 1;
         } elseif ($data['is_active'] === 'n') {
             $data['is_active'] = 0;
         }
     }
     $data_to_save = $data;
     if (!isset($data['title']) and isset($data['content_title'])) {
         $data['title'] = $data['content_title'];
     }
     if (isset($data['title'])) {
         if ($data['title'] == '<br>' or $data['title'] == '<br />' or $data['title'] == '<br/>') {
             $data['title'] = '';
         }
         $data['title'] = htmlspecialchars($data['title'], ENT_QUOTES, "UTF-8");
         $data_to_save['title'] = $data['title'];
     }
     if (!isset($data['url']) and intval($data['id']) != 0) {
         $q = $this->get_by_id($data_to_save['id']);
         $thetitle = $q['title'];
         $q = $q['url'];
         $theurl = $q;
     } else {
         if (isset($data['url'])) {
             $theurl = $data['url'];
         } else {
             $theurl = $data['title'];
         }
         $thetitle = $data['title'];
     }
     if (isset($data['id']) and intval($data['id']) == 0) {
         if (!isset($data['is_deleted']) or $data['is_deleted'] == '') {
             $data_to_save['is_deleted'] = 0;
         } else {
             $data_to_save['is_deleted'] = $data['is_deleted'];
         }
         if (!isset($data['title']) or $data['title'] == '') {
             $data['title'] = "New page";
             if (isset($data['content_type']) and $data['content_type'] != 'page') {
                 $data['title'] = "New " . $data['content_type'];
                 if (isset($data['subtype']) and $data['subtype'] != 'page' and $data['subtype'] != 'post' and $data['subtype'] != 'static' and $data['subtype'] != 'dynamic') {
                     $data['title'] = "New " . $data['subtype'];
                 }
             }
             $data_to_save['title'] = $data['title'];
         }
     }
     if (isset($data['url']) == false or $data['url'] == '') {
         if (isset($data['title']) != false and intval($data['id']) == 0) {
             $data['url'] = $this->app->url_manager->slug($data['title']);
             if ($data['url'] == '') {
                 $data['url'] = date("Y-M-d-His");
             }
         }
     }
     $url_changed = false;
     if (isset($data['url']) != false and is_string($data['url'])) {
         $search_weird_chars = array('%E2%80%99', '%E2%80%99', '%E2%80%98', '%E2%80%9C', '%E2%80%9D');
         $str = $data['url'];
         $good[] = 9;
         #tab
         $good[] = 10;
         #nl
         $good[] = 13;
         #cr
         for ($a = 32; $a < 127; $a++) {
             $good[] = $a;
         }
         $newstr = '';
         $len = strlen($str);
         for ($b = 0; $b < $len + 1; $b++) {
             if (isset($str[$b]) and in_array(ord($str[$b]), $good)) {
                 $newstr .= $str[$b];
             }
         }
         $newstr = str_replace('--', '-', $newstr);
         $newstr = str_replace('--', '-', $newstr);
         if ($newstr == '-' or $newstr == '--') {
             $newstr = 'post-' . date('YmdHis');
         }
         $data['url'] = $newstr;
         $url_changed = true;
         $data_to_save['url'] = $data['url'];
     }
     if (isset($data['category']) or isset($data['categories'])) {
         $cats_modified = true;
     }
     $table_cats = $this->tables['categories'];
     if (isset($data_to_save['title']) and $data_to_save['title'] != '' and (!isset($data['url']) or trim($data['url']) == '')) {
         $data['url'] = $this->app->url_manager->slug($data_to_save['title']);
     }
     if (isset($data['url']) and $data['url'] != false) {
         if (trim($data['url']) == '') {
             $data['url'] = $this->app->url_manager->slug($data['title']);
         }
         $data['url'] = $this->app->database_manager->escape_string($data['url']);
         $date123 = date("YmdHis");
         $get = array();
         $get['url'] = $data['url'];
         $get['single'] = true;
         $q = $this->get($get);
         if (!empty($q)) {
             if ($data['id'] != $q['id']) {
                 $data['url'] = $data['url'] . '-' . $date123;
                 $data_to_save['url'] = $data['url'];
             }
         }
         if (isset($data_to_save['url']) and strval($data_to_save['url']) == '' and isset($data_to_save['quick_save']) == false) {
             $data_to_save['url'] = $data_to_save['url'] . '-' . $date123;
         }
         if (isset($data_to_save['title']) and strval($data_to_save['title']) == '' and isset($data_to_save['quick_save']) == false) {
             $data_to_save['title'] = 'post-' . $date123;
         }
         if (isset($data_to_save['url']) and strval($data_to_save['url']) == '' and isset($data_to_save['quick_save']) == false) {
             $data_to_save['url'] = strtolower(reduce_double_slashes($data['url']));
         }
     }
     if (isset($data_to_save['url']) and is_string($data_to_save['url'])) {
         if ($data_to_save['url'] == '') {
             $data_to_save['url'] = date("Y-M-d-His");
         }
         $data_to_save['url'] = str_replace(site_url(), '', $data_to_save['url']);
     }
     if (isset($data['created_at'])) {
         $data_to_save['created_at'] = $data['created_at'];
     }
     if (isset($data['updated_at'])) {
         $data_to_save['updated_at'] = $data['updated_at'];
     }
     $data_to_save_options = array();
     if (isset($data_to_save['is_home']) and $data_to_save['is_home'] == 'y') {
         $data_to_save['is_home'] = 1;
     } elseif (isset($data_to_save['is_home']) and $data_to_save['is_home'] == 'n') {
         $data_to_save['is_home'] = 0;
     }
     if (isset($data_to_save['is_shop']) and $data_to_save['is_shop'] === 'y') {
         $data_to_save['is_shop'] = 1;
     } elseif (isset($data_to_save['is_shop']) and $data_to_save['is_shop'] === 'n') {
         $data_to_save['is_shop'] = 0;
     }
     if (isset($data_to_save['require_login']) and $data_to_save['require_login'] === 'y') {
         $data_to_save['require_login'] = 1;
     } elseif (isset($data_to_save['require_login']) and $data_to_save['require_login'] === 'n') {
         $data_to_save['require_login'] = 0;
     }
     if (isset($data_to_save['is_home']) and $data_to_save['is_home'] == 1) {
         if ($adm == true) {
             $q = Content::where('is_home', 1)->update(array('is_home' => 0));
         } else {
             $data_to_save['is_home'] = 0;
         }
     }
     if (isset($data_to_save['content_type']) and strval($data_to_save['content_type']) == 'post') {
         if (isset($data_to_save['subtype']) and strval($data_to_save['subtype']) == 'static') {
             $data_to_save['subtype'] = 'post';
         } else {
             if (isset($data_to_save['subtype']) and strval($data_to_save['subtype']) == 'dynamic') {
                 $data_to_save['subtype'] = 'post';
             }
         }
     }
     if (isset($data_to_save['subtype']) and strval($data_to_save['subtype']) == 'dynamic') {
         $check_ex = false;
         if (isset($data_to_save['subtype_value']) and trim($data_to_save['subtype_value']) != '' and intval($data_to_save['subtype_value']) > 0) {
             $check_ex = $this->app->category_manager->get_by_id(intval($data_to_save['subtype_value']));
         }
         if ($check_ex == false) {
             if (isset($data_to_save['id']) and intval(trim($data_to_save['id'])) > 0) {
                 $test2 = $this->app->category_manager->get('data_type=category&rel_type=content&rel_id=' . intval($data_to_save['id']));
                 if (isset($test2[0])) {
                     $check_ex = $test2[0];
                     $data_to_save['subtype_value'] = $test2[0]['id'];
                 }
             }
             unset($data_to_save['subtype_value']);
         }
     }
     $par_page = false;
     if (isset($data_to_save['content_type']) and strval($data_to_save['content_type']) == 'post') {
         if (isset($data_to_save['parent']) and intval($data_to_save['parent']) > 0) {
             $par_page = $this->get_by_id($data_to_save['parent']);
         }
         if (is_array($par_page)) {
             $change_to_dynamic = true;
             if (isset($data_to_save['is_home']) and $data_to_save['is_home'] == 1) {
                 $change_to_dynamic = false;
             }
             if ($change_to_dynamic == true and $par_page['subtype'] == 'static') {
                 $par_page_new = array();
                 $par_page_new['id'] = $par_page['id'];
                 $par_page_new['subtype'] = 'dynamic';
                 $par_page_new = $this->app->database_manager->save($table, $par_page_new);
                 $cats_modified = true;
             }
             if (!isset($data_to_save['categories'])) {
                 $data_to_save['categories'] = '';
             }
             if (is_string($data_to_save['categories']) and isset($par_page['subtype_value']) and intval($par_page['subtype_value']) != 0) {
                 $data_to_save['categories'] = $data_to_save['categories'] . ', ' . intval($par_page['subtype_value']);
             }
         }
         $c1 = false;
         if (isset($data_to_save['category']) and !isset($data_to_save['categories'])) {
             $data_to_save['categories'] = $data_to_save['category'];
         }
         if (isset($data_to_save['categories']) and $par_page == false) {
             if (is_string($data_to_save['categories'])) {
                 $c1 = explode(',', $data_to_save['categories']);
                 if (is_array($c1)) {
                     foreach ($c1 as $item) {
                         $item = intval($item);
                         if ($item > 0) {
                             $cont_cat = $this->get('limit=1&content_type=page&subtype_value=' . $item);
                             if (isset($cont_cat[0]) and is_array($cont_cat[0])) {
                                 $cont_cat = $cont_cat[0];
                                 if (isset($cont_cat["subtype_value"]) and intval($cont_cat["subtype_value"]) > 0) {
                                     $data_to_save['parent'] = $cont_cat["id"];
                                     break;
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     if (isset($data_to_save['content'])) {
         if (trim($data_to_save['content']) == '' or $data_to_save['content'] == false) {
             $data_to_save['content'] = null;
         } else {
             if (isset($data['download_remote_images']) and $data['download_remote_images'] != false and $adm == true) {
                 $site_url = $this->app->url_manager->site();
                 $images = mw()->parser->query($data_to_save['content'], 'img');
                 $to_download = array();
                 $to_replace = array();
                 $possible_sources = array();
                 if (isset($data['insert_content_image']) and $data['insert_content_image'] != false and isset($data['content'])) {
                     $data['content'] = "<img src='{$data['insert_content_image']}' /> " . $data['content'];
                 }
                 if (!empty($images)) {
                     foreach ($images as $image) {
                         $srcs = array();
                         preg_match('/src="([^"]*)"/i', $image, $srcs);
                         if (!empty($srcs) and isset($srcs[1]) and $srcs[1] != false) {
                             $possible_sources[] = $srcs[1];
                         }
                     }
                 }
                 if (!empty($possible_sources)) {
                     foreach ($possible_sources as $image_src) {
                         if (!stristr($image_src, $site_url)) {
                             $to_replace[] = $image_src;
                             $image_src = strtok($image_src, '?');
                             $ext = get_file_extension($image_src);
                             switch (strtolower($ext)) {
                                 case 'jpg':
                                 case 'jpeg':
                                 case 'png':
                                 case 'gif':
                                 case 'svg':
                                     $to_download[] = $image_src;
                                     break;
                                 default:
                                     break;
                             }
                         }
                     }
                 }
                 if (!empty($to_download)) {
                     $to_download = array_unique($to_download);
                     if (!empty($to_download)) {
                         foreach ($to_download as $src) {
                             $dl_dir = media_base_path() . 'downloaded' . DS;
                             if (!is_dir($dl_dir)) {
                                 mkdir_recursive($dl_dir);
                             }
                             $dl_file = $dl_dir . md5($src) . basename($src);
                             if (!is_file($dl_file)) {
                                 $is_dl = $this->app->url_manager->download($src, false, $dl_file);
                             }
                             if (is_file($dl_file)) {
                                 $url_local = dir2url($dl_file);
                                 $data_to_save['content'] = str_ireplace($src, $url_local, $data_to_save['content']);
                             }
                         }
                     }
                 }
             }
             $data_to_save['content'] = mw()->parser->make_tags($data_to_save['content']);
         }
     }
     if (!isset($data_to_save['updated_at'])) {
         $data_to_save['updated_at'] = date("Y-m-d H:i:s");
     }
     if (isset($data_to_save['id']) and intval($data_to_save['id']) == 0 or !isset($data_to_save['id'])) {
         if (!isset($data_to_save['position']) or intval($data_to_save['position']) == 0) {
             $pos_params = array();
             $pos_params['table'] = 'content';
             if (isset($data_to_save['content_type']) and strval($data_to_save['content_type']) == 'page') {
                 $pos_params['content_type'] = $data_to_save['content_type'];
                 $pos_params['min'] = 'position';
             } else {
                 $pos_params['max'] = 'position';
             }
             $get_max_pos = mw()->database_manager->get($pos_params);
             if (is_null($get_max_pos)) {
                 $data_to_save['position'] = 1;
             } else {
                 if (is_int($get_max_pos) or is_string($get_max_pos)) {
                     if (isset($data_to_save['content_type']) and strval($data_to_save['content_type']) == 'page') {
                         $data_to_save['position'] = intval($get_max_pos) - 1;
                     } else {
                         $data_to_save['position'] = intval($get_max_pos) + 1;
                     }
                 }
             }
         }
         $data_to_save['posted_at'] = $data_to_save['updated_at'];
     }
     $cats_modified = true;
     if (isset($data_to_save['url']) and $data_to_save['url'] == $this->app->url_manager->site()) {
         unset($data_to_save['url']);
     }
     $data_to_save['allow_html'] = true;
     $this->no_cache = true;
     //clean some fields
     if (isset($data_to_save['custom_field_type']) and isset($data_to_save['value'])) {
         unset($data_to_save['custom_field_type']);
         unset($data_to_save['value']);
     }
     if (isset($data_to_save['custom_field_help_text'])) {
         unset($data_to_save['custom_field_help_text']);
         unset($data_to_save['custom_field_help_text']);
     }
     if (isset($data_to_save['custom_field_is_active'])) {
         unset($data_to_save['custom_field_is_active']);
     }
     if (isset($data_to_save['name'])) {
         unset($data_to_save['name']);
     }
     if (isset($data_to_save['values'])) {
         unset($data_to_save['values']);
     }
     if (isset($data_to_save['value'])) {
         unset($data_to_save['value']);
     }
     if (isset($data_to_save['title'])) {
         $url_changed = true;
     }
     $data_to_save['table'] = $table;
     $data_fields = array();
     if (!empty($orig_data)) {
         $data_str = 'data_';
         $data_str_l = strlen($data_str);
         foreach ($orig_data as $k => $v) {
             if (is_string($k)) {
                 if (strlen($k) > $data_str_l) {
                     $rest = substr($k, 0, $data_str_l);
                     $left = substr($k, $data_str_l, strlen($k));
                     if ($rest == $data_str) {
                         if (!isset($data_to_save['data_fields'])) {
                             $data_to_save['data_fields'] = array();
                         }
                         $data_to_save['data_fields'][$left] = $v;
                     }
                 }
             }
         }
     }
     if (isset($data_to_save['parent']) and $data_to_save['parent'] != 0) {
         if (isset($data_to_save['id']) and $data_to_save['id'] != 0) {
             if ($data_to_save['parent'] == $data_to_save['id']) {
                 $data_to_save['parent'] = 0;
             }
         }
     }
     $save = $this->app->database->extended_save($table, $data_to_save);
     $id = $save;
     if (isset($data_to_save['parent']) and $data_to_save['parent'] != 0) {
         $upd_posted = array();
         $upd_posted['posted_at'] = $data_to_save['updated_at'];
         $upd_posted['id'] = $data_to_save['parent'];
         $save_posted = $this->app->database_manager->save($table, $upd_posted);
     }
     $after_save = $data_to_save;
     $after_save['id'] = $id;
     $this->app->event_manager->trigger('content.after.save', $after_save);
     $this->app->cache_manager->delete('content/' . $save);
     $this->app->cache_manager->delete('content_fields/global');
     if ($url_changed != false) {
         $this->app->cache_manager->delete('menus');
         $this->app->cache_manager->delete('categories');
     }
     if (!isset($data_to_save['images']) and isset($data_to_save['pictures'])) {
         $data_to_save['images'] = $data_to_save['pictures'];
     }
     if (isset($data_to_save['images']) and is_string($data_to_save['images'])) {
         $data_to_save['images'] = explode(',', $data_to_save['images']);
     }
     if (isset($data_to_save['images']) and is_array($data_to_save['images']) and !empty($data_to_save['images'])) {
         $images_to_save = $data_to_save['images'];
         foreach ($images_to_save as $image_to_save) {
             if (is_string($image_to_save)) {
                 $image_to_save = trim($image_to_save);
                 if ($image_to_save != '') {
                     $save_media = array();
                     $save_media['content_id'] = $id;
                     $save_media['filename'] = $image_to_save;
                     $check = $this->app->media_manager->get($save_media);
                     $save_media['media_type'] = 'picture';
                     if ($check == false) {
                         $this->app->media_manager->save($save_media);
                     }
                 }
             } elseif (is_array($image_to_save) and !empty($image_to_save)) {
                 $save_media = $image_to_save;
                 $save_media['content_id'] = $id;
                 $this->app->media_manager->save($save_media);
             }
         }
     }
     if (isset($data_to_save['add_content_to_menu']) and is_array($data_to_save['add_content_to_menu'])) {
         foreach ($data_to_save['add_content_to_menu'] as $menu_id) {
             $ids_to_save = $save;
             $this->add_content_to_menu($ids_to_save, $menu_id);
         }
     }
     $custom_field_table = $this->tables['custom_fields'];
     $custom_field_table = mw()->database_manager->real_table_name($custom_field_table);
     $sid = mw()->user_manager->session_id();
     $media_table = $this->tables['media'];
     $media_table = mw()->database_manager->real_table_name($media_table);
     if ($sid != false and $sid != '' and $id != false) {
         $clean = " UPDATE {$custom_field_table} SET\n            rel_type =\"content\" ,\n            rel_id =\"{$id}\"\n            WHERE\n\n              (rel_id=0 OR rel_id IS NULL OR rel_id =\"0\")\n            AND rel_type =\"content\"\n\t        ";
         $this->app->database_manager->q($clean);
         $clean = " UPDATE {$media_table} SET\n            rel_id =\"{$id}\"\n            WHERE\n            session_id =\"{$sid}\"\n            AND rel_type =\"content\" AND (rel_id=0 OR rel_id IS NULL)\n            ";
         $this->app->database_manager->q($clean);
     }
     $this->app->cache_manager->delete('custom_fields');
     $this->app->cache_manager->delete('custom_fields_values');
     $this->app->cache_manager->delete('media/global');
     if (isset($data_to_save['parent']) and intval($data_to_save['parent']) != 0) {
         $this->app->cache_manager->delete('content' . DIRECTORY_SEPARATOR . intval($data_to_save['parent']));
     }
     if (isset($data_to_save['id']) and intval($data_to_save['id']) != 0) {
         $this->app->cache_manager->delete('content' . DIRECTORY_SEPARATOR . intval($data_to_save['id']));
     }
     $this->app->cache_manager->delete('content' . DIRECTORY_SEPARATOR . 'global');
     $this->app->cache_manager->delete('content' . DIRECTORY_SEPARATOR . '0');
     $this->app->cache_manager->delete('content_fields/global');
     $this->app->cache_manager->delete('content');
     $this->app->cache_manager->delete('categories/global');
     $this->app->cache_manager->delete('categories_items/global');
     if ($cats_modified != false) {
         if (isset($c1) and is_array($c1)) {
             foreach ($c1 as $item) {
                 $item = intval($item);
                 if ($item > 0) {
                     $this->app->cache_manager->delete('categories/' . $item);
                 }
             }
         }
     }
     event_trigger('mw_save_content', $save);
     return $id;
 }
Esempio n. 20
0
        preg_match('/[^?]*/', $filenamepart, $matches);
        return strtolower($matches[0]);
    }
}
$num = rand(0, pow(10, 5)) . '-';
// 5 digit random number to prefix game name
$thumb_types = array('gif', 'jpeg', 'jpg', 'png');
$file_types = array('swf', 'unity3d', 'dcr', 'mov', 'mpg', 'avi', 'flv', 'wmv');
if (isset($_POST['add'])) {
    include_once "../includes/db_functions.inc.php";
    if (!isset($_FILES['file']['name']) || !isset($_FILES['thumbnail']['name'])) {
        echo '<center>No file or thumbnail detected</center>';
        exit;
    }
    $thumb_ext = get_file_extension($_FILES["thumbnail"]["name"]) or die("<center>You must include a game pic.</center>");
    $file_ext = get_file_extension($_FILES["file"]["name"]) or die("<center>You must include a game file.</center>");
    if (in_array($thumb_ext, $thumb_types) || in_array($file_ext, $file_types)) {
        if ($_FILES["file"]["error"] > 0) {
            echo "<center>Return Code: " . $_FILES["thumbnail"]["error"] . "</center>";
        } else {
            move_uploaded_file($_FILES["thumbnail"]["tmp_name"], $setting['sitepath'] . "/img/" . $num . preg_replace('/[^a-zA-Z0-9.-_]/', '', $_FILES["thumbnail"]["name"]));
            move_uploaded_file($_FILES["file"]["tmp_name"], $setting['sitepath'] . "/swf/" . $num . preg_replace('/[^a-zA-Z0-9.-_]/', '', $_FILES["file"]["name"]));
            $img = yasDB_admin("img/" . $num . preg_replace('/[^a-zA-Z0-9.-_]/', '', $_FILES["thumbnail"]["name"]));
            $file = yasDB_admin("swf/" . $num . preg_replace('/[^a-zA-Z0-9.-_]/', '', $_FILES["file"]["name"]));
            $desc = yasDB_admin(trim($_POST['description']));
            $title = yasDB_admin($_POST['title']);
            $height = intval($_POST['height']);
            $width = intval($_POST['width']);
            $instr = yasDB_admin(trim($_POST['instructions']));
            $keywords = yasDB_admin($_POST['keywords']);
            if ($file_ext == 'swf') {
Esempio n. 21
0
<?php

require_once 'include/db_connect.php';
require_once 'functions.php';
$aid = $_POST['id'];
if (!isset($_FILES['image']['tmp_name'])) {
} else {
    $file = $_FILES['image']['tmp_name'];
    $size = $_FILES['image']['size'];
    $file_name = "../video/" . $_FILES["image"]["name"];
    $exet = get_file_extension($file_name);
    if ($size <= 100000000 && ($exet == "mp4" || "flv" || "3gp")) {
        $image = addslashes(file_get_contents($_FILES['image']['tmp_name']));
        $image_name = addslashes($_FILES['image']['name']);
        move_uploaded_file($_FILES["image"]["tmp_name"], "video/" . $_FILES["image"]["name"]);
        $location = "video/" . $_FILES["image"]["name"];
        $save = mysql_query("insert into galery(user_id,video) values('{$aid}','{$location}')");
        if (!$save) {
            die("error" . mysql_error());
        }
        header("location:vgal.php");
        exit;
    }
}
?>



Esempio n. 22
0
 function extended_save_images($params)
 {
     if ($this->extended_save_has_permission()) {
         event_trigger('mw.database.extended_save_images', $params);
         $data_to_save = $params;
         if (isset($data_to_save['images'])) {
             $data_fields = $data_to_save['images'];
             if (is_array($data_fields) and !empty($data_fields)) {
                 foreach ($data_fields as $k => $v) {
                     if (isset($v['filename'])) {
                         $save_cat_item = array();
                         $save_cat_item['rel_type'] = $data_to_save['table'];
                         $save_cat_item['rel_id'] = $data_to_save['id'];
                         if (isset($data_to_save['download_remote_images']) and $data_to_save['download_remote_images'] != false) {
                             $is_url = false;
                             if (filter_var($v['filename'], FILTER_VALIDATE_URL)) {
                                 if (!stristr($v['filename'], site_url())) {
                                     $image_src = $v['filename'];
                                     $to_download = false;
                                     $image_src = strtok($image_src, '?');
                                     $ext = get_file_extension($image_src);
                                     switch (strtolower($ext)) {
                                         case 'jpg':
                                         case 'jpeg':
                                         case 'png':
                                         case 'gif':
                                         case 'svg':
                                             $to_download = $image_src;
                                             break;
                                         default:
                                             break;
                                     }
                                     if ($to_download != false) {
                                         $output_fn = 'ext_save' . crc32($to_download) . '.' . $ext;
                                         $relative = 'downloaded' . DS . $save_cat_item['rel_type'] . DS . $save_cat_item['rel_id'] . DS;
                                         $output = media_base_path() . $relative;
                                         $output_relative = media_base_url() . str_replace(DS, '/', $relative);
                                         $output = normalize_path($output, true);
                                         if (!is_dir($output)) {
                                             mkdir_recursive($output);
                                         }
                                         $output_file = $output . $output_fn;
                                         if (!is_file($output_file)) {
                                             $download = new \Microweber\Utils\Http();
                                             $download->set_url($image_src);
                                             $download->download($output_file);
                                         }
                                         $v['filename'] = $output_relative . $output_fn;
                                         $v['filename'] = str_replace(site_url(), '{SITE_URL}', $v['filename']);
                                     }
                                 }
                             }
                         }
                         $save_cat_item["filename"] = $v['filename'];
                         $check = $this->app->media_manager->get($save_cat_item);
                         if ($check == false) {
                             if (isset($v['position'])) {
                                 $save_cat_item["position"] = $v['position'];
                             }
                             $save = $this->app->media_manager->save($save_cat_item);
                         }
                     }
                 }
             }
         }
     }
 }
Esempio n. 23
0
function upload_user_photo($user_id)
{
    $file_extension = get_file_extension($_FILES['file']['name']);
    if (db_easy_count("SELECT * FROM `phpbb_avatars` WHERE `user_id`={$user_id}") > 0) {
        db_query("DELETE FROM `phpbb_avatars` WHERE `user_id`={$user_id}");
    }
    db_query("INSERT INTO `phpbb_avatars` SET `user_id`={$user_id}, `extension`='{$file_extension}'");
    $file_id = db_insert_id();
    $uploadfile = $_SERVER['DOCUMENT_ROOT'] . "images/avatars/upload/5748d7ff6b4d48da44e8a6525604c781_" . $file_id . "." . $file_extension;
    if (move_uploaded_file($_FILES['file']['tmp_name'], $uploadfile)) {
        $image_size = getimagesize($uploadfile);
        db_query("UPDATE `phpbb_users` SET `user_avatar`='{$file_id}.{$file_extension}', `user_avatar_type`=1, `user_avatar_width`={$image_size[0]}, `user_avatar_height`={$image_size[1]} WHERE `user_id`={$user_id}");
        return template_get("message", array('message' => "Фотография обновлена"));
    } else {
        return template_get("errormessage", array('message' => "Ошибка"));
    }
}
Esempio n. 24
0
/**
 * Fifth installation step: FTP upload (not used for manual installer).
 *
 * @return array		A pair: progress report/ui, and number of files uploaded so far (or -1 meaning all uploaded)
 */
function step_5_ftp()
{
    global $FILE_ARRAY, $DIR_ARRAY;
    if (count($_POST) == 0) {
        exit(do_lang('INST_POST_ERROR'));
    }
    if (!is_suexec_like()) {
        if (!function_exists('ftp_connect')) {
            warn_exit(do_lang_tempcode('NO_PHP_FTP'));
        }
        $ftp_domain = trim(post_param('ftp_domain'));
        if (strpos($ftp_domain, 'ftp://') !== false) {
            warn_exit(do_lang_tempcode('FTP_DOMAIN_NOT_LIKE_THIS'));
        }
        $port = 21;
        if (strpos($ftp_domain, ':') !== false) {
            list($ftp_domain, $_port) = explode(':', $ftp_domain, 2);
            $port = intval($_port);
        }
        $conn = false;
        if (function_exists('ftp_ssl_connect')) {
            $conn = @ftp_ssl_connect($ftp_domain, $port);
        }
        $ssl = $conn !== false;
        $username = trim(post_param('ftp_username'));
        $password = trim(post_param('ftp_password'));
        if ($ssl && @ftp_login($conn, $username, $password) === false) {
            $conn = false;
            $ssl = false;
        }
        if ($conn === false) {
            $conn = ftp_connect($ftp_domain, $port);
        }
        if ($conn === false) {
            warn_exit(do_lang_tempcode('NO_FTP_CONNECT'));
        }
        if (!$ssl && !@ftp_login($conn, $username, $password)) {
            warn_exit(do_lang_tempcode('NO_FTP_LOGIN', @strval($php_errormsg)));
        }
        $ftp_folder = post_param('ftp_folder');
        if (substr($ftp_folder, -1) != '/') {
            $ftp_folder .= '/';
        }
        if (!@ftp_chdir($conn, $ftp_folder)) {
            warn_exit(do_lang_tempcode('NO_FTP_DIR', @strval($php_errormsg), '1'));
        }
        $files = @ftp_nlist($conn, '.');
        if ($files === false) {
            $files = array();
            if (@ftp_rename($conn, 'install.php', 'install.php')) {
                $files = array('install.php', 'data.ocp');
            }
        }
        if (!in_array('install.php', $files)) {
            warn_exit(do_lang_tempcode('NO_FTP_DIR', @strval($php_errormsg), '2'));
        }
        $overwrite_ok = !file_exists(get_file_base() . '/ocp_inst_tmp/tmp');
        // Because if the file doesn't exist, the step completed in full - we DON'T want to overwrite if it didn't, because the step probably timed out and by refreshing we complete the step in pieces
        if (!file_exists('ocp_inst_tmp')) {
            // Make temporary directory
            if (!in_array('ocp_inst_tmp', $files) && !is_string(@ftp_mkdir($conn, 'ocp_inst_tmp'))) {
                warn_exit(do_lang_tempcode('NO_FTP_ACCESS'));
            }
            @ftp_site($conn, 'CHMOD 0777 ocp_inst_tmp');
        }
        if (!is_writable_wrap('ocp_inst_tmp')) {
            warn_exit(do_lang_tempcode('MANUAL_CHMOD_TMP_FILE'));
        }
        // Test tmp file isn't currently being used by another iteration of process (race issue, causing horrible corruption)
        $file_size_before = @filesize(get_file_base() . '/ocp_inst_tmp/tmp');
        sleep(1);
        $file_size_after = @filesize(get_file_base() . '/ocp_inst_tmp/tmp');
        if ($file_size_before !== $file_size_after) {
            warn_exit(do_lang_tempcode('DATA_FILE_CONFLICT'));
        }
        // Test tmp file isn't currently being used by another iteration of process (race issue, causing horrible corruption)
        $lock_myfile = fopen(get_file_base() . '/ocp_inst_tmp/tmp', 'ab');
        if (!defined('PHALANGER')) {
            if (!flock($lock_myfile, LOCK_EX)) {
                warn_exit(do_lang_tempcode('DATA_FILE_CONFLICT'));
            }
        }
        $file_size_before = @filesize(get_file_base() . '/ocp_inst_tmp/tmp');
        sleep(1);
        $file_size_after = @filesize(get_file_base() . '/ocp_inst_tmp/tmp');
        if ($file_size_before !== $file_size_after) {
            warn_exit(do_lang_tempcode('DATA_FILE_CONFLICT'));
        }
        fclose($lock_myfile);
    } else {
        $overwrite_ok = true;
        $files = array();
        if (file_exists(get_file_base() . '/info.php')) {
            $files[] = 'info.php';
        }
    }
    // Make folders
    $langs1 = get_dir_contents('lang');
    $langs2 = get_dir_contents('lang_custom');
    $langs = array_merge($langs1, $langs2);
    foreach ($DIR_ARRAY as $dir) {
        if (strpos($dir, '/' . fallback_lang()) !== false) {
            foreach (array_keys($langs) as $lang) {
                if ($lang == fallback_lang() || strpos($lang, '.') !== false) {
                    continue;
                }
                if (is_suexec_like()) {
                    @mkdir(get_file_base() . '/' . str_replace('/' . fallback_lang(), '/' . $lang, $dir), 0777);
                    fix_permissions(get_file_base() . '/' . str_replace('/' . fallback_lang(), '/' . $lang, $dir), 0777);
                } else {
                    @ftp_mkdir($conn, str_replace('/' . fallback_lang(), '/' . $lang, $dir));
                    @ftp_site($conn, 'CHMOD 755 ' . str_replace('/' . fallback_lang(), '/' . $lang, $dir));
                }
            }
        }
        if (is_suexec_like()) {
            @mkdir(get_file_base() . '/' . $dir, 0777);
            fix_permissions(get_file_base() . '/' . $dir, 0777);
        } else {
            @ftp_mkdir($conn, $dir);
            if ($dir == 'exports/mods' && !is_suexec_like()) {
                @ftp_site($conn, 'CHMOD 777 ' . $dir);
            } else {
                @ftp_site($conn, 'CHMOD 755 ' . $dir);
            }
        }
    }
    // Upload files
    $count = file_array_count();
    $php_perms = fileperms(get_file_base() . '/install.php');
    $start_pos = get_param_integer('start_from', 0);
    $done_all = false;
    $time_start = time();
    $max_time = intval(round(floatval(ini_get('max_execution_time')) / 1.5));
    $max = post_param_integer('max', is_suexec_like() ? 5000 : 1000);
    for ($i = $start_pos; $i < $start_pos + $max; $i++) {
        list($filename, $contents) = file_array_get_at($i);
        if (is_string($contents)) {
            $file_size = strlen($contents);
        } else {
            list($file_size, $dump_myfile, $dump_offset) = $contents;
        }
        if ($filename != 'info.php' || !in_array('info.php', $files)) {
            if (($overwrite_ok || !file_exists(get_file_base() . '/' . $filename) || @filemtime(get_file_base() . '/' . $filename) < filemtime(get_file_base() . '/install.php') || filesize(get_file_base() . '/' . $filename) != $file_size) && ($filename != 'forum/index.php' || !file_exists(get_file_base() . '/' . $filename))) {
                if (strpos($filename, '/' . fallback_lang() . '/') !== false && is_string($contents)) {
                    foreach (array_keys($langs) as $lang) {
                        if ($lang == fallback_lang() || strpos($lang, '.') !== false) {
                            continue;
                        }
                        if (is_suexec_like()) {
                            $myfile = fopen(get_file_base() . '/' . str_replace('/' . fallback_lang() . '/', '/' . $lang . '/', $filename), 'wb');
                            fwrite($myfile, $contents);
                            fclose($myfile);
                            fix_permissions(get_file_base() . '/' . str_replace('/' . fallback_lang() . '/', '/' . $lang . '/', $filename), 0666);
                        } else {
                            @ftp_delete($conn, str_replace('/' . fallback_lang() . '/', '/' . $lang . '/', $filename));
                            $tmp = fopen(get_file_base() . '/ocp_inst_tmp/tmp', 'wb');
                            fwrite($tmp, $contents);
                            fclose($tmp);
                            ftp_put($conn, str_replace('/' . fallback_lang() . '/', '/' . $lang . '/', $filename), get_file_base() . '/ocp_inst_tmp/tmp', FTP_BINARY);
                            $mask = 0;
                            if (get_file_extension($filename) == 'php') {
                                if (($php_perms & 0100) == 0100) {
                                    $mask = $mask | 0100;
                                }
                                if (($php_perms & 010) == 010) {
                                    $mask = $mask | 010;
                                }
                                if (($php_perms & 01) == 01) {
                                    $mask = $mask | 01;
                                }
                            }
                            @ftp_site($conn, 'CHMOD 0' . decoct(0644 | $mask) . ' ' . str_replace('/' . fallback_lang() . '/', '/' . $lang . '/', $filename));
                        }
                    }
                }
                if (is_suexec_like()) {
                    $myfile = fopen(get_file_base() . '/' . $filename, 'wb');
                    if (is_string($contents)) {
                        fwrite($myfile, $contents);
                    } else {
                        fseek($dump_myfile, $dump_offset, SEEK_SET);
                        $amount_read = 0;
                        while ($amount_read < $file_size) {
                            $read_amount = min(4096, $file_size - $amount_read);
                            $shuttle_contents = fread($dump_myfile, $read_amount);
                            fwrite($myfile, $shuttle_contents);
                            $amount_read += strlen($shuttle_contents);
                        }
                    }
                    fclose($myfile);
                    fix_permissions(get_file_base() . '/' . $filename, 0666);
                } else {
                    @ftp_delete($conn, $filename);
                    $tmp = fopen(get_file_base() . '/ocp_inst_tmp/tmp', 'wb');
                    if (is_string($contents)) {
                        fwrite($tmp, $contents);
                    } else {
                        fseek($dump_myfile, $dump_offset, SEEK_SET);
                        $amount_read = 0;
                        while ($amount_read < $file_size) {
                            $read_amount = min(4096, $file_size - $amount_read);
                            $shuttle_contents = fread($dump_myfile, $read_amount);
                            fwrite($tmp, $shuttle_contents);
                            $amount_read += strlen($shuttle_contents);
                        }
                    }
                    fclose($tmp);
                    if (!@ftp_put($conn, $filename, get_file_base() . '/ocp_inst_tmp/tmp', FTP_BINARY)) {
                        if (strpos(@strval($php_errormsg), 'bind() failed') !== false) {
                            warn_exit(do_lang_tempcode('FTP_FIREWALL_ERROR'));
                        } else {
                            warn_exit(@strval($php_errormsg));
                        }
                    }
                    $mask = 0;
                    if (get_file_extension($filename) == 'php') {
                        if (($php_perms & 0100) == 0100) {
                            $mask = $mask | 0100;
                        }
                        if (($php_perms & 010) == 010) {
                            $mask = $mask | 010;
                        }
                        if (($php_perms & 01) == 01) {
                            $mask = $mask | 01;
                        }
                    }
                    @ftp_site($conn, 'CHMOD ' . decoct(0644 | $mask) . ' ' . $filename);
                }
            }
        }
        if ($max_time > 0 && time() - $time_start >= $max_time) {
            break;
        }
        if ($i + 1 == $count) {
            $done_all = true;
            break;
            // That's them all
        }
    }
    if (!is_suexec_like()) {
        if (!file_exists(get_file_base() . '/ocp_inst_tmp/tmp')) {
            warn_exit(do_lang_tempcode('DOUBLE_INSTALL_DO'));
        }
        @unlink(get_file_base() . '/ocp_inst_tmp/tmp');
    }
    test_htaccess(is_suexec_like() ? NULL : $conn);
    $log = new ocp_tempcode();
    if ($done_all) {
        // If the file user is different to the FTP user, we need to make it world writeable
        if (!is_suexec_like()) {
            // Chmod
            global $CHMOD_ARRAY;
            $no_chmod = false;
            foreach ($CHMOD_ARRAY as $chmod) {
                if (file_exists($chmod) && !@ftp_site($conn, 'CHMOD 0777 ' . $chmod)) {
                    $no_chmod = true;
                }
            }
            $log->attach(do_template('INSTALLER_DONE_SOMETHING', array('_GUID' => '2e4ccdd5a0b034125ee62403d5a48319', 'SOMETHING' => do_lang_tempcode(!$no_chmod ? 'CHMOD_PASS' : 'CHMOD_FAIL'))));
        }
    }
    if (!is_suexec_like()) {
        if (function_exists('ftp_close')) {
            ftp_close($conn);
        }
    }
    $log->attach(do_template('INSTALLER_DONE_SOMETHING', array('_GUID' => '1b447cee9e9aa3ad8e24530d4dceb03f', 'SOMETHING' => do_lang_tempcode('FILES_TRANSFERRED', strval($i + 1), strval($count)))));
    return array($log, $done_all ? -1 : $i);
}
 /**
  * This function will import project documents into the new files section and preserve message / file relations
  *
  * @param void
  * @return boolean
  */
 function importProjectDocuments()
 {
     $this->printMessage('Starting to import documents...');
     if ($result = mysql_query('SELECT * FROM `' . TABLE_PREFIX . 'project_documents`')) {
         mysql_query('BEGIN WORK', $this->database_connection);
         $counter = 0;
         while ($row = mysql_fetch_assoc($result)) {
             $sql = sprintf("INSERT INTO `%sproject_files` (`project_id`, `filename`, `description`, `is_private`, `is_visible`, `created_on`, `created_by_id`, `updated_on`, `updated_by_id`) VALUES ('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')", TABLE_PREFIX, $row['project_id'], mysql_real_escape_string($row['filename']), mysql_real_escape_string($row['description']), $row['is_private'], 1, $row['created_on'], $row['created_by_id'], $row['updated_on'], $row['updated_by_id']);
             if (!mysql_query($sql, $this->database_connection)) {
                 mysql_query('ROLLBACK', $this->database_connection);
                 $this->printMessage('Failed to move project documents. MySQL said: ' . mysql_error(), true);
                 return false;
             }
             // if
             $file_id = mysql_insert_id($this->database_connection);
             $file_type_id = 0;
             $sql = sprintf("SELECT `id` FROM `%sfile_types` WHERE `extension` = '%s'", TABLE_PREFIX, mysql_real_escape_string(strtolower(get_file_extension($row['filename']))));
             if ($file_type_result = mysql_query($sql)) {
                 if ($file_type_row = mysql_fetch_assoc($file_type_result)) {
                     $file_type_id = (int) $file_type_row['id'];
                 }
                 // if
             }
             // if
             $repository_id = '';
             $file_path = INSTALLATION_PATH . '/public/files/project_documents/' . $row['project_id'] . '/' . $row['filename'];
             if (is_file($file_path)) {
                 do {
                     $repository_id = sha1(uniqid(rand(), true));
                     $repository_entry_exists = false;
                     if ($check_repository_id_result = mysql_query(sprintf("SELECT COUNT (`id`) AS 'row_count' FROM `%sfile_repo` WHERE `id` = '%s'", TABLE_PREFIX, $repository_id))) {
                         if ($check_repository_id_row = mysql_fetch_assoc($check_repository_id_result)) {
                             $repository_entry_exists = (bool) $check_repository_id_row['row_count'];
                         }
                         // if
                     }
                     // if
                 } while ($repository_entry_exists);
                 $sql = sprintf("INSERT INTO `%sfile_repo` (`id`, `content`) VALUES ('%s', '%s')", TABLE_PREFIX, $repository_id, mysql_real_escape_string(file_get_contents($file_path), $this->database_connection));
                 // sprintf
                 if (!mysql_query($sql, $this->database_connection)) {
                     mysql_query('ROLLBACK', $this->database_connection);
                     $this->printMessage('Failed to insert file content into file repository. MySQL said: ' . mysql_error(), true);
                     return false;
                 }
                 // if
             }
             // if
             $sql = sprintf("INSERT INTO `%sproject_file_revisions` (`file_id`, `file_type_id`, `repository_id`, `revision_number`, `type_string`, `filesize`, `created_on`, `created_by_id`, `updated_on`, `updated_by_id`) VALUES ('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')", TABLE_PREFIX, $file_id, $file_type_id, $repository_id, 1, $row['type'], $row['size'], $row['created_on'], $row['created_by_id'], $row['updated_on'], $row['updated_by_id']);
             // sprintf
             if (!mysql_query($sql, $this->database_connection)) {
                 mysql_query('ROLLBACK', $this->database_connection);
                 $this->printMessage('Failed to move project documents. MySQL said: ' . mysql_error(), true);
                 return false;
             }
             // if
             // Now, relations with messages...
             if ($related_messages_result = mysql_query(sprintf("SELECT * FROM `%smessage_documents` WHERE `document_id` = '%s'", TABLE_PREFIX, $row['id']), $this->database_connection)) {
                 while ($related_messages_row = mysql_fetch_assoc($related_messages_result)) {
                     $sql = sprintf("INSERT INTO `%sattached_files` (`rel_object_manager`, `rel_object_id`, `file_id`, `created_on`, `created_by_id`) VALUES ('%s', '%s', '%s', '%s', '%s')", TABLE_PREFIX, 'ProjectMessages', $related_messages_row['message_id'], $file_id, $row['created_on'], $row['created_by_id']);
                     // sprintf
                     if (!mysql_query($sql, $this->database_connection)) {
                         mysql_query('ROLLBACK', $this->database_connection);
                         $this->printMessage('Failed to add message - file relation. MySQL said: ' . mysql_error(), true);
                         return false;
                     }
                     // if
                 }
                 // while
             }
             // if
             $counter++;
         }
         // while
         mysql_query('COMMIT');
         $this->printMessage("{$counter} documents moved");
         // Drop tables
         if (mysql_query('DROP TABLE IF EXISTS `' . TABLE_PREFIX . 'project_documents', $this->database_connection)) {
             $this->printMessage('`' . TABLE_PREFIX . 'project_documents` table dropped');
         } else {
             $this->printMessage('Warning: Failed to drop old documents table. MySQL said: ' . mysql_error(), true);
         }
         // if
         if (mysql_query('DROP TABLE IF EXISTS `' . TABLE_PREFIX . 'document_downloads', $this->database_connection)) {
             $this->printMessage('`' . TABLE_PREFIX . 'document_downloads` table dropped');
         } else {
             $this->printMessage('Warning: Failed to drop old document downloads table. MySQL said: ' . mysql_error(), true);
         }
         // if
         if (mysql_query('DROP TABLE IF EXISTS `' . TABLE_PREFIX . 'message_documents', $this->database_connection)) {
             $this->printMessage('`' . TABLE_PREFIX . 'message_documents` table dropped');
         } else {
             $this->printMessage('Warning: Failed to drop old message - documents table. MySQL said: ' . mysql_error(), true);
         }
         // if
     }
     // if
     return true;
 }
Esempio n. 26
0
} else {
    $next_image_name = REPLACE_EMPTY;
    $next_image_url = REPLACE_EMPTY;
    $next_image_file = REPLACE_EMPTY;
    $next_thumb_file = REPLACE_EMPTY;
}
if (!empty($next_prev_cache[$prev_image_id])) {
    $prev_image_name = format_text($next_prev_cache[$prev_image_id]['image_name'], 2);
    $prev_image_url = $site_sess->url(ROOT_PATH . "details.php?" . URL_IMAGE_ID . "=" . $prev_image_id . (!empty($mode) ? "&amp;mode=" . $mode : ""));
    if (!get_file_path($next_prev_cache[$prev_image_id]['image_media_file'], "media", $next_prev_cache[$prev_image_id]['cat_id'], 0, 0)) {
        $prev_image_file = ICON_PATH . "/404.gif";
    } else {
        $prev_image_file = get_file_path($next_prev_cache[$prev_image_id]['image_media_file'], "media", $next_prev_cache[$prev_image_id]['cat_id'], 0, 1);
    }
    if (!get_file_path($next_prev_cache[$prev_image_id]['image_thumb_file'], "thumb", $next_prev_cache[$prev_image_id]['cat_id'], 0, 0)) {
        $prev_thumb_file = ICON_PATH . "/" . get_file_extension($next_prev_cache[$prev_image_id]['image_media_file']) . ".gif";
    } else {
        $prev_thumb_file = get_file_path($next_prev_cache[$prev_image_id]['image_thumb_file'], "thumb", $next_prev_cache[$prev_image_id]['cat_id'], 0, 1);
    }
} else {
    $prev_image_name = REPLACE_EMPTY;
    $prev_image_url = REPLACE_EMPTY;
    $prev_image_file = REPLACE_EMPTY;
    $prev_thumb_file = REPLACE_EMPTY;
}
$site_template->register_vars(array("next_image_id" => $next_image_id, "next_image_name" => $next_image_name, "next_image_url" => $next_image_url, "next_image_file" => $next_image_file, "next_thumb_file" => $next_thumb_file, "prev_image_id" => $prev_image_id, "prev_image_name" => $prev_image_name, "prev_image_url" => $prev_image_url, "prev_image_file" => $prev_image_file, "prev_thumb_file" => $prev_thumb_file));
unset($next_prev_cache);
//-----------------------------------------------------
//--- Save Comment ------------------------------------
//-----------------------------------------------------
$error = 0;
 /**
  * Return URL of file type icon. If we are working with image file type this function
  * will return thumb URL if it success in creating it
  *
  * @param void
  * @return string
  */
 function getTypeIconUrl($showImage = true, $size = '48x48')
 {
     // return image depending on type string
     $image = "file.png";
     $mimeType = str_replace(array("/", "+"), "-", $this->getTypeString());
     $theme = config_option("theme", DEFAULT_THEME);
     $base = ROOT . "/" . PUBLIC_FOLDER . "/assets/themes/{$theme}/images/{$size}/types/";
     $extension = get_file_extension($this->getFile()->getFilename());
     if (is_file($base . $extension . ".png")) {
         $image = $extension . ".png";
     }
     $temp = $mimeType;
     $x = 0;
     while (true) {
         $x++;
         if (is_file($base . $temp . ".png")) {
             $image = $temp . ".png";
             break;
         } else {
             if ($x > 10) {
                 break;
             }
             $i = strrpos($temp, "-");
             if ($i < 0) {
                 break;
             }
             $temp = substr($temp, 0, $i);
         }
     }
     return get_image_url("{$size}/types/{$image}");
 }
 /**
  * Whether the media (video or audio) is supported or not
  *
  * @param  string  $filename
  * @return boolean
  */
 public static function isSupportedMedia($filename)
 {
     return in_array(get_file_extension($filename), self::getSupportedMedia());
 }
Esempio n. 29
0
      <li>
        <a title="<?php 
        print basename($item) . '&#10;' . dirname($item);
        ?>
" class="mw-browser-list-file mw-browser-list-<?php 
        print substr(strrchr($item, '.'), 1);
        ?>
" href="<?php 
        print mw()->url_manager->link_to_file($item);
        ?>
"  onclick="mw.url.windowHashParam('select-file', '<?php 
        print mw()->url_manager->link_to_file($item);
        ?>
'); return false;">
          <?php 
        $ext = strtolower(get_file_extension($item));
        ?>
          <?php 
        if ($ext == 'jpg' or $ext == 'png' or $ext == 'gif' or $ext == 'jpeg' or $ext == 'bmp') {
            ?>
          <img data-src="<?php 
            print thumbnail(mw()->url_manager->link_to_file($item), 48, 48);
            ?>
" class="image-item image-item-not-ready" />
          <?php 
        } else {
            ?>
          <span class="mw-fileico mw-fileico-<?php 
            print $ext;
            ?>
"><?php 
Esempio n. 30
0
 private function install_from_market($item)
 {
     if (isset($item['url']) and !isset($item['download'])) {
         $item['download'] = $item['url'];
     } elseif (isset($item['download_url']) and !isset($item['download'])) {
         $item['download'] = $item['download_url'];
     }
     $download_target = false;
     if (isset($item['download']) and !isset($item['size'])) {
         $url = $item['download'];
         $download_target = $this->temp_dir . md5($url) . basename($url);
         $download_target_extract_lock = $this->temp_dir . md5($url) . basename($url) . '.unzip_lock';
         $this->_log_msg('Downloading from marketplace');
         //if (!is_file($download_target)){
         $dl = $this->http()->url($url)->download($download_target);
         //}
     } else {
         if (isset($item['download']) and isset($item['size'])) {
             $expected = intval($item['size']);
             $download_link = $item['download'];
             $ext = get_file_extension($download_link);
             if ($ext != 'zip') {
                 return;
             }
             if ($download_link != false and $expected > 0) {
                 $text = $download_link;
                 $regex = '/\\b((?:[\\w\\d]+\\:\\/\\/)?(?:[\\w\\-\\d]+\\.)+[\\w\\-\\d]+(?:\\/[\\w\\-\\d]+)*(?:\\/|\\.[\\w\\-\\d]+)?(?:\\?[\\w\\-\\d]+\\=[\\w\\-\\d]+\\&?)?(?:\\#[\\w\\-\\d]*)?)\\b/';
                 preg_match_all($regex, $text, $matches, PREG_SET_ORDER);
                 foreach ($matches as $match) {
                     if (isset($match[0])) {
                         $url = $download_link;
                         $download_target = $this->temp_dir . basename($download_link);
                         $download_target_extract_lock = $this->temp_dir . basename($download_link) . '.unzip_lock';
                         $expectd_item_size = $item['size'];
                         if (!is_file($download_target) or filesize($download_target) != $item['size']) {
                             $dl = $this->http()->url($url)->download($download_target);
                             if ($dl == false) {
                                 if (is_file($download_target) and filesize($download_target) != $item['size']) {
                                     $fs = filesize($download_target);
                                     return array('size' => $fs, 'expected_size' => $expected, 'try_again' => "true", 'warning' => "Only " . $fs . ' bytes downloaded of total ' . $expected);
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     if ($download_target != false and is_file($download_target)) {
         $where_to_unzip = MW_ROOTPATH;
         if (isset($item['item_type'])) {
             if ($item['item_type'] == 'module') {
                 $where_to_unzip = modules_path();
             } elseif ($item['item_type'] == 'module_template') {
                 $where_to_unzip = modules_path();
             } elseif ($item['item_type'] == 'template') {
                 $where_to_unzip = templates_path();
             } elseif ($item['item_type'] == 'element') {
                 $where_to_unzip = elements_path();
             }
             if (isset($item['install_path']) and $item['install_path'] != false) {
                 if ($item['item_type'] == 'module_template') {
                     $where_to_unzip = $where_to_unzip . DS . $item['install_path'] . DS . 'templates' . DS;
                 } else {
                     $where_to_unzip = $where_to_unzip . DS . $item['install_path'];
                 }
             }
             $where_to_unzip = str_replace('..', '', $where_to_unzip);
             $where_to_unzip = normalize_path($where_to_unzip, true);
             $this->_log_msg('Unzipping in ' . $where_to_unzip);
             $unzip = new \Microweber\Utils\Unzip();
             $target_dir = $where_to_unzip;
             $result = $unzip->extract($download_target, $target_dir, $preserve_filepath = true);
             $new_composer = $target_dir . 'composer.json';
             if (is_file($new_composer)) {
                 // $this->composer_merge($new_composer);
             }
             $num_files = count($result);
             return array('files' => $result, 'location' => $where_to_unzip, 'success' => "Item is installed. {$num_files} files extracted in {$where_to_unzip}");
         }
     }
 }