public function getFiles() { $q = "SELECT * FROM file WHERE page_id='" . $this->getPageId() . "' ORDER BY filename, file_id DESC"; $c = new Criteria(); $c->setExplicitQuery($q); return DB_FilePeer::instance()->select($c); }
/** * Get files from page * * Argument array keys: * site: site to get page from * page: page to get (full_name) files from * * @param struct $args * @return struct */ public function files($args) { $this->parseArgs($args, array("performer", "site", "page")); WDPermissionManager::instance()->canAccessSite($this->performer, $this->site); $c = new Criteria(); $c->add("page_id", $this->page->getPageId()); $files = DB_FilePeer::instance()->select($c); return $this->repr($files); }
public function build($runData) { $pl = $runData->getParameterList(); $pageId = $pl->getParameterValue("pageId"); $c = new Criteria(); $c->add("page_id", $pageId); $c->add("has_resized", true); $c->addOrderAscending("filename"); $files = DB_FilePeer::instance()->select($c); $runData->contextAdd("files", $files); }
public function build($runData) { $pl = $runData->getParameterList(); $fileId = $pl->getParameterValue("file_id"); $file = DB_FilePeer::instance()->selectByPrimaryKey($fileId); if ($file == null || $file->getSiteId() != $runData->getTemp("site")->getSiteId()) { $runData->ajaxResponseAdd("status", "wrong_file"); $runData->ajaxResponseAdd("message", _("Error getting file information.")); $runData->setModuleTemplate("Empty"); return; } $runData->contextAdd("file", $file); }
public function build($runData) { $pl = $runData->getParameterList(); $fileId = $pl->getParameterValue("file_id"); $file = DB_FilePeer::instance()->selectByPrimaryKey($fileId); if ($file == null || $file->getSiteId() != $runData->getTemp("site")->getSiteId()) { throw new ProcessException(_("Error getting file information."), "no_file"); } $page = DB_PagePeer::instance()->selectByPrimaryKey($file->getPageId()); if ($page == null || $page->getSiteId() != $runData->getTemp("site")->getSiteId()) { throw new ProcessException(_("Error getting file information."), "no_page"); } // check permissions $category = $page->getCategory(); // now check for permissions!!! $user = $runData->getUser(); WDPermissionManager::instance()->hasPagePermission('rename_file', $user, $category); $runData->contextAdd("file", $file); }
/** * * Renders a token into text matching the requested format. * * @access public * * @param array $options The "options" portion of the token (second * element). * * @return string The text rendered from the token options. * */ function token($options) { $pageName = $this->wiki->vars['pageName']; $size = $options['size']; if (!in_array($size, array("small", "medium", "thumbnail", "square", "original"))) { $size = "thumbnail"; } $sources = $options['sources']; if ($sources) { $noLocal = $this->getConf("no_local"); // each line is a source + parameters. // parse in a similar way as the image rule. // parse sources $sources = explode("\n", $sources); if (count($sources) === 0) { return '<div class="error-block">' . _('Sorry, no images found.') . '</div>'; } $out = '<div class="gallery-box">'; foreach ($sources as $row) { if (!preg_match("/^: /", $row)) { continue; } $row = trim(preg_replace("/^: /", '', $row)); $pos = strpos($row, ' '); if ($pos === false) { $src = $row; $attr = array(); } else { // everything after the space is attribute arguments $src = substr($row, 0, $pos); $attr = $this->getAttrs(substr($row, $pos + 1)); } // SINGLE IMAGE PROCESSING BEGINS if ($src && $src[0] == '*') { $src = substr($src, 1); $target = 'target="_blank"'; } // see if is a flickr image if (strpos($src, 'flickr:') !== false) { preg_match("/^flickr:([0-9]+)(?:_([a-z0-9]+))?/i", $src, $mat2); $photoId = $mat2[1]; $secret = $mat2[2]; $flickr = FlickrHandler::instance(); $photo = $flickr->photos_getInfo($photoId, $secret); if ($photo == null) { return '<div class="error-block">Error fetching flickr image (id: ' . $photoId . ') info. ' . 'The file does not exist, is private or other problem.</div>'; } $src = $flickr->buildPhotoURL($photo, $size); //"http://static.flickr.com/".$photo['_attributes']['server']."/".$photo['_attributes']['id']."_".$photo['_attributes']['secret'].".jpg"; // set/override link attribute $attr['link'] = $photo['urls']['url'][0]['_value']; } elseif (strpos($src, '://') === false) { // is the source a local file or URL? // the source refers to a local file. // add the URL base to it. // see if it refers to a different page if (strpos($src, '/') !== false) { $src = preg_replace("/^\\//", '', $src); $osrc = "/local--files/" . $src; $src = "/local--resized-images/" . $src . '/' . $size . '.jpg'; } else { if ($noLocal) { return '<div class="error-block">' . 'Error fetching local image (: ' . $row . ').' . 'Sorry, can not load files attached to this page in this mode. ' . 'You should specify source page for each local image.</div>'; } $osrc = "/local--files/" . $this->wiki->vars['pageName'] . '/' . $src; $src = "/local--resized-images/" . $this->wiki->vars['pageName'] . '/' . $src . '/' . $size . '.jpg'; } if ($size == "original") { $src = $osrc; } } elseif (strpos($src, '://') !== false) { $attr['link'] = $src; $size = "original"; } else { return '<div class="error-block">Sorry, format for gallery item:<pre>' . $row . '</pre> is not supported.</div>'; } if (isset($attr['link'])) { $link = $attr['link']; if ($link[0] == '*') { $link = substr($link, 1); $target = 'target="_blank"'; $attr['link'] = $link; } // yes, the image is clickable. // are we linked to a URL or a wiki page? if (strpos($attr['link'], '://')) { // it's a URL $href = $attr['link']; } else { // it's a WikiPage; assume it exists. /** @todo This needs to honor sprintf wikilinks (pmjones) */ /** @todo This needs to honor interwiki (pmjones) */ /** @todo This needs to honor freelinks (pmjones) */ $href = $this->wiki->getRenderConf('xhtml', 'wikilink', 'view_url') . $attr['link']; } } else { // image is not clickable. $href = $osrc; } $out .= '<div class="gallery-item ' . $size . '">'; $out .= '<table><tr><td>'; $out .= '<a href="' . $href . '" ' . $target . '>'; $out .= '<img src="' . $src . '" alt=""/>'; $out .= '</a>'; $out .= '</td></tr></table>'; $out .= '</div>'; // SINGLE IMAGE PROCESSING ENDS } $out .= '</div>'; return $out; } // local mode $noLocal = $this->getConf("no_local"); if ($noLocal) { return '<div class="error-block">' . 'Sorry, can not load files attached to the page in this mode. ' . 'You should specify sources for each image.</div>'; } // get page first $site = $GLOBALS['site']; $page = DB_PagePeer::instance()->selectByName($site->getSiteId(), $pageName); if ($page == null) { return '<div class="error-block">Error selecting page.</div>'; } // get attachments that might be images. $c = new Criteria(); $c->add("page_id", $page->getPageId()); $c->add("mimetype", "^image", "~*"); $c->add("has_resized", true); $files = DB_FilePeer::instance()->select($c); if (count($files) == 0) { return '<div class="error-block">Sorry, no images found attached ' . 'to this page.</div>'; } // ok, we have images. now GOGOGO!!! $out = '<div class="gallery-box">'; foreach ($files as $file) { $src = '/local--resized-images/' . $pageName . '/' . $file->getFilename() . '/' . $size . '.jpg'; $href = 'local--files/' . $pageName . '/' . $file->getFilename(); if ($size == "original") { $src = $href; } $out .= '<div class="gallery-item ' . $size . '">'; $out .= '<table><tr><td>'; $out .= '<a href="' . $href . '">'; $out .= '<img src="' . $src . '" alt=""/>'; $out .= '</a>'; $out .= '</td></tr></table>'; $out .= '</div>'; } $out .= '</div>'; return $out; }
public function cloneSite($site, $siteProperties, $attrs = array()) { $db = Database::connection(); $db->begin(); /* * Hopefully attrs contains a set of parameters that determine * the behoviour of the duplicatior. */ $nsite = clone $site; $nsite->setNew(true); $nsite->setSiteId(null); $nsite->setUnixName($siteProperties['unixname']); if (isset($siteProperties['name'])) { $nsite->setName($siteProperties['name']); } if (isset($siteProperties['subtitle'])) { $nsite->setSubtitle($siteProperties['subtitle']); } if (isset($siteProperties['description'])) { $nsite->setDescription($siteProperties['description']); } if (array_key_exists('private', $siteProperties)) { if ($siteProperties['private']) { $nsite->setPrivate(true); } else { $nsite->setPrivate(false); } } $nsite->setCustomDomain(null); $nsite->save(); /* Super settings. */ // site_super_settings $superSettings = $site->getSuperSettings(); $superSettings->setNew(true); $superSettings->setSiteId($nsite->getSiteId()); $superSettings->save(); /* Site settings. */ $settings = $site->getSettings(); $settings->setNew(true); $settings->setSiteId($nsite->getSiteId()); $settings->save(); /* Now handle site owner. */ $c = new Criteria(); $c->add('site_id', $site->getSiteId()); $c->add('founder', true); $owner = DB_AdminPeer::instance()->selectOne($c); $this->owner = $owner; $admin = new DB_Admin(); $admin->setSiteId($nsite->getSiteId()); $admin->setUserId($owner->getUserId()); $admin->setFounder(true); // will be nonremovable ;-) $admin->save(); $member = new DB_Member(); $member->setSiteId($nsite->getSiteId()); $member->setUserId($owner->getUserId()); $member->setDateJoined(new ODate()); $member->save(); /* Theme(s). */ $c = new Criteria(); $c->add('site_id', $site->getSiteId()); $themes = DB_ThemePeer::instance()->select($c); $themeMap = array(); $nthemes = array(); foreach ($themes as $theme) { $ntheme = clone $theme; $ntheme->setNew(true); $ntheme->setSiteId($nsite->getSiteId()); $ntheme->setThemeId(null); $ntheme->save(); $themeMap[$theme->getThemeId()] = $ntheme->getThemeId(); $nthemes[] = $ntheme; } foreach ($nthemes as $ntheme) { if ($ntheme->getExtendsThemeId() && isset($themeMap[$ntheme->getExtendsThemeId()])) { $ntheme->setExtendsThemeId($themeMap[$ntheme->getExtendsThemeId()]); $ntheme->save(); } } // get all categories from the site $c = new Criteria(); $c->add("site_id", $site->getSiteId()); $categories = DB_CategoryPeer::instance()->select($c); foreach ($categories as $cat) { if (!in_array($cat->getName(), $this->excludedCategories)) { $ncategory = $this->duplicateCategory($cat, $nsite); /* Check if is using a custom theme. */ if ($ncategory->getThemeId() && isset($themeMap[$ncategory->getThemeId()])) { $ncategory->setThemeId($themeMap[$ncategory->getThemeId()]); $ncategory->save(); } if ($ncategory->getTemplateId()) { $ncategory->setTemplateId($this->pageMap[$ncategory->getTemplateId()]); $ncategory->save(); } } } /* Recompile WHOLE site. */ $od = new Outdater(); $od->recompileWholeSite($nsite); /* Index. */ $ind = Indexer::instance(); $c = new Criteria(); $c->add("site_id", $site->getSiteId()); $pages = DB_PagePeer::instance()->select($c); foreach ($pages as $p) { $ind->indexPage($p); } /* Handle forum too. */ $fs = $site->getForumSettings(); if ($fs) { $fs->setNew(true); $fs->setSiteId($nsite->getSiteId()); $fs->save(); /* Copy existing structure. */ $c = new Criteria(); $c->add('site_id', $site->getSiteId()); $groups = DB_ForumGroupPeer::instance()->select($c); foreach ($groups as $group) { $ngroup = clone $group; $ngroup->setNew(true); $ngroup->setGroupId(null); $ngroup->setSiteId($nsite->getSiteId()); $ngroup->save(); $c = new Criteria(); $c->add('group_id', $group->getGroupId()); $categories = DB_ForumCategoryPeer::instance()->select($c); foreach ($categories as $category) { $ncategory = clone $category; $ncategory->setNew(true); $ncategory->setCategoryId(null); $ncategory->setNumberPosts(0); $ncategory->setNumberThreads(0); $ncategory->setLastPostId(null); $ncategory->setSiteId($nsite->getSiteId()); $ncategory->setGroupId($ngroup->getGroupId()); $ncategory->save(); } } } /* Copy ALL files from the filesystem. */ $srcDir = WIKIDOT_ROOT . "/web/files--sites/" . $site->getUnixName(); $destDir = WIKIDOT_ROOT . "/web/files--sites/" . $nsite->getUnixName(); $cmd = 'cp -r ' . escapeshellarg($srcDir) . ' ' . escapeshellarg($destDir); exec($cmd); /* Copy file objects. */ $c = new Criteria(); $c->add('site_id', $site->getSiteId()); $files = DB_FilePeer::instance()->select($c); foreach ($files as $file) { $nfile = clone $file; $nfile->setSiteId($nsite->getSiteId()); $nfile->setNew(true); $nfile->setFileId(null); $nfile->setSiteId($nsite->getSiteId()); /* Map to a new page objects. */ $pageId = $this->pageMap[$file->getPageId()]; $nfile->setPageId($pageId); $nfile->save(); } $db->commit(); return $nsite; }
/** * * Renders a token into text matching the requested format. * * @access public * * @param array $options The "options" portion of the token (second * element). * * @return string The text rendered from the token options. * */ function token($options) { // note the image source $src = $options['src']; $size = $options['attr']['size']; $postVars = $this->getConf("post_vars"); if (preg_match('/^:first/', $src)) { $page = DB_PagePeer::instance()->selectByName($GLOBALS['site']->getSiteId(), $this->wiki->vars['pageName']); if (!$page) { return ""; } $c = new Criteria(); $c->add("page_id", $page->getPageId()); $c->add("mimetype", "^image", "~*"); $c->add("has_resized", true); $c->addOrderAscending("filename"); if ($file = DB_FilePeer::instance()->selectOne($c)) { $src = $file->getFileName(); $options['src'] = $src; } else { return ""; } } // see if is a flickr image if (strpos($src, 'flickr:') !== false) { //check if valid arguments, handle sizes etc. preg_match("/^flickr:([0-9]+)(?:_([a-z0-9]+))?/i", $src, $mat2); $photoId = $mat2[1]; $secret = $mat2[2]; if (!in_array($size, array("small", "medium", "thumbnail", "square", "large", "original"))) { $size = null; } $flickr = FlickrHandler::instance(); $photo = $flickr->photos_getInfo($photoId, $secret); if ($photo == null) { return '<div class="error-block">' . sprintf(_('Error fetching flickr image (id: %s) info. The file does not exist, is private or other problem.'), $photoId) . '</div>'; } $src = $flickr->buildPhotoURL($photo, $size); //"http://static.flickr.com/".$photo['_attributes']['server']."/".$photo['_attributes']['id']."_".$photo['_attributes']['secret'].".jpg"; // set/override link attribute $options['attr']['link'] = $photo['urls']['url'][0]['_value']; } elseif (strpos($src, '://') === false) { // is the source a local file or URL? // the source refers to a local file. // add the URL base to it. if (!in_array($size, array("small", "medium", "thumbnail", "square"))) { $size = null; } // should we force size? yes if the file has resized version but is // not a viewable image, e.g. .pdf if (!$size && !preg_match('/\\.(png|jpg|gif)$/i', $src)) { $size = "medium"; } // see if it refers to a different page if ($postVars || preg_match("/^%%%[^%]+%%\$/", $src)) { // this is ok. used for feed parsing. } elseif (strpos($src, '/') !== false) { if ($size) { $src = preg_replace("/^\\//", '', $src); $src = "/local--resized-images/" . $src . '/' . $size . '.jpg'; if ($options['attr']['link'] == null) { // link to the original image $srch = preg_replace("/^\\//", '', $options['src']); $options['attr']['link'] = "/local--files/" . $srch; } } else { // ok, hardcode the path... sorry. $src = preg_replace("/^\\//", '', $src); $src = "/local--files/" . $src; } } else { $noLocal = $this->getConf("no_local"); if ($noLocal) { return '<span class="error-inline">' . _('Sorry, local images without page name specified not allowed. Use <em>pagename</em>/<em>filename</em> as the image source') . '</span>'; } if ($size) { $src = "/local--resized-images/" . $this->wiki->vars['pageName'] . '/' . $src . '/' . $size . '.jpg'; if ($options['attr']['link'] == null) { // link to the original image $srch = preg_replace("/^\\//", '', $options['src']); $options['attr']['link'] = "/local--files/" . $this->wiki->vars['pageName'] . '/' . $srch; } } else { $src = "/local--files/" . $this->wiki->vars['pageName'] . '/' . $src; } } } if (isset($options['attr']['link'])) { // yes, the image is clickable. // are we linked to a URL or a wiki page? if (strpos($options['attr']['link'], '://')) { // it's a URL, prefix the URL base $href = $this->getConf('url_base') . $options['attr']['link']; } else { // it's a WikiPage; assume it exists. /** @todo This needs to honor sprintf wikilinks (pmjones) */ /** @todo This needs to honor interwiki (pmjones) */ /** @todo This needs to honor freelinks (pmjones) */ $href = '/' . $options['attr']['link']; $href = preg_replace(';^/+;', '/', $href); // a dirty fix } } else { // image is not clickable. $href = null; } // unset so it won't show up as an attribute unset($options['attr']['link']); $output .= '<img src="' . htmlspecialchars($src) . '"'; // get the CSS class but don't add it yet $css = "image"; // add the attributes to the output, and be sure to // track whether or not we find an "alt" attribute $alt = false; foreach ($options['attr'] as $key => $val) { // track the 'alt' attribute if (strtolower($key) == 'alt') { $alt = true; } // the 'class' attribute overrides the CSS class conf if (strtolower($key) == 'class') { $css = null; } if ($key == "class" || $key == "alt" || $key == "style" || $key == "width" || $key == "height") { $key = htmlspecialchars($key); $val = htmlspecialchars($val); $output .= " {$key}=\"{$val}\""; } } // always add an "alt" attribute per Stephane Solliec if (!$alt) { $alt = htmlspecialchars(basename($options['src'])); $output .= " alt=\"{$alt}\""; } // end the image tag with the automatic CSS class (if any) if ($css) { $output .= ' class="' . $css . '"'; } $output .= " />"; // was the image clickable? if ($href) { // yes, add the href and return $href = htmlspecialchars($href); $css = $this->formatConf(' class="%s"', 'css_link'); $target = ''; if ($options['target']) { $target = ' target="' . $options['target'] . '" '; } $output = "<a{$css} href=\"{$href}\" {$target}>{$output}</a>"; } $align = $options['align']; if ($align) { $output2 = $output; $output = ''; // start the HTML output $output .= '<div class="image-container'; if ($align === "f<") { $output .= ' floatleft'; } elseif ($align === "f>") { $output .= ' floatright'; } elseif ($align === "<") { $output .= ' alignleft'; } elseif ($align === ">") { $output .= ' alignright'; } elseif ($align === '=') { $output .= ' aligncenter'; } $output .= '">'; $output .= $output2; $output .= '</div>'; } return $output; }
public function deleteFileEvent($runData) { $pl = $runData->getParameterList(); $fileId = $pl->getParameterValue("file_id"); $destinationPageName = $pl->getParameterValue("destination_page_name"); $site = $runData->getTemp("site"); $db = Database::connection(); $db->begin(); $file = DB_FilePeer::instance()->selectByPrimaryKey($fileId); if ($file == null || $file->getSiteId() != $site->getSiteId()) { throw new ProcessException("File does not exist.", "no_file"); } $page = DB_PagePeer::instance()->selectByPrimaryKey($file->getPageId()); if ($page == null) { throw new ProcessException(_("Page does not exist."), "no_page"); } $category = $page->getCategory(); // now check for permissions!!! $user = $runData->getUser(); WDPermissionManager::instance()->hasPagePermission('delete_file', $user, $category, $page); // remove file! and create another revision too... @unlink($file->getFilePath()); // delete resized images if exist if ($file->getHasResized()) { $cmd = "rm -r " . escapeshellarg($file->getResizedDir()); exec($cmd); } DB_FilePeer::instance()->deleteByPrimaryKey($file->getFileId()); // create a new revision $revision = $page->getCurrentRevision(); $revision->setNew(true); $revision->setRevisionId(null); $revision->resetFlags(); $revision->setFlagFile(true); $revision->setRevisionNumber($revision->getRevisionNumber() + 1); $now = new ODate(); $revision->setDateLastEdited($now); $userId = $runData->getUserId(); if ($userId == null) { $userString = $runData->createIpString(); } if ($userId) { $revision->setUserId($userId); $page->setLastEditUserId($userId); } else { $revision->setUserId(0); $page->setLastEditUserId(0); $revision->setUserString($userString); $page->setLastEditUserString($userString); } $revision->setComments('File "' . $file->getFilename() . '" deleted.'); $revision->save(); $page->setRevisionId($revision->getRevisionId()); $page->setDateLastEdited($now); $page->setRevisionNumber($revision->getRevisionNumber()); $page->save(); $od = new Outdater(); $od->pageEvent('file_change', $page); $db->commit(); }