コード例 #1
0
ファイル: Tools.php プロジェクト: PavloKovalov/seotoaster
 public static function applyDeeplink(Application_Model_Models_Deeplink $deeplink, $content)
 {
     $replaced = Zend_Registry::isRegistered('replaced') ? Zend_Registry::get('replaced') : array();
     if (!empty($replaced)) {
         $replaced = array_map(function ($item) {
             return strip_tags($item);
         }, $replaced);
         if (in_array($deeplink->getName(), $replaced)) {
             return $content;
         }
     }
     $websiteHelper = Zend_Controller_Action_HelperBroker::getStaticHelper('Website');
     $pattern = '~<a.*href="' . $websiteHelper->getUrl() . $deeplink->getUrl() . '".*>' . $deeplink->getName() . '</a>~';
     if (preg_match($pattern, $content)) {
         return $content;
     }
     $linksMatches = self::findLinksInContent($content, false, self::PATTERN_LINKSIMPLE);
     $headersMatches = self::findHeadersInContent($content);
     $widgetsMatches = self::findWidgetsInContent($content);
     if (!empty($linksMatches) && isset($linksMatches[0])) {
         $content = self::extractWithReplace($linksMatches[0], $content);
     }
     if (!empty($headersMatches) && isset($headersMatches[0])) {
         $content = self::extractWithReplace($headersMatches[0], $content);
     }
     if (!empty($widgetsMatches) && isset($widgetsMatches[0])) {
         $content = self::extractWithReplace($widgetsMatches[0], $content);
     }
     $pattern = '~([\\>]{1}|\\s+|[\\/\\>]{1}|^)(' . $deeplink->getName() . ')([\\<]{1}|\\s+|[.,!\\?]+|$)~uUi';
     if (preg_match($pattern, $content, $matches)) {
         Zend_Registry::set('applied', true);
         $url = '<a ' . ($deeplink->getType() == Application_Model_Models_Deeplink::TYPE_EXTERNAL ? 'target="_blank" title="' . $deeplink->getUrl() . '" ' : '') . 'href="' . ($deeplink->getType() == Application_Model_Models_Deeplink::TYPE_INTERNAL ? $websiteHelper->getUrl() . $deeplink->getUrl() : $deeplink->getUrl()) . '">' . $matches[2] . '</a>';
         $c = preg_replace('~' . $matches[2] . '~uU', $url, $content, 1);
         //return self::insertReplaced(preg_replace('~' . $matches[2] . '~uU', $url, $content, 1));
         return self::insertReplaced($c);
     }
     return self::insertReplaced($content);
 }
コード例 #2
0
 public function deeplinksAction()
 {
     $deeplinksForm = new Application_Form_Deeplink();
     $pageMapper = Application_Model_Mappers_PageMapper::getInstance();
     $deeplinksForm->setToasterPages($pageMapper->fetchIdUrlPairs());
     if ($this->getRequest()->isPost()) {
         if ($deeplinksForm->isValid($this->getRequest()->getParams())) {
             $data = $deeplinksForm->getValues();
             $deeplink = new Application_Model_Models_Deeplink();
             if (intval($data['url'])) {
                 $deeplink->setType(Application_Model_Models_Deeplink::TYPE_INTERNAL);
                 $page = $pageMapper->find($data['url']);
                 $deeplink->setPageId($data['url']);
                 $deeplink->setUrl($page->getUrl());
             } else {
                 $deeplink->setType(Application_Model_Models_Deeplink::TYPE_EXTERNAL);
                 $urlValidator = new Validators_UrlRegex();
                 if (!$urlValidator->isValid($data['url'])) {
                     $this->_helper->response->fail('External url <br />' . implode('<br />', $urlValidator->getMessages()));
                     exit;
                 }
                 $deeplink->setUrl($data['url']);
                 $deeplink->setPageId(null);
             }
             $deeplink->setName($data['anchorText']);
             $deeplink->setBanned(false);
             $deeplink->setNofollow($data['nofollow']);
             $deeplink->registerObserver(new Tools_Seo_Watchdog());
             Application_Model_Mappers_DeeplinkMapper::getInstance()->save($deeplink);
             $deeplink->notifyObservers();
             $this->_helper->response->success('Deeplink saved');
         } else {
             $this->_helper->response->fail(Tools_Content_Tools::proccessFormMessagesIntoHtml($deeplinksForm->getMessages(), get_class($deeplinksForm)));
             exit;
         }
     } else {
     }
     $this->view->helpSection = 'deeplinks';
     $this->view->form = $deeplinksForm;
 }
コード例 #3
0
 public function delete(Application_Model_Models_Deeplink $deeplink)
 {
     $where = $this->getDbTable()->getAdapter()->quoteInto('id = ?', $deeplink->getId());
     $deleteResult = $this->getDbTable()->delete($where);
     $deeplink->notifyObservers();
 }