public static function updateTagRelationCache($manualLock = false) { if (!$manualLock) { self::checkTagRelationCache('lock'); } try { $tagRelationsFile = sfConfig::get('sf_root_dir') . "/cache/objcache/tagsRelations.php"; $c = new Criteria(); $allTags = TagPeer::doSelect($c); $content = "<?php \n"; foreach ($allTags as $singleTag) { $c = new Criteria(); $c->add(TagrelationPeer::TAG_ID, $singleTag->getId()); $tagRelations = TagrelationPeer::doSelect($c); if ($tagRelations) { $elementsArr = "array("; foreach ($tagRelations as $tagRelation) { $elementsArr .= $tagRelation->getId() . ","; } $content .= "\$_TagRel['" . $singleTag->getTagId() . "'] = " . substr($elementsArr, 0, -1) . ");\n"; } } $content .= "\n?>"; if (FileHelper::writeFile($tagRelationsFile, $content)) { BackendService::loadTagsRelations(); } else { echo FileHelper::Log("Unable to write tag cache in: " . $tagRelationsFile, UtilsHelper::MSG_ERROR); } } catch (Exception $e) { echo FileHelper::Log("Unable to refresh tag cache: " . $e->getMessage(), UtilsHelper::MSG_ERROR); } if (!$manualLock) { self::checkTagRelationCache('unlock'); } }
public function getHref($absolute = true) { $protocol = "http://"; $server = ''; if ($absolute) { if ($_SERVER['HTTP_HOST']) { $host = $_SERVER['HTTP_HOST']; } else { $website = Document::getDocumentByExclusiveTag("website_website_default"); if ($website) { $host = $website->getUrl(); } } if (!$host) { FileHelper::Log("Can not retrieve website URL or HTTP_HOST", UtilsHelper::MSG_ERROR); } else { if (substr($host, -1) != "/") { $host .= "/"; } if (substr($host, 0, 7) == "http://") { $host = substr($host, 7); } if (substr($host, 0, 8) == "https://") { $host = substr($host, 8); } } $server = $protocol . $host; } if ($this->getPageType() == "CONTENT") { if ($rewriteUrl = $this->getRewriteUrl()) { return $server . $rewriteUrl; } // else // { // return "/website/display/pageref/".$this->getId(); // } } else { if ($this->getPageType() == "REFERENCE") { $ref = Document::getDocumentInstance($this->getPageId()); return $ref->getHref($absolute); } else { if ($this->getPageType() == "EXTERNAL") { return $this->getUrl(); } } } if ($absolute) { return $server . "website/display/pageref/" . $this->getId(); } else { return "/website/display/pageref/" . $this->getId(); } }
function getImage($img) { try { if (strpos($img, 'http://') !== false) { $original_url = $img; $pos = strrpos($img, "."); $ext = substr($img, $pos + 1); $media = new Media(); $media->save(); $fileName = $media->getId() . "." . $ext; $basePath = sfConfig::get('sf_web_dir') . "/media/upload/"; file_put_contents($basePath . $fileName, file_get_contents($img)); $mime = explode(";", Media::mime_content_type($basePath . $fileName)); $mime = $mime[0]; $media->setFilename($fileName); $media->setFiletype($mime); $media->setFiledirpath($basePath); $media->save(null, $o); chmod($basePath . $fileName, 0777); $media->resizeImage(null, 450); $media->resizeImage(1, 150); } elseif (base64_decode($img)) { $ext = "jpg"; $media = new Media(); $media->save(); $fileName = $media->getId() . "." . $ext; $basePath = sfConfig::get('sf_web_dir') . "/media/upload/"; file_put_contents($basePath . $fileName, base64_decode($img)); $mime = explode(";", Media::mime_content_type($basePath . $fileName)); $mime = $mime[0]; $media->setFilename($fileName); $media->setFiletype($mime); $media->setFiledirpath($basePath); $media->save(null, $o); chmod($basePath . $fileName, 0777); $media->resizeImage(null, 450); $media->resizeImage(1, 150); } } catch (Exception $e) { $media->delete(); FileHelper::Log("CRON ERROR >>> Field : " . $k . " on item " . $o->getId() . "(" . $offer['originalid'] . ") is not a valid image. [" . $original_url . "]"); echo_cms("CRON ERROR >>> Field : " . $k . " on item " . $o->getId() . "(" . $offer['originalid'] . ") is not a valid image. [" . $original_url . "]"); } }
public function executeOrderDocument() { try { $documentId = $this->getRequestParameter('id'); $up = $this->getRequestParameter('up'); if ($up == "true") { Relation::orderDocument($documentId); } else { Relation::orderDocument($documentId, false); } } catch (Exception $e) { FileHelper::Log('ERROR SORT: ' . $e->getMessage(), UtilsHelper::MSG_ERROR); } }
function run_newsletter($task, $args) { ini_set("memory_limit", "2048M"); define('SF_ROOT_DIR', sfConfig::get('sf_root_dir')); define('SF_APP', 'frontend'); define('SF_ENVIRONMENT', 'prod'); define('SF_DEBUG', false); require_once SF_ROOT_DIR . DIRECTORY_SEPARATOR . 'apps' . DIRECTORY_SEPARATOR . SF_APP . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'config.php'; /*$databaseManager = new sfDatabaseManager(); $databaseManager->initialize();*/ try { $controler = sfContext::getInstance()->getController(); $newsletterHtml = $controler->getPresentationFor("news", "composeNewsletter"); $newsletter = new Newsletter(); $today = UtilsHelper::DateBG(date('Y-m-d H:i:s', time()), 'd F, Y г.'); $newsletter->setLabel($today); $newsletter->setContent($newsletterHtml); $newsletter->save(); $mailinglist = Document::getDocumentByExclusiveTag("newsletter_mailinglist_default"); if ($mailinglist) { $subscribers = Document::getChildrenOf($mailinglist->getId(), "Subscriber"); } $subject = "Sgrada.com - ежедневен бюлетин"; $i = $ind = 0; $mailAddresses = array(); $cnt = count($subscribers); foreach ($subscribers as $subscriber) { $ind++; if ($subscriber->getPublicationStatus() == "ACTIVE") { $mailAddresses[] = $subscriber->getEmail(); echo " ====> " . $subscriber->getEmail() . "\n"; $i++; } if ($i == 100 || $ind == $cnt) { if (!empty($mailAddresses)) { //sendMail($mailAddresses, $subject, $newsletterHtml); $mail = new sfMail(); $mail->initialize(); $mail->setMailer('sendmail'); $mail->setCharset('utf-8'); $mail->setSender(UtilsHelper::NO_REPLY_MAIL, UtilsHelper::SYSTEM_SENDER); $mail->setFrom(UtilsHelper::NO_REPLY_MAIL, UtilsHelper::SYSTEM_SENDER); $mail->addAddress(UtilsHelper::NO_REPLY_MAIL); foreach ($mailAddresses as $mailAdd) { $mail->addBcc($mailAdd); } $mail->setContentType('text/html'); $mail->setSubject($subject); $mail->setBody($newsletterHtml); $mail->send(); } $mailAddresses = array(); $i = 0; } } } catch (Exception $e) { $newsletter->setLabel("ERROR! " . $today); $newsletter->save(); FileHelper::Log("TASK run_newsletter: " . $e->getMessage(), UtilsHelper::MSG_ERROR); } }
public function executeUnsubscribe() { $this->setLayout(false); if ($code = $this->getRequestParameter("codeid")) { try { $c = new Criteria(); $c->add(SubscriberPeer::CODE, $code); $c->add(SubscriberPeer::PUBLICATION_STATUS, UtilsHelper::STATUS_ACTIVE); $user = SubscriberPeer::doSelectOne($c); if (!$user) { $this->getRequest()->setError('unsubscribe_email', "A problem occured"); } else { $user->setPublicationStatus(UtilsHelper::STATUS_WAITING); $user->save(); $this->msg = "<br><br><b>Unsubscribtion successfull</b>"; $subject = "Unsubscribtion"; /*$mail = new sfMail(); $mail->initialize(); $mail->setMailer('sendmail'); $mail->setCharset('utf-8'); $mail->setSender(UtilsHelper::NO_REPLY_MAIL , ''); $mail->setFrom(UtilsHelper::NO_REPLY_MAIL, ''); $mail->addAddress(UtilsHelper::SYSTEM_MAIL ); $mail->setContentType('text/html'); $mail->setSubject($subject); $mail->setBody("User: <b>".$user->getLabel()."</b> ( email: <b>".$user->getEmail()."</b> unsubscribed"); $mail->send();*/ $mail2 = new sfMail(); $mail2->initialize(); $mail2->setMailer('sendmail'); $mail2->setCharset('utf-8'); $mail2->setSender(UtilsHelper::NO_REPLY_MAIL, ''); $mail2->setFrom(UtilsHelper::NO_REPLY_MAIL, ''); $mail2->addAddress($user->getEmail()); $mail2->setContentType('text/html'); $mail2->setSubject($subject); $mail2->setBody("Successfully unsubsribed"); $mail2->send(); } } catch (Exception $e) { $this->getRequest()->setError('unsubscribe_email', "A problem occured"); FileHelper::Log("newsletter/executeUnsubscribe error:" . $e->getMessage(), UtilsHelper::MSG_ERROR); } } else { if ($unsubscribeMail = $this->getRequestParameter("unsubscribeMail")) { try { if ($this->user) { $code = $this->user->getCode(); if (empty($code)) { $code = md5(time()); } $this->user->setCode($code); $this->user->save(); $mail = new sfMail(); $mail->initialize(); $mail->setMailer('sendmail'); $mail->setCharset('utf-8'); $mail->setSender(UtilsHelper::NO_REPLY_MAIL, ''); $mail->setFrom(UtilsHelper::NO_REPLY_MAIL, ''); $mail->addAddress($this->user->getEmail()); $mail->setContentType('text/html'); $mail->setSubject("Usubscribtion"); $unsubscribePage = Document::getDocumentByExclusiveTag('website_page_newsletter_unsubscribe'); if ($unsubscribePage) { $this->unsubscribePageUrl = $unsubscribePage->getHref(); } $request = $this->getRequest(); $request->setParameter('unsubscribePageUrl', $this->unsubscribePageUrl . "?codeid=" . $code); $body = $this->getPresentationFor("newsletter", "unsubscribeRequestMail"); $mail->setBody($body); $mail->send(); $this->msg = "Link sent"; } } catch (Exception $e) { $this->msg = "A probleme occured"; FileHelper::Log("newsletter/executeUnsubscribe error:" . $e->getMessage(), UtilsHelper::MSG_ERROR); } } } }
public function executeForceDownload() { set_time_limit(0); $baseDir = $this->getRequestParameter('dir'); $baseDir = "./" . str_replace("DIR_SEP", "/", $baseDir); if (substr($baseDir, -1) != "/") { $baseDir .= "/"; } $defWebsite = Document::getDocumentByExclusiveTag("website_website_default"); if ($defWebsite) { $allowed_referrer = $defWebsite->getUrl(); if (empty($allowed_referrer)) { FileHelper::Log("Default website URL is not defined", UtilsHelper::MSG_ERROR); } } else { FileHelper::Log("website_website_default tag is not defined", UtilsHelper::MSG_ERROR); } $allowed_ext = array('zip' => 'application/zip', 'pdf' => 'application/pdf', 'doc' => 'application/msword', 'xls' => 'application/vnd.ms-excel', 'ppt' => 'application/vnd.ms-powerpoint', 'exe' => 'application/octet-stream', 'gif' => 'image/gif', 'png' => 'image/png', 'jpg' => 'image/jpeg', 'jpeg' => 'image/jpeg', 'mp3' => 'audio/mpeg', 'wav' => 'audio/x-wav', 'mpeg' => 'video/mpeg', '3gp' => 'video/3gpp', 'mpg' => 'video/mpeg', 'mpe' => 'video/mpeg', 'mov' => 'video/quicktime', 'avi' => 'video/x-msvideo'); // If hotlinking not allowed then make hackers think there are some server problems //if ((!isset($_SERVER['HTTP_REFERER']) || strpos(strtoupper($_SERVER['HTTP_REFERER']), strtoupper($allowed_referrer)) === false)) //{ //die("Internal server error. Please contact system administrator."); //} if (!$this->getRequestParameter('file')) { die("Please specify file name for download."); } $fname = basename($this->getRequestParameter('file')); function find_file($dirname, $fname, &$file_path) { $dir = opendir($dirname); while ($file = readdir($dir)) { if (empty($file_path) && $file != '.' && $file != '..') { if (is_dir($dirname . '/' . $file)) { find_file($dirname . '/' . $file, $fname, $file_path); } else { if (file_exists($dirname . '/' . $fname)) { $file_path = $dirname . '/' . $fname; return; } } } } } $file_path = ''; find_file($baseDir, $fname, $file_path); if (!is_file($file_path)) { die("File does not exist. Make sure you specified correct file name."); } $fsize = filesize($file_path); $fext = strtolower(substr(strrchr($fname, "."), 1)); if (!array_key_exists($fext, $allowed_ext)) { die("File type not allowed."); } if ($allowed_ext[$fext] == '') { $mtype = ''; if (function_exists('mime_content_type')) { $mtype = mime_content_type($file_path); } else { if (function_exists('finfo_file')) { $finfo = finfo_open(FILEINFO_MIME); $mtype = finfo_file($finfo, $file_path); finfo_close($finfo); } } if ($mtype == '') { $mtype = "application/force-download"; } } else { $mtype = $allowed_ext[$fext]; } if (!$this->getRequestParameter('newname')) { $asfname = $fname; } else { $asfname = str_replace(array('"', "'", '\\', '/'), '', $this->getRequestParameter('newname')); if ($asfname === '') { $asfname = 'NoName'; } } $headers = get_headers($_SERVER['HTTP_REFERER'], 1); if (!$headers) { die("Internal server error. Please contact system administrator."); } /*header("Pragma: public"); header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Cache-Control: public"); header("Content-Description: File Transfer");*/ header("Content-Type: {$mtype}"); header("Content-Disposition: attachment; filename=\"{$asfname}\""); //header("Content-Transfer-Encoding: binary"); //header("Content-Length: " . $fsize); $file = @fopen($file_path, "rb"); if ($file) { while (!feof($file)) { print fread($file, 1024 * 8); flush(); if (connection_status() != 0) { @fclose($file); die; } } @fclose($file); } header("Content-Type: text/html; charset=utf-8"); header("Content-Disposition: inline"); }
public static function indexDocument($id) { ini_set("memory_limit", "2048M"); try { $search_config_file = SF_ROOT_DIR . '/config/search.xml'; $documents = simplexml_load_file($search_config_file); $document_instance = Document::getDocumentInstance($id); $document_name = get_class($document_instance); $search_index_path = SF_ROOT_DIR . '/cache/search/' . strtolower($document_name); $search_index = Zend_Search_Lucene::open($search_index_path); $common_field_val = ""; $search_doc = new Zend_Search_Lucene_Document(); $genDoc = Document::getGenericDocument($id); if ($genDoc) { $date = $genDoc->getCreatedAt(); } foreach ($documents as $document) { $docClass = $document->attributes(); if ($document_name == $docClass) { $search_doc->addField(Zend_Search_Lucene_Field::Keyword('document_id', $id, 'utf-8')); $search_doc->addField(Zend_Search_Lucene_Field::Keyword('document_date', $date, 'utf-8')); $search_doc->addField(Zend_Search_Lucene_Field::Text('document_label', $document_instance->getLabel(), 'utf-8')); $search_doc->addField(Zend_Search_Lucene_Field::Keyword('document_type', $document_name, 'utf-8')); /* if(substr($document_name, -4) == "I18n") { $search_doc->addField(Zend_Search_Lucene_Field::Keyword('Culture', $document_instance->getCulture(), 'utf-8')); }*/ foreach ($document as $field_name) { $attr = get_object_vars($field_name); $attributes = $attr['@attributes']; $getFunction = 'get' . $attributes['name']; $fieldContent = ""; if ($attributes['linked']) { $getFunctionLinked = 'get' . $attributes['linked']; $linkedObj = Document::getDocumentInstance($document_instance->{$getFunction}()); if ($linkedObj) { $fieldContent = $linkedObj->{$getFunctionLinked}(); } } else { $fieldContent = $document_instance->{$getFunction}(); } $search_doc->addField(Zend_Search_Lucene_Field::Text($attributes['name'], $fieldContent, 'utf-8')); } $search_index->addDocument($search_doc); $search_index->commit(); //$search_index->optimize(); } } } catch (Exception $e) { FileHelper::Log("INDEXING > Error wile adding document " . $id . " | " . $e->getMessage(), UtilsHelper::MSG_ERROR); throw $e; } /* try { $doc = Document::getDocumentInstance($id); $docClass = get_class($doc); $search_config_file = sfConfig::get('sf_root_dir').'/config/search.xml'; $documents = simplexml_load_file($search_config_file); $index_path = sfConfig::get('sf_root_dir').'/cache/search/'.strtolower($docClass); $search_index = Zend_Search_Lucene::open($index_path); //if($doc && ($doc->getPublicationStatus() == UtilsHelper::STATUS_ACTIVE) && ($docClass == "User" && in_array($docFrontType, $userArr))) { foreach ($documents as $document) { $document_name = $document->attributes(); if($document_name == $docClass) { $common_field_val = null; $profile = $profiles[$docFrontType]; $search_doc = new Zend_Search_Lucene_Document(); $search_doc->addField(Zend_Search_Lucene_Field::Keyword('document_id', $id,'utf-8')); $search_doc->addField(Zend_Search_Lucene_Field::Keyword('document_label', $doc->getLabel(),'utf-8')); $search_doc->addField(Zend_Search_Lucene_Field::Keyword('document_type', $document_name,'utf-8')); $search_doc->addField(Zend_Search_Lucene_Field::Text('Description', $doc->getDescription(), 'utf-8')); $search_doc->addField(Zend_Search_Lucene_Field::Keyword('document_url', "")); foreach ($document as $field_name) { $attr = get_object_vars($field_name); $attributes = $attr['@attributes']; $getFunction = 'get'.$attributes['name']; $fieldContent = null; if($attributes['linked']) { $getFunctionLinked = 'get'.$attributes['linked']; $linkedObj = self::getDocumentInstance($doc->$getFunction()); if($linkedObj) $fieldContent = $linkedObj->$getFunctionLinked(); } else { $fieldContent = $doc->$getFunction(); } if($attributes['setTo']) { $common_field_val .= $fieldContent; } else { $search_doc->addField(Zend_Search_Lucene_Field::Text($attributes['name'], $fieldContent, 'utf-8')); } } if($attributes['setTo']) { $pattern1 = '/[^a-zA-Z0-9 ]/'; $pattern2 = '/ .{1,2} /'; $replacement = ''; $replacement2 = ' '; $common_field_val = preg_replace($pattern1, $replacement, $common_field_val); $common_field_val = preg_replace($pattern2, $replacement2, $common_field_val); $search_doc->addField(Zend_Search_Lucene_Field::Text($attributes['setTo'], $common_field_val, 'utf-8')); } $search_index->addDocument($search_doc); } } } $search_index->commit(); } catch (Exception $e) { FileHelper::Log("INDEXING -> Error wile adding document ".$id." | ".$e->getMessage(), UtilsHelper::MSG_ERROR ); }*/ }
public function delete($con = null) { $file = $this->getServerAbsoluteUrl(); $thumb = $this->getServerAbsoluteThumbUrl(); $filedeleted = true; $thumbdeleted = true; if (file_exists($file)) { $filedeleted = unlink($file); } if (file_exists($thumb)) { $thumbdeleted = unlink($thumb); } if (!$filedeleted) { FileHelper::Log("\tError: file '" . $file . "' could not be deleted!"); } try { $con = Propel::getConnection(); $con->begin(); //deletes generic document $genericDocument = Document::getGenericDocument($this); if ($genericDocument) { $genericDocument->delete(); } $con->commit(); Document::deleteObjCache($this); return true; } catch (Exception $e) { $con->rollback(); throw $e; } }